nomad-parser-plugins-electronic 1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. electronicparsers/__init__.py +1162 -0
  2. electronicparsers/abacus/__init__.py +20 -0
  3. electronicparsers/abacus/__main__.py +32 -0
  4. electronicparsers/abacus/metainfo/__init__.py +19 -0
  5. electronicparsers/abacus/metainfo/abacus.py +836 -0
  6. electronicparsers/abacus/nomad_plugin.yaml +44 -0
  7. electronicparsers/abacus/parser.py +1975 -0
  8. electronicparsers/abinit/__init__.py +19 -0
  9. electronicparsers/abinit/__main__.py +31 -0
  10. electronicparsers/abinit/metainfo/__init__.py +20 -0
  11. electronicparsers/abinit/metainfo/abinit.py +871 -0
  12. electronicparsers/abinit/metainfo/abinit_autogenerated.py +6794 -0
  13. electronicparsers/abinit/nomad_plugin.yaml +43 -0
  14. electronicparsers/abinit/parser.py +1922 -0
  15. electronicparsers/ams/__init__.py +19 -0
  16. electronicparsers/ams/__main__.py +31 -0
  17. electronicparsers/ams/metainfo/__init__.py +19 -0
  18. electronicparsers/ams/metainfo/ams.py +769 -0
  19. electronicparsers/ams/nomad_plugin.yaml +19 -0
  20. electronicparsers/ams/parser.py +1849 -0
  21. electronicparsers/ams/rkf.py +620 -0
  22. electronicparsers/atk/__init__.py +19 -0
  23. electronicparsers/atk/__main__.py +31 -0
  24. electronicparsers/atk/metainfo/__init__.py +19 -0
  25. electronicparsers/atk/metainfo/atk.py +71 -0
  26. electronicparsers/atk/nomad_plugin.yaml +34 -0
  27. electronicparsers/atk/parser.py +388 -0
  28. electronicparsers/bigdft/__init__.py +19 -0
  29. electronicparsers/bigdft/__main__.py +31 -0
  30. electronicparsers/bigdft/metainfo/__init__.py +18 -0
  31. electronicparsers/bigdft/nomad_plugin.yaml +19 -0
  32. electronicparsers/bigdft/parser.py +372 -0
  33. electronicparsers/castep/__init__.py +19 -0
  34. electronicparsers/castep/__main__.py +31 -0
  35. electronicparsers/castep/metainfo/__init__.py +19 -0
  36. electronicparsers/castep/metainfo/castep.py +2481 -0
  37. electronicparsers/castep/nomad_plugin.yaml +28 -0
  38. electronicparsers/castep/parser.py +1680 -0
  39. electronicparsers/charmm/__init__.py +19 -0
  40. electronicparsers/charmm/__main__.py +31 -0
  41. electronicparsers/charmm/metainfo/__init__.py +19 -0
  42. electronicparsers/charmm/metainfo/charmm.py +1931 -0
  43. electronicparsers/charmm/nomad_plugin.yaml +18 -0
  44. electronicparsers/charmm/parser.py +61 -0
  45. electronicparsers/cp2k/__init__.py +19 -0
  46. electronicparsers/cp2k/__main__.py +31 -0
  47. electronicparsers/cp2k/metainfo/__init__.py +19 -0
  48. electronicparsers/cp2k/metainfo/cp2k.py +59185 -0
  49. electronicparsers/cp2k/metainfo/cp2k_general.py +1014 -0
  50. electronicparsers/cp2k/nomad_plugin.yaml +49 -0
  51. electronicparsers/cp2k/parser.py +2324 -0
  52. electronicparsers/cpmd/__init__.py +19 -0
  53. electronicparsers/cpmd/__main__.py +31 -0
  54. electronicparsers/cpmd/metainfo/__init__.py +19 -0
  55. electronicparsers/cpmd/metainfo/cpmd.py +10733 -0
  56. electronicparsers/cpmd/metainfo/cpmd_general.py +988 -0
  57. electronicparsers/cpmd/nomad_plugin.yaml +19 -0
  58. electronicparsers/cpmd/parser.py +680 -0
  59. electronicparsers/crystal/__init__.py +19 -0
  60. electronicparsers/crystal/__main__.py +31 -0
  61. electronicparsers/crystal/metainfo/__init__.py +19 -0
  62. electronicparsers/crystal/metainfo/crystal.py +619 -0
  63. electronicparsers/crystal/nomad_plugin.yaml +36 -0
  64. electronicparsers/crystal/parser.py +1745 -0
  65. electronicparsers/dmol3/__init__.py +19 -0
  66. electronicparsers/dmol3/__main__.py +31 -0
  67. electronicparsers/dmol3/metainfo/__init__.py +19 -0
  68. electronicparsers/dmol3/metainfo/dmol3.py +664 -0
  69. electronicparsers/dmol3/nomad_plugin.yaml +19 -0
  70. electronicparsers/dmol3/parser.py +750 -0
  71. electronicparsers/edmft/__init__.py +19 -0
  72. electronicparsers/edmft/__main__.py +31 -0
  73. electronicparsers/edmft/metainfo/__init__.py +19 -0
  74. electronicparsers/edmft/metainfo/edmft.py +96 -0
  75. electronicparsers/edmft/nomad_plugin.yaml +53 -0
  76. electronicparsers/edmft/parser.py +912 -0
  77. electronicparsers/elk/__init__.py +19 -0
  78. electronicparsers/elk/__main__.py +31 -0
  79. electronicparsers/elk/metainfo/__init__.py +19 -0
  80. electronicparsers/elk/metainfo/elk.py +775 -0
  81. electronicparsers/elk/nomad_plugin.yaml +19 -0
  82. electronicparsers/elk/parser.py +493 -0
  83. electronicparsers/exciting/__init__.py +19 -0
  84. electronicparsers/exciting/__main__.py +31 -0
  85. electronicparsers/exciting/metainfo/__init__.py +19 -0
  86. electronicparsers/exciting/metainfo/exciting.py +2942 -0
  87. electronicparsers/exciting/nomad_plugin.yaml +83 -0
  88. electronicparsers/exciting/parser.py +3398 -0
  89. electronicparsers/fhiaims/__init__.py +19 -0
  90. electronicparsers/fhiaims/__main__.py +31 -0
  91. electronicparsers/fhiaims/metainfo/__init__.py +19 -0
  92. electronicparsers/fhiaims/metainfo/fhi_aims.py +1565 -0
  93. electronicparsers/fhiaims/nomad_plugin.yaml +52 -0
  94. electronicparsers/fhiaims/parser.py +2582 -0
  95. electronicparsers/fleur/__init__.py +19 -0
  96. electronicparsers/fleur/__main__.py +31 -0
  97. electronicparsers/fleur/metainfo/__init__.py +19 -0
  98. electronicparsers/fleur/metainfo/fleur.py +623 -0
  99. electronicparsers/fleur/nomad_plugin.yaml +19 -0
  100. electronicparsers/fleur/parser.py +952 -0
  101. electronicparsers/fplo/__init__.py +19 -0
  102. electronicparsers/fplo/__main__.py +31 -0
  103. electronicparsers/fplo/metainfo/__init__.py +19 -0
  104. electronicparsers/fplo/metainfo/fplo.py +188 -0
  105. electronicparsers/fplo/metainfo/fplo_input_autogenerated.py +2744 -0
  106. electronicparsers/fplo/metainfo/fplo_temporaries.py +319 -0
  107. electronicparsers/fplo/nomad_plugin.yaml +19 -0
  108. electronicparsers/fplo/parser.py +42 -0
  109. electronicparsers/gamess/__init__.py +19 -0
  110. electronicparsers/gamess/__main__.py +31 -0
  111. electronicparsers/gamess/metainfo/__init__.py +19 -0
  112. electronicparsers/gamess/metainfo/gamess.py +837 -0
  113. electronicparsers/gamess/nomad_plugin.yaml +19 -0
  114. electronicparsers/gamess/parser.py +941 -0
  115. electronicparsers/gaussian/__init__.py +19 -0
  116. electronicparsers/gaussian/__main__.py +31 -0
  117. electronicparsers/gaussian/metainfo/__init__.py +19 -0
  118. electronicparsers/gaussian/metainfo/gaussian.py +1707 -0
  119. electronicparsers/gaussian/nomad_plugin.yaml +18 -0
  120. electronicparsers/gaussian/parser.py +1556 -0
  121. electronicparsers/gpaw/__init__.py +19 -0
  122. electronicparsers/gpaw/__main__.py +31 -0
  123. electronicparsers/gpaw/metainfo/__init__.py +19 -0
  124. electronicparsers/gpaw/metainfo/gpaw.py +214 -0
  125. electronicparsers/gpaw/nomad_plugin.yaml +19 -0
  126. electronicparsers/gpaw/parser.py +671 -0
  127. electronicparsers/magres/__init__.py +19 -0
  128. electronicparsers/magres/__main__.py +31 -0
  129. electronicparsers/magres/metainfo/__init__.py +19 -0
  130. electronicparsers/magres/metainfo/magres.py +110 -0
  131. electronicparsers/magres/nomad_plugin.yaml +18 -0
  132. electronicparsers/magres/parser.py +505 -0
  133. electronicparsers/molcas/__init__.py +19 -0
  134. electronicparsers/molcas/__main__.py +31 -0
  135. electronicparsers/molcas/metainfo/__init__.py +19 -0
  136. electronicparsers/molcas/metainfo/molcas.py +151 -0
  137. electronicparsers/molcas/nomad_plugin.yaml +19 -0
  138. electronicparsers/molcas/parser.py +59 -0
  139. electronicparsers/mopac/__init__.py +19 -0
  140. electronicparsers/mopac/__main__.py +31 -0
  141. electronicparsers/mopac/metainfo/__init__.py +19 -0
  142. electronicparsers/mopac/metainfo/mopac.py +79 -0
  143. electronicparsers/mopac/nomad_plugin.yaml +19 -0
  144. electronicparsers/mopac/parser.py +304 -0
  145. electronicparsers/nwchem/__init__.py +19 -0
  146. electronicparsers/nwchem/__main__.py +31 -0
  147. electronicparsers/nwchem/metainfo/__init__.py +19 -0
  148. electronicparsers/nwchem/metainfo/nwchem.py +487 -0
  149. electronicparsers/nwchem/nomad_plugin.yaml +19 -0
  150. electronicparsers/nwchem/parser.py +757 -0
  151. electronicparsers/ocean/__init__.py +19 -0
  152. electronicparsers/ocean/__main__.py +31 -0
  153. electronicparsers/ocean/metainfo/__init__.py +19 -0
  154. electronicparsers/ocean/metainfo/ocean.py +410 -0
  155. electronicparsers/ocean/nomad_plugin.yaml +37 -0
  156. electronicparsers/ocean/parser.py +344 -0
  157. electronicparsers/octopus/__init__.py +19 -0
  158. electronicparsers/octopus/__main__.py +31 -0
  159. electronicparsers/octopus/metainfo/__init__.py +19 -0
  160. electronicparsers/octopus/metainfo/octopus.py +71 -0
  161. electronicparsers/octopus/metainfo/octopus_autogenerated.py +11647 -0
  162. electronicparsers/octopus/nomad_plugin.yaml +41 -0
  163. electronicparsers/octopus/parser.py +1214 -0
  164. electronicparsers/onetep/__init__.py +19 -0
  165. electronicparsers/onetep/__main__.py +31 -0
  166. electronicparsers/onetep/metainfo/__init__.py +19 -0
  167. electronicparsers/onetep/metainfo/onetep.py +3443 -0
  168. electronicparsers/onetep/nomad_plugin.yaml +19 -0
  169. electronicparsers/onetep/parser.py +577 -0
  170. electronicparsers/openmx/__init__.py +19 -0
  171. electronicparsers/openmx/__main__.py +31 -0
  172. electronicparsers/openmx/metainfo/__init__.py +19 -0
  173. electronicparsers/openmx/metainfo/openmx.py +24 -0
  174. electronicparsers/openmx/nomad_plugin.yaml +25 -0
  175. electronicparsers/openmx/parser.py +918 -0
  176. electronicparsers/orca/__init__.py +19 -0
  177. electronicparsers/orca/__main__.py +31 -0
  178. electronicparsers/orca/metainfo/__init__.py +19 -0
  179. electronicparsers/orca/metainfo/orca.py +1448 -0
  180. electronicparsers/orca/nomad_plugin.yaml +19 -0
  181. electronicparsers/orca/parser.py +1371 -0
  182. electronicparsers/psi4/__init__.py +19 -0
  183. electronicparsers/psi4/__main__.py +31 -0
  184. electronicparsers/psi4/metainfo/__init__.py +19 -0
  185. electronicparsers/psi4/metainfo/psi4.py +372 -0
  186. electronicparsers/psi4/nomad_plugin.yaml +27 -0
  187. electronicparsers/psi4/parser.py +1362 -0
  188. electronicparsers/qball/__init__.py +19 -0
  189. electronicparsers/qball/__main__.py +31 -0
  190. electronicparsers/qball/metainfo/__init__.py +19 -0
  191. electronicparsers/qball/metainfo/qball.py +27 -0
  192. electronicparsers/qball/nomad_plugin.yaml +25 -0
  193. electronicparsers/qball/parser.py +152 -0
  194. electronicparsers/qbox/__init__.py +19 -0
  195. electronicparsers/qbox/__main__.py +31 -0
  196. electronicparsers/qbox/metainfo/__init__.py +19 -0
  197. electronicparsers/qbox/metainfo/qbox.py +490 -0
  198. electronicparsers/qbox/nomad_plugin.yaml +19 -0
  199. electronicparsers/qbox/parser.py +508 -0
  200. electronicparsers/quantumespresso/__init__.py +19 -0
  201. electronicparsers/quantumespresso/__main__.py +31 -0
  202. electronicparsers/quantumespresso/metainfo/__init__.py +19 -0
  203. electronicparsers/quantumespresso/metainfo/quantum_espresso.py +3296 -0
  204. electronicparsers/quantumespresso/nomad_plugin.yaml +31 -0
  205. electronicparsers/quantumespresso/parser.py +3594 -0
  206. electronicparsers/siesta/__init__.py +19 -0
  207. electronicparsers/siesta/__main__.py +31 -0
  208. electronicparsers/siesta/metainfo/__init__.py +19 -0
  209. electronicparsers/siesta/metainfo/siesta.py +141 -0
  210. electronicparsers/siesta/metainfo/siesta_autogenerated.py +3365 -0
  211. electronicparsers/siesta/nomad_plugin.yaml +19 -0
  212. electronicparsers/siesta/parser.py +607 -0
  213. electronicparsers/soliddmft/__init__.py +19 -0
  214. electronicparsers/soliddmft/__main__.py +31 -0
  215. electronicparsers/soliddmft/metainfo/__init__.py +19 -0
  216. electronicparsers/soliddmft/metainfo/soliddmft.py +274 -0
  217. electronicparsers/soliddmft/nomad_plugin.yaml +26 -0
  218. electronicparsers/soliddmft/parser.py +727 -0
  219. electronicparsers/tbstudio/__init__.py +19 -0
  220. electronicparsers/tbstudio/__main__.py +31 -0
  221. electronicparsers/tbstudio/metainfo/__init__.py +19 -0
  222. electronicparsers/tbstudio/metainfo/tbstudio.py +34 -0
  223. electronicparsers/tbstudio/nomad_plugin.yaml +24 -0
  224. electronicparsers/tbstudio/parser.py +412 -0
  225. electronicparsers/turbomole/__init__.py +19 -0
  226. electronicparsers/turbomole/__main__.py +31 -0
  227. electronicparsers/turbomole/metainfo/__init__.py +19 -0
  228. electronicparsers/turbomole/metainfo/turbomole.py +727 -0
  229. electronicparsers/turbomole/nomad_plugin.yaml +18 -0
  230. electronicparsers/turbomole/parser.py +1585 -0
  231. electronicparsers/utils/__init__.py +20 -0
  232. electronicparsers/utils/magres_workflow.py +61 -0
  233. electronicparsers/utils/utils.py +636 -0
  234. electronicparsers/vasp/__init__.py +19 -0
  235. electronicparsers/vasp/__main__.py +31 -0
  236. electronicparsers/vasp/metainfo/__init__.py +19 -0
  237. electronicparsers/vasp/metainfo/vasp.py +169 -0
  238. electronicparsers/vasp/metainfo/vasp_incars.py +3428 -0
  239. electronicparsers/vasp/metainfo/vasp_incarsOut.py +3428 -0
  240. electronicparsers/vasp/metainfo/vasp_incarsUnknown.py +86 -0
  241. electronicparsers/vasp/nomad_plugin.yaml +28 -0
  242. electronicparsers/vasp/parser.py +2340 -0
  243. electronicparsers/w2dynamics/__init__.py +19 -0
  244. electronicparsers/w2dynamics/__main__.py +31 -0
  245. electronicparsers/w2dynamics/metainfo/__init__.py +19 -0
  246. electronicparsers/w2dynamics/metainfo/w2dynamics.py +1270 -0
  247. electronicparsers/w2dynamics/nomad_plugin.yaml +36 -0
  248. electronicparsers/w2dynamics/parser.py +674 -0
  249. electronicparsers/wannier90/__init__.py +19 -0
  250. electronicparsers/wannier90/__main__.py +31 -0
  251. electronicparsers/wannier90/metainfo/__init__.py +19 -0
  252. electronicparsers/wannier90/metainfo/wannier90.py +56 -0
  253. electronicparsers/wannier90/nomad_plugin.yaml +34 -0
  254. electronicparsers/wannier90/parser.py +671 -0
  255. electronicparsers/wien2k/__init__.py +19 -0
  256. electronicparsers/wien2k/__main__.py +31 -0
  257. electronicparsers/wien2k/metainfo/__init__.py +19 -0
  258. electronicparsers/wien2k/metainfo/wien2k.py +783 -0
  259. electronicparsers/wien2k/nomad_plugin.yaml +18 -0
  260. electronicparsers/wien2k/parser.py +1133 -0
  261. electronicparsers/yambo/__init__.py +19 -0
  262. electronicparsers/yambo/__main__.py +31 -0
  263. electronicparsers/yambo/metainfo/__init__.py +19 -0
  264. electronicparsers/yambo/metainfo/yambo.py +577 -0
  265. electronicparsers/yambo/nomad_plugin.yaml +31 -0
  266. electronicparsers/yambo/parser.py +896 -0
  267. nomad_parser_plugins_electronic-1.0.dist-info/LICENSE +202 -0
  268. nomad_parser_plugins_electronic-1.0.dist-info/METADATA +360 -0
  269. nomad_parser_plugins_electronic-1.0.dist-info/RECORD +272 -0
  270. nomad_parser_plugins_electronic-1.0.dist-info/WHEEL +5 -0
  271. nomad_parser_plugins_electronic-1.0.dist-info/entry_points.txt +43 -0
  272. nomad_parser_plugins_electronic-1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1849 @@
