A programmable toolkit for molecular simulation workflows
MolPy is a Python toolkit for the full molecular-system workflow — parsing, building, editing, typing, analyzing, and reading/writing simulation formats. Packing a box is the job of the companion package molpack.
Under active development. Public APIs may change between minor releases.
Molecular modeling is fragmented. Every simulation code has its own file formats and conventions; every task — parsing, building, typing, analysis, visualization — lives in a separate library; and moving a system between them means writing throwaway glue.
molpy aims to be the common foundation beneath that workflow: one explicit, programmable representation of a molecular system that every stage can share. Parse a structure into it, build on it, type and analyze it — then hand the same object onward, with no conversion step in between.
That representation is meant to be built on, not just used. It is the data model the MolCrafts ecosystem extends — visualization, experiment management, agent access — and it reads the same whether a human writes it or an agent calls it.
Each row is one src/molpy/ module — parse or build a structure, edit and type
it, analyze or minimize it, then read and write it across formats.
| Module | Capability |
|---|---|
core |
Explicit data model — editable Atomistic topology graph, Frame/Block columnar arrays, ForceField, Box |
parser |
SMILES / SMARTS (SmilesIR, SmartsPattern) |
builder |
System assembly — polymer planning and polydispersity, nanostructures, crystals, virtual sites; site-graph assembly (mp.Assembler) is native, on the molpy root |
conformer |
3D coordinate generation (native ETKDG + MMFF cleanup) |
typifier |
Force-field typing — OPLS-AA and MMFF94 (native), GAFF / GAFF2 via AmberTools |
potential · optimize |
Energy & force potentials with L-BFGS minimization |
compute |
Analysis under molpy.compute — rdf/msd/pmsd/jacf/order/voronoi/… modules, plus dielectric and vibrational-spectrum classes on the package itself (native kernels) |
io |
Read/write — PDB, GRO, LAMMPS data, XYZ, force fields, trajectories, … |
engine |
MD input generation & run management — LAMMPS, CP2K, OpenMM |
wrapper · adapter |
External CLIs (Antechamber, tleap, …) and optional RDKit in-memory bridge |
pip install molcrafts-molpy
# Browser (Pyodide) — needs molcrafts-molrs Pyodide wheel on PyPI:
# await micropip.install("molcrafts-molrs")
# await micropip.install("molcrafts-molpy")Core dependencies: NumPy and
molrs (molcrafts-molrs>=0.15.0,<0.16)
plus the MolCrafts logging/config packages. Optional: RDKit (adapter example),
AmberTools (GAFF charges).
Until molrs 0.15.0 is published. molpy 0.15 needs molrs 0.15, which is not on PyPI yet, so
pip installcannot resolve it. Install from source instead: clone molrs next to molpy (the two checkouts side by side in one directory) and runuv syncin molpy (see Install from source (development) below).uvbuilds molrs from the sibling checkout named in[tool.uv.sources];pipignores that path source, so it does not work for this step.
Nightly builds. Bleeding-edge snapshots are published to the separate project
molcrafts-molpy-nightly(versionedX.Y.Z.devN) on every push to thenightlybranch. Install withpip install --pre molcrafts-molpy-nightly. It imports asmolpy, so it cannot be installed alongside the stablemolcrafts-molpy(same astensorflowvstf-nightly).
Install from source (development)
git clone https://github.com/MolCrafts/molrs.git # sibling checkout, see below
git clone https://github.com/MolCrafts/molpy.git
cd molpy
uv sync --extra dev
pre-commit install --hook-type pre-commit --hook-type pre-push
# the two gates (same as the hooks / CI):
uv run --no-project --with 'tox>=4.23' --with ruff==0.16.1 --with ty==0.0.65 tox -e lint
uv run --extra dev python -m pytest tests/ -n auto[tool.uv.sources] points molcrafts-molrs at the sibling checkout
../molrs/molrs-python, so uv sync builds the Rust core with your toolchain
(rustup). After editing molrs, rebuild what uv
installed:
uv sync --extra dev --reinstall-package molcrafts-molrsSee docs/developer/development-setup for the full workflow.
Parse a SMILES string, assign OPLS-AA types, and write LAMMPS input files:
import molpy as mp
from pathlib import Path
mol = mp.SmilesIR("CCO").to_atomistic() # ethanol from SMILES
mol3d, _ = mp.Conformer(seed=42).generate(mol) # hydrogens + 3D coordinates
typifier = mp.typifier.OPLSAATypifier() # carries the OPLS-AA library
typed = typifier.typify(mol3d)
ff = typifier.forcefield() # parameters of the assigned types
system = typed.to_frame()
system.box = mp.Box.cube(30.0)
system["atoms"]["mol_id"] = mp.Topology.from_frame(system).connected_components() + 1
# the pair cutoff is a run setting: you declare it, molpy never invents one
ff.get_style("pair", "lj/cut")["cutoff"] = 10.0
ff.get_style("pair", "coul/cut")["cutoff"] = 10.0
out = Path("output"); out.mkdir(exist_ok=True)
mp.io.write_lammps_data(out / "system.data", system)
mp.io.write_lammps_forcefield(out / "system.ff", ff, system)More workflows — packed solvent boxes, virtual-site models, polymer chains and networks (the stress test for MolPy's editing machinery), AmberTools parameterization — are in the Example Gallery and the task-oriented Guides.
Full documentation, including executable notebooks: docs.molcrafts.org/molpy
- Getting Started — install and first example
- Example Gallery — short copy-paste workflows
- Guides — task-oriented notebooks
- Concepts — data model deep dives
- API Reference — full API
| Project | Role |
|---|---|
| molpy | Python toolkit — the shared molecular data model & workflow layer — this repo |
| molrs | Rust core — molecular data structures & compute kernels (native + WASM) |
| molpack | Packmol-grade molecular packing (Rust + Python) |
| molvis | WebGL molecular visualization & editing |
| molexp | Workflow & experiment-management platform |
| molnex | Molecular machine-learning framework |
| molq | Unified job queue — local / SLURM / PBS / LSF |
| molcfg | Layered configuration library |
| mollog | Structured logging, stdlib-compatible |
| molhub | Molecular dataset hub |
| molmcp | MCP server for the ecosystem |
| molrec | Atomistic record specification |
Issues and pull requests are welcome — see Contributing.
BSD-3-Clause — see LICENSE.