當前位置: 首頁>>代碼示例>>Python>>正文


Python AllChem.GetMorganFingerprint方法代碼示例

本文整理匯總了Python中rdkit.Chem.AllChem.GetMorganFingerprint方法的典型用法代碼示例。如果您正苦於以下問題:Python AllChem.GetMorganFingerprint方法的具體用法?Python AllChem.GetMorganFingerprint怎麽用?Python AllChem.GetMorganFingerprint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rdkit.Chem.AllChem的用法示例。


在下文中一共展示了AllChem.GetMorganFingerprint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: transform_mol

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def transform_mol(self, mol, misses=False):
        """ transforms the mol into a dense array using the fitted keys as index
        
            :parameter mol: the RDKit molecule to be transformed
            :parameter misses: wheter to return the number of key misses for the molecule
         """
        assert type(self.keys) is np.ndarray, "keys are not defined or is not an np.array, has the .fit(mols) function been used?"
        #Get fingerprint as a dictionary
        fp = AllChem.GetMorganFingerprint(mol,self.radius)
        fp_d = fp.GetNonzeroElements()
        
        #Prepare the array, and set the values
        #TODO is there a way to vectorize and speed up this?
        arr = np.zeros((self.dims,))
        _misses = 0
        for key, value in fp_d.items():
            if key in self.keys:
                arr[self.keys == key] = value
            else:
                _misses = _misses + 1
        
        if misses:
            return arr, _misses
        else:
            return arr 
開發者ID:pcko1,項目名稱:Deep-Drug-Coder,代碼行數:27,代碼來源:vectorizers.py

示例2: _generateFPs

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def _generateFPs(mol,fragmentMethod='Morgan'):
    aBits={}
    fp=None
    # circular Morgan fingerprint fragmentation, we use a simple invariant than ususal here
    if fragmentMethod=='Morgan':
        tmp={}
        fp = AllChem.GetMorganFingerprint(mol,radius=2,invariants=utilsFP.generateAtomInvariant(mol),bitInfo=tmp)
        aBits = utilsFP.getMorganEnvironment(mol, tmp, fp=fp, minRad=2)
        fp = fp.GetNonzeroElements()
    # path-based RDKit fingerprint fragmentation
    elif fragmentMethod=='RDK':
        fp = AllChem.UnfoldedRDKFingerprintCountBased(mol,maxPath=5,minPath=3,bitInfo=aBits)
        fp = fp.GetNonzeroElements()
    # get the final BRICS fragmentation (= smallest possible BRICS fragments of a molecule)
    elif fragmentMethod=='Brics':
        fragMol=BRICS.BreakBRICSBonds(mol)
        propSmi = _prepBRICSSmiles(fragMol)
        fp=Counter(propSmi.split('.'))
    else:
        print("Unknown fragment method")
    return fp, aBits

# this function is not part of the class due to parallelisation
# generate the fragments of a molecule, return a map with moleculeID and fragment dict 
開發者ID:rdkit,項目名稱:CheTo,代碼行數:26,代碼來源:chemTopicModel.py

示例3: new_mol

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def new_mol(self, name):
        if self.sanitized:
            mol = Chem.MolFromSmiles(name)
        else:
            mol = Chem.MolFromSmarts(name)
        if mol is None:            
            return None
        else:
            mg = MolGraph(name, self.sanitized, mol=mol)
            if self.fp_degree > 0:
                bi = {} if self.fp_info else None
                feat = AllChem.GetMorganFingerprint(mol, self.fp_degree, bitInfo=bi, invariants=self._get_inv(mol))
                on_bits = list(feat.GetNonzeroElements().keys())
                mg.fingerprints = on_bits
                mg.fp_info = bi
            return mg 
開發者ID:Hanjun-Dai,項目名稱:GLN,代碼行數:18,代碼來源:mol_utils.py

示例4: CalculateMorganFingerprint

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def CalculateMorganFingerprint(mol, radius=2):
    """
    #################################################################
    Calculate Morgan

    Usage:

        result=CalculateMorganFingerprint(mol)

        Input: mol is a molecule object.

        radius is a radius.

        Output: result is a tuple form. The first is the number of

        fingerprints. The second is a dict form whose keys are the

        position which this molecule has some substructure. The third

        is the DataStructs which is used for calculating the similarity.
    #################################################################
    """
    res = AllChem.GetMorganFingerprint(mol, radius)

    return res.GetLength(), res.GetNonzeroElements(), res 
開發者ID:gadsbyfly,項目名稱:PyBioMed,代碼行數:27,代碼來源:fingerprint.py

