How molecularai/reinvent4 works
Project type and purpose
• REINVENT is a full‑stack, command‑line molecular design tool built in Python.
• Its core purpose is to generate small molecules using Reinforcement Learning (RL) or Transfer Learning (TL), scoring them against user‑defined property profiles, and outputting optimized compounds.
File structure
• Top‑level CLI entrypoint: reinvent/__main__.py and reinvent/Reinvent.py expose the reinvent command.
• Configuration directory: configs/toml and configs/json contain sample TOML/JSON runmode configurations.
• Core modules under reinvent/:
• runmodes/ orchestrates the high‑level workflows (RL, TL, sampling, scoring).
• datapipeline/ handles data cleaning, normalization, tokenization.
• models/ implements multiple model families (RNN, Transformer) and a factory for instantiation.
• scoring/ implements the multi‑component scoring plugin system.
• chemistry/ handles molecule standardization, conversions, and library design.
• utils/ and support/ for CLI helpers, config parsing, and external script wrappers.
• Plugins: reinvent_plugins/ and contrib/reinvent_plugins/ demonstrate the native‑package scoring plugin system.
• Tests and notebooks cover unit, integration tests and tutorials.
README for additional insights
• The workflow is driven via reinvent sampling|scoring|TL|RL commands plus a TOML/JSON config.
• GPU/CPU is selected via environment (PyTorch backend).
• Plugins are auto‑discovered under any reinvent_plugins/components folder in PYTHONPATH.
a. Main components:
1. CLI & Config Parser
2. Runmode Orchestrator (RL, TL, Sampling, Scoring managers)
3. Model Factory & Model Sampler (RNN/Transformer families)
4. Data Pipeline (filters, normalizers, tokenizers)
5. Chemistry Module (standardizers, library design)
6. Scoring Engine (core + plugin components)
7. Plugin Registry (native‑package loader)
8. Reporting (TensorBoard, CSV, remote)
9. FileSystem / Priors / Config / Logs
10. External Executors (dockers, subprocesses for docking, QSAR, etc.)
b. Relationships & data flow:
• User invokes CLI → Config Parser reads TOML/JSON → Runmode Orchestrator.
• Orchestrator uses Model Factory to load a Prior or Agent model → Data Pipeline converts molecules to tokens.
• Model Sampler proposes new SMILES → Chemistry Module standardizes molecules.
• Scoring Engine computes component scores (invoking plugins in Plugin Registry, external programs, or internal transforms).
• Runmode RL: uses scores to compute reward and update model weights (via PyTorch).
• Runmode TL: fine‑tunes model on provided dataset via Data Pipeline and Model Trainer.
• Results & metrics stream to Reporting subsystem, files on disk, and optionally remote endpoints.
• Priors and pre‑trained models loaded from priors/.
c. Architectural patterns & design principles:
• Modular plugin architecture: scoring components auto‑registered using namespace packages.
• Factory pattern: models/model_factory to abstract model instantiation.
• Pipeline abstraction: data cleaning and scoring broken into filter/transform chains.
• Separation of concerns: chemistry, modeling, scoring, orchestrator, and I/O live in distinct packages.
• CLI‑driven entrypoint decoupled from core logic.
d. Key technologies & frameworks:
• Python 3.10+
• PyTorch (GPU/CPU) for model definitions and training loops.
• TOML/JSON for configuration.
• RDKit/OpenEye in chemistry and scoring plugins.
• pytest for test suites.
• Jupytext/Jupyter for notebooks.
Detailed capture of architecture
• Don’t omit the Plugin Registry: show how it dynamically imports scoring components.
• Model Factory branching by model type and associated vocabulary/dataset modules.