Skip to main content

Fast algorithms for MD trajectories

Project description

Rust Simulation Tools

CI/CD PyPI version

High-performance molecular dynamics analysis library with a Python API. Written in Rust for speed, exposed to Python via PyO3.

Installation

From PyPI using uv:

uv pip install rust-simulation-tools

For the latest version which may not be on PyPI yet, make sure you have cloned this repo and have maturin installed to your environment of choice:

uv venv /path/to/env
source /path/to/env/bin/activate
uv pip install maturin

git clone https://github.com/msinclair-py/rust-simulation-tools.git
cd rust-simulation-tools
maturin develop --release

Features

  • File I/O: AMBER topology/coordinates, DCD and MDCRD trajectories
  • Selections: VMD-style atom selection with property access
  • Analysis: SASA, trajectory unwrapping, Kabsch alignment
  • Fingerprints: Per-residue interaction energies (LJ + electrostatic)
  • MM-PBSA/GBSA: Binding free energy with per-residue decomposition

Quick Start

Load a System

from rust_simulation_tools import read_prmtop, read_inpcrd, DcdReader

# Load topology and coordinates
topo = read_prmtop("system.prmtop")
coords, box = read_inpcrd("system.inpcrd")

# Load trajectory
dcd = DcdReader("trajectory.dcd")
trajectory, boxes = dcd.read_all()

Atom Selection

Select atoms using VMD-style expressions. The select() method returns a Selection object with direct property access.

# Select protein backbone
backbone = topo.select("backbone")
print(f"{backbone.n_atoms} atoms, {backbone.n_residues} residues")

# Access properties directly
ca = topo.select("protein and name CA")
print(ca.masses)          # numpy array of masses
print(ca.charges)         # numpy array of charges
print(ca.total_mass())    # sum of masses

# Distance-based selection (requires coordinates)
near_lig = topo.select("protein and within 5.0 of resname LIG", coordinates=coords)

# Set operations
charged = topo.select("charge < -0.5 or charge > 0.5")
sidechain = topo.select("sidechain")
charged_sidechain = sidechain & charged  # intersection

Supported selection keywords:

  • protein, backbone, sidechain, water
  • name CA, resname ALA, resid 1-50
  • charge > 0.5, mass < 2.0
  • within 5.0 of resname LIG
  • Boolean: and, or, not

SASA Calculation

from rust_simulation_tools import compute_sasa_from_topology

# Single frame
sasa = compute_sasa_from_topology(topo, coords)
print(f"Total SASA: {sasa['total']:.1f} A^2")
print(f"Per-atom: {sasa['per_atom'].shape}")
print(f"Per-residue: {sasa['per_residue']}")  # dict of residue_idx -> area

Trajectory Alignment

from rust_simulation_tools import kabsch_align

# Align trajectory to first frame using backbone atoms
backbone = topo.select("backbone")
aligned = kabsch_align(trajectory, trajectory[0], backbone.indices)

Trajectory Unwrapping

from rust_simulation_tools import unwrap_dcd

# Remove periodic boundary artifacts
unwrapped, boxes = unwrap_dcd("trajectory.dcd")

Interaction Fingerprints

Calculate per-residue LJ and electrostatic interactions between a target and partner.

from rust_simulation_tools import FingerprintSession, FingerprintMode

session = FingerprintSession("system.prmtop", "trajectory.dcd")
session.set_target_residues(range(10))           # residues to fingerprint
session.set_binder_residues(range(10, 100))      # interaction partner

# Iterate over frames
for lj_fp, es_fp in session:
    print(f"LJ: {lj_fp.sum():.2f}, ES: {es_fp.sum():.2f} kJ/mol")

# Switch perspective: fingerprint binder residues instead
session.set_fingerprint_mode(FingerprintMode.Binder)
session.seek(0)

MM-PBSA/GBSA Binding Energy

Calculate binding free energy with Generalized Born or Poisson-Boltzmann solvation.

from rust_simulation_tools import (
    compute_binding_energy,
    decompose_binding_energy,
    GbModel, GbParams, PbParams, SaParams,
)

# MM-GBSA over trajectory
result = compute_binding_energy(
    topo,
    trajectory_path="trajectory.dcd",
    receptor_residues=list(range(0, 250)),
    ligand_residues=list(range(250, 251)),
    gb_params=GbParams(model=GbModel.ObcII, salt_concentration=0.15),
    sa_params=SaParams(),
    trajectory_format="dcd",
)

print(f"Delta G: {result.mean_delta_total:.2f} +/- {result.std_delta_total:.2f} kcal/mol")
print(f"  MM:  {result.mean_delta_mm:.2f}")
print(f"  GB:  {result.mean_delta_gb:.2f}")
print(f"  SA:  {result.mean_delta_sa:.2f}")

# MM-PBSA (use pb_params instead of gb_params)
pb_result = compute_binding_energy(
    topo, "trajectory.dcd",
    receptor_residues=list(range(0, 250)),
    ligand_residues=list(range(250, 251)),
    pb_params=PbParams(grid_spacing=0.5, salt_concentration=0.15),
)

# Per-residue decomposition
decomp = decompose_binding_energy(
    topo, coords,
    receptor_residues=list(range(0, 250)),
    ligand_residues=list(range(250, 251)),
)

for res in sorted(decomp.receptor_residues, key=lambda r: r.total())[:5]:
    print(f"{res.residue_label}{res.residue_index}: {res.total():.2f} kcal/mol")

API Reference

File I/O

Function Description
read_prmtop(path) Load AMBER topology, returns AmberTopology
read_inpcrd(path) Load AMBER coordinates, returns (coords, box)
DcdReader(path) DCD trajectory reader
MdcrdReader(path, n_atoms, has_box) AMBER ASCII trajectory reader

