当前位置: 首页>>代码示例>>Python>>正文


Python AllChem.GetMorganFingerprintAsBitVect方法代码示例

本文整理汇总了Python中rdkit.Chem.AllChem.GetMorganFingerprintAsBitVect方法的典型用法代码示例。如果您正苦于以下问题:Python AllChem.GetMorganFingerprintAsBitVect方法的具体用法?Python AllChem.GetMorganFingerprintAsBitVect怎么用?Python AllChem.GetMorganFingerprintAsBitVect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdkit.Chem.AllChem的用法示例。


在下文中一共展示了AllChem.GetMorganFingerprintAsBitVect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compute_ecfp_features

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def compute_ecfp_features(mol, ecfp_degree=2, ecfp_power=11):
  """Computes ECFP features for provided rdkit molecule.

  Parameters:
  -----------
    mol: rdkit molecule
      Molecule to featurize.
    ecfp_degree: int
      ECFP radius
    ecfp_power: int
      Number of bits to store ECFP features (2^ecfp_power will be length of
      ECFP array)
  Returns:
  --------
    ecfp_array: np.ndarray
      Returns an array of size 2^ecfp_power where array at index i has a 1 if
      that ECFP fragment is found in the molecule and array at index j has a 0
      if ECFP fragment not in molecule.
  """
  from rdkit.Chem import AllChem
  bv = AllChem.GetMorganFingerprintAsBitVect(
      mol, ecfp_degree, nBits=2**ecfp_power)
  return np.array(bv) 
开发者ID:deepchem,项目名称:deepchem,代码行数:25,代码来源:rdkit_grid_featurizer.py

示例2: fingerprint_mols

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def fingerprint_mols(mols, fp_dim):
    fps = []
    for mol in mols:
        mol = Chem.MolFromSmiles(mol)

        # Necessary for fingerprinting
        # Chem.GetSymmSSSR(mol)

        # "When comparing the ECFP/FCFP fingerprints and
        # the Morgan fingerprints generated by the RDKit,
        # remember that the 4 in ECFP4 corresponds to the
        # diameter of the atom environments considered,
        # while the Morgan fingerprints take a radius parameter.
        # So the examples above, with radius=2, are roughly
        # equivalent to ECFP4 and FCFP4."
        # <http://www.rdkit.org/docs/GettingStartedInPython.html>
        fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2, nBits=int(fp_dim))
        # fold_factor = fp.GetNumBits()//fp_dim
        # fp = DataStructs.FoldFingerprint(fp, fold_factor)
        fps.append(fp)
    return fps 
开发者ID:frnsys,项目名称:retrosynthesis_planner,代码行数:23,代码来源:policies.py

示例3: highest_tanimoto_precalc_fps

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def highest_tanimoto_precalc_fps(mol, fps):
    """

    Args:
        mol: Rdkit molecule
        fps: precalculated ECFP4 bitvectors

    Returns:

    """

    if fps is None or len(fps) == 0:
        return 0

    fp1 = AllChem.GetMorganFingerprintAsBitVect(mol, 2, 4096)
    sims = np.array(DataStructs.BulkTanimotoSimilarity(fp1, fps))

    return sims.max() 
开发者ID:BenevolentAI,项目名称:guacamol,代码行数:20,代码来源:chemistry.py

示例4: batch_mixed_diversity

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def batch_mixed_diversity(smiles, set_smiles):
    # set smiles
    rand_smiles = random.sample(set_smiles, 100)
    rand_mols = [Chem.MolFromSmiles(s) for s in rand_smiles]
    fps = [Chem.GetMorganFingerprintAsBitVect(
        m, 4, nBits=2048) for m in rand_mols]
    # gen smiles
    rand_gen_smiles = random.sample(smiles, 500)

    gen_mols = [Chem.MolFromSmiles(s) for s in smiles]
    fps = [Chem.GetMorganFingerprintAsBitVect(
        m, 4, nBits=2048) for m in gen_mols]

    vals = [diversity(s, fps) + diversity(s, fps) if verify_sequence(s)
            else 0.0 for s in smiles]

    return vals 
开发者ID:gablg1,项目名称:ORGAN,代码行数:19,代码来源:mol_metrics.py

