Skip to content

Commit d0315a6

Browse files
committed
Fix ruff check issues (E501 line too long)
Changes: - Extract POTCAR regex pattern to module-level constant - Break long log messages and comments to fit 88 char limit - Auto-format multiline function calls and annotations - Remove unused import in test file All ruff checks now pass.
1 parent d2df29e commit d0315a6

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

src/nomad_simulation_parsers/parsers/vasp/outcar_parser.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ def convert(v):
6060
Quantity('RCORE', r'RCORE\s*=\s*([\d\.]+)', dtype=float),
6161
Quantity('ENMAX', r'ENMAX\s*=\s*([\d\.]+)', dtype=float),
6262
Quantity('ENMIN', r'ENMIN\s*=\s*([\d\.]+)', dtype=float),
63-
Quantity('LPAW', r'LPAW\s*=\s*([TF])', dtype=bool), ## doublecheck mapping
64-
Quantity('LULTRA', r'LULTRA\s*=\s*([TF])', dtype=bool), ## doublecheck mapping
65-
Quantity('LMAX', r'number of l-projection\s+operators is LMAX\s*=\s*(\d+)', dtype=int),
66-
Quantity('LMMAX', r'number of lm-projection\s+operators is LMMAX\s*=\s*(\d+)', dtype=int),
63+
Quantity('LPAW', r'LPAW\s*=\s*([TF])', dtype=bool), ## doublecheck mapping
64+
Quantity('LULTRA', r'LULTRA\s*=\s*([TF])', dtype=bool), ## doublecheck mapping
65+
Quantity(
66+
'LMAX', r'number of l-projection\s+operators is LMAX\s*=\s*(\d+)', dtype=int
67+
),
68+
Quantity(
69+
'LMMAX', r'number of lm-projection\s+operators is LMMAX\s*=\s*(\d+)', dtype=int
70+
),
6771
Quantity('SHA256', r'SHA256\s*=\s*(\w+)', dtype=str),
6872
]
6973

74+
# Regex pattern for POTCAR sections in OUTCAR
75+
POTCAR_PATTERN = (
76+
r'POTCAR:([\s\S]+?VRHFIN[\s\S]+?)'
77+
r'(?=\s*POTCAR:|\s*local pseudopotential:|\Z)'
78+
)
79+
7080

7181
# TODO temporary fix for structlog unable to propagate logger
7282
class VASPMetainfoParser(MetainfoParser):
@@ -336,7 +346,7 @@ def str_to_eigenvalues(val_in):
336346
),
337347
Quantity(
338348
'pseudopotentials',
339-
r'POTCAR:([\s\S]+?VRHFIN[\s\S]+?)(?=\s*POTCAR:|\s*local pseudopotential:|\Z)',
349+
POTCAR_PATTERN,
340350
repeats=True,
341351
sub_parser=TextParser(quantities=potcar_quantities),
342352
),
@@ -536,7 +546,6 @@ def derive_is_gw_optimized(self, titel: str) -> bool:
536546
return titel is not None and '_GW' in titel
537547

538548

539-
540549
class OutcarArchiveWriter(ArchiveWriter):
541550
def write_to_archive(self) -> None:
542551
# set up archive parser

src/nomad_simulation_parsers/parsers/vasp/xml_parser.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def reshape_array(self, source: np.ndarray, shape_rest: tuple = (3,)) -> np.ndar
7676
)
7777

7878

79-
8079
class XMLArchiveWriter(ArchiveWriter):
8180
def write_to_archive(self) -> None:
8281
data_parser = VASPMetainfoParser()
@@ -106,22 +105,27 @@ def write_to_archive(self) -> None:
106105
outcar_path = self._find_outcar()
107106
if outcar_path and os.path.exists(outcar_path):
108107
LOGGER.info(
109-
f'Found OUTCAR at {outcar_path}, extending vasprun.xml pseudopotentials '
110-
'with detailed metadata'
108+
f'Found OUTCAR at {outcar_path}, extending vasprun.xml '
109+
'pseudopotentials with detailed metadata'
111110
)
112111
from nomad.parsing.file_parser import Quantity, TextParser
113112
from nomad.parsing.file_parser.mapping_parser import (
114113
TextParser as MappingTextParser,
115114
)
115+
116116
from nomad_simulation_parsers.parsers.vasp.outcar_parser import (
117117
potcar_quantities,
118118
)
119119

