dreid_forge/lib.rs
1//! A high-performance, pure Rust library for automated DREIDING force field parameterization.
2//! It orchestrates structure repair, topology perception, and partial atomic charge calculation
3//! to produce simulation-ready inputs for both biological macromolecules and arbitrary chemical systems.
4//!
5//! # Features
6//!
7//! - **Atom typing** — Automatic assignment of DREIDING atom types based on
8//! element, hybridization, and local bonding environment
9//! - **Flexible charge calculation** — Global QEq, hybrid (classical + QEq), or
10//! embedded QEq with environment polarization for ligands in protein complexes
11//! - **Parameter generation** — Bond, angle, torsion, inversion, van der Waals,
12//! and hydrogen bond potentials with multiple functional forms
13//! - **Flexible I/O** — Read/write PDB, mmCIF, MOL2, SDF formats; export to BGF
14//!
15//! # Quick Start
16//!
17//! The main entry point is the [`forge`] function, which takes a [`System`] and
18//! [`ForgeConfig`] and produces a fully parameterized [`ForgedSystem`]:
19//!
20//! ```
21//! use dreid_forge::{System, Atom, Bond, Element, BondOrder};
22//! use dreid_forge::{forge, ForgeConfig, ForgeError};
23//!
24//! // Build an ethanol molecule (C₂H₅OH)
25//! let mut system = System::new();
26//!
27//! // Atoms: C1 (methyl), C2 (methylene), O, and hydrogens
28//! system.atoms.push(Atom::new(Element::C, [-1.270, 0.248, 0.000])); // C1
29//! system.atoms.push(Atom::new(Element::C, [ 0.139, -0.308, 0.000])); // C2
30//! system.atoms.push(Atom::new(Element::O, [ 1.036, 0.789, 0.000])); // O
31//! system.atoms.push(Atom::new(Element::H, [-1.317, 0.885, 0.883])); // H on C1
32//! system.atoms.push(Atom::new(Element::H, [-1.317, 0.885, -0.883])); // H on C1
33//! system.atoms.push(Atom::new(Element::H, [-2.030, -0.533, 0.000])); // H on C1
34//! system.atoms.push(Atom::new(Element::H, [ 0.358, -0.920, 0.876])); // H on C2
35//! system.atoms.push(Atom::new(Element::H, [ 0.358, -0.920, -0.876])); // H on C2
36//! system.atoms.push(Atom::new(Element::H, [ 1.939, 0.473, 0.000])); // H on O
37//!
38//! // Bonds
39//! system.bonds.push(Bond::new(0, 1, BondOrder::Single)); // C1-C2
40//! system.bonds.push(Bond::new(1, 2, BondOrder::Single)); // C2-O
41//! system.bonds.push(Bond::new(0, 3, BondOrder::Single)); // C1-H
42//! system.bonds.push(Bond::new(0, 4, BondOrder::Single)); // C1-H
43//! system.bonds.push(Bond::new(0, 5, BondOrder::Single)); // C1-H
44//! system.bonds.push(Bond::new(1, 6, BondOrder::Single)); // C2-H
45//! system.bonds.push(Bond::new(1, 7, BondOrder::Single)); // C2-H
46//! system.bonds.push(Bond::new(2, 8, BondOrder::Single)); // O-H
47//!
48//! // Parameterize with default settings
49//! let forged = forge(&system, &ForgeConfig::default())?;
50//!
51//! // Atom types: C_3 (sp³ carbon), O_3 (sp³ oxygen), H_, H_HB (H-bond donor)
52//! assert_eq!(forged.atom_types.len(), 4);
53//! assert!(forged.atom_types.contains(&"C_3".to_string()));
54//! assert!(forged.atom_types.contains(&"O_3".to_string()));
55//! assert!(forged.atom_types.contains(&"H_HB".to_string()));
56//!
57//! // Per-atom properties: charge, mass, type index
58//! assert_eq!(forged.atom_properties.len(), 9);
59//!
60//! // Bond potentials: C-C, C-O, C-H, O-H
61//! assert_eq!(forged.potentials.bonds.len(), 8);
62//!
63//! // Angle potentials: all angles around sp³ centers
64//! assert_eq!(forged.potentials.angles.len(), 13);
65//!
66//! // Torsion potentials: H-C-C-H, H-C-C-O, C-C-O-H, H-C-O-H
67//! assert_eq!(forged.potentials.torsions.len(), 12);
68//!
69//! // Inversion potentials: none for all-sp³ molecule
70//! assert!(forged.potentials.inversions.is_empty());
71//!
72//! // VdW pair potentials: n(n+1)/2 = 4×5/2 = 10 pairs
73//! assert_eq!(forged.potentials.vdw_pairs.len(), 10);
74//!
75//! // H-bond potential: O_3 as donor/acceptor with H_HB
76//! assert_eq!(forged.potentials.h_bonds.len(), 1);
77//! # Ok::<(), ForgeError>(())
78//! ```
79//!
80//! # Module Organization
81//!
82//! - [`io`] — File I/O for molecular structures (PDB, mmCIF, MOL2, SDF, BGF)
83//! - [`forge`] — Main parameterization function
84//! - [`ForgeConfig`] — Configuration for potential types and charge methods
85//!
86//! # Data Types
87//!
88//! ## Input Structures
89//!
90//! - [`System`] — Molecular system with atoms, bonds, and optional metadata
91//! - [`Atom`] — Single atom with element and Cartesian coordinates
92//! - [`Bond`] — Bond between two atoms with bond order
93//! - [`Element`] — Chemical element (H through Og)
94//! - [`BondOrder`] — Bond order (Single, Double, Triple, Aromatic)
95//!
96//! ## Output Structures
97//!
98//! - [`ForgedSystem`] — Fully parameterized system ready for simulation
99//! - [`AtomParam`] — Per-atom charge, mass, and type index
100//! - [`Potentials`] — Collection of all potential energy functions
101//! - [`BondPotential`] — Harmonic or Morse bond stretching
102//! - [`AnglePotential`] — Cosine-harmonic, cosine-linear, or theta-harmonic bending
103//! - [`TorsionPotential`] — Periodic torsion potentials
104//! - [`InversionPotential`] — Planar or umbrella out-of-plane terms
105//! - [`VdwPairPotential`] — Lennard-Jones or Buckingham dispersion
106//! - [`HBondPotential`] — Directional hydrogen bond terms
107//!
108//! ## Configuration
109//!
110//! - [`ChargeMethod`] — None, QEq, or Hybrid charge equilibration
111//! - [`QeqConfig`] — QEq solver settings (total charge, convergence)
112//! - [`HybridConfig`] — Hybrid biological/QEq charge assignment settings
113//! - [`BondPotentialType`] — Harmonic vs Morse selection
114//! - [`AnglePotentialType`] — Cosine vs theta-harmonic selection
115//! - [`VdwPotentialType`] — Lennard-Jones vs Buckingham selection
116//!
117//! ## Biological Metadata
118//!
119//! - [`BioMetadata`] — Per-atom PDB/mmCIF annotations
120//! - [`AtomResidueInfo`] — Residue name, chain, sequence number
121//! - [`StandardResidue`] — Standard amino acids and nucleotides
122//! - [`ResidueCategory`] — Standard, hetero, or ion classification
123//! - [`ResiduePosition`] — Terminal position (N/C-terminal, 5'/3'-end)
124
125mod forge;
126mod model;
127
128pub mod io;
129
130pub use model::atom::Atom;
131pub use model::system::{Bond, System};
132pub use model::types::{BondOrder, Element, ParseBondOrderError, ParseElementError};
133
134pub use model::topology::{
135 AnglePotential, AtomParam, BondPotential, ForgedSystem, HBondPotential, InversionPotential,
136 Potentials, TorsionPotential, VdwPairPotential,
137};
138
139pub use model::metadata::{
140 AtomResidueBuilder, AtomResidueInfo, BioMetadata, ResidueCategory, ResiduePosition,
141 StandardResidue,
142};
143
144pub use forge::{
145 AnglePotentialType, BasisType, BondPotentialType, ChargeMethod, DampingStrategy,
146 EmbeddedQeqConfig, ForgeConfig, HybridConfig, LigandChargeConfig, LigandQeqMethod,
147 NucleicScheme, ProteinScheme, QeqConfig, ResidueSelector, SolverOptions, VdwPotentialType,
148 WaterScheme, forge,
149};
150
151pub use forge::Error as ForgeError;