1
+ #
2
+ # Copyright The NOMAD Authors.
3
+ #
4
+ # This file is part of NOMAD.
5
+ # See https://nomad-lab.eu for further info.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ import os
20
+ import re
21
+ import numpy as np
22
+ import logging
23
+ from datetime import datetime
24
+ from ase.data import chemical_symbols
25
+
26
+ from nomad.units import ureg
27
+ from nomad.parsing.file_parser.text_parser import TextParser, Quantity, FileParser
28
+ from runschema.run import Run, Program, TimeRun
29
+ from runschema.method import (
30
+ Method,
31
+ DFT,
32
+ XCFunctional,
33
+ Functional,
34
+ Electronic,
35
+ BasisSet,
36
+ Scf,
37
+ AtomParameters,
38
+ KMesh,
39
+ BasisSetContainer,
40
+ BasisSetAtomCentered,
41
+ )
42
+ from runschema.system import System, Atoms
43
+ from runschema.calculation import (
44
+ Calculation,
45
+ ScfIteration,
46
+ Dos,
47
+ DosValues,
48
+ Energy,
49
+ EnergyEntry,
50
+ Forces,
51
+ ForcesEntry,
52
+ Charges,
53
+ ChargesValue,
54
+ Multipoles,
55
+ MultipolesEntry,
56
+ BandEnergies,
57
+ BandGapDeprecated,
58
+ BandGap,
59
+ )
60
+ from simulationworkflowschema import (
61
+ GeometryOptimization,
62
+ GeometryOptimizationMethod,
63
+ MolecularDynamics,
64
+ )
65
+ from .metainfo import ams as ams_metainfo # pylint: disable=unused-import
66
+ from electronicparsers.utils import get_files
67
+ from .rkf import rkf_to_dict
68
+
69
+
70
+ re_float = r'[-+]?\d+\.\d*(?:[Ee][-+]\d+)?'
71
+ re_n = r'[\n\r]'
72
+
73
+
74
+ class OutParser(TextParser):
75
+ def __init__(self):
76
+ super().__init__()
77
+
78
+ def init_quantities(self):
79
+ def str_to_labels_positions(val_in):
80
+ val = [v.split() for v in val_in.strip().splitlines()]
81
+ unit = val.pop(0)[0].lower()
82
+ unit = ureg.bohr if unit.startswith('bohr') else ureg.angstrom
83
+ val = np.transpose(val)
84
+ return val[1], np.array(val[2:5].T, dtype=np.dtype(np.float64)) * unit
85
+
86
+ def str_to_lattice_vectors(val_in):
87
+ val = [v.split()[-3:] for v in val_in.strip().splitlines()]
88
+ unit = val.pop(0)[0].lower()
89
+ unit = ureg.bohr if unit.startswith('bohr') else ureg.angstrom
90
+ return np.array(val, dtype=np.dtype(np.float64)) * unit
91
+
92
+ def str_to_forces(val_in):
93
+ val = [v.split()[2:5] for v in val_in.strip().splitlines()]
94
+ return np.array(val, dtype=np.dtype(np.float64)) * ureg.hartree / ureg.bohr
95
+
96
+ def to_parameters(val_in):
97
+ lines = [v.strip().rsplit(' ', 1) for v in val_in.strip().splitlines()]
98
+ return {
99
+ line[0].strip(): line[1].strip() for line in lines if len(line) == 2
100
+ }
101
+
102
+ def to_run_config(val_in):
103
+ lines = [v.strip().split('. ') for v in val_in.strip().splitlines()]
104
+ return {line[0].strip(): line[-1] == 'T' for line in lines}
105
+
106
+ def to_mulliken_populations(val_in):
107
+ lines = [v.strip().split() for v in val_in.strip().splitlines()]
108
+ orbitals = np.transpose([line[0].split('/') for line in lines])
109
+ return (
110
+ orbitals[0],
111
+ orbitals[1],
112
+ orbitals[3],
113
+ np.array([line[1:] for line in lines], np.float64),
114
+ )
115
+
116
+ def to_band_energy_ranges(val_in):
117
+ columns = np.array(
118
+ [v.strip().split() for v in val_in.strip().splitlines()], np.float64
119
+ ).T[1:]
120
+ nspin = len(columns) // 3
121
+ emin = [columns[n * 3 + 0] for n in range(nspin)]
122
+ emax = [columns[n * 3 + 1] for n in range(nspin)]
123
+ occs = [[columns[n * 3 + 2]] for n in range(nspin)]
124
+ return emin, emax, occs
125
+
126
+ system_quantities = [
127
+ Quantity(
128
+ 'labels_positions',
129
+ rf'Index Symbol\s*x\s*\((.+?)\).+(\s+)'
130
+ rf'((?:\d+ + [A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
131
+ convert=False,
132
+ str_operation=str_to_labels_positions,
133
+ ),
134
+ Quantity(
135
+ 'lattice_vectors',
136
+ r'Lattice vectors \((.+?)\)(\s+)'
137
+ rf'((?:\d+ +{re_float} +{re_float} +{re_float}\s+)+)',
138
+ convert=False,
139
+ str_operation=str_to_lattice_vectors,
140
+ ),
141
+ ]
142
+
143
+ method_quantities = [
144
+ Quantity(
145
+ 'band_engine_input',
146
+ r'Band Engine Input\s*\-+\s*([\s\S]+?)\n *\n',
147
+ sub_parser=TextParser(
148
+ quantities=[Quantity('basis', r' Basis\s*Type\s*(.+)')]
149
+ ),
150
+ ),
151
+ Quantity(
152
+ 'model_parameters',
153
+ r'M O D E L P A R A M E T E R S\s*\=+([\s\S]+?)\={10}',
154
+ sub_parser=TextParser(
155
+ quantities=[
156
+ Quantity(
157
+ 'dft_potential',
158
+ r'FUNCTIONAL POTENTIAL \(scf\)([\s\S]+?)DENSITY',
159
+ sub_parser=TextParser(
160
+ quantities=[
161
+ Quantity('LDA', r'LDA\:\s*([\w ]+)', flatten=False),
162
+ Quantity(
163
+ 'GGA',
164
+ r'Gradient Corrections\:\s*([\w ]+)',
165
+ flatten=False,
166
+ ),
167
+ Quantity(
168
+ 'MGGA', r'Meta-GGA\:\s*([\w ]+)', flatten=False
169
+ ),
170
+ ]
171
+ ),
172
+ ),
173
+ Quantity(
174
+ 'spin', r'(UNrestricted)', str_operation=lambda x: True
175
+ ),
176
+ Quantity(
177
+ 'relativistic_corrections',
178
+ r'Relativistic Corrections\:\s*(.+?) ',
179
+ dtype=str,
180
+ flatten=False,
181
+ ),
182
+ Quantity(
183
+ 'x_ams_nuclear_charge_density_model',
184
+ rf'Nuclear Charge Density Model\:\s*(.+?){re_n}',
185
+ str_operation=lambda x: x.strip(),
186
+ dtype=str,
187
+ flatten=False,
188
+ ),
189
+ ]
190
+ ),
191
+ ),
192
+ Quantity(
193
+ 'confinement',
194
+ r'C O N F I N E M E N T\s+\=+\s+([\s\S]+?)\={10}',
195
+ sub_parser=TextParser(
196
+ quantities=[
197
+ Quantity(
198
+ 'x_ams_basis_functions_confinement_radius',
199
+ rf'Basis functions confinement radius\s+({re_float})',
200
+ dtype=np.float64,
201
+ ),
202
+ Quantity(
203
+ 'x_ams_basis_functions_confinement_width',
204
+ rf'Width\s+({re_float})',
205
+ dtype=np.float64,
206
+ ),
207
+ ]
208
+ ),
209
+ ),
210
+ Quantity(
211
+ 'radial_functions',
212
+ r'(T Y P E +\d+\s+\-+[\s\S]+?NR\. OF RADIAL FIT FUNCTIONS.+)',
213
+ repeats=True,
214
+ sub_parser=TextParser(
215
+ quantities=[
216
+ Quantity(
217
+ 'x_ams_radial_points',
218
+ r'RADIAL POINTS\s+(\d+)',
219
+ dtype=np.int32,
220
+ ),
221
+ Quantity('label', r'\*\*> +(\w+) +<\*\*', dtype=str),
222
+ Quantity(
223
+ 'x_ams_nuclear_charge',
224
+ rf'NUCLEAR CHARGE\s+({re_float})',
225
+ dtype=np.float64,
226
+ ),
227
+ Quantity(
228
+ 'n_valence_electrons',
229
+ rf'VALENCE CHARGE\s+({re_float})',
230
+ dtype=np.float64,
231
+ ),
232
+ Quantity(
233
+ 'charge', rf'NET CHARGE\s+({re_float})', dtype=np.float64
234
+ ),
235
+ Quantity(
236
+ 'orbital_parameters',
237
+ rf'Orbital +Q.+\s*\-+\s+((?:\d+\w+ +{re_float}.+\s+)+)',
238
+ str_operation=lambda x: np.transpose(
239
+ [v.strip().split() for v in x.strip().splitlines()]
240
+ ),
241
+ ),
242
+ Quantity(
243
+ 'x_ams_energy_sum_eigenvalues',
244
+ rf'Sum \(energy eigenvalues\)\s+({re_float})',
245
+ dtype=np.float64,
246
+ unit=ureg.hartree,
247
+ ),
248
+ Quantity(
249
+ 'x_ams_energy_total_lda',
250
+ rf'Total energy LDA\s+({re_float})',
251
+ dtype=np.float64,
252
+ unit=ureg.hartree,
253
+ ),
254
+ Quantity(
255
+ 'x_ams_energy_kinetic',
256
+ rf'Kinetic energy\s+({re_float})',
257
+ dtype=np.float64,
258
+ unit=ureg.hartree,
259
+ ),
260
+ Quantity(
261
+ 'x_ams_energy_classical_electron_electron_repulsion',
262
+ rf'Classical e\-e repulsion\s+({re_float})',
263
+ dtype=np.float64,
264
+ unit=ureg.hartree,
265
+ ),
266
+ Quantity(
267
+ 'x_ams_energy_electron_nucleus_repulsion',
268
+ rf'Classical e\-e repulsion\s+({re_float})',
269
+ dtype=np.float64,
270
+ unit=ureg.hartree,
271
+ ),
272
+ Quantity(
273
+ 'x_ams_n_radial_valence_orbitals',
274
+ r'NR\. OF RADIAL VALENCE ORBITALS\s+(\d+)',
275
+ dtype=np.int32,
276
+ ),
277
+ Quantity(
278
+ 'x_ams_n_radial_core_orbitals',
279
+ r'NR\. OF RADIAL CORE ORBITALS\s+(\d+)',
280
+ dtype=np.int32,
281
+ ),
282
+ Quantity(
283
+ 'x_ams_n_radial_fit_functions',
284
+ r'NR\. OF RADIAL FIT FUNCTIONS\s+(\d+)',
285
+ dtype=np.int32,
286
+ ),
287
+ ]
288
+ ),
289
+ ),
290
+ Quantity(
291
+ 'ranges_atomic_orbitals',
292
+ r'R A N G E S F O R A T O M I C O R B I T A L S\s+\=+([\s\S]+?)\={10}',
293
+ sub_parser=TextParser(
294
+ quantities=[
295
+ Quantity(
296
+ 'type',
297
+ rf'Type +valence.+\s+\-+\s+((?:\w+ +{re_float}.+\s+)+)',
298
+ str_operation=lambda x: [
299
+ v.strip().split() for v in x.strip().splitlines()
300
+ ],
301
+ ),
302
+ Quantity(
303
+ 'cutoff',
304
+ rf'Cutoff +({re_float}.+)',
305
+ dtype=np.dtype(np.float64),
306
+ ),
307
+ ]
308
+ ),
309
+ ),
310
+ Quantity(
311
+ 'x_ams_run_config',
312
+ r'R U N C O N F I G\s+\=+\s+((?:\w.+\s+)+)',
313
+ str_operation=to_run_config,
314
+ ),
315
+ Quantity(
316
+ 'k_space_sampling',
317
+ r'(?:K \- S P A C E S A M P L I N G|K\-space integration)([\s\S]+?)\={5}',
318
+ sub_parser=TextParser(
319
+ quantities=[
320
+ Quantity(
321
+ 'x_ams_general_integration_parameter',
322
+ r'General integration parameter\s+(\d+)',
323
+ dtype=np.int32,
324
+ ),
325
+ Quantity(
326
+ 'x_ams_bz_volume_total',
327
+ rf'Total volume\s+({re_float})',
328
+ dtype=np.float64,
329
+ ),
330
+ Quantity(
331
+ 'x_ams_bz_volume_irreducible',
332
+ rf'Irreducible.+\s+({re_float})',
333
+ dtype=np.float64,
334
+ ),
335
+ Quantity(
336
+ 'x_ams_bz_volume_numerical_integration',
337
+ rf'Numerical integration\s+({re_float})',
338
+ dtype=np.float64,
339
+ ),
340
+ Quantity('n_points', r'Total nr\. of K\-points\s+(\d+)'),
341
+ Quantity(
342
+ 'x_ams_n_points_unique',
343
+ r'Nr\. of symmetry unique points\s+(\d+)',
344
+ dtype=np.int32,
345
+ ),
346
+ Quantity(
347
+ 'x_ams_n_simplices',
348
+ r'Nr\. of simplices\s+(\d+)',
349
+ dtype=np.int32,
350
+ ),
351
+ Quantity(
352
+ 'x_ams_n_points_per_simplex',
353
+ r'Nr\. of points per simplex\s+(\d+)',
354
+ dtype=np.int32,
355
+ ),
356
+ Quantity(
357
+ 'points',
358
+ rf'No\. +Sym\..+\s+\-+((?:\d+ +\d+ +{re_float}.+\s+)+)',
359
+ str_operation=lambda x: np.transpose(
360
+ np.array(
361
+ [v.split() for v in x.strip().splitlines()],
362
+ np.float64,
363
+ )
364
+ )[2:5].T,
365
+ ),
366
+ ]
367
+ ),
368
+ ),
369
+ Quantity(
370
+ 'scf_options',
371
+ r'S\. C\. F\. O P T I O N S([\s\S]+?)\*\*',
372
+ sub_parser=TextParser(
373
+ quantities=[
374
+ Quantity(
375
+ 'x_ams_diis_settings_dirac',
376
+ r'DIIS settings info for DIRAC +\*\s+((?:[\w ]+? \w\S*\s+)+)',
377
+ str_operation=to_parameters,
378
+ ),
379
+ Quantity(
380
+ 'x_ams_diis_settings_scf',
381
+ r'DIIS settings info for SCF +\*\s+((?:[\w ]+? \w\S*\s+)+)',
382
+ str_operation=to_parameters,
383
+ ),
384
+ Quantity(
385
+ 'x_ams_growth_factor',
386
+ rf'growth factor\s*({re_float})',
387
+ dtype=np.float64,
388
+ ),
389
+ Quantity(
390
+ 'x_ams_shrink_factor',
391
+ rf'shrink factor\s*({re_float})',
392
+ dtype=np.float64,
393
+ ),
394
+ Quantity('x_ams_mix', rf'Mix\s*({re_float})', dtype=np.float64),
395
+ Quantity(
396
+ 'x_ams_degenerate',
397
+ r'Degenerate\s*(.)',
398
+ str_operation=lambda x: x == 'T',
399
+ ),
400
+ Quantity(
401
+ 'x_ams_edegen', rf'Edegen\s*({re_float})', dtype=np.float64
402
+ ),
403
+ Quantity(
404
+ 'x_ams_scfrtx', rf'SCFRTX\s*({re_float})', dtype=np.float64
405
+ ),
406
+ Quantity(
407
+ 'x_ams_convrg', rf'Convrg\s*({re_float})', dtype=np.float64
408
+ ),
409
+ Quantity('x_ams_ncyclx', r'Ncyclx\s*(\d+)', dtype=np.int32),
410
+ Quantity(
411
+ 'x_ams_vsplit', rf'Vsplit\s*({re_float})', dtype=np.float64
412
+ ),
413
+ ]
414
+ ),
415
+ ),
416
+ Quantity(
417
+ 'x_ams_dftb_resources_dir',
418
+ r'DFTB Resources dir\s*(.+)',
419
+ dtype=str,
420
+ flatten=False,
421
+ ),
422
+ Quantity(
423
+ 'x_ams_scc_convergence_enabled',
424
+ r'SCC convergence (\w+)',
425
+ str_operation=lambda x: x == 'enabled',
426
+ ),
427
+ Quantity(
428
+ 'x_ams_max_scc_cycles', r'Maximum SCC cycles \ſ*(\d+)', dtype=np.int32
429
+ ),
430
+ Quantity(
431
+ 'x_ams_scc_charge_convergence',
432
+ rf'SCC charge convergence\s*({re_float})',
433
+ dtype=np.float64,
434
+ ),
435
+ Quantity(
436
+ 'x_ams_scc_charge_mixing',
437
+ rf'SCC charge mixing\s*({re_float})',
438
+ dtype=np.float64,
439
+ ),
440
+ Quantity(
441
+ 'x_ams_diis_max_dimension',
442
+ r'DIIS max dimension\s*(\d+)',
443
+ dtype=np.int32,
444
+ ),
445
+ Quantity(
446
+ 'x_ams_diis_max_coeff',
447
+ rf'DIIS maximum coeff\.\s*({re_float})',
448
+ dtype=np.float64,
449
+ ),
450
+ Quantity(
451
+ 'x_ams_adaptive_scc_charge_mixing',
452
+ r'Adaptive SCC charge mixing\s*(.)',
453
+ str_operation=lambda x: x == 'T',
454
+ ),
455
+ Quantity(
456
+ 'x_ams_adaptive_scc_mixing_strategy',
457
+ r'Adaptive SCC mixing strategy\s*(\d+)',
458
+ dtype=np.int32,
459
+ ),
460
+ Quantity(
461
+ 'x_ams_spin_polarization',
462
+ r'Spin polarization\s*(.)',
463
+ str_operation=lambda x: x == 'T',
464
+ ),
465
+ Quantity(
466
+ 'x_ams_orbital_dependent_scc',
467
+ r'Orbital\-dependent SCC\s*(.)',
468
+ str_operation=lambda x: x == 'T',
469
+ ),
470
+ Quantity(
471
+ 'x_ams_orbital_fill_strategy',
472
+ r'Orbital fill strategy\s*(.+)',
473
+ dtype=str,
474
+ flatten=False,
475
+ ),
476
+ Quantity(
477
+ 'x_ams_fermi_temperature',
478
+ rf'Fermi temperature \(kelvin\)\s*({re_float})',
479
+ dtype=np.float64,
480
+ unit=ureg.kelvin,
481
+ ),
482
+ Quantity(
483
+ 'x_ams_use_symmetry',
484
+ r'Use of symmetry\s*(.)',
485
+ str_operation=lambda x: x == 'T',
486
+ ),
487
+ Quantity(
488
+ 'x_ams_radial_function_extrapolation_method',
489
+ r'Radial function extrapolation method\s*(.+)',
490
+ dtype=str,
491
+ flatten=False,
492
+ ),
493
+ Quantity(
494
+ 'x_ams_grimme_d3_dispersion_correction',
495
+ r'Settings for Grimme .+ dispersion correction\s+'
496
+ r'((?:\w+ +\S+\s+)+)',
497
+ str_operation=to_parameters,
498
+ ),
499
+ Quantity(
500
+ 'x_ams_other_parameters',
501
+ r'Other \(technical\) parameters\s+' r'((?:\w+ +\S+\s+)+)',
502
+ str_operation=to_parameters,
503
+ ),
504
+ Quantity(
505
+ 'x_ams_assume_insulator',
506
+ r'Assume insulator\s*(.)',
507
+ str_operation=lambda x: x == 'T',
508
+ ),
509
+ Quantity(
510
+ 'x_ams_ewald_tolerance',
511
+ rf'Ewald tolerance\s*({re_float})',
512
+ dtype=np.float64,
513
+ ),
514
+ Quantity(
515
+ 'x_ams_ewald_range_factor',
516
+ rf'Ewald range factor\s*({re_float})',
517
+ dtype=np.float64,
518
+ ),
519
+ Quantity(
520
+ 'x_ams_bzstruct_config',
521
+ r'BZStruct config\s*\-+\s*((?:\w+ ))',
522
+ str_operation=to_parameters,
523
+ ),
524
+ ]
525
+
526
+ calculation_quantities = (
527
+ system_quantities
528
+ + method_quantities
529
+ + [
530
+ Quantity(
531
+ 'total_charge',
532
+ rf'Total System Charge\s*({re_float})',
533
+ dtype=float,
534
+ unit=ureg.elementary_charge,
535
+ ),
536
+ Quantity(
537
+ 'atomic_charges',
538
+ rf'Index +Atom +Charge\s+((?:\d+ +\w+ +{re_float}\s+)+)',
539
+ str_operation=lambda x: [
540
+ v.strip().split()[-1] for v in x.strip().splitlines()
541
+ ],
542
+ ),
543
+ Quantity(
544
+ 'fermi_energy',
545
+ rf'Fermi Energy\:\s*({re_float})\s*a\.u\.',
546
+ dtype=float,
547
+ unit=ureg.hartree,
548
+ ),
549
+ Quantity(
550
+ 'energies',
551
+ r'E N E R G Y A N A L Y S I S([\s\S]+?)\={90}',
552
+ sub_parser=TextParser(
553
+ quantities=[
554
+ Quantity(
555
+ 'electronic_kinetic',
556
+ rf'Kinetic\s*({re_float})',
557
+ dtype=float,
558
+ unit=ureg.hartree,
559
+ ),
560
+ Quantity(
561
+ 'xc',
562
+ rf'XC\s*({re_float})',
563
+ dtype=float,
564
+ unit=ureg.hartree,
565
+ ),
566
+ Quantity(
567
+ 'electrostatic',
568
+ rf'Electrostatic\s*({re_float})',
569
+ dtype=float,
570
+ unit=ureg.hartree,
571
+ ),
572
+ Quantity(
573
+ 'x_ams_v_atomic_def',
574
+ rf'V\(atomic\)\*def\s*({re_float})',
575
+ dtype=float,
576
+ unit=ureg.hartree,
577
+ ),
578
+ Quantity(
579
+ 'x_ams_v_def_def',
580
+ rf'V\(def\)\*def\s*({re_float})',
581
+ dtype=float,
582
+ unit=ureg.hartree,
583
+ ),
584
+ Quantity(
585
+ 'x_ams_dispersion',
586
+ rf'Dispersion\s*({re_float})',
587
+ dtype=float,
588
+ unit=ureg.hartree,
589
+ ),
590
+ Quantity(
591
+ 'total',
592
+ rf'Final bond energy \(.+\)\s*({re_float})',
593
+ dtype=float,
594
+ unit=ureg.hartree,
595
+ ),
596
+ Quantity(
597
+ 'x_ams_fit_error_correction',
598
+ rf'Fit error correction.+?\s*({re_float})',
599
+ dtype=float,
600
+ unit=ureg.hartree,
601
+ ),
602
+ ]
603
+ ),
604
+ ),
605
+ Quantity(
606
+ 'energies',
607
+ r'(Energy Decomposition\s+\-+[\s\S]+?)\-{10}',
608
+ sub_parser=TextParser(
609
+ quantities=[
610
+ Quantity(
611
+ 'total',
612
+ rf'Total Energy \(hartree\)\s*({re_float})',
613
+ dtype=float,
614
+ unit=ureg.hartree,
615
+ ),
616
+ Quantity(
617
+ 'electronic',
618
+ rf'Electronic Energy \(hartree\)\s*({re_float})',
619
+ dtype=float,
620
+ unit=ureg.hartree,
621
+ ),
622
+ Quantity(
623
+ 'electrostatic',
624
+ rf'Coulomb Energy \(hartree\)\s*({re_float})',
625
+ dtype=float,
626
+ unit=ureg.hartree,
627
+ ),
628
+ Quantity(
629
+ 'nuclear_repulsion',
630
+ rf'Repulsion Energy \(hartree\)\s*({re_float})',
631
+ dtype=float,
632
+ unit=ureg.hartree,
633
+ ),
634
+ Quantity(
635
+ 'x_ams_dispersion',
636
+ rf'Dispersion Energy \(hartree\)\s*({re_float})',
637
+ dtype=float,
638
+ unit=ureg.hartree,
639
+ ),
640
+ ]
641
+ ),
642
+ ),
643
+ Quantity(
644
+ 'forces',
645
+ rf'(E N E R G Y +G R A D I E N T S\s+\=+[\s\S]+?FINAL[\s\S]+?){re_n} *{re_n}',
646
+ sub_parser=TextParser(
647
+ quantities=[
648
+ Quantity(
649
+ 'p_matrix',
650
+ rf'P Matrix\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
651
+ str_operation=str_to_forces,
652
+ ),
653
+ Quantity(
654
+ 'electronic_kinetic',
655
+ rf'Kinetic energy\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
656
+ str_operation=str_to_forces,
657
+ ),
658
+ Quantity(
659
+ 'xc',
660
+ rf'XC energy\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
661
+ str_operation=str_to_forces,
662
+ ),
663
+ Quantity(
664
+ 'electrostatic',
665
+ rf'Electrostatic energy\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
666
+ str_operation=str_to_forces,
667
+ ),
668
+ Quantity(
669
+ 'pair_interactions',
670
+ rf'Pair interactions\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
671
+ str_operation=str_to_forces,
672
+ ),
673
+ Quantity(
674
+ 'dispersion',
675
+ rf'Dispersion\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
676
+ str_operation=str_to_forces,
677
+ ),
678
+ Quantity(
679
+ 'total',
680
+ rf'FINAL GRADIENTS\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
681
+ str_operation=str_to_forces,
682
+ ),
683
+ ]
684
+ ),
685
+ ),
686
+ Quantity(
687
+ 'forces',
688
+ r'Gradient Decomposition\s+\-+([\s\S]+?)\-{10}',
689
+ sub_parser=TextParser(
690
+ quantities=[
691
+ Quantity(
692
+ 'total',
693
+ rf'Total Gradients \(hartree/bohr\)\s+Index.+\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
694
+ str_operation=str_to_forces,
695
+ ),
696
+ Quantity(
697
+ 'electronic',
698
+ rf'Electronic Gradients \(hartree/bohr\)\s+Index.+\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
699
+ str_operation=str_to_forces,
700
+ ),
701
+ Quantity(
702
+ 'electrostatic',
703
+ rf'Coulomb Gradients \(hartree/bohr\)\s+Index.+\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
704
+ str_operation=str_to_forces,
705
+ ),
706
+ Quantity(
707
+ 'nuclear_repulsion',
708
+ rf'Repulsion Gradients \(hartree/bohr\)\s+Index.+\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
709
+ str_operation=str_to_forces,
710
+ ),
711
+ Quantity(
712
+ 'dispersion',
713
+ rf'Dispersion Gradients \(hartree/bohr\)\s+Index.+\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
714
+ str_operation=str_to_forces,
715
+ ),
716
+ ]
717
+ ),
718
+ ),
719
+ Quantity(
720
+ 'energy_total',
721
+ rf'Energy\s*\(hartree\)\s*({re_float})',
722
+ dtype=float,
723
+ unit=ureg.hartree,
724
+ ),
725
+ Quantity(
726
+ 'energy_total',
727
+ rf'current energy +({re_float}) +Hartree',
728
+ dtype=float,
729
+ unit=ureg.hartree,
730
+ ),
731
+ Quantity(
732
+ 'forces_total',
733
+ rf'Gradients \(hartree/bohr\)\s+Index.+\s+((?:\d+ +[A-Z][a-z]* +{re_float} +{re_float} +{re_float}\s+)+)',
734
+ str_operation=str_to_forces,
735
+ ),
736
+ Quantity(
737
+ 'self_consistency',
738
+ r'S C F P R O C E D U R E\s*\*\s*\*+\s*([\s\S]+?Self consistent error.+)',
739
+ sub_parser=TextParser(
740
+ quantities=[
741
+ Quantity(
742
+ 'energy_change',
743
+ rf'cyc\=\s*\d+\s*err\=\s*({re_float})',
744
+ repeats=True,
745
+ dtype=float,
746
+ unit=ureg.hartree,
747
+ )
748
+ ]
749
+ ),
750
+ ),
751
+ Quantity(
752
+ 'total_dos',
753
+ r'TOTALDOS([\s\S]+?)ENDINPUT',
754
+ sub_parser=TextParser(
755
+ quantities=[
756
+ Quantity(
757
+ 'nspin_ne',
758
+ r'NSPIN,NE= *(\d+) +(\d+)',
759
+ dtype=np.dtype(np.int32),
760
+ ),
761
+ Quantity(
762
+ 'dos',
763
+ rf'\n *({re_float}) *({re_float}) *({re_float})*',
764
+ dtype=np.dtype(np.float64),
765
+ repeats=True,
766
+ ),
767
+ ]
768
+ ),
769
+ ),
770
+ Quantity(
771
+ 'mulliken_populations',
772
+ r'M U L L I K E N P O P U L A T I O N S\s+\=+([\s\S]+?)\={10}',
773
+ sub_parser=TextParser(
774
+ quantities=[
775
+ Quantity(
776
+ 'orbital',
777
+ rf'(\d+/[A-Z].+?{re_float}[\s\S]+?)\-\-',
778
+ repeats=True,
779
+ str_operation=to_mulliken_populations,
780
+ ),
781
+ Quantity(
782
+ 'atom',
783
+ rf'Charge on atom\s+({re_float}.+)',
784
+ repeats=True,
785
+ str_operation=lambda x: x.strip().split(),
786
+ dtype=np.dtype(np.float64),
787
+ ),
788
+ ]
789
+ ),
790
+ ),
791
+ Quantity(
792
+ 'mulliken_populations',
793
+ rf'(Mulliken Charges\s+\-+[\s\S]+?Total.+)',
794
+ sub_parser=TextParser(
795
+ quantities=[
796
+ Quantity(
797
+ 'atom',
798
+ rf'Index +Atom +Charge.+\s+((?:\d+ +\w+ +{re_float} +{re_float}\s+)+)',
799
+ # shape should be (nspin, natoms)
800
+ str_operation=lambda x: np.array(
801
+ [
802
+ v.strip().split()[2:3]
803
+ for v in x.strip().splitlines()
804
+ ],
805
+ np.float64,
806
+ ),
807
+ convert=False,
808
+ ),
809
+ Quantity(
810
+ 'total',
811
+ rf'Total\s+({re_float})',
812
+ dtype=np.float64,
813
+ unit=ureg.elementary_charge,
814
+ ),
815
+ ]
816
+ ),
817
+ ),
818
+ Quantity(
819
+ 'atom_charge_analysis',
820
+ r'(Atomic Charge Analysis.*\s*\=+[\s\S]+?)\={10}',
821
+ repeats=True,
822
+ sub_parser=TextParser(
823
+ quantities=[
824
+ Quantity(
825
+ 'spin',
826
+ r'(Spin Up \- Spin Down)',
827
+ str_operation=lambda x: True,
828
+ ),
829
+ Quantity(
830
+ 'methods',
831
+ r'Atom +([\w ]+)',
832
+ ),
833
+ Quantity(
834
+ 'atom_charges',
835
+ rf'((?:\d+ +\w+ +{re_float}.+\s+)+)',
836
+ str_operation=lambda x: np.transpose(
837
+ [v.strip().split() for v in x.strip().splitlines()]
838
+ )[2:],
839
+ dtype=np.dtype(np.float64),
840
+ ),
841
+ Quantity(
842
+ 'total',
843
+ rf'Total: +({re_float}.+)',
844
+ dtype=np.dtype(np.float64),
845
+ ),
846
+ ]
847
+ ),
848
+ ),
849
+ Quantity(
850
+ 'dipole_moment',
851
+ rf'direction +dipole.+\s+\=+\s+((?:\w+ +{re_float}.+\s+)+)',
852
+ str_operation=lambda x: (
853
+ [float(v.strip().split()[2]) for v in x.strip().splitlines()]
854
+ * ureg.debye
855
+ )
856
+ .to('C * m')
857
+ .magnitude,
858
+ ),
859
+ Quantity(
860
+ 'band_energy_ranges',
861
+ rf'\=+\s+band +min.+\s+\=+\s+((?:\d+ +{re_float}.+\s+)+)',
862
+ str_operation=to_band_energy_ranges,
863
+ ),
864
+ Quantity(
865
+ 'band_gap_info',
866
+ rf'Band gap information\s+\-([\s\S]+?){re_n} *{re_n}',
867
+ sub_parser=TextParser(
868
+ quantities=[
869
+ Quantity(
870
+ 'x_ams_n_valence_electrons',
871
+ r'Number of valence electrons\s+(\d+)',
872
+ dtype=np.int32,
873
+ ),
874
+ Quantity(
875
+ 'x_ams_valence_band_index',
876
+ r'Valence band index\s+(\d+)',
877
+ dtype=np.int32,
878
+ ),
879
+ Quantity(
880
+ 'x_ams_valence_band_spin_index',
881
+ r'Valence band spin index\s+(\d+)',
882
+ dtype=np.int32,
883
+ ),
884
+ Quantity(
885
+ 'x_ams_conduction_band_index',
886
+ r'Conduction band index\s+(\d+)',
887
+ dtype=np.int32,
888
+ ),
889
+ Quantity(
890
+ 'x_ams_conduction_band_spin_index',
891
+ r'Conduction band spin index\s+(\d+)',
892
+ dtype=np.int32,
893
+ ),
894
+ Quantity(
895
+ 'energy_highest_occupied',
896
+ rf'Top of valence band \(a\.u\.\)\s+({re_float})',
897
+ dtype=np.float64,
898
+ unit=ureg.hartree,
899
+ ),
900
+ Quantity(
901
+ 'energy_lowest_unoccupied',
902
+ rf'Bottom of conduction band \(a\.u\.\)\s+({re_float})',
903
+ dtype=np.float64,
904
+ unit=ureg.hartree,
905
+ ),
906
+ Quantity(
907
+ 'value',
908
+ rf'Band gap \(a\.u\.\)\s+({re_float})',
909
+ dtype=np.float64,
910
+ unit=ureg.hartree,
911
+ ),
912
+ ]
913
+ ),
914
+ ),
915
+ ]
916
+ )
917
+
918
+ self._quantities = [
919
+ Quantity(
920
+ 'program_version', r'\*\s*r(\d+ \d{4}\-\d\d\-\d\d)', flatten=False
921
+ ),
922
+ Quantity(
923
+ 'time_start',
924
+ r'RunTime\:\s*(\w{3}\d+\-\d{4}\s*\d+\:\d+\:\d+)',
925
+ str_operation=lambda x: (
926
+ datetime.strptime(x, '%b%d-%Y %H:%M:%S') - datetime(1970, 1, 1)
927
+ ).total_seconds(),
928
+ ),
929
+ Quantity(
930
+ 'single_point',
931
+ r'SINGLE POINT CALCULATION \*([\s\S]+?)(:?Timing|\Z)',
932
+ sub_parser=TextParser(quantities=calculation_quantities),
933
+ ),
934
+ Quantity(
935
+ 'geometry_optimization',
936
+ r'GEOMETRY OPTIMIZATION\s*\*([\s\S]+?)(:?Timing|Performing a single pooint|\Z)',
937
+ sub_parser=TextParser(
938
+ quantities=system_quantities
939
+ + method_quantities
940
+ + [
941
+ Quantity(
942
+ 'step',
943
+ r'Geometry Convergence after Step\s*([\s\S]+?(?:dE\(predicted\)\:.+|\Z))',
944
+ repeats=True,
945
+ sub_parser=TextParser(quantities=calculation_quantities),
946
+ ),
947
+ Quantity(
948
+ 'method', r'Optimization Method\s*(.+)', flatten=False
949
+ ),
950
+ Quantity(
951
+ 'x_ams_optimization_coordinates',
952
+ r'Optimization Coordinates +(.+)',
953
+ type=str,
954
+ flatten=False,
955
+ ),
956
+ Quantity(
957
+ 'x_ams_optimize_lattice',
958
+ r'Optimize lattice +(.)',
959
+ str_operation=lambda x: x == 'T',
960
+ ),
961
+ Quantity(
962
+ 'convergence_tolerance_force_maximum',
963
+ rf'Maximum gradient\s*({re_float})',
964
+ dtype=float,
965
+ unit=ureg.hartree / ureg.bohr,
966
+ ),
967
+ Quantity(
968
+ 'x_ams_maximum_rms_gradient',
969
+ rf'Maximum rms gradient\s*({re_float})',
970
+ dtype=np.float64,
971
+ ),
972
+ Quantity(
973
+ 'convergence_tolerance_energy_difference',
974
+ rf'Maximum energy change allowe\s*({re_float})',
975
+ dtype=float,
976
+ unit=ureg.hartree,
977
+ ),
978
+ Quantity(
979
+ 'convergence_tolerance_displacement_maximum',
980
+ rf'Maximum step allowed\s*({re_float})',
981
+ dtype=float,
982
+ unit=ureg.bohr,
983
+ ),
984
+ Quantity(
985
+ 'x_ams_maximum_rms_step_allowed',
986
+ rf'Maximum rms step allowed\s*({re_float})',
987
+ dtype=np.float64,
988
+ ),
989
+ Quantity(
990
+ 'x_ams_maximum_stress_energy_allowed',
991
+ rf'Maximum stress energy allowe\s*({re_float})',
992
+ dtype=np.float64,
993
+ ),
994
+ Quantity(
995
+ 'x_ams_initial_model_hessian',
996
+ r'Initial model Hessian\s*(.+)',
997
+ dtype=str,
998
+ flatten=False,
999
+ ),
1000
+ Quantity(
1001
+ 'x_ams_hessian_update_method',
1002
+ r'Hessian Update Method\s*(.+)',
1003
+ dtype=str,
1004
+ flatten=False,
1005
+ ),
1006
+ Quantity(
1007
+ 'optimization_steps_maximum',
1008
+ r'Maximum number of steps\s*(\d+)',
1009
+ ),
1010
+ Quantity(
1011
+ 'x_ams_first_gdiis_cycle',
1012
+ r'First GDIIS cycle\s*(\d+)',
1013
+ dtype=np.int32,
1014
+ ),
1015
+ Quantity(
1016
+ 'x_ams_maximum_gdiis_vectors',
1017
+ r'Maximum GDIIS vectors\s*(\d+)',
1018
+ dtype=np.int32,
1019
+ ),
1020
+ Quantity(
1021
+ 'x_ams_trust_radius',
1022
+ rf'Trust radius \(bohr\)\s*({re_float})',
1023
+ dtype=np.float64,
1024
+ unit=ureg.bohr,
1025
+ ),
1026
+ Quantity(
1027
+ 'x_ams_trust_radius_varies',
1028
+ r'Trust radius varies\s*(.)',
1029
+ str_operation=lambda x: x == 'T',
1030
+ ),
1031
+ Quantity(
1032
+ 'x_ams_constraints_converged_at_all_steps',
1033
+ r'Constraints converged at all steps\s*(.)',
1034
+ str_operation=lambda x: x == 'T',
1035
+ ),
1036
+ Quantity(
1037
+ 'x_ams_use_projector',
1038
+ r'Use projector\s*(.)',
1039
+ str_operation=lambda x: x == 'T',
1040
+ ),
1041
+ Quantity(
1042
+ 'x_ams_symmetrize_steps',
1043
+ r'Symmetrize steps\s*(.)',
1044
+ str_operation=lambda x: x == 'T',
1045
+ ),
1046
+ ]
1047
+ ),
1048
+ ),
1049
+ Quantity(
1050
+ 'calculation_results',
1051
+ r'(CALCULATION RESULTS[\s\S]+?)(?:finished|\Z)',
1052
+ sub_parser=TextParser(quantities=calculation_quantities + []),
1053
+ ),
1054
+ # TODO add other calculation types
1055
+ ]
1056
+
1057
+
1058
+ class RKFParser(FileParser):
1059
+ def __init__(self, mainfile=None, logger=None, open=None):
1060
+ super().__init__(mainfile, logger, open)
1061
+ self._energies_map = {
1062
+ 'Bond Energy': 'x_ams_bond',
1063
+ 'Corr. due to Orthogonalization': 'x_ams_orthogonalization',
1064
+ 'Dispersion Energy': 'x_ams_dispersion',
1065
+ 'Ebond due to Efield': 'x_ams_bond_efield',
1066
+ 'Electrostatic Energy': 'electrostatic',
1067
+ 'Kinetic Energy': 'kinetic',
1068
+ 'MP2 energy': 'x_ams_mp2',
1069
+ 'Orb.Int. A': 'x_ams_orbital_interaction_a',
1070
+ 'Orb.Int. Efield': 'x_ams_orbital_interaction_efield',
1071
+ 'Orb.Int. FitCorrection': 'x_ams_orbital_interaction_fit_correction',
1072
+ 'Orb.Int. TSCorrection (LDA)': 'x_ams_orbital_interaction_ts_correction_lda',
1073
+ 'Orb.Int. TSCorrection (NL)': 'x_ams_orbital_interaction_ts_correction_nl',
1074
+ 'Orb.Int. Total': 'x_ams_orbital_interaction',
1075
+ 'Pauli Coulomb': 'x_ams_pauli_coulomb',
1076
+ 'Pauli Efield': 'x_ams_pauli_efield',
1077
+ 'Pauli FitCorrection': 'x_ams_pauli_fit_correction',
1078
+ 'Pauli Kinetic': 'x_ams_pauli_kinetic',
1079
+ 'Pauli Kinetic+Coulomb': 'x_ams_pauli_kinetic_coulomb',
1080
+ 'Pauli TS Correction (LDA)': 'x_ams_pauli_ts_correction_lda',
1081
+ 'Pauli Total': 'x_ams_pauli',
1082
+ 'RPA energy': 'x_ams_rpa',
1083
+ 'SCF Bond Energy': 'x_ams_bond',
1084
+ 'SumFragmentsSCF FitCorrection': 'x_ams_sum_fragments_scf_fit_correction',
1085
+ 'XC Energy': 'xc',
1086
+ # 'XC energies': 'xc_values_per_atom'
1087
+ }
1088
+ # TODO verfiy list
1089
+ self._ldapot = {1: 'VWN', 2: 'Stoll', 3: 'PW92'}
1090
+
1091
+ @property
1092
+ def data(self):
1093
+ if self._file_handler is None:
1094
+ try:
1095
+ self._file_handler = rkf_to_dict(self.mainfile)
1096
+ except Exception:
1097
+ self.logger.error('Error reading rkf file')
1098
+ return self._file_handler
1099
+
1100
+ def parse(self, key=None):
1101
+ if self.data is None:
1102
+ return
1103
+
1104
+ if self._results is None:
1105
+ self._results = {}
1106
+
1107
+ general = self.data.get('General', {})
1108
+ # TODO determine if program version is same as release, formatting required
1109
+ # for compatibility with text output
1110
+ self._results['program_version'] = (
1111
+ general.get('release', '').replace('(', '').replace(')', '').split('r')[-1]
1112
+ )
1113
+ self._results['program_x_ams_name'] = general.get('program')
1114
+ self._results['program_x_ams_engine'] = general.get('engine')
1115
+
1116
+ nspin = general.get('nspin', 1)
1117
+ xc_functional = {}
1118
+ if (ldapot := general.get('ldapot')) is not None:
1119
+ xc_functional['LDA'] = self._ldapot.get(ldapot)
1120
+ if ggapot := general.get('ggapot', '').strip():
1121
+ xc_functional['GGA'] = ggapot
1122
+ if mgga := general.get('MetaGGAConfig', {}).get('metagga', '').strip():
1123
+ xc_functional['MGGA'] = mgga
1124
+ # TODO parse hybrid, hf
1125
+ self._results['model_parameters'] = {
1126
+ 'spin': nspin > 1,
1127
+ 'dft_potential': xc_functional,
1128
+ }
1129
+
1130
+ k_space_sampling = {}
1131
+ if (kspace := self.data.get('kspace')) is not None:
1132
+ k_space_sampling['x_ams_n_simplices'] = kspace.get('nsimpl')
1133
+ k_space_sampling['x_ams_n_points_unique'] = kspace.get('kuniqu')
1134
+ self._results['k_space_sampling'] = k_space_sampling
1135
+
1136
+ if (kpoints_config := self.data.get('KPointsConfig')) is not None:
1137
+ k_space_sampling['x_ams_general_integration_parameter'] = (
1138
+ kpoints_config.get('interpolation')
1139
+ )
1140
+ k_space_sampling['grid'] = kpoints_config.get('parameters')
1141
+
1142
+ engine_results = self.data.get('EngineResults', {})
1143
+
1144
+ files = [val for key, val in engine_results.items() if key.startswith('Files')]
1145
+ warning = None
1146
+ for n, name in enumerate(files):
1147
+ rkf_files = get_files(name, self.mainfile)
1148
+ if not rkf_files:
1149
+ warning = 'rkf file not found in directory.'
1150
+ files[n] = None
1151
+ continue
1152
+ if len(rkf_files) > 1:
1153
+ warning = 'Multiple rkf files found in directory'
1154
+ files[n] = rkf_files[0]
1155
+ if warning:
1156
+ self.logger.warning(warning)
1157
+
1158
+ labels = []
1159
+ if (molecule := self.data.get('Molecule')) is not None:
1160
+ labels = [chemical_symbols[n] for n in molecule.get('AtomicNumbers', [])]
1161
+ if not labels:
1162
+ labels = molecule.get('AtomSmbols').split()
1163
+ positions = molecule.get('Coords', [])
1164
+ try:
1165
+ positions = np.reshape(positions, (len(labels), 3)) * ureg.bohr
1166
+ except Exception:
1167
+ self.logger.warning('Cannot read atom positions.')
1168
+ self._results['labels_positions'] = [labels, positions]
1169
+ if (lattice_vectors := molecule.get('LatticeVectors')) is not None:
1170
+ self._results['lattice_vectors'] = (
1171
+ np.reshape(lattice_vectors, (3, 3)) * ureg.bohr
1172
+ )
1173
+
1174
+ calc_type = None
1175
+ calc_results = {}
1176
+
1177
+ if (amsresults := self.data.get('AMSResults')) is not None:
1178
+ if (charges := amsresults.get('Charges')) is not None:
1179
+ self._results['atomic_charges'] = amsresults.get('Charges')
1180
+ if (dipole := amsresults.get('DipoleMoment')) is not None:
1181
+ dipole = np.sqrt(np.sum(np.array(dipole) ** 2))
1182
+ self._results['dipole_moment'] = (
1183
+ ([dipole] * ureg.elementary_charge * ureg.bohr)
1184
+ .to('C * m')
1185
+ .magnitude
1186
+ )
1187
+ if (energy := amsresults.get('Energy')) is not None:
1188
+ self._results['energy_total'] = energy * ureg.hartree
1189
+ if (gradients := amsresults.get('Gradients')) is not None:
1190
+ self._results['forces_total'] = (
1191
+ np.reshape(gradients, (len(labels), 3)) * ureg.hartree / ureg.bohr
1192
+ )
1193
+ if (hessian := amsresults.get('Hessian')) is not None:
1194
+ hessian = np.reshape(hessian, (len(labels), 3, len(labels), 3))
1195
+ self._results['hessian_matrix'] = (
1196
+ (
1197
+ np.transpose(hessian, axes=(0, 2, 1, 3))
1198
+ * ureg.hartree
1199
+ / ureg.bohr**2
1200
+ )
1201
+ .to('J / m ** 2')
1202
+ .magnitude
1203
+ )
1204
+
1205
+ if (history := self.data.get('History')) is not None:
1206
+ calc_type = 'geometry_optimization'
1207
+ n_entries = history.get('nEntries', 0)
1208
+ calc_results['step'] = [None] * n_entries
1209
+ for n in range(n_entries):
1210
+ positions = history.get(f'Coords({n + 1})')
1211
+ if positions is not None:
1212
+ positions = np.reshape(positions, (len(labels), 3)) * ureg.bohr
1213
+ calc_results['step'][n] = {'labels_positions': [labels, positions]}
1214
+ if (energy_total := history.get(f'Energy({n + 1})')) is not None:
1215
+ calc_results['step'][n]['energy_total'] = (
1216
+ energy_total * ureg.hartree
1217
+ )
1218
+
1219
+ if (mdhistory := self.data.get('MDHistory')) is not None:
1220
+ calc_type = 'molecular_dynamics'
1221
+ n_entries = mdhistory.get('nEntries', 0)
1222
+ if len(calc_results.get('step', [])) != n_entries:
1223
+ self.logger.warning('Inconsistent number of entries in history.')
1224
+ else:
1225
+ block_size = mdhistory.get('blockSize', 1)
1226
+ for n in range(n_entries):
1227
+ calc_results['step'][n]['atomic_charges'] = mdhistory.get(
1228
+ f'Charges({n + 1})'
1229
+ )
1230
+ energies = {}
1231
+ nblock = (n // block_size) + 1
1232
+ ndata = n % block_size
1233
+ if (total := mdhistory.get(f'TotalEnergy({nblock})')) is not None:
1234
+ energies['total'] = (
1235
+ total if isinstance(total, float) else total[ndata]
1236
+ ) * ureg.hartree
1237
+ if (
1238
+ kinetic := mdhistory.get(f'KineticEnergy({nblock})')
1239
+ ) is not None:
1240
+ energies['total_kinetic'] = (
1241
+ kinetic if isinstance(kinetic, float) else kinetic[ndata]
1242
+ ) * ureg.hartree
1243
+ if (
1244
+ potential := mdhistory.get(f'PotentialEnergy({nblock})')
1245
+ ) is not None:
1246
+ energies['total_potential'] = (
1247
+ potential
1248
+ if isinstance(potential, float)
1249
+ else potential[ndata]
1250
+ ) * ureg.hartree
1251
+ calc_results['step'][n]['energies'] = energies
1252
+ if (step := mdhistory.get(f'Step({nblock})')) is not None:
1253
+ calc_results['step'][n]['step'] = (
1254
+ step if isinstance(step, int) else step[ndata]
1255
+ )
1256
+ if (time := mdhistory.get(f'Time({nblock})')) is not None:
1257
+ calc_results['step'][n]['time'] = (
1258
+ time if isinstance(time, float) else time[ndata]
1259
+ ) * ureg.fs
1260
+ if (
1261
+ temperature := mdhistory.get(f'Temperature({nblock})')
1262
+ ) is not None:
1263
+ calc_results['step'][n]['temperature'] = (
1264
+ temperature
1265
+ if isinstance(temperature, float)
1266
+ else temperature[ndata]
1267
+ ) * ureg.kelvin
1268
+ if (
1269
+ velocities := mdhistory.get(f'Velocities({n + 1})')
1270
+ ) is not None:
1271
+ calc_results['step'][n]['velocities'] = (
1272
+ np.reshape(velocities, (len(labels), 3))
1273
+ * ureg.bohr
1274
+ / ureg.fs
1275
+ )
1276
+
1277
+ if history is None and files:
1278
+ if len(files) != 1:
1279
+ self.logger.warning('Inconsistent number of rkf files found.')
1280
+ calc_type = 'single_point'
1281
+ calc_results = RKFParser(mainfile=files[0] if files else None).parse()
1282
+
1283
+ elif history:
1284
+ # pass
1285
+ if len(files) == 1:
1286
+ calc_results['step'][-1] = RKFParser(mainfile=files[0]).parse()
1287
+ elif len(files) == n_entries:
1288
+ for n, name in enumerate(files):
1289
+ calc_results['step'][n] = RKFParser(mainfile=name).parse()
1290
+ else:
1291
+ self.logger.warning('Inconsistent number of rkf files found.')
1292
+
1293
+ if calc_type is not None:
1294
+ self._results[calc_type] = calc_results
1295
+
1296
+ if (energy := self.data.get('Energy')) is not None:
1297
+ self._results['energies'] = {}
1298
+ for ams_key, nomad_key in self._energies_map.items():
1299
+ val = energy.get(ams_key)
1300
+ if val is not None:
1301
+ self._results['energies'][nomad_key] = val * ureg.hartree
1302
+
1303
+ if (geometry := self.data.get('geometry')) is not None:
1304
+ if (lattice_vectors := geometry.get('standard_lattice')) is not None:
1305
+ self._results['lattice_vectors'] = (
1306
+ np.reshape(lattice_vectors, (3, 3)) * ureg.bohr
1307
+ )
1308
+
1309
+ if (properties := self.data.get('Properties')) is not None:
1310
+ if (mulliken := properties.get('AtomCharge Mulliken')) is not None:
1311
+ self._results['mulliken_populations'] = {
1312
+ 'atom': np.reshape(mulliken, (len(mulliken) // nspin, nspin))
1313
+ }
1314
+
1315
+ if (fermi := properties.get('FermiLevel')) is not None:
1316
+ self._results['fermi_energy'] = fermi * ureg.hartree
1317
+
1318
+ if (dipole := properties.get('Dipole')) is not None:
1319
+ dipole = np.sqrt(np.sum(np.array(dipole) ** 2))
1320
+ self._results['dipole_moment'] = (
1321
+ ([dipole] * ureg.elementary_charge * ureg.bohr)
1322
+ .to('C * m')
1323
+ .magnitude
1324
+ )
1325
+
1326
+ self._results['atomic_charges'] = charges
1327
+
1328
+ self._results['band_gap'] = {}
1329
+ if (homo := properties.get('HOMO')) is not None:
1330
+ self._results['band_gap']['energy_highest_occupied'] = (
1331
+ homo * ureg.hartree
1332
+ )
1333
+ if (lumo := properties.get('LUMO')) is not None:
1334
+ self._results['band_gap']['energy_lowest_unoccupied'] = (
1335
+ lumo * ureg.hartree
1336
+ )
1337
+
1338
+ # TODO parse other quantities
1339
+
1340
+ if (properties := self.data.get('Scalar Atomic Properties')) is not None:
1341
+ if (mulliken := properties.get('Mulliken Charges')) is not None:
1342
+ self._results['mulliken_populations'] = {
1343
+ 'atom': np.reshape(mulliken, (len(mulliken) // nspin, nspin))
1344
+ }
1345
+
1346
+ if (dos := self.data.get('DOS')) is not None:
1347
+ if np.ndim(dos.get('Energies')) > 0:
1348
+ self._results['total_dos'] = {
1349
+ 'dos': np.transpose(
1350
+ [
1351
+ dos.get('Energies'),
1352
+ *np.reshape(
1353
+ dos.get('Total DOS', []),
1354
+ (dos.get('nSpin', 0), dos.get('nEnergies', 0)),
1355
+ ),
1356
+ ]
1357
+ )
1358
+ }
1359
+
1360
+ eigensystem = self.data.get('eigensystem', {})
1361
+ if eigensystem is not None:
1362
+ eigenvalues = {}
1363
+ if (eigval := eigensystem.get('eigval')) is not None:
1364
+ nspin = eigensystem.get('nspin', 1)
1365
+ nband = eigensystem.get('nband', 0)
1366
+ # TODO check if shape is correct
1367
+ eigenvalues['energies'] = (
1368
+ np.reshape(eigval, (nspin, len(eigval) // (nband * nspin), nband))
1369
+ * ureg.hartree
1370
+ )
1371
+ occupations = eigensystem.get('occupationPerBandAndSpin')
1372
+ if occupations is not None:
1373
+ # TODO check if occ shape is correct
1374
+ eigenvalues['occupations'] = np.reshape(
1375
+ occupations,
1376
+ (nspin, np.size(occupations) // (nband * nspin), nband),
1377
+ )
1378
+ self._results['eigenvalues'] = eigenvalues
1379
+
1380
+ if (band_structure := self.data.get('BandStructure')) is not None:
1381
+ if (energy_ranges := band_structure.get('bandsEnergyRange')) is not None:
1382
+ # TODO check if shape is correct
1383
+ nband = band_structure.get('nBand')
1384
+ nspin = band_structure.get('nSpin')
1385
+ energy_ranges = np.transpose(
1386
+ np.reshape(energy_ranges, (nband, nspin, 2))
1387
+ )
1388
+ occupations = self._results.get('eigenvalues', {}).get('occupations')
1389
+ self._results['band_energy_ranges'] = [*energy_ranges, occupations]
1390
+ band_gap = {}
1391
+ if (value := band_structure.get('BandGap')) is not None:
1392
+ band_gap['value'] = value * ureg.hartree
1393
+ if (top_valence_band := band_structure.get('TopValenceBand')) is not None:
1394
+ band_gap['energy_highest_occupied'] = top_valence_band * ureg.hartree
1395
+ if (
1396
+ bottom_conduction_band := band_structure.get('BottomConductionBand')
1397
+ ) is not None:
1398
+ band_gap['energy_lowest_unoccupied'] = (
1399
+ bottom_conduction_band * ureg.hartree
1400
+ )
1401
+ self._results['band_gap'] = band_gap
1402
+
1403
+ if (geoopt := self.data.get('GeoOpt')) is not None:
1404
+ if (gradients := geoopt.get('Gradients_CART')) is not None:
1405
+ self._results['forces_total'] = (
1406
+ np.reshape(gradients, (len(labels), 3)) * ureg.hartree / ureg.bohr
1407
+ )
1408
+ if (hessian := geoopt.get('Hessian_CART')) is not None:
1409
+ hessian = np.reshape(hessian, (len(labels), 3, len(labels), 3))
1410
+ self._results['hessian_matrix'] = (
1411
+ (
1412
+ np.transpose(hessian, axes=(0, 2, 1, 3))
1413
+ * ureg.hartree
1414
+ / ureg.bohr**2
1415
+ )
1416
+ .to('J / m ** 2')
1417
+ .magnitude
1418
+ )
1419
+ # TODO parse Themodynamics, Vibrations, phonons
1420
+
1421
+ self.close()
1422
+ return self
1423
+
1424
+ def keys(self):
1425
+ return self.results.keys()
1426
+
1427
+
1428
+ class AMSParser:
1429
+ def __init__(self):
1430
+ self.out_parser = OutParser()
1431
+ self.rkf_parser = RKFParser()
1432
+ self._relativity_map = {
1433
+ 'scalar (ZORA,APA)': 'scalar_relativistic_atomic_ZORA',
1434
+ '---': None,
1435
+ }
1436
+
1437
+ def init_parser(self):
1438
+ self.out_parser.mainfile = self.mainfile
1439
+ self.out_parser.logger = self.logger
1440
+ self.rkf_parser.logger = self.logger
1441
+ self.parser = self.out_parser
1442
+
1443
+ def parse_configurations(self):
1444
+ sec_run = self.archive.run[0]
1445
+
1446
+ def parse_scc(source, target=None):
1447
+ sec_scc = Calculation()
1448
+ sec_run.calculation.append(sec_scc) if target is None else target
1449
+
1450
+ # total energy
1451
+ sec_energy = Energy()
1452
+ sec_scc.energy = sec_energy
1453
+ if source.get('energy_total') is not None:
1454
+ sec_energy.total = EnergyEntry(value=source.get('energy_total'))
1455
+
1456
+ # fermi energy
1457
+ sec_energy.fermi = source.get('fermi_energy')
1458
+
1459
+ # energy contributions
1460
+ for key, val in source.get('energies', dict()).items():
1461
+ if key == 'electronic_kinetic':
1462
+ sec_energy.electronic = EnergyEntry(kinetic=val)
1463
+ elif match := re.match(
1464
+ r'(\w+)_((?:kinetic|potential|values_per_atom))', key
1465
+ ):
1466
+ entry = getattr(sec_energy, match.group(1))
1467
+ entry = entry if entry else EnergyEntry()
1468
+ entry.m_set(entry.m_get_quantity_definition(match.group(2)), val)
1469
+ sec_energy.m_add_sub_section(getattr(Energy, match.group(1)), entry)
1470
+ else:
1471
+ entry = getattr(sec_energy, key)
1472
+ entry = entry if entry else EnergyEntry()
1473
+ entry.value = val
1474
+ sec_energy.m_add_sub_section(getattr(Energy, key), entry)
1475
+
1476
+ # forces
1477
+ sec_forces = Forces()
1478
+ sec_scc.forces = sec_forces
1479
+ if (forces := source.get('forces_total')) is not None:
1480
+ sec_forces.total = ForcesEntry(value=forces)
1481
+ for key, val in source.get('forces', dict()).items():
1482
+ key = key if key == 'total' else f'x_ams_{key}'
1483
+ sec_forces.m_add_sub_section(
1484
+ getattr(Forces, key), ForcesEntry(value=val)
1485
+ )
1486
+
1487
+ # md
1488
+ sec_scc.temperature = source.get('temperature')
1489
+ sec_scc.step = source.get('step')
1490
+ sec_scc.time = source.get('time')
1491
+
1492
+ # self consistency
1493
+ for energy_change in source.get('self_consistency', {}).get(
1494
+ 'energy_change', []
1495
+ ):
1496
+ sec_scf = ScfIteration()
1497
+ sec_scc.scf_iteration.append(sec_scf)
1498
+ sec_scf_energy = Energy()
1499
+ sec_scf.energy = sec_scf_energy
1500
+ sec_scf_energy.change = energy_change
1501
+
1502
+ # dos
1503
+ total_dos = source.get('total_dos', {}).get('dos')
1504
+ if total_dos is not None:
1505
+ total_dos = np.transpose(total_dos)
1506
+ n_spin_channels = len(total_dos[1:])
1507
+ for spin in range(n_spin_channels):
1508
+ sec_dos = Dos()
1509
+ sec_scc.dos_electronic.append(sec_dos)
1510
+ sec_dos.spin_channel = spin if n_spin_channels == 2 else None
1511
+ sec_dos.energies = total_dos[0] * ureg.hartree
1512
+ sec_dos_values = DosValues()
1513
+ sec_dos.total.append(sec_dos_values)
1514
+ sec_dos_values.value = total_dos[spin + 1] / ureg.hartree
1515
+
1516
+ # atom charges
1517
+ if (charges := source.get('atomic_charges')) is not None:
1518
+ sec_charges = Charges()
1519
+ sec_scc.charges.append(sec_charges)
1520
+ sec_charges.value = charges * ureg.elementary_charge
1521
+
1522
+ for analysis in source.get('atom_charge_analysis', []):
1523
+ for n, method in enumerate(analysis.get('methods', [])):
1524
+ existing_sec_charges = [
1525
+ sec for sec in sec_scc.charges if sec.analysis_method == method
1526
+ ]
1527
+ if existing_sec_charges:
1528
+ sec_charges = existing_sec_charges[0]
1529
+ else:
1530
+ sec_charges = Charges()
1531
+ sec_scc.charges.append(sec_charges)
1532
+ sec_charges.analysis_method = method
1533
+ if analysis.spin:
1534
+ sec_charges.spins = analysis.atom_charges[n]
1535
+ else:
1536
+ sec_charges.total = analysis.total[n]
1537
+ sec_charges.value = (
1538
+ analysis.atom_charges[n] * ureg.elementary_charge
1539
+ )
1540
+
1541
+ # mulliken populations
1542
+ mulliken = source.get('mulliken_populations')
1543
+ if mulliken is not None:
1544
+ sec_charges = Charges()
1545
+ sec_scc.charges.append(sec_charges)
1546
+ sec_charges.analysis_method = 'Mulliken'
1547
+ # atom/spin resolved
1548
+ atom_charges = np.array(mulliken.get('atom', []))
1549
+ spin = len(atom_charges.T)
1550
+ if spin == 2:
1551
+ for natom, charges in enumerate(atom_charges):
1552
+ for nspin, charge in enumerate(charges):
1553
+ sec_charges.spin_projected.append(
1554
+ ChargesValue(
1555
+ spin=nspin,
1556
+ atom_index=natom,
1557
+ value=charge * ureg.elementary_charge,
1558
+ )
1559
+ )
1560
+ elif spin == 1:
1561
+ sec_charges.value = atom_charges.flatten() * ureg.elementary_charge
1562
+ # orbital resolved
1563
+ for natom, atom, orbitals, charges in mulliken.get('orbital', []):
1564
+ for norb, orbital in enumerate(orbitals):
1565
+ for nspin, charge in enumerate(charges[norb]):
1566
+ sec_charges.orbital_projected.append(
1567
+ ChargesValue(
1568
+ orbital=orbital,
1569
+ spin=nspin,
1570
+ atom_label=atom[0],
1571
+ atom_index=int(natom[0]),
1572
+ value=charge * ureg.elementary_charge,
1573
+ )
1574
+ )
1575
+ sec_charges.total = mulliken.get('total')
1576
+
1577
+ # dipole
1578
+ dipole = source.get('dipole_moment')
1579
+ if dipole is not None:
1580
+ sec_multipoles = Multipoles()
1581
+ sec_scc.multipoles.append(sec_multipoles)
1582
+ sec_multipoles.dipole = MultipolesEntry(total=dipole)
1583
+
1584
+ # eigenvalues
1585
+ if (eigenvalues := source.get('eigenvalues')) is not None:
1586
+ sec_eigenvalues = BandEnergies()
1587
+ sec_scc.eigenvalues.append(sec_eigenvalues)
1588
+ sec_eigenvalues.energies = eigenvalues.get('energies')
1589
+ sec_eigenvalues.occupations = eigenvalues.get('occupations')
1590
+
1591
+ band_energy_ranges = source.get('band_energy_ranges')
1592
+ if band_energy_ranges is not None:
1593
+ if sec_scc.eigenvalues:
1594
+ sec_band_energies = sec_scc.eigenvalues[0]
1595
+ else:
1596
+ sec_band_energies = BandEnergies()
1597
+ sec_scc.eigenvalues.append(sec_band_energies)
1598
+ sec_band_energies.x_ams_energy_min = (
1599
+ band_energy_ranges[0] * ureg.hartree
1600
+ )
1601
+ sec_band_energies.x_ams_energy_max = (
1602
+ band_energy_ranges[1] * ureg.hartree
1603
+ )
1604
+ sec_band_energies.occupations = band_energy_ranges[2]
1605
+
1606
+ # band gap
1607
+ band_gap_info = source.get('band_gap_info')
1608
+ if band_gap_info is not None:
1609
+ sec_band_gap = BandGapDeprecated()
1610
+ sec_band_energies.band_gap.append(sec_band_gap)
1611
+ for key, val in band_gap_info.items():
1612
+ sec_band_gap.m_set(
1613
+ sec_band_gap.m_get_quantity_definition(key), val
1614
+ )
1615
+
1616
+ if (band_gap := source.get('band_gap')) is not None:
1617
+ sec_band_gap = BandGap()
1618
+ sec_scc.band_gap.append(sec_band_gap)
1619
+ for key, val in band_gap.items():
1620
+ sec_band_gap.m_set(sec_band_gap.m_get_quantity_definition(key), val)
1621
+
1622
+ sec_scc.hessian_matrix = source.get('hessian_matrix')
1623
+
1624
+ return sec_scc
1625
+
1626
+ def parse_system(source):
1627
+ sec_system = System()
1628
+ sec_run.system.append(sec_system)
1629
+
1630
+ sec_atoms = Atoms()
1631
+ sec_system.atoms = sec_atoms
1632
+ labels_positions = source.get('labels_positions')
1633
+ if labels_positions is not None:
1634
+ sec_atoms.labels = labels_positions[0]
1635
+ sec_atoms.positions = labels_positions[1]
1636
+
1637
+ lattice_vectors = source.get('lattice_vectors')
1638
+ if lattice_vectors is not None:
1639
+ unit = lattice_vectors.units
1640
+ lattice_vectors = list(lattice_vectors.magnitude)
1641
+ pbc = [True, True, True]
1642
+ for n in range(len(lattice_vectors), 3):
1643
+ lattice_vectors.append([0, 0, 0])
1644
+ pbc[n] = False
1645
+ sec_atoms.lattice_vectors = lattice_vectors * unit
1646
+ sec_atoms.periodic = pbc
1647
+
1648
+ sec_atoms.velocities = source.get('velocities')
1649
+
1650
+ return sec_system
1651
+
1652
+ def parse_method(source):
1653
+ if source is None:
1654
+ return
1655
+
1656
+ sec_method = Method()
1657
+ sec_run.method.append(sec_method)
1658
+ sec_atom_centered = BasisSetAtomCentered()
1659
+ for key, val in source.get('confinement', {}).items():
1660
+ sec_atom_centered.m_set(
1661
+ sec_atom_centered.m_get_quantity_definition(key), val
1662
+ )
1663
+ sec_method.electrons_representation = [
1664
+ BasisSetContainer(
1665
+ type='atom-centered orbitals',
1666
+ scope=['wavefunction'],
1667
+ basis_set=[
1668
+ BasisSet(
1669
+ type='numeric AOs',
1670
+ atom_centered=[sec_atom_centered],
1671
+ )
1672
+ ],
1673
+ )
1674
+ ]
1675
+
1676
+ for function in source.get('radial_functions', []):
1677
+ sec_atom_param = AtomParameters()
1678
+ sec_method.atom_parameters.append(sec_atom_param)
1679
+ for key, val in function.items():
1680
+ if val is None:
1681
+ continue
1682
+ if key == 'orbital_parameters':
1683
+ sec_atom_param.orbitals = [str(v) for v in val[0]]
1684
+ sec_atom_param.charges = val[1]
1685
+ sec_atom_param.x_ams_orbital_energies = (
1686
+ np.array(val[2], np.float64) * ureg.hartree
1687
+ )
1688
+ sec_atom_param.x_ams_orbital_radii = np.array(val[4])
1689
+ else:
1690
+ sec_atom_param.m_set(
1691
+ sec_atom_param.m_get_quantity_definition(key), val
1692
+ )
1693
+
1694
+ ranges_orbitals = source.get('ranges_atomic_orbitals', {})
1695
+ for atom_type in ranges_orbitals.get('type', []):
1696
+ for sec_atom_param in sec_method.atom_parameters:
1697
+ if sec_atom_param.label == atom_type[0]:
1698
+ for n, key in enumerate(
1699
+ ['valence', 'core', 'valence_kinetic', 'core_kinetic']
1700
+ ):
1701
+ sec_atom_param.m_set(
1702
+ sec_atom_param.m_get_quantity_definition(
1703
+ f'x_ams_cutoff_{key}'
1704
+ ),
1705
+ atom_type[n + 1],
1706
+ )
1707
+ break
1708
+
1709
+ if (
1710
+ dft_potential := source.get('model_parameters', {}).get(
1711
+ 'dft_potential', {}
1712
+ )
1713
+ ) is not None:
1714
+ sec_dft = DFT()
1715
+ sec_method.dft = sec_dft
1716
+ # TODO provide mapping
1717
+ sec_xc_functional = XCFunctional()
1718
+ sec_dft.xc_functional = sec_xc_functional
1719
+ for xc_type in ['LDA', 'GGA', 'MGGA']:
1720
+ functionals = dft_potential.get(xc_type, '').split()
1721
+ kind = ['XC'] if len(functionals) == 1 else ['X', 'C']
1722
+ for n, functional in enumerate(functionals):
1723
+ functional = functional.rstrip('x').rstrip('c').upper()
1724
+ if kind[n] == 'X':
1725
+ sec_xc_functional.exchange.append(
1726
+ Functional(
1727
+ name='%s_%s_%s' % (xc_type, kind[n], functional)
1728
+ )
1729
+ )
1730
+ elif kind[n] == 'C':
1731
+ sec_xc_functional.correlation.append(
1732
+ Functional(
1733
+ name='%s_%s_%s' % (xc_type, kind[n], functional)
1734
+ )
1735
+ )
1736
+ else:
1737
+ sec_xc_functional.contributions.append(
1738
+ Functional(
1739
+ name='%s_%s_%s' % (xc_type, kind[n], functional)
1740
+ )
1741
+ )
1742
+
1743
+ sec_electronic = Electronic()
1744
+ sec_method.electronic = sec_electronic
1745
+ model_parameters = source.get('model_parameters', {})
1746
+ spin = source.get('x_ams_spin_polarization', model_parameters.get('spin'))
1747
+ sec_electronic.n_spin_channels = 2 if spin else 1
1748
+ sec_electronic.relativity_method = self._relativity_map.get(
1749
+ model_parameters.get('relativistic_corrections')
1750
+ )
1751
+ for key, val in model_parameters.items():
1752
+ if hasattr(Method, key):
1753
+ sec_method.m_set(sec_method.m_get_quantity_definition(key), val)
1754
+
1755
+ if (charge := source.get('total_charge')) is not None:
1756
+ sec_electronic.charge = charge
1757
+
1758
+ # TODO add smearing params
1759
+ if (scf_options := source.get('scf_options')) is not None:
1760
+ sec_scf = Scf()
1761
+ sec_method.scf = sec_scf
1762
+ for key, val in scf_options.items():
1763
+ sec_scf.m_set(sec_scf.m_get_quantity_definition(key), val)
1764
+
1765
+ if (k_space_sampling := source.get('k_space_sampling')) is not None:
1766
+ sec_k_mesh = KMesh()
1767
+ sec_method.k_mesh = sec_k_mesh
1768
+ for key, val in k_space_sampling.items():
1769
+ sec_k_mesh.m_set(sec_k_mesh.m_get_quantity_definition(key), val)
1770
+
1771
+ for key in source.keys():
1772
+ if hasattr(Method, key):
1773
+ sec_method.m_set(
1774
+ sec_method.m_get_quantity_definition(key), source.get(key)
1775
+ )
1776
+
1777
+ return sec_method
1778
+
1779
+ def parse_calculation(source):
1780
+ if source is None:
1781
+ return
1782
+
1783
+ sec_scc = parse_scc(source)
1784
+ sec_system = parse_system(source)
1785
+ sec_scc.system_ref = sec_system
1786
+
1787
+ workflow = None
1788
+ if (geometry_opt := self.parser.geometry_optimization) is not None:
1789
+ workflow = GeometryOptimization(method=GeometryOptimizationMethod())
1790
+ for key, val in geometry_opt.items():
1791
+ if key == 'step':
1792
+ for step in val:
1793
+ parse_calculation(step)
1794
+ elif key.startswith('x_ams') and hasattr(GeometryOptimization, key):
1795
+ workflow.m_set(workflow.m_get_quantity_definition(key), val)
1796
+ sec_method = parse_method(geometry_opt)
1797
+ sec_run.calculation[-1].method_ref = sec_method
1798
+ workflow.method.convergence_tolerance_energy_difference = geometry_opt.get(
1799
+ 'convergence_tolerance_energy_difference'
1800
+ )
1801
+ workflow.method.convergence_tolerance_displacement_maximum = (
1802
+ geometry_opt.get('convergence_tolerance_displacement_maximum')
1803
+ )
1804
+ workflow.method.convergence_tolerance_force_maximum = geometry_opt.get(
1805
+ 'convergence_tolerance_force_maximum'
1806
+ )
1807
+
1808
+ elif (md := self.parser.molecular_dynamics) is not None:
1809
+ workflow = MolecularDynamics()
1810
+ sec_method = parse_method(md)
1811
+ for step in md.get('step', []):
1812
+ parse_calculation(step)
1813
+ sec_run.calculation[-1].method_ref = sec_method
1814
+
1815
+ elif (sp := self.parser.get('single_point')) is not None:
1816
+ sec_method = parse_method(sp)
1817
+ parse_calculation(sp)
1818
+ sec_run.calculation[-1].method_ref = sec_method
1819
+
1820
+ self.archive.workflow2 = workflow
1821
+
1822
+ def parse(self, filepath, archive, logger):
1823
+ self.mainfile = os.path.abspath(filepath)
1824
+ self.archive = archive
1825
+ self.logger = logger if logger is not None else logging.getLogger(__name__)
1826
+
1827
+ self.init_parser()
1828
+
1829
+ rkf_files = get_files('ams.rkf', self.mainfile)
1830
+ if rkf_files:
1831
+ if len(rkf_files) > 1:
1832
+ self.logger.warning('Multiple ams.rkf files found.')
1833
+ self.parser = self.rkf_parser
1834
+ self.parser.mainfile = os.path.join(os.path.dirname(filepath), rkf_files[0])
1835
+
1836
+ sec_run = Run()
1837
+ self.archive.run.append(sec_run)
1838
+ sec_run.program = Program(
1839
+ name='AMS', version=self.parser.get('program_version', '')
1840
+ )
1841
+ for key in self.parser.results.keys():
1842
+ if key.startswith('program_x_ams'):
1843
+ sec_run.program.m_set(
1844
+ sec_run.program.m_get_quantity_definition(key.strip('program_')),
1845
+ self.parser.get(key),
1846
+ )
1847
+ if key == 'time_start':
1848
+ sec_run.time_run = TimeRun(date_start=self.parser.get(key))
1849
+ self.parse_configurations()