Accessing velocity of atoms in each frame

113 views
Skip to first unread message

Teslim Olayiwola

unread,
Oct 1, 2022, 10:57:48 AM10/1/22
to MDnalysis discussion
Hi everyone,

Thanks for the great tool! I am trying to access the velocity of each atom in a lammps trajectory (see attached image for a screenshot of the lammpstrj file) for 1 frame at a time. In my code, I have the tried the following:

import MDAnalysis as mda

lammps_data = "npt_stp04.data"
lammps_trajectory = "dump_npt_step04.lammpstrj"

data = mda.Universe(lammps_data, lammps_trajectory, format="LAMMPSDUMP", has_velocities = True)

choice_atoms = data.select_atoms("type 63")

for ts in data.trajectory:
        reference = choice_atoms.ts.velocities

I got the following error

NoDataError Traceback (most recent call last) <ipython-input-108-7356210d6102> in <module> 
1 for ts in data.trajectory: 
----> 2 reference = choice_atoms.ts.velocities ~/opt/anaconda3/lib/python3.8/site-packages/MDAnalysis/coordinates/base.py in __getattr__(self, attr) 
488 # special-case timestep info 
489 if attr in ('velocities', 'forces', 'positions'):
--> 490 raise NoDataError('This Timestep has no ' + attr) 
491 err = "{selfcls} object has no attribute '{attr}'" 
492 raise AttributeError(err.format(selfcls=type(self).__name__, 

NoDataError: This Timestep has no velocities


Please advise on what to do. Thank you very much!

Screen Shot 2022-10-01 at 9.56.50 AM.png

Oliver Beckstein

unread,
Oct 1, 2022, 7:50:47 PM10/1/22
to mdnalysis-...@googlegroups.com

Hi Teslim,

I’m not sure if the LAMMPS reader actually read velocities. The table https://userguide.mdanalysis.org/stable/formats/index.html#coordinates says no but it may be outdated. 

Did you (or anyone else) have a look at the code to check that it actually reads velocities?

If it doesn’t then you can raise an issue and suggest it as an enhancement. 

Oliver 

Am 10/1/22 um 07:57 schrieb Teslim Olayiwola <olayiwol...@gmail.com>:

Hi everyone,
--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/e306e218-737d-431c-9ead-e633f3d1fa82n%40googlegroups.com.

Hugo Macdermott-Opeskin

unread,
Oct 1, 2022, 11:12:23 PM10/1/22
to MDnalysis discussion
There is an open PR with this fix. 
You may be able to use that branch in the interim until it is merged. :)

Teslim Olayiwola

unread,
Oct 2, 2022, 7:31:13 AM10/2/22
to mdnalysis-...@googlegroups.com
Thank you very much to you (Hugo), Oliver and the entire MDAnalysis team! How do I download this new fix and merge it to the existing version on my PC?

You received this message because you are subscribed to a topic in the Google Groups "MDnalysis discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mdnalysis-discussion/LQ341zc8lt4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mdnalysis-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/b907a639-e55e-44e2-a252-3facb9600fbbn%40googlegroups.com.

Teslim Olayiwola

unread,
Oct 2, 2022, 6:26:47 PM10/2/22
to mdnalysis-...@googlegroups.com
Thank you. I have been able to install it! I made use of the Github desktop to synchronize it to my PC.


Reply all
Reply to author
Forward
0 new messages