Endless streaming calculationΒΆ

Note

syntax might be changed in future.

try pytraj online:


In [1]: import pytraj as pt

In [2]: from pytraj.datasets import DatasetList as CpptrajDatasetList

# create pytraj.TrajectoryIterator, no data is actually loaded yet.
In [3]: traj = pt.iterload("tz2.ortho.nc", "tz2.ortho.parm7")

In [4]: traj
Out[4]: 
pytraj.TrajectoryIterator, 10 frames: 
Size: 0.001183 (GB)
<Topology: 5293 atoms, 1704 residues, 1692 mols, PBC with box type = ortho>
           

# create a list of commands (cpptraj's style)
# advantage: endless streaming calculation, even TB of data.
In [5]: commands = ['autoimage',
   ...:             'distance :3 :7',
   ...:             'distance :3 :10',
   ...:             'vector :2 :3',
   ...:             'vector box',
   ...:             'vector ucellx',
   ...:             ]
   ...: 

# create a CpptrajDatasetList object to hold all datasets
In [6]: dslist = CpptrajDatasetList()

In [7]: dslist
Out[7]: <pytraj.datasets.CpptrajDatasetList - 0 datasets>

# create an ActionList object to hold all actions
In [8]: actlist = pt.ActionList(commands, traj.top, dslist=dslist)

# perform the actions, only a single frame is loaded
# data is saved to dslist
In [9]: for frame in traj:
   ...:     actlist.compute(frame)
   ...: dslist
   ...: 
Out[9]: <pytraj.datasets.CpptrajDatasetList - 5 datasets>

# get values for each Dataset
In [10]: for d in dslist: print(d)
<pytraj.datasets.DatasetDouble: size=10, key=Dis_00000> 
values: 
[  9.4844   9.7962   9.3545   9.5726  10.0996   9.6236  10.3602  10.0464
  10.0329   9.4562]
<pytraj.datasets.DatasetDouble: size=10, key=Dis_00001> 
values: 
[ 5.3508  5.3321  5.1586  5.2995  5.5269  5.0924  5.0605  5.2757  4.858
  5.1329]
<pytraj.datasets.DatasetVector: size=10, key=Vec_00002> 
<pytraj.datasets.DatasetVector: size=10, key=Vec_00003> 
<pytraj.datasets.DatasetVector: size=10, key=Vec_00004> 

# get raw data for the last DatsetVector (x values of unitcells ('vector ucellx'))
In [11]: dslist[-1].values
Out[11]: 
array([[ 35.2628,   0.    ,   0.    ],
       [ 35.2563,   0.    ,   0.    ],
       [ 35.2545,   0.    ,   0.    ],
       ..., 
       [ 35.249 ,   0.    ,   0.    ],
       [ 35.2619,   0.    ,   0.    ],
       [ 35.2735,   0.    ,   0.    ]])