Skip to content

Commit

Permalink
Started implementing elemental weights
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomDefaultUser committed Nov 29, 2024
1 parent 6b81953 commit 64956b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mala/common/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def __init__(self):
self.bispectrum_twojmax = 10
self.bispectrum_cutoff = 4.67637
self.bispectrum_switchflag = 1
self.bispectrum_element_weights = None

# Everything pertaining to the atomic density.
# Seperate cutoff given here because bispectrum descriptors and
Expand Down Expand Up @@ -473,6 +474,30 @@ def bispectrum_switchflag(self, value):
if _int_value > 0:
self._snap_switchflag = 1

@property
def bispectrum_element_weights(self):
"""
Element species weights for the bispectrum calculation.
They are provided as an ordered list, and will be assigned to the
elements alphabetically, i.e., the first entry will go to the element
coming first in the alphabet and so on. Weights are always relative, so
the list will be rescaled such that the largest value is 1 and all
the other ones are scaled accordingly.
"""
return self._bispectrum_element_weights

@bispectrum_element_weights.setter
def bispectrum_element_weights(self, value):
if not isinstance(value, list) and value is not None:
raise ValueError("Bispectrum element weights must be list.")
if value is not None:
if np.max(value) != 1.0:
max = np.max(value)
for element in range(len(value)):
value[element] /= max
self._bispectrum_element_weights = value

def _update_mpi(self, new_mpi):
self._configuration["mpi"] = new_mpi

Expand Down
12 changes: 12 additions & 0 deletions mala/descriptors/bispectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ def __calculate_lammps(self, outdir, **kwargs):
nz = self.grid_dimensions[2]

# Create LAMMPS instance.
if (
len(set(self._atoms.numbers)) > 1
and self.parameters.bispectrum_element_weights is None
):
self.parameters.bispectrum_element_weights = [1] * len(
set(self._atoms.numbers)
)
printout(
"Multielement system selected without providing elemental "
"weights. Set weights to: ",
self.parameters.bispectrum_element_weights,
)
lammps_dict = {
"twojmax": self.parameters.bispectrum_twojmax,
"rcutfac": self.parameters.bispectrum_cutoff,
Expand Down

0 comments on commit 64956b8

Please sign in to comment.