molforge.md¶
md ¶
Molecular dynamics: trajectory I/O, analysis, and engine wrappers.
A molecular dynamics simulation numerically integrates Newton's equations of motion for a system of atoms subject to a force field, typically over picosecond-to-microsecond timescales.
In molforge:
- :class:
Trajectoryis a sequence of coordinate snapshots indexed by frame, with per-frame metadata (time, energy, temperature). - :class:
Simulationis the snapshot of an in-progress simulation: topology, current coordinates, current velocities, the integrator's parameters. You can extend it with :meth:Simulation.runto produce more :class:Trajectoryframes. - :class:
MDEngine(in this package) is the abstract base for MD engine wrappers (OpenMM, GROMACS, ...). Concrete engines live under :mod:molforge.wrappers.md.
By convention, every MD engine wrapper exposes:
- :meth:prepare(protein, force_field, ...) -> Simulation
- :meth:minimize(simulation, ...) -> Simulation
- :meth:run(simulation, n_steps, ...) -> Trajectory
So users get the same call structure regardless of which engine they're running under.
Trajectory
dataclass
¶
Trajectory(
topology: Protein,
coordinates: NDArray[float32],
times: NDArray[float64] | None = None,
energies: NDArray[float64] | None = None,
temperatures: NDArray[float64] | None = None,
metadata: dict[str, object] = dict(),
)
A frame-indexed MD trajectory.
Attributes:
| Name | Type | Description |
|---|---|---|
topology |
Protein
|
A :class: |
coordinates |
NDArray[float32]
|
|
times |
NDArray[float64] | None
|
|
energies |
NDArray[float64] | None
|
|
temperatures |
NDArray[float64] | None
|
|
metadata |
dict[str, object]
|
engine-specific extras (force field name, integrator, timestep, etc.). |
frame ¶
Return frame i as a :class:Protein snapshot.
The returned Protein shares the topology of this trajectory
but has its own coordinate array.
Simulation
dataclass
¶
Simulation(
topology: Protein,
coordinates: NDArray[float32],
velocities: NDArray[float32] | None = None,
time: float = 0.0,
force_field: str = "",
temperature: float = 300.0,
timestep: float = 0.002,
engine_handle: object | None = None,
metadata: dict[str, object] = dict(),
)
The state of an in-progress MD simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
topology |
Protein
|
The system's :class: |
coordinates |
NDArray[float32]
|
|
velocities |
NDArray[float32] | None
|
|
time |
float
|
Current simulation time (ps). |
force_field |
str
|
Force-field name (e.g. |
temperature |
float
|
Thermostat target temperature (K). |
timestep |
float
|
Integrator timestep (ps). |
engine_handle |
object | None
|
Engine-private. Not part of the public API.
An opaque reference to whatever live state the engine
wrapper that produced this :class: Two consequences worth being explicit about:
For per-simulation data you do want to read, use
:attr: |
metadata |
dict[str, object]
|
Free-form engine-specific extras. Unlike
|
MDEngine ¶
Bases: ABC
Abstract base for MD engines (OpenMM, GROMACS, ...).
Subclasses live under :mod:molforge.wrappers.md and must implement
:meth:prepare, :meth:minimize, and :meth:run. The contract is
deliberately small so users can swap engines without rewriting their
pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable engine name (set by subclasses). |
prepare
abstractmethod
¶
Build a :class:Simulation from a protein structure.
Concrete engines handle the engine-specific setup: parameterize the system against the force field, build the topology, place the structure in a (possibly periodic) simulation box, add solvent if requested, etc.
minimize
abstractmethod
¶
minimize(
simulation: Simulation,
*,
max_iterations: int = 1000,
tolerance: float = 10.0,
**kwargs: object,
) -> Simulation
Energy-minimize the system in place and return it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
A :class: |
required |
max_iterations
|
int
|
Limit on minimizer steps. |
1000
|
tolerance
|
float
|
Convergence tolerance (kJ/mol/nm). |
10.0
|
Returns:
| Type | Description |
|---|---|
Simulation
|
The same :class: |
run
abstractmethod
¶
run(
simulation: Simulation,
*,
n_steps: int,
save_every: int = 1,
**kwargs: object,
) -> Trajectory
Integrate the simulation for n_steps and return a
:class:Trajectory containing the recorded frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
A :class: |
required |
n_steps
|
int
|
Number of integrator steps to run. |
required |
save_every
|
int
|
Record a frame every |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Trajectory
|
class: |
MDEngineNotInstalledError ¶
Bases: ImportError
Raised when an MD engine's heavy dependencies aren't installed.