# How to write an entire trajectory into a single PDB file?

I have a trajectory (few frames) that I want to stack together and build a single PDB. I thought either to use VMD or MDAnalysis library.

With VMD if I do atomselect it takes a frame identifier as an argument. With MDAnalysis I saw this:

with MDAnalysis.Writer("all.pdb", multiframe=True) as pdb:
for ts in u.trajectory:
pdb.write(u)


However, I am not sure how to use it in a complete script.

• Not only is your edit asking a different question, it's not the right question. That PDB file doesn't have multiple "trajectories" or frames. It's a protein with quaternary structure, where each subunit is separated by a TER card. You should ask a separate question about how to split apart PDB files. Dec 30 '17 at 17:29
• @pentavalentcarbon I see, that was my original problem. I created a new question.
– 0x90
Dec 31 '17 at 1:29

#!/usr/bin/env python2

import MDAnalysis

# file formats are automatically deduced; this is a standard topology and binary
# (NetCDF) trajectory from AMBER
topology = 'peptide_1.prmtop'
trajectory = '02_peptide_1_equil_NVT.nc'
u = MDAnalysis.Universe(topology, trajectory)

with MDAnalysis.Writer("all.pdb", multiframe=True) as pdb:
for ts in u.trajectory:
pdb.write(u)


One thing that may be important: I see lots of warnings when trying to use Python 3, so 2.7 is probably better at this point.