示例5: make_circular_fingerprint

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def make_circular_fingerprint(mol, circular_fp_key):
  """Returns circular fingerprint for a mol given its circular_fp_key.

  Args:
    mol : rdkit.Mol
    circular_fp_key : A ms_constants.CircularFingerprintKey object
  Returns:
    np.array of len circular_fp_key.fp_len
  """
  # A dictionary to record rdkit functions to base names
  fp_methods_dict = {
      fmap_constants.CIRCULAR_FP_BASENAME:
          AllChem.GetMorganFingerprintAsBitVect,
      fmap_constants.COUNTING_CIRCULAR_FP_BASENAME:
          AllChem.GetHashedMorganFingerprint
  }

  fp = fp_methods_dict[circular_fp_key.fp_type](
      mol, circular_fp_key.radius, nBits=circular_fp_key.fp_len)
  fp_arr = np.zeros(1)
  DataStructs.ConvertToNumpyArray(fp, fp_arr)
  return fp_arr 
开发者ID:brain-research,项目名称:deep-molecular-massspec,代码行数:24,代码来源:feature_utils.py

示例6: ECFP_from_SMILES

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def ECFP_from_SMILES(cls, smiles, radius=3, bit_len=4096, scaffold=0, index=None):
        fps = np.zeros((len(smiles), bit_len))
        for i, smile in enumerate(smiles):
            mol = Chem.MolFromSmiles(smile)
            arr = np.zeros((1,))
            try:
                if scaffold == 1:
                    mol = MurckoScaffold.GetScaffoldForMol(mol)
                elif scaffold == 2:
                    mol = MurckoScaffold.MakeScaffoldGeneric(mol)
                fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius, nBits=bit_len)
                DataStructs.ConvertToNumpyArray(fp, arr)
                fps[i, :] = arr
            except:
                print(smile)
                fps[i, :] = [0] * bit_len
        return pd.DataFrame(fps, index=(smiles if index is None else index)) 
开发者ID:XuhanLiu,项目名称:DrugEx,代码行数:19,代码来源:util.py

示例7: morgan_fingerprint

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def morgan_fingerprint(smiles: str, radius: int = 2, num_bits: int = 2048, use_counts: bool = False) -> np.ndarray:
    """
    Generates a morgan fingerprint for a smiles string.

    :param smiles: A smiles string for a molecule.
    :param radius: The radius of the fingerprint.
    :param num_bits: The number of bits to use in the fingerprint.
    :param use_counts: Whether to use counts or just a bit vector for the fingerprint
    :return: A 1-D numpy array containing the morgan fingerprint.
    """
    if type(smiles) == str:
        mol = Chem.MolFromSmiles(smiles)
    else:
        mol = smiles
    if use_counts:
        fp_vect = AllChem.GetHashedMorganFingerprint(mol, radius, nBits=num_bits)
    else:
        fp_vect = AllChem.GetMorganFingerprintAsBitVect(mol, radius, nBits=num_bits)
    fp = np.zeros((1,))
    DataStructs.ConvertToNumpyArray(fp_vect, fp)

    return fp 
开发者ID:wengong-jin,项目名称:chemprop,代码行数:24,代码来源:morgan_fingerprint.py

示例8: getMorganEnvironment

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def getMorganEnvironment(mol, bitInfo, fp=None, minRad=0):
    """

    >>> m = Chem.MolFromSmiles('CC(O)C')
    >>> bi = {}
    >>> fp = AllChem.GetMorganFingerprintAsBitVect(m,2,2048,bitInfo=bi)
    >>> getMorganEnvironment(m,bi)
    defaultdict(<class 'list'>, {1057: [[], []], 227: [[1]], 709: [[0, 1, 2]], 1: [[]], 283: [[0], [2]], 807: [[]]})
    >>> getMorganEnvironment(m,bi,minRad=1)
    defaultdict(<class 'list'>, {283: [[0], [2]], 227: [[1]], 709: [[0, 1, 2]]})
    >>> list(fp.GetOnBits())
    [1, 227, 283, 709, 807, 1057]
    >>> getMorganEnvironment(m,bi,minRad=1,fp=fp)
    defaultdict(<class 'list'>, {283: [[0], [2]], 227: [[1]], 709: [[0, 1, 2]]})
    >>> list(fp.GetOnBits())
    [227, 283, 709]

    """
    bitPaths=defaultdict(list)
    for bit,info in bitInfo.items():
        for atomID,radius in info:
            if radius < minRad:
                if fp != None:
                    fp[bit]=0
                continue
            env = Chem.FindAtomEnvironmentOfRadiusN(mol,radius,atomID)
            bitPaths[bit].append(list(env))
    return bitPaths 