示例5: NP_score

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def NP_score(smile):
    mol = Chem.MolFromSmiles(smile)
    fp = Chem.GetMorganFingerprint(mol, 2)
    bits = fp.GetNonzeroElements()

    # calculating the score
    score = 0.
    for bit in bits:
        score += NP_model.get(bit, 0)
    score /= float(mol.GetNumAtoms())

    # preventing score explosion for exotic molecules
    if score > 4:
        score = 4. + math.log10(score - 4. + 1.)
    if score < -4:
        score = -4. - math.log10(-4. - score + 1.)
    val = np.clip(remap(score, -3, 1), 0.0, 1.0)
    return val 
開發者ID:gablg1,項目名稱:ORGAN,代碼行數:20,代碼來源:mol_metrics.py

示例6: fingerprints_from_mol

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def fingerprints_from_mol(mol):
    fp = AllChem.GetMorganFingerprint(mol, 3, useCounts=True, useFeatures=True)
    size = 2048
    nfp = np.zeros((1, size), np.int32)
    for idx,v in fp.GetNonzeroElements().items():
        nidx = idx%size
        nfp[0, nidx] += int(v)
    return nfp 
開發者ID:wengong-jin,項目名稱:hgraph2graph,代碼行數:10,代碼來源:drd2_scorer.py

示例7: __init__

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def __init__(self):
        query_mol = Chem.MolFromSmiles(self.query_structure)
        self.query_fp = AllChem.GetMorganFingerprint(query_mol, 2, useCounts=True, useFeatures=True) 
開發者ID:MarcusOlivecrona,項目名稱:REINVENT,代碼行數:5,代碼來源:scoring_functions.py

示例8: __call__

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
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 
開發者ID:MarcusOlivecrona,項目名稱:REINVENT,代碼行數:10,代碼來源:scoring_functions.py

示例9: fingerprints_from_mol

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def fingerprints_from_mol(cls, mol):
        fp = AllChem.GetMorganFingerprint(mol, 3, useCounts=True, useFeatures=True)
        size = 2048
        nfp = np.zeros((1, size), np.int32)
        for idx,v in fp.GetNonzeroElements().items():
            nidx = idx%size
            nfp[0, nidx] += int(v)
        return nfp 
開發者ID:MarcusOlivecrona,項目名稱:REINVENT,代碼行數:10,代碼來源:scoring_functions.py

示例10: fit

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def fit(self, mols):
        """Analyses the molecules and creates the key index for the creation of the dense array"""
        keys=set()
        for mol in mols:
            fp = AllChem.GetMorganFingerprint(mol,self.radius)
            keys.update(fp.GetNonzeroElements().keys())
        keys = list(keys)
        keys.sort()
        self.keys= np.array(keys)
        self.dims = len(self.keys) 
開發者ID:pcko1,項目名稱:Deep-Drug-Coder,代碼行數:12,代碼來源:vectorizers.py

示例11: load_model

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def load_model(self, FP_len=1024, model_tag='1024bool'):
        self.FP_len = FP_len
        if model_tag != '1024bool' and model_tag != '1024uint8' and model_tag != '2048bool':
            MyLogger.print_and_log(
                'Non-existent SCScore model requested: {}. Using "1024bool" model'.format(model_tag), scscore_prioritizer_loc, level=2)
            model_tag = '1024bool'
        filename = 'trained_model_path_'+model_tag
        with open(gc.SCScore_Prioritiaztion[filename], 'rb') as fid:
            self.vars = pickle.load(fid)
        if gc.DEBUG:
            MyLogger.print_and_log('Loaded synthetic complexity score prioritization model from {}'.format(
            gc.SCScore_Prioritiaztion[filename]), scscore_prioritizer_loc)

        if 'uint8' in gc.SCScore_Prioritiaztion[filename]:
            def mol_to_fp(mol):
                if mol is None:
                    return np.array((self.FP_len,), dtype=np.uint8)
                fp = AllChem.GetMorganFingerprint(
                    mol, self.FP_rad, useChirality=True)  # uitnsparsevect
                fp_folded = np.zeros((self.FP_len,), dtype=np.uint8)
                for k, v in fp.GetNonzeroElements().items():
                    fp_folded[k % self.FP_len] += v
                return np.array(fp_folded)
        else:
            def mol_to_fp(mol):
                if mol is None:
                    return np.zeros((self.FP_len,), dtype=np.float32)
                return np.array(AllChem.GetMorganFingerprintAsBitVect(mol, self.FP_rad, nBits=self.FP_len,
                                                                      useChirality=True), dtype=np.bool)
        self.mol_to_fp = mol_to_fp

        self.pricer = Pricer()
        self.pricer.load()
        self._restored = True
        self._loaded = True 
