pymatgen.vis.structure_vtk module

This module contains classes to wrap Python VTK to make nice molecular plots.

class MultiStructuresInteractorStyle(parent)[source]

Bases: pymatgen.vis.structure_vtk.StructureInteractorStyle

keyPressEvent(obj, event)[source]
class MultiStructuresVis(element_color_mapping=None, show_unit_cell=True, show_bonds=False, show_polyhedron=False, poly_radii_tol_factor=0.5, excluded_bonding_elements=None, animated_movie_options={'looping_type': 'restart', 'number_of_loops': 1, 'time_between_frames': 0.1, 'time_between_loops': 1.0})[source]

Bases: pymatgen.vis.structure_vtk.StructureVis

Constructs a Structure Visualization.

Parameters
  • element_color_mapping – Optional color mapping for the elements, as a dict of {symbol: rgb tuple}. For example, {“Fe”: (255, 123,0), ….} If None is specified, a default based on Jmol”s color scheme is used.

  • show_unit_cell – Set to False to not show the unit cell boundaries. Defaults to True.

  • show_bonds – Set to True to show bonds. Defaults to True.

  • show_polyhedron – Set to True to show polyhedrons. Defaults to False.

  • poly_radii_tol_factor – The polyhedron and bonding code uses the ionic radii of the elements or species to determine if two atoms are bonded. This specifies a tolerance scaling factor such that atoms which are (1 + poly_radii_tol_factor) * sum of ionic radii apart are still considered as bonded.

  • excluded_bonding_elements – List of atom types to exclude from bonding determination. Defaults to an empty list. Useful when trying to visualize a certain atom type in the framework (e.g., Li in a Li-ion battery cathode material).

Useful keyboard shortcuts implemented.

h : Show help A/a : Increase/decrease cell by one unit vector in a-direction B/b : Increase/decrease cell by one unit vector in b-direction C/c : Increase/decrease cell by one unit vector in c-direction # : Toggle showing of polyhedrons - : Toggle showing of bonds [ : Decrease poly_radii_tol_factor by 0.05 ] : Increase poly_radii_tol_factor by 0.05 r : Reset camera direction o : Orthogonalize structure Up/Down : Rotate view along Up direction by 90 clock/anticlockwise Left/right : Rotate view along camera direction by 90 clock/anticlockwise

DEFAULT_ANIMATED_MOVIE_OPTIONS = {'looping_type': 'restart', 'number_of_loops': 1, 'time_between_frames': 0.1, 'time_between_loops': 1.0}
apply_tags()[source]
display_help()[source]

Display the help for various keyboard shortcuts.

display_info(info)[source]
display_warning(warning)[source]
erase_info()[source]
erase_warning()[source]
set_animated_movie_options(animated_movie_options=None)[source]
set_structure(structure, reset_camera=True, to_unit_cell=False)[source]

Add a structure to the visualizer.

Parameters
  • structure – structure to visualize

  • reset_camera – Set to True to reset the camera to a default determined based on the structure.

  • to_unit_cell – Whether or not to fall back sites into the unit cell.

set_structures(structures, tags=None)[source]
class StructureInteractorStyle(parent)[source]

Bases: object

A custom interactor style for visualizing structures.

keyPressEvent(obj, event)[source]
leftButtonPressEvent(obj, event)[source]
leftButtonReleaseEvent(obj, event)[source]
mouseMoveEvent(obj, event)[source]
class StructureVis(element_color_mapping=None, show_unit_cell=True, show_bonds=False, show_polyhedron=True, poly_radii_tol_factor=0.5, excluded_bonding_elements=None)[source]

Bases: object

Provides Structure object visualization using VTK.

Constructs a Structure Visualization.

Parameters
  • element_color_mapping – Optional color mapping for the elements, as a dict of {symbol: rgb tuple}. For example, {“Fe”: (255, 123,0), ….} If None is specified, a default based on Jmol”s color scheme is used.

  • show_unit_cell – Set to False to not show the unit cell boundaries. Defaults to True.

  • show_bonds – Set to True to show bonds. Defaults to True.

  • show_polyhedron – Set to True to show polyhedrons. Defaults to False.

  • poly_radii_tol_factor – The polyhedron and bonding code uses the ionic radii of the elements or species to determine if two atoms are bonded. This specifies a tolerance scaling factor such that atoms which are (1 + poly_radii_tol_factor) * sum of ionic radii apart are still considered as bonded.

  • excluded_bonding_elements – List of atom types to exclude from bonding determination. Defaults to an empty list. Useful when trying to visualize a certain atom type in the framework (e.g., Li in a Li-ion battery cathode material).

Useful keyboard shortcuts implemented.

