def get_sa( self, s): m = Chem.MolFromSmiles( s) sa = sascorer.calculateScore( m) if self.graph: jchem.show_mol( s) if self.disp: print('NP Score is', sa) return sa
def sa_score(mol): """ Synthetic acceptability score as proposed by Ertel et al.. """ try: score = sascorer.calculateScore(mol) except: score = 0 return score
def calculate(smis,n): def sort_di(dict_, n): sorted_li=sorted(dict_.items(), key = lambda kv:(kv[1], kv[0])) sorted_li= sorted_li[:n] return sorted_li sa_value={} for smi in smis: try: sa_value[smi] = sa.calculateScore(rkc.MolFromSmiles(smi)) except ZeroDivisionError: pass return sort_di(sa_value,n)
def reward_penalized_log_p(mol): """ Reward that consists of log p penalized by SA and # long cycles, as described in (Kusner et al. 2017). Scores are normalized based on the statistics of 250k_rndm_zinc_drugs_clean.smi dataset Code taken from implementation of: You, Jiaxuan, et al. "Graph Convolutional Policy Network for Goal-Directed Molecular Graph Generation." arXiv preprint arXiv:1806.02473 (2018). https://github.com/bowenliu16/rl_graph_generation """ # normalization constants, statistics from 250k_rndm_zinc_drugs_clean.smi logP_mean = 2.4570953396190123 logP_std = 1.434324401111988 SA_mean = -3.0525811293166134 SA_std = 0.8335207024513095 cycle_mean = -0.0485696876403053 cycle_std = 0.2860212110245455 try: log_p = MolLogP(mol) except ValueError: return 0 try: SA = -sascorer.calculateScore(mol) except ZeroDivisionError: return 0 # cycle score cycle_list = nx.cycle_basis(nx.Graph( Chem.rdmolops.GetAdjacencyMatrix(mol))) if len(cycle_list) == 0: cycle_length = 0 else: cycle_length = max([len(j) for j in cycle_list]) if cycle_length <= 6: cycle_length = 0 else: cycle_length = cycle_length - 6 cycle_score = -cycle_length normalized_log_p = (log_p - logP_mean) / logP_std normalized_SA = (SA - SA_mean) / SA_std normalized_cycle = (cycle_score - cycle_mean) / cycle_std return normalized_log_p + normalized_SA + normalized_cycle
def CalculateSAscore(mol): """ A function to estimate ease of synthesis (synthetic accessibility) of drug-like molecules --->SAscore Reference: (1) `Ertl Peter (2009)`_. :param mol: molecular :type mol: rdkit.Chem.rdchem.Mol :return: ease of synthesis :rtype: float .. _Ertl Peter (2009): https://jcheminf.biomedcentral.com/articles/10.1186/1758-2946-1-8 """ return round(sascorer.calculateScore(mol), 2)
def CalculateSAscore(mol): """ --- Ref.: Ertl, Peter, and Ansgar Schuffenhauer. J Cheminform, 1(1), 8. Based: https://github.com/rdkit/rdkit/tree/master/Contrib/SA_Score --- Brief: A function to estimate ease of synthesis (synthetic accessibility) of drug-like molecules --- Parameters: >>> mol: dkit.Chem.rdchem.Mol; Return: float, meant SA score """ return round(sascorer.calculateScore(mol), 2)
def penalized_logp(molecule): """Calculates the penalized logP of a molecule. Refactored from https://github.com/wengong-jin/icml18-jtnn/blob/master/bo/run_bo.py See Junction Tree Variational Autoencoder for Molecular Graph Generation https://arxiv.org/pdf/1802.04364.pdf Section 3.2 Penalized logP is defined as: y(m) = logP(m) - SA(m) - cycle(m) y(m) is the penalized logP, logP(m) is the logP of a molecule, SA(m) is the synthetic accessibility score, cycle(m) is the largest ring size minus by six in the molecule. Args: molecule: Chem.Mol. A molecule. Returns: Float. The penalized logP value. """ log_p = Descriptors.MolLogP(molecule) sas_score = sascorer.calculateScore(molecule) largest_ring_size = get_largest_ring_size(molecule) cycle_score = max(largest_ring_size - 6, 0) return log_p - sas_score - cycle_score
def sa_score(smi): try: mol = Chem.MolFromSmiles(smi) return sascorer.calculateScore(mol) except: return np.nan
def SA(mol): """ Computes RDKit's Synthetic Accessibility score """ return sascorer.calculateScore(mol)
def get_sa(smi): mol = Chem.MolFromSmiles(smi) return sascorer.calculateScore(mol)
def sa_score(mol): score = sascorer.calculateScore(mol) return score