pytraj
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.
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.
load_remd
(filename, top=None, T='300.0')¶pytraj.
iterload_remd
(filename, top=None, T='300.0')¶Load temperature remd trajectory for single temperature. Example: 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.
load_pdb_rcsb
(pdbid)¶load pdb file from rcsb website
Parameters: | pdbid : str |
---|
Examples
io.loadpdb_rcsb(“2KOC”) # popular RNA hairpin
pytraj.
load_cpptraj_file
(filename)¶Parameters: | fname : str, name of cpptraj input file
|
---|
pytraj.
load_sample_data
(data_name=None)¶Return TrajectoryIterator instance for Ala3 or tz2 data
Notes
pytraj.
load_ParmEd
(parmed_obj, as_traj=False, **kwd)¶return pytraj’s Topology or Trajectory objects
parmed_obj : ParmEd’s Structure object as_traj: bool, default False
if True, return pytraj.trajectory.Trajectory if False, return Topology
>>> import parmed as pmd
>>> import pytraj as pt
>>> p = pmd.download_PDB("1l2y")
>>> top = pt.load_ParmEd(p)
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.
write_parm
(filename=None, top=None, format='amberparm', overwrite=False)¶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.
write_traj
(filename='', traj=None, format='infer', top=None, frame_indices=None, overwrite=False, crdinfo=None, 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 crdinfo : None or dict, default None
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.
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.
read_json
(path)¶Parameters: | path : string
|
---|---|
Returns: | dict : python dict |
pytraj.
to_pickle
(obj, path)¶Pickle (serialize) object to input file path
Parameters: | obj : any object path : string
|
---|
pytraj.
to_json
(obj, path)¶Parameters: | obj : any object path : string
|
---|
pytraj.
align_principal_axis
(traj=None, mask='*', top=None, frame_indices=None, mass=False)¶Notes
apply for mutatble traj (Trajectory, Frame)
pytraj.
dihedral
(traj=None, mask='', top=None, dtype='ndarray', frame_indices=None, *args, **kwargs)¶compute dihedral angle between two maskes
Parameters: | traj : Trajectory-like, list of Trajectory, list of Frames mask : str or array top : Topology, optional dtype : return type, defaul ‘ndarray’ |
---|---|
Returns: | 1D ndarray if mask is a string 2D ndarray, shape (n_atom_pairs, n_frames) if mask is a list of strings or an array |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # calculate dihedral angle for four atoms, using amber mask
>>> pt.dihedral(traj, '@1 @3 @10 @20')
array([ 23.32244362, 23.5386922 , 14.26831569, 14.58865946,
23.98675475, 26.18419185, 6.06982926, 13.57158505,
16.59013076, 29.99131573])
>>> # calculate dihedral angle for four groups of atoms, using amber mask
>>> data = pt.dihedral(traj, '@1,37,8 @2,4,6 @5,20 @21,22')
>>> # calculate dihedral angle for four residues, using amber mask
>>> data = pt.dihedral(traj, ':1 :10 :20 :22')
>>> # calculate multiple dihedral angles for four residues, using amber mask
>>> # angle for residue 1, 10, 20, 30; angle between residue 3, 20, 30, 40
>>> # (when using atom string mask, index starts from 1)
>>> pt.dihedral(traj, [':1 :10 :20 :30', ':3 :20 :30 :40'])
array([[-166.81829116, -160.19029669, -158.56560062, ..., -169.10064772,
-158.81655586, -165.28873555],
[ -0.60994639, 0.78261235, 1.86394369, ..., 1.21170489,
-1.16762607, -3.08412049]])
>>> # calculate dihedral angle for a series of atoms, using array for atom mask
>>> # dihedral angle for atom 1, 5, 8, 10, dihedral for atom 4, 10, 20, 30 (index starts from 0)
>>> data = pt.dihedral(traj, [[1, 5, 8, 10], [4, 10, 20, 30]])
pytraj.
atomicfluct
(traj=None, mask='', top=None, dtype='ndarray', frame_indices=None)¶Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.atomicfluct(traj, '@CA')
>>> data[:3]
array([[ 5. , 0.61822273],
[ 16. , 0.5627449 ],
[ 40. , 0.53717119]])
pytraj.
superpose
(traj, *args, **kwd)¶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.
multivector
(traj, resrange, names, top=None, dtype='dataset', frame_indices=None)¶Parameters: | traj : Trajectory-like resrange : str, residue range names : {str, tuple of str} top : Topology, optional dtype : str, default ‘dataset’ frame_indices : {None, 1D array-like}, optional, default None |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> vecs = pt.multivector(traj, resrange='1-5', names=('C', 'N'))
>>> vecs = pt.multivector(traj, resrange='1-5', names='C N')
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 : 1D-array
|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_rna()
>>> failures = pt.check_structure(traj[0], top=traj.top)
pytraj.
angle
(traj=None, mask='', top=None, dtype='ndarray', frame_indices=None, *args, **kwargs)¶compute angle between two maskes
Parameters: | traj : Trajectory-like, list of Trajectory, list of Frames mask : str or array top : Topology, optional dtype : return type, defaul ‘ndarray’ |
---|---|
Returns: | 1D ndarray if mask is a string 2D ndarray, shape (n_atom_pairs, n_frames) if mask is a list of strings or an array |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> # calculate angle for three atoms, using amber mask
>>> pt.angle(traj, '@1 @3 @10')
array([ 98.06193365, 95.75979717, 105.59626997, 107.64079091,
94.93516228, 102.06028369, 109.3479057 , 110.11532478,
101.86104127, 110.48992512])
>>> # calculate angle for three groups of atoms, using amber mask
>>> angles = pt.angle(traj, '@1,37,8 @2,4,6 @5,20')
>>> # calculate angle between three residues, using amber mask
>>> angles = pt.angle(traj, ':1 :10 :20')
>>> # calculate multiple angles between three residues, using amber mask
>>> # angle between residue 1, 10, 20, angle between residue 3, 20, 30
>>> # (when using atom string mask, index starts from 1)
>>> angles = pt.angle(traj, [':1 :10 :20', ':3 :20 :30'])
>>> # calculate angle for a series of atoms, using array for atom mask
>>> # angle between atom 1, 5, 8, distance between atom 4, 10, 20 (index starts from 0)
>>> angles = pt.angle(traj, [[1, 5, 8], [4, 10, 20]])
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.
radgyr
(traj=None, mask='', top=None, nomax=True, frame_indices=None, dtype='ndarray')¶compute radius of gyration
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.radgyr(traj, '@CA')
>>> data = pt.radgyr(traj, '!:WAT', nomax=False)
>>> data = pt.radgyr(traj, '@CA', frame_indices=[2, 4, 6])
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
pytraj.
molsurf
(traj=None, mask='', probe=1.4, offset=0.0, dtype='ndarray', frame_indices=None, top=None)¶calc molsurf
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> pt.molsurf(traj, '@CA')
array([ 458.51409637, 459.64784573, 456.54690793, 467.72939574,
462.45908781, 458.70327554, 454.40514806, 455.15015576,
468.70566447, 456.0058624 ])
>>> pt.molsurf(traj, '!:WAT')
array([ 1079.1395679 , 1090.79759341, 1069.65127413, 1096.0810919 ,
1091.65862234, 1091.68906298, 1085.53105392, 1069.22510187,
1079.70803583, 1075.8151414 ])
pytraj.
center_of_geometry
(traj=None, mask='', top=None, dtype='ndarray', frame_indices=None)¶pytraj.
pca
(traj, mask, n_vecs=2, fit=True, ref=None, ref_mask=None, dtype='ndarray', top=None)¶perform PCA analysis by following below steps:
Parameters: | traj : Trajectory
mask : str
n_vecs : int, default 2
fit : bool, default True
ref : {None, Frame, int}, default None
ref_mask : {None, str}, default None (use mask)
dtype : return datatype top : Topology, optional |
---|---|
Returns: | out1: projection_data, ndarray with shape=(n_vecs, n_frames) out2: tuple of (eigenvalues, eigenvectors) |
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()[:]
>>> # compute pca for first and second modes
>>> pca_data = pt.pca(traj, '!@H=', n_vecs=2)
>>> # get projection values
>>> pca_data[0]
array([[ 4.93425131, 13.80002308, 20.61605835, ..., -57.92280579,
-61.25728607, -52.85142136],
[ 4.03333616, -6.9132452 , -14.53991318, ..., -6.757936 ,
2.1086719 , -3.60922861]], dtype=float32)
>>> # get eigenvalues for first 2 modes
>>> pca_data[1][0]
array([ 1399.36472919, 240.42342439])
>>> # compute pca for all modes
>>> pca_data = pt.pca(traj, '!@H=', n_vecs=-1)
>>> # does not perform fitting
>>> data = pt.pca(traj, mask='!@H=', fit=False)
>>> # provide different mask for fitting
>>> data = pt.pca(traj, mask='!@H=', fit=True, ref=0, ref_mask='@CA')
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.
distance
(traj=None, mask='', frame_indices=None, dtype='ndarray', top=None, image=False, n_frames=None)¶compute distance between two maskes
Parameters: | traj : Trajectory-like, list of Trajectory, list of Frames mask : str or a list of string or a 2D array-like of integers frame_indices : array-like, optional, default None dtype : return type, default ‘ndarray’ top : Topology, optional image : bool, default False n_frames : int, optional, default None
|
---|---|
Returns: | 1D ndarray if mask is a string 2D ndarray, shape (n_atom_pairs, n_frames) if mask is a list of strings or an array |
Notes
Be careful with Topology. If your topology has Box info but your traj does not, you would get weird output ([0.0, ...]). Make sure to use image=False in this method or set_nobox for Topology.
Examples
>>> import pytraj as pt
>>> # calculate distance for two atoms, using amber mask
>>> traj = pt.datafiles.load_tz2_ortho()
>>> dist = pt.distance(traj, '@1 @3')
>>> # calculate distance for two groups of atoms, using amber mask
>>> dist = pt.distance(traj, '@1,37,8 @2,4,6')
>>> # calculate distance between two residues, using amber mask
>>> dist = pt.distance(traj, ':1 :10')
>>> # calculate multiple distances between two residues, using amber mask
>>> # distance between residue 1 and 10, distance between residue 3 and 20
>>> # (when using atom string mask, index starts from 1)
>>> dist = pt.distance(traj, [':1 :10', ':3 :20'])
>>> # calculate distance for a series of atoms, using array for atom mask
>>> # distance between atom 1 and 5, distance between atom 4 and 10 (index starts from 0)
>>> dist = pt.distance(traj, [[1, 5], [4, 10]])
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.
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.
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
|
---|
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.
grid
(traj=None, command='', top=None, dtype='dataset')¶pytraj.
rdf
(traj=None, solvent_mask=':WAT@O', solute_mask='', maximum=10.0, bin_spacing=0.5, image=True, density=0.033456, volume=False, center_solvent=False, center_solute=False, intramol=True, frame_indices=None, top=None)¶compute radial distribtion function. Doc was adapted lightly from cpptraj doc
Parameters: | traj : Trajectory-like, require solvent_mask : solvent mask, default None, required bin_spacing : float, default 0.5, optional
maximum : float, default 10., optional
solute_mask: str, default None, optional
image : bool, default True, optional
density : float, default 0.033456 molecules / A^3, optional volume : determine density for normalization from average volume of input frames center_solvent : bool, default False, optional
center_solute : bool, default False, optional
intramol : bool, default True, optional
frame_indices : array-like, default None, optional |
---|---|
Returns: | a tuple of bin_centers, rdf values |
Notes
pytraj
and libcpptraj
with openmp to speed up calculationExamples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=10.0, solute_mask=':WAT@O')
>>> data[0]
array([ 0.25, 0.75, 1.25, ..., 8.75, 9.25, 9.75])
>>> data[1]
array([ 0. , 0. , 0. , ..., 0.95620052,
0.95267934, 0.95135242])
>>> # use array-like mask
>>> atom_indices = pt.select(':WAT@O', traj.top)
>>> data = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=10.0, solute_mask=atom_indices)
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.
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.
replicate_cell
(traj=None, mask='', direction='all', 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
if traj
is mutable and update_coordinate=True, its coordinates will be updated.
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])
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.
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.
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.
pairdist
(traj, mask='*', mask2='', delta=0.1, dtype='ndarray', top=None, frame_indices=None)¶compute pair distribution function
Parameters: | traj : Trajectory-like mask : str, default all atoms delta : float, default 0.1 dtype : str, default ‘ndarray’
top : Topology, optional |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.calc_pairdist(traj)
pytraj.
autoimage
(traj, mask='', frame_indices=None, top=None)¶perform autoimage and return the coordinate-updated traj
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()[:]
>>> traj = pt.autoimage(traj)
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.
bfactors
(traj=None, mask='', byres=True, top=None, dtype='ndarray', frame_indices=None)¶calculate pseudo bfactor
Parameters: | traj: Trajectory-like mask: str, mask |
---|---|
Returns: | if dtype is ‘ndarray’ (default), return a numpy array with shape=(n_atoms/n_residues, 2) ([atom_or_residue_idx, value]) |
Notes
This is NOT getting bfactor from xray, but computing bfactor from simulation.
Examples
>>> import pytraj as pt
>>> from pytraj.testing import get_fn
>>> fn, tn = get_fn('tz2')
>>> traj = pt.load(fn, tn, mask='!:WAT')
>>> traj = pt.superpose(traj)
>>> bfactor = pt.calc_bfactors(traj, byres=True)
pytraj.
mindist
(traj=None, command='', top=None, dtype='ndarray', frame_indices=None)¶compute mindist
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> data = pt.mindist(traj, '@CA @H')
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.
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.
surf
(traj=None, mask='', dtype='ndarray', frame_indices=None, top=None)¶calc surf (LCPO method)
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.surf(traj, '@CA')
pytraj.
center_of_mass
(traj=None, mask='', top=None, dtype='ndarray', frame_indices=None)¶compute center of mass
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> # compute center of mass residue 3 for first 2 frames.
>>> pt.calc_center_of_mass(traj(stop=2), ':3')
array([[-0.661702 , 6.69124347, 3.35159413],
[ 0.5620708 , 7.82263042, -0.72707798]])
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.
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 |
---|
pytraj.
make_structure
(traj=None, mask='', top=None)¶pytraj.
diffusion
(traj, mask='', tstep=1.0, individual=False, top=None, dtype='dataset', frame_indices=None)¶compute diffusion
Parameters: | traj : Trajectory-like or iterator mask : str, default ‘’ (all atoms) tstep : float, time step between frames, default 1.0 ps individual : bool, default False top : Topology, optional dtype : str, default ‘dataset’ frame_indices : array or None |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.diffusion(traj, dtype='dict')
>>> data['X']
array([ 0. , 0.87027302, 1.64626022, 2.26262651, 2.98068114,
3.57075535, 4.07030655, 4.71894512, 5.42302306, 6.01310377])
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.
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.
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.
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.calc_volume(traj, '@CA')
pytraj.
multidihedral
(traj=None, dhtypes=None, resrange=None, define_new_type=None, range360=False, dtype='dataset', top=None, frame_indices=None)¶perform dihedral search
Parameters: | traj : Trajectory-like object dhtypes : 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, dhtypes='phi psi')
>>> data = pt.multidihedral(traj, dhtypes='phi psi', resrange='3-7')
>>> data = pt.multidihedral(traj, dhtypes='phi psi', resrange=[3, 4, 8])
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.
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.
center
(traj=None, mask='', center='box', mass=False, top=None, frame_indices=None)¶Parameters: | traj : Trajectory-like or Frame iterator mask : str, mask center : str, {‘box’, ‘origin’} 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.
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.
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.
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.
set_dihedral
(traj, resid='1', 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='3', dihedral_type='phi', deg=60)
>>> traj = pt.set_dihedral(traj, resid=2, dihedral_type='phi', deg=60)
pytraj.
watershell
(traj=None, solute_mask='', solvent_mask=':WAT', lower=3.4, upper=5.0, image=True, dtype='dataset', frame_indices=None, top=None)¶(adapted from cpptraj doc): Calculate numbers of waters in 1st and 2nd solvation shells (defined by <lower cut> (default 3.4 Ang.) and <upper cut> (default 5.0 Ang.)
Parameters: | traj : Trajectory-like solute_mask: solute mask solvent_mask: solvent mask lower : double, default 3.4
upper : double, default 5.0
image : bool, defaul True
dtype : return type, defaul ‘dataset’ top : Topology, optional |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> data = pt.watershell(traj, solute_mask='!:WAT')
>>> data = pt.watershell(traj, solute_mask='!:WAT', lower=5.0, upper=10.)
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.
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.
pairwise_distance
(traj=None, mask_1='', mask_2='', top=None, dtype='ndarray', frame_indices=None)¶compute pairwise distance between atoms in mask_1 and atoms in mask_2
Parameters: | traj : Trajectory-like or iterable that produces Frame mask_1: string or 1D array-like mask_2: string or 1D array-like ... |
---|---|
Returns: | out_1 : numpy array, shape (n_frames, n_atom_1, n_atom_2) out_2 : atom pairs, shape=(n_atom_1, n_atom_2, 2) |
Notes
This method is only fast for small number of atoms.
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> mat = pt.calc_pairwise_distance(traj, '@CA', '@CB')
pytraj.
projection
(traj, mask='', eigenvalues=None, eigenvectors=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')
>>> eigenvalues, eigenvectors = 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.
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.
calc_multidihedral
(traj=None, dhtypes=None, resrange=None, define_new_type=None, range360=False, dtype='dataset', top=None, frame_indices=None)¶perform dihedral search
Parameters: | traj : Trajectory-like object dhtypes : 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, dhtypes='phi psi')
>>> data = pt.multidihedral(traj, dhtypes='phi psi', resrange='3-7')
>>> data = pt.multidihedral(traj, dhtypes='phi psi', resrange=[3, 4, 8])
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_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_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_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_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_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_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.
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_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.
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.
esander
(traj=None, prmtop=None, igb=8, mm_options=None, qm_options=None, mode=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 mode : str, default=None, 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.
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.
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.
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.
Topology
¶Bases: object
Attributes
angle_indices |
|
angles |
|
atom_names |
return unique atom name in Topology |
atomlist |
return a copy of atoms. If the Topology is large, this method calling |
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) |
moleculelist |
return a copy of molecules. (not much information) |
mols |
|
n_atoms |
|
n_mols |
|
n_residues |
|
n_solvents |
|
residue_names |
return unique residue names in Topology |
residuelist |
return a copy of residues |
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) |
|
indices_bonded_to (self, atom_name) |
return indices of the number of atoms that each atom bonds to |
is_empty (self) |
|
join (self, Topology top) |
|
load (self, string filename) |
loading Topology from filename. This is for internal use. Should pytraj.load_topology |
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_distance_mask_reference (self, Frame frame) |
|
set_integer_mask (self, AtomMask atm, ...) |
|
set_nobox (self) |
|
set_solvent (self, mask) |
set mask as solvent |
simplify (...) |
return a (immutable) light version of Topology for fast iterating. (experiment) |
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_dataframe (...) |
convert to pandas’ DataFrame. (experiment) |
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 |
---|
atom_names
¶return unique atom name in Topology
atomlist
¶return a copy of atoms. If the Topology is large, this method calling is every expensive. Make sure to call once and save it.
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)¶indices_bonded_to
(self, atom_name)¶return indices of the number of atoms that each atom bonds to
Parameters: | atom_name : name of the atom |
---|
is_empty
(self)¶join
(self, Topology top)¶load
(self, string filename)¶loading Topology from filename. This is for internal use. Should pytraj.load_topology
mass
¶return a copy of atom masses (numpy 1D array)
moleculelist
¶return a copy of molecules. (not much information)
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 ()
residue_names
¶return unique residue names in Topology
residuelist
¶return a copy of residues
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_distance_mask_reference
(self, Frame frame)¶set_integer_mask
(self, AtomMask atm, Frame frame=<???>)¶set_nobox
(self)¶set_solvent
(self, mask)¶set mask
as solvent
simplify
(self) return a (immutable) light version of Topology for fast iterating. (experiment)¶return a (immutable) light version of Topology for fast iterating. (experiment)
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_dataframe
(self) convert to pandas' DataFrame. (experiment)¶convert to pandas’ DataFrame. (experiment)
to_dict
(self)¶convert Topology to Python dict
to_parmed
(self)¶try to load to ParmEd’s Structure
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.
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.
Trajectory
(filename=None, top=None, xyz=None)¶Bases: pytraj.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 |
at (index) |
|
autoimage ([command]) |
perform autoimage |
center ([command]) |
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 |
reverse () |
reverse Trajectory |
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) |
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
at
(index)¶autoimage
(command='')¶perform autoimage
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
(command='')¶do centering
Returns: | self |
---|
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
¶reverse
()¶reverse Trajectory
Returns: | self |
---|
Examples
>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()[:]
>>> traj = traj.reverse()
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)¶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.c_traj.c_trajectory.TrajectoryCpptraj
, pytraj.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. If set _pickle_topology to True, its Topology will be pickled (slow but more accurate if you change the topology in the fly)
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 |
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) |
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
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])
Example 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)¶require NGLView
Parameters: | args and kwargs : NGLView’s arguments |
---|
xyz
¶return 3D array of coordinates
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.
dispatch
(type cls, CpptrajState state, line)¶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.
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.
set_cpptraj_verbose
(cm=True)¶pytraj.
show_versions
()¶>>> show_versions()