开发者ID:rdkit,项目名称:CheTo,代码行数:30,代码来源:utilsFP.py

示例9: similarity

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
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) 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:13,代码来源:properties.py

示例10: similarity

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
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) 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:13,代码来源:stereo.py

示例11: calcfingerprint

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def calcfingerprint(mol, args):
    '''Return a list of the bits/cnts of the fingerprint of mol.
    Uses fingerprint settings from args which should have been the result
    of a parse of addfpargs'''
    if args.fp == 'rdkit':
        fp = Chem.RDKFingerprint(mol,fpSize=args.fpbits)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp.startswith('ecfp'):
        diameter = int(args.fp.replace('ecfp',''))
        r = diameter/2
        fp = Chem.GetMorganFingerprintAsBitVect(mol,r,nBits=args.fpbits)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp == 'maccs':
        fp = MACCSkeys.GenMACCSKeys(mol)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp == 'smarts':
        if args.smartsfile:
            smarts = args.smartsfile
            ret = [0]*len(smarts)
            for (i,smart) in enumerate(smarts):
                if mol.HasSubstructMatch(smart):
                    ret[i] = 1
            return ret
        else:
            sys.stderr.write("ERROR: Must provide SMARTS file with --smarts\n")
            sys.exit(-1)
    elif args.fp == 'fp2':
        smi = Chem.MolToSmiles(mol) 
        obmol = pybel.readstring('smi',smi)
        fp = obmol.calcfp(fptype='FP2')
        ret = [0]*1021 #FP2 are mod 1021
        for setbit in fp.bits:
            #but pybel makes the bits start at 1 for some reason
            assert(setbit>0)
            ret[setbit-1] = 1
            
        return ret
        
    else:
        return [] 
开发者ID:dkoes,项目名称:qsar-tools,代码行数:42,代码来源:outputfingerprints.py

示例12: calcFingerprints

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def calcFingerprints(smiles):
	m1 = Chem.MolFromSmiles(smiles)
	fp = AllChem.GetMorganFingerprintAsBitVect(m1,2, nBits=2048)
	binary = fp.ToBitString()
	return list(binary)

#calculate fingerprints for chunked array of smiles 
开发者ID:lhm30,项目名称:PIDGINv2,代码行数:9,代码来源:predict_enriched_two_libraries_decision_tree.py

示例13: calcFingerprints

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def calcFingerprints(smiles):
	m1 = Chem.MolFromSmiles(smiles)
	fp = AllChem.GetMorganFingerprintAsBitVect(m1,2, nBits=2048)
	return fp

#calculate fingerprints for chunked array of smiles 
开发者ID:lhm30,项目名称:PIDGINv2,代码行数:8,代码来源:sim_to_train.py

示例14: test_pkl_io

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def test_pkl_io(self):
        bfps = {}
        for smiles in SMILES_SAMPLE:
            mol = Chem.MolFromSmiles(smiles)
            bfp = Chem.GetMorganFingerprintAsBitVect(mol, 2, 512)
            obj = BfpModel.objects.create(bfp=bfp)
            bfps[obj.pk] = bfp

        for obj in BfpModel.objects.all():
            self.assertTrue(obj.pk in bfps)
            ibfp = bfps[obj.pk]
            obfp = obj.bfp
            self.assertEqual(list(ibfp.GetOnBits()),
                             list(obfp.GetOnBits())) 
开发者ID:rdkit,项目名称:django-rdkit,代码行数:16,代码来源:tests.py

示例15: transform_mol

# 需要导入模块: from rdkit.Chem import AllChem [as 别名]
# 或者: from rdkit.Chem.AllChem import GetMorganFingerprintAsBitVect [as 别名]
def transform_mol(self, mol):
        """ transforms the molecule into a numpy bit array with the morgan bits

            :parameter mol: the RDKit molecule to be transformed
        """
        fp = AllChem.GetMorganFingerprintAsBitVect(mol,self.radius,nBits=self.bits)
        arr = np.zeros((self.bits,))
        DataStructs.ConvertToNumpyArray(fp, arr)
        return arr 
开发者ID:pcko1,项目名称:Deep-Drug-Coder,代码行数:11,代码来源:vectorizers.py


注:本文中的rdkit.Chem.AllChem.GetMorganFingerprintAsBitVect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。