View#

Visualizing a molecular system.

Molecular visualization engines allow us to inspect and interact with molecular systems directly in Jupyter notebooks. MolSysMT provides the function molsysmt.basic.view() with MolSysViewer as the default interactive 3D visualization engine, while also supporting third-party viewers such as NGLView.

Added in version 1.0.0.

Basic usage#

Let’s explore how molsysmt.basic.view() visualizes a molecular system (181L) using MolSysViewer as the default visualization engine:

import molsysmt as msm
msm.view('181L')

As with many other MolSysMT functions, molsysmt.basic.view() operates on any supported molecular system form and accepts arguments such as selection or structure_indices:

msm.view('181L', selection='molecule_name=="BENZENE"')

Let’s now see another example using a different molecular system form, and applying a spatial selection constraint:

molsys = msm.convert('181L', selection='molecule_type=="protein" or molecule_name=="BENZENE"', to_form='openmm.Modeller')
msm.view(molsys, selection='all within 7.0 angstroms of molecule_type=="small molecule"')

Working with NGLView#

In addition to MolSysViewer, MolSysMT also supports NGLView as a third-party visualization backend. Specifying viewer='NGLView' returns an nglview.NGLWidget object, which is recognized by MolSysMT as a valid molecular system form:

view = msm.view('181L', viewer='NGLView')

To display the interactive NGLView widget in the notebook, evaluate the view object:

view

As such, nglview.NGLWidget is recognized as a valid form in MolSysMT and can be passed directly to any function that operates on molecular systems:

msm.get_form(view)
'nglview.NGLWidget'
msm.info(view)
form n_atoms n_groups n_components n_chains n_molecules n_entities n_waters n_ions n_small_molecules n_proteins n_structures
nglview.NGLWidget 1441 302 141 6 141 5 136 2 2 1 1
msm.get(view, box=True)
Magnitude
[[[6.089999999999999 0.0 0.0]  [-3.044999999999998 5.274094709047231 0.0]  [5.939536975864663e-16 1.0287579815631596e-15 9.7]]]
Unitsnanometer
msm.get_form(msm.convert(view, to_form='openmm.Modeller'))
'openmm.Modeller'
msm.structure.get_distances(view, selection='atom_index==0', selection_2='atom_index==20')
Magnitude
[[[0.9586227516599015]]]
Unitsnanometer