Modern Python framework for molecular simulation and analysis
Project description
MolPy — A programmable toolkit for molecular simulation workflows
MolPy is under active development. Public APIs may change between minor releases.
MolPy is a Python toolkit for building, editing, typing, and exporting molecular systems. It keeps topology, force fields, numerical frames, and engine I/O explicit and composable in Python.
Polymer construction and reactive topology editing are core strengths, but MolPy is built for broader molecular simulation workflows, from system preparation and topology transformation to force-field assignment and export.
Representative Workflows
Small molecule — parse, type, export:
import molpy as mp
mol = mp.parser.parse_molecule("CCO") # ethanol from SMILES
ff = mp.io.read_xml_forcefield("oplsaa.xml") # bundled OPLS-AA
typed = mp.typifier.OplsAtomisticTypifier(ff).typify(mol)
mp.io.write_lammps_system("output/", typed.to_frame(), ff)
# → output/system.data output/system.in
Polymer chain — G-BigSMILES to LAMMPS in one call:
import molpy as mp
# PEO chain with degree of polymerization = 10, built with 3D coordinates
peo = mp.tool.polymer("{[<]CCOCC[>]}|10|")
ff = mp.io.read_xml_forcefield("oplsaa.xml")
typed = mp.typifier.OplsAtomisticTypifier(ff).typify(peo)
mp.io.write_lammps_system("output/", typed.to_frame(), ff)
Polydisperse melt — Schulz-Zimm distribution, fully atomistic:
import molpy as mp
# Mn = 1500 Da, Mw = 3000 Da, total mass ≈ 500 kDa
chains = mp.tool.polymer_system(
"{[<]CCOCC[>]}|schulz_zimm(1500,3000)||5e5|",
random_seed=42,
)
print(f"Built {len(chains)} chains") # reproducible chain population
frames = [c.to_frame() for c in chains]
packed = mp.pack.pack(frames, box=[80, 80, 80])
mp.io.write_lammps_system("peo_bulk/", packed, ff)
AmberTools pipeline — GAFF2 parameters, partial charges, AMBER topology:
import molpy as mp
eo = mp.tool.PrepareMonomer().run("{[<]CCOCC[>]}") # BigSMILES → 3D + ports
result = mp.tool.polymer(
"{[#EO]|20}",
library={"EO": eo},
backend="amber", # runs antechamber + parmchk2 + tleap
)
# result.prmtop_path, result.inpcrd_path, result.pdb_path
Core Capabilities
| Area | Capability |
|---|---|
| Parsing | Native support for SMILES, BigSMILES, CGSmiles, and G-BigSMILES |
| Polymer construction | Linear, branched, and cyclic assembly from notation-driven specifications |
| Polydispersity | Schulz-Zimm, Poisson, Flory-Schulz, and uniform chain-length distributions |
| Reactive topology editing | Anchor and leaving-group selectors, bond-forming reactions, and LAMMPS fix bond/react template generation |
| Force-field assignment | OPLS-AA and GAFF/GAFF2 typing through SMARTS/SMIRKS matching |
| External parameterization | AmberTools interfaces for antechamber, parmchk2, prepgen, and tleap |
| Packing and export | Packmol-based packing and export to LAMMPS, PDB, XYZ, AMBER, GRO, and HDF5 |
| Simulation interfaces | Input generation for LAMMPS and CP2K |
| Interoperability | RDKit and OpenBabel adapters for conversion and structure preparation |
| Explicit data model | Distinct Atomistic, Frame/Block, and ForceField representations |
| Agent interface | Optional MCP server exposing source symbols and documentation to large language model agents |
Architecture
SMILES / BigSMILES / CGSmiles / G-BigSMILES
│
▼ parser
Atomistic ← editable graph: Atom, Bond, Angle, Dihedral
(topology graph)
│
┌──────┴──────┐
▼ ▼
reacter builder ← reactions, polymer assembly
└──────┬──────┘
│
▼ typifier
Typed Atomistic ← SMARTS pattern matching assigns ForceField types
│
▼ .to_frame()
Frame ← columnar NumPy arrays; Box; metadata
│
┌──────┴──────┐
▼ ▼
pack io / engine ← Packmol packing; LAMMPS / CP2K / AMBER export
Each boundary is an explicit function call. State transitions remain visible throughout the workflow; no hidden coupling or monkey-patching is required.
Installation
pip install molcrafts-molpy
Core dependencies: NumPy, igraph, Lark. Optional: RDKit (3D geometry), AmberTools (GAFF charges).
For development:
git clone https://github.com/MolCrafts/molpy.git
cd molpy
pip install -e ".[dev]"
pre-commit install
pytest tests/ -m "not external"
Documentation
Full documentation, including executable notebooks: https://molcrafts.github.io/molpy
- Getting Started — install and first example
- Guides — task-oriented notebooks
- Concepts — data model deep dives
- API Reference — full API
MolCrafts Ecosystem
| Project | Role |
|---|---|
| MolPy | Python toolkit — this repo |
| MolVis | WebGL molecular visualization and interactive editing |
| MolRS | Rust backend: typed array structures and fast compute kernels (native + WASM) |
Contributing
Issues and pull requests are welcome. See Contributing.
License
BSD-3-Clause — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file molcrafts_molpy-0.3.0.tar.gz.
File metadata
- Download URL: molcrafts_molpy-0.3.0.tar.gz
- Upload date:
- Size: 510.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b44fd266e346bb43bc49c2cb8e695dd13486f5e6c84929a06087eabbcb8875b7
|
|
| MD5 |
d3f8cad74a19e09a54cbc449f8d2e531
|
|
| BLAKE2b-256 |
d591d33970330f0c52962b2ff73ec7f4d124563f0b80504eb011fe3c77fd4e0b
|
Provenance
The following attestation bundles were made for molcrafts_molpy-0.3.0.tar.gz:
Publisher:
release.yml on MolCrafts/molpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
molcrafts_molpy-0.3.0.tar.gz -
Subject digest:
b44fd266e346bb43bc49c2cb8e695dd13486f5e6c84929a06087eabbcb8875b7 - Sigstore transparency entry: 1279585577
- Sigstore integration time:
-
Permalink:
MolCrafts/molpy@f9cb940d376686edd716a8e83fea07ae1b97664c -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/MolCrafts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f9cb940d376686edd716a8e83fea07ae1b97664c -
Trigger Event:
push
-
Statement type:
File details
Details for the file molcrafts_molpy-0.3.0-py3-none-any.whl.
File metadata
- Download URL: molcrafts_molpy-0.3.0-py3-none-any.whl
- Upload date:
- Size: 602.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c5923c30ba0e56bbcb8ed32813f58ccfd374916a2bc92c587371fbe49270826
|
|
| MD5 |
0581bb250b286abd275ec0559cb4ab64
|
|
| BLAKE2b-256 |
d4789627348b8a65cd23fdc41940e7d03a57ae207da759554da1bd9a49011992
|
Provenance
The following attestation bundles were made for molcrafts_molpy-0.3.0-py3-none-any.whl:
Publisher:
release.yml on MolCrafts/molpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
molcrafts_molpy-0.3.0-py3-none-any.whl -
Subject digest:
9c5923c30ba0e56bbcb8ed32813f58ccfd374916a2bc92c587371fbe49270826 - Sigstore transparency entry: 1279585655
- Sigstore integration time:
-
Permalink:
MolCrafts/molpy@f9cb940d376686edd716a8e83fea07ae1b97664c -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/MolCrafts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f9cb940d376686edd716a8e83fea07ae1b97664c -
Trigger Event:
push
-
Statement type: