narupa.ase.openmm.calculator module

ASE calculator for use with OpenMM.

class narupa.ase.openmm.calculator.OpenMMCalculator(simulation, atoms: Optional[ase.atoms.Atoms] = None, **kwargs)

Bases: ase.calculators.calculator.Calculator

Simple implementation of a ASE calculator for OpenMM. Initialises an OpenMM context with the given OpenMM simulation.

Parameters:
  • simulation – An OpenMM simulation.
  • atoms – ASE Atoms to use with the calculator. The topology of the ASE atoms should be consistent with the OpenMM simulation. See generate_atoms() for a helper function to generate a compatible ASE atoms object.
calculate(atoms: Optional[ase.atoms.Atoms] = None, properties=('energy', 'forces'), system_changes=['positions', 'numbers', 'cell', 'pbc', 'initial_charges', 'initial_magmoms'])

Do the calculation.

properties: list of str
List of what needs to be calculated. Can be any combination of ‘energy’, ‘forces’, ‘stress’, ‘dipole’, ‘charges’, ‘magmom’ and ‘magmoms’.
system_changes: list of str
List of what has changed since last calculation. Can be any combination of these six: ‘positions’, ‘numbers’, ‘cell’, ‘pbc’, ‘initial_charges’ and ‘initial_magmoms’.

Subclasses need to implement this, but can ignore properties and system_changes if they want. Calculated properties should be inserted into results dictionary like shown in this dummy example:

self.results = {'energy': 0.0,
                'forces': np.zeros((len(atoms), 3)),
                'stress': np.zeros(6),
                'dipole': np.zeros(3),
                'charges': np.zeros(len(atoms)),
                'magmom': 0.0,
                'magmoms': np.zeros(len(atoms))}

The subclass implementation should first call this implementation to set the atoms attribute and create any missing directories.

classmethod from_xml(input_xml, atoms: Optional[ase.atoms.Atoms] = None, **kwargs)

Initialises an :class: OpenMMCalculator from a simulation serialised to XML with :module serializer.

Parameters:
  • input_xml – XML file from which to create OpenMM simulation.
  • atoms – ASE Atoms to pass to the resulting OpenMMCalculator.
  • kwargs – Keyword arguments for the OpenMMCalculator to be passed upon construction.
Returns:

An :class: OpenMMCalculator.

generate_atoms() → ase.atoms.Atoms

Generates ASE atoms representation of the OpenMM system.

Returns:ASE Atoms, with positions and chemical symbols set as according to the current state of the OpenMM system.
implemented_properties = ['energy', 'forces']
static set_periodic_bounds(atoms: ase.atoms.Atoms, system: pretends.System)

Sets ASE atoms object with the same periodic boundaries as that used in the given OpenMM system.

Parameters:
  • atoms – ASE Atoms
  • system – OpenMM system.
topology