molcrafts-molpack
Packmol-grade molecular packing in pure Rust, with Python bindings. Part of the molrs toolkit.
Install
CLI
Rust library
Python
CLI
The molpack binary accepts the same .inp script format as Packmol, making it a drop-in replacement. Relative file paths in the script are resolved against the script's own directory (file-arg mode) or the current directory (stdin mode).
# File argument (paths resolved relative to the .inp file's directory)
# Stdin — compatible with Packmol usage
|
Supported .inp keywords
| Keyword | Description |
|---|---|
tolerance <f> |
Minimum atom–atom distance (Å). Default 2.0 |
seed <n> |
Random seed for reproducibility |
filetype <fmt> |
Input format for all structure files |
output <path> |
Output file path (format inferred from extension) |
nloop <n> |
Maximum outer-loop iterations. Default 400 |
pbc x y z / pbc x0 y0 z0 x1 y1 z1 |
Periodic box: side lengths from origin, or explicit min+max |
avoid_overlap <no|false|0> |
Reject initial placements that land inside a fixed molecule (default on; faithful to Packmol's initial.f90) |
structure <file> … end structure |
One block per molecule type |
number <n> |
Copies to pack |
inside|outside box x0 y0 z0 x1 y1 z1 |
Axis-aligned box restraint |
inside|outside cube x0 y0 z0 d |
Axis-aligned cube (origin corner + side) |
inside|outside sphere cx cy cz r |
Sphere restraint |
inside|outside ellipsoid a1 a2 a3 b1 b2 b3 c |
Ellipsoid (center, semi-axes, exponent) |
inside|outside cylinder a1 a2 a3 d1 d2 d3 r l |
Finite cylinder (center, axis, radius, length) |
over|above plane nx ny nz d |
Half-space (above) restraint |
below plane nx ny nz d |
Half-space (below) restraint |
center |
Center molecule at origin before packing |
fixed x y z ex ey ez |
Fix molecule at position + Euler angles |
atoms i j … … end atoms |
Per-atom-subset restraints |
All 12 box/cube/sphere/ellipsoid/cylinder/plane restraints are reachable from
both whole-molecule and atoms … end atoms blocks. The Gaussian-surface
restraints (AboveGaussianRestraint / BelowGaussianRestraint) are available
through the Rust/Python API but not yet exposed as .inp keywords. To drive a
whole species onto a target spatial distribution, use the collective
ProfileMatch restraint via the Rust/Python API (with_collective_restraint).
Extended format support — beyond Packmol's PDB/XYZ, molpack also reads SDF/MOL, LAMMPS dump, and LAMMPS data files. Set filetype to sdf, lammps_dump, or lammps_data, or use the matching file extension:
| Format | Read | Write | Extension / filetype |
|---|---|---|---|
| PDB | ✓ | ✓ | .pdb / pdb |
| XYZ | ✓ | ✓ | .xyz / xyz |
| SDF / MOL | ✓ | — | .sdf, .mol / sdf |
| LAMMPS dump | ✓ | ✓ | .lammpstrj / lammps_dump |
| LAMMPS data | ✓ | — | .data / lammps_data |
Quick start
Rust
use ;
let positions = ;
let radii = ;
let target = from_coords
.with_name
.with_restraint;
// `pack` returns the packed, topology-complete `molrs::Frame`.
// Every tuning knob has a Packmol-matching default, so `new().pack(...)`
// is a complete call; `200` is the outer-loop budget.
let frame = new.pack?;
// For full diagnostics, use `pack_with_report` → `PackResult`
// (`frame`, `fdist`, `frest`, `converged`).
let report = new.pack_with_report?;
Python
=
=
=
Examples
Five canonical workloads ship in examples/ (they need the io feature
to read the bundled structure files):
The same workloads run through the CLI from their bundled .inp scripts,
e.g. cargo run --release --features cli --bin molpack -- examples/pack_mixture/mixture.inp.
Python equivalents are in python/examples/.
A measurement harness also lives under examples/: mt_scaling (parallel
speed-up-vs-size sweep, needs --features rayon).
Testing
&& &&
Documentation
- Guide — the Markdown chapters under
docs/: install, getting started, concepts, examples, Packmol parity, architecture, and extending. - Rust API —
cargo doc --open, or docs.rs. The four long-form chapters (getting started, concepts, architecture, extending) are also embedded in the rustdoc asmolpack::getting_started,molpack::concepts,molpack::architecture, andmolpack::extending. - Python — the binding docs under
docs/python/(installation, guide, examples, and the Python API reference), published as the Python section of the same Zensical site.
Contributing
See CONTRIBUTING.md. Bugs and feature requests via GitHub Issues.
License
BSD-3-Clause
References
- Martínez, L.; Andrade, R.; Birgin, E. G.; Martínez, J. M. PACKMOL: A package for building initial configurations for molecular dynamics simulations. J. Comput. Chem. 2009, 30 (13), 2157–2164. https://doi.org/10.1002/jcc.21224