pytraj

pytraj

pytraj.dispatch(type cls, CpptrajState state, line)
pytraj.iterchunk(traj, *args, **kwd)

iterate traj by chunk

Parameters:

traj : TrajectoryIterator

chunksize : int

the number of frames in each chunk

start : int, default 0

start frame to iterate

start : int, default -1 (last frame)

stop frame

autoimage : bool, default False

if True, do autoimage for chunk

See also

pytraj.TrajectoryIterator.iterchunk

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

pytraj.TrajectoryIterator.iterframe

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.load_batch(traj, txt)

perform calculation for traj with cpptraj’s batch style. This is for internal use.

Parameters:

traj : pytraj.TrajectoryIterator

txt : text or a list of test

cpptraj’s commands

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> text = """
... autoimage
... radgyr @CA nomax
... molsurf !@H=
... """
>>> state = pt.load_batch(traj, text)
>>> state = state.run()
>>> state.data
<pytraj.datasets.CpptrajDatasetList - 3 datasets>
>>> # raise if not TrajectoryIterator
>>> traj2 = pt.Trajectory(xyz=traj.xyz, top=traj.top)
>>> not isinstance(traj2, pt.TrajectoryIterator)
True
>>> pt.load_batch(traj2, text)
Traceback (most recent call last):
    ...
ValueError: only support TrajectoryIterator
pytraj.load_pipeline(traj, txt)

perform calculation for traj with cpptraj’s batch style. This is for internal use.

Parameters:

traj : pytraj.TrajectoryIterator

txt : text or a list of test

cpptraj’s commands

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> text = """
... autoimage
... radgyr @CA nomax
... molsurf !@H=
... """
>>> state = pt.load_batch(traj, text)
>>> state = state.run()
>>> state.data
<pytraj.datasets.CpptrajDatasetList - 3 datasets>
>>> # raise if not TrajectoryIterator
>>> traj2 = pt.Trajectory(xyz=traj.xyz, top=traj.top)
>>> not isinstance(traj2, pt.TrajectoryIterator)
True
>>> pt.load_batch(traj2, text)
Traceback (most recent call last):
    ...
ValueError: only support TrajectoryIterator
pytraj.run(fi)

shortcut for for frame in fi: pass

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> fi = pt.pipe(traj, ['autoimage', 'rms', 'center :1-13'])
>>> pt.run(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.select_atoms(mask, topology)

return atom indices

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> atom_indices = pt.select_atoms('@CA', traj.top)
>>> atom_indices
array([  4,  15,  39, ..., 159, 173, 197])
>>> pt.select_atoms(traj.top, '@CA')
array([  4,  15,  39, ..., 159, 173, 197])
pytraj.set_cpptraj_verbose(cm=True)
pytraj.show()

show plot

pytraj.show_versions()
>>> show_versions() 
pytraj.strip(obj, mask)

return a new Trajectory or Topology with given mask.

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> traj.n_atoms
5293
>>> pt.strip(traj, '!@CA').n_atoms
12
>>> pt.strip(traj.top, '!@CA').n_atoms
12
>>> pt.strip('!@CA', traj.top).n_atoms
12
>>> t0 = traj[:3]
>>> pt.strip(t0, '!@CA').n_atoms
12
>>> fi = pt.iterframe(traj, stop=3)
>>> fi = pt.strip(fi, '!@CA')
>>> for frame in fi:
...    print(frame)
<Frame with 12 atoms>
<Frame with 12 atoms>
<Frame with 12 atoms>
>>> # raise ValueError
>>> pt.strip(0, '@CA')
Traceback (most recent call last):
    ...
ValueError: object must be either Trajectory or Topology
pytraj.superpose(traj, *args, **kwd)
>>> import pytraj as pt
>>> traj = pt.datafiles.load_ala3()[:]
>>> traj = pt.superpose(traj)
>>> isinstance(traj, pt.Trajectory)
True