-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from EMMC-ASBL/optional-parse-label
Made `label` optional in the parse strategy
- Loading branch information
Showing
5 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
da31ff66-98af-590c-855d-386c63617755: | ||
uuid: da31ff66-98af-590c-855d-386c63617755 | ||
uri: http://onto-ns.com/meta/0.1/Molecule | ||
meta: http://onto-ns.com/meta/0.3/EntitySchema | ||
description: A minimal description of a molecules | ||
dimensions: | ||
natoms: Number of atoms | ||
ncoords: Number coordinates. Always 3 | ||
properties: | ||
name: | ||
type: string | ||
description: Name of the molecule. | ||
positions: | ||
type: float64 | ||
shape: | ||
- natoms | ||
- ncoords | ||
unit: "\xC5ngstr\xF6m" | ||
description: Atomic positions in Cartesian coordinates. | ||
symbols: | ||
type: string | ||
shape: | ||
- natoms | ||
description: Chemical symbols. | ||
masses: | ||
type: float64 | ||
shape: | ||
- natoms | ||
unit: u | ||
description: Atomic masses. | ||
groundstate_energy: | ||
type: float64 | ||
unit: eV | ||
description: Molecule ground state energy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"b8906302-5cd9-5e34-9fec-9d6101e52554": { | ||
"meta": "http://onto-ns.com/meta/0.1/Molecule", | ||
"dimensions": { | ||
"natoms": 2, | ||
"ncoords": 3 | ||
}, | ||
"properties": { | ||
"name": "H2", | ||
"positions": [[-1.64097, 1.37077, 0], [-1.03814, 1.74207, 0]], | ||
"symbols": ["H", "H"], | ||
"masses": [1.008, 1.008], | ||
"groundstate_energy": 1.34613 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"""Test the image formats in the image parse strategy.""" | ||
|
||
# pylint: disable=too-many-locals | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from oteapi.interfaces import IParseStrategy | ||
|
||
from oteapi_dlite.models import DLiteSessionUpdate | ||
|
||
|
||
# if True: | ||
def test_parse_no_options() -> None: | ||
"""Test the dlite-parse strategy.""" | ||
|
||
import dlite | ||
from oteapi.datacache import DataCache | ||
from paths import staticdir | ||
|
||
from oteapi_dlite.strategies.parse import DLiteParseStrategy | ||
|
||
sample_file = staticdir / "molecule.json" | ||
|
||
cache = DataCache() | ||
|
||
orig_key = cache.add(sample_file.read_bytes()) | ||
config = { | ||
"downloadUrl": sample_file.as_uri(), | ||
"mediaType": "image/vnd.dlite-parse", | ||
"configuration": { | ||
"driver": "json", | ||
}, | ||
} | ||
coll = dlite.Collection() | ||
session = { | ||
"collection_id": coll.uuid, | ||
"key": orig_key, | ||
} | ||
cache.add(coll.asjson(), key=coll.uuid) | ||
parser: "IParseStrategy" = DLiteParseStrategy(config) | ||
output: "DLiteSessionUpdate" = parser.get(session) | ||
assert "collection_id" in output | ||
assert output.collection_id == coll.uuid | ||
|
||
# Get all instances of given metaid (there should only be one instance) | ||
metaid = "http://onto-ns.com/meta/0.1/Molecule" | ||
instances = list(coll.get_instances(metaid=metaid)) | ||
assert len(instances) == 1 | ||
(inst,) = instances | ||
assert inst.meta.uri == metaid | ||
|
||
|
||
# if True: | ||
def test_parse_label() -> None: | ||
"""Test the dlite-parse strategy.""" | ||
|
||
import dlite | ||
from oteapi.datacache import DataCache | ||
from paths import staticdir | ||
|
||
from oteapi_dlite.strategies.parse import DLiteParseStrategy | ||
|
||
sample_file = staticdir / "molecule.json" | ||
|
||
cache = DataCache() | ||
|
||
orig_key = cache.add(sample_file.read_bytes()) | ||
config = { | ||
"downloadUrl": sample_file.as_uri(), | ||
"mediaType": "image/vnd.dlite-parse", | ||
"configuration": { | ||
"driver": "json", | ||
"label": "instance", | ||
}, | ||
} | ||
coll = dlite.Collection() | ||
session = { | ||
"collection_id": coll.uuid, | ||
"key": orig_key, | ||
} | ||
cache.add(coll.asjson(), key=coll.uuid) | ||
parser: "IParseStrategy" = DLiteParseStrategy(config) | ||
output: "DLiteSessionUpdate" = parser.get(session) | ||
assert "collection_id" in output | ||
assert output.collection_id == coll.uuid | ||
|
||
coll2: dlite.Collection = dlite.get_instance(session["collection_id"]) | ||
inst: dlite.Instance = coll2.get("instance") | ||
assert inst.properties.keys() == { | ||
"name", | ||
"positions", | ||
"symbols", | ||
"masses", | ||
"groundstate_energy", | ||
} | ||
assert inst.properties["name"] == "H2" |