mofchecker-next 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. mofchecker_next-0.1.1/LICENSE +37 -0
  2. mofchecker_next-0.1.1/PKG-INFO +173 -0
  3. mofchecker_next-0.1.1/README.md +147 -0
  4. mofchecker_next-0.1.1/py/mofchecker_next/__init__.py +5 -0
  5. mofchecker_next-0.1.1/py/mofchecker_next/batch.py +138 -0
  6. mofchecker_next-0.1.1/py/mofchecker_next/checks/__init__.py +1 -0
  7. mofchecker_next-0.1.1/py/mofchecker_next/checks/_subgraph_rx.py +181 -0
  8. mofchecker_next-0.1.1/py/mofchecker_next/checks/charge_oms.py +620 -0
  9. mofchecker_next-0.1.1/py/mofchecker_next/checks/composition.py +37 -0
  10. mofchecker_next-0.1.1/py/mofchecker_next/checks/geometry.py +216 -0
  11. mofchecker_next-0.1.1/py/mofchecker_next/checks/graph.py +489 -0
  12. mofchecker_next-0.1.1/py/mofchecker_next/core.py +386 -0
  13. mofchecker_next-0.1.1/py/mofchecker_next/diagnostics.py +20 -0
  14. mofchecker_next-0.1.1/py/mofchecker_next/eqeq/LICENSE +280 -0
  15. mofchecker_next-0.1.1/py/mofchecker_next/eqeq/__init__.py +136 -0
  16. mofchecker_next-0.1.1/py/mofchecker_next/eqeq/data/chargecenters.dat +84 -0
  17. mofchecker_next-0.1.1/py/mofchecker_next/eqeq/data/ionizationdata.dat +84 -0
  18. mofchecker_next-0.1.1/py/mofchecker_next/eqeq/parameters.py +112 -0
  19. mofchecker_next-0.1.1/py/mofchecker_next/gui/__init__.py +1 -0
  20. mofchecker_next-0.1.1/py/mofchecker_next/gui/app.py +1 -0
  21. mofchecker_next-0.1.1/py/mofchecker_next/io.py +1 -0
  22. mofchecker_next-0.1.1/pyproject.toml +44 -0
  23. mofchecker_next-0.1.1/rust/Cargo.lock +180 -0
  24. mofchecker_next-0.1.1/rust/Cargo.toml +11 -0
  25. mofchecker_next-0.1.1/rust/src/contacts.rs +128 -0
  26. mofchecker_next-0.1.1/rust/src/eqeq.rs +449 -0
  27. mofchecker_next-0.1.1/rust/src/graph.rs +96 -0
  28. mofchecker_next-0.1.1/rust/src/lib.rs +149 -0
  29. mofchecker_next-0.1.1/rust/src/pbc.rs +159 -0
@@ -0,0 +1,37 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hendrik Krass
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ -------------------------------------------------------------------------------
24
+
25
+ Licensing note for the `mofchecker_next.eqeq` subpackage
26
+ --------------------------------------------------------
27
+
28
+ The core of this project is MIT-licensed as above. The exception is the
29
+ subpackage `py/mofchecker_next/eqeq/`, which is a faithful translation of EQeq
30
+ (https://github.com/lsmo-epfl/EQeq) and vendors its ionization/charge-center
31
+ data tables. EQeq is licensed under the GNU General Public License v2, so that
32
+ subpackage is GPLv2 (see `py/mofchecker_next/eqeq/LICENSE`).
33
+
34
+ Consequently, a work that combines and distributes this project together with
35
+ the `eqeq` subpackage is governed by the terms of the GPLv2. If you need an
36
+ MIT-only distribution, omit the `eqeq` subpackage (and the `has_high_charges`
37
+ diagnostic it powers).
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: mofchecker-next
3
+ Version: 0.1.1
4
+ Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Rust
7
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
8
+ Requires-Dist: numpy>=1.26
9
+ Requires-Dist: structuregraph-helpers>=0.0.9
10
+ Requires-Dist: element-coder>=0.0.8
11
+ Requires-Dist: libconeangle>=0.1.2
12
+ Requires-Dist: rustworkx>=0.14
13
+ Requires-Dist: pymatgen>=2024.8 ; extra == 'parity'
14
+ Requires-Dist: pytest>=8 ; extra == 'test'
15
+ Requires-Dist: maturin>=1.7,<2 ; extra == 'test'
16
+ Provides-Extra: parity
17
+ Provides-Extra: test
18
+ License-File: LICENSE
19
+ Summary: Incremental Rust/Python geometry kernels for MOF checking
20
+ Author: Hendrik Kraß
21
+ License: GPL-2.0-only
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
24
+ Project-URL: Repository, https://github.com/henk789/mofchecker-next
25
+
26
+ <h1 align="center">
27
+ mofchecker-next
28
+ </h1>
29
+
30
+ <p align="center">
31
+ <b>A fast, drop-in replacement for <a href="https://github.com/lamalab-org/mofchecker">MOFChecker</a> 2.0</b> — same diagnostics, same API, <b>~20–25× faster per core</b>, built on Rust kernels and rustworkx graph algorithms.
32
+ </p>
33
+
34
+ <p align="center">
35
+ <a href="https://github.com/henk789/mofchecker-next/actions/workflows/release.yml">
36
+ <img alt="CI" src="https://github.com/henk789/mofchecker-next/actions/workflows/release.yml/badge.svg" />
37
+ </a>
38
+ <a href="https://pypi.org/project/mofchecker-next/">
39
+ <img alt="PyPI" src="https://img.shields.io/pypi/v/mofchecker-next" />
40
+ </a>
41
+ <a href="https://pypi.org/project/mofchecker-next/">
42
+ <img alt="Python versions" src="https://img.shields.io/pypi/pyversions/mofchecker-next" />
43
+ </a>
44
+ <a href="https://github.com/henk789/mofchecker-next/blob/main/py/mofchecker_next/eqeq/LICENSE">
45
+ <img alt="License" src="https://img.shields.io/pypi/l/mofchecker-next" />
46
+ </a>
47
+ <img alt="Speedup" src="https://img.shields.io/badge/vs%20MOFChecker%202.0-~23%C3%97%20faster-brightgreen" />
48
+ <img alt="Built with Rust" src="https://img.shields.io/badge/built%20with-Rust%20%2B%20PyO3-orange" />
49
+ </p>
50
+
51
+ 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.
52
+
53
+ ## 💪 Getting started
54
+
55
+ ```python
56
+ from mofchecker_next import MOFChecker
57
+
58
+ mc = MOFChecker.from_cif("structure.cif") # also .from_ase(atoms) / MOFChecker(structure)
59
+ mc.has_atomic_overlaps, mc.has_lone_molecule, mc.has_oms, mc.metal_number
60
+ descriptors = mc.get_mof_descriptors() # OrderedDict of every diagnostic
61
+ ```
62
+
63
+ Validating many structures? `mofchecker_next.batch` parallelizes across structures, builds each graph once, and never aborts the run on a single bad structure:
64
+
65
+ ```python
66
+ from mofchecker_next.batch import check_structures
67
+
68
+ # inputs may be CIF paths, pymatgen Structures, ASE Atoms, or a mix
69
+ results = check_structures(inputs, n_workers=16) # all CPUs by default
70
+ bad = [r for r in results if r["has_atomic_overlaps"]]
71
+
72
+ # subset to skip work: composition-only descriptors skip graph construction entirely
73
+ fast = check_structures(inputs, descriptors=["has_atomic_overlaps", "has_overcoordinated_c"])
74
+ ```
75
+
76
+ 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.
77
+
78
+ ## 🚀 Installation
79
+
80
+ ```bash
81
+ pip install mofchecker-next
82
+ ```
83
+
84
+ Latest from source (needs a Rust toolchain):
85
+
86
+ ```bash
87
+ pip install git+https://github.com/henk789/mofchecker-next.git
88
+ ```
89
+
90
+ ## ✨ Why use it
91
+
92
+ - ⚡ **Fast.** On 150-atom MOFs, **57.8 ms/structure** single-core vs **1.34 s** for MOFChecker 2.0 (**23×**); **149 structures/s** across 10 cores. The hot paths (floating solvent, 3D-connectivity) were ported off networkx; the numeric kernels (distances, contacts, connected components, EQeq) are Rust.
93
+ - 🔌 **Drop-in.** `MOFChecker`-compatible class — same properties, same `get_mof_descriptors()`. Switch the import and existing code keeps working.
94
+ - ✅ **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.
95
+ - 📦 **Built for batches.** Parallel `check_structures`, graph built once per structure, failures isolated.
96
+ - 🔋 **Bit-exact charges.** `has_high_charges` is a faithful Rust port of EQeq (bit-exact equilibrated charges).
97
+ - 🔁 **Reproducible.** `symmetry_hash` is deterministic (the reference's depends on Python hash randomization).
98
+
99
+ ## ⚡ Performance
100
+
101
+ 120 generated 150-atom CIFs, full geometric descriptor set, MOFChecker 2.0 vs mofchecker-next on identical inputs (10-core node):
102
+
103
+ | | per structure | throughput | speedup |
104
+ |---|---:|---:|---:|
105
+ | MOFChecker 2.0 — 1 core | 1338 ms | 0.7 /s | 1× |
106
+ | **mofchecker-next — 1 core** | **57.8 ms** | **17.3 /s** | **23.2×** |
107
+ | MOFChecker 2.0 — 10 cores | 174.9 ms | 5.7 /s | — |
108
+ | **mofchecker-next — 10 cores** | **6.7 ms** | **149.3 /s** | **26.1×** |
109
+
110
+ Where the speedup comes from: MOFChecker's floating-solvent check builds a 3×3×3 supercell graph via pymatgen `StructureGraph.__mul__` (networkx `union`/`relabel` of 27 copies, ~2.3 s/structure), and 3D-connectivity runs Larsen dimensionality over networkx. Both are replaced by direct integer image-offset algorithms on a rustworkx graph — O(N+E), no supercell — while the geometry kernels run in Rust.
111
+
112
+ ## ⚙️ How it works
113
+
114
+ Python owns CIF/structure loading, pymatgen integration, and orchestration. The heavy lifting is delegated:
115
+
116
+ - **Rust** (`_rust` PyO3 extension): minimum-image distances, short contacts, neighbor candidates, connected components, graph degrees, and the EQeq charge solve.
117
+ - **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.
118
+ - **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.
119
+
120
+ The structure graph is built once per `MOFChecker` and reused across all checks.
121
+
122
+ ## ✅ Parity
123
+
124
+ Verified against a MOFChecker 2.0 checkout (used only as a behavioral oracle) via the harnesses in `scripts/`:
125
+
126
+ - **Real QMOFs:** 4500/4500 descriptor-comparisons (250 structures × 18 descriptors) — 100%.
127
+ - **Reference test CIFs:** 16/16.
128
+ - **Generated (distorted) structures:** 3899/3900. The single difference is **`has_lone_molecule`, where mofchecker-next is more correct** — see Limitations.
129
+
130
+ 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=...`.
131
+
132
+ ## ⚠️ Limitations & deliberate differences
133
+
134
+ - **Healing not implemented.** `adding_hydrogen` / `adding_linker` raise `NotImplementedError`.
135
+ - **No porosity.** `is_porous` returns `None` (no bundled Zeo++).
136
+ - **`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).
137
+ - **Graph construction is still the floor.** pymatgen's VESTA neighbor-finding is unchanged; the speedup is in the graph *algorithms*, not bond perception.
138
+ - **Determinism.** `symmetry_hash` is deterministic by design and will not match the reference's randomized value across runs.
139
+
140
+ ## ⚖️ License
141
+
142
+ The **published package is GPLv2**, because it bundles `py/mofchecker_next/eqeq/` — a faithful translation of [EQeq](https://github.com/lsmo-epfl/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.
143
+
144
+ The MOFChecker 2.0 checkout used as the behavioral oracle (ANCSA 1.0) is **not** redistributed; see `external/REFERENCE.md` to reproduce it locally.
145
+
146
+ ## 🛠️ For developers
147
+
148
+ <details>
149
+ <summary>Build, test, and release</summary>
150
+
151
+ ```bash
152
+ python -m maturin develop --release # build the Rust extension into the venv
153
+ python -m pytest -q # Python tests
154
+ cargo test --release --manifest-path rust/Cargo.toml # Rust tests
155
+ ```
156
+
157
+ **Layout**
158
+
159
+ - `py/mofchecker_next/` — Python package (`checks/`, `diagnostics.py`, the `eqeq` subpackage).
160
+ - `py/mofchecker_next/checks/_subgraph_rx.py` — rustworkx floating-solvent + dimensionality.
161
+ - `rust/` — the `_rust` PyO3 extension (geometry + EQeq kernels).
162
+ - `scripts/` — parity harnesses and the speed benchmark.
163
+ - `tests/` — Rust and Python unit tests.
164
+ - `docs/DIAGNOSTIC_INVENTORY.md` — per-diagnostic parity status.
165
+
166
+ **Making a release** — wheels are built and published by `.github/workflows/release.yml` via PyPI Trusted Publishing on a version tag:
167
+
168
+ ```bash
169
+ git tag v0.1.0 && git push origin v0.1.0
170
+ ```
171
+
172
+ </details>
173
+
@@ -0,0 +1,147 @@
1
+ <h1 align="center">
2
+ mofchecker-next
3
+ </h1>
4
+
5
+ <p align="center">
6
+ <b>A fast, drop-in replacement for <a href="https://github.com/lamalab-org/mofchecker">MOFChecker</a> 2.0</b> — same diagnostics, same API, <b>~20–25× faster per core</b>, built on Rust kernels and rustworkx graph algorithms.
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://github.com/henk789/mofchecker-next/actions/workflows/release.yml">
11
+ <img alt="CI" src="https://github.com/henk789/mofchecker-next/actions/workflows/release.yml/badge.svg" />
12
+ </a>
13
+ <a href="https://pypi.org/project/mofchecker-next/">
14
+ <img alt="PyPI" src="https://img.shields.io/pypi/v/mofchecker-next" />
15
+ </a>
16
+ <a href="https://pypi.org/project/mofchecker-next/">
17
+ <img alt="Python versions" src="https://img.shields.io/pypi/pyversions/mofchecker-next" />
18
+ </a>
19
+ <a href="https://github.com/henk789/mofchecker-next/blob/main/py/mofchecker_next/eqeq/LICENSE">
20
+ <img alt="License" src="https://img.shields.io/pypi/l/mofchecker-next" />
21
+ </a>
22
+ <img alt="Speedup" src="https://img.shields.io/badge/vs%20MOFChecker%202.0-~23%C3%97%20faster-brightgreen" />
23
+ <img alt="Built with Rust" src="https://img.shields.io/badge/built%20with-Rust%20%2B%20PyO3-orange" />
24
+ </p>
25
+
26
+ 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.
27
+
28
+ ## 💪 Getting started
29
+
30
+ ```python
31
+ from mofchecker_next import MOFChecker
32
+
33
+ mc = MOFChecker.from_cif("structure.cif") # also .from_ase(atoms) / MOFChecker(structure)
34
+ mc.has_atomic_overlaps, mc.has_lone_molecule, mc.has_oms, mc.metal_number
35
+ descriptors = mc.get_mof_descriptors() # OrderedDict of every diagnostic
36
+ ```
37
+
38
+ Validating many structures? `mofchecker_next.batch` parallelizes across structures, builds each graph once, and never aborts the run on a single bad structure:
39
+
40
+ ```python
41
+ from mofchecker_next.batch import check_structures
42
+
43
+ # inputs may be CIF paths, pymatgen Structures, ASE Atoms, or a mix
44
+ results = check_structures(inputs, n_workers=16) # all CPUs by default
45
+ bad = [r for r in results if r["has_atomic_overlaps"]]
46
+
47
+ # subset to skip work: composition-only descriptors skip graph construction entirely
48
+ fast = check_structures(inputs, descriptors=["has_atomic_overlaps", "has_overcoordinated_c"])
49
+ ```
50
+
51
+ 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.
52
+
53
+ ## 🚀 Installation
54
+
55
+ ```bash
56
+ pip install mofchecker-next
57
+ ```
58
+
59
+ Latest from source (needs a Rust toolchain):
60
+
61
+ ```bash
62
+ pip install git+https://github.com/henk789/mofchecker-next.git
63
+ ```
64
+
65
+ ## ✨ Why use it
66
+
67
+ - ⚡ **Fast.** On 150-atom MOFs, **57.8 ms/structure** single-core vs **1.34 s** for MOFChecker 2.0 (**23×**); **149 structures/s** across 10 cores. The hot paths (floating solvent, 3D-connectivity) were ported off networkx; the numeric kernels (distances, contacts, connected components, EQeq) are Rust.
68
+ - 🔌 **Drop-in.** `MOFChecker`-compatible class — same properties, same `get_mof_descriptors()`. Switch the import and existing code keeps working.
69
+ - ✅ **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.
70
+ - 📦 **Built for batches.** Parallel `check_structures`, graph built once per structure, failures isolated.
71
+ - 🔋 **Bit-exact charges.** `has_high_charges` is a faithful Rust port of EQeq (bit-exact equilibrated charges).
72
+ - 🔁 **Reproducible.** `symmetry_hash` is deterministic (the reference's depends on Python hash randomization).
73
+
74
+ ## ⚡ Performance
75
+
76
+ 120 generated 150-atom CIFs, full geometric descriptor set, MOFChecker 2.0 vs mofchecker-next on identical inputs (10-core node):
77
+
78
+ | | per structure | throughput | speedup |
79
+ |---|---:|---:|---:|
80
+ | MOFChecker 2.0 — 1 core | 1338 ms | 0.7 /s | 1× |
81
+ | **mofchecker-next — 1 core** | **57.8 ms** | **17.3 /s** | **23.2×** |
82
+ | MOFChecker 2.0 — 10 cores | 174.9 ms | 5.7 /s | — |
83
+ | **mofchecker-next — 10 cores** | **6.7 ms** | **149.3 /s** | **26.1×** |
84
+
85
+ Where the speedup comes from: MOFChecker's floating-solvent check builds a 3×3×3 supercell graph via pymatgen `StructureGraph.__mul__` (networkx `union`/`relabel` of 27 copies, ~2.3 s/structure), and 3D-connectivity runs Larsen dimensionality over networkx. Both are replaced by direct integer image-offset algorithms on a rustworkx graph — O(N+E), no supercell — while the geometry kernels run in Rust.
86
+
87
+ ## ⚙️ How it works
88
+
89
+ Python owns CIF/structure loading, pymatgen integration, and orchestration. The heavy lifting is delegated:
90
+
91
+ - **Rust** (`_rust` PyO3 extension): minimum-image distances, short contacts, neighbor candidates, connected components, graph degrees, and the EQeq charge solve.
92
+ - **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.
93
+ - **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.
94
+
95
+ The structure graph is built once per `MOFChecker` and reused across all checks.
96
+
97
+ ## ✅ Parity
98
+
99
+ Verified against a MOFChecker 2.0 checkout (used only as a behavioral oracle) via the harnesses in `scripts/`:
100
+
101
+ - **Real QMOFs:** 4500/4500 descriptor-comparisons (250 structures × 18 descriptors) — 100%.
102
+ - **Reference test CIFs:** 16/16.
103
+ - **Generated (distorted) structures:** 3899/3900. The single difference is **`has_lone_molecule`, where mofchecker-next is more correct** — see Limitations.
104
+
105
+ 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=...`.
106
+
107
+ ## ⚠️ Limitations & deliberate differences
108
+
109
+ - **Healing not implemented.** `adding_hydrogen` / `adding_linker` raise `NotImplementedError`.
110
+ - **No porosity.** `is_porous` returns `None` (no bundled Zeo++).
111
+ - **`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).
112
+ - **Graph construction is still the floor.** pymatgen's VESTA neighbor-finding is unchanged; the speedup is in the graph *algorithms*, not bond perception.
113
+ - **Determinism.** `symmetry_hash` is deterministic by design and will not match the reference's randomized value across runs.
114
+
115
+ ## ⚖️ License
116
+
117
+ The **published package is GPLv2**, because it bundles `py/mofchecker_next/eqeq/` — a faithful translation of [EQeq](https://github.com/lsmo-epfl/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.
118
+
119
+ The MOFChecker 2.0 checkout used as the behavioral oracle (ANCSA 1.0) is **not** redistributed; see `external/REFERENCE.md` to reproduce it locally.
120
+
121
+ ## 🛠️ For developers
122
+
123
+ <details>
124
+ <summary>Build, test, and release</summary>
125
+
126
+ ```bash
127
+ python -m maturin develop --release # build the Rust extension into the venv
128
+ python -m pytest -q # Python tests
129
+ cargo test --release --manifest-path rust/Cargo.toml # Rust tests
130
+ ```
131
+
132
+ **Layout**
133
+
134
+ - `py/mofchecker_next/` — Python package (`checks/`, `diagnostics.py`, the `eqeq` subpackage).
135
+ - `py/mofchecker_next/checks/_subgraph_rx.py` — rustworkx floating-solvent + dimensionality.
136
+ - `rust/` — the `_rust` PyO3 extension (geometry + EQeq kernels).
137
+ - `scripts/` — parity harnesses and the speed benchmark.
138
+ - `tests/` — Rust and Python unit tests.
139
+ - `docs/DIAGNOSTIC_INVENTORY.md` — per-diagnostic parity status.
140
+
141
+ **Making a release** — wheels are built and published by `.github/workflows/release.yml` via PyPI Trusted Publishing on a version tag:
142
+
143
+ ```bash
144
+ git tag v0.1.0 && git push origin v0.1.0
145
+ ```
146
+
147
+ </details>
@@ -0,0 +1,5 @@
1
+ """mofchecker-next: Rust/Python MOF diagnostics with a drop-in MOFChecker API."""
2
+
3
+ from mofchecker_next.core import MOFChecker
4
+
5
+ __all__ = ["MOFChecker", "diagnostics", "batch"]
@@ -0,0 +1,138 @@
1
+ """Batch validation API.
2
+
3
+ Run MOFChecker diagnostics over many structures efficiently -- useful for
4
+ validating generated structures (e.g. from a diffusion model).
5
+
6
+ - Accepts pymatgen ``Structure``/``IStructure``, ASE ``Atoms``, or CIF path
7
+ (``str``/``Path``) interchangeably -- or a mix.
8
+ - Builds each structure's graph once (via the ``MOFChecker`` class) and reuses it
9
+ across all checks.
10
+ - Parallelizes across structures with ``multiprocessing`` (CPU-bound Python;
11
+ structures are independent).
12
+ - Lets you pick a subset of descriptors.
13
+
14
+ Example
15
+ -------
16
+ >>> from mofchecker_next.batch import check_structures
17
+ >>> results = check_structures(list_of_atoms_or_structures_or_paths, n_workers=16)
18
+ >>> bad = [r for r in results if r["has_atomic_overlaps"]]
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ from functools import partial
25
+ from multiprocessing import Pool
26
+ from pathlib import Path
27
+ from typing import Iterable, Sequence
28
+
29
+ from mofchecker_next.core import DEFAULT_DESCRIPTORS as ALL_DESCRIPTORS # full set (metadata + hashes + diagnostics)
30
+ from mofchecker_next.core import MOFChecker, normalize_structure
31
+
32
+ # Default batch descriptor set: the validation-relevant diagnostics (fast path).
33
+ # It omits the metadata/symmetry/hash descriptors (which add SpacegroupAnalyzer
34
+ # and graph-hash cost); request those explicitly or use ``ALL_DESCRIPTORS``.
35
+ DEFAULT_DESCRIPTORS = (
36
+ "has_carbon", "has_hydrogen", "has_nitrogen", "has_metal", "metal_number",
37
+ "has_atomic_overlaps", "has_overcoordinated_c", "has_overcoordinated_n",
38
+ "has_overcoordinated_h", "has_undercoordinated_c", "has_undercoordinated_n",
39
+ "has_undercoordinated_rare_earth", "has_undercoordinated_alkali_alkaline",
40
+ "has_lone_molecule", "has_3d_connected_graph", "has_suspicious_terminal_oxo",
41
+ "has_geometrically_exposed_metal", "possible_charged_fused_ring",
42
+ "positive_charge_from_linkers", "negative_charge_from_linkers", "has_oms",
43
+ "has_high_charges",
44
+ )
45
+
46
+
47
+ def _input_id(obj, index: int) -> str:
48
+ if isinstance(obj, (str, Path)):
49
+ return Path(obj).name
50
+ return str(index)
51
+
52
+
53
+ def check_structure(obj, *, descriptors: Sequence[str] | None = None, metals=None, method: str = "vesta") -> dict:
54
+ """Run the selected diagnostics on one structure (graph built once).
55
+
56
+ ``obj`` may be a pymatgen Structure, ASE Atoms, or a CIF path. Each
57
+ descriptor is computed independently; a descriptor that errors is reported
58
+ under ``errors`` rather than aborting the rest.
59
+ """
60
+ names = list(descriptors) if descriptors is not None else list(DEFAULT_DESCRIPTORS)
61
+ structure = normalize_structure(obj)
62
+ checker = MOFChecker(structure, metals=metals, method=method)
63
+
64
+ result: dict = {"n_atoms": len(structure)}
65
+ errors = {}
66
+ for name in names:
67
+ try:
68
+ result[name] = getattr(checker, name)
69
+ except Exception as exc: # noqa: BLE001
70
+ errors[name] = f"{type(exc).__name__}: {exc}"[:160]
71
+ if errors:
72
+ result["errors"] = errors
73
+ return result
74
+
75
+
76
+ def _worker(item, descriptors, metals, method, on_error):
77
+ index, obj = item
78
+ base = {"index": index, "id": _input_id(obj, index)}
79
+ try:
80
+ return {**base, **check_structure(obj, descriptors=descriptors, metals=metals, method=method)}
81
+ except Exception as exc: # noqa: BLE001
82
+ if on_error == "raise":
83
+ raise
84
+ return {**base, "error": f"{type(exc).__name__}: {exc}"[:200]}
85
+
86
+
87
+ def check_structures(
88
+ inputs: Iterable,
89
+ *,
90
+ n_workers: int | None = None,
91
+ descriptors: Sequence[str] | None = None,
92
+ metals=None,
93
+ method: str = "vesta",
94
+ on_error: str = "record",
95
+ chunksize: int = 1,
96
+ progress: bool = False,
97
+ ) -> list[dict]:
98
+ """Validate many structures in parallel.
99
+
100
+ Args:
101
+ inputs: iterable of pymatgen Structures, ASE Atoms, and/or CIF paths.
102
+ n_workers: process count (default: all CPUs). ``1`` runs serially.
103
+ descriptors: subset of descriptor names (default: ``DEFAULT_DESCRIPTORS``,
104
+ the diagnostics). Pass ``ALL_DESCRIPTORS`` to also get metadata,
105
+ symmetry, and graph hashes.
106
+ metals: metal symbol set (default: MOFChecker's METALS).
107
+ on_error: ``"record"`` adds an ``error`` field to failed structures;
108
+ ``"raise"`` propagates the first failure.
109
+ progress: show a tqdm bar if tqdm is installed.
110
+
111
+ Returns:
112
+ list of per-structure dicts (ordered to match ``inputs``), each with an
113
+ ``index``, ``id``, ``n_atoms``, and the requested descriptors.
114
+ """
115
+ items = list(enumerate(inputs))
116
+ if metals is not None:
117
+ metals = frozenset(str(m) for m in metals)
118
+ work = partial(_worker, descriptors=descriptors, metals=metals, method=method, on_error=on_error)
119
+
120
+ def _maybe_progress(iterator):
121
+ if not progress:
122
+ return iterator
123
+ try:
124
+ from tqdm import tqdm
125
+
126
+ return tqdm(iterator, total=len(items))
127
+ except ImportError:
128
+ return iterator
129
+
130
+ n_workers = n_workers or os.cpu_count() or 1
131
+ if n_workers <= 1:
132
+ results = list(_maybe_progress(map(work, items)))
133
+ else:
134
+ with Pool(n_workers) as pool:
135
+ results = list(_maybe_progress(pool.imap(work, items, chunksize=chunksize)))
136
+
137
+ results.sort(key=lambda r: r["index"])
138
+ return results
@@ -0,0 +1 @@
1
+ """Checker orchestration modules."""