| Crates.io | dreid-typer |
| lib.rs | dreid-typer |
| version | 0.4.0 |
| created_at | 2025-10-15 02:05:43.057959+00 |
| updated_at | 2025-12-09 14:08:16.509653+00 |
| description | A pure Rust library for DREIDING atom typing and molecular topology perception. |
| homepage | |
| repository | https://github.com/caltechmsc/dreid-typer |
| max_upload_size | |
| id | 1883528 |
| size | 667,697 |
DreidTyper is a Rust library that turns a minimal MolecularGraph (atoms + bonds) into a fully typed, DREIDING-compatible topology. The pipeline is deterministic, aggressively validated, and designed for integrators who need trustworthy chemistry without shipping their own perception code.
At a high level the library walks through:
AnnotatedMolecule.MolecularTopology.H_HB) converge without guesswork.resources/default.rules.toml) and load or merge custom rule files at runtime.unsafe, comprehensive unit/integration tests, and precise error variants for validation, perception, and typing failures.Add the crate to your Cargo.toml:
[dependencies]
dreid-typer = "0.4.0"
Run the full pipeline from connectivity to topology:
use dreid_typer::{assign_topology, Element, GraphBondOrder, MolecularGraph, MolecularTopology};
let mut graph = MolecularGraph::new();
let c1 = graph.add_atom(Element::C);
let c2 = graph.add_atom(Element::C);
let o = graph.add_atom(Element::O);
let h_o = graph.add_atom(Element::H);
let h_atoms: Vec<_> = (0..5).map(|_| graph.add_atom(Element::H)).collect();
graph.add_bond(c1, c2, GraphBondOrder::Single).unwrap();
graph.add_bond(c2, o, GraphBondOrder::Single).unwrap();
graph.add_bond(o, h_o, GraphBondOrder::Single).unwrap();
for (carbon, chunk) in [(c1, &h_atoms[0..3]), (c2, &h_atoms[3..5])].into_iter() {
for &hydrogen in chunk {
graph.add_bond(carbon, hydrogen, GraphBondOrder::Single).unwrap();
}
}
let topology: MolecularTopology = assign_topology(&graph).expect("perception + typing succeed");
assert_eq!(topology.atoms[c1].atom_type, "C_3");
assert_eq!(topology.atoms[c2].atom_type, "C_3");
assert_eq!(topology.atoms[o].atom_type, "O_3");
assert_eq!(topology.atoms[h_o].atom_type, "H_HB");
Need custom chemistry? Parse a TOML file and extend the default rules:
use dreid_typer::{assign_topology_with_rules, rules::{get_default_rules, parse_rules}, MolecularGraph};
// Start with the default DREIDING rules
let mut all_rules = get_default_rules().to_vec();
// Parse and append custom rules from a TOML file
let extra_toml = std::fs::read_to_string("my_metals.rules.toml")?;
all_rules.extend(parse_rules(&extra_toml)?);
// Run the pipeline with extended rules
let topology = assign_topology_with_rules(&graph, &all_rules)?;
This project is licensed under the MIT License - see the LICENSE file for details.