Visualization
autogeom builds on py3Dmol for interactive 3D viewing (e.g. in a Jupyter notebook) and on xyzrender for static image and animation output.
Interactive viewing
autogeom.View is a py3Dmol.view subclass with convenience methods for adding Geometry objects and annotations:
from autogeom import Geometry, View
water = Geometry(
symbols=["O", "H", "H"],
coordinates=[[0.0, 0.0, 0.0], [0.0, 0.0, 0.96], [0.93, 0.0, -0.24]],
charge=0,
spin=0,
)
v = View()
v.add_geometry(water, label=True) # label=True adds atom-index labels
v.show()In a notebook, the view renders inline; v.show() (inherited from py3Dmol.view) is only needed outside of that auto-display context.
For a one-off view without constructing a View yourself:
import autogeom
v = autogeom.view(water, label=True)Annotating with vectors
add_xyz_axes draws the standard x/y/z axes (useful for checking orientation after a rotation), and add_vector/add_vectors draw arbitrary arrows, for example an inertial axis or a bond dipole:
v.add_xyz_axes(scale=2.0)
v.add_vector([1.0, 0.0, 0.0], start_coord=[0.0, 0.0, 0.0], color="purple")
v.add_vectors(
[[1, 0, 0], [0, 1, 0]],
colors=["red", "green"],
)direction=True treats the vector as an offset from start_coord rather than an absolute endpoint.
Rendering to files
render_svg and render_gif produce a static or rotating image without needing a browser or notebook, which is useful for scripts, reports, or CI artifacts:
import autogeom
autogeom.render_svg(water, out="water.svg")
autogeom.render_gif(water, out="water.gif", rotation_axis="y")Both accept config (an xyzrender RenderConfig, or "default") and include_h to control whether hydrogens are drawn. out is optional: omit it to get the rendered result back without writing a file; the result also displays inline automatically in a notebook.
render_svg and render_gif need xyzrender, which is only on PyPI. See Installation.
Next steps
- Geometries: build and transform the Geometry you want to view.
- Conversions: make a Geometry from a SMILES or InChI string.