Skip to main content

Implementations of graph neural networks for molecular machine learning

Project description

MolGraph: Graph Neural Networks for Molecular Machine Learning

This is an early release; things are still being updated and added. Hence, API compatibility may break in the future.

Any feedback is welcomed!

Manuscript

See pre-print

Documentation

See readthedocs

Installation

Install via pip:

pip install molgraph

Install via docker:

git clone https://github.com/akensert/molgraph.git
cd molgraph/docker
docker build -t molgraph-tf[-gpu][-jupyter]/molgraph:0.0 molgraph-tf[-gpu][-jupyter]/
docker run -it [-p 8888:8888] molgraph-tf[-gpu][-jupyter]/molgraph:0.0

Requirements/dependencies

  • Python (version ~= 3.8.10)
  • TensorFlow (version ~= 2.7.0)
  • RDKit (version ~= 2022.3.3)
  • NumPy (version ~= 1.21.2)
  • Pandas (version ~= 1.0.3)

Tested with

  • Ubuntu 20.04 - Python 3.8.10
  • MacOS Monterey (12.3.1) - Python 3.10.3

Minimalistic implementation

A complete GNN implementation for small molecular graphs in about 30 lines of code:

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

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

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

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

encoder = chemistry.MolecularGraphEncoder(atom_encoder, bond_encoder)

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

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

# Build model via Keras API
gnn_model = keras.Sequential([
    keras.layers.Input(type_spec=x_train.spec),
    layers.GATConv(name='gat_conv_1'),
    layers.GATConv(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)
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.predict(x_train)

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.0.3.tar.gz (83.6 kB view details)

Uploaded Source

Built Distribution

molgraph-0.0.3-py3-none-any.whl (131.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: molgraph-0.0.3.tar.gz
  • Upload date:
  • Size: 83.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for molgraph-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8eb932b1d78ff0b2a0fd3dd745827eefed8c478e4e3d9deacfa161a26958e386
MD5 3027d006888129b6d64007b7b8de259a
BLAKE2b-256 4082e9ddba76abe2c643f5913d9f0a767e2b8f68b98b25e65fac9ae1cd1754a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: molgraph-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 131.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for molgraph-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1c75cdedf127fe0562beefcf29af71934a8912982237ed0f3a67df8ba45d1516
MD5 d85c4b90dcedeb73b5a28d67e42ac0d1
BLAKE2b-256 933a17814a7f43b6cc7ea2b002b73edfd92d564f76bc80c965310118969a515b

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