How marcusolivecrona/reinvent works
Project type and purpose
• This is an open‑source molecular‐generation tool that uses a Recurrent Neural Network “Prior” plus a reinforcement‐learning “Agent” to sample chemical structures (SMILES).
• It includes data preprocessing, model training (Prior & Agent), scoring, logging, and a lightweight Bokeh‐based visualization (“Vizard” app).
File structure
• Top level:
– data_structs.py, train_prior.py → Data ingestion & Prior training
– train_agent.py (called by main.py), scoring_functions.py → RL Agent training
– model.py, utils.py → Core model definitions & helpers
– multiprocess.py → Parallel sampling/training support
– vizard_logger.py → Logging interface to the Vizard app
– Vizard/ → Bokeh web‐app (templates + run scripts)
– data/ → SMILES files, vocab, model checkpoints, classifier pickles
– images/ → Demo GIFs and static assets
• Configuration: theme.yaml for Vizard styling, run.sh to launch the UI.
README for additional insights
• The workflow is command‐line‐driven: first filter and build vocabulary; then train a “Prior”; then launch Agent training via main.py.
Main components and their interactions
a. Data Ingestion & Preprocessing
– data_structs.py parses raw SMILES, filters them, builds a token vocabulary → outputs filtered .smi and Voc → stored in data/
b. Prior Training Pipeline
– train_prior.py + model.py + utils.py → consumes data/Voc & filtered SMILES → produces a pre‐trained “Prior” checkpoint (Prior.ckpt)
c. Reinforcement Learning Agent
– main.py / train_agent.py + multiprocess.py + scoring_functions.py → loads Prior, interacts with external scoring (e.g. QSAR model via clf.pkl), computes rewards, updates Agent RNN
d. Logging & Visualization
– vizard_logger.py writes training metrics, sampled SMILES, model weights → outputs logs to data/logs
– Vizard run.sh + templates/index.html + styles.css + theme.yaml → Bokeh server reads logs, hosts a live web UI at localhost:5006/Vizard
e. External dependencies
– PyTorch (model & training loops)
– RDKit (SMILES parsing & chemical operations)
– Scikit‑Learn (QSAR scoring functions)
– pexpect, tqdm, standard Python3.6 ecosystem
Architectural patterns & design principles
• Pipeline pattern: clear separation of data preparation → Prior pretraining → RL Agent training → logging → visualization
• Modular design: each major step is a standalone script or module
Final checklist
• Callouts for key frameworks and file artifacts