Skip to content

atom scattering potential calculation fails when atom name is more than 1 letter #8

@pcbve1

Description

@pcbve1

In template_iterator.py, in the BaseTemplateIterator class, in the function get_template_scattering potential, there is an issue with the get_a_param function call

def get_template_scattering_potential(
self, atom_idxs: torch.Tensor | np.ndarray = None
) -> float:
"""Get the mass (in amu) of a template structure given atom indexes."""
if atom_idxs is None:
atom_idxs = np.arange(len(self.structure_df))
if isinstance(atom_idxs, torch.Tensor):
atom_idxs = atom_idxs.numpy()
total_scattering_potential = 0
atom_counts = self.structure_df.iloc[atom_idxs]["element"].value_counts()
for atom, count in atom_counts.items():
atom = atom.upper()
potentials = get_a_param(atom)
potentials = torch.sum(potentials).item()
total_scattering_potential += potentials * count
return total_scattering_potential

because this function takes a list of atoms as input, passing a multi-character string (for example, the string "Mg" meaning magnesium) will have the simulator get the scattering parameter for M and then g, neither of which are atoms name.

a simple fix that I have implemented in my fork is turning the atom name into a length-1 list
potentials = get_a_param([atom])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions