Run MOFography from the command line with mgrcli — process a CIF, get pore graphs, PSD, RAG, and textural properties in one shot
Overview
mgrcli is the command-line companion to the MOFography Python API. It wraps the same Rust-accelerated pipeline (dgrid_from_atoms_rust → do_periodic_segmentation_rust → downstream analysis) so you can analyze one or many CIFs without writing any Python.
The main entry is mgrcli process:
mgrcli process <cifs...>[flags]
A single invocation can produce:
Per-CIF *_results.npz — the same segmentation dict you’d get from the Python API (dgrid, maxima, regions, connections, RAG-as-arrays).
Pore-diameter CSV with LCD, PLD, DFSD, and percolation history (with --pore-dia).
HTML visualizations — Plotly or Three.js (with --plot-html).
This tutorial walks through installation, the canonical command, every key flag, the output layout, and how to drop down to the Python API when the CLI is not enough.
Prerequisites
A working MOFography environment (see the Installation guide).
A CIF file. The tutorials use docs/IRMOF-1.cif from this repo.
About 5–10 seconds per CIF on a modern laptop for the canonical flags (--pore-dia --psd --rag --types on IRMOF-1 takes ~4 s end-to-end on M-series).
Installation
From PyPI (recommended)
pip install mgrcli
This pulls in mgrcli plus its pinned runtime dependencies (ase, pymatgen, plotly, scikit-image, networkx, …) and the prebuilt Rust extension for your platform.
From source (editable)
If you want to hack on the CLI or pin a development branch:
Adds the PSD (uniform + pocketwise probe sampling).
Saves the RAG as a pickle for downstream graph work.
Add --types to also detect pocket-type families via env_cluster:
mgrcli process IRMOF-1.cif \--dgrid-method rust_exact --vdw-radii-set bondi --b rust_det \--pore-dia--psd--rag--types
This is the command to copy-paste for a “one-shot full analysis”.
End-to-end smoke test
Run the canonical command from inside this docs folder. The output lands in hts_output/IRMOF-1/ (the convention used by the Streamlit HTS tab — any directory you pass to -o works, but hts_output/<stem>/ is the standard layout for batch HTS runs).
returncode: 0
--- stdout (tail) ---
Region 8: 1000 samples, mean pore size: 10.70 Å, std: 2.54 Å
Pocket PSD: 1000 samples/region, 8 regions
Uniform PSD saved to: hts_output/IRMOF-1/IRMOF-1_psd_psd_uniform.csv
Pocket PSD saved to: hts_output/IRMOF-1/IRMOF-1_psd_psd_pockets.csv
RAG (region adjacency graph) saved to: hts_output/IRMOF-1/IRMOF-1_rag_clustered.pkl
Detecting pocket types (env_cluster)...
Creating region-wise PSD plots...
Unique region labels found: [1 2 3 4 5 6 7 8]
Found 8 unique regions/pockets
Region 1: 1000 samples, mean pore size: 14.89 Å, std: 0.93 Å
Region 2: 1000 samples, mean pore size: 11.64 Å, std: 0.41 Å
Region 3: 1000 samples, mean pore size: 14.10 Å, std: 1.10 Å
Region 4: 1000 samples, mean pore size: 11.23 Å, std: 0.24 Å
Region 5: 1000 samples, mean pore size: 14.07 Å, std: 1.17 Å
Region 6: 1000 samples, mean pore size: 14.14 Å, std: 1.05 Å
Region 7: 1000 samples, mean pore size: 11.64 Å, std: 0.36 Å
Region 8: 1000 samples, mean pore size: 11.65 Å, std: 0.35 Å
Found 2 pocket types (env_cluster, probe PSD r=1.200 Å)
Results saved to: hts_output/IRMOF-1/IRMOF-1_results.npz
The expected return code is 0; the tail of stdout should show the per-region PSD stats, the env_cluster type count, and the final Results saved to: ..._results.npz line.
Output directory structure
After the smoke test, hts_output/IRMOF-1/ contains:
Show code
for p insorted(out_dir.iterdir()):print(f"{p.stat().st_size:>9,d}{p.name}")
Compressed NumPy archive with dgrid, maxima, regions, regions_pbc, unique_regions, connections, pocket typing, etc. — the same dict shape returned by the Python API.
IRMOF-1_pore_dia.csv
--pore-dia
LCD, PLD, DFSD in Å + the percolation history point count.
IRMOF-1_psd_psd_uniform.csv
--psd
Globally sampled pore-size distribution (the doubled psd_psd is intentional — save_psd_csv always appends _psd_uniform / _psd_pockets to its base).
IRMOF-1_psd_psd_pockets.csv
--psd
Per-pocket probe-occupiable PSDs.
IRMOF-1_psd_accessible_psd_uniform.csv
--psd-accessible
PSD restricted to the percolating cluster at --probe-radius.
For richer, typed Python access (e.g. the PocketTypingResult object with .n_types, .type_summary, .rep_to_type), use the Python API — see Pocket Type Detection and the CLI → Python workflow section below.
Key flags reference
The process subcommand has ~30 flags. They split into five groups: input/output, analysis parameters, boolean flags, analysis options, and visualization. The defaults mirror the Streamlit web app so a CLI run produces the same numbers as a click-through on the site.
Distance-grid method (--dgrid-method)
Value
Backend
When to use
rust_exact
Thread-parallel Rust, voxel-exact
Default. Correct for all cell types, including non-orthorhombic.
rust_aabb
R-tree accelerated
Large unit cells; trades a small approximation for ~2-5× less RAM. See Distance Grid tutorial.
rust_aabb_interp
Coarse R-tree + trilinear interp
Very large cells where even rust_aabb is heavy.
python_aabb
Pure-Python AABB
Slowest; use only for parity checks against the Python API.
Do not use the deprecated dgrid_from_atoms_gpu or dgrid_from_atoms_cpu_no_aabb paths — they mis-handle non-orthorhombic cells. The *_rust backends are the only correct path on skewed cells.
Tuning knobs for the AABB backends:
Flag
Default
Effect
--dgrid-block-size
50000
Voxels per block for python_aabb. Lower = less RAM, more Python overhead.
--dgrid-n-neighbors
10
R-tree neighbor count for rust_aabb / rust_aabb_interp. Higher = more accurate, slower.
--dgrid-coarse-factor
2
Coarsening factor for rust_aabb_interp only. Higher = much faster, coarser approximation.
For most MOFs the auto policy is fine: by default mgrcli will auto-switch from rust_exact to rust_aabb for very large cells. Pass --no-auto-dgrid to disable that policy and stay on rust_exact.
Drives the percolation test that decides which pockets are reachable from outside the unit cell:
Value
What it does
winding (default)
Winding-number percolation. Fast, robust, matches web app.
lattice
Lattice-based percolation. --lattice-variant chooses v1 (older) or v2 (newer, default).
Accessibility applies to --pore-dia, --sa, and --vol. Combine with --no-window-fp to disable the window-fingerprint rescue for accessible SA / vol (only meaningful with winding).
Segmentation parameters
These map 1:1 to the Python API parameters of do_periodic_segmentation_rust:
Flag
Default
Effect
-s, --spacing
0.5 Å
Grid resolution. Halve → 8× more voxels; the single most expensive knob.
Void-space threshold. Increase to merge nearby pockets.
-ta, --threshold-abs
1.5 Å
Maxima must be at least this far from the framework.
-md, --min-distance
1.5 Å
Minimum separation between distinct maxima.
-ms, --minimum-window-separation
1.0 Å
Minimum separation between detected windows.
-wt, --wall-thickness
0.05
Wall-thickness fraction for window detection.
-ep, --extra-padding
5.0 Å
Extra PBC padding beyond the +5 Å default.
-mrs, --min-region-size
0.001
Filter regions smaller than this fraction of the padded grid.
Heads up: the legacy “batch” profile used mask_thickness=0.5 and rust_bucket (see mgrcli generate-config --profile legacy). The web / default profile is the validated one for pocket typing — keep it unless you have a specific reason to regress.
Probe radius
Flag
Default
Effect
--probe-radius
1.2 Å (He)
Probe for surface area, void volume, and accessible PSD.
--probe-radius-psd
1.2 Å
Probe for the pocket PSD used in env_cluster typing.
Pocket typing (--types / --pocket-typing)
Value
Algorithm
env_cluster (default with --types)
Multi-modal fingerprinting: pocket PSD + framework SH + connectivity SH. The validated, recommended method.
legacy_js
Older RAG + Jensen-Shannon divergence clustering. Kept for regression; less stable.
none (default without --types)
Skip typing — just save the RAG.
--types is a shorthand for --pocket-typing env_cluster. It always saves the RAG pickle (<stem>_rag_clustered.pkl) in addition to running the typing pass.
Boolean flags
Flag
Effect
--no-connections
Skip window + connection detection. Faster, but you lose the pore graph.
--no-auto-dgrid
Disable auto-switch from rust_exact → rust_aabb for large cells.
--no-window-fp
Disable window-fingerprint rescue for accessible SA / vol (winding).
--return-padded-regions
Include the padded region array in the .npz (default off).
--return-dgrid
Keep dgrid in the .npz (default on).
--disable-tqdm
Suppress progress bars (good for log files).
--plot-html
Save a standalone 3D HTML viewer after processing.
--no-stylize
Disable stylized framework rendering in plots.
--pore-dia
Compute LCD/PLD/DFSD + percolation history.
--percolation-plot
Save <stem>_percolation.html (cluster growth).
--sa-plot-html
Save <stem>_surface_area_plot.html.
--vol-plot-html
Save <stem>_void_volume_plot.html.
--psd
Compute pore size distribution.
--psd-accessible
Compute accessible (percolation-filtered) PSD at --probe-radius.
--sa
Compute surface area.
--vol
Compute void volume.
--auto-params
Auto-estimate optimal parameters from the cell geometry.
--types
Detect pocket types via env_cluster.
--rag
Save the RAG pickle (no typing).
--theme {dark,white}
Plot theme (default dark).
Visualization backends
Flag
Default
Effect
--plot-html
off
Save <stem>.html viewer.
--plot-backend {plotly,threejs}
plotly
Viewer engine. Three.js exports smaller, more portable HTML.
--percolation-plot-backend {plotly,threejs}
threejs
Percolation plot engine.
--html-dir
same as -o
Separate folder for HTML outputs.
Re-running from a saved config
If you’ve been clicking around the web app and want to capture the exact parameter set as a JSON config:
generate-config writes a config matching the current defaults (web profile by default; --profile legacy for the older batch defaults). The process subcommand accepts it via -c/--config.
Processing many CIFs
The positional argument is variadic — pass as many CIFs as you like:
mgrcli process mofs/*.cif -o ./results/ --pore-dia--psd--rag--disable-tqdm
Each CIF is processed in turn; outputs are prefixed with the CIF stem (<stem>_results.npz, <stem>_pore_dia.csv, …). Failed CIFs are logged and skipped — a single bad file does not abort the run.
Plotting an existing .npz
If you already saved a *_results.npz (via the CLI or the Python API) and want to (re)render its HTML viewer:
mgrcli plot IRMOF-1_results.npz -o ./plots/ --plot-backend threejs --theme dark
plot reads the .npz, attaches a .html viewer with the same name stem into the output directory, and respects the same --plot-backend / --theme / --no-stylize / --surface-taubin-intensity knobs as --plot-html on process.
Launching the web app
If you’d rather click through, mgrcli interactive boots the same Streamlit app you can use locally:
mgrcli interactive # default portmgrcli interactive --port 8501 # specific portmgrcli interactive --clean# kill stale Streamlit processes first
interactive is the same backend as the deployed Hugging Face Space; the CLI just removes the need to clone + install the Streamlit code by hand.
When to drop down to the Python API
The CLI is the right tool for:
One-shot analysis of a handful of MOFs.
Batch HTS-style runs on hundreds to thousands of CIFs.
Capturing reproducible parameter sets in a JSON config.
Producing standardized artifacts (.npz + CSVs) for downstream pipelines.
But the Python API is strictly more flexible. Drop down to Python when you need:
Custom post-processing on the segmentation dict (dgrid, regions_pbc, connections, pbc_groups).
Typed PocketTypingResult with .n_types, .n_pockets, .type_summary, .rep_to_type, .regions_cluster (see Pocket Type Detection).
Tighter integration with Dask, MOFDB, or PoroNet pipelines (see HTS Dask and the PoroNet tutorial).
Access to close_or_inside_maxima (voxel coords of pockets’ interior maxima) or other low-level arrays the CLI does not surface.
The handoff is clean: every artifact the CLI writes is also a valid input to the Python API. You can read the .npz with numpy.load, or just re-load the CIF and re-run a single step from the CLI’s compute_* functions (they are importable from mgrcli.cli).
Full flag cheat-sheet
For one-line reference, this is the entire process flag surface:
Start with the canonical command, then add flags. Defaults mirror the web app and are validated against IRMOF-1, UiO-66, ZIF-8, HKUST-1, NU-1000, and ZIF-20.
Use -o hts_output/<stem>/ so the per-CIF artifacts live in a predictable folder layout — that’s what the Streamlit HTS tab expects.
Reproducibility: pair -c my_run.json with --disable-tqdm for clean logs you can diff between runs.
For very large cells, the default auto-AABB policy already switches to rust_aabb — you only need to override --dgrid-method if you want to force one specific backend.
VDW sensitivity: if pocket-type counts look wrong, re-run with --vdw-radii-set bondi and compare against crc / alvarez. See the pocket type detection page for the caution on radii.
The CLI hides nothing the API exposes — every artifact on disk is also reachable from Python. The *_results.npz is the canonical handoff.