Skip to content

DoctorDean/molforge

Repository files navigation

molforge

CI PyPI version PyPI Downloads Python versions License: MIT Code style: ruff Docs

Molforge Logo

A forge for protein workflows. One Python script, every tool in your stack: docking, MD, folding, antibody and nanobody engineering, de novo design — without the format-conversion tax.

molforge is an open-source Python library that lets you compose protein workflows across the tools you already use. Bring your structures and sequences in, plug in your engines of choice (Vina, OpenMM, ESMFold, AlphaFold, RFdiffusion, ProteinMPNN, your own model), and walk out with a coherent pipeline instead of five incompatible Python environments and a graveyard of conversion scripts.


Why molforge exists

Modern protein work is multi-tool by nature. A real antibody-design loop might fold a sequence with ESMFold, identify CDR loops with anarci, score binding with FoldX, dock against a target with AutoDock Vina, relax with OpenMM, then evaluate with Rosetta. Each of those tools speaks its own dialect: different file formats, different atom-naming conventions, different ideas of what "the structure" is. Most of an engineer's day disappears into glue code.

molforge is the connective tissue. It provides:

  • A canonical, NumPy-backed data model that's cheap to convert in and out of — so every engine in your pipeline reads from and writes to the same representation.
  • Thin wrappers around the engines you already trust, with consistent interfaces (so swapping ESMFold for AlphaFold is one line, not a refactor).
  • First-class IO for the messy reality of structural-bio files: PDB, mmCIF, FASTA, PDBQT, PQR, SDF, MOL2, and AlphaFold predictions with pLDDT.
  • A plugin registry so the next docking engine, folding model, or scoring function can slot into your pipeline without forking molforge.

Built as a library, not a framework: there's no orchestrator, no DAG runtime, no decorators you have to import to make things work. Use whatever workflow tool you like — Snakemake, Nextflow, Prefect, a shell script — molforge is just imports.

Design principles

  1. Workflows over silos. Every design decision is judged by "does this make it easier to chain N tools together?"
  2. Wrappers, not reimplementations. We don't rebuild OpenMM or AutoDock. We give them a shared vocabulary.
  3. One data model, two views. Hierarchical (protein.chains["A"].residues[42]) for biology, linear (protein.atom_array.coords) for ML — same data, no conversion.
  4. Heterogeneous content is first-class. Antibodies have glycans. Drug targets have ligands and ions. Membrane proteins have lipids. The data model handles all of it without an awkward special case for "non-protein."
  5. Typed, tested, documented. Strict mypy, ruff-clean, >90% coverage target.

Installation

# minimal core (data model + sequence + basic IO)
pip install molforge

# with structure analysis (RMSD, SASA, contacts)
pip install "molforge[structure]"

# with ML wrappers (torch, transformers, esm)
pip install "molforge[ml]"

# with MD support (openmm, mdtraj)
pip install "molforge[md]"

# with structure prep for MD (pdbfixer + openmm)
pip install "molforge[prep]"

# with docking (rdkit for small molecules)
pip install "molforge[docking]"

# everything
pip install "molforge[all]"

# development
git clone https://github.com/DoctorDean/molforge.git
cd molforge
pip install -e ".[dev,all]"

Quickstart

The smallest end-to-end example that shows the cross-tool point:

import molforge as mf
from molforge.wrappers.folding import ESMFold
from molforge.wrappers.docking import Vina
from molforge.wrappers.md import OpenMM

# 1. Fold a sequence
folded = ESMFold().predict("MKTVRQERLKSIVRILERSKEPVSGAQLAEELSVS...")

# 2. Save as PDB, save as mmCIF, hand to anything
mf.save(folded, "candidate.pdb")
mf.save(folded, "candidate.cif")

# 3. Dock a ligand against it (Vina-prepared PDBQT files)
result = Vina().dock(
    receptor="receptor.pdbqt",
    ligand="ligand.pdbqt",
    center=(10.0, 5.0, -2.0),
    box_size=(20.0, 20.0, 20.0),
)
top_pose = result.best

