A practical toolkit for Many-Body Expansion (MBE) workflows: cluster design, MBE input generation, output parsing, and analysis.
Project description
mbe-tools
mbe-tools is a Python package that covers the full Many-Body Expansion (MBE) loop:
- Cluster design: read
.xyz, extract fragments, and sample subsets (with optional ion retention). - MBE job prep: generate subset geometries, build Q-Chem/ORCA inputs, and emit PBS/Slurm job scripts (with optional chunked submission).
- Parsing: read ORCA / Q-Chem outputs, infer method/basis/grid metadata from paths or companion inputs, and write JSONL.
- Analysis: inclusion–exclusion MBE(k), summaries, CSV/Excel export, and basic plots.
Status: 0.1.0 (MVP). Backend syntax (e.g., ghost atoms) may need local tweaks.
What changed (P0–P5)
- P0: Settings loader and precedence (
mbe.toml, env vars) for commands/modules/scratch/queue hints. - P1: Parser auto-detects program and infers method/basis/grid metadata from paths; emits detection + error tags.
- P2: Spatial fragment sampling mode with centroid-based compact selection and ion retention.
- P3: Connectivity-driven fragmentation and fragment labeling (water/methanol/ethanol/benzene/ions).
- P4: Tunable MBE params and input builders (thresh/tole/scf, grid) exposed in CLI.
- P5: Run-control for PBS/Slurm templates (regex confirmation, retries/cleanup, optional delete, state JSON).
Install (editable for development)
cd mbe-tools
python -m pip install -e .[analysis,cli]
Global settings (P0)
Configure default commands/modules/scratch once and reuse across CLI calls. Precedence (lowest → highest): environment variables → ~/.config/mbe-tools/config.toml → ./mbe.toml → explicit path passed to load_settings(path=...).
Supported keys: qchem_command, orca_command, qchem_module, orca_module, scratch_dir, scheduler_queue, scheduler_partition, scheduler_account.
Environment variable map: MBE_QCHEM_CMD, MBE_ORCA_CMD, MBE_QCHEM_MODULE, MBE_ORCA_MODULE, MBE_SCRATCH, MBE_SCHED_QUEUE, MBE_SCHED_PARTITION, MBE_SCHED_ACCOUNT.
Minimal mbe.toml example (edit paths/modules to your site):
qchem_command = "/opt/qchem/bin/qchem"
orca_command = "/opt/orca/bin/orca"
qchem_module = "qchem/5.2.2"
orca_module = "orca/5.0.3"
scratch_dir = "/scratch/${USER}"
scheduler_queue = "normal" # PBS
scheduler_partition = "work" # Slurm
scheduler_account = "proj123"
mbe-tools (v0.1.1)
mbe-tools is a Python toolkit for the Many-Body Expansion (MBE) workflow:
- Cluster handling: read
.xyz, fragment (water heuristic or connectivity + labels), and sample fragments (random/spatial, ion-aware). - Job prep: generate subset geometries, render Q-Chem/ORCA inputs, and emit PBS/Slurm scripts (supports chunked submission with run-control).
- Parsing: read ORCA/Q-Chem outputs, auto-detect program, infer method/basis/grid metadata, emit JSONL.
- Analysis: inclusion–exclusion MBE(k), summaries, CSV/Excel export, and quick plots.
Status: v0.1.1 (MVP) — backend syntax (e.g., ghost atoms) can be customized per site. License: MIT.
Install (editable for development)
cd mbe-tools
python -m pip install -e .[analysis,cli]
Settings precedence (P0)
Configure default commands/modules/scratch once and reuse across CLI calls. Precedence (low → high):
- env vars → 2)
~/.config/mbe-tools/config.toml→ 3)./mbe.toml→ 4) explicitload_settings(path=...).
Keys: qchem_command, orca_command, qchem_module, orca_module, scratch_dir, scheduler_queue, scheduler_partition, scheduler_account.
Env map: MBE_QCHEM_CMD, MBE_ORCA_CMD, MBE_QCHEM_MODULE, MBE_ORCA_MODULE, MBE_SCRATCH, MBE_SCHED_QUEUE, MBE_SCHED_PARTITION, MBE_SCHED_ACCOUNT.
Minimal mbe.toml:
qchem_command = "/opt/qchem/bin/qchem"
orca_command = "/opt/orca/bin/orca"
qchem_module = "qchem/5.2.2"
orca_module = "orca/5.0.3"
scratch_dir = "/scratch/${USER}"
scheduler_queue = "normal"
scheduler_partition = "work"
scheduler_account = "proj123"
Quickstart (Python API)
- Fragment an XYZ
from mbe_tools.cluster import read_xyz, fragment_by_water_heuristic, fragment_by_connectivity
xyz = read_xyz("Water20.xyz")
frags = fragment_by_water_heuristic(xyz, oh_cutoff=1.25)
frags_conn = fragment_by_connectivity(xyz, scale=1.2)
- Sample and write XYZ
from mbe_tools.cluster import sample_fragments, write_xyz
picked = sample_fragments(frags, n=10, seed=42)
write_xyz("Water10_sample.xyz", picked)
- Generate subset geometries
from mbe_tools.mbe import MBEParams, generate_subsets_xyz
params = MBEParams(max_order=3, cp_correction=True, backend="qchem")
subset_jobs = list(generate_subsets_xyz(frags, params)) # (job_id, subset_indices, geom_text)
- Build inputs
mbe build-input water.geom --backend qchem --method wb97m-v --basis def2-ma-qzvpp --out water_qchem.inp
mbe build-input water.geom --backend orca --method wb97m-v --basis def2-ma-qzvpp --out water_orca.inp
- Emit PBS/Slurm templates (run-control included)
mbe template --scheduler pbs --backend qchem --job-name mbe-qchem --chunk-size 20 --out qchem.pbs
mbe template --scheduler slurm --backend orca --job-name mbe-orca --partition work --chunk-size 10 --out orca.sbatch
- Parse outputs to JSONL
mbe parse ./Output --program auto --glob "*.out" --out parsed.jsonl
- Analyze JSONL
mbe analyze parsed.jsonl --to-csv results.csv --to-xlsx results.xlsx --plot mbe.png
CLI cheat sheet
mbe fragment <xyz>: water-heuristic fragmentation + sampling → XYZ. Options:--out-xyz [sample.xyz],--n [10],--seed,--require-ion,--mode [random|spatial], spatial extras--prefer-special,--k-neighbors,--start-index,--oh-cutoff.mbe gen <xyz>: generate subset geometries. Options:--out-dir [mbe_geoms],--max-order [2],--order/--orders,--cp/--no-cp,--scheme,--backend [qchem|orca],--oh-cutoff.mbe build-input <geom>: render Q-Chem/ORCA input. Options for backend, method, basis (required), charge/multiplicity, Q-Chem (--thresh,--tole,--scf-convergence,--rem-extra), ORCA (--grid,--scf-convergence,--keyword-line-extra),--out.mbe template: PBS/Slurm scripts with run-control wrapper. Shared:--scheduler [pbs|slurm],--backend [qchem|orca],--job-name,--walltime,--mem-gb,--chunk-size,--module,--command,--out; PBS+qchem adds--ncpus,--queue,--project; Slurm+orca adds--ncpus(cpus-per-task),--ntasks,--partition,--project(account),--qos.mbe parse <root>: outputs → JSONL. Options:--program [auto|qchem|orca],--glob-pattern,--out,--infer-metadata.mbe analyze <parsed.jsonl>: summaries/exports. Options:--to-csv,--to-xlsx,--plot,--scheme [simple|strict],--max-order.
Use mbe <command> --help for full flags.
Run-control (templates)
- Control file discovery: prefer
<input>.mbe.control.toml, elsembe.control.toml, else run-control disabled. - Attempt logging: write
job._try.out; on failure rename tojob.attemptN.out; on success rename tojob.out.confirm.log_pathcan override temp log location. - Confirmation:
confirm.regex_any(must match) andconfirm.regex_none(must not match) on the temp log; success also requires exit code 0. - Retry:
retry.enabled,max_attempts,sleep_seconds,cleanup_globs,write_failed_last(copy last attempt tofailed_last_path). - Delete safeguards:
delete.enabled+allow_delete_outputs=trueto delete outputs; inputs removed only if matched bydelete_inputs_globs. - State:
.mbe_state.jsonrecords status, attempts, matched regex, log paths;skip_if_doneskips reruns when marked done.
Subset naming
- Recommended:
{backend}_k{order}_f{i1}-{i2}-{i3}_{cp|nocp}_{hash}with 0-based fragment indices (zero-padding allowed), e.g.,qchem_k2_f000-003_cp_deadbeef.out. - Legacy (still parsed):
{backend}_k{order}_{i1}.{i2}..._{hash}treated as 1-based in the name but converted to 0-based internally. JSON always exposessubset_indicesas 0-based.
JSONL schema (parse output)
{
"job_id": "qchem_k2_f000-003_cp_deadbeef",
"program": "qchem",
"program_detected": "qchem",
"status": "ok",
"error_reason": null,
"path": ".../job.out",
"energy_hartree": -458.7018184,
"cpu_seconds": 1234.5,
"wall_seconds": 1234.5,
"method": "wB97M-V",
"basis": "def2-ma-QZVPP",
"grid": "SG-2",
"subset_size": 2,
"subset_indices": [0, 2],
"cp_correction": true,
"extra": {}
}
API highlights
- Cluster (src/mbe_tools/cluster.py):
read_xyz,write_xyz,fragment_by_water_heuristic,fragment_by_connectivity,sample_fragments,spatial_sample_fragments. - MBE generation (src/mbe_tools/mbe.py):
MBEParams,generate_subsets_xyz,qchem_molecule_block,orca_xyz_block. - Input builders (src/mbe_tools/input_builder.py):
render_qchem_input,render_orca_input,build_input_from_geom. - HPC templates (src/mbe_tools/hpc_templates.py):
render_pbs_qchem,render_slurm_orca(both embed run-control wrapper). - Parsing (src/mbe_tools/parsers/io.py):
detect_program,parse_files,infer_metadata_from_path,glob_paths. - Analysis (src/mbe_tools/analysis.py):
read_jsonl,summarize_by_order,compute_delta_energy,strict_mbe_orders.
Notebook
See notebooks/sample_walkthrough.ipynb for an end-to-end demo: build inputs, generate templates, and assemble MBE(k) energies from synthetic data.
License
MIT "cpu_seconds": 1234.5,
"wall_seconds": 1234.5,
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 mbe_tools-0.1.1.tar.gz.
File metadata
- Download URL: mbe_tools-0.1.1.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
832d8d55630041960c354b8ad4578ff0fcc38caf0041cbe4f165c946b8dfc16a
|
|
| MD5 |
1513945b8320d20f965c925758fb0a9d
|
|
| BLAKE2b-256 |
24089addb397c83d165340074a4308dca3fa392a818b7bf81c6fcf0d5e66aa25
|
Provenance
The following attestation bundles were made for mbe_tools-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on JiaruiUNSW/mbe-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mbe_tools-0.1.1.tar.gz -
Subject digest:
832d8d55630041960c354b8ad4578ff0fcc38caf0041cbe4f165c946b8dfc16a - Sigstore transparency entry: 814558368
- Sigstore integration time:
-
Permalink:
JiaruiUNSW/mbe-tools@d5412b8d72de3e14ceb4019e827cf674c1143fe9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/JiaruiUNSW
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d5412b8d72de3e14ceb4019e827cf674c1143fe9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mbe_tools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mbe_tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1992c590705f84341ba03205810e866e2ce2c09b17a06b183b934a6a2795f1b
|
|
| MD5 |
a7cc462852393d899540e92f0eedbb28
|
|
| BLAKE2b-256 |
e115c0a6c906921b2d6fcf9fd37642883185d09302366b22b1a3b236c259aeb1
|
Provenance
The following attestation bundles were made for mbe_tools-0.1.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on JiaruiUNSW/mbe-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mbe_tools-0.1.1-py3-none-any.whl -
Subject digest:
d1992c590705f84341ba03205810e866e2ce2c09b17a06b183b934a6a2795f1b - Sigstore transparency entry: 814558370
- Sigstore integration time:
-
Permalink:
JiaruiUNSW/mbe-tools@d5412b8d72de3e14ceb4019e827cf674c1143fe9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/JiaruiUNSW
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d5412b8d72de3e14ceb4019e827cf674c1143fe9 -
Trigger Event:
push
-
Statement type: