Skip to main content

Graph Neural Networks for Molecular Machine Learning

Project description

MolGraph

Graph Neural Networks with TensorFlow and Keras. Focused on Molecular Machine Learning.

molgraph

Highlights

Build a Graph Neural Network with Keras' Sequential API:

from molgraph import GraphTensor
from molgraph import layers
from tensorflow import keras

model = keras.Sequential([
    layers.GINConv(units=32),
    layers.GINConv(units=32),
    layers.Readout(),
    keras.layers.Dense(units=1),
])
output = model(
    GraphTensor(node_feature=[[4.], [2.]], edge_src=[0], edge_dst=[1])
)

Paper

See arXiv

Documentation

See readthedocs

Implementations

  • Graph tensor (GraphTensor)
    • A composite tensor holding graph data.
    • Has a ragged state (multiple graphs) and a non-ragged state (single disjoint graph).
    • Can conveniently go between both states (merge(), separate()).
    • Can propagate node states (features) based on edges (propagate()).
    • Can add, update and remove graph data (update(), remove()).
    • Compatible with TensorFlow's APIs (including Keras). For instance, graph data (encoded as a GraphTensor) can now seamlessly be used with keras.Sequential, keras.Functional, tf.data.Dataset, and tf.saved_model APIs.
  • Layers
  • Models
    • Although model building is easy with MolGraph, there are some built-in GNN models:
      • GIN
      • MPNN
      • DMPNN
    • And models for improved interpretability of GNNs:
      • SaliencyMapping
      • IntegratedSaliencyMapping
      • SmoothGradSaliencyMapping
      • GradientActivationMapping (Recommended)

Requirements/dependencies

  • Python (version ~= 3.10.0)
    • TensorFlow (version ~= 2.15.0)
    • RDKit (version ~= 2022.3.5)
    • Pandas (version ~= 1.0.3)
    • IPython (version ~= 8.12.0)

MolGraph should work with the more recent TensorFlow and RDKit versions. If not, try installing earlier versions of TensorFlow and RDKit.

Installation

For GPU users:

pip install molgraph[gpu]

For CPU users:

pip install molgraph

Now run your first program with MolGraph:

from tensorflow import keras
from molgraph import chemistry
from molgraph import layers
from molgraph import models

# Obtain dataset, specifically ESOL
esol = chemistry.datasets.get('esol')

# Define molecular graph encoder
atom_encoder = chemistry.Featurizer([
    chemistry.features.Symbol(),
    chemistry.features.Hybridization(),
    # ...
])

bond_encoder = chemistry.Featurizer([
    chemistry.features.BondType(),
    # ...
])

encoder = chemistry.MolecularGraphEncoder(atom_encoder, bond_encoder)

# Obtain graphs and associated labels
x_train = encoder(esol['train']['x'])
y_train = esol['train']['y']

x_test = encoder(esol['test']['x'])
y_test = esol['test']['y']

# Build model via Keras API
gnn_model = keras.Sequential([
    layers.GATConv(units=32, name='gat_conv_1'),
    layers.GATConv(units=32, name='gat_conv_2'),
    layers.Readout(),
    keras.layers.Dense(units=1024, activation='relu'),
    keras.layers.Dense(units=y_train.shape[-1])
])

# Compile, fit and evaluate
gnn_model.compile(optimizer='adam', loss='mae')
gnn_model.fit(x_train, y_train, epochs=50)
scores = gnn_model.evaluate(x_test, y_test)

# Compute gradient activation maps
gam_model = models.GradientActivationMapping(
    model=gnn_model, layer_names=['gat_conv_1', 'gat_conv_2'])

maps = gam_model(x_train.separate())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molgraph-0.6.6.tar.gz (110.2 kB view details)

Uploaded Source

Built Distribution

molgraph-0.6.6-py3-none-any.whl (197.5 kB view details)

Uploaded Python 3

File details

Details for the file molgraph-0.6.6.tar.gz.

File metadata

  • Download URL: molgraph-0.6.6.tar.gz
  • Upload date:
  • Size: 110.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for molgraph-0.6.6.tar.gz
Algorithm Hash digest
SHA256 e989b0b5b52e1808cf48a9b89b24cb26617c6735256acef40514e6004b956e5c
MD5 b93abd49808096d0ad9bdefc50e1d1d2
BLAKE2b-256 f588b6c6d64fe710da113c1cf1de50ea3b4dd0039bc3eb2b119ac47e9359c8cf

See more details on using hashes here.

File details

Details for the file molgraph-0.6.6-py3-none-any.whl.

File metadata

  • Download URL: molgraph-0.6.6-py3-none-any.whl
  • Upload date:
  • Size: 197.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for molgraph-0.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f7469d6afdce3f0d28232c39603588762150e67c903f43b4b52a7ca2b4e93f35
MD5 1c6dec793760b9546cd8129394df2b6f
BLAKE2b-256 67adfa5948054e5a0037f2f7e75efcf25366ea09c8028c77e7f6ad8ccec74fb1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page