In most case, to use pytraj
, you just need to rember this format
import pytraj as pt
traj = pt.iterload(...)
data = pt.method_name(traj, mask=mask, ref=ref, frame_indices=frame_indices ...)
traj
can be a Trajectory-like (having 3D coordinates and a Topology) or it can be
any iterable object that produces pytraj.Frame
(a single snapshot):
# a Trajectory
import pytraj as pt
traj = pt.iterload('traj.nc', 'traj.prmtop')
pt.radgyr(traj)
# an iterable object
def create_iterator(traj):
for frame in traj:
frame.xyz += 2.
yield frame
fi = create_iterator(traj)
pt.radgyr(fi, top=traj.top)
# a FrameIterator
fi2 = pt.iterframe(traj, frame_indices=[0, 8, 3], mask='@CA')
pt.radgyr(fi2)
ref
can be a single Frame or a Trajectory or an integer. If it’s a Trajectory,
first conformation is always picked up. If it’s an integer, pytraj will do slicing the
corresponding Trajectory:
frame = traj[3]
traj2 = traj[3:4]
pt.rmsd(traj, ref=frame)
pt.rmsd(traj, ref=3)
pt.rmsd(traj, ref=traj2)
mask
follows Amber mask syntax (eg. :3-18@CA) or an atom index array (eg. [0, 3, 5]). If mask
is a string (amber mask), the index is 1-based (counting from 1). If mass
is an array-like, the index is 0-based (counting from 0):
# mask is a string
pt.radgyr(traj, '@CA')
# mask is a list of integers (atom indices)
pt.radgyr(traj, mask=[0, 3, 5, 7])
frame_indices
is frame indices for calculation. It’s optional. If no frame_indices
is provided, the calculation will be performed for whole trajectory:
# only compute radgyr for 3 frames (0, 3, and 7-th)
pt.radgyr(traj, frame_indices=[0, 3, 7])
# calculate radius of gyration for whole trajectory, all atoms
In [1]: import pytraj as pt
In [2]: traj = pt.iterload('tz2.nc', 'tz2.parm7')
In [3]: traj
Out[3]:
pytraj.TrajectoryIterator, 101 frames:
Size: 0.000503 (GB)
<Topology: 223 atoms, 13 residues, 1 mols, non-PBC>
In [4]: data = pt.radgyr(traj)
# calculate radius of gyration for whole trajectory, @CA atoms
In [5]: data = pt.radgyr(traj, mask='@CA')
# calculate radius of gyration for whole trajectory, for atom indices of [0, 3, 5, 100]
In [6]: data = pt.radgyr(traj, mask=[0, 3, 5, 100])
# calculate radius of gyration for whole trajectory, all atoms, only for 0, 7, and 8-th frames
In [7]: data = pt.radgyr(traj, frame_indices=[0, 7, 8])
# calculate rmsd with reference as 0-th frame, all atoms
In [8]: data = pt.rmsd(traj, ref=0)
# calculate rmsd with reference as 0-th frame, backbone heavy atoms
In [9]: data = pt.rmsd(traj, ref=0, mask='@C,CA,N,O')
# calculate rmsd with reference as last frame, CA atoms
In [10]: data = pt.rmsd(traj, ref=-1, mask='@CA')
In [11]: data
Out[11]: array([ 4.832 , 5.168 , 4.7418, ..., 1.0441, 1.3155, 0. ])