Page 1 of 1

velocities not written to DCD

Posted: Wed Apr 21, 2021 4:12 pm
by dkonstan
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?

Re: velocities not written to DCD

Posted: Wed Apr 21, 2021 4:34 pm
by peastman
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.

Re: velocities not written to DCD

Posted: Wed Apr 21, 2021 4:38 pm
by dkonstan
Oh ok. Thank you. I thought there was something odd about the naming!

Re: velocities not written to DCD

Posted: Wed Apr 21, 2021 4:49 pm
by dkonstan
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?

Re: velocities not written to DCD

Posted: Wed Apr 21, 2021 6:01 pm
by lewiso1
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.

Re: velocities not written to DCD

Posted: Thu Apr 22, 2021 7:46 am
by dkonstan
It seems the MDtraj netcdf reporter can't write velocities. Is the MDTraj/OpenMM team planning to add velocities to this tool soon?

Re: velocities not written to DCD

Posted: Thu Apr 22, 2021 7:04 pm
by lewiso1
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.

Re: velocities not written to DCD

Posted: Fri Jun 11, 2021 9:45 am
by dkonstan
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.

Re: velocities not written to DCD

Posted: Fri Jun 11, 2021 11:13 am
by peastman
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.

Re: velocities not written to DCD

Posted: Fri Jun 11, 2021 12:18 pm
by dkonstan
Update: velocities are included if velocities=True is specified when initializing the reporter, but not if reporter.velocities = True is set later.