Metadata-Version: 2.4
Name: nexerra
Version: 1.0.0
Summary: Nexerra-R1: a chemical language model for reticular materials design
Author-email: Dhruv Menon <dm958@cam.ac.uk>
License: MIT License
        
        Copyright (c) 2026 Dhruv Menon
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project-URL: Homepage, https://github.com/fairen-group/nexerra-r1
Project-URL: Repository, https://github.com/fairen-group/nexerra-r1
Project-URL: Dataset, https://doi.org/10.5281/zenodo.22284384
Keywords: chemistry,materials,MOF,generative model,SELFIES,flow matching
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: <3.13,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: numpy<2.0,>=1.26
Requires-Dist: pandas<3.0,>=2.2
Requires-Dist: pyfiglet<2.0,>=1.0
Requires-Dist: python-dateutil<3.0,>=2.9
Requires-Dist: rdkit<2025.0,>=2024.3
Requires-Dist: rich<15.0,>=13.7
Requires-Dist: selfies<3.0,>=2.2
Requires-Dist: torch<2.6,>=2.5
Requires-Dist: torchdiffeq<0.3,>=0.2.5
Requires-Dist: tqdm<5.0,>=4.67
Requires-Dist: zenodo-get<2.0,>=1.6
Provides-Extra: train
Requires-Dist: botorch<0.15,>=0.14; extra == "train"
Requires-Dist: gpytorch<1.15,>=1.14; extra == "train"
Requires-Dist: h5py<4.0,>=3.12; extra == "train"
Requires-Dist: matplotlib<4.0,>=3.9; extra == "train"
Requires-Dist: pytorch-lightning<2.6,>=2.5; extra == "train"
Requires-Dist: scikit-learn<2.0,>=1.6; extra == "train"
Requires-Dist: scipy<2.0,>=1.13; extra == "train"
Requires-Dist: tables<4.0,>=3.10; extra == "train"
Requires-Dist: torchaudio<2.6,>=2.5; extra == "train"
Requires-Dist: torchcfm<2.0,>=1.0.7; extra == "train"
Requires-Dist: torchmetrics<2.0,>=1.8; extra == "train"
Requires-Dist: torchvision<0.21,>=0.20; extra == "train"
Requires-Dist: umap-learn<0.6,>=0.5; extra == "train"
Provides-Extra: build
Requires-Dist: ase<4.0,>=3.26; extra == "build"
Requires-Dist: openbabel-wheel<4.0,>=3.1; extra == "build"
Requires-Dist: pymatgen<2026.0,>=2023.12; extra == "build"
Provides-Extra: dev
Requires-Dist: pytest<9.0,>=8.0; extra == "dev"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/cli.gif" alt="nexerra-flow-design terminal session" width="820">
</p>

<p align="center">
  <a href="https://doi.org/10.1021/jacs.6c06920"><img src="https://img.shields.io/badge/paper-JACS%202026-b31b1b.svg" alt="Paper"></a>
  <a href="https://pypi.org/project/nexerra/"><img src="https://img.shields.io/pypi/v/nexerra.svg" alt="PyPI"></a>
  <a href="https://doi.org/10.5281/zenodo.22284384"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.22284384.svg" alt="Zenodo DOI"></a>
  <a href="https://github.com/fairen-group/nexerra-r1/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/python-3.10%20%E2%80%93%203.12-blue.svg" alt="Python 3.10 - 3.12"></a>
  <a href="https://github.com/fairen-group/nexerra-r1/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT"></a>
</p>

<p align="center">
  <b><a href="https://doi.org/10.1021/jacs.6c06920">Paper</a></b> ·
  <b><a href="#results">Results</a></b> ·
  <b><a href="#quickstart">Quickstart</a></b> ·
  <b><a href="#how-it-works">How it works</a></b> ·
  <b><a href="#models-and-data">Models</a></b> ·
  <b><a href="#citation">Citation</a></b>
</p>

**Nexerra<sup>R1</sup> designs organic linkers for metal-organic frameworks.** It pairs a chemical
language model — a variational autoencoder built on transformer encoder-decoder networks,
trained over a corpus of metal-organic framework linkers — with a latent optimal-transport
conditional flow-matching model, so that generation can be steered toward a target
property at inference time. Linkers it designed were built into candidate frameworks, and
one was synthesized and solved by single-crystal X-ray diffraction.