# 4. Drop into MD for relaxation
trajectory = OpenMM().simulate(top_pose.complex, steps=10_000)

# 5. Inspect — hierarchical or linear, your call
print(folded.sequence)                            # one-letter per chain
print(folded.atom_array.coords.shape)             # (N, 3) NumPy array
ca = folded.chains["A"].residues[42].atoms["CA"]  # specific atom

Notice what isn't there: file-format conversions, atom-name remapping, hand-rolled PDB parsers, custom data classes per engine. molforge does that work so your script reads like the science you're actually doing.

Worked examples and walkthroughs (notebooks/):

Repository structure

molforge/
├── src/molforge/             # Library source (src-layout)
│   ├── core/                 # Hierarchical + linear data model, provenance
│   ├── sequence/             # Sequence operations, alignment, mutations
│   ├── structure/            # RMSD, SASA, contacts, DSSP, geometry
│   ├── md/                   # MD trajectories and analysis
│   ├── docking/              # Docking abstractions and pose handling
│   ├── ml/                   # ML utilities, featurizers, tensor views
│   ├── io/                   # PDB, mmCIF, FASTA, PDBQT, PQR, SDF, MOL2, fetch
│   ├── chem/                 # RDKit-backed molecules, descriptors, datasets
│   ├── prep/                 # MD system prep (clean, fix, protonate)
│   ├── ensembles/            # Conformer clustering, consensus, weighting
│   ├── validation/           # Composable design-acceptance criteria
│   ├── plugins/              # Plugin registry and entry-point discovery
│   ├── metrics/              # TM-score, lDDT, GDT-TS, DockQ
│   └── wrappers/             # Thin interfaces to external engines
│       ├── folding/          # ESMFold, AlphaFold, Boltz, Chai-1, RoseTTAFold
│       ├── docking/          # AutoDock Vina, Gnina, DiffDock
│       ├── md/               # OpenMM, GROMACS, AMBER
│       ├── generative/       # RFdiffusion, ProteinMPNN, ESM-IF1
│       ├── freeenergy/       # MM/PB(GB)SA, alchemlyb, cinnabar
│       └── pockets/          # fpocket
├── tests/                    # pytest suite (1,800+ tests)
│   ├── fixtures/pdb/         # synthetic mini_*.pdb + realistic real_*.pdb fixtures
│   ├── unit/                 # per-subpackage unit tests
│   ├── integration/          # end-to-end tests against the realistic fixtures
│   └── benchmarks/           # performance benchmarks (pytest -m benchmark)
├── docs/                     # Architecture docs and reference
├── notebooks/                # Walkthroughs and worked examples
├── plugins/                  # Example external plugins
├── pyproject.toml            # Build config, deps, tool config
└── ACKNOWLEDGEMENTS.md       # Prior art and intellectual debts

A deeper architecture walkthrough is in docs/architecture/overview.md.

Status

