pydft_qmmm.utils.misc

Helper functions accessed by multiple classes.

Functions

center_positions(positions, box, atoms)

Center positions about the centroid of a set of atoms.

check_array(value)

Check if an array has any NaN or Inf vlaues.

generate_velocities(masses, temperature[, seed])

Generate velocities with the Maxwell-Boltzmann distribution.

numerical_gradient(calculator, atoms[, ...])

Calculate the numerical energy gradients for a set of atoms.

residue_partition(atoms, positions, ...)

Perform the residue-wise system partitioning.

wrap_positions(positions, box, residue_map)

Wrap atom positions in accord with PBC.

pydft_qmmm.utils.misc.center_positions(positions, box, atoms)[source]

Center positions about the centroid of a set of atoms.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

The new centered positions of the system.

pydft_qmmm.utils.misc.check_array(value)[source]

Check if an array has any NaN or Inf vlaues.

Parameters:

value (ndarray[tuple[Any, ...], dtype[float64]]) – The array to evaluate.

Return type:

bool

Returns:

Whether the array has any NaN or Inf values.

pydft_qmmm.utils.misc.generate_velocities(masses, temperature, seed=None)[source]

Generate velocities with the Maxwell-Boltzmann distribution.

Parameters:
  • masses (ndarray[tuple[Any, ...], dtype[float64]]) – The masses (\(\mathrm{AMU}\)) of particles.

  • temperature (float | int) – The temperature (\(\mathrm{K}\)) of the system.

  • seed (int | None, default: None) – A seed for the random number generator.

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

A set of velocities (\(\mathrm{\mathring{A}\;fs^{-1}}\)) equal in number to the set of masses provided.

pydft_qmmm.utils.misc.numerical_gradient(calculator, atoms, dist=0.0025, components=None)[source]

Calculate the numerical energy gradients for a set of atoms.

Parameters:
  • calculator (Calculator) – A calculator object used for the energy evaluations.

  • atoms (frozenset[int]) – The atoms for which to perform a numerical gradient calculation.

  • dist (int | float, default: 0.0025) – The displacement for central differencing (\(\mathrm{\mathring{A}}\)).

  • component – The component of the energy dictionary to use in central differencing calculations.

  • components (list[str] | None)

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

The numerical gradients of the energy (\(\mathrm{kJ\;mol^{-1}\;\mathring{A}^{-1}}\)).

pydft_qmmm.utils.misc.residue_partition(atoms, positions, residue_map, atoms_metric, other_metric, cutoff)[source]

Perform the residue-wise system partitioning.

Parameters:
  • atoms (frozenset[int]) – The set of atom indices whose metric will be used to determine the partition.

  • positions (ndarray[tuple[Any, ...], dtype[float64]]) – The system positions (\(\mathrm{\mathring{A}}\)).

  • residue_map (dict[int, frozenset[int]]) – Sets of atom indices indexed by residue index.

  • atoms_metric (Callable[[ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]], float]) – A function to apply to a residue’s positions to generate a single relevant coordinate. This metric is applied to the provided set of atoms.

  • other_metric (Callable[[ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]], float]) – A function to apply to a residue’s positions to generate a single relevant coordinate. This metric is applied to all residues in the system.

  • cutoff (float | int) – The cutoff distance (\(\mathrm{\mathring{A}}\)) to apply in the partition.

Return type:

list[int]

pydft_qmmm.utils.misc.wrap_positions(positions, box, residue_map)[source]

Wrap atom positions in accord with PBC.

Atoms are wrapped to stay inside of the periodic box. This function ensures molecules are not broken up by a periodic boundary, since OpenMM electrostatics will be incorrect if atoms in a molecule are not on the same side of the periodic box.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

The new wrapped positions of the system.