Skip to main content

Incremental Rust/Python geometry kernels for MOF checking

Project description

mofchecker-next

A fast, drop-in replacement for MOFChecker 2.0 — same diagnostics, same API, ~12× faster on the geometric diagnostics (~7× with open-metal-site detection), built on Rust kernels and rustworkx graph algorithms.

CI PyPI Python versions License Speedup Built with Rust

Designed for the workloads where the original is painful: validating thousands of model-generated MOFs (e.g. from a diffusion model), where the slow paths — floating-solvent extraction and dimensionality — dominate.

💪 Getting started

from mofchecker_next import MOFChecker

mc = MOFChecker.from_cif("structure.cif")     # also .from_ase(atoms) / MOFChecker(structure)
mc.has_atomic_overlaps, mc.has_lone_molecule, mc.has_oms, mc.metal_number
descriptors = mc.get_mof_descriptors()        # OrderedDict of every diagnostic

Validating many structures? mofchecker_next.batch parallelizes across structures, builds each graph once, and never aborts the run on a single bad structure:

from mofchecker_next.batch import check_structures

# inputs may be CIF paths, pymatgen Structures, ASE Atoms, or a mix
results = check_structures(inputs, n_workers=16)          # all CPUs by default
bad = [r for r in results if r["has_atomic_overlaps"]]

# subset to skip work: composition-only descriptors skip graph construction entirely
fast = check_structures(inputs, descriptors=["has_atomic_overlaps", "has_overcoordinated_c"])

Each result is a dict with index, id, n_atoms, and the requested descriptors. DEFAULT_DESCRIPTORS is the in-scope diagnostic suite (including bit-exact has_high_charges); ALL_DESCRIPTORS adds metadata, symmetry, and graph hashes. A structure that fails gets an error field (on_error="record") instead of aborting the batch.

🚀 Installation

pip install mofchecker-next

Latest from source (needs a Rust toolchain):

pip install git+https://github.com/henk789/mofchecker-next.git