h : Show help A/a : Increase/decrease cell by one unit vector in a-direction B/b : Increase/decrease cell by one unit vector in b-direction C/c : Increase/decrease cell by one unit vector in c-direction # : Toggle showing of polyhedrons - : Toggle showing of bonds [ : Decrease poly_radii_tol_factor by 0.05 ] : Increase poly_radii_tol_factor by 0.05 r : Reset camera direction o : Orthogonalize structure Up/Down : Rotate view along Up direction by 90 clock/anticlockwise Left/right : Rotate view along camera direction by 90 clock/anticlockwise

add_bonds(neighbors, center, color=None, opacity=None, radius=0.1)[source]

Adds bonds for a site.

Parameters
  • neighbors – Neighbors of the site.

  • center – The site in the center for all bonds.

  • color – Color of the tubes representing the bonds

  • opacity – Opacity of the tubes representing the bonds

  • radius – Radius of tube s representing the bonds

add_edges(edges, type='line', linewidth=2, color=[0.0, 0.0, 0.0])[source]
add_faces(faces, color, opacity=0.35)[source]
add_line(start, end, color=(0.5, 0.5, 0.5), width=1)[source]

Adds a line.

Parameters
  • start – Starting coordinates for line.

  • end – Ending coordinates for line.

  • color – Color for text as RGB. Defaults to grey.

  • width – Width of line. Defaults to 1.

add_partial_sphere(coords, radius, color, start=0, end=360, opacity=1.0)[source]
add_picker()[source]
add_picker_fixed()[source]
add_polyhedron(neighbors, center, color, opacity=1.0, draw_edges=False, edges_color=[0.0, 0.0, 0.0], edges_linewidth=2)[source]

Adds a polyhedron.

Parameters
  • neighbors – Neighbors of the polyhedron (the vertices).

  • center – The atom in the center of the polyhedron.

  • color – Color for text as RGB.

  • opacity – Opacity of the polyhedron

  • draw_edges – If set to True, the a line will be drawn at each edge

  • edges_color – Color of the line for the edges

  • edges_linewidth – Width of the line drawn for the edges

add_site(site)[source]

Add a site to the render window. The site is displayed as a sphere, the color of which is determined based on the element. Partially occupied sites are displayed as a single element color, though the site info still shows the partial occupancy.

Parameters

site – Site to add.

add_text(coords, text, color=(0, 0, 0))[source]

Add text at a coordinate.

Parameters
  • coords – Coordinates to add text at.

  • text – Text to place.

  • color – Color for text as RGB. Defaults to black.

add_triangle(neighbors, color, center=None, opacity=0.4, draw_edges=False, edges_color=[0.0, 0.0, 0.0], edges_linewidth=2)[source]

Adds a triangular surface between three atoms.

Parameters
  • atoms – Atoms between which a triangle will be drawn.

  • color – Color for triangle as RGB.

  • center – The “central atom” of the triangle

  • opacity – opacity of the triangle

  • draw_edges – If set to True, the a line will be drawn at each edge

  • edges_color – Color of the line for the edges

  • edges_linewidth – Width of the line drawn for the edges

display_help()[source]

Display the help for various keyboard shortcuts.

orthongonalize_structure()[source]
redraw(reset_camera=False)[source]

Redraw the render window.

Parameters

reset_camera – Set to True to reset the camera to a pre-determined default for each structure. Defaults to False.

rotate_view(axis_ind=0, angle=0)[source]

Rotate the camera view.

Parameters
  • axis_ind – Index of axis to rotate. Defaults to 0, i.e., a-axis.

  • angle – Angle to rotate by. Defaults to 0.

set_structure(structure, reset_camera=True, to_unit_cell=True)[source]

Add a structure to the visualizer.

Parameters
  • structure – structure to visualize

  • reset_camera – Set to True to reset the camera to a default determined based on the structure.

  • to_unit_cell – Whether or not to fall back sites into the unit cell.

show()[source]

Display the visualizer.

write_image(filename='image.png', magnification=1, image_format='png')[source]

Save render window to an image.

Parameters
  • filename – filename to save to. Defaults to image.png.

  • magnification – magnification. Use it to render high res images.

  • image_format – choose between jpeg, png. Png is the default.

zoom(factor)[source]

Zoom the camera view by a factor.

make_movie(structures, output_filename='movie.mp4', zoom=1.0, fps=20, bitrate='10000k', quality=1, **kwargs)[source]

Generate a movie from a sequence of structures using vtk and ffmpeg.

Parameters
  • structures ([Structure]) – sequence of structures

  • output_filename (str) – filename for structure output. defaults to movie.mp4

  • zoom (float) – A zoom to be applied to the visualizer. Defaults to 1.0.

  • fps (int) – Frames per second for the movie. Defaults to 20.

  • bitrate (str) – Video bitate. Defaults to “10000k” (fairly high quality).

  • quality (int) – A quality scale. Defaults to 1.

  • **kwargs – Any kwargs supported by StructureVis to modify the images generated.