# chemlab.mviewer.api¶

Those are the default commands included in the chemlab molecular viewer.

## Basic Commands¶

Those commands are used to retrieve the basic objects that are currently displayed.

Basic functions to retrieve information on what’s currently displayed in the molecular viewer.

chemlab.mviewer.api.core.current_frame()

Return the integer corresponding to the current frame in the trajectory.

chemlab.mviewer.api.core.current_frame_times()

Return the list of times associated with the current trajectory.

chemlab.mviewer.api.core.current_nframes()

Return the number of frames in the current trajectory.

chemlab.mviewer.api.core.current_representation()

Return the current Representation instance. Representations are a way to interact with the displayed chemical data.

chemlab.mviewer.api.core.current_system()

The chemlab.core.System that is currently being displayed.

chemlab.mviewer.api.core.current_time()

Return the floating point number corresponding to the current time in the trajectory (in ns).

chemlab.mviewer.api.core.current_trajectory()

Return the current trajectory. A trajectory is a set of frames.

chemlab.mviewer.api.core.frames(skip=1)

Useful command to iterate on the trajectory frames. It can be used in a for loop.

for i in frames():
coords = current_trajectory()[i]
# Do operation on coords


You can use the option skip to take every i th frame.

chemlab.mviewer.api.core.msg = <chemlab.mviewer.api.core._Msg object>

Update the message in the status bar

chemlab.mviewer.api.core.trajectory(start=None, stop=None, step=None)

Useful command to iterate on the trajectory frames by time (in ns). It is meant to be used in a for loop:

for i in trajectory(0, 10, 0.1):
coords = current_frame()
t = current_time()
# Do something


The previous snippet will stop at every frame from 0 to 10 ns with a step of 0.1 ns.

Those commands are used to load, write, display or download structures from files or any other source.

chemlab.mviewer.api.display.autozoom()

Find optimal camera zoom level for the current view.

chemlab.mviewer.api.display.autozoom_()

Find optimal camera zoom level for the current view.

chemlab.mviewer.api.display.display_molecule(mol, autozoom=True)

Display a ~chemlab.core.Molecule instance in the viewer.

This function wraps the molecule in a system before displaying it.

chemlab.mviewer.api.display.display_system(system, autozoom=True)

Display a ~chemlab.core.System instance at screen

chemlab.mviewer.api.display.download_molecule(name)

chemlab.mviewer.api.display.goto_frame(frame)

Go to a specific frame in the current trajectory.

chemlab.mviewer.api.display.goto_time(timeval)

Go to a specific time (in nanoseconds) in the current trajectory.

chemlab.mviewer.api.display.guess_bonds()

Guess the bonds in the current system

chemlab.mviewer.api.display.load_molecule(name, format=None)

Read a ~chemlab.core.Molecule from a file.

chemlab.io.datafile

chemlab.mviewer.api.display.load_remote_molecule(url, format=None)

Load a molecule from the remote location specified by url.

Example

load_remote_molecule('https://raw.github.com/chemlab/chemlab-testdata/master/benzene.mol')

chemlab.mviewer.api.display.load_remote_system(url, format=None)

Load a system from the remote location specified by url.

Example

load_remote_system('https://raw.github.com/chemlab/chemlab-testdata/master/naclwater.gro')

chemlab.mviewer.api.display.load_remote_trajectory(url, format=None)

Load a trajectory file from a remote location specified by url.

chemlab.mviewer.api.display.load_system(name, format=None)

Read a ~chemlab.core.System from a file.

chemlab.io.datafile

chemlab.mviewer.api.display.load_trajectory(name, skip=1, format=None)

chemlab.mviewer.api.display.reload_system()

Reload the current system in the viewer.

chemlab.mviewer.api.display.write_molecule(filename, format=None)

Write the system displayed in a file as a molecule.

chemlab.mviewer.api.display.write_system(filename, format=None)

Write the system currently displayed to a file.

## Selection Commands¶

