diff --git a/express/parsers/structure.py b/express/parsers/structure.py index 5ea088ef..d916017e 100644 --- a/express/parsers/structure.py +++ b/express/parsers/structure.py @@ -51,12 +51,19 @@ def __init__(self, *args, **kwargs): # cell_type is either original, primitive or conventional self.cell_type = kwargs.get("cell_type", "original") - self.structure = Structure.from_str(self.structure_string, self.structure_format) + + # Initialize structure class + if self.structure_format == "pymatgen.core.structure": + structure_as_dict = json.loads(self.structure_string) + self.structure = Structure.from_dict(structure_as_dict) + else: + self.structure = Structure.from_str(self.structure_string, self.structure_format) + if self.cell_type != "original": self.structure = STRUCTURE_MAP[self.cell_type](self.structure) # keep only one atom inside the basis in order to have the original lattice type - self.lattice_only_structure = Structure.from_str(self.structure_string, self.structure_format) # deepcopy + self.lattice_only_structure = self.structure.copy() # deepcopy self.lattice_only_structure.remove_sites(range(1, len(self.structure.sites))) def lattice_vectors(self): diff --git a/tests/fixtures/data.py b/tests/fixtures/data.py index 5d03bd92..44c6ecdc 100644 --- a/tests/fixtures/data.py +++ b/tests/fixtures/data.py @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1856a70b24c1282e38835fbfdcdcdcb2ec4dac9cd0081bf88b66141412eeacf1 -size 24072 +oid sha256:b43ccbf21870a847e8f01e1aa733605294e04332b3f12946526360a6811c14fb +size 24827 diff --git a/tests/fixtures/structural/test-002/mp-32.json b/tests/fixtures/structural/test-002/mp-32.json new file mode 100644 index 00000000..e58cdd57 --- /dev/null +++ b/tests/fixtures/structural/test-002/mp-32.json @@ -0,0 +1,83 @@ +{ + "@module": "pymatgen.core.structure", + "@class": "Structure", + "charge": 0, + "lattice": { + "matrix": [ + [ + 3.47512448, + 0.0, + 2.00636466 + ], + [ + 1.15837483, + 3.2763781, + 2.00636466 + ], + [ + 0.0, + 0.0, + 4.01272831 + ] + ], + "pbc": [ + true, + true, + true + ], + "a": 4.012728410993222, + "b": 4.012727856438068, + "c": 4.01272831, + "alpha": 59.99998793483045, + "beta": 59.99999250641951, + "gamma": 59.999990385095536, + "volume": 45.68820923290832 + }, + "properties": {}, + "sites": [ + { + "species": [ + { + "element": "Ge", + "occu": 1 + } + ], + "abc": [ + 0.875, + 0.875, + 0.875 + ], + "properties": { + "magmom": -0.0 + }, + "label": "Ge", + "xyz": [ + 4.05431189625, + 2.8668308375000002, + 7.02227542625 + ] + }, + { + "species": [ + { + "element": "Ge", + "occu": 1 + } + ], + "abc": [ + 0.125, + 0.125, + 0.125 + ], + "properties": { + "magmom": -0.0 + }, + "label": "Ge", + "xyz": [ + 0.579187413749999, + 0.4095472625, + 1.00318220375 + ] + } + ] +} diff --git a/tests/integration/parsers/test_structure.py b/tests/integration/parsers/test_structure.py index a8c3a0e0..880f6264 100644 --- a/tests/integration/parsers/test_structure.py +++ b/tests/integration/parsers/test_structure.py @@ -1,7 +1,7 @@ import os from express.parsers.structure import StructureParser -from tests.fixtures.data import JVASP_677, SI, SiC +from tests.fixtures.data import JVASP_677, SI, SiC, GE from tests.integration import IntegrationTestBase @@ -41,5 +41,11 @@ def test_structure_jarvis_db_entry_basis(self): def test_structure_jarvis_db_entry_lattice_bravais(self): self.assertDeepAlmostEqual(self.parser.lattice_bravais(), JVASP_677["lattice"], places=2) + def test_structure_pymatgen_core_structure_basis(self): + self.assertDeepAlmostEqual(self.parser.basis(), GE["basis"], places=2) + + def test_structure_pymatgen_core_structure_lattice_bravais(self): + self.assertDeepAlmostEqual(self.parser.lattice_bravais(), GE["lattice"], places=2) + def test_material_vasp_structure_order_of_elements(self): self.assertDeepAlmostEqual(self.parser.basis(), SiC["basis"], places=2) diff --git a/tests/manifest.yaml b/tests/manifest.yaml index a10820f3..cd8467d8 100644 --- a/tests/manifest.yaml +++ b/tests/manifest.yaml @@ -174,6 +174,14 @@ test_structure_jarvis_db_entry_lattice_bravais: structurePath: fixtures/structural/test-002/JVASP-677.json structureFormat: jarvis-db-entry +test_structure_pymatgen_core_structure_basis: + structurePath: fixtures/structural/test-002/mp-32.json + structureFormat: pymatgen.core.structure + +test_structure_pymatgen_core_structure_lattice_bravais: + structurePath: fixtures/structural/test-002/mp-32.json + structureFormat: pymatgen.core.structure + test_molecule_inchi: structurePath: fixtures/structural/test-001/POSCAR