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]:


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)
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)>