pub struct PyMdSimulation { /* private fields */ }Expand description
Molecular Dynamics simulation (NVE/NVT) with periodic boundary conditions.
Uses a velocity-Verlet integrator and a truncated-shifted Lennard-Jones pair potential. Supports an optional velocity-rescaling thermostat.
Implementations§
Source§impl PyMdSimulation
impl PyMdSimulation
Sourcepub fn new(config: PyMdConfig) -> Self
pub fn new(config: PyMdConfig) -> Self
Create a new empty MD simulation from the given configuration.
Sourcepub fn add_atom(&mut self, position: [f64; 3], atom_type: u32) -> usize
pub fn add_atom(&mut self, position: [f64; 3], atom_type: u32) -> usize
Add an atom at position with the given type index.
Returns the index of the newly added atom.
Sourcepub fn set_velocity(&mut self, i: usize, vel: [f64; 3])
pub fn set_velocity(&mut self, i: usize, vel: [f64; 3])
Set the velocity of atom i. No-op if i is out of bounds.
Sourcepub fn position(&self, i: usize) -> Option<[f64; 3]>
pub fn position(&self, i: usize) -> Option<[f64; 3]>
Get the position of atom i, or None if out of bounds.
Sourcepub fn velocity(&self, i: usize) -> Option<[f64; 3]>
pub fn velocity(&self, i: usize) -> Option<[f64; 3]>
Get the velocity of atom i, or None if out of bounds.
Sourcepub fn atom_count(&self) -> usize
pub fn atom_count(&self) -> usize
Number of atoms in the simulation.
Sourcepub fn step_count(&self) -> u64
pub fn step_count(&self) -> u64
Number of completed steps.
Sourcepub fn set_thermostat(&mut self, active: bool)
pub fn set_thermostat(&mut self, active: bool)
Enable or disable the velocity-rescaling thermostat.
Sourcepub fn thermostat_active(&self) -> bool
pub fn thermostat_active(&self) -> bool
Whether the thermostat is active.
Sourcepub fn set_target_temperature(&mut self, t: f64)
pub fn set_target_temperature(&mut self, t: f64)
Set the target temperature for the thermostat.
Sourcepub fn potential_energy(&self) -> f64
pub fn potential_energy(&self) -> f64
Total potential energy from the last step.
Sourcepub fn kinetic_energy(&self) -> f64
pub fn kinetic_energy(&self) -> f64
Total kinetic energy summed over all atoms.
Sourcepub fn total_energy(&self) -> f64
pub fn total_energy(&self) -> f64
Total energy (kinetic + potential).
Sourcepub fn temperature(&self) -> f64
pub fn temperature(&self) -> f64
Instantaneous temperature from equipartition: T = 2KE / (3N*k_B).
In reduced units k_B = 1, so T = 2KE / (3N).
Sourcepub fn step(&mut self, dt: f64)
pub fn step(&mut self, dt: f64)
Advance the simulation by dt using velocity Verlet integration.
Steps:
- Half-kick velocities: v += 0.5 * f/m * dt
- Update positions: x += v * dt (with PBC wrap)
- Recompute forces from LJ pair potential
- Half-kick velocities again
- Optionally rescale velocities to match target temperature
Sourcepub fn all_positions(&self) -> Vec<f64>
pub fn all_positions(&self) -> Vec<f64>
Return all atom positions as a flat Vecf64of[x,y,z]` triples.
Sourcepub fn all_velocities(&self) -> Vec<f64>
pub fn all_velocities(&self) -> Vec<f64>
Return all atom velocities as a flat Vec<f64> of [vx,vy,vz] triples.
Trait Implementations§
Source§impl Clone for PyMdSimulation
impl Clone for PyMdSimulation
Source§fn clone(&self) -> PyMdSimulation
fn clone(&self) -> PyMdSimulation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PyMdSimulation
impl RefUnwindSafe for PyMdSimulation
impl Send for PyMdSimulation
impl Sync for PyMdSimulation
impl Unpin for PyMdSimulation
impl UnsafeUnpin for PyMdSimulation
impl UnwindSafe for PyMdSimulation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.