Skip to content

daydayupzzl/fcd_torch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fréchet ChemNet Distance on PyTorch

Build Status PyPI version

PyTorch implementation of Fréchet ChemNet Distance ported from the original repository https://github.com/bioinf-jku/FCD. The ported model produces the same outputs as the original Keras implementation and can be used for reproducible research. The PyTorch model of ChemNet weights tenfold less, resulting in faster loading.

Other features:

  • You can precalculate mean and sigma for further usage, useful if you use the statistics from the same dataset multiple times
  • Supports calculation on GPU and selection of GPU device number
  • Multithreaded SMILES parsing

Installation

First, install RDKit: conda install -yq -c rdkit rdkit and then install fcd_torch from pip (pip install fcd_torch), or directly from the source:

git clone https://github.com/insilicomedicine/fcd_torch.git
cd fcd_torch
python setup.py install

Usage

Import the module from fcd_torch import FCD. You can run calculation directly or precalculate statistics to reuse them on the test set (see example below). If you run FCD on GPU, the GPU memory will be allocated only during calculation of FCD.

# Example 1:
    fcd = FCD(device='cuda:0', n_jobs=8)
    smiles_list1 = ['COc1cccc(NC(=O)Cc2coc3ccc(OC)cc23)c1', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
    smiles_list2 = ['Oc1ccccc1-c1cccc2cnccc12', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
    fcd(smiles_list1, smiles_list2)
# Example 2:
    fcd = FCD(device='cuda:0', n_jobs=8)
    smiles_list1 = ['COc1cccc(NC(=O)Cc2coc3ccc(OC)cc23)c1', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
    smiles_list2 = ['Oc1ccccc1-c1cccc2cnccc12', 'Cc1noc(C)c1CN(C)C(=O)Nc1cc(F)cc(F)c1']
    pgen = fcd.precalc(smiles_list2)
    fcd(smiles_list1, pgen=pgen)

For the constructor, you can pass the device as device='cpu' for CPU and device='cuda:n' for GPU, where n is the GPU device number. n_jobs parameter specifies the number of threads for parsing SMILES. You can also vary the batch_size parameter. Call parameters for FCD are fcd(ref=None, gen=None, pref=None, pgen=None), where you should specify either ref (SMILES list), or pref (precalculated statistics), and the same for gen and pgen.

About

Fréchet ChemNet Distance on PyTorch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%