Crate ffcharge

Crate ffcharge 

Source
Expand description

A lightweight pure Rust library for fast, residue-based force field charge assignment (AMBER/CHARMM) in molecular modeling pipelines.

§FFCharge

FFCharge provides pre-computed atomic partial charges from AMBER and CHARMM force fields for proteins, nucleic acids, water, and ions. Designed with no_std support and zero runtime dependencies, it is ideal for high-performance molecular dynamics preprocessing and biomolecular structure analysis.

§Features

  • O(1) Lookups: Uses compile-time perfect hash functions (PHF) for constant-time charge retrieval.
  • Comprehensive Coverage: Supports 29 protein residues, 10 nucleic acid residues, 5 water models, and 66 ion types.
  • Terminal-Aware: Handles N-/C-terminal protein residues (including protonation variants) and 5’/3’-terminal nucleic acids.
  • Type-Safe API: Strongly-typed enums for schemes and positions prevent invalid queries at compile time.
  • no_std Compatible: Suitable for embedded systems and WebAssembly targets.

§Quick Start

use ffcharge::{ProteinScheme, NucleicScheme, WaterScheme, IonScheme, Position};

// Protein: Get charge for CA atom of Alanine (middle position, AMBER ff99SB)
let charge = ProteinScheme::AmberFFSB
    .charge(Position::Middle, "ALA", "CA")
    .expect("Charge not found");
assert!((charge - 0.0337).abs() < 1e-4);

// Protein: N-terminal residue
let n_term = ProteinScheme::AmberFFSB
    .charge(Position::NTerminal, "ALA", "N")
    .expect("Charge not found");
assert!((n_term - 0.1414).abs() < 1e-4);

// Nucleic acid: DNA adenine at 5' terminus (AMBER)
let dna = NucleicScheme::Amber
    .charge(Position::FivePrime, "DA", "N9")
    .expect("Charge not found");
assert!((dna - (-0.0268)).abs() < 1e-4);

// Water: TIP3P model
let water = WaterScheme::Tip3p.charges().expect("Water model not found");
assert!((water.o - (-0.834)).abs() < 1e-3);
assert!((water.h1 - 0.417).abs() < 1e-3);

// Ion: Sodium
let na = IonScheme::Classic.charge("NA").expect("Ion not found");
assert!((na - 1.0).abs() < 1e-6);

§Supported Force Fields

CategorySchemes
ProteinAMBER ff99SB/ff14SB/ff19SB, AMBER ff03, CHARMM C22/C27/C36/C36m
NucleicAMBER OL15/OL21/OL24/bsc1/OL3, CHARMM C27/C36
WaterTIP3P, TIP3P-FB, SPC, SPC/E, OPC3
IonClassic (formal charges)

§Position Handling

Residues at chain termini have different charge distributions. Use Position to specify the residue location:

PositionDescriptionApplicable To
NTerminalN-terminal (protonated NH₃⁺)Protein
NTerminalDeprotonatedN-terminal (neutral NH₂)Protein
CTerminalC-terminal (deprotonated COO⁻)Protein
CTerminalProtonatedC-terminal (protonated COOH)Protein
FivePrime5’-terminalNucleic acid
ThreePrime3’-terminalNucleic acid
MiddleInternal residue (default)Both

Structs§

WaterCharges
Water charge distribution.

Enums§

IonScheme
Ion charge scheme.
NucleicScheme
Nucleic acid charge scheme.
Position
Position of a residue in its chain.
ProteinScheme
Protein charge scheme.
WaterScheme
Water charge scheme.