# undeadpixel/reinvent-gdb13 architecture

> Architecture diagram of the GitHub repository undeadpixel/reinvent-gdb13, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/undeadpixel/reinvent-gdb13
- Repository: https://github.com/undeadpixel/reinvent-gdb13

## Overview

##### Main components
- Input Data: SMILES files containing chemical structure data.
- Preprocessing/Vocabulary Creation: Code in the “models/reinvent” module (e.g., vocabulary.py and dataset.py) that processes input SMILES to extract or compute the vocabulary.
- Model Creation: The “create_model.py” script is used to generate an empty model configured with the right parameters (embedding layer size, number of GRU layers, and GRU layer size).
- Model Training: The “train_model.py” script that uses the created model and training data to adjust model parameters over a number of epochs.
- Model Sampling: The “sample_from_model.py” script which loads a trained model (from the trained_models folder) to generate chemical structures or retrieve log-likelihoods.
- Supporting Libraries and Environment: The environment.yml file shows that dependencies are managed via Conda.

##### Interactions between components
- Data Flow:
- SMILES Input → Preprocessing/Vocabulary Extraction (models/reinvent/dataset.py, vocabulary.py)
- Preprocessed Data → Model Creation (create_model.py) where the vocabulary is embedded into a blank model.
- Blank Model + Training Data → Model Training (train_model.py). Here, the GRU-based RNN learns the chemical space.
- Trained Model (saved in the “trained_models” folder) → Model Sampling (sample_from_model.py) to produce new SMILES or calculate log-likelihood.
- The components are loosely connected via file I/O, where intermediate files (empty model files and trained model files) are passed from one stage to the next.

##### Architectural patterns and design principles
- Modularity: The project leverages a module (models/reinvent) that encapsulates dataset handling, model definition, and utility functions for the RNN architecture.
- Pipeline/Workflow: There is a clearly defined workflow beginning with model creation, followed by training, and finally inference (sampling). Each step is handled by a dedicated script.
- Parameterization: Key hyperparameters (number of GRU layers, GRU layer size, embedding size) are exposed via command-line arguments, which enhances flexibility and reusability.
- Reproducibility: The inclusion of a Conda environment (environment.yml) ensures that the project can be set up with all required libraries easily.

##### Detailed Elements
- “Input SMILES Data”
- “Data Preprocessing & Vocabulary Extraction (dataset.py, vocabulary.py)”
- “Model Creation (create_model.py)”
- “Model Training (train_model.py)”
- “Trained Model Storage (trained_models folder)”
- “Model Sampling & Inference (sample_from_model.py)”
- Annotations for key hyperparameters and configuration options (e.g., GRU layer size, number of GRU layers, embedding layer size).
- External dependencies (like the Conda environment and any required libraries referenced in environment.yml).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main components
    A(("Input SMILES Data")):::data
    subgraph "Data Preprocessing & Vocabulary Extraction"
        DP1["Dataset Processing (dataset.py)"]:::preproc
        DP2["Vocabulary Extraction (vocabulary.py)"]:::preproc
        DP1 --> DP2
    end
    C["Model Creation (create_model.py)"]:::process
    D["Model Training (train_model.py)"]:::process
    E(("Trained Model Storage (trained_models folder)")):::storage
    F["Model Sampling & Inference (sample_from_model.py)"]:::process
    G["Environment & Dependencies (environment.yml)"]:::env

    %% Data Flow
    A --> DP1
    DP2 --> C
    C --> D
    D --> E
    E --> F

    %% Environment Dependencies connections (dotted lines)
    G --- A
    G --- DP1
    G --- DP2
    G --- C
    G --- D
    G --- E
    G --- F

    %% Click Events
    click DP1 "https://github.com/undeadpixel/reinvent-gdb13/blob/master/models/reinvent/dataset.py"
    click DP2 "https://github.com/undeadpixel/reinvent-gdb13/blob/master/models/reinvent/vocabulary.py"
    click C "https://github.com/undeadpixel/reinvent-gdb13/blob/master/create_model.py"
    click D "https://github.com/undeadpixel/reinvent-gdb13/blob/master/train_model.py"
    click E "https://github.com/undeadpixel/reinvent-gdb13/tree/master/trained_models"
    click F "https://github.com/undeadpixel/reinvent-gdb13/blob/master/sample_from_model.py"
    click G "https://github.com/undeadpixel/reinvent-gdb13/blob/master/environment.yml"

    %% Styles
    classDef data fill:#FFF2CC, stroke:#B58900, stroke-width:2px, rx:10, ry:10
    classDef preproc fill:#FFCCCC, stroke:#CC0000, stroke-width:2px, rx:10, ry:10
    classDef process fill:#CCFFCC, stroke:#007700, stroke-width:2px, rx:10, ry:10
    classDef storage fill:#FFD700, stroke:#B8860B, stroke-width:2px, rx:10, ry:10
    classDef env fill:#CCE5FF, stroke:#0066CC, stroke-width:2px, rx:10, ry:10
```
