molsysmt.basic.view#
- molsysmt.basic.view(molecular_system=None, selection='all', structure_indices='all', viewer='MolSysViewer', syntax='MolSysMT', skip_digestion=False)[source]#
Visualizing a molecular system.
This function displays a molecular system using an external interactive 3D visualization library inside a Jupyter notebook. The visualization backend can be selected by the viewer argument.
- Parameters:
molecular_system (molecular system, optional) – Molecular system to be displayed. It can be in any of the supported forms. If None, an empty viewer is returned.
selection (str, tuple, list or numpy.ndarray, default='all') – Selection of atoms to be shown. It can be a list/array of 0-based indices, or a query string using one of the supported selection syntaxes. The default ‘all’ includes all atoms in the system.
structure_indices (int, tuple, list, numpy.ndarray or 'all', default='all') – 0-based indices of structures to be shown. The default ‘all’ includes all structures.
viewer ({'MolSysViewer', 'NGLView'}, default='MolSysViewer') – Viewer backend to use for visualization. ‘MolSysViewer’ is the default backend in MolSysMT. ‘NGLView’ is supported when the optional nglview dependency is installed.
syntax (str, default='MolSysMT') – Syntax used to interpret the selection string. See Selection syntaxes for details.
skip_digestion (bool, default=False) –
Whether to skip MolSysMT’s internal argument digestion mechanism.
MolSysMT includes a built-in digestion system that validates and normalizes function arguments. This process checks types, shapes, and values, and automatically adjusts them when possible to meet expected formats.
Setting skip_digestion=True disables this process, which may improve performance in workflows where inputs are already validated. Use with caution: only set this to True if you are certain all input arguments are correct and consistent.
- Returns:
Visualization widget returned by the selected viewer. For ‘MolSysViewer’, this is a molsysviewer.MolSysView instance. For ‘NGLView’, this is an nglview.NGLWidget instance.
- Return type:
object
- Raises:
NotSupportedFormError – If the molecular system is provided in an unsupported form.
ArgumentError – If one or more input arguments are invalid, including a malformed selection or an out-of-range element or structure index.
ModuleNotFoundError – If the requested viewer backend is not available in the current environment.
Notes
Supported molecular-system forms are described in Items and Forms.
Selection syntaxes and valid query expressions are described in Selection syntaxes.
Selections and structure indices are validated before the viewer backend is created.
See also
molsysmt.basic.select()Selecting atoms or elements from a molecular system.
Examples
The following example illustrates how to visualize only the protein component of a molecular system:
>>> import molsysmt as msm >>> molecular_system = msm.systems['T4 lysozyme L99A']['181l.h5msm'] >>> msm.basic.view(molecular_system, selection='molecule_type=="protein"') <molsysviewer.viewer.MolSysView object at 0x...>
Select an alternative backend (requires nglview):
>>> msm.basic.view(molecular_system, selection='molecule_type=="protein"', viewer='NGLView') NGLWidget()
Tutorial with more examples
See the following tutorial for a practical demonstration of how to use this function, along with additional examples: View
Added in version 1.0.0.