Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Fix Win parsing with new example data
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Apr 30, 2024
1 parent cfa2173 commit 8bde57e
Show file tree
Hide file tree
Showing 7 changed files with 6,749 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/nomad_parser_wannier90/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ def parse_atomic_cell(self) -> AtomicCell:

# Parsing `atoms_state` from `structure`
labels = self.wout_parser.get('structure', {}).get('labels')
atoms_state = self.parse_atoms_state(labels)
atomic_cell.atoms_state = atoms_state
if labels is not None:
atoms_state = self.parse_atoms_state(labels)
atomic_cell.atoms_state = atoms_state
# and parsing `positions`
if self.wout_parser.get('structure', {}).get('positions') is not None:
atomic_cell.positions = (
Expand Down Expand Up @@ -427,7 +428,11 @@ def parse_outputs(self, simulation: Simulation, logger: BoundLogger) -> Outputs:
if len(hr_files) > 1:
logger.info('Multiple `*hr.dat` files found.')
for hr_file in hr_files:
hopping_matrix = Wannier90HrParser().parse_hoppings(hr_file, logger)
# contains information about `n_orbitals`
wannier_method = simulation.model_method[-1]
hopping_matrix = Wannier90HrParser().parse_hoppings(
hr_file, wannier_method, logger
)
outputs.hopping_matrix.append(hopping_matrix)

# Parse Fermi level
Expand Down
25 changes: 19 additions & 6 deletions src/nomad_parser_wannier90/win_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

import numpy as np
from typing import List, Optional, Tuple
from typing import List, Optional, Tuple, Union
from structlog.stdlib import BoundLogger

from nomad.parsing.file_parser import TextParser, Quantity
Expand Down Expand Up @@ -118,21 +118,24 @@ def _convert_positions_to_symbols(

def parse_child_atom_indices(
self,
atom: str,
atom: Union[str, int],
atomic_cell: AtomicCell,
units: str,
) -> Tuple[str, List[int]]:
) -> Tuple[Optional[str], List[int]]:
"""
Parse the atom indices for the child model system.
Args:
atom (str): The atom string containing the positions information.
atom (Union[str, int]): The atom string containing the positions information. In some older version,
this can be an integer index pointing to the atom.
atomic_cell (AtomicCell): The `AtomicCell` section where `positions` are stored
units (str): The units in which the positions are defined.
Returns:
(Tuple[str, List[int]]): The `branch_label` and `atom_indices` for the child model system.
"""
if isinstance(atom, int):
return '', [atom]
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)
Expand Down Expand Up @@ -161,16 +164,25 @@ def populate_orbitals_state(
Populate the `OrbitalsState` sections for the AtomsState relevant for the Wannier projection.
Args:
projection (List[str]): The projection information for the atom.
projection (List[Union[int, str]]): The projection information for the atom.
model_system_child (ModelSystem): The child model system to get the `atom_indices`.
atomic_cell (AtomicCell): The `AtomicCell` section where `positions` are stored.
logger (BoundLogger): The logger to log messages.
"""
atom = projection[0]
for atom_index in model_system_child.atom_indices:
if atomic_cell.atoms_state is None or len(atomic_cell.atoms_state) == 0:
logger.warning(
'Could not extract the `AtomicCell.atoms_state` sections.'
)
continue
atom_state = atomic_cell.atoms_state[atom_index]
if atom != atom_state.chemical_symbol:

# To avoid issues when `atom` is an integer
if isinstance(atom, str) and atom != atom_state.chemical_symbol:
continue

# Try to get the orbitals information
try:
orbitals = projection[1].split(';')
angular_momentum = None
Expand All @@ -192,6 +204,7 @@ def populate_orbitals_state(
except Exception:
logger.warning('Projected orbital labels not found from win.')
return None
return None

def parse_child_model_systems(
self,
Expand Down
22 changes: 22 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from nomad import utils


logger = utils.get_logger(__name__)
Loading

0 comments on commit 8bde57e

Please sign in to comment.