Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions express/parsers/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/data.py
Git LFS file not shown
83 changes: 83 additions & 0 deletions tests/fixtures/structural/test-002/mp-32.json
Original file line number Diff line number Diff line change
@@ -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
]
}
]
}
8 changes: 7 additions & 1 deletion tests/integration/parsers/test_structure.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions tests/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading