velocities not written to DCD

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

velocities not written to DCD

Post by Daniel Konstantinovsky » Wed Apr 21, 2021 4:12 pm

Hi, here I am again.
I am trying to use MDTraj's dcdreporter to write both coordinates and velocities to a trajectory. I am using this tool:

https://mdtraj.org/1.9.3/api/generated/ ... ctory%20to.

I set velocitiesbool to True but the velocities are not written to the DCD file.

How can I fix this?

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

Re: velocities not written to DCD

Post by Peter Eastman » Wed Apr 21, 2021 4:34 pm

I think the docs rendering is messed up. The parameter is called "velocities", not "velocitiesbool". It's leaving out the space between the name and type.

User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

Re: velocities not written to DCD

Post by Daniel Konstantinovsky » Wed Apr 21, 2021 4:38 pm

Oh ok. Thank you. I thought there was something odd about the naming!

User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

Re: velocities not written to DCD

Post by Daniel Konstantinovsky » Wed Apr 21, 2021 4:49 pm

An update: I tried "velocities" and while it successfully sets the parameter to True (checked vars()), velocities are still not written. Is it possible that the MDTraj DCDReporter hasn't implemented velocity writing yet and the documentation is ahead of the code? Should I just use DCDReporter from the main OpenMM tools?

User avatar
lewis martin
Posts: 63
Joined: Tue Mar 06, 2018 8:56 pm

Re: velocities not written to DCD

Post by lewis martin » Wed Apr 21, 2021 6:01 pm

DCD files don't specify velocities - the `velocities: bool` in the MDTraj docs was probably intended for the other reporters like HDF5Reporter or NetCDFReporter, either of which can store velocities. So if you wanted to store the velocities alongside the trajectory, use one of those. But if you're stuck with DCD, then you'll need to record the velocities elsewhere.

User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

Re: velocities not written to DCD

Post by Daniel Konstantinovsky » Thu Apr 22, 2021 7:46 am

It seems the MDtraj netcdf reporter can't write velocities. Is the MDTraj/OpenMM team planning to add velocities to this tool soon?

User avatar
lewis martin
Posts: 63
Joined: Tue Mar 06, 2018 8:56 pm

Re: velocities not written to DCD

Post by lewis martin » Thu Apr 22, 2021 7:04 pm

My bad, looks like AMBER can write velocities to a netcdf file ( https://ambermd.org/FileFormats.php#trajectory ) but perhaps the MDTraj NetCDF writer doesn't do a similar thing since I see no mention of 'velocities' in the code: https://github.com/mdtraj/mdtraj/blob/m ... /netcdf.py

You know, looking at the mdtraj 'Trajectory' object, it doesn't even let you access velocities anyway. So how about this:

use hdf5reporter, setting both 'coordinates' and 'velocities' to True. If you want to visualize the trajectory, load the trajectory with mdtraj (i.e. `traj = load_hdf5('my_traj.h5')` ) and then save it as a DCD to view with VMD or whatever ( `traj.save('my_traj.dcd')` ) .

Next, to load the velocities:

Code: Select all

vel = h5py.File('my_traj.h5', 'r')
velocities = vel['velocities'][:]
vel.close()
You'll need to install h5py to read the .h5 file.

User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

Re: velocities not written to DCD

Post by Daniel Konstantinovsky » Fri Jun 11, 2021 9:45 am

I tried the advice above with hdf5 reporter and the even though i said velocities = True, the hdf5 file doesn't have velocities, only coordinates. Is it possible that mdtrajreporters.hdf5reporter just hasn't implemented velocity writing yet, despite the documentation? It would be really great if OpenMM had a straightforward way to save velocities like what AMBER has.

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

Re: velocities not written to DCD

Post by Peter Eastman » Fri Jun 11, 2021 11:13 am

I would try posting on the MDTraj github. If their documentation is incorrect it should be fixed. But more likely there's some other reason it isn't giving you velocities.

User avatar
Daniel Konstantinovsky
Posts: 77
Joined: Tue Jun 11, 2019 12:21 pm

Re: velocities not written to DCD

Post by Daniel Konstantinovsky » Fri Jun 11, 2021 12:18 pm

Update: velocities are included if velocities=True is specified when initializing the reporter, but not if reporter.velocities = True is set later.

POST REPLY