maxwelllink.mxl_drivers.python.models.md_model module¶
Built-in classical molecular-dynamics (MD) driver for MaxwellLink.
- class maxwelllink.mxl_drivers.python.models.md_model.MDModel[source]¶
Bases:
DummyModelClassical molecular-dynamics socket driver: the scalar (
num=1) front end of the sharedMDEngine.- __init__(ff='qtip4pf', n_molecules=None, positions=None, xyz=None, batch_xyz=None, box=None, replicate=None, rcut=None, ewald_wrcut=None, thermostat='nve', temperature_K=300.0, friction_fs=100.0, init_velocities=True, pre_nvt=False, pre_nvt_duration_ps=20.0, reset_dipole=True, seed=0, force_evaluator='auto', property_filename=None, traj_filename=None, record_every_steps=10, record_max_steps=None, checkpoint=False, restart=False, verbose=False, backend='cpu', *, property_list='base', traj_content='positions')[source]¶
Initialize the classical MD driver.
All keywords are forwarded unchanged to the shared
MDEngine; they are documented in full here for user convenience.- Parameters:
ff (str or DummyForceField, default: 'qtip4pf') – Name of a registered force field (
'qtip4pf'for flexible water,'co2jcp2021'for flexible CO2,'cs2compass'for flexible CS2,'ch4compass'for flexible CH4), or an already constructedDummyForceFieldinstance.n_molecules (int, optional) – Number of molecules to build when
positionsis not given (before anyreplicate). IfNone(the default) each force field applies its own default count (32 for water and 36 for CO2, which load the bundled equilibrated bulk boxes).positions (array-like of float, shape (n_atoms, 3), optional) – Initial atomic positions in Bohr. If
Nonethe force field builds a default geometry fromn_molecules(andbox).xyz (str, optional) – Path to an XYZ file (Angstrom) to take the starting geometry from, with the atoms in the order the force field expects (
[C, O, O, ...]for CO2,[O, H, H, ...]for water). Overridespositions; but this also gives coordinates only, so a periodic system still needsbox.batch_xyz (str, optional) – Path to a multi-frame XYZ file (Angstrom) that gives every molecule its own starting geometry: molecule
mstarts from framem, so a batch of drivers, or several batches, read consecutive frames and the same molecule ID always gets the same frame. Every frame must list the same atoms; there must be more frames than the largest molecule ID. Frame 0 doubles as the template geometry when neitherxyznorpositionsis given.box (float or array-like of float, shape (3,), optional) – Periodic box lengths in Bohr.
Nonetreats the system as a finite 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 cutoff in Bohr for the periodic non-bonded sums.
ewald_wrcut (float, optional) – Real-space cutoff in Bohr for the Ewald sum (periodic electrostatics).
thermostat ({'nve', 'nvt'}, default: 'nve') – Ensemble.
'nve'is plain velocity Verlet;'nvt'adds a Langevin (Ornstein-Uhlenbeck) thermostat.temperature_K (float, default: 300.0) – Target temperature in Kelvin (NVT) and temperature for the initial Maxwell-Boltzmann velocities.
friction_fs (float, default: 100.0) – Langevin relaxation time in femtoseconds (
gamma = 1 / tau). Only used whenthermostat == 'nvt'.init_velocities (bool, default: True) – Whether to sample initial velocities from a Maxwell-Boltzmann distribution at
temperature_K. IfFalsethe system starts at rest.pre_nvt (bool, default: False) – Whether to thermally equilibrate the system inside
initialize()before any EM-coupled dynamics. The random seed is offset bymolecule_idso that different molecules are decorrelated even at the sameseed.pre_nvt_duration_ps (float, default: 20.0) – Duration of the pre-NVT equilibration in picoseconds. It uses a Langevin thermostat with a 100 fs relaxation time at
temperature_K, regardless of the productionthermostat.reset_dipole (bool, default: True) – Whether to report the dipole moment relative to its value at time zero.
seed (int, default: 0) – Seed for the random-number generator in EM-coupled dynamics; this molecule draws from
seed + molecule_id.force_evaluator ({'auto', 'numba', 'numpy'}, default: 'auto') – Which force evaluator to use.
'numba'uses the compiled loop-form kernels, which are typically several times faster than the array-at-a-time NumPy reference and allocate no(na, na, 3)temporaries;'numpy'forces the reference implementation.'auto'picks'numba'whenever the force field provides a compiled-kernel description and silently falls back to'numpy'when it does not.property_filename (str, optional) – Turns on a run-time record of per-molecule properties written to this file every
record_every_stepsproduction steps: HDF5, streamed while the run goes, unless the name ends in.npzorh5pyis missing.traj_filename (str, optional) – Runtime extended-XYZ output with one frame per independent system every
record_every_stepsproduction steps. Positions are in Angstrom, atomic velocities in Bohr per atomic time, and 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.record_every_steps (int, default: 10) – Record every this many production steps, for both files.
record_max_steps (int, optional) – Stop recording after this many records;
Nonefor no cap.checkpoint (bool, default: False) – Whether to enable checkpointing (one
md_checkpoint_id_<molecule ID>.npzfile per molecule).restart (bool, default: False) – Whether to restart from a checkpoint if available.
verbose (bool, default: False) – Whether to print verbose output.
backend ({'cpu', 'gpu', None}, default: 'cpu') –
'cpu'runs the compiled (numba) kernels;'gpu'runs the CUDA kernels through CuPy;None(auto) picks the GPU when CuPy reaches a CUDA device. The GPU integrator assigns one CUDA block per system, so a single socket driver usually runs fastest on the CPU.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_filenameis set.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.
- append_additional_data()[source]¶
Append additional data to be sent back to MaxwellLink.
- Returns:
A dictionary with
time_au,energy_au,potential_auand the dipole componentsmux_au/muy_au/muz_au(half a step after the force time) andmux_m_au/muy_m_au/muz_m_au(at the force time), all in atomic units.- Return type:
dict
- calc_amp_vector()[source]¶
Update the source amplitude vector after propagating this molecule for one time step.
- Returns:
Amplitude vector in the form \([\mathrm{d}\mu_x/\mathrm{d}t,\ \mathrm{d}\mu_y/\mathrm{d}t,\ \mathrm{d}\mu_z/\mathrm{d}t]\).
- Return type:
numpy.ndarray of float, shape (3,)
- commit_step()¶
Commit the previewed step and return the staged amplitude.
This method applies the changes from the staged step to the internal state and returns the calculated amplitude vector.
Notes
This method should not be overridden by subclasses.
- Returns:
Amplitude vector in the form \([\mathrm{d}\mu_x/\mathrm{d}t,\ \mathrm{d}\mu_y/\mathrm{d}t,\ \mathrm{d}\mu_z/\mathrm{d}t]\).
- Return type:
numpy.ndarray of float, shape (3,)
- have_result()¶
Check if a staged step is ready to be committed.
Notes
This method should not be overridden by subclasses.
- Returns:
Whether a staged step is ready.
- Return type:
bool
- initialize(dt_new, molecule_id)[source]¶
Initialize the MD simulation and possibly pre-equilibrate.
This is called during the INIT stage of the socket communication, once the molecule ID has been assigned. When
pre_nvtis enabled (and this is not a checkpoint restart), the system is thermally equilibrated here before any EM coupling.- Parameters:
dt_new (float) – The new time step in atomic units (a.u.).
molecule_id (int) – The ID of the molecule assigned by SocketHub.
- propagate(effective_efield_vec)[source]¶
Advance the system by one OBABO velocity-Verlet step under the field.
The step recomputes the force at the new geometry, then records the source amplitude and two dipole snapshots (at the force-evaluation position and half a time step later) that the SingleModeSimulation EM solver needs.
- Parameters:
effective_efield_vec (array-like of float, shape (3,)) – Effective electric field vector in the form
[E_x, E_y, E_z]in atomic units.
- stage_step(E_vec)¶
Stage a propagation step with the given effective electric field vector.
This method performs the propagation and calculates the amplitude vector, but does not commit the changes to the internal state. The result can be committed later using the
self.commit_stepmethod.Notes
This method should not be overridden by subclasses.
- Parameters:
E_vec (array-like of float, shape (3,)) – Effective electric field vector in the form
[E_x, E_y, E_z].