Trajectory Output

This example shows how to output processed trajectories.

Input files

Currently, ProDy supports only DCD format files. Two DCD trajectory files and corresponding PDB structure file is needed for this example:

Setup environment

We start by importing everything from ProDy:

In [1]: from prody import *

In [2]: from pylab import *

In [3]: ion()

Load structure

The PDB file provided with this example contains an X-ray structure:

In [4]: mdm2 = parsePDB('mdm2.pdb')

In [5]: repr(mdm2)
Out[5]: '<AtomGroup: mdm2 (1449 atoms)>'

This function returned a AtomGroup instance that stores all atomic data parsed from the PDB file.

Open trajectories

Trajectory is designed for handling multiple trajectory files:

In [6]: traj = Trajectory('mdm2.dcd')

In [7]: traj
Out[7]: <Trajectory: mdm2 (next 0 of 500 frames; 1449 atoms)>

In [8]: traj.addFile('mdm2sim2.dcd')

In [9]: traj
Out[9]: <Trajectory: mdm2 (2 files; next 0 of 1000 frames; 1449 atoms)>

Now we link the trajectory (traj) with the atom group (mdm2):

In [10]: traj.link(mdm2)

Note

Note that when a frame (coordinate set) is parsed from the trajectory file, coordinates of the atom group will be updated.

Output selected atoms

You can write a trajectory in DCD format using writeDCD() function. Let’s select non-hydrogen protein atoms and write a merged trajectory for MDM2:

In [11]: traj.setAtoms(mdm2.noh)

In [12]: traj
Out[12]: <Trajectory: mdm2 (linked to AtomGroup mdm2; 2 files; next 0 of 1000 frames; selected 706 of 1449 atoms)>

In [13]: writeDCD('mdm2_merged_noh.dcd', traj)


@> Writing DCD [  1%]
                     
@> Writing DCD [  2%]
                     
@> Writing DCD [  3%]
                     
@> Writing DCD [  4%] 1s
                        
@> Writing DCD [  5%] 1s
                        
@> Writing DCD [  6%] 1s
                        
@> Writing DCD [  7%] 1s
                        
@> Writing DCD [  8%] 1s
                        
@> Writing DCD [  9%] 1s
                        
@> Writing DCD [ 10%] 1s
                        
@> Writing DCD [ 11%] 1s
                        
@> Writing DCD [ 12%] 1s
                        
@> Writing DCD [ 13%] 1s
                        
@> Writing DCD [ 14%] 1s
                        
@> Writing DCD [ 15%] 1s
                        
@> Writing DCD [ 16%] 1s
                        
@> Writing DCD [ 17%] 1s
                        
@> Writing DCD [ 18%] 1s
                        
@> Writing DCD [ 19%] 1s
                        
@> Writing DCD [ 20%] 1s
                        
@> Writing DCD [ 21%] 1s
                        
@> Writing DCD [ 22%] 1s
                        
@> Writing DCD [ 23%] 1s
                        
@> Writing DCD [ 24%] 1s
                        
@> Writing DCD [ 25%] 1s
                        
@> Writing DCD [ 26%] 1s
                        
@> Writing DCD [ 27%] 1s
                        
@> Writing DCD [ 28%] 1s
                        
@> Writing DCD [ 29%] 1s
                        
@> Writing DCD [ 30%] 1s
                        
@> Writing DCD [ 31%] 1s
                        
@> Writing DCD [ 32%] 1s
                        
@> Writing DCD [ 33%] 1s
                        
@> Writing DCD [ 34%] 1s
                        
@> Writing DCD [ 35%] 1s
                        
@> Writing DCD [ 36%] 1s
                        
@> Writing DCD [ 37%] 1s
                        
@> Writing DCD [ 38%] 1s
                        
@> Writing DCD [ 39%] 1s
                        
@> Writing DCD [ 40%] 1s
                        
@> Writing DCD [ 41%] 1s
                        
@> Writing DCD [ 42%] 1s
                        
@> Writing DCD [ 43%] 1s
                        
@> Writing DCD [ 44%] 1s
                        
@> Writing DCD [ 45%] 1s
                        
@> Writing DCD [ 46%] 1s
                        
@> Writing DCD [ 47%] 1s
                        
@> Writing DCD [ 48%] 1s
                        
