Skip to content

About

Extended CycleChemist to become a hardened, DFT-validated RL framework for organic photovoltaic (OPV) discovery, combining generative transformers, structural plausibility gating, and TD-DFTB oracle validation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CycleChemist (Extended)

Disclaimer: This is a snapshot of an actively developed project, not the latest version. Ongoing work continues in a private repository and has not been synced here. Contact Dr. Mohsen Rezayat for more details: mohsen.rezayat@omid-usa.org

A hardened, DFT-validated extension of CycleChemist, a dual-pronged machine learning framework for organic photovoltaic (OPV) discovery. The original framework paired a generative molecular transformer (MatGPT) with GNN property predictors (MOE2/P3, OPVC) and a reinforcement learning loop to design novel donor:acceptor (D:A) molecular pairs. This version rebuilds that RL loop around real quantum-chemistry validation and reward-hacking-resistant gating, closing the gap between what the reward model scores highly and what is actually a synthesizable, spectrally plausible D:A candidate.

What This Version Adds

The base CycleChemist reward signal (PCE and transparency scores from a learned surrogate) is fast but exploitable: a policy can learn to maximize the surrogate's score without producing chemistry that a domain expert, or a real quantum-chemical calculation, would accept. This version closes that gap with a three-phase gating system layered directly into the RL fine-tuning loop (matgpt/code/finetune.py):

  • Phase 1: Structural plausibility gate (matgpt/code/structural_gates.py) — scores every RL-generated candidate against the literature-typical D-A conjugated-polymer motif (extended conjugation, a solubilizing alkyl chain, donor/acceptor SMARTS motifs) using soft, multiplicatively-combined checks, so a candidate cannot earn full credit by satisfying only one axis of "looks like a real OPV polymer."

  • Phase 2: Curated D-A fragment library and synthetic corpus builder (matgpt/code/fragment_library.py, matgpt/code/build_fragment_corpus.py) — assembles donor and acceptor building blocks, each tagged with RDKit attachment points, into synthetically-plausible D-A oligomers via molzip, with randomized solubilizing-chain lengths per sample. This corpus is used to fine-tune MatGPT toward the real D-A polymer chemical space before RL ever begins.

  • Phase 3: Oracle-driven validation gate (property_predictors/moe2_p3/dftb_oracle.py, phase3_validate.py, validate_top_candidates.py) — a DFTB+/xTB pipeline computes actual TD-DFTB excitation spectra for candidate molecules and derives Phi_vis / AVT from them, giving the RL loop a ground-truth-adjacent signal instead of relying solely on a learned PCE surrogate. The gate is triggered selectively during RL fine-tuning, renormalizes and calibrates the spectral surrogate's output against oracle spectra, and gates the spectral reward path by OPV-material probability so a high transparency score can no longer be earned by drifting outside the OPV-relevant chemical space. Known TD-DFTB limitations (systematic underestimation of charge-transfer excitation energies in donor-acceptor push-pull systems) are documented in-code rather than silently absorbed into the reward.

  • RL training stability fixes: gradient clipping and a floored reward-anneal term in the fine-tuning loss, plus a pass of CLI argument fixes (store_true footguns) that had been silently producing wrong runs.

  • Test coverage: structural_gates.py and fragment_library.py ship with pytest suites (matgpt/code/tests/) — the RL reward's gating logic has regression coverage where the original codebase had none.

  • Repo hygiene: checkpoint directories are untracked and gitignored rather than committed, keeping the repo lightweight and reproducible from config instead of from stored weights.

Net effect: the generation-validation loop no longer trusts a single learned scalar. A candidate has to pass a structural plausibility check, come from (or resemble) a corpus of synthetically real D-A chemistry, and hold up under an actual excited-state quantum-chemistry calculation before it is rewarded as a good OPV candidate.

Overview

The underlying discovery framework combines material generation, property prediction, and reinforcement learning for iterative improvement:

CycleChemist discovery framework

Credit

