narupa.ase.imd_calculator module

Provides an implementation of IMD force field in ASE.

class narupa.ase.imd_calculator.ImdCalculator(imd_state: narupa.imd.imd_state.ImdStateWrapper, calculator: Optional[ase.calculators.calculator.Calculator] = None, atoms: Optional[ase.atoms.Atoms] = None, dynamics: Optional[ase.md.md.MolecularDynamics] = None, reset_scale=0.5, **kwargs)

Bases: ase.calculators.calculator.Calculator

Implementation of IMD as an ASE calculator.

Given another ASE calculator to act as the internal calculator, will compute the external energy and forces via the IMD service, and add them to the internal force calculations.

Parameters:
  • imd_state – A wrapper that provides access to the active interactive forces.
  • calculator – An existing ASE calculator to perform internal energy calculation.
  • atoms – An ASE atoms object to use.
  • dynamics – An ASE dynamics object from which to draw the equilibrium temperature for resetting velocities
  • reset_scale – A scale factor to apply to velocities when reset.
  • kwargs – Key word args passed to the base calculator.

See also

The ImdServer class makes use of this class, and makes running an interactive molecular dynamics simulation in ASE straightforward.

calculate(atoms: ase.atoms.Atoms = None, properties=('energy', 'forces'), system_changes=['positions', 'numbers', 'cell', 'pbc', 'initial_charges', 'initial_magmoms'])

Calculates the given properties of the ASE atoms. The internal molecular calculator is called first, and then any interactive forces currently being applied to the system are added.

Results are stored in the results dictionary, as normal.

Parameters:
  • atoms – Optional Atoms object to perform the calculation on. If no atoms is passed, the atoms object passed at initialisation are used.
  • properties – The properties to calculate. The ImdCalculator support ‘energy’ and ‘forces’, but will pass any other requested properties to the internal atomic calculator. See calculate() for details.
  • system_changes – List of what has changed since last calculation. See calculate() for details.
Raises:

ValueError – If no ASE atoms are supplied to the calculation, and no ASE atoms were supplied during initialisation.

calculator

The internal ASE calculator being used.

Returns:ASE calculator being used to compute internal forces.
interactions

Fetches a copy of the current interactions.

reset_temperature

The temperature this calculator will reset the velocities of atoms interacted with to if the interaction is set to reset velocities.

Returns:The reset temperature.
Raises:Attribute error, if not temperature has been defined.
temperature

Gets the temperature used for reinitialising velocities after an interaction.

By default, it will attempt to use the temperature of the dynamics. If a custom temperature has been set by this attributes setter, then that will be used.

Returns:The temperature used for reinitialising velocities after an interaction.
Raises:AttributeError: If no temperature is defined for this calculator, in the case that no dynamics object has been passed, or the dynamics object does not implement the temperature or ‘temp’ attribute.
narupa.ase.imd_calculator.get_periodic_box_lengths(atoms: ase.atoms.Atoms) → Optional[numpy.ndarray]

Gets the periodic box lengths of an orthorhombic box, in nm, from an ASE atoms collection, if it exists.

Parameters:atoms – ASE atoms.
Returns:Array of periodic box lengths if periodic boundaries are in use, None otherwise.