Skip to main content

Modern Python framework for molecular simulation and analysis

Project description

MolPy — A programmable toolkit for molecular simulation workflows

Python License Docs CI Ruff Type checked: ty

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 Source-introspection MCP server provided by the molmcp gateway (local or hosted)

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


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


Download files

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

Source Distribution

molcrafts_molpy-0.3.2.tar.gz (546.1 kB view details)

Uploaded Source

Built Distribution

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

molcrafts_molpy-0.3.2-py3-none-any.whl (648.7 kB view details)

Uploaded Python 3

File details

Details for the file molcrafts_molpy-0.3.2.tar.gz.

File metadata

  • Download URL: molcrafts_molpy-0.3.2.tar.gz
  • Upload date:
  • Size: 546.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for molcrafts_molpy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d2c8a61f464aab133b3bb633de5a10cc8a80de445f5ae0401afcaa753d38825e
MD5 d95856d6c9fd185629c621926120232d
BLAKE2b-256 f5f41781b10387f2d8ec5b8f7cdc1aeb2aabfa71a2a12f750bd265c800d0e6f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for molcrafts_molpy-0.3.2.tar.gz:

Publisher: release.yml on MolCrafts/molpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file molcrafts_molpy-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: molcrafts_molpy-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 648.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for molcrafts_molpy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 697bc8ebf38d997fedbd2623dffd97ce3f96e4ec66d99dcb29d7bee922b73d2e
MD5 910ed3a98943b01bf1b61b860e59969e
BLAKE2b-256 5325f330e227f85fb10886c2767409bd34839fc1e04f14de88a7bf1ca38a4e6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for molcrafts_molpy-0.3.2-py3-none-any.whl:

Publisher: release.yml on MolCrafts/molpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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