pytraj.ActionList

class pytraj.c_action.actionlist.ActionList(commands=None, Topology top=None, DatasetList dslist=<???>, DataFileList dflist=<???>, crdinfo={})

Bases: object

Attributes

data Store data (CpptrajDatasetList).
n_frames n_frames: ‘unsigned int’

Methods

add(self[, action, command, top, check_status]) Add action to ActionList
check_topology(self, Topology top[, ...]) perform Topology checking and some stuff
compute(self[, traj]) perform a series of Actions on Frame or Trajectory
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

return status of Action (0 or 1) if “True”

Examples

>>> actlist = ActionList()
>>> actlist.add('radgyr', '@CA', top=traj.top, dslist=dslist) 
check_topology(self, Topology top, crdinfo={}, n_frames_t=0, bool exit_on_error=True)

perform Topology checking and some stuff

compute(self, traj=<???>)

perform a series of Actions on Frame or Trajectory

data

Store data (CpptrajDatasetList). This is for internal use.

n_frames

n_frames: ‘unsigned int’

pytraj.c_action.actionlist.do(lines, traj, *args, **kwd)

perorm a series of cpptraj’s actions on trajectory

Parameters:

lines : {str, list of string}

traj : Trajectory-like

process : {None, int}, default None

if not None, there will have progess bar if user is using jupyter notebook. The value of progess shows how often the bar is displayed. Make sure to choose large progess number to avoid slowing down your calculation.

*args, **kwd : more arguments

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> # cpptraj command style
>>> data = pt.do('''
...              rms
...              radgyr
...              molsurf
...              ''', traj)
>>> # a list of commands
>>> data = pt.do([
...              'rms',
...              'radgyr',
...              'molsurf',], traj)
>>> # a list of commands with reference
>>> # need to explicitly add ``reference`` keyword and specify `ref=`
>>> # calculate rms and use traj[3] as reference
>>> data = pt.do([
...              'rms myrms reference @CA',
...              'radgyr myrg @CA nomax',
...              'molsurf',], traj, ref=traj[3])
>>> data['myrms']
array([ 3.46476336,  3.4343108 ,  2.94523273, ...,  4.21848857,
        4.4566457 ,  3.94477017])
>>> data['myrms'][3]
0.0
>>> # a list of commands with reference
>>> # can also specify 'refindex'
>>> # calculate rms and use traj[3] as reference
>>> data = pt.do([
...              'rms myrms refindex 0 @CA',
...              'radgyr myrg @CA nomax',
...              'molsurf',], traj, ref=traj[3])
>>> data['myrms']
array([ 3.46476336,  3.4343108 ,  2.94523273, ...,  4.21848857,
        4.4566457 ,  3.94477017])
>>> data['myrms'][3]
0.0
pytraj.c_action.actionlist.pipe(traj, commands, DatasetList dslist=<???>, frame_indices=None)

create frame iterator from cpptraj’s commands.

This method is useful if you want cpptraj pre-processing your Trajectory before throwing it to your own method.

Parameters:

commands : a list of strings of cpptraj’s Action commands

traj : Trajectory or any iterable that produces Frame

dslist : CpptrajDatasetList, optional

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2_ortho()
>>> for frame in pt.pipe(traj, ['autoimage', 'rms', 'center :1']): pass

Above example is similiar to cpptraj’s command:

cpptraj -i EOF<<
parm tz2.ortho.parm
trajin tz2.ortho.nc
autoimage
rms
center :1
EOF

You can design your own method:

def new_method(traj, ...):
    for frame in traj:
        do_some_thing_fun_with(frame)

fi = pt.pipe(traj, ['autoimage', 'rms', 'center :1'])

# perform action with pre-processed frames (already autoimaged, then rms fit to
# 1st frame, then center at box center.
data = new_method(fi, ...)