Trajectory is a
pyscal module intended for working with molecular dynamics trajectories which contain more than one time slice. Currently, the module only supports LAMMPS dump text file formats. It can be used to get a single or slices from a trajectory, trim the trajectory or even combine multiple trajectories. The example below illustrates various uses of the module.
``Trajectory`` is an experimental feature at the moment and may undergo significant changes in future releases
Start with importing the module
from pyscal import Trajectory
Read in a trajectory.
traj = Trajectory("traj.light")
When using the above statement, the trajectory is not yet read in to memory. Just the basic information is available now.
Trajectory of 10 slices with 500 atoms
We can know the number of slices in the trajectory and the number of atoms.
Trajectory only works with fixed number of atoms.
Now, one can get a single slice or multiple slices just as is done with a python list. Getting the 2nd slice (counting starts from 0!).
sl = traj sl
Trajectory slice 2-2 natoms=500
This slice can now be converted to a more usable format, either to a pyscal
System or just written to another text file. Convert to a pyscal
sys = sl.to_system() sys
[<pyscal.core.System at 0x7f81f93971d0>]
System objects contain all the information. The atomic positions, simulation box and so on are easily accessible.
[[18.22887, 0.0, 0.0], [0.0, 18.234740000000002, 0.0], [0.0, 0.0, 18.37877]]
[-4.9941, -6.34185, -6.8551]
If information other than positions are required, the
customkeys keyword can be used. For example, for velocity in the x direction,
sys = sl.to_system(customkeys=["vx"]) sys
[<pyscal.core.System at 0x7f81f9397530>]
Instead of creating a System object, the slice can also be written to a file directly.
Like normal python lists, multiple slices can also be accessed directly
sl1 = traj[0:4] sl1
Trajectory slice 0-3 natoms=500
to_file methods can be used on this object too.
Multiple slices can be added together
sl2 = traj[5:7] sl2
Trajectory slice 5-6 natoms=500
slnew = sl1+sl2 slnew
Trajectory slice 0-3/5-6 natoms=500
Once again, one could write the combined trajectory slice to a file, or create a System object out of it.