Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
1b5820a5
Commit
1b5820a5
authored
Aug 29, 2019
by
Mufei Li
Committed by
Zihao Ye
Aug 29, 2019
Browse files
Fix (#806)
parent
98b825e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
6 deletions
+37
-6
examples/pytorch/model_zoo/chem/README.md
examples/pytorch/model_zoo/chem/README.md
+34
-4
examples/pytorch/model_zoo/chem/generative_models/dgmg/utils.py
...es/pytorch/model_zoo/chem/generative_models/dgmg/utils.py
+3
-2
No files found.
examples/pytorch/model_zoo/chem/README.md
View file @
1b5820a5
...
...
@@ -23,8 +23,6 @@ The rest dependencies can be installed with `pip install -r requirements.txt`.
## Property Prediction
[
**Get started with our example code!**
](
https://github.com/dmlc/dgl/tree/master/examples/pytorch/model_zoo/chem/property_prediction
)
To evaluate molecules for drug candidates, we need to know their properties and activities. In practice, this is
mostly achieved via wet lab experiments. We can cast the problem as a regression or classification problem.
In practice, this can be quite difficult due to the scarcity of labeled data.
...
...
@@ -54,7 +52,22 @@ as front end and Set2Set for output prediction.
### Example Usage of Pre-trained Models

```
python
from
dgl.data
import
Tox21
from
dgl
import
model_zoo
dataset
=
Tox21
()
model
=
model_zoo
.
chem
.
load_pretrained
(
'GCN_Tox21'
)
# Pretrained model loaded
model
.
eval
()
smiles
,
g
,
label
,
mask
=
dataset
[
0
]
feats
=
g
.
ndata
.
pop
(
'h'
)
label_pred
=
model
(
feats
,
g
)
print
(
smiles
)
# CCOc1ccc2nc(S(N)(=O)=O)sc2c1
print
(
label_pred
[:,
mask
!=
0
])
# Mask non-existing labels
# tensor([[-0.7956, 0.4054, 0.4288, -0.5565, -0.0911,
# 0.9981, -0.1663, 0.2311, -0.2376, 0.9196]])
```
## Generative Models
...
...
@@ -76,7 +89,24 @@ progressively adding atoms and bonds.
### Example Usage of Pre-trained Models

```
python
# We recommend running the code below with Jupyter notebooks
from
IPython.display
import
SVG
from
rdkit
import
Chem
from
rdkit.Chem
import
Draw
from
dgl
import
model_zoo
model
=
model_zoo
.
chem
.
load_pretrained
(
'DGMG_ZINC_canonical'
)
model
.
eval
()
mols
=
[]
for
i
in
range
(
4
):
SMILES
=
model
(
rdkit_mol
=
True
)
mols
.
append
(
Chem
.
MolFromSmiles
(
SMILES
))
# Generating 4 molecules takes less than a second.
SVG
(
Draw
.
MolsToGridImage
(
mols
,
molsPerRow
=
4
,
subImgSize
=
(
180
,
150
),
useSVG
=
True
))
```

...
...
examples/pytorch/model_zoo/chem/generative_models/dgmg/utils.py
View file @
1b5820a5
...
...
@@ -578,6 +578,7 @@ def preprocess_dataset(atom_types, bond_types, smiles, max_num_atoms=23):
mol
=
smiles_to_standard_mol
(
raw_s
)
if
mol
is
None
:
continue
standard_s
=
Chem
.
MolToSmiles
(
mol
)
if
(
max_num_atoms
is
not
None
)
and
(
mol
.
GetNumAtoms
()
>
max_num_atoms
):
continue
...
...
@@ -586,10 +587,10 @@ def preprocess_dataset(atom_types, bond_types, smiles, max_num_atoms=23):
canonical_mol
=
Chem
.
MolFromSmiles
(
canonical_s
)
random_mol
=
Chem
.
MolFromSmiles
(
random_s
)
if
(
raw
_s
!=
canonical_s
)
or
(
canonical_s
!=
random_s
)
or
(
canonical_mol
is
None
)
or
(
random_mol
is
None
):
if
(
standard
_s
!=
canonical_s
)
or
(
canonical_s
!=
random_s
)
or
(
canonical_mol
is
None
)
or
(
random_mol
is
None
):
continue
valid_smiles
.
append
(
Chem
.
MolToSmiles
(
mol
)
)
valid_smiles
.
append
(
standard_s
)
valid_smiles
=
list
(
set
(
valid_smiles
))
return
valid_smiles
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment