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