Graph Neural Networks for Molecular Machine Learning
Project description
Deep Learning on Molecules: Graph Neural Networks for Molecular Machine Learning.
Examples
Context-Aware Graph Neural Network
Implement a context-aware graph neural network by embedding context features in the super node.
The super node is a virtual node bidirectionally linked to all atomic nodes,
allowing both efficient information propagation and inclusion of context features.
Context features may be continuous or discrete (categorical); for discrete context features, specify
the number of categories expected via num_categories of the AddContext layer.
from molcraft import features
from molcraft import featurizers
from molcraft import layers
from molcraft import models
import keras
import pandas as pd
featurizer = featurizers.MolGraphFeaturizer(
atom_features=[
features.AtomType(),
features.NumHydrogens(),
features.Degree(),
],
bond_features=[
features.BondType(),
features.IsRotatable(),
],
super_node=True,
self_loops=True,
)
df = pd.DataFrame({
'smiles': [
'N[C@@H](C)C(=O)O', 'N[C@@H](CS)C(=O)O'
],
'label': [3.5, -1.5],
'ph': [7.2, 4.5],
'temperature': [35., 45.],
})
graph = featurizer(df)
model = models.GraphModel.from_layers(
[
layers.Input(graph.spec),
layers.NodeEmbedding(dim=128),
layers.EdgeEmbedding(dim=128),
layers.AddContext(field='ph'),
layers.AddContext(field='temperature'),
layers.GraphConv(units=128),
layers.GraphConv(units=128),
layers.GraphConv(units=128),
layers.GraphConv(units=128),
layers.Readout(mode='mean'),
keras.layers.Dense(units=1024, activation='elu'),
keras.layers.Dense(units=1024, activation='elu'),
keras.layers.Dense(1)
]
)
model.compile(
keras.optimizers.Adam(1e-4), keras.losses.MeanSquaredError()
)
model.fit(graph, epochs=30)
pred = model.predict(graph)
# Uncomment below to save and load model (including featurizer)
# featurizers.save_featurizer(featurizer, '/tmp/featurizer.json')
# models.save_model(model, '/tmp/model.keras')
# loaded_featurizer = featurizers.load_featurizer('/tmp/featurizer.json')
# loaded_model = models.load_model('/tmp/model.keras')
Hybrid Model for Peptides
Implement a GNN-RNN hybrid model for peptides.
from molcraft import features
from molcraft import featurizers
from molcraft import layers
from molcraft import models
import keras
import pandas as pd
featurizer = featurizers.PeptideGraphFeaturizer(
atom_features=[
features.AtomType(),
features.NumHydrogens(),
features.Degree(),
],
bond_features=[
features.BondType(),
features.IsRotatable(),
],
)
# Allow modified amino acids:
# featurizer.monomers.update({
# "C[Carbamidomethyl]": "N[C@@H](CSCC(=O)N)C(=O)O"
# })
df = pd.DataFrame({
'sequence': [
'CYIQNCPLG', 'KTTKS'
],
'label': [1.0, 0.0],
})
graph = featurizer(df)
model = models.GraphModel.from_layers(
[
layers.Input(graph.spec),
layers.NodeEmbedding(dim=128),
layers.EdgeEmbedding(dim=128),
layers.GraphConv(units=128),
layers.GraphConv(units=128),
layers.GraphConv(units=128),
layers.GraphConv(units=128),
layers.PeptideReadout(),
keras.layers.Masking(),
keras.layers.Bidirectional(
keras.layers.LSTM(units=128, return_sequences=True)
),
keras.layers.GlobalAveragePooling1D(),
keras.layers.Dense(units=1024, activation='elu'),
keras.layers.Dense(units=1024, activation='elu'),
keras.layers.Dense(1, activation='sigmoid')
]
)
model.compile(
keras.optimizers.Adam(1e-4), keras.losses.BinaryCrossentropy()
)
model.fit(graph, epochs=30)
pred = model.predict(graph)
# Uncomment below to save and load model (including featurizer)
# featurizers.save_featurizer(featurizer, '/tmp/featurizer.json')
# models.save_model(model, '/tmp/model.keras')
# loaded_featurizer = featurizers.load_featurizer('/tmp/featurizer.json')
# loaded_model = models.load_model('/tmp/model.keras')
Installation
For CPU users:
pip install molcraft
For GPU users:
pip install molcraft[gpu]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file molcraft-0.4.0.tar.gz.
File metadata
- Download URL: molcraft-0.4.0.tar.gz
- Upload date:
- Size: 54.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f1b07ef2abc53f2f19a64616a355ea831d10d5d7e815a5262f63d26577560e3
|
|
| MD5 |
4c1032571cf21b0185f668549e8f4a6b
|
|
| BLAKE2b-256 |
d83a1277f65dc32798a87056c9b036929050956107b878c554f83bb2e5212059
|
File details
Details for the file molcraft-0.4.0-py3-none-any.whl.
File metadata
- Download URL: molcraft-0.4.0-py3-none-any.whl
- Upload date:
- Size: 54.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f555b00b634a92b3b2b9ff4dde098c972e3b1d77f28e8e998147ca82541d1a13
|
|
| MD5 |
b369326f634d314c976def0c595c7358
|
|
| BLAKE2b-256 |
7eccf754d3c50d9efe48a1310c3abaf6b220567f7f99476c1396690ad1444977
|