Analysing molecular trajectories

BioSimSpace provides functionality for reading, writing, and analysing a variety of common molecular trajectory formats.

For example, to load an AMBER NetCDF trajectory from file:

import BioSimSpace as BSS

traj = BSS.Trajectory(trajectory="traj.nc", topology="topology.prm7")

While useful, it is more likely that you will want to create a trajectory from a BioSimSpace process.

# Load a molecular system from file.
system = BSS.IO.readMolecules["ala.crd", "ala.top"])

# Create a default production protocol.
protocol = BSS.Protocol.Production()

# Launch a molecular dynamics simulation using the system and protocol.
process = BSS.MD.run(system, protocol)

# Read the latest trajectory file and return a trajectory object.
traj = process.getTrajectory()

Alternatively, you can create the Trajectory object yourself by passing the process as a keyword argument:

traj = BSS.Trajectory(process=process)

The BioSimSpace Trajectory class provides a wrapper around MDTraj and MDAnalysis. To get access to the full power of the excellent libraries you can convert the BioSimSpace object to either format:

# Return a MDTraj object.
mdtraj = traj.getTrajectory()

# Return a MDAnalysis object.
mdanalysis = traj.getTrajectory(format=mdanalysis)

(Note that if you’ve generated the Trajectory object from a process, or attached to one, then the above will read the latest trajectory file and return.)

To see how many frames are in the current trajectory:

traj.nFrames()

To get all of the frames as a list of system objects:

frames = traj.getFrames()

To get specific frames:

# Get the first, second, and third frames.
frames = traj.getFrames([0, 1 ,2])

# Get every other frame.
frames = traj.getFrames([x for x in range(0, trajectory.nFrames(), 2)])

Where supported, trajectories can also be indexed by time stamp. These will be rounded to the nearest frame index. For example:

# Get the frames with time stamps that are closest to 0.1, 0.2, and 0.3 nanoseconds.
frames = traj.getFrames([0.1, 0.2, 0.3])

BioSimSpace also enables simple analysis of trajectory data, such as the calculation of the root mean squared displacement (RMSD).

# Calculate the RMSD of all atoms with reference to the first frame in the trajectory.
rmsd = traj.RMSD()

# Calculate the RSMD of all atoms with reference to the last frame.
rmsd = traj.RMSD(frame=-1)

# Calculate the RMSD with reference to a list of atom indices in the first frame.
rmsd = traj.RMSD(atoms=[0, 1, 2, 3, 4, 5])

# Calculate the RMSD with reference to a specific molecule.
rmsd = traj.RMSD(molecule=0)

With a running process, you can compute the RMSD using the latest trajectory:

rmsd = process.getTrajectory().RMSD(molecule=0)