Python rdkit.DataStructs.TanimotoSimilarity() Examples

The following are 8 code examples of rdkit.DataStructs.TanimotoSimilarity(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rdkit.DataStructs , or try the search function .
Example #1
Source File: properties.py    From hgraph2graph with MIT License 8 votes vote down vote up
def similarity(a, b):
    if a is None or b is None: 
        return 0.0
    amol = Chem.MolFromSmiles(a)
    bmol = Chem.MolFromSmiles(b)
    if amol is None or bmol is None:
        return 0.0

    fp1 = AllChem.GetMorganFingerprintAsBitVect(amol, 2, nBits=2048, useChirality=False)
    fp2 = AllChem.GetMorganFingerprintAsBitVect(bmol, 2, nBits=2048, useChirality=False)
    return DataStructs.TanimotoSimilarity(fp1, fp2) 
Example #2
Source File: molecule.py    From rl_graph_generation with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def reward_target_molecule_similarity(mol, target, radius=2, nBits=2048,
                                      useChirality=True):
    """
    Reward for a target molecule similarity, based on tanimoto similarity
    between the ECFP fingerprints of the x molecule and target molecule
    :param mol: rdkit mol object
    :param target: rdkit mol object
    :return: float, [0.0, 1.0]
    """
    x = rdMolDescriptors.GetMorganFingerprintAsBitVect(mol, radius=radius,
                                                        nBits=nBits,
                                                        useChirality=useChirality)
    target = rdMolDescriptors.GetMorganFingerprintAsBitVect(target,
                                                            radius=radius,
                                                        nBits=nBits,
                                                        useChirality=useChirality)
    return DataStructs.TanimotoSimilarity(x, target)


### TERMINAL VALUE REWARDS ### 
Example #3
Source File: predict_enriched.py    From PIDGINv3 with GNU General Public License v3.0 6 votes vote down vote up
def doSimilarityWeightedAdAnalysis(model_name, rdkit_mols):
	global ad_settings
	ad_idx = []
	known = []
	ad_data = getAdData(model_name)
	required_threshold = np.percentile(ad_data[:,5],ad_settings)
	for mol_idx, m in enumerate(rdkit_mols):
		ad_flag = False
		#only check for known compounds if set in options (True means dont check)
		if options.known: k_flag = False
		else: k_flag = True
		for training_instance in ad_data:
			sim = DataStructs.TanimotoSimilarity(m,training_instance[0])
			if sim == 1.0 and k_flag == False:
				known.append([mol_idx,training_instance[1]])
				k_flag = True
			weight = sim/(training_instance[2]*training_instance[3])
			if weight >= required_threshold and ad_flag != True:
				ad_idx.append(mol_idx)
				ad_flag = True
			#if compound is in AD and no need to check accross all comps for known then break
			if k_flag == True and ad_flag == True: break
	return ad_idx, np.array(known)

#return target prediction information for first and second files (p1,p2) 
Example #4
Source File: stereo.py    From hgraph2graph with MIT License 5 votes vote down vote up
def similarity(a, b, chiral=False):
    if a is None or b is None: 
        return 0.0
    amol = Chem.MolFromSmiles(a)
    bmol = Chem.MolFromSmiles(b)
    if amol is None or bmol is None:
        return 0.0

    fp1 = AllChem.GetMorganFingerprintAsBitVect(amol, 2, nBits=2048, useChirality=chiral)
    fp2 = AllChem.GetMorganFingerprintAsBitVect(bmol, 2, nBits=2048, useChirality=chiral)
    return DataStructs.TanimotoSimilarity(fp1, fp2) 
Example #5
Source File: scoring_functions.py    From REINVENT with MIT License 5 votes vote down vote up
def __call__(self, smile):
        mol = Chem.MolFromSmiles(smile)
        if mol:
            fp = AllChem.GetMorganFingerprint(mol, 2, useCounts=True, useFeatures=True)
            score = DataStructs.TanimotoSimilarity(self.query_fp, fp)
            score = min(score, self.k) / self.k
            return float(score)
        return 0.0 
Example #6
Source File: representation.py    From ScaffoldGraph with MIT License 5 votes vote down vote up
def __init__(self, fp_func=None, sim_func=None, fp_cache_maxsize=None, sim_cache_maxsize=None):
        self._fp_func = fp_func if fp_func else Chem.RDKFingerprint
        assert callable(self._fp_func), 'fp_func must be callable or None'
        self._sim_func = sim_func if sim_func else DataStructs.TanimotoSimilarity
        assert callable(self._sim_func), 'sim_func must be callable or None'
        self._fp_cache = Cache(fp_cache_maxsize)
        self._sim_cache = Cache(sim_cache_maxsize) 
Example #7
Source File: predict.py    From PIDGINv3 with GNU General Public License v3.0 5 votes vote down vote up
def doSimilarityWeightedAdAnalysis(model_name):
	global rdkit_mols, ad_settings
	ad_idx = []
	known = []
	ad_data = getAdData(model_name)
	required_threshold = np.percentile(ad_data[:,5],ad_settings)
	for mol_idx, m in enumerate(rdkit_mols):
		ad_flag = True
		#only check for known compounds if set in options (True means check)
		if options.known: k_flag = True
		else: k_flag = False
		for training_instance in ad_data:
			sim = DataStructs.TanimotoSimilarity(m,training_instance[0])
			#check if input=train & need to check input=train
			if sim == 1.0 and k_flag == True:
				known.append([mol_idx,training_instance[1]])
				k_flag = False
			weight = sim/(training_instance[2]*training_instance[3])
			#if comp in AD & no comp already in AD
			if weight >= required_threshold and ad_flag == True:
				ad_idx.append(mol_idx)
				ad_flag = False
			#if compound is in AD and no need to check accross all comps for known then break
			if k_flag == False and ad_flag == False: break
	return ad_idx, np.array(known)

#get smiles from training set of model 
Example #8
Source File: properties.py    From iclr19-graph2graph with MIT License 5 votes vote down vote up
def similarity(a, b):
    if a is None or b is None: 
        return 0.0
    amol = Chem.MolFromSmiles(a)
    bmol = Chem.MolFromSmiles(b)
    if amol is None or bmol is None:
        return 0.0

    fp1 = AllChem.GetMorganFingerprintAsBitVect(amol, 2, nBits=2048, useChirality=False)
    fp2 = AllChem.GetMorganFingerprintAsBitVect(bmol, 2, nBits=2048, useChirality=False)
    return DataStructs.TanimotoSimilarity(fp1, fp2)