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.
Hint
Visit the section Viewers for an overview of supported visualization backends.
Added in version 1.0.0.
API documentation
Follow this link for a detailed description of the input arguments, raised errors, and returned objects of this function: molsysmt.basic.view().
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')
Tip
All methods defined in the molsysmt.basic module can also be invoked from the main level of the library. Hence, molsysmt.view() is the same function as molsysmt.basic.view().
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]]] |
|---|---|
| Units | nanometer |
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]]] |
|---|---|
| Units | nanometer |
Tip
There are more examples on how MolSysMT works with nglview.NGLWidget objects in the third-party NGLView guide.
See also
Related Tools & References
Viewers: Overview of molecular visualization tools supported by MolSysMT.
Convert: Convert molecular systems between different forms with
molsysmt.basic.convert().View: Visualize a molecular system with
molsysmt.basic.view().Select: Select atoms or elements to visualize specific parts of a system with
molsysmt.basic.select().Get form: Identify the form of a view object with
molsysmt.basic.get_form().Info: Display structural and topological summaries of a molecular system with
molsysmt.basic.info().Get: Retrieve attribute values from a molecular system with
molsysmt.basic.get().