nanover.nglview.nglclient module

Provides an NGLView python client to connect to a NanoVer server in order to visualise the molecular system from within a Jupyter notebook (or iPython interface).

class nanover.nglview.nglclient.FrameDataStructure(frame, ext='pdb', params={})

Bases: Structure

Subclass of the nglview.Structure class that converts FrameData objects to formatted strings that can be read by NGLView to visualise the molecular system.

Parameters:
  • frame – The FrameData object containing the data from the molecular simulation.

  • ext – The file extension for the structure representation that is passed to NGLView, which defaults to PDB.

  • params – A dictionary of loading parameters that are passed to NGLView (see parent class).

get_structure_string()

A function that overrides the get_structure_string function of the parent class to convert the frame to a PDB formatted string to be read by NGLView.

Returns:

A PDB string of the molecular structure defined in the frame.

class nanover.nglview.nglclient.NGLClient(dynamic_bonds=False, *args, update_callback=None, **kwargs)

Bases: NanoverImdClient

A python client that enables visualisation of the molecular system via an NGLView widget.

Example

from nanover.nglview import NGLClient
client = NGLClient.autoconnect()
client.view
param dynamic_bonds:

A boolean flag that dictates whether bonds should be dynamically updated during the simulation.

param args:

Additional arguments passed to the parent class (NanoverImdClient) constructor.

param update_callback:

An optional callback function executed each time a new frame is received (CURRENTLY UNUSED).

param kwargs:

Additional arguments passed to the parent class (NanoverImdClient) constructor.

property view

Returns an NGLView widget to visualise the molecular system.

nanover.nglview.nglclient.fill_empty_fields(universe: Universe)

Set the PDB-specific fields with their default values.

Some topology fields are specific to PDB files and are often missing from Universes. This function set these fields to their default values if they are not present already.

Parameters:

universe – The MDAnalysis universe describing the current frame.

nanover.nglview.nglclient.frame_data_to_nglwidget(frame, **kwargs)

Function that takes a FrameData object and outputs an NGLView widget for visualisation of the molecular system described by the frame.

Parameters:
  • frame – The FrameData object containing the data from the molecular simulation.

  • *kwargs

    Additional keyword arguments passed to the NGLWidget constructor.

Returns:

An NGLView widget to visualise the molecular system described by the frame.

nanover.nglview.nglclient.frame_data_to_pdb(frame: FrameData) str

Converts a FrameData object to a PDB string, by first reading the frame as an MDAnalysis universe and then converting it to a PDB string.

Parameters:

frame – The FrameData object containing the data from the molecular simulation.

Returns:

A PDB string of the molecular structure defined in the frame.

nanover.nglview.nglclient.mda_to_pdb_str(universe: Universe)

Converts an MDAnalysis Universe to a PDB string.

Parameters:

universe – The MDAnalysis universe describing the current frame.

Returns:

A PDB string of the molecular structure defined in the MDAnalysis universe.