Improved prepare structures
The loop when you need to prepare structures to add to the structure container is a bit tedious
from hiphive.utilities import get_displacements
for structure in structures:
structure.calc = calc
forces = structure.get_forces()
structure.arrays['forces'] = forces
displacements = get_displacements(structure, atoms_ideal)
structure.arrays['displacements'] = displacements
structure.positions = atoms_ideal.positions
structure.calc = None
instead it would be nice if the prepare structures utility could handle the preparation for us
from hiphive.utilities import prepare_structures
prepare_structures(structures, atoms_ideal, calc)
I updated the function to try to handle a few usecases
- a calculator is given by the user
- arrays are already present
- a single point calculator is present
- structure is permuted compared to the ideal structure
If any of the provided means to calculate forces and displacements the function checks for inconsistencies. E.g. a calculator is given but a single point calculator is also present.
A question arised regarding whether we should really modify the given structures in place. I think it is better to make copies. As it is now the structures would be partially modified if the function raises an exception.
Edited by Paul Erhart