# 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.

from pyscal.trajectory import 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.

traj

Trajectory of 10 slices with 500 atoms


You can also access some basic properties of the trajectories

traj.nblocks

10


traj.nblocks gives the number of time slices in the trajectory. natoms gives the number of atoms.

traj.natoms

500


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[2]
sl

Trajectory slice
2-2
natoms=500


This slice can now be converted to a number of usable formats:
Convert to a pyscal System object.

sys = sl.to_system()
sys

[<pyscal.core.System at 0x7f23e687b6d0>]


System objects contain all the information. The atomic positions, simulation box and so on are easily accessible.

sys[0].box

[[18.22887, 0.0, 0.0], [0.0, 18.234740000000002, 0.0], [0.0, 0.0, 18.37877]]

sys[0].atoms[0].pos

[-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 0x7f23e687bbd0>]

sys[0].atoms[0].custom["vx"]

'-1.21558'


Convert to an ASE atoms object,

aseobj = sl.to_ase(species=["Au"])
aseobj

[Atoms(symbols='Au500', pbc=True, cell=[18.22887, 18.234740000000002, 18.37877])]


It can also be converted to a python dictionary with easily accessible quantities,

adict = sl.to_dict()

dict_keys(['box', 'atoms'])


The atom properties can also be accessed.

adict[0]["atoms"]["x"][0]

-4.9941


Instead of creating a System object, the slice can also be written to a file directly.

sl.to_file("test.dump")


Or can be saved also in a HDF format

sl.to_hdf("test.h5")


If one needs to call any of the above methods on the complete trajectory, you can use the : index. For example,

complete_dict = traj[:].to_dict()


Like normal python lists, multiple slices can also be accessed directly

sl1 = traj[0:4]
sl1

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

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.