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,1214 @@
1
+ import logging
2
+ import os
3
+ import numpy as np
4
+ import re
5
+ from ase.io import read
6
+ from ase import units as ase_units
7
+
8
+ from .metainfo import octopus # noqa
9
+ from nomad.units import ureg
10
+ from nomad.utils import get_logger
11
+ from nomad.parsing.file_parser import TextParser, Quantity
12
+ from runschema.run import Run, Program
13
+ from runschema.method import (
14
+ Electronic,
15
+ Functional,
16
+ Smearing,
17
+ Method,
18
+ DFT,
19
+ BasisSet,
20
+ BasisSetContainer,
21
+ XCFunctional,
22
+ KMesh,
23
+ )
24
+ from runschema.system import System, Atoms
25
+ from runschema.calculation import (
26
+ Calculation,
27
+ ScfIteration,
28
+ Energy,
29
+ EnergyEntry,
30
+ Forces,
31
+ ForcesEntry,
32
+ BandEnergies,
33
+ )
34
+ from simulationworkflowschema import GeometryOptimization
35
+
36
+
37
+ re_float = r'[\d\.\-\+Ee]+'
38
+
39
+
40
+ class EigenvalueParser(TextParser):
41
+ def __init__(self):
42
+ super().__init__()
43
+
44
+ def init_quantities(self):
45
+ def str_to_eigenvalues(val_in):
46
+ val = [v.split() for v in val_in.strip().split('\n')]
47
+ kpoint = (
48
+ [0.0, 0.0, 0.0]
49
+ if val[0][0] == '#st'
50
+ else [float(v.rstrip(',')) for v in val[0]]
51
+ )
52
+ if len(val) == 1:
53
+ return
54
+ eigenvalues = np.array([[v[0], v[2], v[3]] for v in val[1:]], dtype=float)
55
+ eigenvalues = np.transpose(eigenvalues)
56
+ nspin = 2 if eigenvalues[0][1] == 1.0 else 1
57
+ nbands = int(max(eigenvalues[0]))
58
+ eigenvalues = eigenvalues[1:]
59
+ eigenvalues.shape = (2, nbands, nspin)
60
+ return kpoint, eigenvalues[0], eigenvalues[1]
61
+
62
+ def str_to_fermi_energy(val_in):
63
+ val = val_in.split()
64
+ unit = ureg.eV if val[1].startswith('e') else ureg.hartree
65
+ return float(val[0]) * unit
66
+
67
+ self._quantities = [
68
+ Quantity(
69
+ 'eigenvalues',
70
+ r'(Eigenvalues \[[\s\S]+?)(?:\n\n|\Z)',
71
+ sub_parser=TextParser(
72
+ quantities=[
73
+ Quantity(
74
+ 'eigenvalues',
75
+ r'(?:(#st)\s*Spin\s*Eigenvalue\s*Occupation|#k =\s*\d+, k = \(([\-\d\.,\s]+)\))([\d\s\.\-updn]+)',
76
+ str_operation=str_to_eigenvalues,
77
+ repeats=True,
78
+ convert=False,
79
+ ),
80
+ Quantity(
81
+ 'unit',
82
+ r'Eigenvalues \[(.*)\]',
83
+ convert=False,
84
+ str_operation=lambda x: 'eV' if x == 'eV' else 'hartree',
85
+ ),
86
+ Quantity(
87
+ 'fermi_energy',
88
+ rf'Fermi energy =\s*({re_float} .*)',
89
+ convert=False,
90
+ str_operation=str_to_fermi_energy,
91
+ ),
92
+ ]
93
+ ),
94
+ )
95
+ ]
96
+
97
+
98
+ class InfoParser(EigenvalueParser):
99
+ def __init__(self):
100
+ super().__init__()
101
+
102
+ def init_quantities(self):
103
+ def str_to_energies(val_in):
104
+ val = [v.split('=') for v in val_in.strip().split('\n')]
105
+ unit = ureg.eV if '[eV]:' in val[0] else ureg.hartree
106
+ return {v[0].strip(): float(v[1]) * unit for v in val if len(v) == 2}
107
+
108
+ def str_to_forces(val_in):
109
+ val = [v.split() for v in val_in.strip().split('\n')]
110
+ unit = (
111
+ ureg.eV / ureg.angstrom
112
+ if '[eV/A]' in val[0]
113
+ else ureg.hartree / ureg.bohr
114
+ )
115
+ return np.array([v[2:5] for v in val if len(v) == 5], dtype=float) * unit
116
+
117
+ super().init_quantities()
118
+ self._quantities += [
119
+ Quantity(
120
+ 'brillouin_zone_sampling',
121
+ r'Brillouin zone sampling([\s\S]+?)\*+\n\n',
122
+ sub_parser=TextParser(
123
+ quantities=[
124
+ Quantity(
125
+ 'kgrid',
126
+ r'Dimensions of the k\-point grid\s*=(.*)',
127
+ dtype=int,
128
+ ),
129
+ Quantity(
130
+ 'n_kpoints', r'Total number of k\-points\s*=(.*)', dtype=int
131
+ ),
132
+ Quantity(
133
+ 'n_kpoints_reduced',
134
+ r'Number of symmetry-reduced k\-points\s*=(.*)',
135
+ dtype=int,
136
+ ),
137
+ Quantity(
138
+ 'kpoints',
139
+ rf'\d+\s*({re_float})\s*({re_float})\s*({re_float})\s*({re_float})',
140
+ dtype=float,
141
+ repeats=True,
142
+ ),
143
+ ]
144
+ ),
145
+ ),
146
+ Quantity(
147
+ 'energies', r'Energy (\[[\s\S]+?)\n\n', str_operation=str_to_energies
148
+ ),
149
+ Quantity(
150
+ 'total_magnetic_moment',
151
+ rf'Total Magnetic Moment:\s*mz\s*=\s*({re_float})',
152
+ ),
153
+ Quantity(
154
+ 'local_magnetic_moments',
155
+ r'Ion\s*mz\s*([\w\s\.\-]+?)\n\n',
156
+ convert=False,
157
+ str_operation=lambda x: np.array(
158
+ [v.split()[2] for v in x.strip().split('\n')], dtype=float
159
+ ),
160
+ ),
161
+ Quantity(
162
+ 'dipole',
163
+ rf'Dipole:.*\[Debye\]\s*<x> =\s*\S+\s*({re_float})\s*'
164
+ rf'<y> =\s*\S+\s*({re_float})\s*<z> =\s*\S+\s*({re_float})',
165
+ dtype=float,
166
+ ),
167
+ Quantity(
168
+ 'forces',
169
+ r'Forces on the ions (\[.*\]\s*)Ion\s*x\s*y\s*z\s*([\s\S]*)',
170
+ str_operation=str_to_forces,
171
+ convert=False,
172
+ ),
173
+ ]
174
+
175
+
176
+ class ControlParser(TextParser):
177
+ def __init__(self):
178
+ super().__init__()
179
+ self._constants = {
180
+ 'pi': np.pi,
181
+ 'angstrom': 1.0 / ase_units.Bohr,
182
+ 'ev': 1.0 / ase_units.Hartree,
183
+ 'yes': True,
184
+ 'no': False,
185
+ 't': True,
186
+ 'f': False,
187
+ 'true': True,
188
+ 'false': False,
189
+ 'i': 1j,
190
+ }
191
+ self._re_sqrt = re.compile(r'sqrt([\w\. ]+\Z)')
192
+ self._info = None
193
+
194
+ def init_quantities(self):
195
+ def str_to_line(val_in):
196
+ val = val_in.replace('"', '').replace("'", '').split('=', 1)
197
+ return [v.strip().split('#')[0] for v in val]
198
+
199
+ self._quantities = [
200
+ Quantity(
201
+ 'line', r'(\w.*\s*=\s*.*)#?', str_operation=str_to_line, repeats=True
202
+ )
203
+ ]
204
+
205
+ @property
206
+ def mainfile(self):
207
+ return super().mainfile
208
+
209
+ @mainfile.setter
210
+ def mainfile(self, val):
211
+ # TODO pylint complains when inheriting property
212
+ self._results = None
213
+ self._file_handler = None
214
+ self._mainfile = os.path.abspath(val) if val is not None else val
215
+ self._info = None
216
+ self._keys_mapping = dict()
217
+
218
+ def evaluate_value(self, value):
219
+ # evaluate octopus parameterized variables, e.g. 2*angstrom
220
+ # TODO implement all operations and parameters supported by Octopus
221
+
222
+ if isinstance(value, list):
223
+ return [self.evaluate_value(v) for v in value]
224
+
225
+ if not isinstance(value, str):
226
+ return value
227
+
228
+ try:
229
+ return float(value)
230
+ except Exception:
231
+ pass
232
+
233
+ value = value.strip()
234
+ if value == '':
235
+ return 1
236
+
237
+ val = self._constants.get(value.lower(), None)
238
+ if val is not None:
239
+ return val
240
+
241
+ val = self._info.get(self._keys_mapping.get(value.lower(), None), None)
242
+ if val is not None:
243
+ return val
244
+
245
+ open_p = value.rfind('(')
246
+ if open_p > -1:
247
+ n_groups = value.count('(')
248
+ if n_groups != value.count(')'):
249
+ return value
250
+ for _ in range(n_groups):
251
+ part = value[open_p + 1 :]
252
+ part = part[: part.find(')')]
253
+ value = value.replace('(%s)' % part, str(self.evaluate_value(part)))
254
+ open_p = value.rfind('(')
255
+ return self.evaluate_value(value)
256
+
257
+ sqrt = self._re_sqrt.match(value)
258
+ if sqrt:
259
+ val = self.evaluate_value(sqrt.group(1))
260
+ return np.sqrt(val)
261
+
262
+ vals = value.split('**')
263
+ if len(vals) > 1:
264
+ vals = [self.evaluate_value(v) for v in vals]
265
+ val = vals[0]
266
+ for v in reversed(vals[1:]):
267
+ val = val**v
268
+ return val
269
+
270
+ vals = value.split('*')
271
+ if len(vals) > 1:
272
+ vals = [self.evaluate_value(v) for v in vals]
273
+ return np.product(vals)
274
+
275
+ vals = value.split('/')
276
+ if len(vals) > 1:
277
+ vals = [self.evaluate_value(v) for v in vals]
278
+ val = vals[0]
279
+ for v in vals[1:]:
280
+ val /= v
281
+ return val
282
+
283
+ if '+' in value:
284
+ vals = value.split('+')
285
+ vals = [self.evaluate_value(v) for v in vals]
286
+ val = 0.0
287
+ for v in vals:
288
+ val += v
289
+ return val
290
+
291
+ if '-' in value:
292
+ vals = value.split('-')
293
+ vals = [self.evaluate_value(v) for v in vals]
294
+ val = 0.0
295
+ for v in vals:
296
+ val -= v
297
+ return val
298
+
299
+ return value
300
+
301
+ @property
302
+ def info(self):
303
+ if self._info is None:
304
+ self._info = {v[0].strip(): v[1] for v in self.get('line', [])}
305
+ self._info.update({v[0].strip(): v[1:] for v in self.get('block', [])})
306
+ self._keys_mapping = {k.lower(): k for k in self._info.keys()}
307
+ for key, val in self._info.items():
308
+ try:
309
+ val = self.evaluate_value(val)
310
+ except Exception:
311
+ continue
312
+ self._info[key] = val
313
+ self._keys_mapping[key.lower()] = key
314
+ return self._info
315
+
316
+
317
+ class InpParser(ControlParser):
318
+ def __init__(self):
319
+ super().__init__()
320
+
321
+ def init_quantities(self):
322
+ def str_to_block(val_in):
323
+ val = [v.split('#')[0] for v in val_in.strip().split('\n')]
324
+ val = [v.replace('"', '').replace("'", '').split('|') for v in val if v]
325
+ val[0] = val[0][0]
326
+ return val
327
+
328
+ super().init_quantities()
329
+ self._quantities += [
330
+ Quantity('block', r'%([\s\S]+?)%', repeats=True, str_operation=str_to_block)
331
+ ]
332
+
333
+ def get_coordinates(self):
334
+ val = self.info.get('Coordinates', self.info.get('ReducedCoordinates', []))
335
+
336
+ symbols = []
337
+ coordinates = []
338
+ for v in val:
339
+ symbols.append(v[0].strip())
340
+ coordinates.append(v[1:])
341
+
342
+ coordinates = np.array(coordinates, dtype=float)
343
+ coordinates.shape = (len(symbols), 3)
344
+ return symbols, coordinates
345
+
346
+
347
+ class LogParser(ControlParser):
348
+ def __init__(self):
349
+ super().__init__()
350
+
351
+ def init_quantities(self):
352
+ def str_to_block(val_in):
353
+ val = val_in.strip().split('\n')
354
+ name = val[0].strip().replace('"', '').replace("'", '')
355
+ val = [
356
+ v.split('#')[0].split('=')[1].replace('"', '').replace("'", '').strip()
357
+ for v in val[1:]
358
+ ]
359
+ return [name, val]
360
+
361
+ super().init_quantities()
362
+ self._quantities += [
363
+ Quantity(
364
+ 'block',
365
+ r'Opened block([\s\S]+?)Closed block',
366
+ repeats=True,
367
+ str_operation=str_to_block,
368
+ )
369
+ ]
370
+
371
+ def get_coordinates(self):
372
+ symbols = []
373
+ coordinates = []
374
+
375
+ val = self.info.get('Coordinates', self.info.get('ReducedCoordinates', [[]]))[0]
376
+
377
+ for v in val:
378
+ if isinstance(v, str):
379
+ symbols.append(v.strip())
380
+ else:
381
+ coordinates.append(v)
382
+
383
+ coordinates = np.array(coordinates, dtype=float)
384
+ coordinates.shape = (len(symbols), 3)
385
+
386
+ return symbols, coordinates
387
+
388
+
389
+ class OutParser(TextParser):
390
+ def __init__(self):
391
+ super().__init__()
392
+
393
+ def init_quantities(self):
394
+ def str_to_option(val_in):
395
+ val = val_in.strip().split(':')
396
+ return [val[0].strip(), ''.join(val[1:]).strip()]
397
+
398
+ def str_to_cell(val_in):
399
+ unit = ureg.angstrom if val_in.lower().startswith('a') else ureg.bohr
400
+ val = [v.split() for v in val_in.strip().split('\n')[1:]]
401
+ return np.array(val, dtype=float) * unit
402
+
403
+ def str_to_spacing(val_in):
404
+ unit = ureg.angstrom if val_in.startswith('A') else ureg.bohr
405
+ return np.array(val_in.split()[1:4], dtype=float) * unit
406
+
407
+ def str_to_energy(val_in):
408
+ val = val_in.split()
409
+ unit = ureg.eV if val[1].startswith('e') else ureg.hartree
410
+ return float(val[0]) * unit
411
+
412
+ def str_to_td_iteration(val_in):
413
+ val = val_in.strip().split()
414
+ return dict(
415
+ iter=int(val[0]),
416
+ time=float(val[1]),
417
+ energy=float(val[2]),
418
+ scfsteps=int(val[3]),
419
+ elapsed_time=float(val[4]),
420
+ )
421
+
422
+ iteration_quantities = [
423
+ Quantity('energy_total', rf'etot\s*=\s*({re_float})'),
424
+ # TODO scf_iteration eigenvalues are sometimes truncated and unusable
425
+ Quantity(
426
+ 'fermi_level',
427
+ rf'Fermi energy\s*=\s*({re_float} .*)',
428
+ str_operation=str_to_energy,
429
+ convert=False,
430
+ ),
431
+ Quantity(
432
+ 'time',
433
+ r'Elapsed time for SCF step\s*\d+:\s*([\d\.]+)',
434
+ unit='s',
435
+ dtype=float,
436
+ ),
437
+ ]
438
+
439
+ self._quantities = [
440
+ Quantity(
441
+ 'header',
442
+ r'Running octopus([\s\S]+?)\*{10}',
443
+ sub_parser=TextParser(
444
+ quantities=[
445
+ Quantity(
446
+ 'options',
447
+ r'\n *([\w ]+?\s*:\s*.*)',
448
+ str_operation=str_to_option,
449
+ repeats=True,
450
+ ),
451
+ ]
452
+ ),
453
+ ),
454
+ Quantity(
455
+ 'grid',
456
+ r'\*\s*Grid\s*\*+\s*([\s\S]+?)\*{10}',
457
+ sub_parser=TextParser(
458
+ quantities=[
459
+ Quantity('boxshape', r'Type\s*=\s*(.*)'),
460
+ Quantity(
461
+ 'npbc',
462
+ r'Octopus will treat the system as periodic in (\S+) dim',
463
+ dtype=int,
464
+ ),
465
+ Quantity(
466
+ 'cell',
467
+ r'Lattice Vectors \[(.*)\]([-\d\s\.]+)',
468
+ str_operation=str_to_cell,
469
+ convert=False,
470
+ ),
471
+ Quantity(
472
+ 'spacing',
473
+ r'Spacing \[(.*)\] = \(\s*(\S+), (\S+), (\S+)\s*\)',
474
+ str_operation=str_to_spacing,
475
+ convert=False,
476
+ ),
477
+ ]
478
+ ),
479
+ ),
480
+ Quantity(
481
+ 'theory_level',
482
+ r'\*\s*Theory Level\s*\*+\s*([\s\S]+?)\*{10}',
483
+ sub_parser=TextParser(
484
+ quantities=[
485
+ Quantity(
486
+ 'theory_level', r'\[TheoryLevel = (.+)\]', flatten=False
487
+ ),
488
+ Quantity('exchange', r'Exchange\s+(.*) \(', flatten=False),
489
+ Quantity(
490
+ 'correlation', r'Correlation\s+(.*) \(', flatten=False
491
+ ),
492
+ ]
493
+ ),
494
+ ),
495
+ Quantity(
496
+ 'self_consistent',
497
+ r'Info: Starting SCF iteration\.\s*([\s\S]+?)Info: SCF',
498
+ repeats=True,
499
+ sub_parser=TextParser(
500
+ quantities=[
501
+ Quantity(
502
+ 'iteration',
503
+ r'SCF CYCLE ITER #\s*(\d+\s*\*+[\s\S]+?)\*{10}',
504
+ repeats=True,
505
+ sub_parser=TextParser(quantities=iteration_quantities),
506
+ )
507
+ ]
508
+ ),
509
+ ),
510
+ Quantity(
511
+ 'time_dependent',
512
+ r'Time\-Dependent Simulation \*+([\s\S]+?)Info: Finished writing information',
513
+ repeats=True,
514
+ sub_parser=TextParser(
515
+ quantities=[
516
+ Quantity(
517
+ 'iteration',
518
+ rf'\n *(\d+\s*{re_float}\s*{re_float}\s*\d+\s*{re_float}) *\n',
519
+ str_operation=str_to_td_iteration,
520
+ repeats=True,
521
+ convert=False,
522
+ )
523
+ ]
524
+ ),
525
+ ),
526
+ Quantity(
527
+ 'x_octopus_info_scf_converged_iterations',
528
+ r'SCF converged in\s*(\d+) iterations',
529
+ dtype=int,
530
+ ),
531
+ Quantity(
532
+ 'minimization',
533
+ r'(MINIMIZATION ITER #:\s*\d+\s*\++\s*Energy[\s\S]+?\+{10})',
534
+ repeats=True,
535
+ sub_parser=TextParser(
536
+ quantities=[
537
+ Quantity(
538
+ 'energy_total',
539
+ rf'Energy\s*=\s*({re_float} .*)',
540
+ str_operation=str_to_energy,
541
+ convert=False,
542
+ ),
543
+ Quantity('number', r'ITER #:\s*(\d+)', dtype=int),
544
+ ]
545
+ ),
546
+ ),
547
+ # calculation results are not printed in outfile but in info
548
+ ]
549
+
550
+ self._header = None
551
+
552
+ @property
553
+ def header(self):
554
+ return {k: v for k, v in self.get('header', {}).get('options', [])}
555
+
556
+
557
+ class OctopusParser:
558
+ def __init__(self):
559
+ self.out_parser = OutParser()
560
+ self.log_parser = LogParser()
561
+ self.info_parser = InfoParser()
562
+ self.inp_parser = InpParser()
563
+ self.eigenvalue_parser = EigenvalueParser()
564
+
565
+ self._info = None
566
+
567
+ self._metainfo_keys_mapping = {
568
+ 'Total': 'energy_total',
569
+ 'Free': 'energy_free',
570
+ 'Ion-ion': 'energy_nuclear_repulsion',
571
+ 'Eigenvalues': 'energy_sum_eigenvalues',
572
+ 'Hartree': 'energy_electrostatic',
573
+ 'Exchange': 'energy_exchange',
574
+ 'Correlation': 'energy_correlation',
575
+ 'vanderWaals': 'energy_van_der_Waals',
576
+ '-TS': 'energy_correction_entropy',
577
+ 'Kinetic': 'energy_kinetic_electronic',
578
+ 'SpinComponents': 'n_spin_channels',
579
+ 'ExcessCharge': 'charge',
580
+ }
581
+
582
+ # TODO metainfo smearing_kind should be extended to cover all functions,
583
+ # e.g. gaussian and spline are not the same
584
+ self._smearing_functions = {
585
+ 1: 'empty',
586
+ 2: 'fermi',
587
+ 3: 'marzari-vanderbilt',
588
+ 4: 'methfessel_paxton',
589
+ 5: 'gaussian',
590
+ 'semiconducting': 'empty',
591
+ 'spline_smearing': 'gaussian',
592
+ 'fermi_dirac': 'fermi',
593
+ 'cold_smearing': 'marzari-vanderbilt',
594
+ 'methfessel_paxton': 'methfessel-paxton',
595
+ }
596
+
597
+ # TODO metainfo electronic_structure_method should be extended to cover all these
598
+ # HF is not DFT but nomad treats it this way
599
+ self._theory_levels = {
600
+ 1: 'DFT',
601
+ 2: None,
602
+ 3: 'DFT',
603
+ 4: 'DFT',
604
+ 5: None,
605
+ 'hartree': 'DFT',
606
+ 'independent_particles': None,
607
+ 'hartree_fock': 'DFT',
608
+ 'dft': 'DFT',
609
+ 'classical': None,
610
+ }
611
+
612
+ # List was generated from https://github.com/qsnake/octopus/blob/master/share/varinfo
613
+ # In parser.log, XCFunctional is an integer given as a sum of exchange
614
+ # and correlation. In stdout.txt, XCFunctional can be read as a string
615
+ # but it is not always consistent with the mapping that we have below (see for
616
+ # example Exchange which is Slater Exchange in stdout.txt). Therefore, in
617
+ # resolving the nomad xc_functional name, we first try to get it from the string
618
+ # output of stdout.txt and if it does not work, we get it from the integer value
619
+ # in parser.log.
620
+ # TODO resolve solely from the integer value
621
+ self._xc_functionals = {
622
+ 'Exchange': ('lda_x', 1),
623
+ 'Wigner parametrization': ('lda_c_wigner', 2000),
624
+ 'Random Phase Approximation': ('lda_c_rpa', 3000),
625
+ 'Hedin & Lundqvist': ('lda_c_hl', 4000),
626
+ 'Gunnarson & Lundqvist': ('lda_c_gl', 5000),
627
+ 'Slater Xalpha': ('lda_c_xalpha', 6000),
628
+ 'Vosko, Wilk, & Nussair': ('lda_c_vwn', 7000),
629
+ 'Vosko, Wilk, & Nussair (RPA)': ('lda_c_vwn_rpa', 8000),
630
+ 'Perdew & Zunger': ('lda_c_pz', 9000),
631
+ 'Perdew & Zunger (Modified)': ('lda_c_pz_mod', 10000),
632
+ 'Ortiz & Ballone (PZ)': ('lda_c_ob_pz', 11000),
633
+ 'Perdew & Wang': ('lda_c_pw', 12000),
634
+ 'Perdew & Wang (Modified)': ('lda_c_pw_mod', 13000),
635
+ 'Ortiz & Ballone (PW)': ('lda_c_ob_pw', 14000),
636
+ 'Attacalite et al': ('lda_c_2d_amgb', 15000),
637
+ 'Pittalis, Rasanen & Marques correlation in 2D': ('lda_c_2d_prm', 16000),
638
+ 'von Barth & Hedin': ('lda_c_vbh', 17000),
639
+ 'Casula, Sorella, and Senatore 1D correlation': ('lda_c_1d_csc', 18000),
640
+ 'Exchange in 2D': ('lda_x_2d', 19),
641
+ 'Teter 93 parametrization': ('lda_xc_teter93', 20000),
642
+ 'Exchange in 1D': ('lda_x_1d', 21),
643
+ 'Modified LSD (version 1) of Proynov and Salahub': ('lda_c_ml1', 22000),
644
+ 'Modified LSD (version 2) of Proynov and Salahub': ('lda_c_ml2', 23000),
645
+ 'Gombas parametrization': ('lda_c_gombas', 24000),
646
+ 'Thomas-Fermi kinetic energy functional': ('lda_k_tf', 50),
647
+ 'Lee and Parr Gaussian ansatz': ('lda_k_lp', 51),
648
+ 'Perdew, Burke & Ernzerhof exchange': ('gga_x_pbe', 101),
649
+ 'Perdew, Burke & Ernzerhof exchange (revised)': ('gga_x_pbe_r', 102),
650
+ 'Becke 86 Xalfa,beta,gamma': ('gga_x_2d_b86', 128),
651
+ 'Herman et al original GGA': ('gga_x_herman', 104),
652
+ 'Becke 86 Xalfa,beta,gamma (with mod. grad. correction)': (
653
+ 'gga_x_b86_mgc',
654
+ 105,
655
+ ),
656
+ 'Becke 88': ('gga_x_b88', 106),
657
+ 'Gill 96': ('gga_x_g96', 107),
658
+ 'Perdew & Wang 86': ('gga_x_pw86', 108),
659
+ 'Perdew & Wang 91': ('gga_c_pw91', 134000),
660
+ 'Handy & Cohen OPTX 01': ('gga_x_optx', 110),
661
+ 'dePristo & Kress 87 (version R1)': ('gga_x_dk87_r1', 111),
662
+ 'dePristo & Kress 87 (version R2)': ('gga_x_dk87_r2', 112),
663
+ 'Lacks & Gordon 93': ('gga_x_lg93', 113),
664
+ 'Filatov & Thiel 97 (version A)': ('gga_x_ft97_a', 114),
665
+ 'Filatov & Thiel 97 (version B)': ('gga_x_ft97_b', 115),
666
+ 'Perdew, Burke & Ernzerhof exchange (solids)': ('gga_x_pbe_sol', 116),
667
+ 'Hammer, Hansen & Norskov (PBE-like)': ('gga_x_rpbe', 117),
668
+ 'Wu & Cohen': ('gga_x_wc', 118),
669
+ 'Modified form of PW91 by Adamo & Barone': ('gga_x_mpw91', 119),
670
+ 'Armiento & Mattsson 05 exchange': ('gga_x_am05', 120),
671
+ 'Madsen (PBE-like)': ('gga_x_pbea', 121),
672
+ 'Adamo & Barone modification to PBE': ('gga_x_mpbe', 122),
673
+ 'xPBE reparametrization by Xu & Goddard': ('gga_c_xpbe', 136000),
674
+ 'Becke 86 MGC for 2D systems': ('gga_x_2d_b86_mgc', 124),
675
+ 'Bayesian best fit for the enhancement factor': ('gga_x_bayesian', 125),
676
+ 'JSJR reparametrization by Pedroza, Silva & Capelle': (
677
+ 'gga_x_pbe_jsjr',
678
+ 126,
679
+ ),
680
+ 'Becke 88 in 2D': ('gga_x_2d_b88', 127),
681
+ 'Perdew, Burke & Ernzerhof exchange in 2D': ('gga_x_2d_pbe', 129),
682
+ 'Perdew, Burke & Ernzerhof correlation': ('gga_c_pbe', 130000),
683
+ 'Lee, Yang & Parr': ('gga_c_lyp', 131000),
684
+ 'Perdew 86': ('gga_c_p86', 132000),
685
+ 'Perdew, Burke & Ernzerhof correlation SOL': ('gga_c_pbe_sol', 133000),
686
+ 'Armiento & Mattsson 05 correlation': ('gga_c_am05', 135000),
687
+ 'Langreth and Mehl correlation': ('gga_c_lm', 137000),
688
+ 'JRGX reparametrization by Pedroza, Silva & Capelle': (
689
+ 'gga_c_pbe_jrgx',
690
+ 138000,
691
+ ),
692
+ 'Becke 88 reoptimized to be used with vdW functional of Dion et al': (
693
+ 'gga_x_optb88_vdw',
694
+ 139,
695
+ ),
696
+ 'PBE reparametrization for vdW': ('gga_x_optpbe_vdw', 141),
697
+ 'Regularized PBE': ('gga_c_rge2', 143000),
698
+ 'refitted Perdew & Wang 86': ('gga_x_rpw86', 144),
699
+ 'Keal and Tozer version 1': ('gga_x_kt1', 145),
700
+ 'Keal and Tozer version 2': ('gga_xc_kt2', 146000),
701
+ 'Wilson & Levy': ('gga_c_wl', 147000),
702
+ 'Wilson & Ivanov': ('gga_c_wi', 148000),
703
+ 'van Leeuwen & Baerends': ('gga_x_lb', 160),
704
+ 'HCTH functional fitted to 93 molecules': ('gga_xc_hcth_93', 161000),
705
+ 'HCTH functional fitted to 120 molecules': ('gga_xc_hcth_120', 162000),
706
+ 'HCTH functional fitted to 147 molecules': ('gga_xc_hcth_407', 164000),
707
+ 'Empirical functionals from Adamson, Gill, and Pople': (
708
+ 'gga_xc_edf1',
709
+ 165000,
710
+ ),
711
+ 'XLYP functional': ('gga_xc_xlyp', 166000),
712
+ 'Becke 97': ('hyb_gga_xc_b97', 407000),
713
+ 'Becke 97-1': ('hyb_gga_xc_b97_1', 408000),
714
+ 'Becke 97-2': ('hyb_gga_xc_b97_2', 410000),
715
+ 'Grimme functional to be used with C6 vdW term': ('gga_xc_b97_d', 170000),
716
+ 'Boese-Martin for Kinetics': ('hyb_gga_xc_b97_k', 413000),
717
+ 'Becke 97-3': ('hyb_gga_xc_b97_3', 414000),
718
+ 'Functionals fitted for water': ('gga_xc_pbelyp1w', 175000),
719
+ 'Schmider-Becke 98 parameterization 1a': ('hyb_gga_xc_sb98_1a', 420000),
720
+ 'Schmider-Becke 98 parameterization 1b': ('hyb_gga_xc_sb98_1b', 421000),
721
+ 'Schmider-Becke 98 parameterization 1c': ('hyb_gga_xc_sb98_1c', 422000),
722
+ 'Schmider-Becke 98 parameterization 2a': ('hyb_gga_xc_sb98_2a', 423000),
723
+ 'Schmider-Becke 98 parameterization 2b': ('hyb_gga_xc_sb98_2b', 424000),
724
+ 'Schmider-Becke 98 parameterization 2c': ('hyb_gga_xc_sb98_2c', 425000),
725
+ 'van Leeuwen & Baerends modified': ('gga_x_lbm', 182),
726
+ 'von Weiszaecker correction to Thomas-Fermi': ('gga_k_vw', 500),
727
+ 'Second-order gradient expansion (l = 1/9)': ('gga_k_ge2', 501),
728
+ 'TF-lambda-vW form by Golden (l = 13/45)': ('gga_k_golden', 502),
729
+ 'TF-lambda-vW form by Yonei and Tomishima (l = 1/5)': ('gga_k_yt65', 503),
730
+ 'TF-lambda-vW form by Baltin (l = 5/9)': ('gga_k_baltin', 504),
731
+ 'TF-lambda-vW form by Lieb (l = 0.185909191)': ('gga_k_lieb', 505),
732
+ 'gamma-TFvW form by Acharya et al [g = 1 - 1.412/N^(1/3)]': (
733
+ 'gga_k_absr1',
734
+ 506,
735
+ ),
736
+ 'gamma-TFvW form by Acharya et al [g = 1 - 1.332/N^(1/3)]': (
737
+ 'gga_k_absr2',
738
+ 507,
739
+ ),
740
+ 'gamma-TFvW form by Gázquez and Robles': ('gga_k_gr', 508),
741
+ 'gamma-TFvW form by Ludeña': ('gga_k_ludena', 509),
742
+ 'gamma-TFvW form by Ghosh and Parr': ('gga_k_gp85', 510),
743
+ 'Pearson': ('gga_k_pearson', 511),
744
+ 'Ou-Yang and Levy v.1': ('gga_k_ol1', 512),
745
+ 'Ou-Yang and Levy v.2': ('gga_k_ol2', 513),
746
+ 'Fuentealba & Reyes (B88 version)': ('gga_k_fr_b88', 514),
747
+ 'Fuentealba & Reyes (PW86 version)': ('gga_k_fr_pw86', 515),
748
+ 'The original hybrid proposed by Becke': ('hyb_gga_xc_b3pw91', 401000),
749
+ 'The (in)famous B3LYP': ('hyb_gga_xc_b3lyp', 402000),
750
+ 'Perdew 86 hybrid similar to B3PW91': ('hyb_gga_xc_b3p86', 403000),
751
+ 'hybrid using the optx functional': ('hyb_gga_xc_o3lyp', 404000),
752
+ 'mixture of mPW91 and PW91 optimized for kinetics': (
753
+ 'hyb_gga_xc_mpw1k',
754
+ 405000,
755
+ ),
756
+ 'aka PBE0 or PBE1PBE': ('hyb_gga_xc_pbeh', 406000),
757
+ 'maybe the best hybrid': ('hyb_gga_xc_x3lyp', 411000),
758
+ 'Becke 1-parameter mixture of WC and PBE': ('hyb_gga_xc_b1wc', 412000),
759
+ 'mixture with the mPW functional': ('hyb_gga_xc_mpw3pw', 415000),
760
+ 'Becke 1-parameter mixture of B88 and LYP': ('hyb_gga_xc_b1lyp', 416000),
761
+ 'Becke 1-parameter mixture of B88 and PW91': ('hyb_gga_xc_b1pw91', 417000),
762
+ 'Becke 1-parameter mixture of mPW91 and PW91': (
763
+ 'hyb_gga_xc_mpw1pw',
764
+ 418000,
765
+ ),
766
+ 'mixture of mPW and LYP': ('hyb_gga_xc_mpw3lyp', 419000),
767
+ 'Local tau approximation of Ernzerhof & Scuseria': ('mgga_x_lta', 201),
768
+ 'Perdew, Tao, Staroverov & Scuseria exchange': ('mgga_x_tpss', 202),
769
+ 'Zhao, Truhlar exchange': ('mgga_x_m06l', 203),
770
+ 'GVT4 from Van Voorhis and Scuseria (exchange part)': ('mgga_x_gvt4', 204),
771
+ 'tau-HCTH from Boese and Handy': ('mgga_x_tau_hcth', 205),
772
+ 'Becke-Roussel 89': ('mgga_x_br89', 206),
773
+ 'Becke & Johnson correction to Becke-Roussel 89': ('mgga_x_bj06', 207),
774
+ 'Tran & Blaha correction to Becke & Johnson': ('mgga_x_tb09', 208),
775
+ 'Rasanen, Pittalis, and Proetto correction to Becke & Johnson': (
776
+ 'mgga_x_rpp09',
777
+ 209,
778
+ ),
779
+ 'Pittalis, Rasanen, Helbig, Gross Exchange Functional': (
780
+ 'mgga_x_2d_prhg07',
781
+ 210,
782
+ ),
783
+ 'PRGH07 with PRP10 correction': ('mgga_x_2d_prhg07_prp10', 211),
784
+ 'Perdew, Tao, Staroverov & Scuseria correlation': ('mgga_c_tpss', 231000),
785
+ 'VSxc from Van Voorhis and Scuseria (correlation part)': (
786
+ 'mgga_c_vsxc',
787
+ 232000,
788
+ ),
789
+ 'Orestes, Marcasso & Capelle': ('lca_omc', 301),
790
+ 'Lee, Colwell & Handy': ('lca_lch', 302),
791
+ 'OEP: Exact exchange': ('oep_x', 901),
792
+ }
793
+
794
+ self._units_mapping = dict(
795
+ ev=ureg.eV, hartree=ureg.hartree, angstrom=ureg.angstrom, bohr=ureg.bohr
796
+ )
797
+
798
+ def init_parser(self, filepath, logger):
799
+ self.out_parser.mainfile = filepath
800
+ self.out_parser.logger = logger
801
+
802
+ self.info_parser.mainfile = os.path.join(self.maindir, 'static/info')
803
+ self.info_parser.logger = logger
804
+ self.log_parser.mainfile = os.path.join(self.maindir, 'exec/parser.log')
805
+ self.log_parser.logger = logger
806
+ self.inp_parser.mainfile = os.path.join(self.maindir, 'inp')
807
+ self.inp_parser.logger = logger
808
+ self.eigenvalue_parser.mainfile = os.path.join(
809
+ self.maindir, 'static/eigenvalues'
810
+ )
811
+ self.eigenvalue_parser.logger = logger
812
+ self._info = None
813
+
814
+ @property
815
+ def info(self):
816
+ if self._info is None:
817
+ self._info = dict()
818
+ self._info.update(self.inp_parser.info)
819
+ # the variables read from log are more reliable as these are converted
820
+ # to proper octopus values, i.e. we do not worry about compatibility issue
821
+ self._info.update(self.log_parser.info)
822
+ # add units for energy, length
823
+ # TODO not sure what defaults are for units and expected values for units(input)
824
+ # and their meaning
825
+ energyunit = 'hartree'
826
+ lengthunit = 'bohr'
827
+ units = self._info.get('Units', self._info.get('UnitsInput', 0))
828
+ if isinstance(units, str):
829
+ units = units.lower()
830
+ energyunit = 'eV' if 'ev' in units else energyunit
831
+ lengthunit = 'angstrom' if 'angs' in units else lengthunit
832
+ elif isinstance(units, int):
833
+ energyunit = 'eV' if units == 1 else energyunit
834
+ lengthunit = 'angstrom' if units == 1 else lengthunit
835
+ elif units is None:
836
+ cell = self.out_parser.get('grid', {}).get('cell')
837
+ if cell is not None:
838
+ lengthunit = cell.units
839
+ energyunit = 'eV' if lengthunit == 'angstrom' else energyunit
840
+ self._info.update(dict(energyunit=energyunit, lengthunit=lengthunit))
841
+ return self._info
842
+
843
+ def parse_scc(self):
844
+ sec_run = self.archive.run[-1]
845
+
846
+ # self-consistent
847
+ # SCF energies are printed only in output
848
+ initial_time = (
849
+ sec_run.calculation[-1].time_physical if sec_run.calculation else 0 * ureg.s
850
+ )
851
+ for scf in self.out_parser.get('self_consistent', []):
852
+ sec_scc = Calculation()
853
+ sec_run.calculation.append(sec_scc)
854
+ for iteration in scf.get('iteration', []):
855
+ initial_time = (
856
+ sec_scc.scf_iteration[-1].time_physical
857
+ if sec_scc.scf_iteration
858
+ else initial_time
859
+ )
860
+ sec_scf = ScfIteration()
861
+ sec_scc.scf_iteration.append(sec_scf)
862
+ sec_scf_energy = Energy()
863
+ sec_scf.energy = sec_scf_energy
864
+ fermi_level = iteration.get('fermi_level')
865
+ unit = None
866
+ if fermi_level is not None:
867
+ sec_scf_energy.fermi = fermi_level
868
+ energy_total = iteration.get('energy_total')
869
+ if energy_total is not None:
870
+ unit = (
871
+ self._units_mapping.get(
872
+ self.info.get('energyunit', 'hartree').lower()
873
+ )
874
+ if unit is None
875
+ else unit
876
+ )
877
+ sec_scf_energy.total = EnergyEntry(value=energy_total * unit)
878
+ time = iteration.get('time')
879
+ if time is not None:
880
+ sec_scf.time_calculation = time
881
+ sec_scf.time_physical = initial_time + sec_scf.time_calculation
882
+ if sec_scc.scf_iteration:
883
+ sec_scc.time_calculation = sum(
884
+ scf.time_calculation for scf in sec_scc.scf_iteration
885
+ )
886
+ sec_scc.time_physical = sec_scc.scf_iteration[-1].time_physical
887
+
888
+ # time-dependent
889
+ # each td iteration is an scc
890
+ for td in self.out_parser.get('time_dependent', []):
891
+ for iteration in td.get('iteration', []):
892
+ sec_scc = Calculation()
893
+ sec_run.calculation.append(sec_scc)
894
+ energy = iteration.get('energy', None)
895
+ if energy is not None:
896
+ sec_scc.energy = Energy(
897
+ total=EnergyEntry(
898
+ value=energy
899
+ * self._units_mapping.get(
900
+ self.info.get('energyunit', 'hartree').lower()
901
+ )
902
+ )
903
+ )
904
+
905
+ # TODO add other calculation types
906
+
907
+ # TODO bandstructures
908
+
909
+ # TODO dipoles
910
+
911
+ # TODO add volumetric data
912
+
913
+ # TODO test geometry optimizations, cannot find an exaple
914
+ for minimization in self.out_parser.get('minimization', []):
915
+ sec_scc = Calculation()
916
+ sec_run.calculation.append(sec_scc)
917
+ energy_total = minimization.get('energy_total')
918
+ if energy_total is not None:
919
+ sec_scc.energy = Energy(total=EnergyEntry(value=energy_total))
920
+ number = minimization.get('number')
921
+ cell = sec_run.system[-1].atoms.lattice_vectors
922
+ pbc = sec_run.system[-1].atoms.periodic
923
+ if number is not None:
924
+ path = os.path.join(
925
+ self.out_parser.maindir, 'geom/go.%04d.xyz' % number
926
+ )
927
+ try:
928
+ atoms = read(path, format='xyz')
929
+ except Exception:
930
+ continue
931
+ sec_system = System()
932
+ sec_run.system.append(sec_system)
933
+ # TODO xyz does not contain cell info right?
934
+ cell = cell if cell is None else atoms.get_cell() * ureg.angstrom
935
+ sec_atoms = Atoms()
936
+ sec_system.atoms = sec_atoms
937
+ sec_atoms.lattice_vectors = cell
938
+ sec_atoms.periodic = pbc
939
+ sec_atoms.positions = atoms.get_positions() * ureg.angstrom
940
+ sec_atoms.labels = atoms.get_chemical_symbols()
941
+ sec_scc.system_ref = sec_system
942
+
943
+ if len(sec_run.calculation) > 0:
944
+ sec_scc = sec_run.calculation[-1]
945
+ # final results are printed only in static/info
946
+ # energies
947
+ energies = self.info_parser.get('energies', {})
948
+ sec_energy = Energy()
949
+ sec_scc.energy = sec_energy
950
+ for key, val in energies.items():
951
+ metainfo_key = self._metainfo_keys_mapping.get(key, None)
952
+ if metainfo_key is None:
953
+ continue
954
+ if metainfo_key.startswith('energy_'):
955
+ sec_energy.m_add_sub_section(
956
+ getattr(Energy, metainfo_key.replace('energy_', '').lower()),
957
+ EnergyEntry(value=val),
958
+ )
959
+ else:
960
+ setattr(sec_scc, metainfo_key, val)
961
+
962
+ # forces
963
+ forces = self.info_parser.get('forces')
964
+ if forces is not None:
965
+ sec_scc.forces = Forces(free=ForcesEntry(value_raw=forces))
966
+
967
+ # eigenvalues
968
+ eigenvalues = self.eigenvalue_parser.get(
969
+ 'eigenvalues', self.info_parser.get('eigenvalues')
970
+ )
971
+ if eigenvalues is not None and eigenvalues.get('eigenvalues') is not None:
972
+ kpts, eigs, occs = list(
973
+ zip(*[e for e in eigenvalues.eigenvalues if e is not None])
974
+ )
975
+ eigs = np.transpose(eigs, axes=(2, 0, 1))
976
+ occs = np.transpose(occs, axes=(2, 0, 1))
977
+ sec_eigenvalues = BandEnergies()
978
+ sec_scc.eigenvalues.append(sec_eigenvalues)
979
+ if len(kpts) > 0:
980
+ sec_eigenvalues.kpoints = kpts
981
+ eigs = eigs * self._units_mapping.get(
982
+ self.info.get('energyunit').lower()
983
+ )
984
+ sec_eigenvalues.energies = eigs
985
+ sec_eigenvalues.occupations = occs
986
+
987
+ fermi_level = eigenvalues.get('fermi_energy')
988
+ if fermi_level is not None:
989
+ sec_energy.fermi = fermi_level
990
+
991
+ converged = self.out_parser.get('x_octopus_info_scf_converged_iterations')
992
+ if converged is not None:
993
+ sec_run.x_octopus_info_scf_converged_iterations = converged
994
+
995
+ sec_scc.method_ref = sec_run.method[-1]
996
+ sec_scc.system_ref = sec_run.system[-1]
997
+
998
+ def parse_system(self):
999
+ sec_run = self.archive.run[-1]
1000
+ sec_system = System()
1001
+ sec_run.system.append(sec_system)
1002
+
1003
+ symbols, coordinates = self.log_parser.get_coordinates()
1004
+ if len(coordinates) == 0:
1005
+ # get if from inp
1006
+ symbols, coordinates = self.inp_parser.get_coordinates()
1007
+ if len(coordinates) == 0:
1008
+ # try to read from file
1009
+ atoms = None
1010
+ file_types = {
1011
+ 'PDBCoordinates': 'proteindatabank',
1012
+ 'XYZCoordinates': 'xyz',
1013
+ 'XSFCoordinates': 'xsf',
1014
+ }
1015
+ for ftype, fformat in file_types.items():
1016
+ filename = self.info.get(ftype)
1017
+ if filename is None:
1018
+ continue
1019
+ try:
1020
+ atoms = read(os.path.join(self.maindir, filename), format=fformat)
1021
+ except Exception:
1022
+ self.logger.error(
1023
+ 'Error reading coordinates file', data=dict(filename=filename)
1024
+ )
1025
+ if atoms is not None:
1026
+ symbols = atoms.get_chemical_symbols()
1027
+ coordinates = atoms.get_positions()
1028
+ break
1029
+
1030
+ if len(coordinates) == 0:
1031
+ self.logger.error('Error parsing atom positions and labels.')
1032
+ return
1033
+
1034
+ sec_atoms = Atoms()
1035
+ sec_system.atoms = sec_atoms
1036
+
1037
+ cell = self.out_parser.get('grid', {}).get('cell')
1038
+ if cell is not None:
1039
+ sec_atoms.lattice_vectors = cell
1040
+ npbc = self.out_parser.get('grid', {}).get('npbc', 3)
1041
+ pbc = [True for _ in range(npbc)]
1042
+ sec_atoms.periodic = pbc + [False] * (3 - len(pbc))
1043
+
1044
+ if self.info.get('ReducedCoordinates', None) is not None and cell is not None:
1045
+ coordinates = np.dot(coordinates, cell.magnitude)
1046
+ units = cell.units
1047
+ elif self.info.get('Coordinates', None) is not None:
1048
+ units = self.info.get('lengthunit')
1049
+ else:
1050
+ # read from ase atoms (in angstroms)
1051
+ units = 'angstrom'
1052
+ sec_atoms.positions = coordinates * self._units_mapping.get(str(units).lower())
1053
+ sec_atoms.labels = symbols
1054
+
1055
+ def parse_method(self):
1056
+ sec_run = self.archive.run[-1]
1057
+ sec_method = Method()
1058
+ sec_run.method.append(sec_method)
1059
+ k_mesh = KMesh()
1060
+ sec_method.k_mesh = k_mesh
1061
+ brillouin_zone_sampling = self.info_parser.get('brillouin_zone_sampling')
1062
+ if brillouin_zone_sampling is not None:
1063
+ if brillouin_zone_sampling.results is not None:
1064
+ k_mesh.grid = brillouin_zone_sampling.results.get('kgrid')
1065
+
1066
+ sec_electronic = Electronic()
1067
+ sec_method.electronic = sec_electronic
1068
+ sec_dft = DFT()
1069
+ sec_method.dft = sec_dft
1070
+
1071
+ # basis set
1072
+ sec_method.electrons_representation.append(
1073
+ BasisSetContainer(
1074
+ type='real-space grid',
1075
+ scope=['wavefunction'],
1076
+ basis_set=[
1077
+ BasisSet(
1078
+ scope=['valence'],
1079
+ type='real-space grid',
1080
+ )
1081
+ ],
1082
+ )
1083
+ )
1084
+
1085
+ # smearing
1086
+ smearing_function = self._smearing_functions.get(
1087
+ self.info.get('SmearingFunction'), None
1088
+ )
1089
+ if smearing_function is not None:
1090
+ sec_electronic.smearing = Smearing(kind=smearing_function)
1091
+ smearing_width = self.info.get('Smearing', None)
1092
+ if smearing_width is not None:
1093
+ sec_electronic.smearing.width = (
1094
+ (
1095
+ smearing_width
1096
+ * self._units_mapping.get(self.info['energyunit'].lower())
1097
+ )
1098
+ .to('joule')
1099
+ .magnitude
1100
+ )
1101
+
1102
+ # check dft+u
1103
+ dft_u = self.info.get('DFTULevel')
1104
+ if dft_u is not None:
1105
+ sec_electronic.method = 'DFT+U'
1106
+ else:
1107
+ theory_level = self._theory_levels.get(
1108
+ self.info.get('TheoryLevel', 4), None
1109
+ )
1110
+ if theory_level is not None:
1111
+ sec_electronic.method = theory_level
1112
+
1113
+ # xc functional
1114
+ xc_functionals = []
1115
+ xc_int_sum = 0
1116
+ xc_functional = self.info.get('XCFunctional', 0)
1117
+ if isinstance(xc_functional, str):
1118
+ xc_functionals = [xc.strip() for xc in xc_functional.upper().split('+')]
1119
+ else:
1120
+ # we try to resolve from output string
1121
+ for key in ['exchange', 'correlation']:
1122
+ val = self.out_parser.get('theory_level', {}).get(key, None)
1123
+ name, number = self._xc_functionals.get(val, (None, 0))
1124
+ if name is not None:
1125
+ xc_functionals.append(name.upper())
1126
+ xc_int_sum += number
1127
+ # get it from log
1128
+ diff = xc_functional - xc_int_sum
1129
+ if diff > 0:
1130
+ names_numbers = list(zip(*self._xc_functionals.values()))
1131
+ while diff > 0:
1132
+ index = np.argmin(abs(np.array(names_numbers[1]) - diff))
1133
+ xc_functionals.append(names_numbers[0][index].upper())
1134
+ diff -= names_numbers[1][index]
1135
+ if diff < 0:
1136
+ xc_functionals = []
1137
+ self.logger.error(
1138
+ 'Error resolving xc functional',
1139
+ data=dict(XCfunctional=xc_functional),
1140
+ )
1141
+ sec_xc_functional = XCFunctional()
1142
+ sec_dft.xc_functional = sec_xc_functional
1143
+ for xc_functional in xc_functionals:
1144
+ if '_X_' in xc_functional or xc_functional.endswith('_X'):
1145
+ sec_xc_functional.exchange.append(Functional(name=xc_functional))
1146
+ elif '_C_' in xc_functional or xc_functional.endswith('_C'):
1147
+ sec_xc_functional.correlation.append(Functional(name=xc_functional))
1148
+ elif 'HYB' in xc_functional:
1149
+ sec_xc_functional.hybrid.append(Functional(name=xc_functional))
1150
+ else:
1151
+ sec_xc_functional.contributions.append(Functional(name=xc_functional))
1152
+
1153
+ method_keys = ['SpinComponents', 'ExcessCharge']
1154
+ for key in method_keys:
1155
+ val = self.info.get(key)
1156
+ metainfo_key = self._metainfo_keys_mapping.get(key, None)
1157
+ if val is None or metainfo_key is None:
1158
+ continue
1159
+ try:
1160
+ setattr(sec_electronic, metainfo_key, int(val))
1161
+ except Exception:
1162
+ self.logger.warning(
1163
+ 'Error setting metainfo', data=dict(key=metainfo_key)
1164
+ )
1165
+
1166
+ # parse keywords from inp and parser.log
1167
+ sources = {'input': self.inp_parser, 'parserlog': self.log_parser}
1168
+ for prefix, source in sources.items():
1169
+ for key, val in source.info.items():
1170
+ try:
1171
+ val = source.info.get(key)
1172
+ quantity_def = sec_run.m_def.all_quantities.get(
1173
+ f'x_octopus_{prefix}_{key}'
1174
+ )
1175
+ if quantity_def is not None:
1176
+ val = (
1177
+ np.array(
1178
+ val,
1179
+ quantity_def.type.standard_type()
1180
+ if hasattr(quantity_def.type, 'standard_type')
1181
+ else quantity_def.type,
1182
+ )
1183
+ if quantity_def.shape
1184
+ else val
1185
+ )
1186
+ sec_run.m_set(quantity_def, val)
1187
+ except Exception:
1188
+ print(key, val)
1189
+ raise
1190
+ self.logger.warning('Error setting metainfo', data=dict(key=key))
1191
+
1192
+ def parse(self, filepath, archive, logger):
1193
+ self.filepath = filepath
1194
+ self.archive = archive
1195
+ self.logger = get_logger(__name__) if logger is None else logger
1196
+
1197
+ self.maindir = os.path.dirname(os.path.abspath(filepath))
1198
+ self.init_parser(filepath, logger)
1199
+
1200
+ sec_run = Run()
1201
+ self.archive.run.append(sec_run)
1202
+ header = self.out_parser.header
1203
+ sec_run.program = Program(
1204
+ name='Octopus', version=str(header.get('Version', ''))
1205
+ )
1206
+ sec_run.x_octopus_log_svn_revision = int(header.get('Revision', 0))
1207
+
1208
+ self.parse_method()
1209
+
1210
+ self.parse_system()
1211
+
1212
+ self.parse_scc()
1213
+
1214
+ archive.workflow2 = GeometryOptimization()