120+
potcar_pattern = (
121+
r'POTCAR:([\s\S]+?VRHFIN[\s\S]+?)'
122+
r'(?=\s*POTCAR:|\s*local pseudopotential:|\Z)'
123+
)
120124
outcar_supplement_parser = TextParser(
121125
quantities=[
122126
Quantity(
123127
'pseudopotentials',
124-
r'POTCAR:([\s\S]+?VRHFIN[\s\S]+?)(?=\s*POTCAR:|\s*local pseudopotential:|\Z)',
128+
potcar_pattern,
125129
repeats=True,
126130
sub_parser=TextParser(quantities=potcar_quantities),
127131
)
@@ -136,8 +140,8 @@ def write_to_archive(self) -> None:
136140
# This preserves XML structure while adding OUTCAR's detailed metadata
137141
outcar_parser.convert(data_parser, update_mode='merge')
138142

139-
# Clean up duplicate pseudopotentials created by type mismatch during merge
140-
# When PP_OUT tries to merge at index 0 but finds KSpace, it creates a new PP
143+
# Clean up duplicate pseudopotentials created by type mismatch
144+
# When PP_OUT merges at index 0 but finds KSpace, creates new PP
141145
model_method = data_parser.data_object.model_method[0]
142146
seen_pp_names = set()
143147
deduplicated_ns = []
@@ -170,6 +174,10 @@ def _find_outcar(self) -> str | None:
170174
"""
171175
mainfile_dir = PathLib(self.mainfile).parent
172176
return next(
173-
(str(f) for f in mainfile_dir.iterdir() if f.name.lower().startswith('outcar')),
174-
None
177+
(
178+
str(f)
179+
for f in mainfile_dir.iterdir()
180+
if f.name.lower().startswith('outcar')
181+
),
182+
None,
175183
)

src/nomad_simulation_parsers/schema_packages/vasp.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class Simulation(general.Simulation):
5454
add_mapping_annotation(general.ModelMethod.m_def, KPOINTS_XML, '.@')
5555
add_mapping_annotation(general.ModelMethod.m_def, PP_XML, '.@')
5656
add_mapping_annotation(general.ModelMethod.m_def, PP_OUT, '.@')
57-
add_mapping_annotation(
58-
general.Simulation.model_system, XML_KEY, '.calculation'
59-
)
57+
add_mapping_annotation(general.Simulation.model_system, XML_KEY, '.calculation')
6058
add_mapping_annotation(general.Simulation.model_system, OUTCAR_KEY, '.calculation')
6159
add_mapping_annotation(general.Simulation.outputs, XML_KEY, '.calculation')
6260
add_mapping_annotation(general.Simulation.outputs, XML2_KEY, '.calculation')
@@ -80,7 +78,9 @@ class Program(general.Program):
8078

8179
class ModelMethod(general.ModelMethod):
8280
add_mapping_annotation(
83-
numerical_settings.Pseudopotential.m_def, PP_XML, '.atominfo.array[?"@name"==\'atomtypes\'] | [0].set.rc'
81+
numerical_settings.Pseudopotential.m_def,
82+
PP_XML,
83+
'.atominfo.array[?"@name"==\'atomtypes\'] | [0].set.rc',
8484
)
8585

8686

@@ -114,6 +114,7 @@ class XCComponent(model_method.XCComponent):
114114
model_method.XCComponent.canonical_label, OUTCAR_KEY, '.name'
115115
)
116116

117+
117118
class KSpace(numerical_settings.KSpace):
118119
add_mapping_annotation(numerical_settings.KSpace.k_mesh, KPOINTS_XML, '.@')
119120

@@ -347,12 +348,8 @@ class Pseudopotential(numerical_settings.Pseudopotential):
347348
'.RCORE',
348349
unit='angstrom',
349350
)
350-
add_mapping_annotation(
351-
numerical_settings.Pseudopotential.l_max, PP_OUT, '.LMAX'
352-
)
353-
add_mapping_annotation(
354-
numerical_settings.Pseudopotential.lm_max, PP_OUT, '.LMMAX'
355-
)
351+
add_mapping_annotation(numerical_settings.Pseudopotential.l_max, PP_OUT, '.LMAX')
352+
add_mapping_annotation(numerical_settings.Pseudopotential.lm_max, PP_OUT, '.LMMAX')
356353
add_mapping_annotation(
357354
numerical_settings.Pseudopotential.type,
358355
PP_OUT,
@@ -375,4 +372,5 @@ class Pseudopotential(numerical_settings.Pseudopotential):
375372
except Exception as e:
376373
print(f'[ERROR] Failed to initialize VASP schema package: {e}', flush=True)
377374
import traceback
375+
378376
traceback.print_exc()

tests/parsers/test_vasp_parser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from nomad.utils import get_logger
33

44
from nomad_simulation_parsers.parsers.vasp.parser import VASPParser
5-
from tests.parsers.utils import approx
65

76
LOGGER = get_logger(__name__)
87

0 commit comments

Comments
 (0)