trajectory with velocities?

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Michal Krompiec
Posts: 21
Joined: Tue Jul 02, 2019 1:17 pm

trajectory with velocities?

Post by Michal Krompiec » Mon Mar 23, 2020 7:32 am

Hello, I would like to save a trajectory with both positions and velocities of all particles. Ideally, in XYZ or GRO format (or something that can be converted to any of these). Is it possible or do I have to write my own reporter? So far, I tried the MdcrdReporter from Parmed, but its format is not what I need (unless there is a way to convert it to xyz or gro?).
Thanks in advance,
Michal

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: trajectory with velocities?

Post by Peter Eastman » Mon Mar 23, 2020 9:11 am

The NetCDF reporter in ParmEd can also save velocities. And MDTraj has an HDF5 reporter that can save velocities: http://mdtraj.org/development/api/gener ... F5Reporter.

User avatar
Michal Krompiec
Posts: 21
Joined: Tue Jul 02, 2019 1:17 pm

Re: trajectory with velocities?

Post by Michal Krompiec » Mon Mar 23, 2020 3:17 pm

Thank you!
It turned out to be relatively simple. Just in case anyone else needs a xyz trajectory with units of their choice, this is how I eventually did it:

Code: Select all

class XyzReporter(object):
    def __init__(self, file, reportInterval):
        self._reportInterval = reportInterval
        self._out = None
        self.fname = file

    def describeNextReport(self, simulation):
        stepsleft = simulation.currentStep % self._reportInterval
        steps = self._reportInterval - stepsleft
        return (steps, True, True, False, False)

    def report(self, simulation, state):
        crds = state.getPositions().value_in_unit(unit.angstrom)
        vels = state.getVelocities().value_in_unit(unit.angstrom / unit.femtosecond)
        if self._out is None:
            self.atom = len(crds)
            self._out = open(self.fname, 'w')

        self._out.write(f"{self.atom}\nOpenMM Trajectory\n")
        # Add the coordinates, velocities, and/or forces as needed
        atoms=simulation.topology.atoms()
        for atom, crd, vel in zip(atoms, crds, vels):
            self._out.write(f"{atom.name} {crd[0]} {crd[1]} {crd[2]} {vel[0]} {vel[1]} {vel[2]}\n")

Best,
Michal

POST REPLY