This work builds directly on CycleChemist, originally developed by Hou Hei Lam, Jiangjie Qiu, Xiuyuan Hu, Wentao Li, Fankun Zeng, Siwei Fu, Hao Zhang, and Xiaonan Wang — see CycleChemist: A Dual-Pronged Machine Learning Framework for Organic Photovoltaic Discovery and the earlier Accelerating High-Efficiency Organic Photovoltaic Discovery via Pretrained Graph Neural Networks and Generative Reinforcement Learning. The MatGPT generative model, the MOE2/P3 and OPVC property predictors, and the original RL fine-tuning scaffold are their work. The DFTB+/xTB oracle pipeline, spectral calibration, multi-phase reward gating, fragment-based corpus construction, and associated test coverage described above are additions in this version, maintained by Om (@OJ102).

Datasets

  • Experimental dataset (used in experiments): data/exp_dataset.csv
  • Active / continuously updated dataset: OPV2D
  • D-A fragment library (this version): data/fragments/da_fragments.csv

Quick Start

Installation

This repo was developed with Python 3.9. A minimal setup is:

conda create -n CycleChemist python=3.9 -y
conda activate CycleChemist

# PyTorch (example: CUDA 11.8; adjust for your machine)
pip install torch==2.7.1 torchvision==0.22.1 torchaudio==2.7.1 --index-url https://download.pytorch.org/whl/cu118

# Core scientific stack
conda install -c conda-forge numpy pandas tqdm psutil scikit-learn rdkit torch-geometric tensorboard matplotlib seaborn -y

To use the DFTB+/xTB oracle pipeline (Phase 3), also install DFTB+ with the 3ob-3-1 Slater-Koster parameter set (bundled under DFTB/) and set DFTB_PARAM_DIR to its location.

Data Preparation

PubChem

cd data/
wget ftp://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Extras/CID-SMILES.gz
gunzip CID-SMILES.gz
tr '\t' ',' < CID-SMILES > CID-SMILES.csv
sed -i '1i CID,SMILES' CID-SMILES.csv
python down_sample.py
cd ..

MMC2

Source: "Design Principles and Top Non-Fullerene Acceptor Candidates for Organic Photovoltaics" (https://www.sciencedirect.com/science/article/pii/S2542435117301307)

cd data/
wget -O mmc2.csv "https://ars.els-cdn.com/content/image/1-s2.0-S2542435117301307-mmc2.csv"
cd ..

Training

MatGPT Pretraining

python matgpt/code/pretrain.py --config matgpt/pretrain_config/pubchem.json
tensorboard --logdir matgpt/runs/matgpt_pretrain_pubchem/

Training OPVC

python property_predictors/opvc/build_opv_dataset.py
python property_predictors/opvc/train_rf_classifier.py

Training MOE2 and P3

python property_predictors/moe2_p3/pretrain.py
python property_predictors/moe2_p3/train_pce.py

tensorboard --logdir property_predictors/moe2_p3/runs/MLM-Pretrain
tensorboard --logdir property_predictors/moe2_p3/runs/HOMO-Finetune
tensorboard --logdir property_predictors/moe2_p3/runs/HOMO-EXP-Finetune
tensorboard --logdir property_predictors/moe2_p3/runs/PCE-Predict

MatGPT Finetuning (on exp_dataset.csv)

# Fit to data/exp_dataset.csv
python matgpt/code/pretrain.py --config matgpt/pretrain_config/exp_dataset.json
tensorboard --logdir matgpt/runs/matgpt_pretrain_exp_dataset/

Phase 2: D-A Fragment Corpus (this version)

Build a synthetic D-A oligomer corpus from the curated fragment library and fine-tune MatGPT toward it before RL:

python matgpt/code/build_fragment_corpus.py
python matgpt/code/pretrain.py --config matgpt/pretrain_config/hendsbee_da_corpus.json

Case study: fix acceptor (Y6) and search for donors

python matgpt/code/finetune.py \
  --run_name donor_Y6 \
  --prior_path matgpt/ckpt/matgpt_pretrain_exp_dataset/final_model.pt \
  --target_type "donor" \
  --fixed_smiles "CCCCCCCCCCCc1c(/C=C2\C(=O)c3cc(F)c(F)cc3C2=C(C#N)C#N)sc2c1sc1c3c4nsnc4c4c5sc6c(CCCCCCCCCCC)c(/C=C7\C(=O)c8cc(F)c(F)cc8C7=C(C#N)C#N)sc6c5n(CC(CC)CCCC)c4c3n(CC(CC)CCCC)c21" \
  --use_homo_lumo_loss

tensorboard --logdir matgpt/runs/donor_Y6

Case study: fix donor (PTB7-Th) and search for acceptors

python matgpt/code/finetune.py \
  --run_name acceptor_PTB7-Th \
  --prior_path matgpt/ckpt/matgpt_pretrain_exp_dataset/final_model.pt \
  --target_type "acceptor" \
  --fixed_smiles "CCCCC(CC)COC(=O)c1sc2c(-c3cc4c(-c5ccc(CC(CC)CCCC)s5)c5sc(C)cc5c(-c5ccc(CC(CC)CCCC)s5)c4s3)sc(C)c2c1F" \
  --use_homo_lumo_loss

tensorboard --logdir matgpt/runs/acceptor_PTB7-Th

Both case studies now run against the Phase 1/2/3 gates by default when the corresponding config flags are set — see matgpt/code/finetune.py for the structural-gate, oracle-trigger, and reward-anneal flags.

Phase 3: Oracle Validation (this version)

Validate a trained spectral surrogate, or a batch of top RL candidates, against real DFTB+/TD-DFTB spectra:

python property_predictors/moe2_p3/phase3_validate.py --n-workers 4
python property_predictors/moe2_p3/validate_top_candidates.py

Optional: Sampling

python matgpt/code/sample.py \
  --model_path matgpt/ckpt/rl_fine_tune/donor_Y6/step500.pt \
  --vocab_path data/vocab_pubchem_len20-290_no_ions_no_multi_random5M_123.txt \
  --output_path results/out.csv

Citation

There is yet to be a published version of this repository. If you use this work in your research, please cite the repository and the original CycleChemist papers:

@misc{qiu2025,
      title={Accelerating High-Efficiency Organic Photovoltaic Discovery via Pretrained Graph Neural Networks and Generative Reinforcement Learning}, 
      author={Jiangjie Qiu and Hou Hei Lam and Xiuyuan Hu and Wentao Li and Siwei Fu and Fankun Zeng and Hao Zhang and Xiaonan Wang},
      year={2025},
      eprint={2503.23766},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2503.23766}, 
}

