# miloszgrabski/deepchem_molgan architecture

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

- Interactive diagram: https://gitdiagram.com/miloszgrabski/deepchem_molgan
- Repository: https://github.com/miloszgrabski/deepchem_molgan

## Overview

##### Project Type & Purpose
- This is an open‐source DeepChem extension implementing the MolGAN paper (graph‐based molecular generative adversarial network).
- It provides a featurizer, custom graph layers, and a MolGAN model, intended to be merged into DeepChem as of v2.5.

##### File Structure
Top‐level modules:
- data/ – raw QM9 dataset (.csv)
- feat/ – MolGANFeaturizer (converts molecules to graph tensors)
- layers/ – custom graph neural network layers (generator, discriminator components)
- models/ – MolGAN architecture (wiring of generator, discriminator, reward net)
- main.ipynb & tutorial.ipynb – demonstration notebooks
Other files: packaging (__init__.py), config (.gitignore, .gitattributes), metadata (LICENSE, README).

##### Gather Insights from README
- Implements “MolGAN” in DeepChem 2.4, migrating code directly into DeepChem’s repository.
- No external services—pure library code to be called from Python or notebooks.

##### Main Components & Their Interactions
- Data Ingestion
- Source: data/QM9_HAC_5_9_.csv
- Responsible for loading raw molecular data.
- Featurization
- feat/molgan_featurizer.py
- Transforms SMILES (or molecule objects) → graph adjacency & feature tensors.
- Custom Layers
- layers/layers.py
- Implements graph conv, noise‐to‐graph (generator), graph‐to‐scalar (discriminator, reward network).
- MolGAN Model
- models/molgan.py
- Assembles generator, discriminator, reward network; defines loss, training loop hooks.
- Execution / Orchestration
- main.ipynb / tutorial.ipynb
- Example pipelines: load data → featurize → instantiate MolGAN → train → sample new molecules.
- External Dependencies
- DeepChem core (v2.4+), RDKit (chemistry utilities), TensorFlow or PyTorch backend.

##### Architectural Patterns & Principles
- Modular layering: clear separation between data handling, featurization, network layers, high‐level model.
- Extensibility point: new featurizers or layers can be dropped into feat/ or layers/ without altering core model.
- Leverages DeepChem’s Trainer API for standard training loops.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Repository Modules
    subgraph "Repository Modules"
        DataCSV["QM9_HAC_5_9_.csv"]:::inrepo
        Featurizer["MolGANFeaturizer"]:::inrepo
        Layers["Custom Graph Layers"]:::inrepo
        Model["MolGAN Model"]:::inrepo
        Init["__init__.py"]:::inrepo
        Metadata["README.md & LICENSE"]:::inrepo
    end

    %% User-Facing Notebooks
    subgraph "User Notebooks"
        MainNB["main.ipynb"]:::notebook
        TutorialNB["tutorial.ipynb"]:::notebook
    end

    %% External Dependencies
    subgraph "External Dependencies"
        DC["DeepChem Core"]:::external
        RDKit["RDKit"]:::external
        TF["TensorFlow/PyTorch"]:::external
    end

    %% Data and Control Flow
    DataCSV -->|"raw SMILES"| Featurizer
    Featurizer -->|"graph tensors"| Model
    Model -->|"invokes layers"| Layers
    Model -->|"integrates"| DC
    DC -->|"backend support"| TF
    Model -->|"uses cheminformatics"| RDKit
    MainNB -->|"orchestrates pipeline"| DataCSV
    MainNB -->|"calls featurizer"| Featurizer
    MainNB -->|"trains model"| Model
    TutorialNB -->|"demonstrates"| MainNB

    %% Click Events
    click DataCSV "https://github.com/miloszgrabski/deepchem_molgan/blob/master/data/QM9_HAC_5_9_.csv"
    click Featurizer "https://github.com/miloszgrabski/deepchem_molgan/blob/master/feat/molgan_featurizer.py"
    click Layers "https://github.com/miloszgrabski/deepchem_molgan/blob/master/layers/layers.py"
    click Model "https://github.com/miloszgrabski/deepchem_molgan/blob/master/models/molgan.py"
    click MainNB "https://github.com/miloszgrabski/deepchem_molgan/blob/master/main.ipynb"
    click TutorialNB "https://github.com/miloszgrabski/deepchem_molgan/blob/master/tutorial.ipynb"
    click Init "https://github.com/miloszgrabski/deepchem_molgan/blob/master/__init__.py"
    click Metadata "https://github.com/miloszgrabski/deepchem_molgan/blob/master/README.md"

    %% Styles
    classDef inrepo fill:#AED6F1,stroke:#1F618D,color:#1B4F72
    classDef external fill:#ABEBC6,stroke:#1D8348,color:#145A32
    classDef notebook fill:#F9E79F,stroke:#B7950B,color:#7D6608
```
