Converting from TRR file to xyz format of velocity and coordinate

18 views
Skip to first unread message

Quyen V. Vu

unread,
May 24, 2020, 6:33:11 AM5/24/20
to MDnalysis discussion
Dear all,
I load the Gromacs trajectory from TRR file and want to convert to XYZ with the command:

import MDAnalysis as mda

u
=mda.Universe('md.tpr','md.trr')

with mda.Writer('md.xyz', n_atoms=u.atoms.n_atoms) as xyz:
   
for ts in u.trajectory:
        xyz
.write(ts)

I think mdanalysis will understand the atom name in topology (md.tpr format) and write the XYZ format like:


<number of atoms>
comment line
atom_symbol11 x-coord11 y-coord11 z-coord11

but in fact, the result I got is:
1044
frame
0
       X    
16.44057    1.47570   15.73273
       X    
15.87332    1.95316   16.33811
       X    
15.93302    0.70192   15.48798
       X    
17.21523    7.28262   20.23445
       X    
17.36406    7.14757   19.29858
       X    
18.00691    7.72399   20.54212
       X    
20.12906    8.03738   20.74384

the Atom names are X for all.

How I can solve this problem and I also want to write velocity in xyz format also.
Best regards,
Quyen


Oliver Beckstein

unread,
May 29, 2020, 5:18:56 AM5/29/20
to mdnalysis-...@googlegroups.com
Hi Quyen,

The problem is that you write the raw timestep ts (which we should deprecate and remove from any docs… where did you see this usage?)

xyz.write(ts)
Instead write 

xyz.write(u.atoms)

which will properly read atom information.

For writing velocities you either need a custom writer or you could try a hack like the following where you assign the velocities to the positions in order to trick the XYZWriter into writing them:

with mda.Writer(‘velocities.xyz', n_atoms=u.atoms.n_atoms) as xyz:
    for ts in u.trajectory:
u.atoms.positions = u.atoms.velocities
        xyz.write(u.atoms)

(Your need to do u.atoms.positions = u.atoms.velocities for every frame as they change dynamically.) 

Hope that helps!
Oliver


--
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/b0a269fc-950b-49d1-aaa8-480c74d49273%40googlegroups.com.

--
Oliver Beckstein





Quyen V. Vu

unread,
May 29, 2020, 7:20:45 AM5/29/20
to mdnalysis-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages