Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 44 lines (32 sloc) 1.17 KB
#!/usr/bin/env python
# coding=utf-8
"""
MDAnalysis example: Convert Amber formatted trajectory to DCD
=============================================================
This example shows how one can use MDAnalysis to convert between
different trajectory formats.
"""
# from MDAnalysis.tests.datafiles import PRMpbc,TRJpbc_bz2
from MDAnalysis.tests.datafiles import PRM, TRJ_bz2
from MDAnalysis import Universe, Writer
from MDAnalysis.lib.util import greedy_splitext
import os.path
topol = PRM # PRMpbc
intrj = TRJ_bz2 # TRJpbc_bz2
ext = '.dcd' # output format determined by extension
root, oldext = greedy_splitext(os.path.basename(intrj))
outtrj = root + ext
outpdb = root + '.pdb'
u = Universe(topol, intrj)
# create a writer instance for the output trajectory
w = Writer(outtrj, u.trajectory.numatoms)
# loop through the trajectory and write a frame for every step
for ts in u.trajectory:
w.write(ts)
print "Converted frame {0:d}".format(ts.frame)
w.close_trajectory()
print "Converted {0!r} --> {1!r}".format(intrj, outtrj)
# make a pdb file as a simple 'topology'
u.trajectory.rewind()
u.atoms.write(outpdb)
print "Created {0!r} to be used with the trajectory".format(outpdb)