# wangchenghuidream/rnnmgm architecture

> Architecture diagram of the GitHub repository wangchenghuidream/rnnmgm, 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/wangchenghuidream/rnnmgm
- Repository: https://github.com/wangchenghuidream/rnnmgm

## Overview

##### Project Type & Purpose
- This project is centered on developing and training recurrent neural network (RNN) based models for molecular generation.
- It supports both a generative model (CLM_RNN) and a predictive (scorer or regressor) model, with the workflow including data preprocessing, training (with both pretraining and fine-tuning steps), generation of new molecules, and the scoring of generated outputs.
- The README outlines distinct sections for data preprocessing, training (with separate launchers for generation and predictive tasks), generation, and scoring.

##### File Structure
- Data Directory: Contains various CSV and ZIP files along with README documentation. These represent the datasets that are used for both training the models and generating molecules.
- Model Files: Found under the "models" directory – including clm_rnn.py (likely for generating molecule sequences) and reg_rnn.py (for predictive/regression tasks). This indicates a separation between modules hence designating clear architectural boundaries.
- Launcher Scripts:
- launcher_of_clm.py for operations related to the generative model.
- launcher_of_sm.py for operations related to the predictive scoring model.
- Utility Modules:
- The "utils" directory contains important helper scripts like augmentation (data preprocessing), builder, and tools.
- A dedicated "SA_Score" package under "utils" serves for scoring functions, complete with its own initialization, test, and data files.
- Configs File: A top-level configuration script likely used to centralize parameters across modules.

a. Main Components:
- Data Layer: Represented by the "data" directory, including all raw CSV/ZIP inputs.
- Data Preprocessing Module: Illustrated by the utils/augmentation.py and possibly aspects of the builder and other tools in utils.
- Generative Model (CLM_RNN): Encapsulated by models/clm_rnn.py and launched via launcher_of_clm.py. This should also cover the two-stage training (pretrain and fine-tune) process.
- Predictive/Scoring Model (Reg_RNN): Located in models/reg_rnn.py and launched via launcher_of_sm.py, with close integration to scoring logic from SA_Score.
- Scoring Module: The SA_Score subpackage (within utils), including its scoring functions and unit tests.
- Configuration Module: The configs.py file ensuring centralized parameters and configuration management.

b. Interactions & Data Flow:
- From the Data Layer to the Data Preprocessing Module (augmentation functions and builders).
- From the Preprocessing Module to both the Generative Model (training via launcher_of_clm.py) and Predictive Model (training via launcher_of_sm.py).
- Data flow between the output of pretraining and fine-tuning (as one feeds into the predictive model training, where pretrainer parameters are specified).
- Links between the Predictive Model and the Scoring Module (where score() is triggered).

c. Architectural Patterns & Design Principles:
- Separation of concerns: Distinct modules handle data preprocessing, model training, generation, and scoring.
- Pipeline flow: The architecture is designed as a pipeline – starting with raw data, moving through preprocessing, training, and finally generation/scoring.
- Reusability & Modularity: The use of subdirectories (models, utils with SA_Score subpackage) suggests an emphasis on modularity.

d. Relevant Technologies & Frameworks:
- While not explicitly stated, the naming conventions (RNN, augmentation) imply usage of machine learning libraries (such as PyTorch or TensorFlow) for model training.
- The project may also include traditional Python tools for data handling (pandas, numpy) indicated by CSV usage.
- Clearly denote the custom scoring utilities in SA_Score which appear to be significant.

##### Elements
- Optionally, add sequence labels to illustrate the training steps (pretrain, fine-tune, generate, and score).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Layer"
        DL["Data Layer"]:::dataLayer
    end

    subgraph "Data Preprocessing"
        A["Augmentation"]:::preproc
        B["Builder"]:::preproc
    end

    subgraph "Generative Model (CLM_RNN)"
        CLM["CLM_RNN Model"]:::model
        CLMLauncher["CLM Launcher"]:::model
    end

    subgraph "Predictive Model (Reg_RNN)"
        REG["Reg_RNN Model"]:::model
        SMLauncher["SM Launcher"]:::model
    end

    SM["Scoring Module (SA_Score)"]:::scoring
    CFG["Configurations"]:::config

    DL -->|"raw_data"| A
    DL -->|"raw_data"| B
    A -->|"preprocessed"| CLMLauncher
    B -->|"preprocessed"| CLMLauncher
    A -->|"preprocessed"| SMLauncher
    B -->|"preprocessed"| SMLauncher
    CLMLauncher -->|"trains"| CLM
    CLM -->|"pretraining_to"| REG
    SMLauncher -->|"trains"| REG
    REG -->|"score_trigger"| SM

    CFG ---|"config_params"| A
    CFG ---|"config_params"| B
    CFG ---|"config_params"| CLM
    CFG ---|"config_params"| REG

    classDef dataLayer fill:#FFF3CD,stroke:#FFB100,stroke-width:2px;
    classDef preproc fill:#D4EFDF,stroke:#28B463,stroke-width:2px;
    classDef model fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef scoring fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px;

    click DL "https://github.com/wangchenghuidream/rnnmgm/tree/main/data"
    click A "https://github.com/wangchenghuidream/rnnmgm/blob/main/utils/augmentation.py"
    click B "https://github.com/wangchenghuidream/rnnmgm/blob/main/utils/builder.py"
    click CLM "https://github.com/wangchenghuidream/rnnmgm/blob/main/models/clm_rnn.py"
    click CLMLauncher "https://github.com/wangchenghuidream/rnnmgm/blob/main/launcher_of_clm.py"
    click REG "https://github.com/wangchenghuidream/rnnmgm/blob/main/models/reg_rnn.py"
    click SMLauncher "https://github.com/wangchenghuidream/rnnmgm/blob/main/launcher_of_sm.py"
    click SM "https://github.com/wangchenghuidream/rnnmgm/tree/main/utils/SA_Score"
    click CFG "https://github.com/wangchenghuidream/rnnmgm/blob/main/configs.py"
```
