Skip to main content

uff_relax/atom/
mod.rs

1use glam::DVec3;
2use serde::{Deserialize, Serialize};
3
4/// Represents an atom type label in UFF (e.g., "C_3", "N_R").
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct UffAtomType(pub String);
7
8impl UffAtomType {
9    pub fn as_str(&self) -> &str {
10        &self.0
11    }
12    pub fn unknown() -> Self {
13        Self("Unknown".to_string())
14    }
15}
16
17/// Represents an individual atom in the system.
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct Atom {
20    /// Atomic number (e.g., 1 for H, 6 for C).
21    pub element: usize,
22    /// Position in Cartesian coordinates (Å).
23    pub position: DVec3,
24    /// Current force acting on the atom (kcal/mol/Å).
25    pub force: DVec3,
26    /// Partial charge of the atom (e).
27    pub charge: f64,
28    /// Internal UFF atom type label (assigned automatically).
29    pub uff_type: UffAtomType,
30}
31
32impl Atom {
33    /// Creates a new atom with the given atomic number and position.
34    pub fn new(element: usize, position: DVec3) -> Self {
35        Self {
36            element,
37            position,
38            force: DVec3::ZERO,
39            charge: 0.0,
40            uff_type: UffAtomType::unknown(),
41        }
42    }
43
44    /// Sets the partial charge of the atom.
45    pub fn with_charge(mut self, charge: f64) -> Self {
46        self.charge = charge;
47        self
48    }
49}
50
51/// Represents a chemical bond between two atoms.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct Bond {
54    /// Indices of the two atoms in the `System::atoms` vector.
55    pub atom_indices: (usize, usize),
56    /// Bond order (1.0 for single, 1.5 for aromatic, 2.0 for double).
57    pub order: f32,
58}