# pymatgen.core.trajectory module¶

class Trajectory(lattice, species, frac_coords, time_step=2, site_properties=None, constant_lattice=True, coords_are_displacement=False, base_positions=None)[source]

Bases: monty.json.MSONable

Trajectory object that stores structural information related to a MD simulation. Provides basic functions such as slicing trajectory or obtaining displacements.

Create a trajectory object

Parameters
• lattice – The lattice as any 2D array. Each row should correspond to a lattice vector. E.g., [[10,0,0], [20,10,0], [0,0,30]] specifies a lattice with lattice vectors [10,0,0], [20,10,0] and [0,0,30].

• species

List of species on each site. Can take in flexible input, including:

1. A sequence of element / specie specified either as string symbols, e.g. [“Li”, “Fe2+”, “P”, …] or atomic numbers, e.g., (3, 56, …) or actual Element or Specie objects.

2. List of dict of elements/species and occupancies, e.g., [{“Fe” : 0.5, “Mn”:0.5}, …]. This allows the setup of disordered structures.

• frac_coords (MxNx3 array) – list of fractional coordinates of each species

• time_step (int, float) – Timestep of simulation in femtoseconds. Defaults to 2fs.

• site_properties (list) – Properties associated with the sites as a list of dicts of sequences, e.g., [{“magmom”:[5,5,5,5]}, {“magmom”:[5,5,5,5]}]. The sequences have to be the same length as the atomic species and fractional_coords. Number of supplied dicts should match number of frames in trajectory Defaults to None for no properties.

• constant_lattice (bool) – Whether the lattice changes during the simulation, such as in an NPT MD simulation.

• coords_are_displacement (bool) – Whether supplied coordinates are given in displacements (True) or positions (False)

• base_positions (Nx3 array) – The starting positions of all atoms in trajectory. Used to reconstruct positions when converting from displacements to positions. Only needs to be specified if coords_are_displacement=True. Defaults to first index of frac_coords if coords_are_displacement=False.

as_dict()[source]

A JSON serializable dict representation of an object.

copy()[source]
extend(trajectory)[source]

Concatenate another trajectory

Parameters

trajectory (Trajectory) – Trajectory to add

classmethod from_file(filename, constant_lattice=True, **kwargs)[source]

Convenience constructor to obtain trajectory from XDATCAR or vasprun.xml file

Parameters
• filename (str) – The filename to read from.

• constant_lattice (bool) – Whether the lattice changes during the simulation, such as in an NPT MD simulation. True results in

Returns

(Trajectory)

classmethod from_structures(structures, constant_lattice=True, **kwargs)[source]

Convenience constructor to obtain trajectory from a list of structures. Note: Assumes no atoms removed during simulation

Parameters
• structures (list) – list of pymatgen Structure objects.

• constant_lattice (bool) – Whether the lattice changes during the simulation, such as in an NPT MD simulation. True results in

Returns

(Trajectory)

get_structure(i)[source]

Returns structure at specified index :param i: Index of structure :type i: int

Returns

(Structure) pymatgen structure object

to_displacements()[source]

Converts position coordinates of trajectory into displacements between consecutive frames

to_positions()[source]

Converts fractional coordinates of trajectory into positions