maxwelllink.matter.md.force_fields.force_field module

Force-field base class for classical molecular-dynamics (MD) driver.

All quantities are in atomic units.

class maxwelllink.matter.md.force_fields.force_field.DummyForceField[source]

Bases: object

Abstract base class for a classical molecular-dynamics (MD) force field.

__init__(n_molecules=1, positions=None, box=None, replicate=None, rcut=None, ewald_wrcut=None)[source]

Initialize the shared environment parameters of the force field.

Parameters:
  • n_molecules (int, optional) – Number of molecules in the system (before replication). This is used to determine the total number of atoms when the geometry is not provided. The default is 1.

  • positions (array-like of float, shape (na, 3), optional) – Atomic positions in atomic units (Bohr). If None a default geometry is built from n_molecules via _build_default_geometry().

  • box (float or array-like of float, shape (3,), optional) – Periodic box lengths in atomic units (Bohr). If None the system is a finite cluster and no periodic images are used.

  • replicate (int or array-like of int, shape (3,), optional) – Replicate the periodic cell. The molecules and the box lengths grow together, so the density is unchanged.

  • rcut (float, optional) – Real-space cutoff in Bohr for the non-bonded sums when a box is present.

  • ewald_wrcut (float, optional) – Real-space cutoff in Bohr for the Ewald sum (force fields with periodic electrostatics). None lets the subclass pick a default.

build_force_kernels(xp, threads_per_block=128)[source]

Return the compiled force evaluator of this force field.

Notes

This method should be overridden by subclasses that want the fast (numba) CPU path and the GPU batch backend. Without it only compute() is available.

Parameters:
  • xp (module) – Array module: numpy for the CPU path, cupy for the GPU path.

  • threads_per_block (int, default: 128) – CUDA block size, ignored on the CPU path.

Returns:

The force field’s compiled kernels.

Return type:

object

compute(x, efield, terms=None)[source]

Evaluate the total force and potential energy for a geometry and field.

The returned force must already include the external light-matter force \(q_i \mathbf{E}\) on each charge site (with any virtual-site forces redistributed onto the real atoms). The potential energy is the mechanical (field-free) one.

Notes

This method must be overridden by subclasses.

Parameters:
  • x (numpy.ndarray of float, shape (na, 3)) – Atomic positions in atomic units (Bohr).

  • efield (numpy.ndarray of float, shape (3,)) – Effective electric field [E_x, E_y, E_z] in atomic units.

  • terms (numpy.ndarray of float, shape (len(reported_term_names),), optional) – Filled with the energy terms of reported_term_names when given.

Returns:

  • forces (numpy.ndarray of float, shape (na, 3)) – Total force on each atom in atomic units.

  • potential (float) – Mechanical potential energy in atomic units (Hartree).

compute_fast(x, efield, terms=None)[source]

Evaluate the force and potential with the compiled (numba) kernels.

Physically identical to compute() but several times faster. The kernels and the output buffer are built once and reused.

Parameters:
  • x (numpy.ndarray of float, shape (na, 3)) – Atomic positions in atomic units (Bohr).

  • efield (numpy.ndarray of float, shape (3,)) – Effective electric field [E_x, E_y, E_z] in atomic units.

  • terms (numpy.ndarray of float, shape (len(reported_term_names),), optional) – Filled with the energy terms of reported_term_names when given.

Returns:

  • forces (numpy.ndarray of float, shape (na, 3)) – Total force on each atom in atomic units.

  • potential (float) – Mechanical potential energy in atomic units (Hartree).

dipole(x)[source]

Return the molecular dipole moment for a given geometry.

Notes

This method must be overridden by subclasses.

Parameters:

x (numpy.ndarray of float, shape (na, 3)) – Atomic positions in atomic units (Bohr).

Returns:

The dipole moment \(\boldsymbol{\mu} = \sum_i q_i \mathbf{r}_i\) in atomic units.

Return type:

numpy.ndarray of float, shape (3,)

dipole_velocity(v)[source]

Return the time derivative of the molecular dipole moment.

Notes

This method must be overridden by subclasses.

Parameters:

v (numpy.ndarray of float, shape (na, 3)) – Atomic velocities in atomic units.

Returns:

The dipole velocity \(\mathrm{d}\boldsymbol{\mu}/\mathrm{d}t = \sum_i q_i \mathbf{v}_i\) in atomic units.

Return type:

numpy.ndarray of float, shape (3,)

has_compiled_kernels = False
molecule_symbols = ()
name = 'dummy'
reported_term_names = ()
maxwelllink.matter.md.force_fields.force_field.replicate_cell(positions, box, replicate)[source]

Tile a periodic cell nx * ny * nz times.

Parameters:
  • positions (array-like of float, shape (..., na, 3)) – Atomic positions in atomic units (Bohr); leading axes (e.g. XYZ frames) are kept.

  • box (float or array-like of float, shape (3,)) – Periodic box lengths in atomic units (Bohr) of the cell being tiled.

  • replicate (int or array-like of int, shape (3,)) – Three integers are the images along x, y and z. One integer is the total number of images, laid out as a cube when it is a cubic number (27 -> 3 x 3 x 3), as a square in the xy plane when it is a square number (4 -> 2 x 2 x 1), and in a row along x otherwise (6 -> 6 x 1 x 1).

Returns:

  • positions (numpy.ndarray of float, shape (…, na * nx * ny * nz, 3)) – The tiled positions; every image keeps the per-molecule atom order.

  • box (numpy.ndarray of float, shape (3,)) – The enlarged box lengths.

  • counts (numpy.ndarray of int, shape (3,)) – The image counts (nx, ny, nz) that were applied.

Raises:

ValueError – If replicate is not one or three positive integers.