Skip to content

Commit fe24d1b

Browse files
Merge pull request #150 from Exabyte-io/feature/pymatgen.core.structure
feature: pymatgen.core.structure
2 parents 5ded4f0 + 896b5d8 commit fe24d1b

File tree

5 files changed

+109
-5
lines changed

5 files changed

+109
-5
lines changed

express/parsers/structure.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ def __init__(self, *args, **kwargs):
5151

5252
# cell_type is either original, primitive or conventional
5353
self.cell_type = kwargs.get("cell_type", "original")
54-
self.structure = Structure.from_str(self.structure_string, self.structure_format)
54+
55+
# Initialize structure class
56+
if self.structure_format == "pymatgen.core.structure":
57+
structure_as_dict = json.loads(self.structure_string)
58+
self.structure = Structure.from_dict(structure_as_dict)
59+
else:
60+
self.structure = Structure.from_str(self.structure_string, self.structure_format)
61+
5562
if self.cell_type != "original":
5663
self.structure = STRUCTURE_MAP[self.cell_type](self.structure)
5764

5865
# keep only one atom inside the basis in order to have the original lattice type
59-
self.lattice_only_structure = Structure.from_str(self.structure_string, self.structure_format) # deepcopy
66+
self.lattice_only_structure = self.structure.copy() # deepcopy
6067
self.lattice_only_structure.remove_sites(range(1, len(self.structure.sites)))
6168

6269
def lattice_vectors(self):

tests/fixtures/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:1856a70b24c1282e38835fbfdcdcdcb2ec4dac9cd0081bf88b66141412eeacf1
3-
size 24072
2+
oid sha256:b43ccbf21870a847e8f01e1aa733605294e04332b3f12946526360a6811c14fb
3+
size 24827
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"@module": "pymatgen.core.structure",
3+
"@class": "Structure",
4+
"charge": 0,
5+
"lattice": {
6+
"matrix": [
7+
[
8+
3.47512448,
9+
0.0,
10+
2.00636466
11+
],
12+
[
13+
1.15837483,
14+
3.2763781,
15+
2.00636466
16+
],
17+
[
18+
0.0,
19+
0.0,
20+
4.01272831
21+
]
22+
],
23+
"pbc": [
24+
true,
25+
true,
26+
true
27+
],
28+
"a": 4.012728410993222,
29+
"b": 4.012727856438068,
30+
"c": 4.01272831,
31+
"alpha": 59.99998793483045,
32+
"beta": 59.99999250641951,
33+
"gamma": 59.999990385095536,
34+
"volume": 45.68820923290832
35+
},
36+
"properties": {},
37+
"sites": [
38+
{
39+
"species": [
40+
{
41+
"element": "Ge",
42+
"occu": 1
43+
}
44+
],
45+
"abc": [
46+
0.875,
47+
0.875,
48+
0.875
49+
],
50+
"properties": {
51+
"magmom": -0.0
52+
},
53+
"label": "Ge",
54+
"xyz": [
55+
4.05431189625,
56+
2.8668308375000002,
57+
7.02227542625
58+
]
59+
},
60+
{
61+
"species": [
62+
{
63+
"element": "Ge",
64+
"occu": 1
65+
}
66+
],
67+
"abc": [
68+
0.125,
69+
0.125,
70+
0.125
71+
],
72+
"properties": {
73+
"magmom": -0.0
74+
},
75+
"label": "Ge",
76+
"xyz": [
77+
0.579187413749999,
78+
0.4095472625,
79+
1.00318220375
80+
]
81+
}
82+
]
83+
}

tests/integration/parsers/test_structure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
from express.parsers.structure import StructureParser
4-
from tests.fixtures.data import JVASP_677, SI, SiC
4+
from tests.fixtures.data import JVASP_677, SI, SiC, GE
55
from tests.integration import IntegrationTestBase
66

77

@@ -41,5 +41,11 @@ def test_structure_jarvis_db_entry_basis(self):
4141
def test_structure_jarvis_db_entry_lattice_bravais(self):
4242
self.assertDeepAlmostEqual(self.parser.lattice_bravais(), JVASP_677["lattice"], places=2)
4343

44+
def test_structure_pymatgen_core_structure_basis(self):
45+
self.assertDeepAlmostEqual(self.parser.basis(), GE["basis"], places=2)
46+
47+
def test_structure_pymatgen_core_structure_lattice_bravais(self):
48+
self.assertDeepAlmostEqual(self.parser.lattice_bravais(), GE["lattice"], places=2)
49+
4450
def test_material_vasp_structure_order_of_elements(self):
4551
self.assertDeepAlmostEqual(self.parser.basis(), SiC["basis"], places=2)

tests/manifest.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ test_structure_jarvis_db_entry_lattice_bravais:
174174
structurePath: fixtures/structural/test-002/JVASP-677.json
175175
structureFormat: jarvis-db-entry
176176

177+
test_structure_pymatgen_core_structure_basis:
178+
structurePath: fixtures/structural/test-002/mp-32.json
179+
structureFormat: pymatgen.core.structure
180+
181+
test_structure_pymatgen_core_structure_lattice_bravais:
182+
structurePath: fixtures/structural/test-002/mp-32.json
183+
structureFormat: pymatgen.core.structure
184+
177185
test_molecule_inchi:
178186
structurePath: fixtures/structural/test-001/POSCAR
179187

0 commit comments

Comments
 (0)