開發者ID:connorcoley,項目名稱:ASKCOS,代碼行數:37,代碼來源:scscore.py

示例12: depict_identifier

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def depict_identifier(mol, identifier, radius, useFeatures=False, **kwargs):
    """Depict an identifier in Morgan fingerprint.
    
    Parameters
    ----------
    mol : rdkit.Chem.rdchem.Mol
        RDKit molecule
    identifier : int or str
        Feature identifier from Morgan fingerprint
    radius : int
        Radius of Morgan FP
    useFeatures : bool
        Use feature-based Morgan FP
    
    Returns
    -------
    IPython.display.SVG
    """
    identifier = int(identifier)
    info = {}
    AllChem.GetMorganFingerprint(mol, radius, bitInfo=info, useFeatures=useFeatures)
    if identifier in info.keys():
        atoms, radii = zip(*info[identifier])
        return depict_atoms(mol, atoms, radii, **kwargs)
    else:
        return mol_to_svg(mol, **kwargs) 
開發者ID:samoturk,項目名稱:mol2vec,代碼行數:28,代碼來源:helpers.py

示例13: mol2alt_sentence

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def mol2alt_sentence(mol, radius):
    """Same as mol2sentence() expect it only returns the alternating sentence
    Calculates ECFP (Morgan fingerprint) and returns identifiers of substructures as 'sentence' (string).
    Returns a tuple with 1) a list with sentence for each radius and 2) a sentence with identifiers from all radii
    combined.
    NOTE: Words are ALWAYS reordered according to atom order in the input mol object.
    NOTE: Due to the way how Morgan FPs are generated, number of identifiers at each radius is smaller
    
    Parameters
    ----------
    mol : rdkit.Chem.rdchem.Mol
    radius : float 
        Fingerprint radius
    
    Returns
    -------
    list
        alternating sentence
    combined
    """
    radii = list(range(int(radius) + 1))
    info = {}
    _ = AllChem.GetMorganFingerprint(mol, radius, bitInfo=info)  # info: dictionary identifier, atom_idx, radius

    mol_atoms = [a.GetIdx() for a in mol.GetAtoms()]
    dict_atoms = {x: {r: None for r in radii} for x in mol_atoms}

    for element in info:
        for atom_idx, radius_at in info[element]:
            dict_atoms[atom_idx][radius_at] = element  # {atom number: {fp radius: identifier}}

    # merge identifiers alternating radius to sentence: atom 0 radius0, atom 0 radius 1, etc.
    identifiers_alt = []
    for atom in dict_atoms:  # iterate over atoms
        for r in radii:  # iterate over radii
            identifiers_alt.append(dict_atoms[atom][r])

    alternating_sentence = map(str, [x for x in identifiers_alt if x])

    return list(alternating_sentence) 
開發者ID:samoturk,項目名稱:mol2vec,代碼行數:42,代碼來源:features.py

示例14: CalculateECFP2Fingerprint

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def CalculateECFP2Fingerprint(mol, radius=1):
    """
    #################################################################
    Calculate ECFP2

    Usage:

        result=CalculateECFP2Fingerprint(mol)

        Input: mol is a molecule object.

        radius is a radius.

        Output: result is a tuple form. The first is the vector of

        fingerprints. The second is a dict form whose keys are the

        position which this molecule has some substructure. The third

        is the DataStructs which is used for calculating the similarity.
    #################################################################
    """
    res = AllChem.GetMorganFingerprint(mol, radius)

    fp = tuple(AllChem.GetMorganFingerprintAsBitVect(mol, radius, nBits=1024))

    return fp, res.GetNonzeroElements(), res 
開發者ID:gadsbyfly,項目名稱:PyBioMed,代碼行數:29,代碼來源:fingerprint.py

示例15: CalculateECFP4Fingerprint

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprint [as 別名]
def CalculateECFP4Fingerprint(mol, radius=2):
    """
    #################################################################
    Calculate ECFP4

    Usage:

        result=CalculateECFP4Fingerprint(mol)

        Input: mol is a molecule object.

        radius is a radius.

        Output: result is a tuple form. The first is the vector of

        fingerprints. The second is a dict form whose keys are the

        position which this molecule has some substructure. The third

        is the DataStructs which is used for calculating the similarity.
    #################################################################
    """
    res = AllChem.GetMorganFingerprint(mol, radius)

    fp = tuple(AllChem.GetMorganFingerprintAsBitVect(mol, radius, nBits=1024))

    return fp, res.GetNonzeroElements(), res 
開發者ID:gadsbyfly,項目名稱:PyBioMed,代碼行數:29,代碼來源:fingerprint.py


注:本文中的rdkit.Chem.AllChem.GetMorganFingerprint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。