nanover.ase.omm_calculator module
ASE calculator for use with OpenMM.
- class nanover.ase.omm_calculator.OpenMMCalculator(simulation, atoms: Atoms | None = None, **kwargs)
Bases:
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. Seegenerate_atoms()
for a helper function to generate a compatible ASE atoms object.
- calculate(atoms: Atoms | None = 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: Atoms | None = 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() 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: List[str] = ['energy', 'forces']
Properties calculator can handle (energy, forces, …)
- make_frame_converter()
Return a function that converts ase atoms into frame data, using the topology available from this calculator instead of from the ase atoms.
- static set_periodic_bounds(atoms: Atoms, system: 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.
- simulation: Simulation
- property topology