molforge is pre-1.0 and under active development. What's working today:

  • Core data modelProtein / Chain / Residue / Atom over a canonical NumPy-backed AtomArray, with first-class heterogeneous content (ligands, water, ions, modified residues).
  • File I/O — full read/write for PDB (NMR ensembles, altlocs, insertion codes), mmCIF, FASTA, PDBQT, PQR, SDF, and MOL2; an AlphaFold loader that surfaces pLDDT as a first-class field; trajectory I/O (XTC, TRR, DCD, NetCDF, HDF5 via mdtraj); and remote fetch from RCSB, AlphaFold DB, and ChEMBL, plus full-text PDB search.
  • Sequence operations — pairwise alignment (Needleman-Wunsch / Smith-Waterman with BLOSUM62 / PAM250), point mutations with protein-engineering notation (A123V, A123V/T56K, H:K42N), composition and property helpers (MW, GRAVY, aromaticity).
  • Structural analysis — Kabsch/Umeyama superposition, RMSD (whole-structure and per-residue, multiple atom subsets), contact and distance maps, radius of gyration, centroid / center of mass, in-place translate / rotate, DSSP secondary-structure assignment (8-state and 3-state, no external binary), SASA (Shrake-Rupley, no FreeSASA dependency), and backbone dihedrals (φ, ψ, ω, Ramachandran).
  • Validation utilitiesmolforge.validation orchestrates the "score designs across multiple validators and combine results" pattern. Declarative Criterion (composable with & / | / ~), CriteriaSet for per-criterion diagnostics, cross_validate to run designs through one or more validators, consensus to merge verdict lists ("ESMFold AND AlphaFold both pass" / "majority of validators pass" / threshold rules).
  • Evaluation metricsmolforge.metrics ships the standard structural-prediction metrics: TM-score (Zhang & Skolnick), GDT-TS / GDT-HA (CASP), lDDT (alignment-free, what AlphaFold's pLDDT estimates), and DockQ (Basu & Wallner, for protein-protein complexes). NumPy-only — no tmalign/lddt binaries required.
  • ML featurization — sequence featurizers (one-hot, BLOSUM/PAM, positional encoding), structure featurizers (RBF-binned distances, pair orientations, local environment), ESM-2 protein language model embeddings, and graph construction (to_graph → PyTorch Geometric / DGL).
  • Engine wrappers across six modalities, all behind consistent, swappable interfaces:
    • Folding — ESMFold, AlphaFold/ColabFold, Boltz, Chai-1, RoseTTAFold (with multi-component cofolding on Boltz and Chai-1).
    • Docking — AutoDock Vina (automatic meeko/RDKit prep), Gnina (CNN rescoring), DiffDock.
    • MD — OpenMM (full prepare → minimize → run), GROMACS, AMBER.
    • Generative design — RFdiffusion (backbones), ProteinMPNN and ESM-IF1 (sequence design). The full de novo design loop is in one library.
    • Binding free energy — MM/PB(GB)SA via AmberTools and gmx_MMPBSA; alchemlyb and cinnabar for FEP ingestion.
    • Pocket detection — fpocket.
  • Provenance and caching — every wrapper records a Provenance chain (engine, version, parameters, inputs, parent) on its output, and a content-addressed cache keyed on that chain skips recomputation and invalidates automatically when an upstream step changes.

Coming next: local MSA search (mmseqs2 / hmmer), parallel batch helpers (fold_many / dock_many), and higher-level design-loop tooling. See CHANGELOG.md for the full picture.

Acknowledgements

molforge is inspired by Protkit (SilicoGenesis), which pioneered the idea of a unified, hierarchical representation for protein structures in Python. molforge extends that direction toward cross-tool, cross-format workflows and a different internal architecture (NumPy-backed linear store, hierarchical views as accessors). See ACKNOWLEDGEMENTS.md for the longer list of projects we've learned from.

Contributing

We welcome contributions. See CONTRIBUTING.md and the Code of Conduct before opening an issue or PR.

Statement of need

Modern protein science is multi-tool by nature: a single study may fold a sequence with one deep-learning model, dock a ligand with another engine, relax the complex with molecular dynamics, design new sequences generatively, and score the result with a learned potential. Each tool speaks its own dialect — different file formats, atom-naming conventions, and notions of what "the structure" is — so much of a researcher's time goes into format conversion and glue code, and workflows are rarely reproducible end to end.

Biopython, Biotite, MDAnalysis, and RDKit each solve part of this, but none offers a single data model spanning the current engine landscape — deep-learning folding, diffusion docking and design, classical docking, and MD — together with the provenance and reproducibility a multi-engine workflow needs. molforge fills that gap: one canonical Protein representation that every wrapped engine reads and writes, a from-scratch analysis stack validated against independent reference implementations, and first-class provenance that emits a citable, re-executable pipeline.yaml. It is a library, not a framework — plain imports, usable inside Snakemake, Nextflow, a notebook, or a shell script.

License

MIT — see LICENSE.

Citation

If you use molforge in academic work, please cite us (BibTeX coming with the first tagged release).

Releases

Packages

Used by

Contributors

Languages