I am trying to save a PDB of the final frame of my trajectory/universe. I apologize if this has been asked before, but I don't see it in the tutorials or the Google group.
Try #1 - The tutorial code below saves the first frame, although, notably, the first frame isn't explicitly specified anywhere in the code:
from MDAnalysis.tests.datafiles import PDB, XTC
u = MDAnalysis.Universe(PDB, XTC)
protein = u.select_atoms("protein")
protein.write("test.pdb")
I'd expect that slicing out on the last frame would save the last frame:
# slice out final frame
finalFrame = u.trajectory[:-1]
protein = finalFrame.select_atoms("protein")
protein.write("test.pdb")
But I get the error:
AttributeError: 'FrameIteratorSliced' object has no attribute 'select_atoms'
Try #2A - This tutorial code saves the PDB for every step in the trajectory:
u = MDAnalysis.Universe(PDB, XTC)
protein = u.select_atoms("protein")
with MDAnalysis.Writer("test.pdb", protein.n_atoms) as W:
for ts in u.trajectory:
W.write(protein)
W.write(protein)
But if I slice out just the final frame (like below) I get the same AttributeError above.
u = MDAnalysis.Universe(PDB, XTC)
#slice out final frame of trajectory
u = u.trajectory[:-1]
protein = u.select_atoms("protein")
with MDAnalysis.Writer("test.pdb", protein.n_atoms) as W:
for ts in u.trajectory[-1]:
W.write(protein)
Try # 2B - and if I slice out the final frame later, like below, it takes at least 1000X+ longer than saving every frame as a PDB and never seems to finish.
u = MDAnalysis.Universe(PDB, XTC)
protein = u.select_atoms("protein")
with MDAnalysis.Writer("test.pdb", protein.n_atoms) as W:
for ts in u.trajectory[-1]:
W.write(protein)
So, I am still not sure how to save the final frame as a PDB with MDAnalysis. Thanks for your help! -Jason