Skip to content

Biomolecular preparation

atomli.biomol prepares molecular coordinates and chemical topology in Rust. The prepared structure uses the existing Atoms, calculator, optimizer, and MD interfaces.

from atomli.biomol import prepare, select, within, extract_cluster
from atomli.io import read, write
source = read("complex.pdb")
result = prepare(source, ph=7.4)
atoms = result.atoms
write("prepared.h5", atoms)
write("prepared.mmcif", atoms)

Preparation returns a new structure and a report. Existing atom coordinates stay fixed. The report records added atoms, removed atoms, residue variants, template sources, charge, and the mapping to input indices. Preparation does not minimize an energy.

atoms.topology contains atom records, residues, and typed bonds. Atom records include stable identities, atom names, alternate locations, occupancy, formal charge, and stereochemistry. Residue records include author and label identifiers, insertion codes, chain segments, and assigned variants. Bonds distinguish covalent, disulfide, and coordination links.

PDB, mmCIF, and SDF import this chemical information. Native HDF5, JSON, checkpoints, and trajectories preserve topology. Atom selection remaps bonds and residues. Supercells create separate residue and bond copies. Use mmCIF for structures that exceed PDB field limits. Use HDF5 for native trajectories and restart data.

SDF supports V2000 bond orders, formal charges, atom parity, and directional bond stereo. Selections with MDL atom parity require complete bonded neighborhoods and the original atom order. V3000, radical records, and coordination export require another supported representation. PDB and mmCIF symmetry links require explicit crystal images. PDB export groups atoms by residue and chain segment. Use native files or mmCIF when array order must remain fixed.

The bundled CCD templates cover the 20 standard amino acids, water, benzamidine, ACE, and NME. Each template records its source URL and CCD revision. Custom templates use the same schema returned by templates(). Unknown ligands require explicit bond orders and formal charges or a custom template. Preparation does not infer missing ligand heavy atoms from an incomplete graph.

from atomli.biomol import (
templates, repair_missing_atoms, assign_protonation, add_hydrogens, validate,
)
registry = templates()
repaired = repair_missing_atoms(source)
assigned = assign_protonation(repaired.atoms, ph=7.4, variants={"A:57:0": "HID"})
complete = add_hydrogens(assigned.atoms)
issues = validate(complete.atoms)

Variant keys use chain:sequence[insertion]:segment. Read these fields from atoms.topology["residues"]. Supported states include HID/HIE/HIP, ASP/ASH, GLU/GLH, CYS/CYX/CYM, LYS/LYN, ARG/ARN, TYR/TYM, and BEN+. The pH policy uses intrinsic residue defaults. It does not calculate a site-specific pKa. Explicit variants and preparation pH persist across separate operations. Use assign_protonation to request a new assignment.

Alternate locations are selected per residue using summed occupancy. Missing heavy atoms use a proper rotation of CCD reference geometry. Reconstruction requires at least three noncollinear heavy-atom anchors. Hydrogen placement uses local geometry and existing hydrogen anchors. Validation checks topology, upper valence limits, template chirality, and coincident coordinates. It does not provide complete steric validation.

Assign an MLIP that supports the system’s elements and chemistry. Use the existing optimization and dynamics drivers. Keep the model identifier, device, convergence state, timestep, temperature, and random seed in the run record.

from atomli.calculators import MLIP
from atomli.optimize import FIRE
atoms.calc = MLIP("path/to/validated-model.nqx", device="gpu")
converged = FIRE(atoms, logfile="relaxation.log").run(fmax=0.05, steps=500)
if not converged:
raise RuntimeError("Relaxation did not converge")

Element coverage alone does not establish protein accuracy. Solvent, ions, charge state, and boundary conditions remain part of the physical model.

Select the ligand and nearby residues after relaxation or MD. Extract a nonperiodic cluster with explicit chemical boundaries.

ligand = select(atoms, resname="BEN")
region = within(atoms, ligand, 6.0, residues=True)
cluster = extract_cluster(atoms, region, reference_atom=ligand[0], unpaired=0)
from atomli.calculators import XTB
cluster.atoms.calc = XTB(
method="gxtb", charge=cluster.report["formal_charge"], unpaired=0, device="cpu",
)
energy = cluster.atoms.get_potential_energy()
forces = cluster.atoms.get_forces()

Peptide cuts receive ACE/NME caps. Other supported single-bond cuts receive hydrogen caps. Disulfide partners and short peptide bridges can expand the region. Multiple bonds, aromatic cuts, and incomplete coordination environments require a larger selection. The report records caps, boundary expansions, image shifts, charge, and input mappings. The supplied spin must agree with the cluster electron count.

This calculation analyzes an isolated extracted cluster. It does not couple local electronic forces back into the full protein simulation. The trypsin preparation example includes separate protein and ligand layers.