Skip to content

Commit

Permalink
Added explicitly input in functions for numerical_settings.py and its…
Browse files Browse the repository at this point in the history
… testing
  • Loading branch information
JosePizarro3 committed Jun 5, 2024
1 parent 55963e8 commit ab84ca6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
38 changes: 21 additions & 17 deletions src/nomad_simulations/numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def resolve_high_symmetry_points(
lattice = None
for model_system in model_systems:
# General checks to proceed with normalization
if is_not_representative(model_system, logger):
if is_not_representative(model_system=model_system, logger=logger):
continue
if model_system.symmetry is None:
logger.warning('Could not find `ModelSystem.symmetry`.')
Expand All @@ -253,9 +253,9 @@ def resolve_high_symmetry_points(
)
continue
# function defined in AtomicCell
atoms = prim_atomic_cell.to_ase_atoms(logger)
atoms = prim_atomic_cell.to_ase_atoms(logger=logger)
cell = atoms.get_cell()
lattice = cell.get_bravais_lattice(eps)
lattice = cell.get_bravais_lattice(eps=eps)
break # only cover the first representative `ModelSystem`

# Checking if `bravais_lattice` and `lattice` are defined
Expand Down Expand Up @@ -380,8 +380,8 @@ def resolve_points_and_offset(
offset = np.array([0, 0, 0])
elif self.center == 'Monkhorst-Pack':
try:
points = monkhorst_pack(self.grid)
offset = get_monkhorst_pack_size_and_offset(points)[-1]
points = monkhorst_pack(size=self.grid)
offset = get_monkhorst_pack_size_and_offset(kpts=points)[-1]
except ValueError:
logger.warning(
'Could not resolve `KMesh.points` and `KMesh.offset` from `KMesh.grid`. ASE `monkhorst_pack` failed.'
Expand Down Expand Up @@ -448,7 +448,7 @@ def resolve_k_line_density(

for model_system in model_systems:
# General checks to proceed with normalization
if is_not_representative(model_system, logger):
if is_not_representative(model_system=model_system, logger=logger):
continue
# TODO extend this for other dimensions (@ndaelman-hu)
if model_system.type != 'bulk':
Expand All @@ -457,7 +457,7 @@ def resolve_k_line_density(

# Resolve `k_line_density`
if k_line_density := self.get_k_line_density(
reciprocal_lattice_vectors, logger
reciprocal_lattice_vectors=reciprocal_lattice_vectors, logger=logger
):
return k_line_density
return None
Expand All @@ -472,7 +472,7 @@ def normalize(self, archive, logger) -> None:

# Normalize k mesh from grid sampling
if self.points is None and self.offset is None:
self.points, self.offset = self.resolve_points_and_offset(logger)
self.points, self.offset = self.resolve_points_and_offset(logger=logger)

# Calculate k_line_density for data quality measures
model_systems = self.m_xpath(
Expand All @@ -483,7 +483,9 @@ def normalize(self, archive, logger) -> None:
)
if self.k_line_density is None:
self.k_line_density = self.resolve_k_line_density(
model_systems, reciprocal_lattice_vectors, logger
model_systems=model_systems,
reciprocal_lattice_vectors=reciprocal_lattice_vectors,
logger=logger,
)

# Resolve `high_symmetry_points`
Expand Down Expand Up @@ -624,7 +626,7 @@ def get_high_symmetry_path_norms(
`high_symmetry_path_value_norms = [0, 0.5, 0.5 + 1 / np.sqrt(2), 1 + 1 / np.sqrt(2)]`
"""
# Checking the high symmetry path quantities
if not self.validate_high_symmetry_path(logger):
if not self.validate_high_symmetry_path(logger=logger):
return None
# Checking if `reciprocal_lattice_vectors` is defined and taking its magnitude to operate
if reciprocal_lattice_vectors is None:
Expand Down Expand Up @@ -672,7 +674,7 @@ def resolve_points(
logger (BoundLogger): The logger to log messages.
"""
# General checks for quantities
if not self.validate_high_symmetry_path(logger):
if not self.validate_high_symmetry_path(logger=logger):
return None
if reciprocal_lattice_vectors is None:
logger.warning(
Expand All @@ -693,7 +695,7 @@ def resolve_points(

# Calculate the norms in the path and find the closest indices in points_norm to the high symmetry path norms
high_symmetry_path_value_norms = self.get_high_symmetry_path_norms(
reciprocal_lattice_vectors, logger
reciprocal_lattice_vectors=reciprocal_lattice_vectors, logger=logger
)
closest_indices = list(
map(
Expand Down Expand Up @@ -751,11 +753,13 @@ def normalize(self, archive, logger) -> None:
or len(self.high_symmetry_path_values) == 0
):
self.high_symmetry_path_values = self.resolve_high_symmetry_path_values(
model_systems, reciprocal_lattice_vectors, logger
model_systems=model_systems,
reciprocal_lattice_vectors=reciprocal_lattice_vectors,
logger=logger,
)

# If `high_symmetry_path` is not defined, we do not normalize the KLinePath
if not self.validate_high_symmetry_path(logger):
if not self.validate_high_symmetry_path(logger=logger):
return


Expand Down Expand Up @@ -801,7 +805,7 @@ def resolve_reciprocal_lattice_vectors(
"""
for model_system in model_systems:
# General checks to proceed with normalization
if is_not_representative(model_system, logger):
if is_not_representative(model_system=model_system, logger=logger):
continue

# TODO extend this for other dimensions (@ndaelman-hu)
Expand All @@ -815,7 +819,7 @@ def resolve_reciprocal_lattice_vectors(
continue

# Set the `reciprocal_lattice_vectors` using ASE
ase_atoms = atomic_cell[0].to_ase_atoms(logger)
ase_atoms = atomic_cell[0].to_ase_atoms(logger=logger)
return 2 * np.pi * ase_atoms.get_reciprocal_cell() / ureg.angstrom
return None

Expand All @@ -826,7 +830,7 @@ def normalize(self, archive, logger) -> None:
model_systems = self.m_xpath('m_parent.m_parent.model_system', dict=False)
if self.reciprocal_lattice_vectors is None:
self.reciprocal_lattice_vectors = self.resolve_reciprocal_lattice_vectors(
model_systems, logger
model_systems=model_systems, logger=logger
)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_resolve_points_and_offset(
k_mesh = KMesh(center=center)
if grid is not None:
k_mesh.grid = grid
points, offset = k_mesh.resolve_points_and_offset(logger)
points, offset = k_mesh.resolve_points_and_offset(logger=logger)
if points is not None:
assert np.allclose(points, result_points)
else:
Expand Down Expand Up @@ -305,7 +305,7 @@ def test_validate_high_symmetry_path(
high_symmetry_path_names=high_symmetry_path_names,
high_symmetry_path_values=high_symmetry_path_values,
)
assert k_line_path.validate_high_symmetry_path(logger) == result
assert k_line_path.validate_high_symmetry_path(logger=logger) == result

@pytest.mark.parametrize(
'reciprocal_lattice_vectors, high_symmetry_path_names, result',
Expand Down

0 comments on commit ab84ca6

Please sign in to comment.