nanover.ase.imd module
Interactive molecular dynamics server for use with an ASE molecular dynamics simulation.
- class nanover.ase.imd.NanoverASEDynamics(nanover_imd_app: NanoverImdApplication, dynamics: MolecularDynamics, frame_method: Callable | None = None, frame_interval=1)
Bases:
object
Interactive molecular dynamics adaptor for use with ASE.
- Parameters:
nanover_imd_app – A
NanoverImdApplication
to pass frames to and read forces from.dynamics – A prepared ASE molecular dynamics object to run, with IMD attached.
frame_interval – Interval, in steps, at which to publish frames.
frame_method – Method to use to generate frames, given the ASE
Atoms
and aFramePublisher
. The signature of the callback is expected to beframe_method(ase_atoms, frame_publisher)
.
Example
>>> from ase.calculators.emt import EMT >>> from ase.lattice.cubic import FaceCenteredCubic >>> atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol="Cu", size=(2, 2, 2), pbc=True) >>> atoms.calc = EMT() >>> ase_dynamics = Langevin(atoms, timestep=0.5, temperature_K=300, friction=1.0) >>> with NanoverASEDynamics.basic_imd(ase_dynamics) as sim: # run basic NanoVer server ... ... with NanoverImdClient.autoconnect() as client: # connect an iMD client. ... sim.run(10) # run some dynamics ... client.first_frame.particle_count # the client will have received some MD data! 32
- property address: str
The address of the NanoVer server.
- property atoms: Atoms
The atoms in the MD system.
- Returns:
ASE atoms.
- classmethod basic_imd(dynamics: MolecularDynamics, address: str | None = None, port: int | None = None, **kwargs)
Initialises basic interactive molecular dynamics running a NanoVer server at the given address and port.
- Parameters:
dynamics – Molecular dynamics object to attach the server to.
address – Address to run the server at.
port – Port to run the server on.
kwargs – Key-word arguments to pass to the constructor of :class:~NanoverASEDynamics
- Returns:
Instantiation of a :class:~NanoverASEDynamics configured with the given server parameters and dynamics.
- cancel_run(wait=False)
Cancel molecular dynamics that is running on a background thread.
- Parameters:
wait – Whether to block and wait for the molecular dynamics to halt before returning.
- close()
Cancels the molecular dynamics if it is running.
- dynamics: MolecularDynamics
- property dynamics_interval
Minimum interval, in seconds, between frames sent to the frame publisher.
- imd_calculator: ImdCalculator
- property internal_calculator: Calculator | None
The internal calculator being used to compute internal energy and forces.
- Returns:
ASE internal calculator.
- property is_running
Whether or not the molecular dynamics is currently running on a background thread or not. :return: True, if molecular dynamics is running, False otherwise.
- on_reset_listeners: List[Callable[[], None]]
- pause()
Pause the simulation, by cancelling any current run.
This method is called whenever a client runs the pause command, described in :mod:nanover.trajectory.frame_server.
- play()
Run the simulation indefinitely
Cancels any current run and then begins running the simulation on a background thread.
This method is called whenever a client runs the play command, described in :mod:nanover.trajectory.frame_server.
- property port: str
The port of the NanoVer server. :return:
- replace_dynamics(dynamics: MolecularDynamics, reset=True)
- reset()
Reset the positions, velocities, and box to their initial values.
When this happens, the “on_reset” event is triggered and all the callbacks listed in the
on_reset_listeners
are called. These callbacks are called without arguments and no return value is stored.Note
Only the positions, the velocities, and the simulation box are reset to their initial values. If a simulation needs any other state to be reset or updated, one should register a callback in the
on_reset_listeners
list. The callbacks are executed in the order of the list, after the positions, velocities, and box are reset.Such callbacks also allow to modify the simulation at each reset. They would allow, for instance, to draw new velocities, or to place molecules differently.
This method is called whenever a client runs the reset command, described in
nanover.trajectory.frame_server
.
- run(steps: int | None = None, block: bool | None = None, reset_energy: float | None = None)
Runs the molecular dynamics.
- Parameters:
steps – If passed, will run the given number of steps, otherwise will run forever on a background thread and immediately return.
block – If
False
, run in a separate thread. By default, “block” isNone
, which means it is automatically set toTrue
if a number of steps is provided and toFalse
otherwise.reset_energy – Threshold of total energy in kJ/mol above which the simulation is reset to its initial conditions. If a value is provided, the simulation is reset if the total energy is greater than this value, or if the total energy is nan or infinite. If
None
is provided instead, then the simulation will not be automatically reset.
- step()
Take a single step of the simulation and stop.
This method is called whenever a client runs the step command, described in :mod:nanover.trajectory.frame_server.