Skip to content

Commit

Permalink
Adding nomad-lab[infrastructure] for connecting with DFT entries
Browse files Browse the repository at this point in the history
Clean up of methods
  • Loading branch information
JosePizarro3 committed Jul 29, 2024
1 parent 7d780da commit 8f1b05e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ maintainers = [
license = { file = "LICENSE" }
dependencies = [
"nomad-lab>=1.3.0",
"nomad-simulations>=0.0.2",
"nomad-simulations>=0.0.3",
]

[project.urls]
Expand All @@ -39,7 +39,8 @@ dev = [
"pytest",
"pytest-timeout",
"pytest-cov",
"structlog"
"structlog",
"nomad-lab[infrastructure]", # for search and MetadataRequired to work
]

[tool.ruff]
Expand Down
1 change: 1 addition & 0 deletions src/nomad_parser_wannier90/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def load(self):
nomad_parser_wannier90_plugin = Wannier90ParserEntryPoint(
name='Wannier90ParserEntryPoint',
description='Entry point for the Wannier90 parser.',
parser_as_interface=False, # in order to use `child_archives` and auto workflows
level=1,
mainfile_contents_re=r'\|\s*WANNIER90\s*\|',
)
4 changes: 3 additions & 1 deletion src/nomad_parser_wannier90/parsers/band_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def parse_band_structure(

# Resolving `reciprocal_lattice_vectors` from `KSpace` method
try:
rlv = k_space.resolve_reciprocal_lattice_vectors(model_systems, logger)
rlv = k_space.resolve_reciprocal_lattice_vectors(
model_systems=model_systems, logger=logger
)
except Exception:
logger.error(
'Could not resolve the reciprocal lattice vectors for obtaining the band structure.'
Expand Down
56 changes: 36 additions & 20 deletions src/nomad_parser_wannier90/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ def __init__(self, *args, **kwargs):
'Nband': 'n_bloch_bands',
}

def init_parser(self, logger: 'BoundLogger') -> None:
"""
Initialize the `WOutParser` with the mainfile and logger.
Args:
logger (BoundLogger): The logger to log messages.
"""
self.wout_parser.mainfile = self.mainfile
self.wout_parser.logger = logger

def parse_atoms_state(self, labels: Optional[list[str]]) -> list[AtomsState]:
"""
Parse the `AtomsState` from the labels by storing them as the `chemical_symbols`.
Expand Down Expand Up @@ -249,7 +259,7 @@ def parse_atomic_cell(self) -> AtomicCell:
# Parsing `atoms_state` from `structure`
labels = self.wout_parser.get('structure', {}).get('labels')
if labels is not None:
atoms_state = self.parse_atoms_state(labels)
atoms_state = self.parse_atoms_state(labels=labels)
atomic_cell.atoms_state = atoms_state
# and parsing `positions`
if self.wout_parser.get('structure', {}).get('positions') is not None:
Expand Down Expand Up @@ -385,31 +395,37 @@ def parse_outputs(self, simulation: Simulation, logger: 'BoundLogger') -> Output
outputs.model_method_ref = simulation.model_method[-1]

# Parse hoppings
hr_files = get_files('*hr.dat', self.filepath, self.mainfile)
hr_files = get_files(
pattern='*hr.dat', filepath=self.mainfile, stripname=self.basename
)
if len(hr_files) > 1:
logger.info('Multiple `*hr.dat` files found.')
# contains information about `n_orbitals`
wannier_method = simulation.m_xpath('model_method[-1]', dict=False)
for hr_file in hr_files:
hopping_matrix, crystal_field_splitting = Wannier90HrParser(
hr_file
hr_file=hr_file
).parse_hoppings(wannier_method=wannier_method, logger=logger)
if hopping_matrix is not None:
outputs.hopping_matrices.append(hopping_matrix)
if crystal_field_splitting is not None:
outputs.crystal_field_splittings.append(crystal_field_splitting)

# Parse DOS
dos_files = get_files('*dos.dat', self.filepath, self.mainfile)
dos_files = get_files(
pattern='*dos.dat', filepath=self.mainfile, stripname=self.basename
)
if len(dos_files) > 1:
logger.info('Multiple `*dos.dat` files found.')
for dos_file in dos_files:
electronic_dos = Wannier90DosParser(dos_file).parse_dos()
electronic_dos = Wannier90DosParser(dos_file=dos_file).parse_dos()
if electronic_dos is not None:
outputs.electronic_dos.append(electronic_dos)

# Parse BandStructure
band_files = get_files('*band.dat', self.filepath, self.mainfile)
band_files = get_files(
pattern='*band.dat', filepath=self.mainfile, stripname=self.basename
)
# contains information about `k_line_path`
k_space = simulation.m_xpath(
'model_method[-1].numerical_settings[-1]', dict=False
Expand All @@ -419,7 +435,9 @@ def parse_outputs(self, simulation: Simulation, logger: 'BoundLogger') -> Output
if len(band_files) > 1:
logger.info('Multiple `*band.dat` files found.')
for band_file in band_files:
band_structure = Wannier90BandParser(band_file).parse_band_structure(
band_structure = Wannier90BandParser(
band_file=band_file
).parse_band_structure(
k_space=k_space,
wannier_method=wannier_method,
model_systems=model_systems,
Expand All @@ -430,19 +448,15 @@ def parse_outputs(self, simulation: Simulation, logger: 'BoundLogger') -> Output

return outputs

def init_parser(self, logger: 'BoundLogger') -> None:
self.wout_parser.mainfile = self.filepath
self.wout_parser.logger = logger

def parse(
self, filepath: str, archive: EntryArchive, logger: 'BoundLogger'
) -> None:
self.filepath = filepath
self.mainfile = filepath
self.maindir = os.path.dirname(self.mainfile)
self.basename = os.path.basename(self.mainfile)
self.archive = archive
self.maindir = os.path.dirname(self.filepath)
self.mainfile = os.path.basename(self.filepath)

self.init_parser(logger)
self.init_parser(logger=logger)

# Adding Simulation to data
simulation = Simulation()
Expand All @@ -453,28 +467,30 @@ def parse(
archive.data = simulation

# `ModelSystem` parsing
model_system = self.parse_model_system(logger)
model_system = self.parse_model_system(logger=logger)
if model_system is not None:
simulation.model_system.append(model_system)

# Child `ModelSystem` and `OrbitalsState` parsing
win_files = get_files('*.win', self.filepath, self.mainfile)
win_files = get_files(
pattern='*.win', filepath=self.mainfile, stripname=self.basename
)
if len(win_files) > 1:
logger.warning(
'Multiple `*.win` files found. We will parse the first one.'
)
if win_files is not None:
child_model_systems = Wannier90WInParser(
win_files[0]
).parse_child_model_systems(model_system, logger)
win_file=win_files[0]
).parse_child_model_systems(model_system=model_system, logger=logger)
model_system.model_system = child_model_systems

# `ModelWannier(ModelMethod)` parsing
model_method = self.parse_model_method()
simulation.model_method.append(model_method)

# `Outputs` parsing
outputs = self.parse_outputs(simulation, logger)
outputs = self.parse_outputs(simulation=simulation, logger=logger)
simulation.outputs.append(outputs)

# Workflow section
Expand Down
15 changes: 11 additions & 4 deletions src/nomad_parser_wannier90/parsers/win_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ def parse_child_atom_indices(
if atom.startswith('f='): # fractional coordinates
positions = [float(x) for x in atom.replace('f=', '').split(',')]
positions = np.dot(positions, atomic_cell.lattice_vectors.magnitude)
sites = self._convert_positions_to_symbols(atomic_cell, units, positions)
sites = self._convert_positions_to_symbols(
atomic_cell=atomic_cell, units=units, positions=positions
)
elif atom.startswith('c='): # cartesian coordinates
positions = [float(x) for x in atom.replace('c=', '').split(',')]
sites = self._convert_positions_to_symbols(atomic_cell, units, positions)
sites = self._convert_positions_to_symbols(
atomic_cell=atomic_cell, units=units, positions=positions
)
else: # atom label directly specified
sites = atom

Expand Down Expand Up @@ -254,7 +258,7 @@ def parse_child_model_systems(
atom = projection[0]
try:
branch_label, atom_indices = self.parse_child_atom_indices(
atom, atomic_cell, wannier90_units
atom=atom, atomic_cell=atomic_cell, units=wannier90_units
)
model_system_child.branch_label = branch_label
model_system_child.atom_indices = atom_indices
Expand All @@ -266,7 +270,10 @@ def parse_child_model_systems(

# orbital angular momentum information always index=1 for `projections[nat]`
self.populate_orbitals_state(
projection, model_system_child, atomic_cell, logger
projection=projection,
model_system_child=model_system_child,
atomic_cell=atomic_cell,
logger=logger,
)
model_system_childs.append(model_system_child)

Expand Down

1 comment on commit 8f1b05e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_parser_wannier90
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_parser_wannier90/parsers
   __init__.py8275%9–11
   band_parser.py511571%23, 43, 69–70, 92–93, 96–97, 104–108, 117–118, 123–124
   dos_parser.py18194%32
   hr_parser.py48981%23, 47, 65–66, 78–79, 113–115
   parser.py1791293%27, 232, 286–287, 327, 345, 384–385, 402, 419, 436, 479
   win_parser.py973168%23, 54, 111–117, 138, 140–142, 146–147, 179–182, 187, 196–198, 208–210, 231–234, 241, 243–244, 248, 265–269
src/nomad_parser_wannier90/parsers/utils
   utils.py14379%46–48
src/nomad_parser_wannier90/schema_packages
   __init__.py8275%9–11
   package.py13130%1–24
TOTAL4529280% 

Tests Skipped Failures Errors Time
1 0 💤 0 ❌ 0 🔥 17.840s ⏱️

Please sign in to comment.