pytraj
pytraj.
ActionList
(commands=None, Topology top=None, DatasetList dslist=<???>, DataFileList dflist=<???>, crdinfo={})¶Bases: object
Attributes
data |
Store data (CpptrajDatasetList). |
is_setup |
is_setup: ‘bool’ |
n_frames |
n_frames: ‘unsigned int’ |
Methods
add (self[, action, command, top, check_status]) |
Add action to ActionList |
compute (self[, traj]) |
perform a series of Actions on Frame or Trajectory |
post_process (self) |
|
setup (self, Topology top[, crdinfo, n_frames_t]) |
perform Topology checking and some stuff |
add
(self, action='', command='', top=None, DatasetList dslist=<???>, DataFileList dflist=<???>, check_status=False)¶Add action to ActionList
Parameters: | action : str or Action object command : str or ArgList object top : str | Topology | TopologyList dslist : DatasetList dflist : DataFileList check_status : bool, default=False
|
---|
Examples
>>> actlist = ActionList()
>>> actlist.add('radgyr', '@CA', top=traj.top, dslist=dslist)
compute
(self, traj=<???>)¶perform a series of Actions on Frame or Trajectory
data
¶Store data (CpptrajDatasetList). This is for internal use.
is_setup
¶is_setup: ‘bool’
n_frames
¶n_frames: ‘unsigned int’
post_process
(self)¶setup
(self, Topology top, crdinfo={}, n_frames_t=0, bool exit_on_error=True)¶perform Topology checking and some stuff
pytraj.
Atom
¶Bases: object
Examples
>>> from pytraj.core import Atom
>>> # name, type, charge, mass
>>> H = Atom(name='H', type='H', charge='0.0', mass='1.0', resid=0)
Attributes
atomic_number |
|
chain |
|
charge |
|
element |
|
gb_radius |
|
index |
|
mass |
|
molnum |
|
n_bonds |
|
name |
|
resid |
|
resname |
resname: object |
type |
Methods
bonded_indices (self) |
get bond indices that self bonds to |
copy (self) |
|
is_bonded_to (self, int idx) |
|
set_mol (self, int mol_num) |
atomic_number
¶bonded_indices
(self)¶get bond indices that self bonds to
chain
¶charge
¶copy
(self)¶element
¶gb_radius
¶index
¶is_bonded_to
(self, int idx)¶mass
¶molnum
¶n_bonds
¶name
¶resid
¶resname
¶resname: object
set_mol
(self, int mol_num)¶type
¶pytraj.
AtomMask
¶Bases: object
Attributes
indices |
|
mask_string |
|
n_atoms |
|
n_selected |
Methods
add_atom (self, int atom_num) |
add atom index and sort |
add_atom_range (self, int begin, int end) |
|
add_atoms (self, vector[int] v) |
|
add_selected_indices (self, arr0) |
add atom index without sorting |
invert_mask (self) |
|
is_empty (self) |
|
mask_expression (self) |
|
selected_indices (self) |
add_atom
(self, int atom_num)¶add atom index and sort
add_atom_range
(self, int begin, int end)¶add_atoms
(self, vector[int] v)¶indices
¶invert_mask
(self)¶is_empty
(self)¶mask_expression
(self)¶mask_string
¶n_atoms
¶n_selected
¶selected_indices
(self)¶pytraj.
Frame
¶Bases: object
A snapshot of trajectory, hodling coordinates, unicell (box), vector (optional), force (optional), ... This class is for internal use.
Parameters: | n_atoms : int, default=0
frame : a Frame, default=None
atommask : AtomMask, default=None
|
---|
Examples
>>> import pytraj as pt
>>> # create an empty Frame
>>> frame = pt.Frame()
>>> frame.n_atoms
0
>>> # create a Frame with 304 atoms
>>> frame = pt.Frame(304)
>>> frame.n_atoms
304
>>> # create an empty Frame then append coordinate
>>> traj = pt.datafiles.load_tz2()
>>> f0 = traj[0]
>>> frame = pt.Frame()
>>> frame.append_xyz(f0.xyz)
<Frame with 223 atoms>
>>> frame.n_atoms == f0.n_atoms
True
>>> # copy from other Frame
>>> frame2 = pt.Frame(frame)
>>> # create a Frame as a pointer (does not own any memory), used for fast iterating
>>> frame = pt.Frame(f0.n_atoms, f0.xyz, _as_ptr=True)
>>> frame.n_atoms == f0.n_atoms
True
Attributes
box |
unitcell |
coordinates |
return a copy of Frame’s coordinates |
force |
force, default None |
mass |
return mass array |
n_atoms |
|
n_frames |
|
shape |
|
size |
|
temperature |
|
time |
|
top |
|
velocity |
|
xyz |
Methods
append_xyz (self, __Pyx_memviewslice xyz) |
append 3D array and return itself |
atom (self, int atomnum) |
return xyz coordinates of idx-th atom |
center_of_geometry (self, AtomMask atmask) |
return Vec3 storing center of geometry |
center_of_mass (self, AtomMask atmask) |
return Vec3 storing center of mass |
copy (self) |
return a deep copy of Frame |
has_box (self) |
|
has_force (self) |
|
has_velocity (self) |
|
is_ (self, Frame other) |
check if Frame is itself or not |
rmsd (self, Frame frame, AtomMask atommask=None) |
Calculate rmsd betwen two frames |
rmsd_nofit (self, Frame frame, bool mass=False) |
Calculate rmsd betwen two frames without fitting |
rmsfit (self[, ref]) |
do the fitting to reference Frame by rotation and translation |
set_mass (self, Topology top) |
set mass for Frame, requires a Topology |
set_nobox (self) |
set nobox |
strip (self, AtomMask atm) |
strip |
swap_atoms |
swap coordinates for an array of atom pairs |
to_ndarray (self) |
return a ndarray as a view of Frame’s coordinates |
append_xyz
(self, __Pyx_memviewslice xyz)¶append 3D array and return itself
atom
(self, int atomnum)¶return xyz coordinates of idx-th atom
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> frame = traj[0]
>>> frame.atom(10)
array('d', [0.27399998903274536, 11.727999687194824, 8.701000213623047])
box
¶unitcell
center_of_geometry
(self, AtomMask atmask)¶return Vec3 storing center of geometry
center_of_mass
(self, AtomMask atmask)¶return Vec3 storing center of mass
coordinates
¶return a copy of Frame’s coordinates
copy
(self)¶return a deep copy of Frame
force
¶force, default None
has_box
(self)¶has_force
(self)¶has_velocity
(self)¶is_
(self, Frame other)¶check if Frame is itself or not
mass
¶return mass array
n_atoms
¶n_frames
¶rmsd
(self, Frame frame, AtomMask atommask=None, mask=None, top=None, bool mass=False, get_mvv=False)¶Calculate rmsd betwen two frames
Parameters: | frame : Frame instance mass : bool, default = False get_mvv : bool
|
---|
rmsd_nofit
(self, Frame frame, bool mass=False)¶Calculate rmsd betwen two frames without fitting
Parameters: | frame : Frame instance mass : bool, default = False |
---|
rmsfit
(self, ref=None, AtomMask atm=None)¶do the fitting to reference Frame by rotation and translation
set_mass
(self, Topology top)¶set mass for Frame, requires a Topology
set_nobox
(self)¶set nobox
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> frame = traj[0]
>>> frame.box
<Box: ortho, (x, y, z, alpha, beta, gamma) = (35.262779662258, 41.845547679864616, 36.16862952899312, 90.0, 90.0, 90.0)>
>>> frame.set_nobox()
>>> frame.box
<Box: nobox, (x, y, z, alpha, beta, gamma) = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)>
shape
¶size
¶strip
(self, AtomMask atm)¶strip
Parameters: | atm: AtomMask |
---|---|
Returns: | self |
swap_atoms
¶swap coordinates for an array of atom pairs
Parameters: | int_view: 2D-int array-like, shape=(2, n_atoms) |
---|
temperature
¶time
¶to_ndarray
(self)¶return a ndarray as a view of Frame’s coordinates
top
¶velocity
¶xyz
¶pytraj.
Molecule
¶Bases: object
Attributes
begin_atom |
|
end_atom |
|
n_atoms |
Methods
is_solvent (self) |
|
set_first (self, int begin) |
|
set_last (self, int last) |
|
set_no_solvent (self) |
|
set_solvent (self) |
begin_atom
¶end_atom
¶is_solvent
(self)¶n_atoms
¶set_first
(self, int begin)¶set_last
(self, int last)¶set_no_solvent
(self)¶set_solvent
(self)¶pytraj.
Residue
¶Bases: object
Examples
>>> Residue('ALA', resid=0, icode=0, chainID=0)
Attributes
first |
return first atom index (alias of first_atom_index. (experiment)) |
first_atom_index |
|
index |
shortcut of original_resid |
last |
return last atom index (alias of last_atom_index. (experiment)) |
last_atom_index |
|
n_atoms |
|
name |
|
original_resid |
Methods
is_solvent (self) |
|
ntype (self) |
|
set_last_atom (self, int i) |
first
¶return first atom index (alias of first_atom_index. (experiment))
first_atom_index
¶index
¶shortcut of original_resid
is_solvent
(self)¶last
¶return last atom index (alias of last_atom_index. (experiment))
last_atom_index
¶n_atoms
¶name
¶ntype
(self)¶original_resid
¶set_last_atom
(self, int i)¶pytraj.
Topology
¶Bases: object
Attributes
angle_indices |
|
angles |
|
atoms |
|
bond_indices |
|
bonds |
|
box |
|
charge |
return a copy of atom charges (numpy 1D array) |
dihedral_indices |
|
dihedrals |
|
filename |
return original filename. This is for testing purpose. |
mass |
return a copy of atom masses (numpy 1D array) |
mols |
|
n_atoms |
|
n_mols |
|
n_residues |
|
n_solvents |
|
residues |
Methods
__call__ |
intended to use with Frame indexing: atm = top('@CA‘) (for internal use) |
add_angles |
add angle for a group of 3 atoms. |
add_atom (self, Atom atom, Residue residue) |
|
add_bonds |
add bond for pairs of atoms. |
add_dihedrals |
add dihedral for a group of 4 atoms. |
atom (self, int idx) |
return an Atom based on idx. Update this Atom will update Topology. |
atom_indices (self, mask, \*args, \*\*kwd) |
return atom indices with given mask |
copy (self, \*args) |
Return a copy of ‘self’ or copy from ‘other’ to ‘self’ |
from_dict (type cls, dict_data) |
internal use for serialize Topology |
has_box (self) |
|
is_empty (self) |
|
join (self, Topology top) |
|
residue (self, int idx, bool atom=False) |
if atom is True, get full list of atoms for idx-th residue. This will be very slow |
save (self[, filename, format]) |
save to given file format (parm7, psf, ...) |
select (self, mask) |
return atom indices |
set_nobox (self) |
|
set_reference (self, Frame frame) |
Set reference frame for distance-based mask |
set_solvent (self, mask) |
set mask as solvent |
simplify (self) |
return a (immutable) lightweight version of Topology for fast iterating. |
start_new_mol (self) |
|
strip (self, mask[, copy]) |
strip atoms with given mask |
summary (...) |
basic info. This information only appears in Ipython or Python shell. |
to_dict (self) |
convert Topology to Python dict |
to_parmed (self) |
try to load to ParmEd’s Structure |
add_angles
¶add angle for a group of 3 atoms.
Parameters: | indices : 2D array_like (must have buffer interface),
|
---|
add_atom
(self, Atom atom, Residue residue)¶add_bonds
¶add bond for pairs of atoms.
Parameters: | bond_indices : 2D array_like (must have buffer interface)
|
---|
add_dihedrals
¶add dihedral for a group of 4 atoms.
Parameters: | indices : 2D array_like (must have buffer interface),
|
---|
angle_indices
¶angles
¶atom
(self, int idx)¶return an Atom based on idx. Update this Atom will update Topology. Make this method private for now.
atom_indices
(self, mask, *args, **kwd)¶return atom indices with given mask To be the same as cpptraj/Ambertools: we mask indexing starts from 1 but the return list/array use 0
Parameters: | mask : str
Returns —— indices : Python array |
---|
atoms
¶bond_indices
¶bonds
¶box
¶charge
¶return a copy of atom charges (numpy 1D array)
copy
(self, *args)¶Return a copy of ‘self’ or copy from ‘other’ to ‘self’ TODO : add more doc
dihedral_indices
¶dihedrals
¶filename
¶return original filename. This is for testing purpose.
from_dict
(type cls, dict_data)¶internal use for serialize Topology
has_box
(self)¶is_empty
(self)¶join
(self, Topology top)¶mass
¶return a copy of atom masses (numpy 1D array)
mols
¶n_atoms
¶n_mols
¶n_residues
¶n_solvents
¶residue
(self, int idx, bool atom=False)¶if atom is True, get full list of atoms for idx-th residue. This will be very slow if atom is False, get ()
residues
¶save
(self, filename=None, format='AMBERPARM') save to given file format (parm7, psf, ...)¶save to given file format (parm7, psf, ...)
select
(self, mask)¶return atom indices
Notes
support openmp for distance-based atommask selction
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> atm = traj.top.select("@CA")
>>> atm
array([ 4, 15, 39, ..., 159, 173, 197])
>>> pt.rmsd(traj, mask=atm)
array([ 1.94667955e-07, 2.54596866e+00, 4.22333034e+00, ...,
4.97189564e+00, 5.53947712e+00, 4.83201237e+00])
set_nobox
(self)¶set_reference
(self, Frame frame)¶Set reference frame for distance-based mask
Parameters: | frame : Frame
|
---|
set_solvent
(self, mask)¶set mask
as solvent
simplify
(self)¶return a (immutable) lightweight version of Topology for fast iterating. The API is not stable.
No writing capabibility (you should use ParmEd for Topology editing)
Examples
>>> import pytraj as pt
>>> top = pt.load_topology('data/tz2.parm7')
>>> simp_top = top.simplify()
>>> atom = simp_top.atoms[0]
>>> atom.resname
'SER'
>>> res = simp_top.residues[0]
>>> # get all atoms for 1st residue
>>> atoms = simp_top.atoms[res.first:res.last]
start_new_mol
(self)¶strip
(self, mask, copy=False)¶strip atoms with given mask
summary
(self) basic info. This information only appears in Ipython or Python shell. It does not appear in Jupyter notebook (due to C++ stdout)¶basic info. This information only appears in Ipython or Python shell. It does not appear in Jupyter notebook (due to C++ stdout)
to_dict
(self)¶convert Topology to Python dict
to_parmed
(self)¶try to load to ParmEd’s Structure
pytraj.
Trajectory
(filename=None, top=None, xyz=None, velocity=None, force=None)¶Bases: pytraj.trajectory.shared_trajectory.SharedTrajectory
Simple in-memory Trajectory. It has only information about 3D coordinates and unitcells (no time, no velocity, no force, ...)
Parameters: | filename: str, trajectory filename top : Topology xyz: 3D-array
|
---|
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('ala3')
>>> # load from filename and topology name
>>> traj = pt.Trajectory(fn, tn)
>>> # load from a list of filenames
>>> traj = pt.Trajectory([fn, fn], tn)
>>> # load from 3D array-like
>>> xyz = traj.xyz
>>> traj_1 = pt.Trajectory(xyz=xyz, top=traj.top)
>>> # get new Trajectory with only CA atoms
>>> traj['@CA'].xyz[:, :, 0]
array([[ 3.970048 , 7.6400076, 10.1610562]])
>>> # iterate
>>> for frame in traj: pass
Attributes
n_atoms |
|
n_frames |
|
shape |
(n_frames, n_atoms, 3) |
top |
Topology (having info about atom, residue, ...) |
topology |
Topology (having info about atom, residue, ...) |
unitcells |
return 2D ndarray, shape=(n_frames, 6) |
xyz |
Trajectory’s coordinates, shape=(n_frames, n_frames, 3), dtype=’f8’ |
Methods
__call__ (\*args, \*\*kwd) |
shortcut of iterframe method |
align_principal_axis ([command]) |
align principal axis |
append (other) |
other: xyz, Frame, Trajectory, ... |
append_xyz (xyz) |
append 3D numpy array |
autoimage ([command]) |
perform autoimage |
center (\*args, \*\*kwargs) |
do centering |
copy () |
return a deep copy of trajectory |
from_iterable (iterables[, top]) |
create a new Trajectory from iterable (produce Frame) |
iterframe ([start, stop, step, mask, ...]) |
iterate trajectory with given frame_indices or given (start, stop, step) |
load ([filename]) |
load file or files. This is for internal use. User should always use |
rmsfit (\*args, \*\*kwd) |
do the fitting to reference Frame by rotation and translation |
rotate ([command]) |
do rotation |
save ([filename, overwrite]) |
|
scale ([command]) |
do scaling |
strip (mask) |
strip atoms with given mask |
superpose ([mask, ref, ref_mask, ...]) |
do the fitting to reference Frame by rotation and translation |
transform (commands[, frame_indices]) |
apply a series of cpptraj commands to trajectory |
translate ([command]) |
do translation |
view (\*args, \*\*kwargs) |
|
visualize (\*args, \*\*kwargs) |
require NGLView |
align_principal_axis
(command='')¶align principal axis
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('ala3')[:]
>>> traj = traj.align_principal_axis()
append
(other)¶other: xyz, Frame, Trajectory, ...
Notes
Examples
>>> import pytraj as pt
>>> import numpy as np
>>> traj = pt.load_sample_data('tz2')[:]
>>> t0 = pt.Trajectory(top=traj.top)
>>> t0.n_frames
0
>>> f0 = traj[0]
>>> t0.append(f0)
>>> t0.n_frames
1
>>> t0.append(np.array([traj[3].xyz,]))
>>> t0.n_frames
2
>>> t0.append(traj)
>>> t0.n_frames
12
>>> t0.append(traj())
>>> t0.n_frames
22
>>> t1 = pt.Trajectory(top=traj.top)
>>> t1.append(traj)
>>> t2 = pt.Trajectory(top=traj.top)
>>> t2.append(traj.xyz)
append_xyz
(xyz)¶append 3D numpy array
Notes
This method is not well optimized for speed.
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')
>>> t0 = pt.Trajectory(top=traj.top)
>>> t0.append_xyz(traj.xyz)
>>> t0.n_frames
10
>>> t0.append_xyz(traj.xyz)
>>> t0.n_frames
20
autoimage
(command='')¶perform autoimage
Returns: | self |
---|
Examples
>>> import pytraj as pt; from pytraj.testing import get_fn
>>> t0 = pt.load(*get_fn('tz2'))
>>> t0.top.has_box()
True
>>> t0 = t0.autoimage()
center
(*args, **kwargs)¶do centering
Returns: | self |
---|
See also
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('ala3')[:]
>>> traj = traj.center('@CA origin')
copy
()¶return a deep copy of trajectory
Examples
>>> import pytraj as pt
>>> t0 = pt.datafiles.load_rna()[:]
>>> isinstance(t0.copy(), pt.Trajectory)
True
from_iterable
(iterables, top=None)¶create a new Trajectory from iterable (produce Frame)
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')
>>> t0 = pt.Trajectory.from_iterable(traj(3, 8, 2))
>>> from pytraj import pipe
>>> fi = pipe(traj, ['autoimage', 'rms'])
>>> t0 = pt.Trajectory.from_iterable(fi, top=traj.top)
>>> t0.n_frames
10
>>> pt.radgyr(t0)
array([ 18.90953437, 18.93564662, 18.85415458, 18.90994856,
18.85884218, 18.88551081, 18.9364612 , 18.89353463,
18.91772124, 18.87070283])
iterframe
(start=0, stop=None, step=1, mask=None, autoimage=False, frame_indices=None, rmsfit=None)¶iterate trajectory with given frame_indices or given (start, stop, step)
Parameters: | start : int, default 0 stop : {None, int}, default None
step : int, default 1 mask : {None, str}, default None
autoimage : bool, default False
rmsfit : {None, int, tuple}, default None
frame_indices : {None, array-like}
|
---|
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> traj = pt.load(*get_fn('tz2'))
>>> for frame in traj.iterframe(0, 8, 2): pass
>>> for frame in traj.iterframe(0, 8, 2, autoimage=True): pass
>>> # use negative index
>>> traj.n_frames
10
>>> fi = traj.iterframe(0, -1, 2, autoimage=True)
>>> fi.n_frames
5
>>> # mask is atom indices
>>> fi = traj.iterframe(0, -1, 2, mask=range(100), autoimage=True)
>>> fi.n_atoms
100
load
(filename='')¶load file or files. This is for internal use. User should always use
pytraj.load
(or iterload
) method
Notes
It’s better to use pytraj.load
method
>>> traj = pt.load(fname, tname)
>>> traj.n_atoms
5293
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> fname, tname = get_fn('tz2')
>>> traj = pt.Trajectory()
>>> traj.top = pt.load_topology(tname)
>>> traj.load(fname)
>>> traj.n_atoms
5293
>>> # from list/tuple
>>> traj.load([fname, fname])
>>> traj.load((fname, fname))
n_atoms
¶n_frames
¶rmsfit
(*args, **kwd)¶do the fitting to reference Frame by rotation and translation
Parameters: | ref : {Frame, int}, default=None (first Frame)
mask : str or AtomMask object, default=’*’ (fit all atoms) |
---|---|
Returns: | self |
Notes
this is alias of superpose
Examples
>>> traj.rmsfit(0) # fit to 1st frame
>>> traj.rmsfit(-1, '@CA') # fit to last frame using @CA atoms
rotate
(command='')¶do rotation
Returns: | self |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('ala3')[:]
>>> traj = traj.rotate('@CA x 20')
save
(filename='', overwrite=False, **kwd)¶scale
(command='')¶do scaling
Returns: | self |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('ala3')[:]
>>> traj = traj.scale('@CA x 1.2')
shape
¶(n_frames, n_atoms, 3)
strip
(mask)¶strip atoms with given mask
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data()[:]
>>> traj.n_atoms
34
>>> t0 = traj.strip('!@CA') # keep only CA atoms
>>> isinstance(t0, pt.Trajectory)
True
>>> t0.n_atoms
3
superpose
(mask='*', ref=None, ref_mask='', frame_indices=None, mass=False)¶do the fitting to reference Frame by rotation and translation
Parameters: | mask : str or AtomMask object, default=’*’ (fit all atoms) ref : {Frame object, int, str}, default=None
ref_mask : str, default ‘’
mass : bool, default False
frame_indices : array-like, default None, optional
|
---|---|
Returns: | self |
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> traj = pt.load(*get_fn('tz2'))
>>> traj = traj.superpose() # fit to 1st frame
>>> traj = traj.superpose(ref=0) # fit to 1st frame, explitly specify
>>> traj = traj.superpose(ref=-1, mask='@CA') # fit to last frame using @CA atoms
top
¶Topology (having info about atom, residue, ...)
See also
topology
¶Topology (having info about atom, residue, ...)
See also
transform
(commands, frame_indices=None)¶apply a series of cpptraj commands to trajectory
Returns: | self |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()[:]
>>> traj.xyz[0, 0]
array([ 15.55458927, 28.54844856, 17.18908691])
>>> traj = traj.transform(['autoimage', 'center @CA origin', 'translate x 1.2'])
>>> traj.xyz[0, 0]
array([-1.19438073, 8.75046229, -1.82742397])
>>> # which is similiar to below:
>>> traj2 = pt.datafiles.load_tz2_ortho()[:]
>>> traj2.xyz[0, 0] # before transforming
array([ 15.55458927, 28.54844856, 17.18908691])
>>> traj = traj2.autoimage().center('@CA origin').translate('x 1.2')
>>> traj2.xyz[0, 0] # after transforming
array([-1.19438073, 8.75046229, -1.82742397])
translate
(command='')¶do translation
Returns: | self |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('ala3')[:]
>>> traj = traj.translate('@CA x 1.2')
unitcells
¶return 2D ndarray, shape=(n_frames, 6)
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')[:]
>>> traj.unitcells[0]
array([ 35.26277966, 41.84554768, 36.16862953, 90. ,
90. , 90. ])
view
(*args, **kwargs)¶visualize
(*args, **kwargs)¶require NGLView
Parameters: | args and kwargs : NGLView’s arguments |
---|
xyz
¶Trajectory’s coordinates, shape=(n_frames, n_frames, 3), dtype=’f8’
Examples
>>> import pytraj as pt
>>> traj0 = pt.datafiles.load_ala3()
>>> traj1 = pt.Trajectory(xyz=np.empty((traj0.n_frames, traj0.n_atoms, 3), dtype='f8'), top=traj0.top)
>>> traj1.xyz = traj0.xyz.copy()
>>> # autoconvert from fortran order to c order
>>> xyz = np.asfortranarray(traj0.xyz)
>>> traj1.xyz = xyz
pytraj.
TrajectoryIterator
(filename=None, top=None, *args, **kwd)¶Bases: pytraj.trajectory.c_traj.c_trajectory.TrajectoryCpptraj
, pytraj.trajectory.shared_trajectory.SharedTrajectory
out-of-core trajectory holder.
Notes
It’s a bit tricky to pickle this class. As default, new TrajectoryIterator will use original trj filename and top filename.
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> traj_name, top_name = get_fn('tz2')
>>> traj = pt.TrajectoryIterator(traj_name, top_name)
>>> # user should always use :method:`pytraj.iterload` to load TrajectoryIterator
>>> traj = pt.iterload(['remd.x.000', 'remd.x.001'], 'input.parm7')
Attributes
filelist |
return a list of input filenames. Order does matter |
filename |
return 1st filename in filelist. For testing only |
metadata |
return a dict of general information |
n_atoms |
used for frame_iter |
n_frames |
total snapshots |
shape |
(n_frames, n_atoms, 3) |
temperatures |
return 1D array of temperatures |
top |
Topology |
topology |
alias of traj.top |
unitcells |
return unitcells (Box) with shape=(n_frames, 6) |
xyz |
return 3D array of coordinates |
Methods
__call__ |
Call self as a function. |
at (index) |
same as traj[index] |
autoimage (self[, command]) |
|
center (self[, command]) |
|
copy () |
return a deep copy. Use this method with care since the copied traj just reuse |
image (self[, command]) |
|
iterchunk ([chunksize, start, stop, ...]) |
iterate trajectory by chunk |
iterframe ([start, stop, step, mask, ...]) |
iterate trajectory with given frame_indices or given (start, stop, step) |
principal (self, command) |
|
rotate (self, command) |
|
save ([filename, overwrite]) |
|
scale (self, command) |
|
strip (mask) |
|
superpose ([mask, ref, ref_mask, mass]) |
register to superpose to reference frame when iterating. |
translate (self, command) |
|
view (\*args, \*\*kwargs) |
|
visualize (\*args, \*\*kwargs) |
require NGLView |
at
(index)¶same as traj[index]
autoimage
(self, command='')¶center
(self, command='')¶copy
()¶return a deep copy. Use this method with care since the copied traj just reuse the filenames
filelist
¶return a list of input filenames. Order does matter
filename
¶return 1st filename in filelist. For testing only
image
(self, command='')¶iterchunk
(chunksize=2, start=0, stop=-1, autoimage=False, rmsfit=None)¶iterate trajectory by chunk
Parameters: | chunk : int, default=2
start : int, default=0 (first frame) stop : int, default=-1 (last frame) autoimage : bool, default=False rmsfit : None | tuple/list of (reference frame, mask) |
---|
Notes
if using ‘autoimage` with reference frame for rms-fit, make sure to autoimage ref first
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')
>>> ref = traj[3]
>>> for chunk in traj.iterchunk(3, autoimage=True, rmsfit=(ref, '@CA')): pass
iterframe
(start=0, stop=None, step=1, mask=None, autoimage=False, rmsfit=None, copy=False, frame_indices=None)¶iterate trajectory with given frame_indices or given (start, stop, step)
Parameters: | start : int, default 0 stop : {None, int}, default None
step : int, default 1 mask : {None, str}, default None
autoimage : bool, default False
rmsfit : {None, int, tuple}, default None
frame_indices : {None, array-like}
|
---|
Examples
>>> import pytraj as pt
>>> traj = pt.load_sample_data('tz2')
>>> for frame in traj.iterframe(0, 8, 2): pass
>>> for frame in traj.iterframe(0, 8, 2, autoimage=True): pass
>>> # use negative index
>>> traj.n_frames
10
>>> fi = traj.iterframe(0, -1, 2, autoimage=True)
>>> fi.n_frames
5
>>> # mask is atom indices
>>> fi = traj.iterframe(0, -1, 2, mask=range(100), autoimage=True)
>>> fi.n_atoms
100
metadata
¶return a dict of general information
Examples
>>> traj.metadata
{'box_type': 'ortho',
'has_box': True,
'has_force': False,
'has_replcica_dims': False,
'has_temperature': False,
'has_time': True,
'has_velocity': False,
'n_atoms': 5293,
'n_frames': 10}
n_atoms
¶used for frame_iter
n_frames
¶total snapshots
principal
(self, command)¶rotate
(self, command)¶save
(filename='', overwrite=False, **kwd)¶scale
(self, command)¶shape
¶(n_frames, n_atoms, 3)
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> traj.shape
(10, 5293, 3)
strip
(mask)¶superpose
(mask='*', ref=None, ref_mask='', mass=False)¶register to superpose to reference frame when iterating. To turn off superposing, set traj._being_transformed = False
Notes
This method is different from superpose
in pytraj.Trajectory.
It does not change the coordinates of TrajectoryCpptraj/TrajectoryIterator itself but
changing the coordinates of copied Frame.
This method is mainly for NGLView in Jupyter notebook, to view out-of-core data. It’s good to do translation and rotation on the fly.
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> isinstance(traj, pt.TrajectoryIterator)
True
>>> traj[0].xyz[0]
array([-1.88900006, 9.1590004 , 7.56899977])
>>> # turn on superpose
>>> _ = traj.superpose(ref=-1, mask='@CA')
>>> traj[0].xyz[0]
array([ 6.97324167, 8.82901548, 1.31844696])
>>> # turn off superpose
>>> traj._being_transformed = False
>>> traj[0].xyz[0]
array([-1.88900006, 9.1590004 , 7.56899977])
Examples for NGLView:
import pytraj as pt, nglview as nv
traj = pt.datafiles.load_tz2()
traj.superpose(ref=0, mask='@CA')
view = nv.show_pytraj(traj)
view
temperatures
¶return 1D array of temperatures
top
¶Topology
topology
¶alias of traj.top
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> fname, tname = get_fn('ala3')
>>> traj = pt.iterload(fname, tname)
>>> traj.topology
<Topology: 34 atoms, 3 residues, 1 mols, non-PBC>
>>> new_traj = pt.TrajectoryIterator()
>>> new_traj.topology = traj.topology
>>> new_traj._load(traj.filename)
translate
(self, command)¶unitcells
¶return unitcells (Box) with shape=(n_frames, 6)
view
(*args, **kwargs)¶visualize
(*args, **kwargs)¶require NGLView
Parameters: | args and kwargs : NGLView’s arguments |
---|
xyz
¶return 3D array of coordinates
pytraj.
TrajectoryWriter
¶Bases: object
Methods
close (self) |
|||
get_formats (type cls) |
|||
help (type cls) |
|||
open (self[, filename, top, crdinfo, format, ...]) |
filename : str, output filename | ||
write (self, Frame frame) |
|
close
(self)¶get_formats
(type cls)¶help
(type cls)¶open
(self, filename='', top=<???>, crdinfo=<???>, format='infer', options='', overwrite=False)¶filename : str, output filename top : Topology format : str, default ‘infer’
if ‘infer’, determine file format based on extension. If can not detect extension, use AMBER mdcrd format
options : str, additional keywords for writing file (good for pdb, mol2, ...) overwrite : bool, default False
write
(self, Frame frame)¶Parameters: | frame : Frame instance *args, **kwd: just dummy |
---|
pytraj.
acorr
(data, dtype='ndarray', option='')¶compute autocorrelation
Parameters: | data : 1d array-like dtype: return type, default ‘ndarray’ covar : bool, default True option : str
|
---|
Notes
Same as autocorr in cpptraj
pytraj.
align_principal_axis
(traj=None, mask='*', top=None, frame_indices=None, mass=False)¶Notes
apply for mutatble traj (Trajectory, Frame)
pytraj.
analyze_modes
(mode_type, eigenvectors, eigenvalues, scalar_type='mwcovar', options='', dtype='dict')¶pytraj.
atom_map
(traj, ref, rmsfit=False)¶Limited support for cpptraj atommap
Parameters: | traj : Trajectory-like ref : Trajectory-like with one frame rmsfit : bool, default False
|
---|---|
Returns: | out : Tuple[str, np.ndarray]
|
Notes
This method in pytraj is not mature yet.
pytraj.
atomiccorr
(traj, mask='', cut=None, min_spacing=None, byres=True, frame_indices=None, dtype='ndarray', top=None)¶compute average correlations between the motion of atoms in mask.
Parameters: | traj : Trajectory-like mask : atom mask cut : {None, float}, default None
min_spacing : {None, float}, default None
byres : bool, default False
|
---|
pytraj.
autoimage
(traj, mask='', frame_indices=None, top=None)¶perform autoimage and return the updated-coordinate traj
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()[:]
>>> traj = pt.autoimage(traj)
pytraj.
calc_alpha
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_beta
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_chin
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_chip
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_delta
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_epsilon
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_gamma
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_multidihedral
(traj=None, dihedral_types=None, resrange=None, define_new_type=None, range360=False, dtype='dataset', top=None, frame_indices=None)¶perform dihedral search
Parameters: | traj : Trajectory-like object dihedral_types : dihedral type, default None
resrange : str | array-like
define_new_type : str
range360 : bool, default False
top : Topology | str, optional
|
---|---|
Returns: | pytraj.DatasetList (use values attribute to get raw numpy array) |
Notes
Dataset lables show residue number in 1-based index
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.multidihedral(traj)
>>> data = pt.multidihedral(traj, 'phi psi')
>>> data = pt.multidihedral(traj, resrange=range(8))
>>> data = pt.multidihedral(traj, range360=True)
>>> data = pt.multidihedral(traj, resrange='1,3,5')
>>> data = pt.multidihedral(traj, dihedral_types='phi psi')
>>> data = pt.multidihedral(traj, dihedral_types='phi psi', resrange='3-7')
>>> data = pt.multidihedral(traj, dihedral_types='phi psi', resrange=[3, 4, 8])
pytraj.
calc_nu1
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_nu2
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_omega
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_phi
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_psi
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
calc_zeta
(traj=None, resrange='', range360=False, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like or anything that makes iterframe_master(traj) return Frame resrange : string or iterable, cpptraj resrange, default “”
range360 : bool, default False
top : {str, Topology}, optional, default None frame_indices : {None, 1D array-like}, default None
|
---|
Examples
>>> import pytraj.dihedral_ as da
>>> da.calc_phi(traj)
>>> da.calc_psi(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10")
>>> da.calc_chip(traj, resrange="3-10", range360=True)
>>> da.calc_chip(traj, resrange="3-10", dtype='dict')
>>> da.calc_multidihedral(traj, resrange="3-10")
>>> da.calc_multidihedral(traj, resrange=range(5, 10))
>>> # assert
>>> from pytraj import all_actions as pyca
>>> phi0 = pyca.calc_multidihedral(traj, "phi", dtype='dataset')
>>> phi1 = da.calc_phi(traj, dtype='dataset')
>>> from pytraj.testing import aa_eq
>>> for key in phi0.keys():
>>> aa_eq(phi0[key], phi1[key])
pytraj.
center
(traj=None, mask='', center='box', mass=False, top=None, frame_indices=None)¶Center coordinates in mask to specified point.
Parameters: | traj : Trajectory-like or Frame iterator mask : str, mask center : str, {‘box’, ‘origin’, array-like}, default ‘box’
mass : bool, default: False
top : Topology, optional, default: None |
---|---|
Returns: | updated traj |
See also
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # load all frames to memory so we can 'mutate' them
>>> traj = traj[:]
>>> # all atoms, center to box center (x/2, y/2, z/2)
>>> traj = pt.center(traj)
>>> # center at origin, use @CA
>>> traj = pt.center(traj, '@CA', center='origin')
>>> # center to box center, use mass weighted
>>> traj = pt.center(traj, mass=True)
>>> traj = pt.center(traj, ':1', mass=True)
pytraj.
check_structure
(traj, mask='', options='', frame_indices=None, top=None, dtype='ndarray')¶check if the structure is ok or not
Parameters: | traj : Trajectory-like mask: str, default all atoms options : str, default ‘’
dtype : str, default ‘ndarray’ |
---|---|
Returns: | out : Tuple[np.ndarray, str]
|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_rna()
>>> failures = pt.check_structure(traj[:1])
pytraj.
closest
(traj=None, mask='*', solvent_mask=None, n_solvents=10, frame_indices=None, dtype='iterator', top=None)¶return either a new Trajectory or a frame iterator. Keep only n_solvents
closest to mask
Parameters: | traj : Trajectory-like | list of Trajectory-like/frames | frame iterator | chunk iterator mask: str, default ‘*’ (all solute atoms) top : Topology-like object, default=None, optional dtype : {‘iterator’, ‘trajectory’}, default ‘iterator’
|
---|---|
Returns: | out : (check above) |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # obtain new traj, keeping only closest 100 waters
>>> # to residues 1 to 13 (index starts from 1) by distance to the first atom of water
>>> t = pt.closest(traj, mask='@CA', n_solvents=10)
pytraj.
density
(traj, mask='*', density_type='number', delta=0.25, direction='z', dtype='dict')¶Compute density (number, mass, charge, electron) along a coordinate
Parameters: | traj : Trajectory-like mask : str or list of str, default ‘*’
density_type : str, {‘number’, ‘mass’, ‘charge’, ‘electron’}, default ‘number’ delta : float, default 0.25
direction : str, default ‘z’ dtype : str, default ‘dict’
|
---|---|
Returns: | out : dict of average density and std for each frame |
Notes
Syntax might be changed
Examples
>>> def func():
... import pytraj as pt
... fn = "data/DOPC.rst7"
... tn = "data/DOPC.parm7"
... traj = pt.load("data/DOPC.rst7", "data/DOPC.parm7")
... delta = ‘0.25’ ... density_type = ‘charge’ ... masks = [”:PC@P31”, ”:PC@N31”, ”:PC@C2”, ”:PC | :OL | :OL2”] ... density_dict = pt.density(traj, mask=masks, density_type=density_type, delta=delta) ... return density_dict >>> density_dict = func() # doctest: +SKIP
pytraj.
dispatch
(type cls, CpptrajState state, line)¶pytraj.
distance_rmsd
(traj=None, mask='', ref=0, top=None, dtype='ndarray', frame_indices=None)¶compute distance rmsd between traj and reference
Parameters: | traj : Trajectory-like or iterator that produces Frame ref : {int, Frame}, default 0 (1st Frame) mask : str top : Topology or str, optional, default None dtype : return dtype, default ‘ndarray’ |
---|---|
Returns: | 1D ndarray if dtype is ‘ndarray’ (default) |
Examples
>>> import pytraj as pt
>>> # compute distance_rmsd to last frame
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.distance_rmsd(traj, ref=-1)
>>> # compute distance_rmsd to first frame with mask = '@CA'
>>> data = pt.distance_rmsd(traj, ref=0, mask='@CA')
pytraj.
esander
(traj=None, prmtop=None, igb=8, mm_options=None, qm_options=None, dtype='dict', frame_indices=None, top=None)¶energy decomposition by calling libsander
Parameters: | traj : Trajectory-like or iterables that produce Frame
prmtop : str or Structure from ParmEd, default=None, optional
igb : GB model, default=8 (GB-Neck2)
mm_options : InputOptions from sander, default=None, optional
qm_options : InputOptions from sander for QMMM, optional top : pytraj.Topology or str, default=None, optional
dtype : str, {‘dict’, ‘dataset’, ‘ndarray’, ‘dataframe’}, default=’dict’
frame_indices : None or 1D array-like, default None
|
---|---|
Returns: | Dict of energies (to be used with DataFrame) or DatasetList |
Notes
This method does not work with pytraj.pmap when you specify mm_options and qm_options. Use pytraj.pmap_mpi with MPI instead.
Work with pytraj.pmap
:
pt.pmap(pt.esander, traj, igb=8, dtype='dict')
Will NOT work with pytraj.pmap
:
import sander
inp = sander.gas_input(8)
pt.pmap(pt.esander, traj, mm_options=inp, dtype='dict')
Why? Because Python need to pickle each object to send to different cores and Python does not know how to pickle mm_options from sander.gas_input(8).
This works with pytraj.pmap_mpi
because pytraj explicitly create mm_options
in each core without pickling.
Examples
Examples are adapted from $AMBERHOME/test/sanderapi
>>> import pytraj as pt
>>> # GB energy
>>> traj = pt.datafiles.load_ala3()
>>> traj.n_frames
1
>>> data = pt.esander(traj, igb=8)
>>> data['gb']
array([-92.88577683])
>>> data['bond']
array([ 5.59350521])
>>> # PME
>>> import os
>>> from pytraj.testing import amberhome
>>> import sander
>>> topfile = os.path.join(amberhome, "test/4096wat/prmtop")
>>> rstfile = os.path.join(amberhome, "test/4096wat/eq1.x")
>>> traj = pt.iterload(rstfile, topfile)
>>> options = sander.pme_input()
>>> options.cut = 8.0
>>> edict = pt.esander(traj=traj, mm_options=options)
>>> edict['vdw']
array([ 6028.95167558])
>>> # GB + QMMM
>>> topfile = os.path.join(amberhome, "test/qmmm2/lysine_PM3_qmgb2/prmtop")
>>> rstfile = os.path.join(amberhome, "test/qmmm2/lysine_PM3_qmgb2/lysine.crd")
>>> traj = pt.iterload(rstfile, topfile)
>>> options = sander.gas_input(8)
>>> options.cut = 99.0
>>> options.ifqnt = 1
>>> qm_options = sander.qm_input()
>>> qm_options.iqmatoms[:3] = [8, 9, 10]
>>> qm_options.qm_theory = "PM3"
>>> qm_options.qmcharge = 0
>>> qm_options.qmgb = 2
>>> qm_options.adjust_q = 0
>>> edict = pt.esander(traj=traj, mm_options=options, qm_options=qm_options)
>>> edict['bond']
array([ 0.00160733])
>>> edict['scf']
array([-11.92177575])
>>> # passing options to `pytraj.pmap`: need to pass string
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2')
>>> traj = pt.iterload(fn, tn)
>>> inp_str = 'mm_options = sander.pme_input()'
>>> edict = pt.pmap(pt.esander, traj, mm_options=inp_str, n_cores=2)
>>> edict['dihedral']
array([ 126.39307126, 127.0460586 , 137.26793522, 125.30521069,
125.25110884, 137.69287326, 125.78280543, 125.14530517,
118.41540102, 128.73535036])
pytraj.
esander
(traj=None, prmtop=None, igb=8, mm_options=None, qm_options=None, dtype='dict', frame_indices=None, top=None)energy decomposition by calling libsander
Parameters: | traj : Trajectory-like or iterables that produce Frame
prmtop : str or Structure from ParmEd, default=None, optional
igb : GB model, default=8 (GB-Neck2)
mm_options : InputOptions from sander, default=None, optional
qm_options : InputOptions from sander for QMMM, optional top : pytraj.Topology or str, default=None, optional
dtype : str, {‘dict’, ‘dataset’, ‘ndarray’, ‘dataframe’}, default=’dict’
frame_indices : None or 1D array-like, default None
|
---|---|
Returns: | Dict of energies (to be used with DataFrame) or DatasetList |
Notes
This method does not work with pytraj.pmap when you specify mm_options and qm_options. Use pytraj.pmap_mpi with MPI instead.
Work with pytraj.pmap
:
pt.pmap(pt.esander, traj, igb=8, dtype='dict')
Will NOT work with pytraj.pmap
:
import sander
inp = sander.gas_input(8)
pt.pmap(pt.esander, traj, mm_options=inp, dtype='dict')
Why? Because Python need to pickle each object to send to different cores and Python does not know how to pickle mm_options from sander.gas_input(8).
This works with pytraj.pmap_mpi
because pytraj explicitly create mm_options
in each core without pickling.
Examples
Examples are adapted from $AMBERHOME/test/sanderapi
>>> import pytraj as pt
>>> # GB energy
>>> traj = pt.datafiles.load_ala3()
>>> traj.n_frames
1
>>> data = pt.esander(traj, igb=8)
>>> data['gb']
array([-92.88577683])
>>> data['bond']
array([ 5.59350521])
>>> # PME
>>> import os
>>> from pytraj.testing import amberhome
>>> import sander
>>> topfile = os.path.join(amberhome, "test/4096wat/prmtop")
>>> rstfile = os.path.join(amberhome, "test/4096wat/eq1.x")
>>> traj = pt.iterload(rstfile, topfile)
>>> options = sander.pme_input()
>>> options.cut = 8.0
>>> edict = pt.esander(traj=traj, mm_options=options)
>>> edict['vdw']
array([ 6028.95167558])
>>> # GB + QMMM
>>> topfile = os.path.join(amberhome, "test/qmmm2/lysine_PM3_qmgb2/prmtop")
>>> rstfile = os.path.join(amberhome, "test/qmmm2/lysine_PM3_qmgb2/lysine.crd")
>>> traj = pt.iterload(rstfile, topfile)
>>> options = sander.gas_input(8)
>>> options.cut = 99.0
>>> options.ifqnt = 1
>>> qm_options = sander.qm_input()
>>> qm_options.iqmatoms[:3] = [8, 9, 10]
>>> qm_options.qm_theory = "PM3"
>>> qm_options.qmcharge = 0
>>> qm_options.qmgb = 2
>>> qm_options.adjust_q = 0
>>> edict = pt.esander(traj=traj, mm_options=options, qm_options=qm_options)
>>> edict['bond']
array([ 0.00160733])
>>> edict['scf']
array([-11.92177575])
>>> # passing options to `pytraj.pmap`: need to pass string
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2')
>>> traj = pt.iterload(fn, tn)
>>> inp_str = 'mm_options = sander.pme_input()'
>>> edict = pt.pmap(pt.esander, traj, mm_options=inp_str, n_cores=2)
>>> edict['dihedral']
array([ 126.39307126, 127.0460586 , 137.26793522, 125.30521069,
125.25110884, 137.69287326, 125.78280543, 125.14530517,
118.41540102, 128.73535036])
pytraj.
get_average_frame
(traj, mask='', frame_indices=None, dtype='frame', autoimage=False, rmsfit=None, top=None)¶get mean structure for a given mask and given frame_indices
Parameters: | traj : Trajectory-like or iterable that produces Frame mask : None or str, default None (all atoms) frame_indices : iterable that produces integer, default None, optional
dtype: str, {‘frame’, ‘traj’}, default ‘frame’
autoimage : bool, default False
rmsfit : object, {Frame, int, tuple, None}, default None
|
---|
Notes
if autoimage=True and having rmsfit, perform autoimage first and do rmsfit
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # get average structure from whole traj, all atoms
>>> frame = pt.mean_structure(traj)
>>> # get average structure from several frames, '@CA' atoms"
>>> frame = pt.mean_structure(traj, '@CA', frame_indices=range(2, 8, 2))
>>> # get average structure but do autoimage and rmsfit to 1st Frame
>>> frame = pt.mean_structure(traj(autoimage=True, rmsfit=0))
>>> # get average structure but do autoimage and rmsfit to 1st Frame.
>>> frame = pt.mean_structure(traj(autoimage=True, rmsfit=0, frame_indices=[0, 5, 6]))
pytraj.
get_velocity
(traj, mask=None, frame_indices=None)¶get velocity for specify frames with given mask
Parameters: | traj : Trajectory-like or iterable that produces Frame mask : str, default None (use all atoms), optional
frame_indices : iterable that produces integer, default None, optional
|
---|---|
Returns: | out : 3D numpy array, shape (n_frames, n_atoms, 3) |
Notes
Since pytraj has limited support for force and velocity info, if user wants to load both from disk, should iterate the TrajectoryIterator (got by pytraj.iterload method)
import pytraj as pt
forces = []
velocities = []
traj = pt.iterload(filename, topology_filename)
for frame in traj:
forces.append(frame.force)
velocities.append(frame.velocity)
# Note: pytraj can efficiently load arbitary frame indices to memory
for frame in pt.iterframe(traj, frame_indices=[0, 8, 8, 100, 1000]): pass
Examples
>>> vels = pt.get_velocity(traj, frame_indices=[0, 3])
pytraj.
gist
(traj, grid_center=[0.0, 0.0, 0], grid_dim=[40, 40, 40], grid_spacing=0.5, do_order=False, do_eij=False, reference_density=0.0334, temperature=300.0, options='', dtype='dict')¶minimal support for gist command in cpptraj
Parameters: | traj : Trajectory-like grid_center : 1-D array-like or str, default [0., 0., 0.] (origin)
grid_dim: 1-D array-like or str, default [40, 40, 40]
grid_spacing: float, default 0.5 do_order : bool, default False do_eij : bool, default False reference_density : float, default 0.0334
options : str
temperature : float, default 300. dtype : str, default ‘dict’
|
---|---|
Returns: | out : dict (or another data type based on dtype)
|
Notes
Syntax might be changed. There is a bug in pytraj that causes segmentation fault sometimes.
pytraj.
image
(traj, mask='', frame_indices=None, top=None)¶perform imaging and return the updated-coordinate traj
Notes
User should always try to use autoimage first
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()[:]
>>> traj = pt.image(traj, 'origin center :WAT')
pytraj.
ired_vector_and_matrix
(traj=None, mask='', frame_indices=None, order=2, dtype='tuple', top=None)¶perform vector calculation and then calculate ired matrix
Parameters: | traj : Trajectory-like or iterable that produces mask : str or a list of strings frame_indices : array-like, optional, default None
order : default 2 dtype : output’s dtype, {‘dataset’, ‘tuple’} default ‘dataset’ top : Topology, optional, default None |
---|---|
Returns: | out : if dtype is ‘dataset’, return pytraj.DatasetList with shape=(n_vectors+1,)
|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> h = pt.select('@H', traj.top)
>>> n = h - 1
>>> nh = list(zip(n, h))
>>> vecs, mat = pt.ired_vector_and_matrix(traj, mask=nh)
>>> dslist = pt.ired_vector_and_matrix(traj, mask=nh, dtype='dataset')
pytraj.
iterchunk
(traj, *args, **kwd)¶iterate traj
by chunk
Parameters: | traj : TrajectoryIterator chunksize : int
start : int, default 0
start : int, default -1 (last frame)
autoimage : bool, default False
|
---|
See also
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> for frame in pt.iterchunk(traj, 4): pass
>>> for frame in pt.iterchunk(traj, chunksize=4, start=2): pass
>>> for frame in pt.iterchunk(traj, chunksize=4, start=2, stop=9): pass
>>> for frame in pt.iterchunk(traj, chunksize=4, autoimage=True): pass
pytraj.
iterframe
(traj, *args, **kwd)¶create frame iterator with given indices, mask or some iter_options
See also
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> for frame in pt.iterframe(traj, 0, 8, 2): pass
>>> for frame in pt.iterframe(traj, 4, mask='@CA'): print(frame)
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
# create frame iterator for given indices >>> for frame in pt.iterframe(traj, frame_indices=[0, 7, 3]): print(frame) <Frame with 5293 atoms> <Frame with 5293 atoms> <Frame with 5293 atoms>
>>> fi = pt.iterframe(traj)
>>> # iterframe its self
>>> fi = pt.iterframe(fi)
pytraj.
iterload
(*args, **kwd)¶return TrajectoryIterator object
Parameters: | filename: {str, list-like of filenames, pattern}
top : {str, Topology}
frame_slice: tuple or list of tuple
stride : {None, int}, default None
|
---|---|
Returns: | pytraj.TrajectoryIterator |
Notes
Unlike pytraj.load, you can not arbitarily set frame_indices. If you want to do so, first load trajectories to TrajectoryIterator object, then do fancy slicing
>>> import pytraj as pt
>>> # register to load traj.nc from 0-th to 99-th frame
>>> traj = pt.iterload('traj.nc', 'prmtop', frame_slice=(0, 100)])
>>> # do fancy indexing to load specific frames to memory
>>> traj[[0, 8, 3, 50, 7]]
>>> # load to disk with given mask
>>> traj[[0, 8, 3, 50, 7], '!@H=']
Examples
>>> import pytraj as pt
>>> traj = pt.iterload('traj.nc', '2koc.parm7')
>>> # load from a list of filenames
>>> traj = pt.iterload(['traj0.nc', 'traj1.nc'], '2koc.parm7')
>>> # load all files with a given pattern (sorted)
>>> traj = pt.iterload('./traj*.nc', '2koc.parm7')
>>> # load from a list of files with given frame step
>>> # for each file, only register to load from frame 0 to 9 (skip 10), skip every 2 frames
>>> traj = pt.iterload(['traj0.nc', 'traj1.nc'], '2koc.parm7', frame_slice=[(0, 10, 2),]*2)
>>> # load from frame 0 to 9 for `traj0.nc`
>>> # load all frames from `traj1.nc`
>>> traj = pt.iterload(['traj0.nc', 'traj1.nc'], '2koc.parm7', frame_slice=[(0, 10), (0, -1)])
>>> # use stride, skip every 2 frames
>>> from pytraj.testing import get_remd_fn
>>> filenames, topology_filename = get_remd_fn('remd_ala2')
>>> [fn.split('/')[-1] for fn in filenames]
['rem.nc.000', 'rem.nc.001', 'rem.nc.002', 'rem.nc.003']
>>> traj = pt.iterload(filenames, topology_filename, stride=2)
pytraj.
iterload_remd
(filename, top=None, T='300.0')¶Load temperature remd trajectory for single temperature. e.g: Suppose you have replica trajectoris remd.x.00{1-4}. You want to load and extract only frames at 300 K, use this method
Parameters: | filename : str top : {str, Topology} T : {float, str}, default=300.0 |
---|---|
Returns: | pytraj.traj.TrajectoryCpptraj |
pytraj.
jcoupling
(traj=None, mask='', top=None, kfile=None, dtype='dataset', frame_indices=None)¶compute j-coupling
Parameters: | traj : any things that make frame_iter_master returning Frame object command : str, default “”
kfile : str, default None, optional
dtype : str, {‘dataset’, ...}, default ‘dataset’ |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> data = pt.calc_jcoupling(traj, ':1-12', kfile='data/Karplus.txt')
pytraj.
lie
(traj, mask, options='', dtype='dict', frame_indices=None, top=None)¶LIE
pytraj.
load
(filename, top=None, frame_indices=None, mask=None, stride=None)¶try loading and returning appropriate values. See example below.
Parameters: | filename : str, Trajectory filename top : Topology filename or a Topology frame_indices : {None, array_like}, default None
stride : {None, int}, default None
mask : {str, None}, default None
|
---|---|
Returns: | pytraj.Trajectory |
See also
Notes
pytraj.iterload
)Examples
>>> import pytraj as pt
>>> # load netcdf file with given amber parm file
>>> traj = pt.load('traj.nc', '2koc.parm7')
>>> # load mol2 file
>>> traj = pt.load('traj.mol2') #
>>> # load pdb file
>>> traj = pt.load('traj.pdb')
>>> # load given frame numbers
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2_dry')
>>> traj = pt.load(fn, top=tn, frame_indices=[0, 3, 5, 12, 20])
>>> traj = pt.load(fn, top=tn, frame_indices=[0, 3, 5, 12, 20], mask='!@H=')
>>> # load with frame slice
>>> traj = pt.load(fn, tn, frame_indices=slice(0, 10, 2))
>>> # which is equal to:
>>> traj = pt.load(fn, tn, frame_indices=range(0, 10, 2))
>>> # load with stride
>>> traj = pt.load(fn, tn)
>>> traj.n_frames
101
>>> traj = pt.load(fn, tn, stride=5)
>>> traj.n_frames
21
>>> # load with stride for more than one filename
>>> traj = pt.load([fn, fn], tn, stride=5)
>>> traj.n_frames
42
>>> traj.n_atoms
223
>>> # load with stride for more than one filename, and with mask
>>> traj = pt.load([fn, fn], tn, stride=5, mask='@CA')
>>> traj.n_frames
42
>>> traj.n_atoms
12
pytraj.
load_antechamber
(filename, format=None, options='')¶create pytraj.Trajectory by using antechamber to convert filename to mol2 format, then using pytraj.load
Good for file formats that cpptraj and ParmEd do not support (.ac, ...)
Parameters: | filename : str format : str or None, default None
options : str, additional antechamber command |
---|
pytraj.
load_cpptraj_file
(filename)¶Parameters: | fname : str, name of cpptraj input file
|
---|
pytraj.
load_leap
(command, verbose=False)¶create pytraj.Trajectory from tleap’s command.
Notes
If you load pdb file, make sure to use absolute dir. This method is not extensively tested. Use it with your own risk.
pytraj.
load_parmed
(parm, traj=True, **kwd)¶return pytraj’s Topology or Trajectory objects
Parameters: | parm : ParmEd’s Structure object traj: bool, default True
>>> import parmed as pmd >>> import pytraj as pt >>> p = pmd.download_PDB(“1l2y”) >>> traj = pt.load_parmed(p) |
---|
pytraj.
load_pdb_rcsb
(pdbid)¶load pdb file from rcsb website
Parameters: | pdbid : str |
---|
Examples
io.loadpdb_rcsb(“2KOC”) # popular RNA hairpin
pytraj.
load_remd
(filename, top=None, T='300.0')¶pytraj.
load_sample_data
(data_name=None)¶Return TrajectoryIterator instance for Ala3 or tz2 data
Parameters: | data_name : str, {‘ala3’, ‘tz2’, ‘rna’, ‘trpcage’}, default ‘ala3’ |
---|
Notes
pytraj.
load_topology
(filename, option='')¶load Topology from a filename or from url or from ParmEd object. Adapted from cpptraj doc.
Parameters: | filename : str, Amber prmtop, pdb, mol2, psf, cif, gromacs topology, sdf, tinker formats option : cpptraj options.
|
---|
Notes
if cpptraj/pytraj does not support specific file format, you still can convert to PDB file. cpptraj will do the bond guess based on distance.
Examples
>>> import pytraj as pt
>>> # from a filename
>>> pt.load_topology("data/tz2.ortho.parm7")
<Topology: 5293 atoms, 1704 residues, 1692 mols, PBC with box type = ortho>
>>> # read with option
>>> pt.load_topology('1KX5.pdb', 'bondsearch 0.2')
pytraj.
lowestcurve
(data, points=10, step=0.2)¶compute lowest curve for data
Parameters: | data : 2D array-like points : number of lowest points in each bin, default 10 step : step size, default 0.2 |
---|---|
Returns: | 2d array |
pytraj.
make_structure
(traj, command='', ref=None)¶limited support for make_structure
Parameters: | traj : Trajectory command : cpptraj command or a list of cpptraj commands ref : None or a Frame or a Trajectory with one Frame
|
---|---|
Returns: | traj : itself |
Notes
Apply dihedrals to specified residues using arguments found in <List of Args>, where an argument is 1 or more of the following arg types:
‘<sstype>:<res range>’
Apply SS type (phi/psi) to residue range.
<sstype> standard = alpha, left, pp2, hairpin, extended
- <sstype> turn = typeI, typeII, typeVIII, typeI’, typeII, typeVIa1, typeVIa2, typeVIb
- Turns are applied to 2 residues at a time, so resrange must be divisible by 4.
‘<custom ss>:<res range>:<phi>:<psi>’
Apply custom <phi>/<psi> to residue range.
‘<custom turn>:<res range>:<phi1>:<psi1>:<phi2>:<psi2>’
Apply custom turn <phi>/<psi> pair to residue range.
‘<custom dih>:<res range>:<dih type>:<angle>’
Apply <angle> to dihedrals in range.
<dih type> = alpha beta gamma delta epsilon zeta nu1 nu2 h1p c2p chin phi psi chip omega
‘<custom dih>:<res range>:<at0>:<at1>:<at2>:<at3>:<angle>[:<offset>]’
Apply <angle> to dihedral defined by atoms <at1>, <at2>, <at3>, and <at4>.
- Offset -2=<a0><a1> in previous res, -1=<a0> in previous res,
- 0=All <aX> in single res, 1=<a3> in next res, 2=<a2><a3> in next res.
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()[:]
>>> # Make alpha helix for residue 1 to 12)
>>> traj = pt.make_structure(traj, "alpha:1-12")
>>> # Make hairpin for residue 1 to 5 and make alpha helix for residue 6 to 12
>>> traj = pt.make_structure(traj, ["hairpin:1-5", "alpha:6-12"])
>>> # From cpptraj example:
>>> # Make residues 1 and 12 'extended', residues 6 and 7 a type I' turn, and two
>>> # custom assignments, one (custom1) for residues 2-5, the other (custom2) for residues 8-11:
>>> traj = pt.make_structure(traj, ["extended:1,12",
... "custom1:2-5:-80.:130.:-130.:140.",
... "typeI':6-7",
... "custom2:8-11:-140.:170.:-100.:140."])
>>>
>>> # Make new structure from reference
>>> def make_new_by_using_ref():
... tz2_parm7 = 'tz2.parm7'
... ref_rst7 = 'tz2.rst7'
... trajin_rst7 = pp2.rst7.save'
... traj = pt.load(trajin_rst7, top=tz2_parm7)
... ref = pt.load(ref_rst7, top=tz2_parm7)
... # make dihedral angle for targeted residues 1 to 13 by using
... # reference residues 1 to 13
... pt.make_structure(traj, "ref:1-13:1-13", ref=ref)
pytraj.
mean_structure
(traj, mask='', frame_indices=None, dtype='frame', autoimage=False, rmsfit=None, top=None)¶get mean structure for a given mask and given frame_indices
Parameters: | traj : Trajectory-like or iterable that produces Frame mask : None or str, default None (all atoms) frame_indices : iterable that produces integer, default None, optional
dtype: str, {‘frame’, ‘traj’}, default ‘frame’
autoimage : bool, default False
rmsfit : object, {Frame, int, tuple, None}, default None
|
---|
Notes
if autoimage=True and having rmsfit, perform autoimage first and do rmsfit
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # get average structure from whole traj, all atoms
>>> frame = pt.mean_structure(traj)
>>> # get average structure from several frames, '@CA' atoms"
>>> frame = pt.mean_structure(traj, '@CA', frame_indices=range(2, 8, 2))
>>> # get average structure but do autoimage and rmsfit to 1st Frame
>>> frame = pt.mean_structure(traj(autoimage=True, rmsfit=0))
>>> # get average structure but do autoimage and rmsfit to 1st Frame.
>>> frame = pt.mean_structure(traj(autoimage=True, rmsfit=0, frame_indices=[0, 5, 6]))
pytraj.
nastruct
(traj=None, ref=0, resrange=None, resmap=None, hbcut=3.5, frame_indices=None, pucker_method='altona', dtype='nupars', baseref=None, groove_3dna=True, top=None)¶compute nucleic acid parameters. (adapted from cpptraj doc)
Parameters: | traj : Trajectory-like ref : {Frame, int}, default 0 (first frame) resrange : None, str or array-like of integers resmap : residue map, example: ‘AF2:A’ hbcut : float, default=3.5 Angstrong
pucker_method : str, {‘altona’, ‘cremer’}, default ‘altona’
frame_indices : array-like, default None (all frames) baseref : {None, str}, default None
groove_3dna : bool, default True
dtype : str, {‘nupars’, ‘cpptraj_dataset’}, default ‘nupars’ |
---|---|
Returns: | out : nupars object. One can assess different values (major groove width, xdips values ...) by accessing its attribute. See example below. |
Examples
>>> import pytraj as pt
>>> import numpy as np
>>> traj = pt.datafiles.load_rna()
>>> data = pt.nastruct(traj, groove_3dna=False)
>>> data.keys()[:5]
['buckle', 'minor', 'major', 'xdisp', 'stagger']
>>> # get minor groove width values for each pairs for each snapshot
>>> # data.minor is a tuple, first value is a list of basepairs, seconda value is
>>> # numpy array, shape=(n_frames, n_pairs)
>>> data.minor
(['1G16C', '2G15C', '3G14C', '4C13G', '5G12C', '6C11G', '7C10G', '8C9G'],
array([[ 13.32927036, 13.403409 , 13.57159901, ..., 13.26655865,
13.43054485, 13.4557209 ],
[ 13.32002068, 13.45918751, 13.63253593, ..., 13.27066231,
13.42743683, 13.53450871],
[ 13.34087658, 13.53778553, 13.57062435, ..., 13.29017353,
13.38542843, 13.46101475]]))
>>> data.twist
(['1G16C-2G15C', '2G15C-3G14C', '3G14C-4C13G', '4C13G-5G12C', '5G12C-6C11G', '6C11G-7C10G', '7C10G-8C9G'],
array([[ 34.77773666, 33.98158646, 30.18647003, ..., 35.14608765,
33.9628334 , 33.13056946],
[ 33.39176178, 32.68476105, 28.36385536, ..., 36.59774399,
30.20827484, 26.48732948],
[ 36.20665359, 32.58955002, 27.47707367, ..., 33.42843246,
30.90047073, 33.73724365]]))
>>> # change dtype
>>> data = pt.nastruct(traj, dtype='cpptraj_dataset')
pytraj.
native_contacts
(traj=None, mask='', mask2='', ref=0, dtype='dataset', distance=7.0, image=True, include_solvent=False, byres=False, frame_indices=None, top=None)¶compute native contacts
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # use 1st frame as reference, don't need specify ref Frame
>>> data = pt.native_contacts(traj)
>>> # explicitly specify reference, specify distance cutoff
>>> ref = traj[3]
>>> data = pt.native_contacts(traj, ref=ref, distance=8.0)
>>> # use integer array for mask
>>> data = pt.native_contacts(traj, mask=range(100), mask2=[200, 201], ref=ref, distance=8.0)
pytraj.
nh_order_parameters
(traj, vector_pairs, order=2, tstep=1.0, tcorr=10000.0, n_cores=1, **kwargs)¶compute NH order parameters
Parameters: | traj : Trajectory-like vector_pairs : 2D array-like, shape (n_pairs, 2) order : default 2 tstep : default 1. tcorr : default 10000. kwargs : additional keyword argument |
---|---|
Returns: | S2 : 1D array, order parameters |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> h_indices = pt.select('@H', traj.top)
>>> n_indices = h_indices - 1
>>> nh_pairs = list(zip(n_indices, h_indices))
>>> data = pt.nh_order_parameters(traj, nh_pairs)
pytraj.
pairwise_rmsd
(traj=None, mask='', metric='rms', top=None, dtype='ndarray', mat_type='full', frame_indices=None)¶Calculate pairwise rmsd with different metrics.
Parameters: | traj : Trajectory-like or iterable object mask : mask
metric : {‘rms’, ‘dme’, ‘srmsd’, ‘nofit’}
top : Topology, optional, default=None dtype: ndarray
mat_type : str, {‘full’, ‘half’}
|
---|
Notes
Install libcpptraj
with openmp
to get benefit from parallel
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> arr = pt.pairwise_rmsd(traj(0, 1000, mask='@CA'))
>>> # calculate pairwise rmsd for all frames using CA atoms, use `dme` (distance RMSD)
>>> # convert to numpy array
>>> arr_np = pt.pairwise_rmsd(traj, "@CA", metric="dme", dtype='ndarray')
>>> # calculate pairwise rmsd for all frames using CA atoms, nofit for RMSD
>>> # convert to numpy array
>>> arr_np = pt.pairwise_rmsd(traj, "@CA", metric="nofit", dtype='ndarray')
>>> # calculate pairwise rmsd for all frames using CA atoms
>>> # use symmetry-corrected RMSD, convert to numpy array
>>> arr_np = pt.pairwise_rmsd(traj, "@CA", metric="srmsd", dtype='ndarray')
>>> # use different dtype
>>> arr_np = pt.pairwise_rmsd(traj, "@CA", metric="srmsd", dtype='dataset')
pytraj.
principal_axes
(traj=None, mask='*', dorotation=False, mass=True, top=None)¶compute principal axes
Parameters: | traj : Trajectory-like mask : str, default ‘*’ (all atoms) mass: bool, defaul True if `dorotation`, the system will be aligned along principal axes (apply for mutable system) top : Topology, optional |
---|---|
Returns: | out_0 : numpy array, shape=(n_frames, 3, 3) out_1: numpy array with shape=(n_frames, 3) |
pytraj.
projection
(traj, mask='', eigenvectors=None, eigenvalues=None, scalar_type='covar', average_coords=None, frame_indices=None, dtype='ndarray', top=None)¶compute projection along given eigenvectors
Parameters: | traj : Trajectory-like mask : atom mask, either string or array-like eigenvalues : 1D array-like eigenvectors : 2D array-like scalar_type : str, {‘covar’, ‘mwcovar’, }, default ‘covar’
average_coords : 3D array-like, optional, default None
frame_indices : array-like
dtype : str, return data type, default ‘ndarray’ top : Topology, optional, default None |
---|---|
Returns: | projection_data : ndarray, shape=(n_vecs, n_frames) |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> mat = pt.matrix.covar(traj, '@CA')
>>> eigenvectors, eigenvalues = pt.matrix.diagonalize(mat, 2)
>>> # since we compute covariance matrix, we need to specify
>>> # scalar_type = 'covar'
>>> scalar_type = 'covar'
>>> data = pt.projection(traj, '@CA', eigenvalues=eigenvalues, eigenvectors=eigenvectors, scalar_type=scalar_type)
>>> data.shape
(2, 101)
pytraj.
pucker
(traj=None, pucker_mask=("C1'", "C2'", "C3'", "C4'", "O4'"), resrange=None, top=None, dtype='dataset', range360=False, method='altona', use_com=True, amplitude=False, offset=None)¶compute pucker
Parameters: | traj : Trajectory-like pucker_mask : str resrange : None or array of int top : Topology, optional dtype : str, return type range360: bool, use 360 or 180 scale method : {‘altona’, ‘cremer’}, default ‘altona’ use_com : bool amplitude : bool, default False offset : None or float |
---|---|
Returns: | Dataset |
pytraj.
randomize_ions
(traj, mask, around, by, overlap, seed=1, top=None, frame_indices=None)¶randomize_ions for given Frame with Topology
Parameters: | traj : Trajectory-like or a Frame
mask : str
frame_indices : {None, array-like}, optional top : Topology, optional (only needed if |
---|
Examples
>>> pt.randomize_ions(traj, mask='@Na+', around=':1-16', by=5.0, overlap=3.0, seed=113698)
pytraj.
read_pickle
(path)¶Load pickled pandas object (or any other pickled object) from the specified file path
Warning: Loading pickled data received from untrusted sources can be unsafe. See: http://docs.python.org/2.7/library/pickle.html
Parameters: | path : string
|
---|---|
Returns: | unpickled : type of object stored in file |
pytraj.
replicate_cell
(traj=None, mask='', direction='all', frame_indices=None, top=None)¶create a trajectory where the unit cell is replicated in 1 or more direction (up to 27)
Parameters: | traj : Trajectory-like or Frame iterator mask : str, default: “”
direction: {‘all’, ‘dir’} or list/tuple of <XYZ> (below)
top : Topology, optional, default: None |
---|---|
Returns: | traj : pytraj.Trajectory |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> new_traj = pt.replicate_cell(traj, direction='all')
>>> new_traj = pt.replicate_cell(traj, direction='dir 001 dir 111')
>>> new_traj = pt.replicate_cell(traj, direction='dir 001 dir 1-10')
>>> new_traj = pt.replicate_cell(traj, direction='dir 001 dir 1-10')
>>> # similiar usage
>>> new_traj = pt.replicate_cell(traj, direction=('001', '0-10'))
>>> new_traj = pt.replicate_cell(traj, direction=['001', '0-10'])
pytraj.
rmsd
(traj=None, mask='', ref=0, ref_mask='', nofit=False, mass=False, update_coordinate=True, frame_indices=None, top=None, dtype='ndarray')¶compute rmsd
Parameters: | traj : Trajectory-like mask : str or 1D array-like of string or 1D or 2D array-like
ref : {Frame, int}, default=0 (first frame)
ref_mask: str, optional
nofit : bool, default False
mass : bool, default False
update_coordinate : bool, default True
frame_indices : int 1D array-like, default None
top : {Topology, str}, default None, optional dtype : return data type, default=’ndarray’ |
---|
Notes
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_trpcage()
>>> # all atoms, do fitting, using ref=traj[-3]
>>> data = pt.rmsd(traj, ref=-3)
>>> # rmsd for 3 maskes, do fitting, using ref=traj[0] (defaul)
>>> data = pt.rmsd(traj, mask=['@CA', '@C', ':3-18@CA'], dtype='dataset')
>>> # rmsd to first frame, use mass ':3-13' but do not perorm fitting
>>> data= pt.rmsd(traj, ref=traj[0], mask=':3-13', nofit=True)
>>> # use atom indices for mask
>>> data= pt.rmsd(traj, ref=traj[0], mask=range(40), nofit=True)
>>> # compute rmsd (and align) with reference having different atoms
>>> trpcage_traj = pt.datafiles.load_trpcage()[:]
>>> tz2_traj = pt.datafiles.load_tz2()[:1]
>>> data = pt.rmsd(trpcage_traj, mask='@1-10', ref=tz2_traj, ref_mask='@11-20')
>>> data
array([ 2.16203842, 2.28859396, 2.15817654, ..., 2.20767189,
2.30087764, 1.92654945])
Notes
-----
if ``traj`` is mutable and update_coordinate=True, its coordinates will be updated.
pytraj.
rmsd_nofit
(traj=None, mask='', ref=0, mass=False, frame_indices=None, top=None, dtype='ndarray', **kwd)¶compute rmsd without fitting (translating and rotating)
Parameters: | traj : Trajectory-like mask : str ref : Frame or int mass : bool, default False
frame_indices : 1D array-like, default None
|
---|
Notes
This method is equal to pytraj.rmsd(traj, mask, ref, nofit=True, ...)
pytraj.
rmsd_perres
(traj=None, mask='', ref=0, mass=False, resrange=None, perres_mask=None, perres_center=False, perres_invert=False, frame_indices=None, top=None, dtype='dataset', **kwd)¶superpose traj
to ref
with mask, then calculate nofit rms for residues
in resrange with given perresmask
Returns: | out : pytraj.DatasetList, shape=(1+n_residues, n_frames)
|
---|
pytraj.
rmsd_perres
(traj=None, mask='', ref=0, mass=False, resrange=None, perres_mask=None, perres_center=False, perres_invert=False, frame_indices=None, top=None, dtype='dataset', **kwd)superpose traj
to ref
with mask, then calculate nofit rms for residues
in resrange with given perresmask
Returns: | out : pytraj.DatasetList, shape=(1+n_residues, n_frames)
|
---|
pytraj.
rotate
(traj=None, command='', frame_indices=None, top=None)¶Notes
rotate
is an alias of do_rotation
Examples
>>> import pytraj as pt
>>> # load to mutable trajectory by `load` method
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2')
>>> traj = pt.load(fn, tn)
>>> # do transform traj and return itself
>>> traj = pt.rotate(traj, 'x 90')
pytraj.
rotation_matrix
(traj=None, mask='', ref=0, mass=False, frame_indices=None, top=None, with_rmsd=False)¶Compute rotation matrix with/without rmsd
Parameters: | traj : Trajectory-like ref : {int, Frame}, default 0 (first Frame)
mask : str, default all atoms mass : bool, default False
frame_indices : {None, array-like}
top : Topology, optional with_rmsd : bool, default False
|
---|---|
Returns: | out : if with_rmsd=False, return numpy array, shape (n_frames, 3, 3)
|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> mat = pt.calc_rotation_matrix(traj, mask='@CA')
>>> mat.shape
(101, 3, 3)
pytraj.
save
(filename, obj, *args, **kwd)¶an universal method
Parameters: | filename : output filename obj : Topology or Trajetory-like
*args, **kwd: additional options |
---|
See also
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_ala3()
>>> isinstance(traj, pt.TrajectoryIterator)
True
>>> top = traj.top
>>> isinstance(top, pt.Topology)
True
>>> # save Topology to a new Topology
>>> pt.save('output/prmtop', top, overwrite=True)
>>> isinstance(pt.load_topology('output/prmtop'), pt.Topology)
True
>>> # save TrajectoryIterator to disk
>>> pt.save('output/traj.nc', traj, overwrite=True)
>>> isinstance(pt.iterload('output/traj.nc', traj.top), pt.TrajectoryIterator)
True
pytraj.
scale
(traj=None, command='', frame_indices=None, top=None)¶Examples
>>> import pytraj as pt
>>> # load to mutable trajectory by `load` method
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2')
>>> traj = pt.load(fn, tn)
>>> # do transform traj and return itself
>>> traj = pt.scale(traj, '@CA x 1.2')
pytraj.
search_neighbors
(traj=None, mask='', frame_indices=None, dtype='dataset', top=None)¶search neighbors
Returns: | pytraj.DatasetList, is a list of atom index arrays for each frame. Those arrays might not have the same lenghth |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> indices = pt.search_neighbors(traj, ':5<@5.0') # around residue 5 with 5.0 cutoff
pytraj.
select
(mask, topology)¶return atom indices
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> atom_indices = pt.select_atoms('@CA', traj.top)
>>> atom_indices
array([ 4, 15, 39, ..., 159, 173, 197])
>>> pt.select_atoms(traj.top, '@CA')
array([ 4, 15, 39, ..., 159, 173, 197])
pytraj.
select_atoms
(mask, topology)¶return atom indices
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> atom_indices = pt.select_atoms('@CA', traj.top)
>>> atom_indices
array([ 4, 15, 39, ..., 159, 173, 197])
>>> pt.select_atoms(traj.top, '@CA')
array([ 4, 15, 39, ..., 159, 173, 197])
pytraj.
set_cpptraj_verbose
(cm=True)¶pytraj.
set_dihedral
(traj, resid=0, dihedral_type=None, deg=0, top=None)¶Returns: | updated traj |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> # make mutable traj by loading all frames to disk
>>> traj = traj[:]
>>> traj = pt.set_dihedral(traj, resid=2, dihedral_type='phi', deg=60)
pytraj.
show_versions
()¶>>> show_versions()
pytraj.
strip
(obj, mask)¶return a new Trajectory or FrameIterator or Topology with given mask.
Notes
This method is trying to be smart. If you give it an in-memory Trajectory, it will return a corresponding in-memory Trajectory. If you give it an out-of-memory TrajectoryIterator, it will give you a corresponding FrameIterator object (out-of-memory). If you give it a Topology, it will return a new stripped Topology.
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> traj.n_atoms
5293
>>> pt.strip(traj, '!@CA').n_atoms
12
>>> pt.strip(traj.top, '!@CA').n_atoms
12
>>> pt.strip('!@CA', traj.top).n_atoms
12
>>> t0 = traj[:3]
>>> pt.strip(t0, '!@CA').n_atoms
12
>>> fi = pt.iterframe(traj, stop=3)
>>> fi = pt.strip(fi, '!@CA')
>>> for frame in fi:
... print(frame)
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
>>> # raise ValueError
>>> pt.strip(0, '@CA')
Traceback (most recent call last):
...
ValueError: object must be either Trajectory or Topology
pytraj.
superpose
(traj, *args, **kwd)¶pytraj.
symmrmsd
(traj, mask='', ref=0, ref_mask=None, fit=True, remap=False, mass=False, top=None, dtype='ndarray', frame_indices=None)¶Compute symmetry-corrected RMSD
Parameters: | traj : Trajectory-like mask : str, default ‘’ (all atoms) ref : {int, Frame}, default 0 (first frame) ref_mask : {str, None}, default None
fit : Bool, default True
mass : Bool, default False
remap : Bool, default False
dtype : str, default ‘ndarray’
frame_indices : {None, array-like}, default None
|
---|
Examples
>>> import pytraj as pt
>>> traj = pt.load("TYR.nc", "TYR.parm7")
>>> data = pt.symmrmsd(traj, ref=0)
Notes
-----
versionadded: 1.0.6
pytraj.
timecorr
(vec0, vec1, order=2, tstep=1.0, tcorr=10000.0, norm=False, dtype='ndarray')¶compute time correlation.
Parameters: | vec0 : 2D array-like, shape=(n_frames, 3) vec1 : 2D array-like, shape=(n_frames, 3) order : int, default 2 tstep : float, default 1. tcorr : float, default 10000. norm : bool, default False |
---|
pytraj.
to_pickle
(obj, path)¶Pickle (serialize) object to input file path
Parameters: | obj : any object path : string
|
---|
pytraj.
transform
(traj, by, frame_indices=None)¶transform pytraj.Trajectory by a series of cpptraj’s commands
Parameters: | traj : Mutable Trajectory by : list of cpptraj commands frame_indices : {None, array-like}, default None
|
---|---|
Returns: | transformed Trajectory. Trajectory’s coordinates will be inplace-updated |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # perform 'autoimage', then 'rms', then 'center'
>>> traj = pt.transform(traj[:], by=['autoimage', 'rms', 'center :1-5'])
pytraj.
translate
(traj=None, command='', frame_indices=None, top=None)¶translate coordinate
Examples
>>> import pytraj as pt
>>> # load to mutable trajectory by `load` method
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2')
>>> traj = pt.load(fn, tn)
>>> # do transform traj and return itself
>>> traj = pt.translate(traj, '@CA x 120.')
pytraj.
velocityautocorr
(traj, mask='', maxlag=-1, tstep=1.0, direct=True, norm=False, usevelocity=False, dtype='ndarray', top=None, velocity_arr=None)¶Parameters: | traj : Trajectory-like mask : str
maxlag : int, default -1
tstep : float, default 1.0 direct : bool, default True
norm : bool, default False
usevelocity : bool, default False
dtype : str, default ‘ndarray’
top : None or Topology, default None, optional velocity_arr : None or 3D like array, default None
|
---|
Notes
If you create Trajectory by pytraj.load method, there is no velocity information. So if you want to use usevelocity=True, you need to provide 3D-array velocity_arr
pytraj.
volmap
(traj, mask, grid_spacing, size=None, center=None, buffer=3.0, centermask='*', radscale=1.36, peakcut=0.05, top=None, dtype='ndarray', frame_indices=None)¶(combined with cpptraj doc) Grid data as a volumetric map, similar to the volmap command in VMD. The density is calculated by treating each atom as a 3-dimensional Gaussian function whose standard deviation is equal to the van der Waals radius
Parameters: | mask : {str, array-like}, default all atoms
grid_spacing : tuple, grid spacing in X-, Y-, Z-dimensions, require size : {None, tuple}, default None
center : {None, tuple}, default None
buffer : float, default 3.0 Angstrom
centermask : str radscale : float, default 1.36 (to match to VMD calculation)
peakcut : float |
---|
Examples
>>> import pytraj as pt
>>> # load all frames to memory
>>> traj = pt.datafiles.load_tz2_ortho()[:]
>>> # do fitting and centering before perform volmap
>>> traj = traj.superpose(mask=':1-13').center(':1-13 mass origin')
>>> data = pt.volmap(traj, mask=':WAT@O', grid_spacing=(0.5, 0.5, 0.5), buffer=2.0, centermask='!:1-13', radscale=1.36)
pytraj.
volume
(traj=None, mask='', top=None, dtype='ndarray', frame_indices=None)¶compute volume
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> vol = pt.volume(traj, '@CA')
pytraj.
wavelet
(traj, command)¶wavelet analysis
Parameters: | traj : Trajectory-like command : str, cpptraj command |
---|---|
Returns: | out : dict |
Notes
you need to type cpptraj command. Please check cpptraj manual for further info if you really want to use it.
so this method is only good for small trajectory that fit to your RAM.
version added: 1.0.6
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_dpdp()
>>> c0 = 'nb 10 s0 2 ds 0.25 type morlet correction 1.01 chival 0.25 :1-22'
>>> c1 = 'cluster minpoints 66 epsilon 10.0'
>>> command = ' '.join((c0, c1))
>>> wavelet_dict = pt.wavelet(traj, command)
pytraj.
write_parm
(filename=None, top=None, format='amberparm', overwrite=False)¶pytraj.
write_traj
(filename, traj, format='infer', top=None, frame_indices=None, overwrite=False, force=False, velocity=False, options='')¶write Trajectory-like or iterable object to trajectory file
Parameters: | filename : str traj : Trajectory-like or iterator that produces Frame or 3D ndarray with shape=(n_frames, n_atoms, 3) format : str, default ‘infer’
top : Topology, optional, default: None frame_indices: array-like or iterator that produces integer, default: None
overwrite: bool, default: False velocity : bool, default False
force : bool, default False
options : str, additional cpptraj keywords |
---|
Notes
Format | Extension |
---|---|
Amber Trajectory | .crd |
Amber NetCDF | .nc |
Amber Restart | .rst7 |
Amber NetCDF | .ncrst |
Charmm DCD | .dcd |
PDB | .pdb |
Mol2 | .mol2 |
Scripps | .binpos |
Gromacs | .trr |
SQM Input | .sqm |
‘options’ for writing to pdb format (cptraj manual):
dumpq: Write atom charge/GB radius in occupancy/B-factor columns (PQR format)."
parse: Write atom charge/PARSE radius in occupancy/B-factor columns (PQR format)."
vdw: Write atom charge/VDW radius in occupancy/B-factor columns (PQR format)."
pdbres: Use PDB V3 residue names."
pdbatom: Use PDB V3 atom names."
pdbv3: Use PDB V3 residue/atom names."
teradvance: Increment record (atom) # for TER records (default no)."
terbyres: Print TER cards based on residue sequence instead of molecules."
model: Write to single file separated by MODEL records."
multi: Write each frame to separate files."
chainid <c>: Write character 'c' in chain ID column."
sg <group>: Space group for CRYST1 record, only if box coordinates written."
include_ep: Include extra points."
conect: Write CONECT records using bond information.");
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> pt.write_traj("output/t.nc", traj, overwrite=True) # write to amber netcdf file
>>> # write to multi pdb files (t.pdb.1, t.pdb.2, ...)
>>> pt.write_traj("output/t.pdb", traj, overwrite=True, options='multi')
>>> # write all frames to single pdb file and each frame is seperated by "MODEL" word
>>> pt.write_traj("output/t.pdb", traj, overwrite=True, options='model')
>>> # write to DCD file
>>> pt.write_traj("output/test.dcd", traj, overwrite=True)
>>> # write to netcdf file from 3D numpy array, need to provide Topology
>>> xyz = traj.xyz
>>> top = traj.top
>>> pt.write_traj("output/test_xyz.nc", xyz, top=traj.top, overwrite=True)
>>> pt.write_traj("output/test_xyz.nc", xyz, top=traj.top, overwrite=True)
>>> # you can make a fake Topology to write xyz coordinates too
>>> n_atoms = xyz.shape[1]
>>> top2 = pt.tools.make_fake_topology(n_atoms)
>>> pt.write_traj("output/test_xyz_fake_top.nc", xyz, top=top2, overwrite=True)
‘options’ for writing to amber netcdf format (cptraj manual):
remdtraj: Write temperature to trajectory (makes REMD trajectory)."
velocity: Write velocities to trajectory."
force: Write forces to trajectory.");
‘options’ for writing to amber netcdf restart format(cptraj manual):
novelocity: Do not write velocities to restart file."
notime: Do not write time to restart file."
remdtraj: Write temperature to restart file."
time0: Time for first frame (default 1.0)."
dt: Time step for subsequent frames, t=(time0+frame)*dt; (default 1.0)");
keepext Keep filename extension; write '<name>.<num>.<ext>' instead (example: myfile.1.rst7)
‘options’ for writing to mol2 format (cptraj manual):
single : Write to a single file."
multi : Write each frame to a separate file."
sybyltype: Convert Amber atom types (if present) to SYBYL types.");
‘options’ for other formats:
please check http://ambermd.org/doc12/Amber15.pdf
pytraj.
xcorr
(data0, data1, dtype='ndarray')¶compute cross correlation between two datasets
Parameters: | data0 and data1: 1D-array like dtype : return datatype, default ‘ndarray’ |
---|
Notes
Same as corr in cpptraj