rdtools.view.base#

Base viewer functions built on py3Dmol.

rdtools.view.base.animation_viewer(obj: str, model: str = 'xyz', loop: str = 'forward', reps: int = 0, step: int = 1, interval: int = 60, atom_index: bool = False, **kwargs: Any) view#

Create a viewer for molecule animation.

The only viable input the RDMC authors know is a xyz string of multiple molecules.

Parameters:
  • obj (str) – A string representation of molecules in xyz format.

  • model (str, optional) – The model (format) of the molecule representation, e.g., 'xyz'. Defaults to 'xyz'.

  • loop (str, optional) – The direction of looping. Available options are 'forward', 'backward', or 'backAndForth'. Defaults to 'forward'.

  • reps (int, optional) – The number of times the animation is repeated. Defaults to 0, for infinite loop.

  • step (int, optional) – The number of steps between frames. Defaults to 1, showing all the frames,

  • interval (int, optional) – The time interval between each frame in millisecond. Defaults to 60. To slow down the animation, you may want to use a larger number.

  • atom_index (bool, optional) – Whether to show atom index persistently. Defaults to False. Currently, the label is only created based on the first frame, so we suggest turning it off.

  • **kwargs (Any, optional) – Additional arguments for the viewer. E.g., {'viewer_size': (400, 400)}. See base_viewer for more details.

Returns:

py3Dmol.view – The molecule viewer.

rdtools.view.base.base_viewer(obj: str | list[str], model: str = 'xyz', model_extra: dict[str, Any] | None = None, animate: dict[str, Any] | None = None, atom_index: bool = True, style_spec: dict[str, Any] | None = None, viewer: view | None = None, viewer_size: tuple[int, int] = (400, 400), viewer_loc: tuple[int, int] | None = None, as_frames: bool = False) view#

General function to view a molecule.

Powered by py3Dmol and its backend 3Dmol.js. This allows you to visualize molecules in 3D with a javascript object or in IPython notebooks. This function is also used to build up more complicated viewers, e.g., freq_viewer.

Parameters:
  • obj (Union[str, list[str]]) – A string representation of the molecule can be xyz string, sdf string, etc.

  • model (str, optional) – The format of the molecule representation, e.g., 'xyz'. Defaults to 'xyz'.

  • model_extra (Optional[dict[str, Any]], optional) – Extra specs for the model (format). E.g., frequency specs. Default to None

  • animate (Optional[dict[str, Any]], optional) – Specs for animation. E.g., {'loop': 'backAndForth'}.

  • atom_index (bool, optional) – Whether to show atom index persistently. Defaults to True. Otherwise, atom index can be viewed by hovering the mouse onto the atom and stay a while.

  • style_spec (Optional[dict[str, Any]], optional) –

    Style of the shown molecule. The default is showing atom as spheres and bond as rods. The default setting is:

    {'stick': {'radius': 0.05,
            'color': '#f2f2f2'},
    'sphere': {'scale': 0.25},}
    

    which set both bond width/color and atom sizes. For more details, please refer to the original APIs in 3DMol.js.

  • viewer (Optional[py3Dmol.view], optional) – Provide an existing viewer, instead of create a new one.

  • viewer_size (tuple[int, int], optional) – Set the viewer size. Only useful if viewer is not provided. Defaults to (400, 400).

  • viewer_loc (Optional[tuple[int, int]], optional) – The location of the viewer in the grid. E.g., (0, 1). Defaults to None.

  • as_frames (bool, optional) – If add object as frames of an animation. Defaults to False.

Returns:

py3Dmol.view – The molecule viewer.

Raises:

NotImplementedError – If passing multiple objects with model_extra.

rdtools.view.base.grid_viewer(viewer_grid: tuple[int, int], linked: bool = False, viewer_size: tuple[int, int] | None = None) view#

Create a empty grid viewer.

You can then fill in each blank by passing this viewer and viewer_loc to desired viewer functions.

Parameters:
  • viewer_grid (tuple[int, int]) – The layout of the grid, e.g., (1, 4) or (2, 2).

  • linked (bool, optional) – Whether changes in different sub viewers are linked. Defaults to False.

  • viewer_size (Optional[tuple[int, int]], optional) – The size of the viewer in (width, height). By Default, each block is 250 width and 400 height.

Returns:

py3Dmol.view – The empty grid viewer.