Skip to content

Commit

Permalink
FCD from fcd_torch (molecularsets#29)
Browse files Browse the repository at this point in the history
* FCD from fcd_torch

* evaluation script gpu -> device

* pyTorch 1.0.1

* shm-size

* save config and vocab first

* jtnn sampling fix

* device in run.py

* minor fixes

* minor fixes

* share pool

* share pool

* close pool
  • Loading branch information
danpol authored and zhebrak committed Feb 11, 2019
1 parent b892521 commit 2b613a0
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 415 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ RUN set -ex \

ENV PATH /opt/miniconda/bin:$PATH
RUN conda install -yq numpy=1.15.0 scipy=1.1.0 matplotlib=3.0.1 pandas=0.23.3 scikit-learn=0.19.1 tqdm \
&& pip install tensorflow-gpu==1.12 keras==2.2.4 \
&& conda install -yq -c rdkit rdkit=2018.09.1.0 \
&& conda install -yq -c pytorch pytorch=0.4.1 torchvision=0.2.1 \
&& conda install -yq -c pytorch pytorch=1.0.1 torchvision=0.2.1 \
&& conda clean -yq -a

WORKDIR /moses
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ nvidia-docker image build --tag molecularsets/moses moses/

3. Create a container:
```
nvidia-docker run -it --name moses --network="host" --shm-size 1G molecularsets/moses
nvidia-docker run -it --name moses --network="host" --shm-size 10G molecularsets/moses
```

4. The dataset and source code are available inside the docker container at /moses:
Expand Down Expand Up @@ -250,9 +250,9 @@ python scripts/run.py
```
This will **split** the dataset, **train** the models, **generate** new molecules, and **calculate** the metrics. Evaluation results will be saved in `metrics.csv`.

You can specify the GPU index (-1 for CPU) and/or model by running:
You can specify the GPU device index as `cuda:n` (or `cpu` for CPU) and/or model by running:
```
python scripts/run.py --gpu 1 --model aae
python scripts/run.py --device cuda:1 --model aae
```

For more details run `python scripts/run.py --help`.
2 changes: 1 addition & 1 deletion moses/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.1.1'
5 changes: 4 additions & 1 deletion moses/junction_tree/jtnn/jtnn_dec.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ def decode(self, mol_vec, prob_decode):

if prob_decode:
b = pred_score.data.squeeze().cpu() # TODO
sort_wid = torch.multinomial(b, 5)
to_sample = 5
nonzero = (b != 0).long().sum()
to_sample = min(to_sample, nonzero)
sort_wid = torch.multinomial(b, to_sample)
else:
_, sort_wid = torch.sort(pred_score, dim=1, descending=True)
sort_wid = sort_wid.data.squeeze()
Expand Down
2 changes: 2 additions & 0 deletions moses/junction_tree/jtnn/jtnn_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def dfs_assemble(self, tree_mess, mol_vec, all_nodes, cur_mol, global_amap, fa_a

if prob_decode:
probs = nn.Softmax(dim=-1)(scores.view(1, -1)).squeeze() + 1e-5 # prevent prob = 0
if probs.ndimension() == 0:
probs = probs[None,]
cand_idx = torch.multinomial(probs, probs.numel())
else:
_, cand_idx = torch.sort(scores, descending=True)
Expand Down
Binary file removed moses/metrics/ChemNet_v0.13_pretrained.h5
Binary file not shown.
10 changes: 7 additions & 3 deletions moses/metrics/NP_Score/npscorer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# calculation of natural product-likeness as described in:
#
# Natural Product-likeness Score and Its Application for Prioritization of Compound Libraries
# Natural Product-likeness Score and Its Application for Prioritization of
# Compound Libraries
# Peter Ertl, Silvio Roggo, and Ansgar Schuffenhauer
# Journal of Chemical Information and Modeling, 48, 68-74 (2008)
# http://pubs.acs.org/doi/abs/10.1021/ci700286x
Expand Down Expand Up @@ -98,7 +99,9 @@ def processMols(fscore, suppl):
if __name__ == '__main__':
fscore = readNPModel() # fills fscore

suppl = Chem.SmilesMolSupplier(sys.argv[1], smilesColumn=0, nameColumn=1, titleLine=False)
suppl = Chem.SmilesMolSupplier(
sys.argv[1], smilesColumn=0, nameColumn=1, titleLine=False
)
processMols(fscore, suppl)

#
Expand All @@ -117,7 +120,8 @@ def processMols(fscore, suppl):
# with the distribution.
# * Neither the name of Novartis Institutes for BioMedical Research Inc.
# nor the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written permission.
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Expand Down
11 changes: 7 additions & 4 deletions moses/metrics/SA_Score/sascorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def calculateScore(m):
readFragmentScores()

# fragment score
fp = rdMolDescriptors.GetMorganFingerprint(m,
2) # <- 2 is the *radius* of the circular fingerprint
fp = rdMolDescriptors.GetMorganFingerprint(
m, 2 # <- 2 is the *radius* of the circular fingerprint
)
fps = fp.GetNonzeroElements()
score1 = 0.
nf = 0
Expand Down Expand Up @@ -87,7 +88,8 @@ def calculateScore(m):
if nMacrocycles > 0:
macrocyclePenalty = math.log10(2)

score2 = 0. - sizePenalty - stereoPenalty - spiroPenalty - bridgePenalty - macrocyclePenalty
score2 = (0. - sizePenalty - stereoPenalty -
spiroPenalty - bridgePenalty - macrocyclePenalty)

# correction for the fingerprint density
# not in the original publication, added in version 1.1
Expand Down Expand Up @@ -158,7 +160,8 @@ def processMols(mols):
# with the distribution.
# * Neither the name of Novartis Institutes for BioMedical Research Inc.
# nor the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written permission.
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Expand Down
Loading

0 comments on commit 2b613a0

Please sign in to comment.