Contributing
Contributions are welcome: bug reports, documentation, and code. For larger changes, please open an issue first to discuss the idea.
Setup
Install Pixi.
Fork and clone the repository.
In the clone, install the environments and the Git hooks:
pixi install --all pixi run lefthook install
The project follows the copier-pixi-python template, whose README explains the tooling in more detail.
Workflow
| task | what it does |
|---|---|
pixi run test |
Run the tests, including the doctests in src/ |
pixi run test-lowest |
Run the tests with the lowest dependency versions allowed by pyproject.toml |
pixi run pre-commit |
Run every check that runs on commit: format, lint, types, import contracts, both test runs, and a clean-tree check |
pixi run pre-commit-check |
The same, without the tests |
pixi run docs-preview |
Build and preview the documentation site |
pixi run add <pkg> |
Add a run dependency to pyproject.toml |
To run a single test, call pytest in the test environment:
pixi run -e test pytest tests/test_geom.py::test__center_of_massCoverage must stay at or above 80%. Docstrings use the Google style, with types taken from the annotations rather than repeated in Args: and Returns:. Docstring examples run as doctests, so keep them working.
Design
One model, functions at the root
autogeom is centered on the Geometry model, and everything that operates on it is a function exported from the package root:
import autogeom
geo = autogeom.from_smiles("O")
com = autogeom.center_of_mass(geo)- Algorithms are functions, not methods, and take the Geometry as their first argument. Algorithms that need more than a geometry take a model containing one first, e.g.
vibrational_analysis(point: PESPoint). Geometry only has methods for what it needs to construct and display itself (xyz I/O, relabel_atoms). - Variables holding a Geometry are named
geo. - Add new functions to a private module (
_measure.py,_transform.py, …) and export them inautogeom/__init__.py. The private modules exist to keep files small; users never import from them. - Public submodules are for things that aren’t about Geometry:
autogeom.rd(RDKitMolfunctions),autogeom.element(periodic table data), andautogeom.types(array types and Pydantic fields).
Layers
Modules are layered, and a module may only import from the layers below it. pixi run imports enforces this with the contract in pyproject.toml:
_view | _convert (highest)
_transform
_measure
_trajectory
_geometry
rd
element | types | units
exc (lowest)
The one exception is Geometry._repr_html_, which imports view lazily to display itself in Jupyter.
Conversions
Each conversion between Geometry and an external library or format has exactly one home in autogeom. Bridge modules know only their external library: autogeom.rd deals only in RDKit Mol objects and never imports Geometry. The conversions themselves, such as rdkit_mol() and from_rdkit_mol(), live above the bridge, in _convert.py. Other packages, such as autostorage, call these conversions rather than reimplementing them.
This works for libraries autogeom depends on anyway, like RDKit. For a library that is heavy or optional, import it lazily inside the function that needs it, as render_svg does with xyzrender.
Element data
src/autogeom/elements-data.json is generated by pixi run elements-data (scripts/elements-data.py, in the data environment). Don’t edit it by hand.