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]
Metadata
Release files for molcraft 0.10.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| molcraft-0.10.8.tar.gz | 59.9 kB | Without provenance | Details for molcraft-0.10.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| molcraft-0.10.8-py3-none-any.whl | Python 3 | none | any | Details for molcraft-0.10.8-py3-none-any.whl |
Total release size: 119.3 kB
Release files / molcraft-0.10.8.tar.gz
| Download URL | molcraft-0.10.8.tar.gz |
|---|---|
| Size | 59.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d150bd03d2d73d232fc38cf7e3a3cc65ecf29aedc5c079fc9ae48f0307ca021b
|
|
BLAKE2b-256 checksum How to use checksums |
5086004d1a025eda2e88486d1e34dc17ad9e94a115aafd2525e5851981f18030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / molcraft-0.10.8-py3-none-any.whl
| Download URL | molcraft-0.10.8-py3-none-any.whl |
|---|---|
| Size | 59.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
419e0f7fdf41a5bf70045b729c677556a712bbd23c2573d05a41415264c90ed6
|
|
BLAKE2b-256 checksum How to use checksums |
7ed2e67f409789badd6db337c988c6494d312541b5191493c5868a086189c60a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for molcraft 0.10.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.