maxwelllink.matter.md package

Built-in classical molecular dynamics in MaxwellLink

class maxwelllink.matter.md.MD[source]

Bases: object

A single standalone classical-MD simulation.

Example

>>> co2 = MD(ff="co2jcp2021", n_molecules=1, dt_fs=0.25)
>>> co2.equilibrate(duration_ps=2.0, temperature_K=300.0)
>>> result = co2.run(duration_ps=10.0, thermostat="nve")
>>> frequency_cm, intensity = result.ir_spectrum()
__init__(ff='qtip4pf', n_molecules=None, xyz=None, positions=None, box=None, replicate=None, rcut=None, ewald_wrcut=None, dt_fs=0.5, temperature_K=300.0, friction_fs=100.0, init_velocities=True, backend='cpu', force_evaluator='auto', seed=0, verbose=False, *, property_filename=None, property_list='base', traj_filename=None, traj_content='positions', record_every_steps=10, record_max_steps=None)[source]

Initialize the MD Engine.

Parameters:
  • ff (str or DummyForceField, default: 'qtip4pf') – A registered force-field name ('qtip4pf' flexible water, 'co2jcp2021' flexible CO2, 'cs2compass' flexible CS2, 'ch4compass' flexible CH4; list them all with maxwelllink.matter.available_force_fields()) or a ready-made user-defined force-field instance.

  • n_molecules (int, optional) – Number of molecules of a default-built geometry, before any replicate. None keeps each force field’s own default (the bundled 32-water / 36-CO2 / 36-CS2 / 100-CH4 bulk boxes).

  • xyz (str, optional) – XYZ file (Angstrom) with the starting geometry, atoms ordered as the force field expects.

  • positions (array-like of float, shape (n_atoms, 3), optional) – Starting geometry in Bohr; overridden by xyz.

  • box (float or array-like of float, shape (3,), optional) – Periodic box lengths in Bohr; None treats the system as a cluster.

  • 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 cutoffs in Bohr of the periodic non-bonded and Ewald sums.

  • ewald_wrcut (float, optional) – Real-space cutoffs in Bohr of the periodic non-bonded and Ewald sums.

  • dt_fs (float, default: 0.5) – Integration time step in femtoseconds.

  • temperature_K (float, default: 300.0) – Default temperature: initial Maxwell-Boltzmann velocities, and the bath of equilibrate() / NVT runs unless they override it.

  • friction_fs (float, default: 100.0) – Default Langevin relaxation time in femtoseconds.

  • init_velocities (bool, default: True) – Sample initial velocities at temperature_K; False starts at rest.

  • backend ({'cpu', 'gpu', None}, default: 'cpu') – 'cpu' runs the compiled (numba) kernels; 'gpu' runs the CUDA kernels through CuPy; None picks the GPU automatically when one is reachable. The GPU integrator assigns one CUDA block per system, so a single cell usually runs fastest on the CPU, while the GPU backend shines in the many-cell batch drivers.

  • force_evaluator ({'auto', 'numba', 'numpy'}, default: 'auto') – CPU force evaluator; 'numpy' forces the reference implementation.

  • seed (int, default: 0) – Random seed (initial velocities and Langevin noise).

  • verbose (bool, default: False) – Print a short note when the cell is initialized.

  • property_filename (str, optional) – Filename for the property file.

  • property_list (str or list or tuple, default: "base") – Select “base”, “all”, or semicolon-separated property names. Lists and tuples are also accepted. Only used when property_filename is set.

  • traj_filename (str, optional) – Runtime extended-XYZ output with one frame per independent system. Positions are in Angstrom, atomic velocities in Bohr per atomic time, and molecular body-frame angular velocities in inverse atomic time. Angular output automatically includes the corresponding principal moments of inertia in electron-mass times Bohr-squared units. Each molecule’s six angular-output values are repeated for all its atoms.

  • traj_content (str, default: "positions") – Content to record: “positions”, “velocities”, “angular_velocity_body”, or “all”. Angular output contains three angular velocities followed by three principal moments of inertia. “all” includes positions, atomic velocities, and these six angular-output columns. Velocities and angular data are sampled before the final Langevin O half-step.

  • record_every_steps (int, default: 10) – Record the property and trajectory files every this many production steps, independently of the arrays returned by run().

  • record_max_steps (int, optional) – Maximum number of records in each output file; None for no cap.

close()[source]

Release the engine state (device buffers included).

equilibrate(duration_ps=20.0, temperature_K=None, friction_fs=None)[source]

Thermalize the cell with a Langevin (NVT) trajectory, in place.

Nothing is recorded; call run() afterwards for production data.

Parameters:
  • duration_ps (float, default: 20.0) – Equilibration length in picoseconds.

  • temperature_K (float, optional) – Bath temperature; the constructor’s temperature_K by default.

  • friction_fs (float, optional) – Langevin relaxation time; the constructor’s friction_fs by default.

Returns:

The cell itself, so calls can be chained.

Return type:

MD

get_positions()[source]

Return the current atomic positions in Bohr, shape (n_atoms, 3).

get_velocities()[source]

Return the current atomic velocities in a.u., shape (n_atoms, 3).

run(duration_ps=None, n_steps=None, thermostat='nve', temperature_K=None, friction_fs=None, field=None, record_every=1, snapshot_every=None)[source]

Propagate the cell and record its trajectory.

Successive calls continue from the current state, so a typical session is equilibrate() followed by one or more run() calls.

Parameters:
  • duration_ps (float, optional) – Length of the run in picoseconds. Give this or n_steps.

  • n_steps (int, optional) – Number of time steps; overrides duration_ps.

  • thermostat ({'nve', 'nvt'}, default: 'nve') – Plain velocity Verlet, or with a Langevin thermostat.

  • temperature_K (float, optional) – NVT bath temperature; the constructor’s value by default.

  • friction_fs (float, optional) – NVT Langevin relaxation time; the constructor’s value by default.

  • field (optional) – External electric field in atomic units: None (field-free), a constant (3,) vector, an (n_steps, 3) table, or a callable field(t_au) -> (3,) evaluated at the start of every step.

  • record_every (int, default: 1) – Keep every this-many steps in the returned arrays.

  • snapshot_every (int, optional) – Also record the geometry and velocities every this-many steps.

Return type:

MDResult

maxwelllink.matter.md.available_force_fields()[source]

Return the registered force-field names.

Subpackages

Submodules