pub mod angles;
mod distance;
pub mod neighbor_list;
mod rmsd;
mod transform;
pub use angles::{
AngleResult, DihedralResult, all_bond_angles, all_dihedral_angles, bond_angle, dihedral_angle,
};
pub use distance::distance_matrix;
pub use neighbor_list::{NeighborList, neighbor_list, neighbor_list_with_self_loops};
pub use rmsd::{rmsd_from_coords, rmsd_to};
pub use transform::{apply_rotation_matrix, apply_transform, rotate};
use crate::{Molecule, SdfError};
impl Molecule {
pub fn rotate(&mut self, axis: [f64; 3], angle: f64) {
rotate(self, axis, angle);
}
pub fn apply_rotation_matrix(&mut self, matrix: &[[f64; 3]; 3]) {
apply_rotation_matrix(self, matrix);
}
pub fn apply_transform(&mut self, rotation: &[[f64; 3]; 3], translation: [f64; 3]) {
apply_transform(self, rotation, translation);
}
pub fn distance_matrix(&self) -> Vec<Vec<f64>> {
distance_matrix(self)
}
pub fn rmsd_to(&self, other: &Molecule) -> Result<f64, SdfError> {
rmsd_to(self, other)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Atom;
use std::f64::consts::PI;
#[test]
fn test_molecule_rotate_method() {
let mut mol = Molecule::new("test");
mol.atoms.push(Atom::new(0, "C", 1.0, 0.0, 0.0));
mol.rotate([0.0, 0.0, 1.0], PI / 2.0);
assert!((mol.atoms[0].x).abs() < 1e-10);
assert!((mol.atoms[0].y - 1.0).abs() < 1e-10);
}
#[test]
fn test_molecule_distance_matrix_method() {
let mut mol = Molecule::new("test");
mol.atoms.push(Atom::new(0, "C", 0.0, 0.0, 0.0));
mol.atoms.push(Atom::new(1, "C", 3.0, 4.0, 0.0));
let matrix = mol.distance_matrix();
assert!((matrix[0][1] - 5.0).abs() < 1e-10);
}
#[test]
fn test_molecule_rmsd_to_method() {
let mut mol1 = Molecule::new("mol1");
mol1.atoms.push(Atom::new(0, "C", 0.0, 0.0, 0.0));
let mol2 = mol1.clone();
let rmsd = mol1.rmsd_to(&mol2).unwrap();
assert!(rmsd.abs() < 1e-10);
}
#[test]
fn test_molecule_apply_rotation_matrix_method() {
let mut mol = Molecule::new("test");
mol.atoms.push(Atom::new(0, "C", 1.0, 2.0, 3.0));
let identity = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];
mol.apply_rotation_matrix(&identity);
assert!((mol.atoms[0].x - 1.0).abs() < 1e-10);
assert!((mol.atoms[0].y - 2.0).abs() < 1e-10);
assert!((mol.atoms[0].z - 3.0).abs() < 1e-10);
}
#[test]
fn test_molecule_apply_transform_method() {
let mut mol = Molecule::new("test");
mol.atoms.push(Atom::new(0, "C", 0.0, 0.0, 0.0));
let identity = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];
mol.apply_transform(&identity, [1.0, 2.0, 3.0]);
assert!((mol.atoms[0].x - 1.0).abs() < 1e-10);
assert!((mol.atoms[0].y - 2.0).abs() < 1e-10);
assert!((mol.atoms[0].z - 3.0).abs() < 1e-10);
}
}