AmberTopology

Property/Method Description
.n_atoms, .n_residues System size
.atom_names, .residue_labels Atom/residue names
.charges(), .sigmas(), .epsilons() Force field parameters
.select(expression, coordinates=None) VMD-style selection, returns Selection
.bonds() List of bonded atom pairs

Selection

Property/Method Description
.n_atoms, .n_residues Selection size
.indices Atom indices (numpy array)
.masses, .charges, .radii Per-atom properties
.atom_names, .residue_names Names as lists
.positions Coordinates (if provided during selection)
.total_mass(), .total_charge() Aggregate properties
&, |, - Set operations (intersection, union, difference)

DcdReader

Property/Method Description
.n_frames, .n_atoms Trajectory size
.read_frame() Read next frame, returns (coords, box)
.read_all() Read all frames, returns (trajectory, boxes)
.seek(frame) Jump to frame index

Analysis Functions

Function Description
compute_sasa_from_topology(topo, coords) SASA using topology for radii
calculate_sasa(coords, radii, residue_indices) SASA with explicit radii
kabsch_align(trajectory, reference, align_indices) RMSD-minimizing alignment
unwrap_dcd(path) Remove PBC artifacts from DCD
unwrap_system(trajectory, boxes) Remove PBC artifacts

MM-PBSA/GBSA

Function Description
compute_binding_energy(...) Trajectory-averaged binding energy
compute_binding_energy_single_frame(...) Single frame binding energy
decompose_binding_energy(...) Per-residue energy decomposition
compute_mm_energy(topo, coords) Molecular mechanics energy
compute_gb_energy(topo, coords, params) GB solvation energy
compute_pb_energy(topo, coords, params) PB solvation energy
interaction_entropy(frames, temperature) Entropy correction

Development

git clone https://github.com/msinclair-py/rust-simulation-tools.git
cd rust-simulation-tools
pip install maturin pytest numpy
maturin develop --release
pytest tests/ -v

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rust_simulation_tools-0.2.4.tar.gz (110.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rust_simulation_tools-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (697.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rust_simulation_tools-0.2.4-cp313-cp313-macosx_11_0_arm64.whl (621.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rust_simulation_tools-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (698.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rust_simulation_tools-0.2.4-cp312-cp312-macosx_11_0_arm64.whl (621.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rust_simulation_tools-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (696.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rust_simulation_tools-0.2.4-cp311-cp311-macosx_11_0_arm64.whl (620.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rust_simulation_tools-0.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (696.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

rust_simulation_tools-0.2.4-cp310-cp310-macosx_11_0_arm64.whl (620.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file rust_simulation_tools-0.2.4.tar.gz.

File metadata

  • Download URL: rust_simulation_tools-0.2.4.tar.gz
  • Upload date:
  • Size: 110.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for rust_simulation_tools-0.2.4.tar.gz
Algorithm Hash digest
SHA256 2e0b14ff33a23136d4d97ffd4b9a501afebaeb4bd310e663a9037de6711b3a58
MD5 73e2f165586fbe11d606feb90fa67f0d
BLAKE2b-256 9a51cb1be60bd094115337a1e7034ea54f455ebca7f41ac15f491cd4af11af47

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a46291ba88945b95bafe799b2459b3ce9eb5e7ed49a82588469a6bc187ecb2f1
MD5 4f11da52328e7d9829a8af0e4f3cffec
BLAKE2b-256 7555d50b03285493a3287a2fe0083baee759d57e8a51fbfd522809fb2734eec4

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20fd9c60b20d23047d48fc6cc2a1ab02766dcf99992666c587c9cfb97400475b
MD5 098cdcee57c8ee97d845f2f049dd4ab1
BLAKE2b-256 4f93e7409811c859c9b24fef6db28a3369b466ddf176d280dde46ec8e7dd1605

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e4c1ac15dc7942974a2e9d7ba286c07b9e4a3d3e49b5ad294e726b1d8c93c70
MD5 795d83b14ada493d6b2c01359dd6a2fd
BLAKE2b-256 488a709813d63c65942705caa14822200caf7b238fdbe91b32867f629deffcf3

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c6bbd402ed35e19e37b7d723e7c6d10886976afd4b444e304d16242b4d63d3f
MD5 2aabcef763f287a2038005c7488e8bd8
BLAKE2b-256 2f062518b206a6dd69ec9b06b416c383ca75bb2a4c788188efe692df3c9cf031

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd41785661df0d39cd09c87c3ec8f3344c2c10bd05d97144f543436492a1fdcb
MD5 66a58193ba0ca60901966418f5785007
BLAKE2b-256 c65c1b789e8baed7b8b146fb0ac15f0722ee679b5c56b62f058b74d471169ce4

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84713aee7b95c612161c31fcae8b4f20104cb4dec3589c0f80bde9ef3e0ff0e9
MD5 8c116efbea51048a9319b429f155d986
BLAKE2b-256 1aba2a1823bd3e0901071918c1a2bdca69547d81aded24e3629ce4e2081b10eb

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7482f127890e11c2f12529e5777051284fac72b4043fc065836c461c7cfccae
MD5 2ae04fa0688f01352331c4e6eee14d4f
BLAKE2b-256 f225cc4448d6fbd275a76ece2efefcb8822e8b3bb04e94569448e1fcda3de1bf

See more details on using hashes here.

File details

Details for the file rust_simulation_tools-0.2.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rust_simulation_tools-0.2.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89c288bcc1cf2c04b3b5aff11f0caf2a5e42f099094943682519ffcbf2f4d0ae
MD5 8a0f2a6ad274a6b4459e929274de9285
BLAKE2b-256 2b39120ec4814b57bdf8025a94e47164fc5e38785b6c842f25af14de41ebca9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page