Skip to content

Commit

Permalink
Verify all examples in the spec with validator
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Mar 5, 2020
1 parent 4c30c05 commit 32d3501
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
42 changes: 42 additions & 0 deletions optimade/validator/filters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
filter=_exmpl1_bandgap<2.0 OR _exmpl2_bandgap<2.5
NOT ( chemical_formula_hill = "Al" AND chemical_formula_anonymous = "A" OR chemical_formula_anonymous = "H2O" AND NOT chemical_formula_hill = "Ti" )
nelements > 3
chemical_formula_hill = "H2O" AND chemical_formula_anonymous != "AB"
_exmpl_aax <= +.1e8 OR nelements >= 10 AND NOT ( _exmpl_x != "Some string" OR NOT _exmpl_a = 7)
_exmpl_spacegroup="P2"
_exmpl_cell_volume<100.0
_exmpl_bandgap > 5.0 AND _exmpl_molecular_weight < 350
_exmpl_melting_point<300 AND nelements=4 AND elements="Si,O2"
_exmpl_some_string_property = 42
5 < _exmpl_a
identifier CONTAINS x
identifier STARTS WITH x
identifier ENDS WITH x
chemical_formula_anonymous CONTAINS "C2" AND chemical_formula_anonymous STARTS WITH "A2"
chemical_formula_anonymous STARTS "B2" AND chemical_formula_anonymous ENDS WITH "D2"
list HAS value
list HAS ALL values
list HAS ANY values
list LENGTH value
list HAS ONLY values
inverse
list HAS < 3
list HAS ALL < 3, > 3
list:list HAS >=2:<=5
references
identifier
chemical_formula_hill IS KNOWN AND NOT chemical_formula_anonymous IS UNKNOWN
NOT a > b OR c = 100 AND f = "C2 H6"
a >= 0 AND NOT b < c OR c = 0
elements HAS ALL "Si", "Al", "O"
elements HAS ALL "Si", "Al", "O" AND elements LENGTH 3
nelements=4
nelements>=2 AND nelements<=7
elements:elements_ratios HAS ALL "Al":>0.3333, "Al":<0.3334
chemical_formula_descriptive="(H2O)2 Na"
chemical_formula_descriptive CONTAINS "H2O"
chemical_formula_reduced="H2NaO"
chemical_formula_hill="H2O2"
chemical_formula_anonymous="A2B"
nsites=4
nsites>=2 AND nsites<=7
9 changes: 7 additions & 2 deletions optimade/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
import traceback

from pathlib import Path
from typing import Union

from pydantic import ValidationError
Expand All @@ -34,13 +35,17 @@
LINKS_ENDPOINT = "links"
REQUIRED_ENTRY_ENDPOINTS = ["references", "structures"]

with open(Path(__file__).parent.joinpath("filters.txt"), "r") as f:
SPEC_FILTERS = f.readlines()

ENDPOINT_MANDATORY_QUERIES = {
"structures": [
'elements HAS "Na"',
'elements HAS ANY "Na","Cl"',
'elements HAS ALL "Na","Cl"',
],
"references": [],
]
+ SPEC_FILTERS,
"references": SPEC_FILTERS,
}

RESPONSE_CLASSES = {
Expand Down

0 comments on commit 32d3501

Please sign in to comment.