Skip to main content

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):

  1. env vars → 2) ~/.config/mbe-tools/config.toml → 3) ./mbe.toml → 4) explicit load_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)

  1. 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)
  1. 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)
  1. 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)
  1. 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
  1. 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
  1. Parse outputs to JSONL
mbe parse ./Output --program auto --glob "*.out" --out parsed.jsonl
  1. 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, else mbe.control.toml, else run-control disabled.
  • Attempt logging: write job._try.out; on failure rename to job.attemptN.out; on success rename to job.out. confirm.log_path can override temp log location.
  • Confirmation: confirm.regex_any (must match) and confirm.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 to failed_last_path).
  • Delete safeguards: delete.enabled + allow_delete_outputs=true to delete outputs; inputs removed only if matched by delete_inputs_globs.
  • State: .mbe_state.json records status, attempts, matched regex, log paths; skip_if_done skips 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 exposes subset_indices as 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

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


Download files

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

Source Distribution

mbe_tools-0.1.1.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

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

mbe_tools-0.1.1-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

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

Hashes for mbe_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 832d8d55630041960c354b8ad4578ff0fcc38caf0041cbe4f165c946b8dfc16a
MD5 1513945b8320d20f965c925758fb0a9d
BLAKE2b-256 24089addb397c83d165340074a4308dca3fa392a818b7bf81c6fcf0d5e66aa25

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbe_tools-0.1.1.tar.gz:

Publisher: publish-pypi.yml on JiaruiUNSW/mbe-tools

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

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

Hashes for mbe_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1992c590705f84341ba03205810e866e2ce2c09b17a06b183b934a6a2795f1b
MD5 a7cc462852393d899540e92f0eedbb28
BLAKE2b-256 e115c0a6c906921b2d6fcf9fd37642883185d09302366b22b1a3b236c259aeb1

See more details on using hashes here.

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

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