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,1133 @@
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 numpy as np
21
+ import logging
22
+ import re
23
+ from datetime import datetime
24
+ from ase.io import read as ioread
25
+ from ase import Atoms
26
+
27
+ from nomad.units import ureg
28
+ from nomad.parsing.file_parser.file_parser import FileParser
29
+ from nomad.parsing.file_parser import TextParser, Quantity
30
+ from runschema.run import Run, Program, TimeRun
31
+ from runschema.method import (
32
+ Electronic,
33
+ Method,
34
+ DFT,
35
+ Smearing,
36
+ XCFunctional,
37
+ Functional,
38
+ KMesh,
39
+ BasisSet,
40
+ BasisSetContainer,
41
+ OrbitalAPW,
42
+ )
43
+ from runschema.system import System, Atoms
44
+ from runschema.calculation import (
45
+ Calculation,
46
+ Forces,
47
+ ForcesEntry,
48
+ ScfIteration,
49
+ Energy,
50
+ EnergyEntry,
51
+ BandEnergies,
52
+ Dos,
53
+ DosValues,
54
+ )
55
+ from simulationworkflowschema import SinglePoint
56
+ from .metainfo.wien2k import x_wien2k_section_equiv_atoms
57
+
58
+
59
+ class In0Parser(TextParser):
60
+ def __init__(self):
61
+ super().__init__()
62
+
63
+ def init_quantities(self):
64
+ self._quantities = [
65
+ Quantity(
66
+ 'xc_functional', r'(?:TOT|KXC|POT|MULT|COUL|EXCH)\s*([\w ]+)', dtype=str
67
+ ),
68
+ Quantity('fft', r'FFT[\s\S]+?(\d+\s+\d+\s+\d+\s+[\d\.]+)'),
69
+ ]
70
+
71
+
72
+ class In1Parser(FileParser):
73
+ def __init__(self, mainfile=None, logger=None, open=None):
74
+ super().__init__(mainfile, logger=logger, open=open)
75
+
76
+ def parse(self):
77
+ self._results = {'species': []}
78
+ num_orbitals = 0
79
+ with self.open_mainfile_obj() as f:
80
+ for line_id, line in enumerate(f):
81
+ if line_id == 0:
82
+ line = line.strip().split()
83
+ self._results['calc_mode'] = line[0]
84
+ if re.match(r'EF', line[1]):
85
+ self._results['e_ref'] = float(line[1].split('=')[1])
86
+ elif line_id == 1:
87
+ line = line.strip().split()
88
+ for tag, val in zip(['rkmax', 'lmax', 'lvnsmax'], line):
89
+ try:
90
+ self._results[tag] = int(val)
91
+ except ValueError:
92
+ self._results[tag] = float(val)
93
+ elif re.search(r'K-VECTORS', line):
94
+ continue
95
+ # further specify the species setup
96
+ elif num_orbitals > 0:
97
+ line = line.strip().split()
98
+ orbital_settings = {}
99
+ for tag, val in zip(
100
+ ['l', 'e_param', 'e_diff', 'diff_search', 'type'], line[:5]
101
+ ):
102
+ for converter in (int, float, lambda x: x):
103
+ try:
104
+ orbital_settings[tag] = converter(val)
105
+ break
106
+ except ValueError:
107
+ pass
108
+ self._results['species'][-1]['orbital'].append(orbital_settings)
109
+ num_orbitals -= 1
110
+ # add a new species setup
111
+ elif num_orbitals == 0:
112
+ species_settings = {'orbital': []}
113
+ line = line.strip().split()
114
+ species_settings['e_param'] = float(line[0])
115
+ species_settings['type'] = int(line[2])
116
+ self._results['species'].append(species_settings)
117
+ num_orbitals = int(line[1])
118
+
119
+
120
+ class StructParser(TextParser):
121
+ def __init__(self):
122
+ super().__init__()
123
+ self._units_map = {'b': ureg.bohr, 'a': ureg.angstrom}
124
+
125
+ def init_quantities(self):
126
+ re_float = r'[\d\.\-]+'
127
+ re_lat = r'\d+\.\d{6}'
128
+ self._quantities = [
129
+ Quantity(
130
+ 'lattice',
131
+ r'([\s\S]+?)\n *AT',
132
+ sub_parser=TextParser(
133
+ quantities=[
134
+ Quantity(
135
+ 'nonequiv_atoms', r'NONEQUIV\.ATOMS\:\s*(\d+)', dtype=int
136
+ ),
137
+ Quantity('lattice', r'(\w+)\s*LATTICE'),
138
+ Quantity('calc_mode', r'(N*REL\S*)'),
139
+ Quantity(
140
+ 'lattice_constants',
141
+ # fixed precision, sometimes no spaces
142
+ rf'({re_lat})\s*({re_lat})\s*({re_lat})\s*({re_lat})\s*({re_lat})\s*({re_lat})',
143
+ dtype=np.dtype(np.float64),
144
+ ),
145
+ Quantity(
146
+ 'unit',
147
+ r'unit=(\w)',
148
+ str_operation=lambda x: self._units_map.get(x, ureg.bohr),
149
+ ),
150
+ ]
151
+ ),
152
+ ),
153
+ Quantity(
154
+ 'atom',
155
+ r'OM\s+\-*\d+\:\s*(X\=[\s\S]+?)LOCAL',
156
+ repeats=True,
157
+ sub_parser=TextParser(
158
+ quantities=[
159
+ Quantity(
160
+ 'positions',
161
+ rf'X\=({re_float})\s*Y=({re_float})\s*Z=({re_float})',
162
+ repeats=True,
163
+ dtype=np.dtype(np.float64),
164
+ ),
165
+ Quantity('atom_name', r'(\n *[A-Z][a-z]*\d* +)'),
166
+ Quantity('NPT', r'NPT\s*\=\s*(\d+)', dtype=int),
167
+ Quantity('R0', r'R0\s*\=\s*(\d+)', dtype=int),
168
+ Quantity('Z', r'Z\:\s*([\d\.]+)', dtype=np.float64),
169
+ ]
170
+ ),
171
+ ),
172
+ ]
173
+
174
+ def get_atoms(self):
175
+ """
176
+ Returns an ASE atoms representation of the structure.
177
+ """
178
+ if self.mainfile is None:
179
+ return
180
+
181
+ try:
182
+ return ioread(self.mainfile, format='struct')
183
+ except Exception:
184
+ # read it from parsed info
185
+ if self.get('lattice') is None:
186
+ return
187
+
188
+ lattice_constants = self.get('lattice').get('lattice_constants')
189
+ unit = self.get('lattice').get('unit', ureg.bohr)
190
+ lattice_constants[:3] = (
191
+ (lattice_constants[:3] * unit).to('angstrom').magnitude
192
+ )
193
+ scaled_positions = []
194
+ numbers = []
195
+ for atom in self.get('atom', []):
196
+ positions = atom.get('positions', [])
197
+ scaled_positions.extend(positions)
198
+ numbers.extend([int(atom.get('Z', 0))] * len(positions))
199
+
200
+ return Atoms(
201
+ cell=lattice_constants,
202
+ scaled_positions=scaled_positions,
203
+ numbers=numbers,
204
+ pbc=True,
205
+ )
206
+
207
+
208
+ class In2Parser(TextParser):
209
+ def __init__(self):
210
+ super().__init__()
211
+
212
+ def init_quantities(self):
213
+ self._quantities = [
214
+ Quantity('switch', r'(TOT|FOR|QTL|EFG|FERMI)'),
215
+ Quantity('emin', r'([\d\.\- ]+)\s*EMIN'),
216
+ Quantity('smearing', r'(GAUSS|ROOT|TEMP|TETRA|ALL)\s*([\d\.]+)'),
217
+ Quantity('gmax', r'([\d\.\-]+)\s*GMAX'),
218
+ ]
219
+
220
+
221
+ class DosParser(TextParser):
222
+ def __init__(self):
223
+ super().__init__()
224
+
225
+ def init_quantities(self):
226
+ re_f = r'\-*\d+\.\d+'
227
+ self._quantities = [
228
+ Quantity('labels', r'# ENERGY +(.+)', flatten=False),
229
+ Quantity(
230
+ 'data', rf'({re_f} +{re_f}.*)', repeats=True, dtype=np.dtype(np.float64)
231
+ ),
232
+ ]
233
+
234
+
235
+ class OutParser(TextParser):
236
+ def __init__(self):
237
+ super().__init__()
238
+
239
+ def init_quantities(self):
240
+ re_float = r'[\d\.Ee\-\+]+'
241
+
242
+ iteration_quantities = [
243
+ Quantity(
244
+ 'NATO',
245
+ r'(NATO\s*\:[\s\S]+?)\n *\:',
246
+ sub_parser=TextParser(
247
+ quantities=[
248
+ Quantity(
249
+ 'nr_of_independent_atoms', r'(\d+)\s*INDEPENDENT', dtype=int
250
+ ),
251
+ Quantity(
252
+ 'total_atoms', r'(\d+)\s*TOTAL ATOMS IN UNITCELL', dtype=int
253
+ ),
254
+ Quantity('system_name', r'SUBSTANCE:\s*(.+)', flatten=False),
255
+ ]
256
+ ),
257
+ ),
258
+ Quantity(
259
+ 'POT',
260
+ r'(POT\s*\:[\s\S]+?)\n *\:',
261
+ sub_parser=TextParser(
262
+ quantities=[
263
+ Quantity(
264
+ 'potential_option',
265
+ r'POTENTIAL OPTION\s*(.+)',
266
+ dtype=str,
267
+ flatten=False,
268
+ )
269
+ ]
270
+ ),
271
+ ),
272
+ Quantity(
273
+ 'LAT',
274
+ r'(LAT\s*\:[\s\S]+?)\n *\:',
275
+ sub_parser=TextParser(
276
+ quantities=[
277
+ Quantity('lattice_const', r'LATTICE CONSTANTS=\s*([\d\. ]+)')
278
+ ]
279
+ ),
280
+ ),
281
+ Quantity(
282
+ 'VOL',
283
+ r'(VOL\s*\:[\s\S]+?)\n *\:',
284
+ sub_parser=TextParser(
285
+ quantities=[
286
+ Quantity(
287
+ 'unit_cell_volume_bohr3',
288
+ rf'UNIT CELL VOLUME\s*\=\s*({re_float})',
289
+ dtype=np.float64,
290
+ ),
291
+ Quantity(
292
+ 'spinpolarization', r'((?:NON-)*SPINPOLARIZED) CALCULATION'
293
+ ),
294
+ ]
295
+ ),
296
+ ),
297
+ Quantity(
298
+ 'RKM',
299
+ r'(RKM\s*\:[\s\S]+?)\n *\:',
300
+ sub_parser=TextParser(
301
+ quantities=[
302
+ Quantity('matrix_size', r'MATRIX SIZE\s*(\d+)', dtype=int),
303
+ Quantity('LOs', r'LOs:\s*(\d+)', dtype=int),
304
+ Quantity('rkm', r'RKM\=\s*([\d\.]+)', dtype=np.float64),
305
+ ]
306
+ ),
307
+ ),
308
+ Quantity(
309
+ 'KPT',
310
+ r'(KPT\s*\:[\s\S]+?)\n *\:',
311
+ sub_parser=TextParser(
312
+ quantities=[
313
+ Quantity('nr_kpts', r'NUMBER OF K-POINTS:\s*(\d+)', dtype=int)
314
+ ]
315
+ ),
316
+ ),
317
+ Quantity(
318
+ 'GAP',
319
+ r'(GAP\s*\:[\s\S]+?)\n *\:',
320
+ sub_parser=TextParser(
321
+ quantities=[
322
+ Quantity(
323
+ 'ene_gap',
324
+ rf'({re_float})\s*Ry',
325
+ dtype=np.float64,
326
+ unit=ureg.rydberg,
327
+ )
328
+ ]
329
+ ),
330
+ ),
331
+ Quantity(
332
+ 'NOE',
333
+ r'(NOE\s*\:[\s\S]+?)\n *\:',
334
+ sub_parser=TextParser(
335
+ quantities=[
336
+ Quantity(
337
+ 'noe',
338
+ rf'NUMBER OF ELECTRONS\s*\=\s*({re_float})',
339
+ dtype=np.float64,
340
+ )
341
+ ]
342
+ ),
343
+ ),
344
+ Quantity(
345
+ 'FER',
346
+ r'(FER\s*\:[\s\S]+?)\n *\:',
347
+ sub_parser=TextParser(
348
+ quantities=[
349
+ Quantity(
350
+ 'energy_reference_fermi',
351
+ r'F E R M I \- ENERGY.+?\=\s*([\d\.\-\+Ee ]+)',
352
+ str_operation=lambda x: [
353
+ float(v) for v in x.strip().split()
354
+ ]
355
+ * ureg.rydberg,
356
+ convert=False,
357
+ )
358
+ ]
359
+ ),
360
+ ),
361
+ Quantity(
362
+ 'GMA',
363
+ r'(GMA\s*\:[\s\S]+?)\n *\:',
364
+ sub_parser=TextParser(
365
+ quantities=[
366
+ Quantity(
367
+ 'cutoff',
368
+ rf'POTENTIAL AND CHARGE CUT\-OFF\s*({re_float})',
369
+ dtype=np.float64,
370
+ )
371
+ ]
372
+ ),
373
+ ),
374
+ Quantity(
375
+ 'POSi',
376
+ r'(POS\d+\:[\s\S]+?)\n *\:',
377
+ repeats=True,
378
+ sub_parser=TextParser(
379
+ quantities=[
380
+ Quantity('atom_mult', r'MULT.*?\s*\=\s*(\d+)', dtype=int),
381
+ Quantity(
382
+ 'position',
383
+ rf'POSITION\s*\=\s*({re_float}\s*{re_float}\s*{re_float})',
384
+ dtype=np.float64,
385
+ ),
386
+ ]
387
+ ),
388
+ ),
389
+ Quantity(
390
+ 'CHAi',
391
+ r'(CHA\d+\:[\s\S]+?)\n *\:',
392
+ repeats=True,
393
+ sub_parser=TextParser(
394
+ quantities=[
395
+ Quantity(
396
+ 'tot_val_charge_cell',
397
+ rf'TOTAL .+?CHARGE INSIDE.+?\=\s*({re_float})',
398
+ dtype=np.float64,
399
+ )
400
+ ]
401
+ ),
402
+ ),
403
+ Quantity(
404
+ 'SUM',
405
+ r'(SUM\s*\:[\s\S]+?)\n *\:',
406
+ sub_parser=TextParser(
407
+ quantities=[
408
+ Quantity(
409
+ 'energy_sum_eigenvalues',
410
+ rf'SUM OF EIGENVALUES\s*\=\s*({re_float})',
411
+ dtype=np.float64,
412
+ unit=ureg.rydberg,
413
+ )
414
+ ]
415
+ ),
416
+ ),
417
+ Quantity(
418
+ 'RTOi',
419
+ rf'RTO\d+\:\s*\d+\s*({re_float})\s*({re_float})\s*({re_float})\s*({re_float})\s*',
420
+ dtype=np.dtype(np.float64),
421
+ repeats=True,
422
+ ),
423
+ Quantity(
424
+ 'NTO',
425
+ r'(NTO\s*\:[\s\S]+?)\n *\:',
426
+ sub_parser=TextParser(
427
+ quantities=[
428
+ Quantity(
429
+ 'tot_int_charge_nm',
430
+ rf'CHARGE\s*\=\s*({re_float})',
431
+ dtype=np.float64,
432
+ )
433
+ ]
434
+ ),
435
+ ),
436
+ Quantity(
437
+ 'NTOi',
438
+ r'(NTO\d+\:[\s\S]+?)\n *\:',
439
+ repeats=True,
440
+ sub_parser=TextParser(
441
+ quantities=[
442
+ Quantity(
443
+ 'tot_charge_in_sphere_nm',
444
+ rf'CHARGE.+\=\s*({re_float})',
445
+ dtype=np.float64,
446
+ )
447
+ ]
448
+ ),
449
+ ),
450
+ Quantity(
451
+ 'DTOi',
452
+ r'(DTO\d+\:[\s\S]+?)\n *\:',
453
+ repeats=True,
454
+ sub_parser=TextParser(
455
+ quantities=[
456
+ Quantity(
457
+ 'tot_diff_charge',
458
+ rf'TOTAL\s*DIFFERENCE CHARGE.+\=\s*({re_float})',
459
+ dtype=np.float64,
460
+ )
461
+ ]
462
+ ),
463
+ ),
464
+ Quantity(
465
+ 'DIS',
466
+ r'(DIS\s*\:[\s\S]+?)\n *\:',
467
+ sub_parser=TextParser(
468
+ quantities=[
469
+ Quantity(
470
+ 'charge_distance',
471
+ rf'CHARGE DISTANCE.+\)\s*({re_float})',
472
+ dtype=np.float64,
473
+ )
474
+ ]
475
+ ),
476
+ ),
477
+ Quantity(
478
+ 'CTO',
479
+ r'(CTO\s*\:[\s\S]+?)\n *\:',
480
+ sub_parser=TextParser(
481
+ quantities=[
482
+ Quantity(
483
+ 'tot_int_charge',
484
+ rf'CHARGE\s*\=\s*({re_float})',
485
+ dtype=np.float64,
486
+ )
487
+ ]
488
+ ),
489
+ ),
490
+ Quantity(
491
+ 'CTOi',
492
+ r'(CTO\d+\:[\s\S]+?)\n *\:',
493
+ repeats=True,
494
+ sub_parser=TextParser(
495
+ quantities=[
496
+ Quantity(
497
+ 'tot_charge_in_sphere',
498
+ rf'TOTAL\s*CHARGE IN SPHERE.+\=\s*({re_float})',
499
+ dtype=np.float64,
500
+ )
501
+ ]
502
+ ),
503
+ ),
504
+ Quantity(
505
+ 'NECi',
506
+ rf'NEC\d+\:\s*NUCLEAR AND ELECTRONIC CHARGE\s*({re_float})\s*({re_float})',
507
+ dtype=np.dtype(np.float64),
508
+ repeats=True,
509
+ ),
510
+ Quantity(
511
+ 'MMINT',
512
+ r'(MMINT\s*\:[\s\S]+?)\n *\:',
513
+ sub_parser=TextParser(
514
+ quantities=[
515
+ Quantity(
516
+ 'mmint',
517
+ rf'MAGNETIC MOMENT IN INTERSTITIAL\s*\=\s*({re_float})',
518
+ dtype=np.float64,
519
+ )
520
+ ]
521
+ ),
522
+ ),
523
+ Quantity(
524
+ 'MMIi',
525
+ r'(MMI\d+\:[\s\S]+?)\n *\:',
526
+ repeats=True,
527
+ sub_parser=TextParser(
528
+ quantities=[
529
+ Quantity(
530
+ 'mmi',
531
+ rf'MAGNETIC MOMENT IN SPHERE\s*\=\s*({re_float})',
532
+ dtype=np.float64,
533
+ )
534
+ ]
535
+ ),
536
+ ),
537
+ Quantity(
538
+ 'MMTOT',
539
+ r'(MMTOT\s*\:[\s\S]+?)\n *\:',
540
+ sub_parser=TextParser(
541
+ quantities=[
542
+ Quantity(
543
+ 'mmtot',
544
+ rf' MAGNETIC MOMENT IN CELL\s*\=\s*({re_float})',
545
+ dtype=np.float64,
546
+ )
547
+ ]
548
+ ),
549
+ ),
550
+ Quantity(
551
+ 'ENE',
552
+ r'(ENE\s*\:[\s\S]+?)\n',
553
+ sub_parser=TextParser(
554
+ quantities=[
555
+ Quantity(
556
+ 'energy_total',
557
+ rf'TOTAL ENERGY IN Ry\s*\=\s*({re_float})',
558
+ dtype=np.float64,
559
+ unit=ureg.rydberg,
560
+ )
561
+ ]
562
+ ),
563
+ ),
564
+ Quantity(
565
+ 'FORi',
566
+ rf'FOR\d+\:\s*\d+\.ATOM\s*({re_float}\s*{re_float}\s*{re_float}\s*{re_float})',
567
+ repeats=True,
568
+ dtype=np.dtype(np.float64),
569
+ ),
570
+ Quantity(
571
+ 'FGLi',
572
+ rf'FGL\d+\:\s*\d+\.ATOM\s*({re_float}\s*{re_float}\s*{re_float})',
573
+ repeats=True,
574
+ dtype=np.dtype(np.float64),
575
+ ),
576
+ ]
577
+
578
+ self._quantities = [
579
+ Quantity(
580
+ 'version',
581
+ r'LABEL\d+\:\s*using WIEN2k_(\S+) \(Release ([\d\/]+)\)',
582
+ flatten=False,
583
+ ),
584
+ Quantity(
585
+ 'start_date',
586
+ r'LABEL\d+\:\s*on .+ at \w+ (\w+ \d+ \d\d\:\d\d\:\d\d)\s*\w*\s*(\d+)',
587
+ flatten=False,
588
+ ),
589
+ Quantity(
590
+ 'iteration',
591
+ r'\d+\:\s*(\d+\.\s* ITERATION[\s\S]+?)(?:\:ITE|\Z)',
592
+ repeats=True,
593
+ sub_parser=TextParser(quantities=iteration_quantities),
594
+ ),
595
+ ]
596
+
597
+
598
+ class Wien2kParser:
599
+ def __init__(self):
600
+ # TODO complete list and verify if consistent with current implementation
601
+ # http://www.wien2k.at/reg_user/textbooks/usersguide.pdf
602
+ # implement libxc compatibility
603
+ self._xc_functional_map = {
604
+ '5': ['LDA_X', 'LDA_C_PW'],
605
+ '6': ['HF_X'],
606
+ '11': ['GGA_X_WC', 'GGA_C_PBE'],
607
+ '13': ['GGA_X_PBE', 'GGA_C_PBE'],
608
+ '17': ['GGA_X_PW91'],
609
+ '18': ['HYB_GGA_XC_B3PW91'],
610
+ '19': ['GGA_X_PBE_SOL', 'GGA_C_PBE_SOL'],
611
+ '24': ['GGA_X_B88', 'GGA_C_LYP'],
612
+ '28': ['MGGA_X_TB09', 'LDA_C_PW'],
613
+ '27': ['MGGA_X_TPSS', 'MGGA_C_TPSS'],
614
+ '29': ['MGGA_C_REVTPSS, GGA_C_REGTPSS'],
615
+ '46': ['GGA_X_HTBS'],
616
+ '47': ['HYB_GGA_XC_B3LYP'],
617
+ 'XC_LDA': ['LDA_X', 'LDA_C_PW'],
618
+ 'XC_PBE': ['GGA_X_PBE', 'GGA_C_PBE'],
619
+ 'XC_WC': ['GGA_X_WC', 'GGA_C_PBE'],
620
+ 'XC_PBESOL': ['GGA_X_PBE_SOL', 'GGA_C_PBE_SOL'],
621
+ 'XC_B3PW91': ['HYB_GGA_XC_B3PW91'],
622
+ 'XC_B3LYP': ['HYB_GGA_XC_B3LYP'],
623
+ 'XC_MBJ': ['MGGA_X_TB09', 'LDA_C_PW'],
624
+ 'XC_TPSS': ['MGGA_X_TPSS', 'MGGA_C_TPSS'],
625
+ 'XC_REVTPSS': ['MGGA_C_REVTPSS, GGA_C_REGTPSS'],
626
+ 'XC_MGGA_MS': ['MGGA_X_MS', 'MGGA_C_MS'],
627
+ 'XC_MVS': ['MGGA_X_MVS', 'MGGA_C_MVS'],
628
+ 'XC_MBEEF': ['MGGA_X_MBEEF', 'GGA_C_PBE_SOL'],
629
+ 'XC_SCAN': ['MGGA_X_SCAN', 'MGGA_C_SCAN'],
630
+ 'XC_SCANL': ['MGGA_X_SCANL', 'MGGA_C_SCANL'],
631
+ 'XC_RSCAN': ['MGGA_X_RSCAN', 'MGGA_C_RSCAN'],
632
+ 'XC_R2SCAN': ['MGGA_X_R2SCAN', 'MGGA_C_R2SCAN'],
633
+ 'XC_TM': ['MGGA_X_TM', 'MGGA_C_TM'],
634
+ 'EC_PW91': ['GGA_X_PW91'],
635
+ 'VC_PW91': ['GGA_X_PW91'],
636
+ 'EX_B88': ['GGA_X_B88'],
637
+ 'VX_B88': ['GGA_X_B88'],
638
+ 'EC_LYP': ['GGA_C_LYP'],
639
+ 'VC_LYP': ['GGA_C_LYP'],
640
+ 'XC_HTBS': ['GGA_X_HTBS'],
641
+ 'EX_LDA': ['HF_X'],
642
+ 'VX_LDA': ['HF_X'],
643
+ }
644
+
645
+ self.out_parser = OutParser()
646
+ self.in0_parser = In0Parser()
647
+ self.in1_parser = In1Parser()
648
+ self.in2_parser = In2Parser()
649
+ self.struct_parser = StructParser()
650
+ self.dos_parser = DosParser()
651
+
652
+ def init_parser(self):
653
+ self.out_parser.mainfile = self.filepath
654
+ self.out_parser.logger = self.logger
655
+
656
+ def get_wien2k_file(self, ext, multiple=False):
657
+ paths = [p for p in os.listdir(self.maindir) if re.match(rf'.*{ext}$', p)]
658
+ if not paths:
659
+ return [] if multiple else None
660
+ elif len(paths) == 1:
661
+ path = os.path.join(self.maindir, paths[0])
662
+ return [path] if multiple else path
663
+ else:
664
+ prefix = os.path.basename(self.filepath).rsplit('.', 1)[0]
665
+ paths = [
666
+ os.path.join(self.maindir, p) for p in paths if p.startswith(prefix)
667
+ ]
668
+ if not paths:
669
+ return [] if multiple else None
670
+ return paths if multiple else paths[0]
671
+
672
+ def get_nspin(self):
673
+ return (
674
+ 2
675
+ if self.out_parser.get('iteration', [{}])[0]
676
+ .get('VOL', {})
677
+ .get('spinpolarization')
678
+ == 'SPINPOLARIZED'
679
+ else 1
680
+ )
681
+
682
+ def get_kpoints(self):
683
+ k_list_file = self.get_wien2k_file('klist')
684
+ if k_list_file is None:
685
+ return None
686
+
687
+ kpoints = []
688
+ weights = []
689
+ with open(k_list_file) as f:
690
+ while True:
691
+ line = f.readline()
692
+ if not line or 'END' in line:
693
+ break
694
+ try:
695
+ line = np.array(line.split()[:6], dtype=float)
696
+ except Exception:
697
+ continue
698
+ kpoints.append(line[1:4] / line[4])
699
+ weights.append(line[5])
700
+ weights /= sum(weights)
701
+
702
+ return kpoints, weights
703
+
704
+ def get_eigenvalues(self):
705
+ nspin = self.get_nspin()
706
+ if nspin == 1:
707
+ files = self.get_wien2k_file(r'energy\_\d+', multiple=True)
708
+ # sort the files so that the k-points are read in order
709
+ files = sorted(files, key=lambda x: int(x.split('_')[-1]))
710
+ if not files:
711
+ files = [self.get_wien2k_file('energy')]
712
+ else:
713
+ files = []
714
+ for spin in ['up', 'dn']:
715
+ files_spin = self.get_wien2k_file(rf'energy{spin}\_\d+', multiple=True)
716
+ # sort the files so that the k-points are read in order
717
+ files_spin = sorted(files_spin, key=lambda x: int(x.split('_')[-1]))
718
+ if not files_spin:
719
+ files_spin = [self.get_wien2k_file('energy%s' % spin)]
720
+ files.extend(files_spin)
721
+ if None in files:
722
+ return
723
+
724
+ re_k = r'\-?\d\.\d+E[\-\+]\d\d'
725
+ re_kpoint = re.compile(
726
+ rf'\s*({re_k})\s*({re_k})\s*({re_k})\w*\s*(\d+)\s*\d+\s*\d+\s*([\d\.]+)\s*'
727
+ )
728
+ re_eigenvalue = re.compile(r'\s*\d+ +(\-?\d+\.\d+[E\-\+\d]+) *\n*')
729
+ kpoints, eigenvalues, multiplicity, index = [], [], [], []
730
+ for file_i in files:
731
+ with open(file_i) as f:
732
+ while True:
733
+ line = f.readline()
734
+ if not line:
735
+ break
736
+ kpoint = re_kpoint.match(line)
737
+ if kpoint:
738
+ eigenvalues.append([])
739
+ if 'energydn' not in file_i:
740
+ kpoints.append(kpoint.groups()[:3])
741
+ index.append(kpoint.group(4))
742
+ multiplicity.append(kpoint.group(5))
743
+ continue
744
+ eigenvalue = re_eigenvalue.match(line)
745
+ if eigenvalue:
746
+ eigenvalues[-1].append(eigenvalue.group(1))
747
+ try:
748
+ # There can be different amount of eigenvalues calculated at every k-point.
749
+ # However, the metainfo expects a homogeneous array, so just find the k-point
750
+ # with the least amount and discard the extra values at other k-points.
751
+ num_eigvals = [len(eig) for eig in eigenvalues]
752
+ min_eigval_index = min(num_eigvals)
753
+ max_eigval_index = max(num_eigvals)
754
+ if min_eigval_index < max_eigval_index:
755
+ self.logger.warning(
756
+ 'Different number of eigenvalues at different k-points. Truncating the extra values.'
757
+ )
758
+ for i, e in enumerate(eigenvalues):
759
+ eigenvalues[i] = e[:min_eigval_index]
760
+
761
+ eigenvalues = np.array(eigenvalues, dtype=np.dtype(np.float64))
762
+ kpoints = np.array(kpoints, dtype=np.dtype(np.float64))
763
+ multiplicity = np.array(multiplicity, dtype=np.dtype(np.float64))
764
+ eigenvalues = np.reshape(
765
+ eigenvalues, (nspin, len(kpoints), min_eigval_index)
766
+ )
767
+ return eigenvalues, kpoints, multiplicity
768
+ except Exception:
769
+ self.logger.error('Error reading eigenvalues.')
770
+ return
771
+
772
+ def get_dos(self):
773
+ # dos (projections and total) are printed in dos1, dos2....
774
+ nspin = self.get_nspin()
775
+ if nspin == 1:
776
+ files = self.get_wien2k_file(r'dos\d+', multiple=True)
777
+ files.sort()
778
+ else:
779
+ files = []
780
+ for spin in ['up', 'dn']:
781
+ files_spin = self.get_wien2k_file(r'dos\d+%s' % spin, multiple=True)
782
+ files_spin.sort()
783
+ files.extend(files_spin)
784
+
785
+ if not files:
786
+ return
787
+
788
+ dos = []
789
+ labels = []
790
+ for file_i in files:
791
+ self.dos_parser.mainfile = file_i
792
+ data = self.dos_parser.get('data')
793
+ if data is None:
794
+ continue
795
+ if not file_i.endswith('dn'):
796
+ labels.extend(self.dos_parser.get('labels', '').split())
797
+ data = np.transpose(data)
798
+ energy = data[0]
799
+ dos.append(data[1:])
800
+
801
+ try:
802
+ dos = np.vstack(dos)
803
+ dos = np.reshape(dos, (nspin, len(dos) // nspin, len(dos[0])))
804
+ dos = np.transpose(dos, axes=(1, 0, 2))
805
+ total_dos = []
806
+ partial_dos = []
807
+ for n in range(len(dos)):
808
+ # wien2k may not uniformly print out projections, we get only total projections
809
+ # on the species (independent atoms) denoted by the header N:total
810
+ if labels[n].endswith(':total'):
811
+ partial_dos.append(dos[n])
812
+ elif labels[n] == 'total-DOS' or labels[n] == 'TOTAL':
813
+ # TODO determine if total dos is always the last column
814
+ total_dos = dos[n]
815
+ if len(partial_dos) > 0:
816
+ partial_dos = np.transpose(partial_dos, axes=(1, 0, 2))
817
+ return energy, total_dos, partial_dos
818
+
819
+ except Exception:
820
+ self.logger.error('Error reading dos.')
821
+ return
822
+
823
+ def parse_scc(self):
824
+ if self.out_parser.get('iteration') is None:
825
+ return
826
+
827
+ sec_scc = Calculation()
828
+ self.archive.run[0].calculation.append(sec_scc)
829
+
830
+ for iteration in self.out_parser.get('iteration'):
831
+ sec_scf = ScfIteration()
832
+ sec_scc.scf_iteration.append(sec_scf)
833
+ sec_scf_energy = Energy()
834
+ sec_scf.energy = sec_scf_energy
835
+ for key in iteration.keys():
836
+ if iteration.get(key) is None:
837
+ continue
838
+ elif key == 'FORi':
839
+ forces = np.transpose(iteration.get(key))
840
+ sec_scf.x_wien2k_for = np.transpose(forces[1:4])
841
+ sec_scf.x_wien2k_for_abs = forces[0]
842
+ elif key == 'FGLi':
843
+ sec_scf.x_wien2k_for_gl = iteration.get(key)
844
+ elif key == 'MMIi':
845
+ mmi = [mm.mmi for mm in iteration.get(key)]
846
+ if None not in mmi:
847
+ sec_scf.x_wien2k_mmi = [mm.mmi for mm in iteration.get(key)]
848
+ elif key == 'NECi':
849
+ charge = np.transpose(iteration.get(key))
850
+ sec_scf.x_wien2k_nuclear_charge = charge[0]
851
+ sec_scf.x_wien2k_electronic_charge = charge[1]
852
+ elif key == 'CTOi':
853
+ charge = [c.tot_charge_in_sphere for c in iteration.get(key)]
854
+ if None not in charge:
855
+ sec_scf.x_wien2k_tot_charge_in_sphere = charge
856
+ elif key == 'DTOi':
857
+ charge = [c.tot_diff_charge for c in iteration.get(key)]
858
+ if None not in charge:
859
+ sec_scf.x_wien2k_tot_diff_charge = charge
860
+ elif key == 'NTOi':
861
+ charge = [c.tot_charge_in_sphere_nm for c in iteration.get(key)]
862
+ if None not in charge:
863
+ sec_scf.x_wien2k_tot_charge_in_sphere_nm = charge
864
+ elif key == 'RTOi':
865
+ density = np.transpose(iteration.get(key))
866
+ sec_scf.x_wien2k_density_at_nucleus_valence = density[0]
867
+ sec_scf.x_wien2k_density_at_nucleus_semicore = density[1]
868
+ sec_scf.x_wien2k_density_at_nucleus_core = density[2]
869
+ sec_scf.x_wien2k_density_at_nucleus_tot = density[3]
870
+ elif key == 'CHAi':
871
+ charge = [c.tot_val_charge_cell for c in iteration.get(key)]
872
+ sec_scf.x_wien2k_tot_val_charge_sphere = charge
873
+ elif key == 'POSi':
874
+ mult = [p.atom_mult for p in iteration.get(key)]
875
+ sec_scf.x_wien2k_atom_mult = mult
876
+ else:
877
+ for sub_key, val in iteration.get(key, {}).items():
878
+ if sub_key.startswith('energy_reference_fermi'):
879
+ sec_scf_energy.fermi = val[0]
880
+ elif sub_key.startswith('energy_'):
881
+ sec_scf_energy.m_add_sub_section(
882
+ getattr(Energy, sub_key.replace('energy_', '').lower()),
883
+ EnergyEntry(value=val),
884
+ )
885
+ else:
886
+ setattr(sec_scf, 'x_wien2k_%s' % sub_key, val)
887
+
888
+ # write final iteration values to scc
889
+ if sec_scf.energy.total is not None:
890
+ sec_scc.energy = Energy(total=EnergyEntry(value=sec_scf.energy.total.value))
891
+ if sec_scf.energy.fermi is not None:
892
+ sec_scc.energy.fermi = sec_scf.energy.fermi
893
+
894
+ if sec_scf.x_wien2k_for_gl is not None:
895
+ forces = []
896
+ for n, force in enumerate(sec_scf.x_wien2k_for_gl):
897
+ forces.extend([force] * sec_scf.x_wien2k_atom_mult[n])
898
+ sec_scc.forces = Forces(
899
+ total=ForcesEntry(value=forces * (ureg.mRy / ureg.bohr))
900
+ )
901
+
902
+ # eigenvalues
903
+ eigenvalues = self.get_eigenvalues()
904
+ if eigenvalues is not None:
905
+ sec_eigenvalues = BandEnergies()
906
+ sec_scc.eigenvalues.append(sec_eigenvalues)
907
+ sec_eigenvalues.kpoints = eigenvalues[1]
908
+ sec_eigenvalues.kpoints_multiplicities = eigenvalues[2]
909
+ sec_eigenvalues.energies = eigenvalues[0] * ureg.rydberg
910
+
911
+ # dos
912
+ dos = self.get_dos()
913
+ if dos is not None:
914
+ # total dos
915
+ if len(dos[1]) > 0:
916
+ n_spin_channels = len(dos[1])
917
+ for spin in range(n_spin_channels):
918
+ sec_dos = Dos()
919
+ sec_scc.dos_electronic.append(sec_dos)
920
+ sec_dos.spin_channel = spin if n_spin_channels == 2 else None
921
+ sec_dos.energies = dos[0] * ureg.rydberg
922
+ sec_dos_total = DosValues()
923
+ sec_dos.total.append(sec_dos_total)
924
+ sec_dos_total.value = dos[1][spin] * (1 / ureg.rydberg)
925
+
926
+ # projected dos
927
+ if len(dos[2]) > 0:
928
+ labels = [a.atom_name for a in self.struct_parser.get('atom', [])]
929
+ if len(labels) == 0:
930
+ self.logger.warning('Cannot resolve atom labels.')
931
+ else:
932
+ for species in range(len(dos[2])):
933
+ for spin in range(len(dos[2][species])):
934
+ if sec_scc.dos_electronic is not None:
935
+ sec_dos = sec_scc.dos_electronic[spin]
936
+ else:
937
+ sec_dos = Dos()
938
+ sec_scc.dos_electronic.append(sec_dos)
939
+ sec_dos.spin_channel = (
940
+ spin if len(dos[2][species]) == 2 else None
941
+ )
942
+ sec_dos_species = DosValues()
943
+ sec_dos.species_projected.append(sec_dos_species)
944
+ sec_dos_species.atom_label = labels[species]
945
+ sec_dos_species.value = dos[2][species][spin] * (
946
+ 1 / ureg.rydberg
947
+ )
948
+
949
+ def parse_system(self):
950
+ sec_system = System()
951
+ self.archive.run[0].system.append(sec_system)
952
+ sec_atoms = Atoms()
953
+ sec_system.atoms = sec_atoms
954
+
955
+ self.struct_parser.mainfile = self.get_wien2k_file('struct')
956
+ for key, val in self.struct_parser.get('lattice', {}).items():
957
+ setattr(sec_system, 'x_wien2k_%s' % key, val)
958
+
959
+ for atom in self.struct_parser.get('atom', []):
960
+ sec_atom = x_wien2k_section_equiv_atoms()
961
+ sec_system.x_wien2k_section_equiv_atoms.append(sec_atom)
962
+ for key, val in atom.items():
963
+ setattr(sec_atom, 'x_wien2k_%s' % key, val)
964
+
965
+ atoms = self.struct_parser.get_atoms()
966
+ if atoms is None:
967
+ return
968
+
969
+ sec_atoms.lattice_vectors = np.array(atoms.get_cell()) * ureg.angstrom
970
+ sec_atoms.positions = atoms.get_positions() * ureg.angstrom
971
+ sec_atoms.labels = atoms.get_chemical_symbols()
972
+ sec_atoms.periodic = atoms.get_pbc()
973
+
974
+ def parse_method(self):
975
+ sec_method = Method()
976
+ self.archive.run[0].method.append(sec_method)
977
+ sec_dft = DFT()
978
+ sec_method.dft = sec_dft
979
+ sec_electronic = Electronic()
980
+ sec_method.electronic = sec_electronic
981
+ sec_electronic.method = 'DFT'
982
+ sec_electronic.n_spin_channels = self.get_nspin()
983
+
984
+ # read functional settings from in0 file
985
+ self.in0_parser.mainfile = self.get_wien2k_file('in0')
986
+
987
+ # better to read it from scf?
988
+ xc_functional = self.in0_parser.get('xc_functional', None)
989
+ xc_functional = (
990
+ xc_functional if isinstance(xc_functional, list) else [xc_functional]
991
+ )
992
+ sec_xc_functional = XCFunctional()
993
+ sec_dft.xc_functional = sec_xc_functional
994
+ for name in xc_functional:
995
+ functionals = self._xc_functional_map.get(name)
996
+ if functionals is None:
997
+ self.logger.warning('Cannot resolve XC functional.')
998
+ continue
999
+ for functional in functionals:
1000
+ if '_X_' in functional or functional.endswith('_X'):
1001
+ sec_xc_functional.exchange.append(Functional(name=functional))
1002
+ elif '_C_' in functional or functional.endswith('_C'):
1003
+ sec_xc_functional.correlation.append(Functional(name=functional))
1004
+ elif 'HYB' in functional:
1005
+ sec_xc_functional.hybrid.append(Functional(name=functional))
1006
+ else:
1007
+ sec_xc_functional.contributions.append(Functional(name=functional))
1008
+
1009
+ fft = self.in0_parser.get('fft')
1010
+ if fft is not None:
1011
+ sec_method.x_wien2k_ifft = fft[:3]
1012
+ sec_method.x_wien2k_ifft_factor = fft[3]
1013
+
1014
+ # read cut off settings from in1
1015
+ in1_file = self.get_wien2k_file('in1')
1016
+ if in1_file is None:
1017
+ in1_file = self.get_wien2k_file('in1c')
1018
+ self.in1_parser.mainfile = in1_file
1019
+
1020
+ # read integration data from in2 file
1021
+ in2_file = self.get_wien2k_file('1n2')
1022
+ if in2_file is None:
1023
+ in2_file = self.get_wien2k_file('in2c')
1024
+ self.in2_parser.mainfile = in2_file
1025
+
1026
+ for key in ['gmax', 'switch']:
1027
+ val = self.in2_parser.get(key)
1028
+ if val is not None:
1029
+ setattr(sec_method, 'x_wien2k_in2_%s' % key, val)
1030
+
1031
+ emin_keys = ['emin', 'ne', 'espermin', 'esper0']
1032
+ for n, val in enumerate(self.in2_parser.get('emin', [])):
1033
+ if n < 4:
1034
+ setattr(sec_method, 'x_wien2k_in2_%s' % emin_keys[n], val)
1035
+
1036
+ smearing, width = self.in2_parser.get('smearing', [None, None])
1037
+ if smearing is not None:
1038
+ sec_smearing = Smearing()
1039
+ sec_electronic.smearing = sec_smearing
1040
+ if smearing.startswith('GAUSS'):
1041
+ smearing = 'gaussian'
1042
+ elif smearing.startswith('TEMP'):
1043
+ smearing = 'fermi'
1044
+ elif smearing.startswith('TETRA'):
1045
+ smearing = 'tetrahedra'
1046
+ sec_smearing.kind = smearing
1047
+ sec_smearing.width = (float(width) * ureg.rydberg).to('joule').magnitude
1048
+
1049
+ # read kpoints from klist
1050
+ kpoints = self.get_kpoints()
1051
+ if kpoints is not None:
1052
+ sec_k_mesh = KMesh()
1053
+ sec_method.k_mesh = sec_k_mesh
1054
+ sec_k_mesh.points = kpoints[0]
1055
+ sec_k_mesh.weights = kpoints[1]
1056
+
1057
+ # basis
1058
+ if self.in1_parser.mainfile:
1059
+ self.in1_parser.parse()
1060
+ if self.in1_parser._results:
1061
+ type_mapping = ('LAPW', 'APW', 'HDLO', 'LO')
1062
+ source = self.in1_parser._results
1063
+ em = BasisSetContainer(scope=['wavefunction'])
1064
+ em.basis_set.append(
1065
+ BasisSet(
1066
+ scope=['intersitial', 'valence'],
1067
+ type='plane waves',
1068
+ cutoff_fractional=source.get('rkmax'),
1069
+ )
1070
+ )
1071
+ for mt in source.get('species', []):
1072
+ bs = BasisSet(
1073
+ scope=['muffin-tin', 'full-electron'],
1074
+ spherical_harmonics_cutoff=source.get('lmax'),
1075
+ )
1076
+ for l_n in range(source.get('lmax', -1) + 1):
1077
+ orbital = OrbitalAPW()
1078
+ orbital.l_quantum_number = l_n
1079
+ orbital.core_level = False
1080
+ e_param = mt.get(
1081
+ 'e_param', source.get('e_ref', 0.5) - 0.2
1082
+ ) # TODO: check for +.2 case
1083
+ update = False
1084
+ apw_type = mt.get('type')
1085
+ last_orbital_type = None
1086
+ for orb in mt['orbital']:
1087
+ if l_n == orb['l']:
1088
+ e_param = orb.get('e_param', e_param)
1089
+ update = orb.get('e_diff', 0) is not None
1090
+ apw_type = orb.get('type', apw_type)
1091
+ if last_orbital_type == apw_type:
1092
+ orbital.energy_parameter = [e_param]
1093
+ orbital.update = update
1094
+ orbital.type = type_mapping[3]
1095
+ continue
1096
+ last_orbital_type = apw_type
1097
+ orbital.energy_parameter = [e_param]
1098
+ orbital.update = update
1099
+ orbital.type = type_mapping[apw_type]
1100
+ bs.orbital.append(orbital)
1101
+ em.basis_set.append(bs)
1102
+ sec_method.electrons_representation.append(em)
1103
+
1104
+ def parse(self, filepath, archive, logger):
1105
+ self.filepath = os.path.abspath(filepath)
1106
+ self.archive = archive
1107
+ self.maindir = os.path.dirname(self.filepath)
1108
+ self.logger = logger if logger is not None else logging.getLogger(__name__)
1109
+
1110
+ self.init_parser()
1111
+
1112
+ sec_run = Run()
1113
+ self.archive.run.append(sec_run)
1114
+
1115
+ sec_run.program = Program(
1116
+ name='WIEN2k', version=self.out_parser.get('version', '')
1117
+ )
1118
+ start_date = self.out_parser.get('start_date')
1119
+ if start_date is not None:
1120
+ # TODO resolve proper timezone
1121
+ dt = datetime.strptime(
1122
+ start_date, '%b %d %H:%M:%S %Y'
1123
+ ) - datetime.utcfromtimestamp(0)
1124
+ sec_run.time_run = TimeRun(date_start=dt.total_seconds())
1125
+
1126
+ # TODO implement geometry optimization
1127
+ archive.workflow2 = SinglePoint()
1128
+
1129
+ self.parse_method()
1130
+
1131
+ self.parse_system()
1132
+
1133
+ self.parse_scc()