In seeded design mode, a seed linker is encoded into the model's latent space, the flow
transports that latent toward a property-conditioned region of the corpus, and the decoded
candidates are filtered on chemistry and scored against the design objective. One command
is all it takes to go from a starting linker to new design candidates.

Published in the *Journal of the American Chemical Society* **148**, 39546-39555 (2026);
weights, latent banks and the tokenized corpus are archived on Zenodo. The package
automatically loads the weights during the first inference run.

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/header.png" alt="Nexerra-R1">
</p>

## Highlights

- **Exceptional generative capabilities.** The model accurately reproduces the marginals
  of experimentally reported linker properties, achieving a per-token reconstruction
  accuracy of 96.5% over 100+ tokens with > 96% novelty. The model is explicitly biased
  away from synthetically-complex linkers.
- **Property-steered generation.** Latent OT-CFM guidance directs sampling toward
  high-reward regions rather than relying on random neighbourhood search. The available
  weights support increased linker span (with an average 2.4 Å elongation) or
  higher hydrophilicity. The provided trainers can be used to adapt the model to a
  property of interest.
- **Three design modes.** Direct neighbourhood design, scaffold-constrained design that
  holds a core fixed while varying arms, and flow-guided design from a seed linker.
- **Validated end to end.** Designed linker → constructed framework → synthesized and
  characterized by SCXRD at Synchrotron SOLEIL.
- **Reproducible and installable.** `pip install nexerra`, one command to a result, with
  checkpoints fetched and checksum-verified from the Zenodo record of record.

## Results
<a id="results"></a>

### Training behaviour

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/training-metrics.png" alt="Training metrics" width="860">
</p>
<p align="center"><sub>Training logs measured over 172 epochs indicate stable training.
(From left to right, top to bottom): Total loss, reconstruction loss, KL loss, per-token
reconstruction accuracy, internal diversity, and novelty of sampled molecules
(n = 5000).</sub></p>

### Flow-guided property shifts

Conditioning on the OT-CFM flow changes *what* gets sampled, not just how much.

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/flow-shifts.png" alt="Property distribution shifts under flow guidance" width="720">
</p>
<p align="center"><sub>Linker span distributions of molecules sampled from the training
dataset (n = 10,000), Nexerra<sup>R1</sup> (n = 10,000) and Nexerra<sup>R1</sup>-Flow
(n = 10,000). The typical generated linker from Nexerra<sup>R1</sup>-Flow is 2.4 Å longer
compared to the training dataset.</sub></p>

### From linker to framework

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/designs.gif" alt="Five frameworks built from Nexerra-R1 linkers" width="860">
</p>
<p align="center"><sub>Frameworks constructed from linkers designed by Nexerra<sup>R1</sup>,
including CU-525, which was taken through to synthesis and single-crystal X-ray
diffraction.</sub></p>

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/compilation.png" alt="Representative designed linkers" width="860">
</p>
<p align="center"><sub>Representative linkers generated by Nexerra<sup>R1</sup>.</sub></p>

## Quickstart
<a id="quickstart"></a>

Python 3.10-3.12.

```bash
pip install nexerra
nexerra-flow-design --seed '[Lr]c1cc([Lr])cc([Lr])c1'
```

The first run fetches the pretrained weights, which are too large to ship in a wheel. It
lists what it needs, asks before downloading, and takes only the files that mode uses —
about 1.6 GB for flow design, 1.1 GB for the other two. Files are verified against the
Zenodo record's checksums and resume if interrupted.

Assets live in `~/.nexerra`, or `$NEXERRA_HOME` if you set it; results are written to
`./nexerra_output/`. To fetch everything up front:

```bash
nexerra-download-assets
```

Clone the repository instead if you want to train from scratch, build frameworks, or
reproduce the paper's directory layout — inside a clone the commands use the repo's own
paths and nothing is written to your home directory.

The package installs four console commands — the three design modes plus
`nexerra-download-assets` — and leaves the published inference code untouched. The styled
terminal interface wraps the original entrypoints rather than modifying them, so output is
byte-identical to running the scripts directly.

## How it works
<a id="how-it-works"></a>

<p align="center">
  <img src="https://raw.githubusercontent.com/fairen-group/nexerra-r1/main/assets/architecture.png" alt="Model architecture and workflow" width="860">
</p>
<p align="center"><sub>The model architecture &amp; overall workflow.</sub></p>