✨ Why use it

  • Fast. On 150-atom QMOF MOFs, the geometric diagnostic set runs in ~101 ms/structure single-core vs ~1.20 s for MOFChecker 2.0 (~12×); ~77 structures/s across 10 cores. The win is the floating-solvent and 3D-connectivity paths, ported off networkx onto rustworkx; the numeric kernels (distances, contacts, connected components, OMS Voronoi/order-parameters, EQeq) are Rust.
  • 🔌 Drop-in. MOFChecker-compatible class — same properties, same get_mof_descriptors(). Switch the import and existing code keeps working.
  • Parity-verified. 100% agreement with MOFChecker 2.0 on real QMOFs (4500/4500 descriptor-comparisons over 250 structures × 18 descriptors; 16/16 on the reference test CIFs). See Parity below.
  • 📦 Built for batches. Parallel check_structures, graph built once per structure, failures isolated.
  • 🔋 Bit-exact charges. has_high_charges is a faithful Rust port of EQeq (bit-exact equilibrated charges).
  • 🔁 Reproducible. symmetry_hash is deterministic (the reference's depends on Python hash randomization).

⚡ Performance

30 QMOF relaxed 150-atom MOFs, cold batch (each structure processed once), MOFChecker 2.0 vs mofchecker-next on identical inputs, dedicated compute node, 1 vs 10 cores. Reproduce with scripts/benchmark_throughput.py (the structure set is pinned + fingerprinted so before/after runs are comparable).

Geometric diagnostic set (the structural/graph checks; excludes open-metal-site detection):

per structure throughput speedup
MOFChecker 2.0 — 1 core 1201 ms 0.8 /s
mofchecker-next — 1 core 101 ms 9.9 /s 11.9×
MOFChecker 2.0 — 10 cores 162 ms 6.2 /s
mofchecker-next — 10 cores 13.1 ms 76.6 /s 12.4×

Full geometric suite (includes has_oms open-metal-site order parameters):

per structure throughput speedup
MOFChecker 2.0 — 1 core 1535 ms 0.7 /s
mofchecker-next — 1 core 140 ms 7.1 /s 10.9×
MOFChecker 2.0 — 10 cores 197 ms 5.1 /s
mofchecker-next — 10 cores 20.0 ms 49.9 /s 9.8×

Where the speedup comes from — it is concentrated in one check. MOFChecker's floating-solvent detection (has_lone_molecule) builds a 3×3×3 supercell graph via pymatgen StructureGraph.__mul__ (networkx union/relabel of 27 copies, ~940 ms/structure here) and 3D-connectivity runs Larsen dimensionality over networkx. These are replaced by direct integer image-offset algorithms on a rustworkx graph — O(N+E), no supercell — making has_lone_molecule ~94× faster (~940 ms → ~10 ms); it dominates the reference's runtime, so it drives the speedup. has_oms now uses Rust for Voronoi facet-neighbor selection and pymatgen-compatible local order-parameter formulas. Speedup also grows with structure size and is higher on generated/distorted structures (more disconnected fragments).

⚙️ How it works

Python owns CIF/structure loading, pymatgen integration, and orchestration. The heavy lifting is delegated:

  • Rust (_rust PyO3 extension): minimum-image distances, short contacts, neighbor candidates, connected components, graph degrees, OMS Voronoi/order-parameters, and the EQeq charge solve.
  • rustworkx (checks/_subgraph_rx.py): floating-solvent / lone-molecule detection (finite connected components via an image-offset consistency test) and Larsen dimensionality (rank of the lattice-image vectors a component spans). These replace the networkx-heavy paths.
  • structuregraph_helpers is retained for the logic-critical, non-hot pieces it does well: graph construction (tuned VESTA cutoffs) and the Weisfeiler–Lehman graph hashes.

The structure graph is built once per MOFChecker and reused across all checks.

✅ Parity

Verified against a MOFChecker 2.0 checkout (used only as a behavioral oracle) via the harnesses in scripts/:

  • Real QMOFs: 4500/4500 descriptor-comparisons (250 structures × 18 descriptors) — 100%.
  • Reference test CIFs: 16/16.
  • Generated (distorted) structures: 3899/3900. The single difference is has_lone_molecule, where mofchecker-next is more correct — see Limitations.

Reproduce: scripts/qmof_parity.py (real QMOFs), scripts/generated_parity.py (generated CIFs), scripts/validate_subgraph_rx.py (floating-solvent port). Point them at a local QMOF CIF directory with QMOF_DIR=....

⚠️ Limitations & deliberate differences

  • Healing not implemented. adding_hydrogen / adding_linker raise NotImplementedError.
  • No porosity. is_porous returns None (no bundled Zeo++).
  • has_lone_molecule is more correct than the reference. MOFChecker 2.0's supercell + in-cell-filter heuristic silently misses finite molecules that wrap the unit-cell boundary (the origin-cell copy is truncated at the supercell face). mofchecker-next detects them via a topological finite-component test. This is the only descriptor that ever disagrees with the reference, only on pathological/distorted structures (0 disagreements on real QMOFs).
  • Graph construction is still the floor. pymatgen's VESTA neighbor-finding is unchanged; the speedup is in the graph algorithms, not bond perception.
  • Determinism. symmetry_hash is deterministic by design and will not match the reference's randomized value across runs.

⚖️ License

The published package is GPLv2, because it bundles py/mofchecker_next/eqeq/ — a faithful translation of EQeq (GPLv2, see py/mofchecker_next/eqeq/LICENSE) — and the GPL governs the combined work. The non-eqeq sources are MIT (LICENSE); for an MIT-only build, omit the eqeq subpackage and the has_high_charges diagnostic.

The MOFChecker 2.0 checkout used as the behavioral oracle (ANCSA 1.0) is not redistributed; see external/REFERENCE.md to reproduce it locally.

🛠️ For developers

Build, test, and release
python -m maturin develop --release          # build the Rust extension into the venv
python -m pytest -q                          # Python tests
cargo test --release --manifest-path rust/Cargo.toml   # Rust tests
# Source builds need libclang available for qhull-sys/bindgen.

Layout

  • py/mofchecker_next/ — Python package (checks/, diagnostics.py, the eqeq subpackage).
  • py/mofchecker_next/checks/_subgraph_rx.py — rustworkx floating-solvent + dimensionality.
  • rust/ — the _rust PyO3 extension (geometry + OMS + EQeq kernels).
  • scripts/ — parity harnesses and the speed benchmark.
  • tests/ — Rust and Python unit tests.
  • docs/DIAGNOSTIC_INVENTORY.md — per-diagnostic parity status.

Making a release — wheels are built and published by .github/workflows/release.yml via PyPI Trusted Publishing on a version tag:

git tag v0.1.0 && git push origin v0.1.0

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

mofchecker_next-0.1.2.tar.gz (54.8 kB view details)

Uploaded Source

Built Distributions

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

mofchecker_next-0.1.2-cp310-abi3-win_amd64.whl (384.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_x86_64.whl (548.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_aarch64.whl (529.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

mofchecker_next-0.1.2-cp310-abi3-macosx_11_0_arm64.whl (475.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file mofchecker_next-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for mofchecker_next-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7335255f803ff0a41d9f297ca426fa64a20be360cfc590f2317e6f7d21deb1df
MD5 fb358ba8bb1dcb64ff6fe6ce7ce46154
BLAKE2b-256 8f8128909479a6d9ea2d1775d9c214e10139fc7a57532e44609af22be0fe4de6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mofchecker_next-0.1.2.tar.gz:

Publisher: release.yml on henk789/mofchecker-next

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

File details

Details for the file mofchecker_next-0.1.2-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for mofchecker_next-0.1.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d65cd0b21943c32f4ff41c90dd06e2eb90dd9c62ebaca5b959ba366b698fbf6e
MD5 39372235ac206721672eaa56f968a62a
BLAKE2b-256 8881295dd6094974219e262085c26a137840cbd544a88362ea3c54240b80c75f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mofchecker_next-0.1.2-cp310-abi3-win_amd64.whl:

Publisher: release.yml on henk789/mofchecker-next

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

File details

Details for the file mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f8afa467720b4c9dc7f9a61a2db9846bc5aac0c62dc757bc4a09a909856833c9
MD5 61c3ab9bf77ba3c027112169afcaab36
BLAKE2b-256 042b4eb2daa0ad8a380d9b69bc6bd84f04f2b094a2f3af55920e4ecfe5993ece

See more details on using hashes here.

Provenance

The following attestation bundles were made for mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on henk789/mofchecker-next

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

File details

Details for the file mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3152659c57904a30fb271e37db2e1b5fccf9cbec05cef94a93a52970521c8a19
MD5 6ab33da41fe4da06a094769054390600
BLAKE2b-256 a25c01b55404bf0e0401b5cd9e18ce166479b3847a4a0126425c4f9b87ef310d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mofchecker_next-0.1.2-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on henk789/mofchecker-next

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

File details

Details for the file mofchecker_next-0.1.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mofchecker_next-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f04cac337a538b8353e9e8641836a5a72dac1bd6cda9920ecdd32b65fdd52f7
MD5 0f15d95dcc3a1bf325a0a0c6ec506607
BLAKE2b-256 4d56c822985047972bdb12301287c24d98aaa0557c56ea0aecd92f73303df08e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mofchecker_next-0.1.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on henk789/mofchecker-next

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