StereoMorph.jl is a high-performance computational chemistry and cheminformatics engine written in pure Julia. It implements rigorous 3D distance geometry (DG), metric matrix embedding via Classical Multidimensional Scaling (MDS), stereochemical parity enforcement, analytical gradient L-BFGS penalty refinement, Kabsch optimal rotational alignment, and 3D pharmacophore feature extraction.
flowchart TD
A["Chemical Topology (Atoms, Bonds, Chirality)"] --> B["Distance Bounds Matrix L, U"]
B --> C["Floyd-Warshall Triangle Inequality Smoothing O(N³)"]
C --> D["Crippen-Havel Incremental Metrization"]
D --> E["Metric Gram Matrix G = -½ H D² H"]
E --> F["Spectral Eigendecomposition & 3D MDS Projection"]
F --> G["Chiral Parity Verification & Coordinate Inversion"]
G --> H["L-BFGS & Conjugate Gradient Penalty Refinement"]
H --> I["3D Conformation Ensemble"]
I --> J["Kabsch SVD Superposition & RMSD Matrix"]
I --> K["3D Pharmacophore Feature Extraction (HBD, HBA, AROM, HYD, NEG)"]
J --> L["Conformational Cluster Medoids"]
K --> M["Gaussian Spatial Pharmacophore Alignment Score"]
Given a molecular graph
-
1-2 Bonded Pairs:
$$L_{ij} = r_{\text{cov}}(i) + r_{\text{cov}}(j) - \delta_{\text{order}} - \epsilon_{\text{bond}}, \quad U_{ij} = r_{\text{cov}}(i) + r_{\text{cov}}(j) - \delta_{\text{order}} + \epsilon_{\text{bond}}$$ -
1-3 Geminal Pairs (subtending bond angle
$\theta_k$ around atom$k$ ):$$d_{13}^2 = r_{ik}^2 + r_{jk}^2 - 2 r_{ik} r_{jk} \cos\theta_k$$ where$\theta_k \in {109.47^\circ, 120.0^\circ, 180.0^\circ}$ is determined by orbital hybridization ($sp^3, sp^2, sp$ ). -
1-4 Dihedral Pairs: Bound between cis (
$d_{\text{cis}}$ ) and trans ($d_{\text{trans}}$ ) geometries. -
1-5+ Non-Bonded Pairs: Lower bound governed by van der Waals contact radii:
$$L_{ij} = r_{\text{vdw}}(i) + r_{\text{vdw}}(j) - \Delta_{\text{steric}}$$
Bounds are smoothed to global metric consistency using the Floyd-Warshall triangle inequality relaxation in
To sample an embeddable trial distance matrix
- Sample trial distance:
$d_{ij} \sim \mathcal{U}(L_{ij}, U_{ij})$ . - Tighten bounds:
$L_{ij} = U_{ij} = d_{ij}$ . - Dynamically propagate localized triangle inequalities to all neighboring atoms
$k$ :$$U_{ik} \leftarrow \min(U_{ik}, d_{ij} + U_{jk}), \quad L_{ik} \leftarrow \max(L_{ik}, d_{ij} - U_{jk}, L_{jk} - d_{ij})$$
4-point and 5-point Cayley-Menger determinants assess the metric embedding dimension:
Let $D^{(2)}{ij} = d{ij}^2$ denote the squared distance matrix. The centering projection operator
The metric Gram matrix
Spectral decomposition yields eigenvalues and eigenvectors:
The 3D Cartesian coordinates matrix
The 3D embedding quality metric is computed as:
For each designated chiral tetrahedral center
If the computed sign deviates from the requested stereochemical descriptor
Coordinates are refined by minimizing the total penalty energy
where:
Exact analytical chain-rule gradients
Planarity of aromatic rings and amides is enforced via exact improper tetrahedral volumes
Given two coordinate matrices
- Covariance matrix:
$H = P Q^T = \sum_{i=1}^N \mathbf{p}_i \mathbf{q}_i^T$ . - Singular Value Decomposition:
$H = U \Sigma V^T$ . - Enforce proper rotation condition
$d = \operatorname{det}(V U^T)$ : $$R = V \begin{pmatrix} 1 & 0 & 0 \ 0 & 1 & 0 \ 0 & 0 & d \end{pmatrix} U^T$$ - Optimal Root-Mean-Square Deviation:
$$\operatorname{RMSD}(P, Q) = \sqrt{\frac{1}{N} \sum_{i=1}^N |R \mathbf{p}_i - \mathbf{q}_i|^2}$$
3D feature points are classified into 6 categories:
- HBD: Hydrogen Bond Donors (-OH, -NH-, -NH2)
- HBA: Hydrogen Bond Acceptors (=O, -O-, -N=)
-
AROM: Aromatic ring centroids with normal vectors
$\hat{n}$ - HYD: Aliphatic hydrophobic carbon centers
- POS / NEG: Basic amine cations and carboxylate anions
Pairwise overlay similarity is scored via continuous Gaussian overlap:
Evaluated on standard chemical topologies (Julia 1.13, AMD/Intel x86_64):
| Molecule | Formula | Atoms | Bonds | Generation + L-BFGS Time | Final Energy | Violations |
|---|---|---|---|---|---|---|
| Methane | 5 | 4 | 4.34 ms | 0 | ||
| Ethane | 8 | 7 | 0.11 ms | 0 | ||
| Propane | 3 | 2 | 0.02 ms | 0 | ||
| Butane | $\text{C}4\text{H}{10}$ | 4 | 3 | 0.01 ms | 0 | |
| Cyclohexane | $\text{C}6\text{H}{12}$ | 6 | 6 | 0.08 ms | 0 | |
| Benzene | 6 | 6 | 0.18 ms | 0 | ||
| L-Alanine | 7 | 6 | 0.11 ms | 0 | ||
| Aspirin | 13 | 13 | 1.49 ms | 0 | ||
| Ibuprofen | $\text{C}{13}\text{H}{18}\text{O}_2$ | 16 | 16 | 2.02 ms | 6 |
StereoMorph.jl requires Julia 1.10 or newer. It relies entirely on Julia standard libraries (LinearAlgebra, Statistics, Random, Printf, Test), ensuring zero external network dependencies and immediate execution.
git clone https://github.com/ZengLLQ/stereomorph.git
cd stereomorph
julia --project=. -e "using Pkg; Pkg.instantiate(); Pkg.test()"using StereoMorph
# Load benchmark topology or construct custom Molecule
aspirin = make_aspirin()
# Generate refined 3D conformation
conf = generate_conformation(aspirin; method=:lbfgs, max_iter=300)
println("Energy: $(conf.energy) kcal/mol | Quality: $(conf.embedding_quality)")
# Export to standard formats
write_xyz("aspirin.xyz", aspirin, conf.coords)
write_sdf("aspirin.sdf", aspirin, conf.coords)using StereoMorph
# Generate 20 distinct conformers and cluster by RMSD (cutoff = 0.6 Å)
all_confs, cluster_medoids = generate_ensemble(aspirin, 20; cluster_cutoff=0.6)
println("Generated $(length(all_confs)) conformers; extracted $(length(cluster_medoids)) unique clusters.")
write_ensemble_xyz("aspirin_ensemble.xyz", aspirin, cluster_medoids)using StereoMorph
ibuprofen = make_ibuprofen()
conf1 = generate_conformation(ibuprofen)
conf2 = generate_conformation(ibuprofen)
# Superimpose conf1 onto conf2
aligned_coords, rot_mat, rmsd_val = align_coordinates(conf1.coords, conf2.coords)
println("Optimal Kabsch RMSD: $(rmsd_val) Å")using StereoMorph
conf = generate_conformation(aspirin)
ph = extract_pharmacophore(aspirin, conf.coords)
# Print tabular summary of spatial features
print_pharmacophore_summary(stdout, ph)StereoMorph provides a full-featured CLI:
# Generate 10 conformers and cluster at 0.6 Å cutoff
julia --project=. -e "using StereoMorph; CLI.run_cli([\"generate\", \"aspirin\", \"--samples\", \"10\", \"--out\", \"aspirin.xyz\"])"
# Extract 3D pharmacophore features
julia --project=. -e "using StereoMorph; CLI.run_cli([\"pharmacophore\", \"ibuprofen\"])"
# Kabsch alignment between two coordinate files
julia --project=. -e "using StereoMorph; CLI.run_cli([\"align\", \"conf1.xyz\", \"conf2.xyz\"])"
# Execute internal benchmark suite
julia --project=. -e "using StereoMorph; CLI.run_cli([\"benchmark\"])"- Empirical Bound Heuristics: Initial 1-4 dihedral ranges use standard stereochemical rules; highly congested macrocyclic systems with non-standard ring strain may require iterative dihedral sampling.
- Implicit vs Explicit Hydrogens: Benchmarks default to heavy-atom topologies with functional group polar hydrogens; all-atom explicit hydrogen graphs are fully supported via
Moleculetopology definition. - Rigid Pharmacophore Superposition: Pharmacophore overlay scoring evaluates static spatial overlap; dynamic conformational flexibility is addressed by evaluating multi-conformer ensembles.
This project is licensed under the MIT License.