---
name: autogeom
description: >
  Use when writing Python code that uses the autogeom package.
license: MIT
compatibility: Requires Python >= 3.13.
---

# autogeom

## Installation

```bash
pip install autogeom
```

## API overview

### Geometry

The model at the center of the package, and selecting or combining its atoms

- `Geometry`: Molecular geometry
- `select_atoms`: Select a subset of atoms
- `remove_atoms`: Remove a subset of atoms
- `join`: Join geometries into one

### Geometry Methods

Methods for the Geometry class

- `Geometry.__eq__`
- `Geometry.__repr__`
- `Geometry.atom_count`
- `Geometry.masses`
- `Geometry.atomic_numbers`
- `Geometry.covalent_radii`
- `Geometry.valences`
- `Geometry.xyz_block`
- `Geometry.xyz_file`
- `Geometry.from_xyz_block`
- `Geometry.from_xyz_file`
- `Geometry.relabel_atoms`

### XYZ files

Reading and writing single- and multi-frame xyz

- `xyz_block`: Format a geometry as an xyz block
- `from_xyz_block`: Parse a geometry from a single-frame xyz block
- `xyz_file`: Write a geometry to an xyz file
- `from_xyz_file`: Read a geometry from an xyz file (see `from_xyz_block`)
- `xyz_trajectory_block`: Format geometries as a multi-frame xyz block, one frame per geometry
- `from_xyz_trajectory_block`: Parse geometries from a multi-frame xyz block, e.g. a list of conformers
- `xyz_trajectory_file`: Write geometries to a multi-frame xyz file (see `xyz_trajectory_block`)
- `from_xyz_trajectory_file`: Read geometries from a multi-frame xyz file (see `from_xyz_trajectory_block`)
- `xyz_trajectory_comments`: Get the comment line of each frame of a multi-frame xyz block

### Properties and measurements

Quantities computed from the coordinates

- `center_of_mass`: Calculate the center of mass
- `inertia_tensor`: Calculate the inertia tensor about the center of mass
- `principal_axes`: Calculate the principal moments and axes of inertia
- `distance_matrix`: Calculate the interatomic distance matrix
- `adjacency_matrix`: Determine connectivity from covalent radii
- `distance_keys`: Build a sorted distance descriptor
- `distance`: Measure the distance between two atoms
- `angle`: Measure the angle between three atoms
- `dihedral`: Measure the dihedral angle between four atoms
- `bonds`: List bond distances
- `angles`: List bond angles
- `dihedrals`: List dihedral angles

### Transformations

Moving atoms, and the rotations that align geometries

- `translate`: Translate a geometry
- `rotate`: Rotate a geometry about a point
- `reflect`: Reflect a geometry across a plane
- `center`: Translate a geometry so that its center of mass is at the origin
- `twist`: Rotate a group about a bond, e.g. a methyl or amine group
- `twist_angle`: Find the twist about a bond that turns one direction onto another
- `alignment_rotation`: Find the rotation that best aligns a reference geometry onto a geometry
- `axis_alignment_rotation`: Find the smallest rotation pointing the vector between two atoms along an axis
- `inertial_frame_rotation`: Find the rotation into the principal axis frame

### Conversions

InChI, SMILES, formulas, and RDKit molecules

- `inchi`: Generate the standard InChI string of a geometry with RDKit
- `from_inchi`: Embed a geometry for an InChI string with RDKit
- `smiles`: Generate the canonical SMILES string of a geometry with RDKit
- `from_smiles`: Embed a geometry for a SMILES string with RDKit
- `formula`: Generate the molecular formula of a geometry in Hill order
- `rdkit_mol`: Convert a geometry to an RDKit molecule
- `from_rdkit_mol`: Convert an RDKit molecule to a geometry, embedding coordinates if missing

### Visualization

Interactive views and rendered images

- `View`: A `py3Dmol.view` with helpers for geometries and arrows
- `view`: Display a geometry with py3Dmol
- `render_svg`: Render a geometry as an SVG image with xyzrender
- `render_gif`: Render a geometry rotating about an axis as a GIF with xyzrender

### Exceptions and units

Errors raised by the package, and its unit registry

- `GeometryConversionError`: A geometry could not be converted to or from another representation
- `XYZFormatError`: An xyz block could not be parsed
- `ElementNotFoundError`: No element matches the given atomic number or symbol
- `ureg`: The unit registry stores the definitions and relationships between units

### RDKit molecules

`autogeom.rd`: functions on RDKit `Mol` objects, which never see a `Geometry`

- `rd.from_smiles`
- `rd.smiles`
- `rd.from_inchi`
- `rd.inchi`
- `rd.from_xyz_block`
- `rd.xyz_block`
- `rd.symbols`
- `rd.coordinates`
- `rd.charge`
- `rd.spin`
- `rd.has_coordinates`
- `rd.set_coordinates`
- `rd.add_coordinates`
- `rd.add_atom_numbers`
- `rd.canonical_ranks`
- `rd.assign_stereochemistry`
- `rd.chiral_centers`
- `rd.max_bond_count`
- `rd.from_connectivity`
- `rd.EMBED_SEED`

### Elements

`autogeom.element`: periodic table data, looked up by atomic number or symbol

- `element.Element`
- `element.from_key`
- `element.number`
- `element.mass_number`
- `element.symbol`
- `element.mass`
- `element.covalent_radius`
- `element.group`
- `element.period`
- `element.electronegativity`
- `element.is_metal`
- `element.shell_capacity`
- `element.valence`
- `element.bonding_capacity`

### Types

`autogeom.types`: array types and Pydantic fields

- `types.FloatArray`
- `types.FloatArrayField`
- `types.CoordinatesField`

## Resources

- [Full documentation](https://avcopan.github.io/autogeom/)
- [llms.txt](llms.txt) — Indexed API reference for LLMs
- [llms-full.txt](llms-full.txt) — Comprehensive documentation for LLMs
- [Source code](https://github.com/avcopan/autogeom)