Those commands are for selecting objects in the molecular viewer before performing operations on them.

chemlab.mviewer.api.selections.cancel_selection()

Reset the current selection

chemlab.mviewer.api.selections.clear_selection()

Clear the current selection.

chemlab.mviewer.api.selections.hide_selected()

Hide the selected objects.

chemlab.mviewer.api.selections.hide_water()

Conveniency command to hide water molecules.

chemlab.mviewer.api.selections.invert_selection()

Invert the current selection. Select the currently unselected atoms.

chemlab.mviewer.api.selections.select_all()

Select all the visible atoms.

chemlab.mviewer.api.selections.select_atom_type(name)

Select atoms by their type.

You can select all the hydrogen atoms as follows:

select_atom_type('H')

chemlab.mviewer.api.selections.select_atoms(indices)

Select atoms by their indices.

You can select the first 3 atoms as follows:

select_atoms([0, 1, 2])


Return the current selection dictionary.

chemlab.mviewer.api.selections.select_connected_bonds()

Select the bonds connected to the currently selected atoms.

chemlab.mviewer.api.selections.select_molecules(name)

Select all the molecules corresponding to the formulas.

chemlab.mviewer.api.selections.select_selection(selection)

Select a Selection object

chemlab.mviewer.api.selections.selected_atoms()

The indices of the currently selected atoms.

chemlab.mviewer.api.selections.unhide_all()

Unhide all the objects

chemlab.mviewer.api.selections.unhide_selected()

Unhide the selected objects

chemlab.mviewer.api.selections.visible_atoms()

Return the indices of the currently visible atoms.

chemlab.mviewer.api.selections.visible_to_original(visible_index)

Transform the indexes of the visible atoms to the indexes of the total atoms.

## Appeareance Commands¶

Those commands are for changing the appeareance of the object displayed by the molecular viewer.

chemlab.mviewer.api.appeareance.add_post_processing(effect, **options)

Apply a post processing effect.

Parameters

effect: string
The effect to be applied, choose between ssao, outline, fxaa, gamma.
**options:
Options used to initialize the effect, check the List of Post Processing Effects for a complete reference of all the options.

Returns

A string identifier that can be used to reference the applied effect.

chemlab.mviewer.api.appeareance.change_background(color)

Setup the background color to color.

Example:

change_background('black')
change_background('white')
change_background('#ffffff')


You can call this function interactively by using:

change_color.interactive()


A new dialog will popup with a color chooser.

chemlab.graphics.colors.parse_color()

chemlab.mviewer.api.appeareance.change_color(color)

Change the color of the currently selected objects. color is represented as a string. Otherwise color can be passed as an rgba tuple of values between 0, 255

Reset the color by passing color=None.

You can call this function interactively by using:

change_color.interactive()


A new dialog will popup with a color chooser.

chemlab.mviewer.api.appeareance.change_default_radii(def_map)

chemlab.mviewer.api.appeareance.change_post_processing_options(str_id, **options)

Change the options of the post processing effect referred by its string id.

chemlab.mviewer.api.appeareance.change_radius(value)

Change the radius of the currently selected atoms by a certain value.

If value is None, set the radius to the default value.

chemlab.mviewer.api.appeareance.clear_post_processing()

Remove all post processing effects.

chemlab.mviewer.api.appeareance.list_post_processing()

List all the post processing effects by name.

chemlab.mviewer.api.appeareance.remove_post_processing(str_id)

Remove a post processing effect by passing its string id provided by add_post_processing().

chemlab.mviewer.api.appeareance.scale_atoms(fac)

Scale the currently selected atoms atoms by a certain factor fac.

Use the value fac=1.0 to reset the scale.

chemlab.mviewer.api.appeareance.screenshot(filename, width=None, height=None)

Make a screenshot of the current view. You can tweak the resolution up to what your GPU memory supports.

By defaults it uses the current window resolution.

Example:

screenshot('screen.png', 1200, 1200)