**Representation.** Linkers are tokenized as SELFIES, so every string decodes to a
chemically valid molecule, and connection points are marked with `[Lr]` placeholders that
are resolved after generation.

**Latent space.** A variational autoencoder (latent dimension 128) is trained over the
linker corpus. Direct and scaffold-constrained design work entirely in this space,
sampling a neighbourhood around an encoded seed and decoding candidates back out.

**Flow guidance.** A conditional optimal-transport flow-matching model is trained on
latents drawn from a property percentile slice of the corpus. At inference it transports
samples toward that slice, with `--guidance-scale` controlling strength, so generation is
steered rather than merely perturbed.

**Selection.** Candidates pass ring, synthetic-complexity (SCScore) and functional-group
filters, then a reward model scores them against the design objective; only those clearing
`--threshold` are returned.

## Usage

Three commands, one per mode:

```bash
nexerra-flow-design      --seed '[Lr]c1cc([Lr])cc([Lr])c1'
nexerra-design           --seed '[Lr]c1cc([Lr])cc([Lr])c1'
nexerra-scaffold-design  --seed 'c1cc([Lr])cc([Lr])c1' --arm '[Lr]C(=O)O'
```

`--seed` takes the linker directly; scaffold-constrained design also needs `--arm`. Use
`--input <file>` for the file layout each entrypoint expects. `nexerra-design` accepts
`--no-filters` to disable chemistry filtering. Add `--plain` for unstyled log output, or
`--export-svg <path>` to save a snapshot of the session.

A fuller flow-guided run:

```bash
nexerra-flow-design --alpha 0.9 --num-samples 1000 --batch-size 128 \
  --reward gas --threshold 0.5 --filters
```

> **Note** — `nexerra-design` and `nexerra-scaffold-design` take their sample count from `n_samples`
> in `inference_config.txt`, which ships with the published value of 5000 — several
> minutes of work. Point `--config` at a file with a smaller `n_samples` for a quick trial.
> `nexerra-flow-design` takes `--num-samples` on the command line instead.

### From Python

```python
from nexerra.utils import cli

cli.flow_design(["--seed", "[Lr]c1cc([Lr])cc([Lr])c1", "--num-samples", "256"])
```

## Models and data
<a id="models-and-data"></a>

