This project explores a graph encoding technique for molecular graphs using the ESOL dataset. The main idea is to enrich each node's feature vector by adding information about its neighboring nodes through an adjacency-based encoding. The encoded graphs are then used to compare the performance of different Graph Neural Network (GNN) models.
Graph Neural Networks usually learn from node features and graph connectivity separately. In this project, the graph structure is directly incorporated into the node features by concatenating each node's adjacency information with its original features.
The workflow compares three graph learning models:
- Graph Convolutional Network (GCN)
- Graph Attention Network (GAT)
- Transformer-based Graph Model
The models are trained to predict molecular solubility values from the ESOL dataset.
Dataset: ESOL (Delaney)
Source:
- MoleculeNet
- Loaded using PyTorch Geometric
Each molecule is represented as a graph:
- Nodes = Atoms
- Edges = Chemical bonds
- Target = Water solubility (regression)
Load the ESOL molecular dataset using PyTorch Geometric.
For every molecule:
- Extract original node features
- Build an adjacency matrix
- Concatenate adjacency information with node features
Original node feature size:
9 features
Example:
Original node features
Atom A
[feature1 feature2 ... feature9]
↓
Encoded node features
[feature1 ... feature9 | adjacency row]
This allows every node to contain both:
- Chemical information
- Neighbor connectivity information
Since molecules contain different numbers of atoms, every graph is padded to the maximum graph size in the dataset.
Padding ensures all graphs have the same dimensions before batching.
Example:
Maximum nodes: 55
Original graph:
32 × 41
↓
Padded graph:
55 × 64
The dataset is divided into:
- 80% Training
- 10% Validation
- 10% Testing
Uses graph convolution layers to aggregate neighborhood information.
Uses attention weights to determine the importance of neighboring nodes.
Uses Multi-Head Self-Attention instead of graph convolution to capture long-range dependencies between nodes.
Each model is trained for 20 epochs.
Loss Function:
Mean Squared Error (MSE)
Optimizer:
Adam
Learning Rate:
0.001
Performance is evaluated using:
Root Mean Squared Error (RMSE)
Lower RMSE indicates better prediction performance.
The experiment compares:
| Model | Performance |
|---|---|
| GCN | Baseline |
| GAT | Best RMSE |
| TransformerGraph | Highest RMSE in current implementation |
The GAT model achieved the best predictive performance on the ESOL dataset.
- Python
- PyTorch
- PyTorch Geometric
- NumPy
- Matplotlib
- Scikit-learn
Graph_Encoding/
│
├── Untitled0.ipynb # Main notebook
├── README.md
└── requirements.txt
Clone the repository
git clone https://github.com/ParisaArbab/Graph_Encoding.gitInstall dependencies
pip install torch
pip install torch-geometric
pip install rdkit
pip install matplotlib
pip install scikit-learnOpen the notebook:
Untitled0.ipynb
Run all cells sequentially.
- Fix the Transformer output shape mismatch warning.
- Replace adjacency concatenation with weighted edge encoding.
- Experiment with positional encodings for graphs.
- Add graph-level pooling for the Transformer model.
- Evaluate on additional MoleculeNet datasets such as FreeSolv and Lipophilicity.
- Perform hyperparameter tuning for improved performance.
- Designed a custom graph encoding method that augments node features with adjacency information.
- Built a preprocessing pipeline for variable-sized molecular graphs.
- Implemented and compared GCN, GAT, and Transformer-based graph models.
- Evaluated models using RMSE on the ESOL molecular property prediction task.
Parisa Arbab
GitHub: https://github.com/ParisaArbab