jinysun commited on
Commit
2235bde
·
verified ·
1 Parent(s): 9a91b57

Update tool/comget/utils.py

Browse files
Files changed (1) hide show
  1. tool/comget/utils.py +18 -1
tool/comget/utils.py CHANGED
@@ -3,12 +3,29 @@ import numpy as np
3
  import torch
4
  import torch.nn as nn
5
  from torch.nn import functional as F
6
- from .moses.utils import get_mol
7
  from rdkit import Chem
8
 
9
  import numpy as np
10
  import threading
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def set_seed(seed):
13
  random.seed(seed)
14
  np.random.seed(seed)
 
3
  import torch
4
  import torch.nn as nn
5
  from torch.nn import functional as F
 
6
  from rdkit import Chem
7
 
8
  import numpy as np
9
  import threading
10
 
11
+
12
+ def get_mol(smiles_or_mol):
13
+ '''
14
+ Loads SMILES/molecule into RDKit's object
15
+ '''
16
+ if isinstance(smiles_or_mol, str):
17
+ if len(smiles_or_mol) == 0:
18
+ return None
19
+ mol = Chem.MolFromSmiles(smiles_or_mol)
20
+ if mol is None:
21
+ return None
22
+ try:
23
+ Chem.SanitizeMol(mol)
24
+ except ValueError:
25
+ return None
26
+ return mol
27
+ return smiles_or_mol
28
+
29
  def set_seed(seed):
30
  random.seed(seed)
31
  np.random.seed(seed)