def test_greedy_splitext(inp="foo/bar/boing.2.pdb.bz2",
                         ref=("foo/bar/boing", ".2.pdb.bz2")):
    root, ext = util.greedy_splitext(inp)
    assert_equal(root, ref[0], err_msg="root incorrect")
    assert_equal(ext, ref[1], err_msg="extension incorrect")
Exemple #2
0
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 %d" % ts.frame
w.close_trajectory()
print "Converted %r --> %r" % (intrj, outtrj)