Analysis
Structural analysis lives in molex::analysis (source: src/analysis/). Most analysis functions operate on entity-level types (&[Atom], &[ResidueBackbone], &[MoleculeEntity]).
The eagerly-computed pipeline (DSSP secondary structure + backbone H-bonds + disulfides) is exposed through Assembly — see Assembly::ss_types, Assembly::hbonds, and Assembly::disulfides. The standalone functions documented below are the building blocks underneath.
Secondary structure (analysis::ss)
DSSP-based secondary structure classification.
use molex::analysis::ss::{classify, from_string};
use molex::analysis::{HBond, SSType};
// Classify residues from a precomputed H-bond list.
let ss_types: Vec<SSType> = classify(&hbonds, n_residues);
// Parse a secondary-structure string like "HHHCCCEEE" into Vec<SSType>.
let ss_types = from_string("HHHCCCEEE");
SSType is a Q3 classification:
pub enum SSType { Helix, Sheet, Coil }
Each variant has a .color() method returning an RGB [f32; 3] for rendering.
analysis::merge_short_segments converts isolated 1-residue helix/sheet runs to Coil.
For most callers the recommended path is to construct an Assembly and read assembly.ss_types(entity_id) — the assembly internally runs H-bond detection and classify for every protein entity.
Bond detection (analysis::bonds)
Covalent bonds (distance-based)
use molex::analysis::{infer_bonds, InferredBond, BondOrder, DEFAULT_TOLERANCE};
let bonds: Vec<InferredBond> = infer_bonds(atoms, DEFAULT_TOLERANCE);
// InferredBond { atom_a: usize, atom_b: usize, order: BondOrder }
// BondOrder: Single, Double, Triple, Aromatic
Distance-based inference using element covalent radii with a configurable tolerance. Used for ligands and other non-protein entities where bond topology isn’t supplied by a chemistry table. Protein and nucleic-acid bonds are populated from the chemistry tables at entity construction time and live on ProteinEntity::bonds / NAEntity::bonds.
Hydrogen bonds
Backbone H-bond detection is an internal pipeline step of Assembly; the function analysis::bonds::hydrogen::detect_hbonds(&[ResidueBackbone]) is pub(crate). Read H-bonds via assembly.hbonds():
use molex::Assembly;
let assembly = Assembly::new(entities);
for hb in assembly.hbonds() {
println!("donor={} acceptor={} energy={}", hb.donor, hb.acceptor, hb.energy);
}
HBond is { donor: usize, acceptor: usize, energy: f32 } (Kabsch-Sander electrostatic energy in kcal/mol).
Disulfide bonds
use molex::{detect_disulfides, CovalentBond};
let disulfides: Vec<CovalentBond> = detect_disulfides(&entities);
Scans every protein entity for CYS SG atoms and emits one CovalentBond (with AtomId endpoints) per SG-SG pair within 1.5–2.5 Å. Also surfaced via assembly.disulfides().
Bounding box (analysis::aabb)
use molex::analysis::Aabb;
let aabb = Aabb::from_positions(&positions)?;
aabb.center(); // Vec3 -- geometric center
aabb.extents(); // Vec3 -- size along each axis
aabb.radius(); // f32 -- bounding sphere radius
let merged = aabb.union(&other_aabb);
let combined = Aabb::from_aabbs(&[aabb1, aabb2, aabb3])?;
Also available directly on entities: entity.aabb().
Volumetric (analysis::volumetric)
Voxel-grid analysis used for surface and cavity work:
use molex::analysis::{
binary_to_sdf, compute_gaussian_field, compute_ses_sdf, detect_cavities,
detect_cavity_mask, edt_1d, edt_3d, voxelize_sas,
DetectedCavity, ScalarVoxelGrid, VoxelBbox,
};
These power Gaussian density approximations, solvent-excluded surface SDFs, and cavity detection.