Skip to content

Commit 8d2dd40

Browse files
committed
Various fixes
1 parent 6cfec1c commit 8d2dd40

File tree

8 files changed

+65
-14
lines changed

8 files changed

+65
-14
lines changed

src/nomad_simulation_parsers/parsers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Wannier90ParserEntryPoint(EntryPoint):
6363
description='NOMAD parser for CRYSTAL.',
6464
python_package='nomad_simulation_parsers',
6565
mainfile_contents_re=r'(\r?\n \*\s+CRYSTAL[\d]+\s+\*\r?\n \*\s*[a-zA-Z]+ :'
66-
' \d+[\.\d+]*)',
66+
r' \d+[\.\d+]*)',
6767
parser_class_name='nomad_simulation_parsers.parsers.crystal.parser.CrystalParser',
6868
code_name='CRYSTAL',
6969
code_homepage='https://www.crystal.unito.it/',

src/nomad_simulation_parsers/parsers/crystal/parser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88
import pint
9+
from ase.data import chemical_symbols
910
from nomad import atomutils
1011
from nomad.datamodel import EntryArchive
1112
from nomad.parsing import MatchingParser
@@ -104,10 +105,13 @@ def get_atoms(self, source: dict[str, Any]) -> list[str]:
104105

105106
def normalize_label(label: str) -> str:
106107
norm = re.match(r'([a-z][a-z]?).*', label.lower())
107-
if norm:
108-
return norm.group(1).capitalize()
109108
# unknown specie
110-
return 'X'
109+
# TODO not possible to define ghost atom
110+
unknown = None
111+
if norm:
112+
label = norm.group(1).capitalize()
113+
return label if label in chemical_symbols[1:] else unknown
114+
return unknown
111115

112116
return [
113117
dict(label=normalize_label(label), number=numbers[n])

src/nomad_simulation_parsers/parsers/fhiaims/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def init_quantities(self) -> None:
3939
]
4040

