ash icon indicating copy to clipboard operation
ash copied to clipboard

Inititialisation of velocities in MD

Open jromero-astro opened this issue 4 months ago • 3 comments

Dear Ragnar, I was wondering if it is possible to provide a list of velocities directly to the MD module for each atom. In addition, I've noticed there is the possibility of using the RRPM integrator in the MD module. Is it documented within ASH or should we rely on the openMM backend?

Thanks a lot, J. Enrique-Romero

jromero-astro avatar Sep 19 '25 09:09 jromero-astro

Hi there

Yes, this is possible. Unfortunately, not yet documented in the ASH documentation. The OpenMM library supports restarting simulations by either binary checkpoint files or XML-state files: https://docs.openmm.org/latest/userguide/application/02_running_sims.html#saving-simulation-progress-and-results

The state-XML file option is here what you want. It has this syntax (diatomic molecule shown):

<?xml version="1.0" ?>
<State openmmVersion="8.3" stepCount="100" time=".10000000000000007" type="State" version="1">
    <PeriodicBoxVectors>
        <A x="2" y="0" z="0"/>
        <B x="0" y="2" z="0"/>
        <C x="0" y="0" z="2"/>
    </PeriodicBoxVectors>
    <Parameters/>
    <Positions>
        <Position x=".008686653612073623" y=".013197006052021825" z="-.0001458851064637103"/>
        <Position x="-.0005478869013667725" y="-.000729813364949961" z=".09166779442536259"/>
    </Positions>
    <Velocities>
        <Velocity x=".03210965794276634" y=".4381082392746044" z=".682044684968602"/>
        <Velocity x="-.014983076408536472" y="-.011669544972909418" z="-.012789170128928287"/>
    </Velocities>
    <IntegratorParameters/>
</State>

This file (named OpenMM_MD_state.xml) is automatically written to disk when running MD via ASH, every X steps, where X is controlled by the restartfile_frequency keyword (default is 1000).

You can also create the file yourself or modify e.g. the velocities manually.

To then start a new simulation from that file with your desired coordinates and velocities you do this:

from ash import *

frag = Fragment(databasefile="hf.xyz")
theory = xTBTheory()

MolecularDynamics(theory=theory, fragment=frag, simulation_time=2,
    statefile="OpenMM_MD_state_prev.xml")

The RPMD integrator was made available in the ASH interface, per a user request, but a practical simulation has not really been run and tested by me. I think some additional changes may be necessary to the ASH interface for it to be useful. It's on the TODO list.

RagnarB83 avatar Sep 21 '25 11:09 RagnarB83

Added to documentation: https://ash.readthedocs.io/en/latest/module_dynamics.html#restarting-md-simulations

RagnarB83 avatar Sep 21 '25 11:09 RagnarB83

Thanks a lot Ragnar! That is very helpful and informative :)

jromero-astro avatar Sep 22 '25 13:09 jromero-astro