Skip to content

Commit 92b0c12

Browse files
committed
Support pymatgen JSON format
1 parent 89a04bd commit 92b0c12

10 files changed

Lines changed: 639 additions & 0 deletions

File tree

doc/format-pymatgen.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
title: Pymatgen JSON
3+
---
4+
5+
## Specification
6+
7+
@Note [Reference](https://pymatgen.org)
8+
9+
Pymatgen formatted JSON files are identified by the extension ``pmgjson`` and parsed following the ``Molecule`` or ``Structure`` format.
10+
11+
12+
## Example
13+
14+
Water molecules using ``Molecule`` schema.
15+
16+
```json
17+
{
18+
"@module": "pymatgen.core.structure",
19+
"@class": "Molecule",
20+
"charge": 0,
21+
"spin_multiplicity": 1,
22+
"sites": [
23+
{
24+
"name": "O",
25+
"species": [{"element": "O", "occu": 1}],
26+
"xyz": [1.1847029, 1.1150792, -0.0344641],
27+
"properties": {},
28+
"label": "O"
29+
},
30+
{
31+
"name": "H",
32+
"species": [{"element": "H", "occu": 1}],
33+
"xyz": [0.4939088, 0.9563767, 0.6340089],
34+
"properties": {},
35+
"label": "H"
36+
},
37+
{
38+
"name": "H",
39+
"species": [{"element": "H", "occu": 1}],
40+
"xyz": [2.0242676, 1.0811246, 0.4301417],
41+
"properties": {},
42+
"label": "H"
43+
},
44+
{
45+
"name": "O",
46+
"species": [{"element": "O", "occu": 1}],
47+
"xyz": [-1.1469443, 0.0697649, 1.1470196],
48+
"properties": {},
49+
"label": "O"
50+
},
51+
{
52+
"name": "H",
53+
"species": [{"element": "H", "occu": 1}],
54+
"xyz": [-1.2798308, -0.5232169, 1.8902833],
55+
"properties": {},
56+
"label": "H"
57+
},
58+
{
59+
"name": "H",
60+
"species": [{"element": "H", "occu": 1}],
61+
"xyz": [-1.0641398, -0.4956693, 0.356925],
62+
"properties": {},
63+
"label": "H"
64+
},
65+
{
66+
"name": "O",
67+
"species": [{"element": "O", "occu": 1}],
68+
"xyz": [-0.1633508, -1.0289346, -1.2401808],
69+
"properties": {},
70+
"label": "O"
71+
},
72+
{
73+
"name": "H",
74+
"species": [{"element": "H", "occu": 1}],
75+
"xyz": [0.4914771, -0.3248733, -1.0784838],
76+
"properties": {},
77+
"label": "H"
78+
},
79+
{
80+
"name": "H",
81+
"species": [{"element": "H", "occu": 1}],
82+
"xyz": [-0.5400907, -0.8496512, -2.1052499],
83+
"properties": {},
84+
"label": "H"
85+
}
86+
],
87+
"properties": {}
88+
}
89+
```
90+
91+
Rutile using ``Structure`` schema:
92+
93+
```json
94+
{
95+
"@module": "pymatgen.core.structure",
96+
"@class": "Structure",
97+
"charge": 0.0,
98+
"lattice": {
99+
"matrix": [
100+
[5.59003664376222, 0.0, 0.0],
101+
[0.0, 8.68089159045265, 0.0],
102+
[0.0, 0.0, 8.68089159045265]
103+
],
104+
"pbc": [true, true, true],
105+
"a": 5.59003664376222,
106+
"b": 8.68089159045265,
107+
"c": 8.68089159045265,
108+
"alpha": 90.0,
109+
"beta": 90.0,
110+
"gamma": 90.0,
111+
"volume": 421.253303917213
112+
},
113+
"properties": {},
114+
"sites": [
115+
{
116+
"species": [{"element": "Ti", "occu": 1}],
117+
"abc": [0.0, 0.0, 0.0],
118+
"properties": {},
119+
"label": "Ti",
120+
"xyz": [0.0, 0.0, 0.0]
121+
},
122+
{
123+
"species": [{"element": "Ti", "occu": 1}],
124+
"abc": [0.5, 0.5000000000000007, 0.5000000000000007],
125+
"properties": {},
126+
"label": "Ti",
127+
"xyz": [2.79501832188111, 4.340445795226331, 4.340445795226331]
128+
},
129+
{
130+
"species": [{"element": "O", "occu": 1}],
131+
"abc": [0.0, 0.30530000000000074, 0.30530000000000074],
132+
"properties": {},
133+
"label": "O",
134+
"xyz": [0.0, 2.6502762025652005, 2.6502762025652005]
135+
},
136+
{
137+
"species": [{"element": "O", "occu": 1}],
138+
"abc": [0.0, 0.6947000000000005, 0.6947000000000005],
139+
"properties": {},
140+
"label": "O",
141+
"xyz": [0.0, 6.03061538788746, 6.03061538788746]
142+
},
143+
{
144+
"species": [{"element": "O", "occu": 1}],
145+
"abc": [0.5, 0.1946999999999999, 0.8053000000000002],
146+
"properties": {},
147+
"label": "O",
148+
"xyz": [2.79501832188111, 1.69016959266113, 6.99072199779152]
149+
},
150+
{
151+
"species": [{"element": "O", "occu": 1}],
152+
"abc": [0.5, 0.8053000000000002, 0.1946999999999999],
153+
"properties": {},
154+
"label": "O",
155+
"xyz": [2.79501832188111, 6.99072199779152, 1.69016959266113]
156+
}
157+
]
158+
}
159+
```
160+
161+
## Missing features
162+
163+
The schema is not verified on completeness and not all data is stored in the final structure type.
164+
165+
@Note Feel free to contribute support for missing features
166+
or bring missing features to our attention by opening an issue.

doc/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ This library supports reading and writing of the following formats:
1313
- [Gaussian external format](./format-ein.html)
1414
- [Chemical JSON format](./format-cjson.html)
1515
- [QCSchema JSON format](./format-qcschema.html)
16+
- [Pymatgen JSON format](./format-pymatgen.html)
1617
- [FHI-aims geometry.in](./format-aims.html)
1718
- [Q-Chem molecule format](./format-qchem.html)

src/mctc/io/filetype.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ module mctc_io_filetype
6363
!> Chemical JSON format (avogadro)
6464
integer :: cjson = 12
6565

66+
!> Pymatgen JSON format
67+
integer :: pymatgen = 13
68+
6669
end type enum_filetype
6770

6871
!> File type enumerator
@@ -110,6 +113,8 @@ elemental function get_filetype(file) result(ftype)
110113
ftype = filetype%cjson
111114
case('qchem')
112115
ftype = filetype%qchem
116+
case('pmgjson')
117+
ftype = filetype%pymatgen
113118
end select
114119
if (ftype /= filetype%unknown) return
115120
else

src/mctc/io/read/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ list(
2424
"${dir}/qchem.f90"
2525
"${dir}/qcschema.F90"
2626
"${dir}/pdb.f90"
27+
"${dir}/pymatgen.f90"
2728
"${dir}/turbomole.f90"
2829
"${dir}/vasp.f90"
2930
"${dir}/xyz.f90"

src/mctc/io/read/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ srcs += files(
2121
'qchem.f90',
2222
'qcschema.F90',
2323
'pdb.f90',
24+
'pymatgen.f90',
2425
'turbomole.f90',
2526
'vasp.f90',
2627
'xyz.f90',

0 commit comments

Comments
 (0)