All artifacts are archived at [10.5281/zenodo.22284384](https://doi.org/10.5281/zenodo.22284384)
and fetched automatically on first run.

| Artifact | Size | Purpose |
|---|---|---|
| `no_prop_vae_epoch_120.pt` | 528 MB | SELFIES VAE, latent dim 128 |
| `otcfm_step_180000_len.pt` | 60 MB | OT-CFM flow, length-conditioned |
| `otcfm_step_180000_logP.pt` | 60 MB | OT-CFM flow, logP-conditioned |
| `latent_bank.pt` | 442 MB | Latent encodings of the training corpus |
| `latent_bank_len.pt` | 403 MB | Latent bank, length slice |
| `latent_bank_logp.pt` | 442 MB | Latent bank, logP slice |
| `tokenized_dataset.pkl` | 610 MB | Tokenized corpus and vocabulary |

### Model card

**Architecture.** A SELFIES variational autoencoder built on transformer encoder-decoder
networks, latent dimension 128, vocabulary of 62 SELFIES tokens, maximum sequence length
102. On top of it, conditional optimal-transport flow-matching models trained on latents
drawn from a property percentile slice of the corpus — one length-conditioned, one
logP-conditioned.

**Training corpus.** `data/raw/training_dataset.csv`, 898,677 linker SMILES, committed to
this repository. Corpus provenance and construction are described in the
[source publication](https://doi.org/10.1021/jacs.6c06920).

**Splits.** Random, committed as artifacts rather than regenerated at training time:

| Split | Molecules | Share | File |
|---|---|---|---|
| Train | 898,450 | 92.0% | `data/processed/train_smiles.txt` |
| Validation | 39,217 | 4.0% | `data/processed/val_smiles.txt` |
| Test | 39,217 | 4.0% | `data/processed/test_smiles.txt` |

A chemistry-filtered subset of the training split, `filtered_train_smiles.txt`, holds
820,019 molecules. The split files ship as committed artifacts; `preprocess.py` tokenizes
the corpus but does not regenerate them, so reproducing the split exactly means reusing
these files. Distributions across the three splits are plotted in
[`data/figures/train_test_validation_distributions.png`](https://github.com/fairen-group/nexerra-r1/blob/main/data/figures/train_test_validation_distributions.png).

**Training.** 172 epochs. The VAE and the flow model each took approximately 48 hours on a
single NVIDIA RTX 5080.

**Intended use.** Research use: generating candidate organic linkers for metal-organic
frameworks, either sampled freely or steered toward a target property. Generated linkers
are design candidates, not validated materials — they require the usual computational and
experimental screening before synthesis.

**Known limitations.** Described in the
[source publication](https://doi.org/10.1021/jacs.6c06920).

<details>
<summary><strong>Full setup — clone, training extras, Conda fallback</strong></summary>

## Set-up
<a id="set-up"></a>

The default install is for pretrained inference. Training from scratch and MOF
construction utilities are optional extras. Use Conda only when compiled chemistry
dependencies fail to install cleanly through `uv`.

### 1. Clone the repo

```bash
git clone https://github.com/fairen-group/nexerra-r1.git
cd nexerra-R1
```

### 2. Install for pretrained inference

From the repo root:

```bash
uv venv
source .venv/bin/activate
uv pip install -e .
```

Download the pretrained checkpoints and tokenized dataset (about 2.5 GB in total):

```bash
nexerra-download-assets
```

Inside a clone this writes into the repo's own `artifacts/` and `data/` directories. Pass
`--dry-run` to see what it would fetch, or `--dest <dir>` to put them elsewhere.

Sanity-check the installed CLI:

```bash
nexerra-flow-design --help
```

### 3. Install for training from scratch

```bash
uv pip install -e ".[train]"
```

Then follow the [Model Training](#model-training) workflow.

### 4. Install MOF construction utilities

The default inference install does not include Open Babel, ASE, or Pymatgen. If you need
the utilities under `nexerra/build/`:

```bash
uv pip install -e ".[build]"
```

The `nexerra/build/` scripts still expect an external `tobacco3.0` installation.

### 5. Conda fallback

Use this path if `uv` fails on RDKit/Open Babel/Pymatgen, or if you want the full curated
chemistry environment:

```bash
conda env create -f environment.yml
conda activate nexerra
pip install -e .
```

For training in the Conda environment:

```bash
pip install -e ".[train]"
```

### Runtime assets

The inference code expects:

```text
artifacts/ckpt/vae/no_prop_vae_epoch_120.pt
artifacts/ckpt/flow/otcfm_step_180000_len.pt
artifacts/ckpt/flow/otcfm_step_180000_logP.pt
artifacts/latent_banks/latent_bank.pt
artifacts/latent_banks/latent_bank_len.pt
artifacts/latent_banks/latent_bank_logp.pt
data/processed/tokenized_dataset.pkl
data/processed/train_smiles.txt
designed/linker/inference_config.txt
```

`nexerra-download-assets` resolves download links from the Zenodo API and falls back to
direct file URLs if the API cannot be reached. Each file is checked against the record's
md5 and written through a `.part` sidecar, so an interrupted download resumes where it
stopped. Use `--zenodo-record <id>` to pull from a different record, or `--overwrite` to
replace files already on disk.

</details>

<details>
<summary><strong>Supported modes and example inputs</strong></summary>

## Supported Modes
<a id="supported-modes"></a>

> **Tip** — For best results, run inference in flow-guided and/or scaffold-constrained modes.

By default, flow-guided design reads one seed SMILES from `designed/linker/run/input.txt`;
scaffold-constrained design uses `designed/linker/run/input_scaf.txt`.

Inference uses CUDA automatically when a working GPU PyTorch install is available:

```python
torch.device('cuda' if torch.cuda.is_available() else 'cpu')
```

### Direct Design

```text
nexerra/inference/Design.py
```

### Scaffold-Constrained Design

```text
nexerra/inference/ScafDesign.py
```

### Flow-Guided Seeded Design

```text
nexerra/inference/FlowDesign.py
```

Combines the pretrained VAE with a latent OT-CFM model, using the flow checkpoint to steer
decoding.

## Example Inputs
<a id="example-inputs"></a>

Example linker inputs for direct and scaffold-constrained design are documented in:

```text
designed/linker/README.md
```

</details>

<details>
<summary><strong>Model training</strong></summary>

## Model Training
<a id="model-training"></a>

To train from scratch, install the training dependencies before running this workflow:

```bash
uv pip install -e ".[train]"
```

The training workflow has two stages:
- train the VAE linker model
- build a latent bank and train the OT-CFM flow model on top of the pretrained VAE

> **Important** — Training wall-clock time was not systematically benchmarked, but in our runs the base VAE
> and flow model together took approximately 48 hours each on an NVIDIA RTX 5080.

### 1. Prepare tokenized training data

From `nexerra/utils/`, preprocess the raw training CSV into the tokenized dataset bundle
used by both the VAE and flow stages:

```bash
python preprocess.py --mode gen --src ../../data/raw/training_dataset.csv --dst ../../data/processed
```

This produces artifacts such as:
- `data/processed/tokenized_dataset.pkl`
- `data/processed/tok2id.json`
- `data/processed/id2tok.json`

### 2. Train the VAE model

The VAE training entrypoint is:

```text
nexerra/model/Trainer.py
```

Run it from `nexerra/model/` with the tokenized dataset and the raw training CSV:

```bash
python Trainer.py \
  --data ../../data/processed/tokenized_dataset.pkl \
  --rs ../../data/raw/training_dataset.csv \
  --batch 128 --ckpt ../../artifacts/ckpt/vae/
```

The production-oriented defaults in the training script use a `latent_dim` of `128`.
Checkpoints are written per epoch as:

```text
artifacts/ckpt/vae/vae_epoch_<n>.pt
```

To resume training from an existing checkpoint:

```bash
python Trainer.py \
  --data ../../data/processed/tokenized_dataset.pkl \
  --rs ../../data/raw/training_dataset.csv \
  --batch 128 \
  --resume ../../artifacts/ckpt/vae/vae_epoch_<n>.pt \
  --epoch <n>
```

### 3. Build the latent bank

The flow model is trained on latent encodings produced by the pretrained VAE. Build the
latent bank from the training SMILES list using:

```text
nexerra/cfm/build_bank.py
```

Run it from `nexerra/cfm/`:

```bash
python build_bank.py \
  --mode build \
  --data ../../data/processed/train_smiles.txt \
  --batch_size 128 \
  --savepath ../../artifacts/latent_banks/latent_bank.pt
```

This script loads the VAE checkpoint from `artifacts/ckpt/vae/no_prop_vae_epoch_120.pt` by
default and writes the latent bank to the path you provide.

### 4. Train the OT-CFM flow model

The flow training entrypoint is:

```text
nexerra/cfm/otcfm_trainer.py
```

Run it from `nexerra/cfm/` using the latent bank built in the previous step:

```bash
python otcfm_trainer.py \
  --latent_pt ../../artifacts/latent_banks/latent_bank.pt \
  --percentile_start 70 \
  --percentile_end 100 \
  --steps 50000 \
  --batch 2048 \
  --out_path ../../artifacts/ckpt/flow/otcfm_step_50000.pt
```

Important defaults from the training script:
- the flow trainer reloads the pretrained VAE from `artifacts/ckpt/vae/no_prop_vae_epoch_120.pt`
- the tokenizer bundle is loaded from `data/processed/tokenized_dataset.pkl`
- `--matcher otcfm` is the active matcher choice
- `--mode max` or `--mode min` controls whether the conditioned property is maximized or minimized

The percentile arguments define the property slice used for conditional flow matching.
Adjust them to match the reward/property regime you want the model to learn.

### 5. Evaluate a trained flow checkpoint

The same flow training script also supports evaluation sweeps over guidance scales:

```bash
python otcfm_trainer.py \
  --eval_ckpt ../../artifacts/ckpt/flow/otcfm_step_50000.pt \
  --eval_scales 0.0,1.0,1.5,2.0,3.0 \
  --eval_samples 10000
```

</details>

<details>
<summary><strong>Repository layout</strong></summary>

```text
.
├── nexerra                          <- Core source code
│   ├── model                        <- VAE architecture and VAE training code
│   ├── cfm                          <- Latent bank construction and OT-CFM flow training
│   ├── inference                    <- Direct, scaffold-constrained, and flow-guided inference entrypoints
│   ├── build                        <- MOF/CIF construction utilities
│   ├── resources                    <- Small files bundled into the installed package
│   ├── assets.py                    <- First-run download of the pretrained assets from Zenodo
│   └── utils                        <- Tokenization, preprocessing, analysis, and helper modules
├── artifacts                        <- External/runtime artifacts and training outputs
│   ├── ckpt                         <- VAE and flow checkpoints
│   ├── latent_banks                 <- Saved latent bank tensors for flow training/inference
│   └── logs                         <- Training and metrics outputs
├── data                             <- Dataset inputs and processed training assets
│   ├── raw                          <- Raw CSV datasets
│   ├── processed                    <- Tokenized dataset bundle and split SMILES files
│   ├── analysis                     <- Analysis text outputs and summary statistics
│   └── figures                      <- Generated training/evaluation figures
├── designed                         <- User-facing design inputs, outputs, and references
│   ├── linker                       <- Inference config, sample inputs, and runtime linker I/O
│   ├── reference                    <- Reference linkers, CIFs, and scaffold assets
│   └── cif                          <- CIF-side generated artifacts and examples
├── assets                           <- README/demo assets
├── environment.yml                  <- Conda environment definition
├── setup_assets.py                  <- Standalone asset bootstrapper (repo use; see nexerra/assets.py)
├── setup.py                         <- Thin compatibility wrapper
├── LICENSE.md                       <- MIT license
└── README.md                        <- Project documentation
```

</details>

<details>
<summary><strong>Dependencies</strong></summary>

## Dependencies
<a id="dependencies"></a>

For pretrained inference:

```bash
uv pip install -e .
```

For training from scratch:

```bash
uv pip install -e ".[train]"
```

For MOF construction utilities:

```bash
uv pip install -e ".[build]"
```

The default install covers:
- direct, scaffold-constrained, and flow-guided inference
- pretrained asset download via `nexerra-download-assets`

Python 3.10, 3.11 and 3.12 are supported; 3.13 is not, because of the pinned
`torch>=2.5,<2.6` and `numpy<2` requirements.

The training extra adds dependencies for:
- VAE training and preprocessing
- OT-CFM flow training
- analysis and diagnostics utilities

Additional notes:
- If `uv pip install -e .` fails on compiled chemistry dependencies, use the Conda fallback.
- The Open Babel-based helper under `nexerra/build/addH.py` can be installed with
  `uv pip install -e ".[build]"`, but Conda is usually more reliable for Open Babel.
- MOF construction utilities under `nexerra/build/` still expect an external `tobacco3.0`
  package. Alternatively, the system can be made compatible with PoreMake.
- Prototype bio/reward and GCMC workflows are maintained separately in
  [`nexerra-experiments`](https://github.com/fairen-group/nexerra-experiments).
- The SCScore code under `nexerra/utils/scscore/` includes some legacy utilities, but normal
  Nexerra inference does not require the full legacy SCScore training stack. If you use this
  part, please cite the parent publication:

```bib
@article{coley2018scscore,
  title={SCScore: synthetic complexity learned from a reaction corpus},
  author={Coley, Connor W and Rogers, Luke and Green, William H and Jensen, Klavs F},
  journal={Journal of chemical information and modeling},
  volume={58},
  number={2},
  pages={252--261},
  year={2018},
  publisher={ACS Publications}
}
```

</details>

## Citation
<a id="citation"></a>

```bib
@article{menon2026flow,
  title={Flow-Guided Chemical Language Modeling for Linker Design in Reticular Chemistry},
  author={Menon, Dhruv and Singh, Vivek and Chen, Xu and Kiapi, Mohammad Reza Alizadeh and Zyuzin, Ivan and MacLeod, Hamish W and Rampal, Nakul and Shepard, William and Yaghi, Omar M and Fairen-Jimenez, David},
  journal={Journal of the American Chemical Society},
  volume={148},
  number={37},
  pages={39546--39555},
  year={2026},
  doi={10.1021/jacs.6c06920}
}
```

## License

MIT. See [LICENSE.md](https://github.com/fairen-group/nexerra-r1/blob/main/LICENSE.md).

## Funding

This work was primarily carried out at the Adsorption and Advanced Materials (A2ML)
Laboratory. Supported by the Winton Cambridge-Berkeley Exchange Fellowship, the
Engineering and Physical Sciences Research Council (EPSRC), the Trinity Henry-Barlow
(Honorary) Scholarship and the Harding Distinguished Postgraduate Scholarship Programme.
The authors further acknowledge the allocation of beamtime at Synchrotron SOLEIL and the
help of the PROXIMA 2A staff in performing SCXRD experiments.

## Contact

Dhruv Menon — dm958[at]cam[dot]ac[dot]uk