4141
def get_atoms(self) -> Atoms:
42-
return Atoms(
42+
atoms = Atoms(
4343
cell=self.lattice_vector,
4444
pbc=self.lattice_vector is not None,
4545
positions=[
@@ -51,7 +51,15 @@ def get_atoms(self) -> Atoms:
5151
symbols=[atom.label for atom in self.atom],
5252
magmoms=self.magmom,
5353
)
54-
54+
# TODO compatibility with PhonopyAtoms
55+
add_attribs = dict(
56+
masses=atoms.get_masses(),
57+
magnetic_moments=None,
58+
scaled_positions=atoms.get_scaled_positions(),
59+
)
60+
for key, val in add_attribs.items():
61+
setattr(atoms, key, val)
62+
return atoms
5563

5664
class ControlParser(TextParser):
5765
def __init__(self):

src/nomad_simulation_parsers/parsers/fhiaims/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ def is_mainfile(
602602
children = ['phonon', 'phonon_workflow']
603603

604604
if children:
605-
self.level = 1
605+
# TODO not possible at the moment to redefine level
606+
# self.level = 1
606607
self.creates_children = True
607608

608609
return children or is_mainfile

src/nomad_simulation_parsers/parsers/quantumespresso/parser.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ class QuantumEspressoParser(MatchingParser):
216216
"""
217217

218218
archive_writer = QuantumEspressoArchiveWriter()
219+
_levels = {}
220+
_mainfile = None
221+
222+
@property
223+
def level(self):
224+
return self._levels.pop(self._mainfile, self._level)
225+
226+
@level.setter
227+
def level(self, value: int):
228+
self._level = value
219229

220230
def is_mainfile(
221231
self,
@@ -239,7 +249,10 @@ def is_mainfile(
239249
continue
240250
programs.append(f'{len(programs)} {match.group(1)}')
241251
if 'pwscf' in programs[0].lower():
242-
self.level = 2
252+
# TODO not possible at the moment to redefine level
253+
self._levels[filename] = 2
254+
self._mainfile = filename
255+
# self.level = 2
243256
# search all qe mainfiles in the directory and sub directories
244257
qe_files = search_files(
245258
'*.out', os.path.dirname(filename), include_all=True
@@ -266,5 +279,4 @@ def parse(
266279
logger: BoundLogger,
267280
child_archives: dict[str, EntryArchive] = {},
268281
) -> None:
269-
print('PPPP')
270282
self.archive_writer.write(mainfile, archive, logger, child_archives)

src/nomad_simulation_parsers/parsers/vasp/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def parse(
2525
mainfile: str,
2626
archive: 'EntryArchive',
2727
logger: 'BoundLogger',
28-
child_archives: dict[str, 'EntryArchive'] = None,
28+
child_archives: dict[str, 'EntryArchive'] = {},
2929
) -> None:
3030
# reload schema to load vasp annotations
3131
reload(vasp)

src/nomad_simulation_parsers/parsers/vasp/xml_parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_eigenvalues(self, array: list) -> dict[str, Any]:
3636
return dict(eigenvalues=transposed[0], occupations=transposed[1])
3737

3838
def get_energy_contributions(
39-
self, source: dict[str, Any], **kwargs
39+
self, source: list[dict[str, Any]], **kwargs
4040
) -> list[dict[str, Any]]:
4141
return [
4242
c
@@ -60,6 +60,13 @@ def get_forces(self, source: dict[str, Any]) -> dict[str, Any]:
6060
return {}
6161
return dict(forces=value, npoints=len(value), rank=[3])
6262

63+
def reshape_array(self, source: np.ndarray, shape_rest: tuple = (3,)) -> np.ndarray:
64+
if source is None:
65+
return
66+
return np.reshape(
67+
source, (np.size(source) // int(np.prod(shape_rest)), *shape_rest)
68+
)
69+
6370

6471
class XMLArchiveWriter(ArchiveWriter):
6572
def write_to_archive(self) -> None:

src/nomad_simulation_parsers/schema_packages/vasp.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,29 @@ class KMesh(numerical_settings.KMesh):
166166
numerical_settings.KMesh.points.m_annotations.setdefault(
167167
MAPPING_ANNOTATION_KEY, {}
168168
).update(
169-
dict(xml=MapperAnnotation(mapper='.varray[?"@name"==\'kpointlist\'].v | [0]'))
169+
dict(
170+
xml=MapperAnnotation(
171+
mapper=(
172+
'reshape_array',
173+
['.varray[?"@name"==\'kpointlist\'].v | [0]'],
174+
dict(shape_rest=(3)),
175+
)
176+
)
177+
)
170178
)
171179

172180
numerical_settings.KMesh.weights.m_annotations.setdefault(
173181
MAPPING_ANNOTATION_KEY, {}
174182
).update(
175-
dict(xml=MapperAnnotation(mapper='.varray[?"@name"==\'weights\'].v | [0]'))
183+
dict(
184+
xml=MapperAnnotation(
185+
mapper=(
186+
'reshape_array',
187+
['.varray[?"@name"==\'weights\'].v | [0]'],
188+
dict(shape_rest=()),
189+
)
190+
)
191+
)
176192
)
177193

178194

@@ -193,7 +209,10 @@ class AtomicCell(model_system.AtomicCell):
193209
MAPPING_ANNOTATION_KEY, {}
194210
).update(
195211
dict(
196-
xml=MapperAnnotation(mapper='.varray.v', unit='angstrom'),
212+
xml=MapperAnnotation(
213+
mapper=('reshape_array', ['.varray.v'], dict(shape_rest=(3))),
214+
unit='angstrom',
215+
),
197216
outcar=MapperAnnotation(
198217
mapper='.positions_forces', unit='angstrom', search='@ | [0]'
199218
),

0 commit comments

Comments
 (0)