API Reference

Module chemview.widget

class RepresentationViewer(self, width=500, height=500)

RepresentationViewer is an IPython notebook widget useful to display 3d scenes through webgl.


from IPython.display import display

rv = RepresentationViewer()
rv.add_representation('point', {'coordinates': coordinates, 'colors': colors, 'sizes': sizes})
add_representation(self, rep_type, options)

Add a 3D representation to the viewer. See User Guide for a complete description of the representations available.

Returns:An unique hexadecimal identifier for the representation.
Return type:str
remove_representation(self, rep_id)

Remove a representation from the viewer

Parameters:rep_id (str) – the unique identifier generated by RepresentationViewer.add_representation
update_representation(self, rep_id, options)

Update a representation with new data.

  • rep_id (str) – the unique identifier returned by RepresentationViewer.add_representation
  • options (dict) – dictionary containing the updated data.
class TrajectoryControls(self, n_frames, fps=30)

Play/Pause controls useful for playing trajectories.


You can connect a callback to be executed every time the frame changes.

from IPython.display import display

controls = TrajectoryControls(10) # 10 frames

def callback(frame):
    print("Current frame %d" % frame)


Current frame


Total number of frames


Frames per second (defaults to 30)

on_frame_change(self, callback)

Connect a callback to be executed every time the frame attribute changes.

Module chemview.viewer

class MolecularViewer(self, coordinates, topology, width=500, height=500)

Create a Molecular Viewer widget to be displayed in IPython notebook.

  • coordinates (np.ndarray) – A numpy array containing the 3D coordinates of the atoms to be displayed
  • topology (dict) – A dict specifying the topology as described in the User Guide.
points(self, size=1.0)

Display the system as points.

Parameters:size (float) – the size of the points.

Display the system bonds as lines.

wireframe(self, pointsize=0.2)

Display atoms as points of size pointsize and bonds as lines.

ball_and_sticks(self, ball_radius=0.05, stick_radius=0.02)

Display the system using a ball and stick representation.


Display the protein secondary structure as a white lines that passes through the backbone chain.


Display the protein secondary structure as a white, solid tube and the alpha-helices as yellow cylinders.

add_isosurface(self, function, isolevel=0.3, resolution=32, style='wireframe', color=16777215)

Add an isosurface to the current scene.

  • function (callable) – A function that takes x, y, z coordinates as input and is broadcastable using numpy. Typically simple functions that involve standard arithmetic operations and functions such as x**2 + y**2 + z**2 or np.exp(x**2 + y**2 + z**2) will work. If not sure, you can first pass the function through numpy.vectorize. Example: mv.add_isosurface(np.vectorize(f))
  • isolevel (float) – The value for which the function should be constant.
  • resolution (int) – The number of grid point to use for the surface. An high value will give better quality but lower performance.
  • style (str) – The surface style, choose between solid, wireframe and transparent.
  • color (int) – The color given as an hexadecimal integer. Example: 0xffffff is white.

Module chemview.trajectory

class TrajectoryViewer(self, coordinate_frames, topology, width=500, height=500)

Display a trajectory in the IPython notebook.

  • coordinate_frames (list) – A list containing the positions of the atoms (as np.ndarray) for each frame.
  • topology (dict) – A dictionary specifying the topology

See also


Module chemview.utils


Encode a numpy array as a base64 encoded string, to be JSON serialized.

Returns:a dictionary containing the fields: - data: the base64 string - type: the array type - shape: the array shape