1- from functools import reduce , lru_cache
1+ from functools import reduce
22import inspect
3- from typing import *
3+ from typing import Any , Callable , Dict , List , Optional , Set , Tuple , Union , cast
44import io
55import math
66import requests # type: ignore
77import numpy as np
88import matplotlib .pyplot as plt # type: ignore
9- from matplotlib .patches import Rectangle , FancyBboxPatch # type: ignore
9+ from matplotlib .patches import FancyBboxPatch # type: ignore
1010from matplotlib .offsetbox import AnnotationBbox # type: ignore
1111import matplotlib as mpl # type: ignore
1212import re
1313import selfies as sf # type: ignore
1414import tqdm # type: ignore
15- import textwrap # type: ignore
15+ import textwrap
1616import skunk # type: ignore
1717import synspace # type: ignore
1818
2525from rdkit .Chem import MolToSmiles as mol2smi # type: ignore
2626from rdkit .Chem import rdchem , MACCSkeys , AllChem # type: ignore
2727from rdkit .Chem .Draw import MolToImage as mol2img , DrawMorganBit # type: ignore
28- from rdkit .Chem import rdchem # type: ignore
2928from rdkit .DataStructs .cDataStructs import BulkTanimotoSimilarity , TanimotoSimilarity # type: ignore
3029
3130import openai
@@ -52,7 +51,7 @@ def _ecfp_names(examples, joint_bits):
5251 multiple_bases = _check_multiple_bases (examples )
5352 # need to get base molecule(s) for naming
5453 bitInfo = {} # Type Dict[Any, Any]
55- base_mol = [smi2mol (e .smiles ) for e in examples if e .is_origin == True ]
54+ base_mol = [smi2mol (e .smiles ) for e in examples if e .is_origin ]
5655 if multiple_bases :
5756 multiBitInfo = {} # type: Dict[int, Tuple[Any, int, int]]
5857 for b in base_mol :
@@ -256,7 +255,7 @@ def name_morgan_bit(m: Any, bitInfo: Dict[Any, Any], key: int) -> Optional[str]:
256255
257256def get_functional_groups (
258257 mol : Any , return_all : bool = False , cutoff : int = 300
259- ) -> set [str ]:
258+ ) -> Set [str ]:
260259 """Get a set of functional groups present in a molecule, sorted by priority, avoiding overlaps.
261260
262261 :param mol: RDKit molecule
@@ -467,16 +466,16 @@ def run_stoned(
467466 """
468467 if alphabet is None :
469468 alphabet = get_basic_alphabet ()
470- if type (alphabet ) == set :
469+ if isinstance (alphabet , set ) :
471470 alphabet = list (alphabet )
472471 alphabet_symbols = _alphabet_to_elements (alphabet )
473472 # make sure starting smiles is consistent with alphabet
474473 _ = _check_alphabet_consistency (start_smiles , alphabet_symbols , check = True )
475474 num_mutation_ls = list (range (min_mutations , max_mutations + 1 ))
476475
477476 start_mol = smi2mol (start_smiles )
478- if start_mol == None :
479- raise Exception ("Invalid starting structure encountered" )
477+ if start_mol is None :
478+ raise ValueError ("Invalid starting structure encountered" )
480479
481480 # want it so after sampling have num_samples
482481 randomized_smile_orderings = [
@@ -582,7 +581,7 @@ def run_chemed(
582581 return [], []
583582 try :
584583 data = reply .json ()
585- except :
584+ except Exception :
586585 return [], []
587586 smiles = [d ["CanonicalSMILES" ] for d in data ["PropertyTable" ]["Properties" ]]
588587 smiles = list (set (smiles ))
@@ -990,7 +989,7 @@ def rcf_explain(
990989 :param nmols: Desired number of molecules
991990 :param filter_nondrug: Whether or not to filter out non-drug molecules. Default is True if input passes filter
992991 """
993- if type (delta ) is float :
992+ if isinstance (delta , ( int , float )) :
994993 delta = (- delta , delta )
995994
996995 def is_high (e ):
@@ -1144,7 +1143,7 @@ def plot_cf(
11441143 fig , axs = plt .subplots (R , C , ** figure_kwargs )
11451144 else :
11461145 axs = fig .subplots (R , C )
1147- if type (axs ) != np .ndarray : # Happens if nrows=ncols=1
1146+ if not isinstance (axs , np .ndarray ) : # Happens if nrows=ncols=1
11481147 axs = np .array ([[axs ]])
11491148 axs = axs .flatten ()
11501149 for i , (img , e ) in enumerate (zip (imgs , exps )):
@@ -1256,7 +1255,7 @@ def plot_descriptors(
12561255 if descriptor_type == "ecfp" :
12571256 # get reference for ECFP
12581257 if multiple_bases :
1259- bases = [smi2mol (e .smiles ) for e in examples if e .is_origin == True ]
1258+ bases = [smi2mol (e .smiles ) for e in examples if e .is_origin ]
12601259 bi = {} # type: Dict[Any, Any]
12611260 for b in bases :
12621261 bit_info = {} # type: Dict[Any, Any]
@@ -1403,7 +1402,7 @@ def check_multiple_aromatic_rings(mol):
14031402 continue
14041403 if flag :
14051404 count += 1
1406- return True if count > 1 else False
1405+ return count > 1
14071406
14081407
14091408def merge_text_explains (
0 commit comments