@misc{lam2025cyclechemistdualprongedmachinelearning,
      title={CycleChemist: A Dual-Pronged Machine Learning Framework for Organic Photovoltaic Discovery}, 
      author={Hou Hei Lam and Jiangjie Qiu and Xiuyuan Hu and Wentao Li and Fankun Zeng and Siwei Fu and Hao Zhang and Xiaonan Wang},
      year={2025},
      eprint={2511.19500},
      archivePrefix={arXiv},
      primaryClass={cond-mat.mtrl-sci},
      url={https://arxiv.org/abs/2511.19500}, 
}

And cite the original data sources:

@article{Min2020,
   author  = {Wu, Yao and Guo, Jie and Sun, Rui and Min, Jie},
   title   = {Machine learning for accelerating the discovery of high-performance donor/acceptor pairs in non-fullerene organic solar cells},
   journal = {npj Computational Materials},
   volume  = {6},
   number  = {1},
   pages   = {120},
   year    = {2020}
}

@article{Saeki2021,
   author  = {Miyake, Yuta and Saeki, Akinori},
   title   = {Machine Learning-Assisted Development of Organic Solar Cell Materials: Issues, Analyses, and Outlooks},
   journal = {The Journal of Physical Chemistry Letters},
   volume  = {12},
   number  = {51},
   pages   = {12391-12401},
   year    = {2021}
}

@article{lopez2017design,
   title     = {Design principles and top non-fullerene acceptor candidates for organic photovoltaics},
   author    = {Lopez, Steven A and Sanchez-Lengeling, Benjamin and de Goes Soares, Julio and Aspuru-Guzik, Al{\'a}n},
   journal   = {Joule},
   volume    = {1},
   number    = {4},
   pages     = {857--870},
   year      = {2017},
   publisher = {Elsevier}
}

About

Extended CycleChemist to become a hardened, DFT-validated RL framework for organic photovoltaic (OPV) discovery, combining generative transformers, structural plausibility gating, and TD-DFTB oracle validation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages