View#

Showing a molecular system

Molecular visualization libraries such as NGLView allow us to visualize and interact with molecular systems directly in Jupyter notebooks. MolSysMT provides the function molsysmt.basic.view() to simplify this integration in your workflow.

Tip

Visit the section User guide > Introduction > Viewers to know about the supported viewers by this function.

Added in version 1.0.0.

How this function works#

API documentation

Follow this link for a detailed description of the input arguments, raised errors, and returned objects of this function:molsysmt.basic.view().

Let’s explore how molsysmt.basic.view() can be used to visualize a complete system and apply different rendering options:

import molsysmt as msm
msm.view('181L', standard=True, with_water_as='licorice', viewer='NGLView')

Tip

All methods defined in the molsysmt.basic module can be invoked also from the main level of the library. Hence, molsysmt.view() is the same method as molsysmt.basic.view().

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

msm.view('181L', selection='molecule_name=="BENZENE"', standard=True, viewer='NGLView')

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

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

Working with NGLView#

At this moment MolSysMT works only with a single molecular visualization library: NGLView. In fact, an nglview.NGLWidget python object is recognized by MolSysMT as the form of a molecular system.

view = msm.view('181L')
msm.get_form(view)
'nglview.NGLWidget'

As such, nglview.NGLWidget is recognized as a valid form in MolSysMT, and can be passed to any function that operates on molecular systems. Let’s see some examples:

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 1 141 5 136 2 2 1 1
msm.get(view, box=True)
Magnitude
[[[6.089999999999999 0.0 0.0]  [-3.0449999999999995 5.274094699999999 0.0]  [0.0 0.0 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.9586227516599012]]]
Unitsnanometer

Tip

There are more examples on how MolSysMT can work with nglview.NGLWidget objects in the section User guide > Showcase > Working with NGLView.

Additionally, MolSysMT includes a module with auxiliary functions to work with NGLView in the section User guide > Tools > Thirds > NGLView.

See also

User guide > Introduction > Viewers:
Overview of molecular visualization tools supported by MolSysMT.

User guide > Showcase > Working with NGLView:
Examples of how to use MolSysMT with NGLView objects.

User guide > Tools > Basic > Select:
Select atoms or elements to visualize specific parts of a system.

User guide > Tools > Basic > Info:
Display topological and structural summaries of a molecular system.

User guide > Tools > Basic > Get:
Retrieve attribute values from a molecular system.

User guide > Tools > Thirds > NGLView:
Auxiliary functions to extend NGLView usage in MolSysMT.