Interactive molecular visualisation

Another useful interactive tool provided by BioSimSpace is the View class. This is a wrapper around the excellent NGLView to allow easy visualisation of molecular systems. When creating a View object you can either directly pass a molecular system, or alternatively pass a Process object to allow you to dynamically visualise the latest molecular system as the process runs.

To create a view from a molecular system:

import BioSimSpace as BSS

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

# Initialise a view object using the molecular system.
view = BSS.NoteBook.View(system)

To attach to a process:

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

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

# Create a new view, attaching to the running process.
view = BSS.Notebook.View(process)

Once the view is created, you can visualise the molecular system by running:

view.system()

or

view.molecules()

To view a subset of the molecules in the system, pass a list of molecule indices:

# View molecules 0, 5, and 10.
view.molecules([0, 5, 10])

To just view a single molecule:

# Only show molecule 3.
view.molecule(3)

Each new view you generate is saved. To see how many views there are, run:

view.nViews()

If you want to reload a specific view, run:

# Reload view number 2 (the third that was generated).
view.reload(2)

To save a PDB file for a specific view, run:

view.savePDB("my-view.pdb", index=6)

By default, a graphical user interface (GUI) is displayed for each view. To disable this, set the gui keyword argument to False, e.g.:

view.system(gui=False)