@> Writing DCD [ 49%] 1s
                        
@> Writing DCD [ 50%] 1s
                        
@> Writing DCD [ 51%] 1s
                        
@> Writing DCD [ 52%] 1s
                        
@> Writing DCD [ 53%] 1s
                        
@> Writing DCD [ 54%] 1s
                        
@> Writing DCD [ 55%] 1s
                        
@> Writing DCD [ 56%] 1s
                        
@> Writing DCD [ 57%] 1s
                        
@> Writing DCD [ 58%] 1s
                        
@> Writing DCD [ 59%] 1s
                        
@> Writing DCD [ 60%] 1s
                        
@> Writing DCD [ 61%] 1s
                        
@> Writing DCD [ 62%] 1s
                        
@> Writing DCD [ 63%] 1s
                        
@> Writing DCD [ 64%] 1s
                        
@> Writing DCD [ 65%] 1s
                        
@> Writing DCD [ 66%] 1s
                        
@> Writing DCD [ 67%] 1s
                        
@> Writing DCD [ 68%] 1s
                        
@> Writing DCD [ 69%] 1s
                        
@> Writing DCD [ 70%] 1s
                        
@> Writing DCD [ 71%] 1s
                        
@> Writing DCD [ 72%] 1s
                        
@> Writing DCD [ 73%] 1s
                        
@> Writing DCD [ 74%] 1s
                        
@> Writing DCD [ 75%] 1s
                        
@> Writing DCD [ 76%] 1s
                        
@> Writing DCD [ 77%] 1s
                        
@> Writing DCD [ 78%] 1s
                        
@> Writing DCD [ 79%] 1s
                        
@> Writing DCD [ 80%] 1s
                        
@> Writing DCD [ 81%] 1s
                        
@> Writing DCD [ 82%] 1s
                        
@> Writing DCD [ 83%] 1s
                        
@> Writing DCD [ 84%] 1s
                        
@> Writing DCD [ 85%] 1s
                        
@> Writing DCD [ 86%] 1s
                        
@> Writing DCD [ 87%] 1s
                        
@> Writing DCD [ 88%] 1s
                        
@> Writing DCD [ 89%] 1s
                        
@> Writing DCD [ 90%] 1s
                        
@> Writing DCD [ 91%] 1s
                        
@> Writing DCD [ 92%] 1s
                        
@> Writing DCD [ 93%] 1s
                        
@> Writing DCD [ 94%] 1s
                        
@> Writing DCD [ 95%] 1s
                        
@> Writing DCD [ 96%] 1s
                        
@> Writing DCD [ 97%] 1s
                        
@> Writing DCD [ 98%] 1s
                        
@> Writing DCD [ 99%] 1s
                        
Out[13]: 'mdm2_merged_noh.dcd'

Parsing this file returns:

In [14]: DCDFile('mdm2_merged_noh.dcd')
Out[14]: <DCDFile: mdm2_merged_noh (next 0 of 1000 frames; 706 atoms)>

Output aligned frames

You can write a trajectory in DCD format after aligning the frames. Let’s return to the first frame by resetting the trajectory:

In [15]: traj.reset()

In [16]: traj
Out[16]: <Trajectory: mdm2 (linked to AtomGroup mdm2; 2 files; next 0 of 1000 frames; selected 706 of 1449 atoms)>

It is possible to write multiple DCD files at the same time. We open two DCD files in write mode, one for all atoms, and another for backbone atoms:

In [17]: out = DCDFile('mdm2_aligned.dcd', 'w')

In [18]: out_bb = DCDFile('mdm2_bb_aligned.dcd', 'w')

In [19]: mdm2_bb = mdm2.backbone

Let’s align and write frames one by one:

In [20]: for frame in traj:
   ....:     frame.superpose()
   ....:     out.write(mdm2)
   ....:     out_bb.write(mdm2_bb)
   ....: 

Let’s open these files to show number of atoms in each:

In [21]: DCDFile('mdm2_aligned.dcd')
Out[21]: <DCDFile: mdm2_aligned (next 0 of 1000 frames; 1449 atoms)>

In [22]: DCDFile('mdm2_bb_aligned.dcd')
Out[22]: <DCDFile: mdm2_bb_aligned (next 0 of 1000 frames; 339 atoms)>