Esempio n. 1
0
def fp_tt_std_mp(mol, mol_can, i, nBits, chiral):
    fp_mol = Torsions.GetHashedTopologicalTorsionFingerprint(mol, nBits=nBits, includeChirality=chiral)
    if id(mol) == id(mol_can):
        fp_can = fp_mol
    else:
        fp_can = Torsions.GetHashedTopologicalTorsionFingerprint(mol_can, nBits=nBits, includeChirality=chiral)
    return (i, fp_mol, fp_can)
Esempio n. 2
0
 def score_model(self, model_configuration: dict, fragments_file: str,
                 descriptors_file: str, output_file: str):
     inputoutput_utils.create_parent_directory(output_file)
     model_data = model_configuration["data"]
     active_molecules_tt = []
     nbits = model_configuration["configuration"]["nbits"]
     for active_molecule in model_data["active"]:
         molecule_smiles = active_molecule.strip("\"")
         molecule = Chem.MolFromSmiles(molecule_smiles)
         tt_fingerprint = Torsions.GetHashedTopologicalTorsionFingerprint(
             molecule, nBits=nbits)
         active_molecules_tt.append(tt_fingerprint)
     first_line = True
     with open(output_file, "w", encoding="utf-8") as output_stream:
         with open(fragments_file, "r", encoding="utf-8") as input_stream:
             for new_line in input_stream:
                 line = json.loads(new_line)
                 test_molecule_input = line["smiles"]
                 test_molecule_smiles = test_molecule_input.strip("\"")
                 test_molecule = Chem.MolFromSmiles(test_molecule_smiles)
                 test_mol_fingerprint = Torsions.GetHashedTopologicalTorsionFingerprint(
                     test_molecule, nBits=nbits)
                 max_sim = max([
                     DataStructs.TanimotoSimilarity(test_mol_fingerprint,
                                                    fingerprint)
                     for fingerprint in active_molecules_tt
                 ])
                 score = {"name": line["name"], "score": max_sim}
                 if first_line:
                     first_line = False
                 else:
                     output_stream.write("\n")
                 json.dump(score, output_stream)
Esempio n. 3
0
def fp_tt_std(mols, nBits, chiral):
    for i in mols:
        fp_mol = Torsions.GetHashedTopologicalTorsionFingerprint(mols[i]["mol"], nBits=nBits, includeChirality=chiral)
        mols[i]["fp"] = fp_mol
        if id(mols[i]["mol"]) == id(mols[i]["mol_can"]):
            mols[i]["fp_can"] = fp_mol
        else:
            mols[i]["fp_can"] = Torsions.GetHashedTopologicalTorsionFingerprint(mols[i]["mol_can"], nBits=nBits,
                                                                                includeChirality=chiral)
Esempio n. 4
0
def _torsionsFingerprintsClustering(rdkit_mols):
    """
        Returns the dice distance matrix based on torsionsfingerprints method

        Parameters
        ----------
        rdkit_mols: list
            The list of rdkit.Chem.rdchem.Mol objects

        Returns
        -------
        dicematrix: np.array
            The numpy array containing the dice matrix
        """
    from rdkit.Chem.AtomPairs import Torsions  # Topological Torsions

    fps = []
    for m in tqdm(rdkit_mols):
        fps.append(Torsions.GetHashedTopologicalTorsionFingerprint(m))

    aprun = ParallelExecutor(n_jobs=-1)  # _config['ncpus'])
    dice_matrix = aprun(total=len(fps), desc='TorsionsFingerprints Distance') \
        (delayed(DiceDistances)(fp1, fps) for fp1 in fps)

    return np.array(dice_matrix)
Esempio n. 5
0
def GetMolFingerprint(mol,maxPathLength):
    FQuery = Chem.MolFromSmarts('F')
    CF3Query= Chem.MolFromSmarts('[$(C(F)(F)F)]')
    CF3Rxn = AllChem.ReactionFromSmarts('[*:1]-C(F)(F)F>>[*:1]-F')
    hasCF3 = mol.HasSubstructMatch(CF3Query)
    if hasCF3:
        p = CF3Rxn.RunReactants((mol,))[0][0]
        Chem.SanitizeMol(p)
        for nm in mol.GetPropNames():
            p.SetProp(nm,mol.GetProp(nm))
        mol = p
    match = mol.GetSubstructMatch(FQuery)
    fp = Torsions.GetHashedTopologicalTorsionFingerprint(mol,nBits=9192,targetSize=maxPathLength,fromAtoms=match)
    for i in range(2,maxPathLength):
        nfp = Torsions.GetHashedTopologicalTorsionFingerprint(mol,nBits=9192,targetSize=i,fromAtoms=match)
        for bit,v in nfp.GetNonzeroElements().iteritems():
            fp[bit] = fp[bit]+v
    return fp
Esempio n. 6
0
def GetTorsionFPs(mol, nBits = 2048, binary = True):
    '''
    atompairs fingerprints
    '''
    fp = Torsions.GetHashedTopologicalTorsionFingerprint(mol, nBits = nBits)
    if binary:
        arr = np.zeros((0,),  dtype=np.bool)
    else:
        arr = np.zeros((0,),  dtype=np.int8)
    DataStructs.ConvertToNumpyArray(fp, arr)
    return arr
Esempio n. 7
0
def fp_torsion(mols, key, nBits, chiral):
    for i in mols:
        fp = Torsions.GetHashedTopologicalTorsionFingerprint(
            mols[i][key], nBits=nBits, includeChirality=chiral)
        mols[i]["fp"] = fp
Esempio n. 8
0
def fp_torsion_taut_mp(taut, i, k, nBits, chiral):
    fp = Torsions.GetHashedTopologicalTorsionFingerprint(
        taut, nBits=nBits, includeChirality=chiral)
    return (i, fp, k)
Esempio n. 9
0
def fp_torsion_mp(mol, i, nBits, chiral):
    fp = Torsions.GetHashedTopologicalTorsionFingerprint(
        mol, nBits=nBits, includeChirality=chiral)
    return (i, fp)
Esempio n. 10
0
def fp_torsion_taut(query, nBits, chiral):
    for i in query:
        for j in range(len(query[i]["tauts"])):
            fp = Torsions.GetHashedTopologicalTorsionFingerprint(
                query[i]["tauts"][j], nBits=nBits, includeChirality=chiral)
            query[i][f"fp{j}"] = fp