pyscal Trajectory
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
[1]:
from pyscal import Trajectory
Read in a trajectory.
[2]:
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.
[3]:
traj
[3]:
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!).
[4]:
sl = traj[2]
sl
[4]:
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 System
object,
[5]:
sys = sl.to_system()
sys
[5]:
[<pyscal.core.System at 0x7f81f93971d0>]
System
objects contain all the information. The atomic positions, simulation box and so on are easily accessible.
[6]:
sys[0].box
[6]:
[[18.22887, 0.0, 0.0], [0.0, 18.234740000000002, 0.0], [0.0, 0.0, 18.37877]]
[7]:
sys[0].atoms[0].pos
[7]:
[-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,
[8]:
sys = sl.to_system(customkeys=["vx"])
sys
[8]:
[<pyscal.core.System at 0x7f81f9397530>]
[9]:
sys[0].atoms[0].custom["vx"]
[9]:
'-1.21558'
Instead of creating a System object, the slice can also be written to a file directly.
[10]:
sl.to_file("test.dump")
Like normal python lists, multiple slices can also be accessed directly
[12]:
sl1 = traj[0:4]
sl1
[12]:
Trajectory slice
0-3
natoms=500
to_system
and to_file
methods can be used on this object too.
Multiple slices can be added together
[13]:
sl2 = traj[5:7]
sl2
[13]:
Trajectory slice
5-6
natoms=500
[14]:
slnew = sl1+sl2
slnew
[14]:
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.