LAMMPS dump - problem with coordinates

105 views
Skip to first unread message

yann claveau

unread,
Jun 9, 2021, 8:28:50 AM6/9/21
to MDnalysis discussion
Dear all,

I am discovering MDAnalysis.

When reading a lammps' dump file, the atom's coordinates do not follow the lammps convention :
For instance, for LAMMPS, here are my (cubic) box dimensions

-2 2
-2 2
-2 2

and here are the reduce coordinates of one atom, in the dump file :
[0.5 , 0.5 , 0.5]

Following the lammps convention, that means that the atom is at the center of the box. So its real coordinates are :
[0, 0, 0]

That is indeed the case when opening the dump file in ovito or vmd. However, MDanalysis does not use the box coordinates but rather :
[4, 4, 4, 90°, 90°, 90°]

and so, for MDA, the atom coordinates are
[2, 2, 2]

Is it possible to follow the lammps convention or do I have to shift all coordinates after importation ?

Thanks,
Yann


Lily Wang

unread,
Jun 9, 2021, 9:41:23 AM6/9/21
to mdnalysis-...@googlegroups.com
Hi Yann,

Welcome to MDAnalysis!

Currently MDAnalysis stores all boxes as box lengths relative to the origin, i.e. it follows these equations but does not store xlo, ylo, zlo. Therefore it is definitely easiest to translate your coordinates upon or after loading into MDAnalysis. One way you could do this is with on-the-fly transformations, which will shift your coordinates for every frame as it’s read so you don’t need to manually shift. e.g.

import MDAnalysis as mda

from MDAnalysis import transformations as trans

u = mda.Universe("my_lammps_files", transformations=trans.translate([-2, -2, -2]))

Hope that helps!

Cheers,
Lily

--
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/68cab6a2-6b33-4cea-85af-272e149d0b5bn%40googlegroups.com.

yann claveau

unread,
Jun 9, 2021, 12:14:54 PM6/9/21
to MDnalysis discussion
Thank you Lily !

Your solution is quite convenient but can be source of problem if I forgot to change the trans.translate([-2, -2, -2]) for a box with a different size. So I would probably stick to a shift such as

u = mda.Universe("my_lammps_files")

for ts in u.trajectory:
    x = u.atoms.ts.positions[:,0] - u.dimensions[0]/2

Cheers,
Yann

Irfan Alibay

unread,
Jun 9, 2021, 12:17:20 PM6/9/21
to MDnalysis discussion
Hi Yann,

> for ts in u.trajectory:
>    x = u.atoms.ts.positions[:,0] - u.dimensions[0]/2

Just in case, it's worth mentioning here that this will only change the positions temporarily whilst you're accessing that timestep (i.e. if you then access the first frame your positions won't be changed).
You can get around this by transferring to memory although that can be a quite memory intensive thing to do.

- Irfan

yann claveau

unread,
Jun 9, 2021, 1:47:25 PM6/9/21
to MDnalysis discussion

HI Irfan,

thanks. I just realized, I was writing python script, so I can use standard python to get the xlo xhi etc. of my dump and then use.  😅

transformations=trans.translate(xlo, ylo, zlo) when importing the dump ! ^^


Yann

Reply all
Reply to author
Forward
0 new messages