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


Python AllChem.MolFromSmiles方法代碼示例

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


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

示例1: batch_mixed_diversity

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [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

示例2: NP_score

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [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

示例3: shingling_from_smiles

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def shingling_from_smiles(
        in_smiles, radius=3, rings=True, kekulize=True, min_radius=1, sanitize=False
    ):
        """Creates a molecular shingling from a SMILES string.
    
    Arguments:
      in_smiles {string} -- A valid SMILES string
      radius {int} -- The MHFP radius (a radius of 3 corresponds to MHFP6)  (default: {3})
      rings {boolean} -- Whether or not to include rings in the shingling (default: {True})
      kekulize {boolean} -- Whether or not to kekulize the extracted SMILES (default: {True})
      min_radius {int} -- The minimum radius that is used to extract n-grams (default: {1})
      sanitize {boolean} -- Whether or not to sanitize the SMILES when parsing it using RDKit  (default: {False})
    
    Returns:
      list -- The molecular shingling.
    """

        return MHFPEncoder.shingling_from_mol(
            AllChem.MolFromSmiles(in_smiles, sanitize=sanitize),
            rings=rings,
            radius=radius,
            kekulize=True,
            min_radius=min_radius,
        ) 
開發者ID:reymond-group,項目名稱:mhfp,代碼行數:26,代碼來源:encoder.py

示例4: secfp_from_smiles

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def secfp_from_smiles(
        in_smiles, length=2048, radius=3, rings=True, kekulize=True, sanitize=False
    ):
        """Creates a folded binary vector fingerprint of a input SMILES string.

    Arguments:
      in_smiles {string} -- A valid SMILES string
      length {int} -- The length of the folded fingerprint (default: {2048})
      radius {int} -- The MHFP radius (a radius of 3 corresponds to SECFP6)  (default: {3})
      rings {boolean} -- Whether or not to include rings in the shingling (default: {True})
      kekulize {boolean} -- Whether or not to kekulize the extracted SMILES (default: {True})
      sanitize {boolean} -- Whether or not to sanitize the SMILES when parsing it using RDKit  (default: {False})
    
    Returns:
      numpy.ndarray -- The folded fingerprint.
    """
        return MHFPEncoder.secfp_from_mol(
            AllChem.MolFromSmiles(in_smiles, sanitize=sanitize),
            length=length,
            radius=radius,
            rings=rings,
            kekulize=kekulize,
        ) 
開發者ID:reymond-group,項目名稱:mhfp,代碼行數:25,代碼來源:encoder.py

示例5: sizeAttributeVector

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def sizeAttributeVector(molecular_attributes = False):
	m = AllChem.MolFromSmiles('CC')
	g = molToGraph(m, molecular_attributes = molecular_attributes)
	a = g.nodes[0]
	b = g.edges[0]
	return len(a.attributes) + len(b.attributes) 
開發者ID:connorcoley,項目名稱:conv_qsar_fast,代碼行數:8,代碼來源:neural_fp.py

示例6: sizeAttributeVectors

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def sizeAttributeVectors(molecular_attributes = False):
	m = AllChem.MolFromSmiles('CC')
	g = molToGraph(m, molecular_attributes = molecular_attributes)
	a = g.nodes[0]
	b = g.edges[0]
	return len(a.attributes), len(b.attributes) 
開發者ID:connorcoley,項目名稱:conv_qsar_fast,代碼行數:8,代碼來源:neural_fp.py

示例7: test_exact_lookup

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def test_exact_lookup(self):

        objs = MoleculeModel.objects.filter(molecule='COC(c1ccccc1)c1ccccc1')
        self.assertEqual(objs.count(), 1)

        objs = MoleculeModel.objects.filter(molecule='Nc1ccc(Cl)nc1')
        self.assertEqual(objs.count(), 1)

        objs = MoleculeModel.objects.filter(molecule=Chem.MolFromSmiles('Nc1ccc(Cl)nc1'))
        self.assertEqual(objs.count(), 1)

        objs = MoleculeModel.objects.filter(molecule=MOL_FROM_SMILES(Value('Nc1ccc(Cl)nc1')))
        self.assertEqual(objs.count(), 1) 
開發者ID:rdkit,項目名稱:django-rdkit,代碼行數:15,代碼來源:tests.py

示例8: test_hassubstruct_lookup

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def test_hassubstruct_lookup(self):

        objs = MoleculeModel.objects.filter(molecule__hassubstruct='C1=C(C)C=CC=C1')
        self.assertEqual(objs.count(), 61)

        objs = MoleculeModel.objects.filter(
            molecule__hassubstruct=MOL_FROM_SMILES(Value('C1=C(C)C=CC=C1')))
        self.assertEqual(objs.count(), 61)

        objs = MoleculeModel.objects.filter(molecule__hassubstruct='C1=CC=CC=C1')
        cnt1 = objs.count()
        self.assertEqual(cnt1, 70)

        objs = MoleculeModel.objects.filter(molecule__hassubstruct='C1=CN=CC=C1')
        cnt2 = objs.count()
        self.assertEqual(cnt2, 7)

        objs = MoleculeModel.objects.filter(
            Q(molecule__hassubstruct='C1=CC=CC=C1') |
            Q(molecule__hassubstruct='C1=CN=CC=C1'),
        )
        cnt3 = objs.count()
        self.assertEqual(cnt3, 73)
        self.assertTrue(cnt3 <= cnt1 + cnt2)

        qmol = QMOL(Value('c1[c,n]cccc1'))
        objs = MoleculeModel.objects.filter(molecule__hassubstruct=qmol)
        self.assertEqual(objs.count(), cnt3)

        objs = MoleculeModel.objects.filter(molecule__hassubstruct=Chem.MolFromSmiles('C1=CN=CC=C1'))
        cnt4 = objs.count()
        self.assertEqual(cnt2, 7) 
開發者ID:rdkit,項目名稱:django-rdkit,代碼行數:34,代碼來源:tests.py

示例9: test_issubstruct_lookup

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def test_issubstruct_lookup(self):

        objs = MoleculeModel.objects.filter(molecule__issubstruct='CCN1c2ccccc2Sc2ccccc21')
        self.assertEqual(objs.count(), 2)

        objs = MoleculeModel.objects.filter(molecule__issubstruct='CC[N+]([O-])(CC)CCCN1c2ccccc2S(=O)c2ccccc21')
        self.assertEqual(objs.count(), 4)

        objs = MoleculeModel.objects.filter(molecule__issubstruct=Chem.MolFromSmiles('CC[N+]([O-])(CC)CCCN1c2ccccc2S(=O)c2ccccc21'))
        self.assertEqual(objs.count(), 4) 
開發者ID:rdkit,項目名稱:django-rdkit,代碼行數:12,代碼來源:tests.py

示例10: test_pkl_io

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [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

示例11: setUp

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def setUp(self):
        mol = Chem.MolFromSmiles('c1cocc1')
        CtabModel.objects.create(ctab=Chem.MolToMolBlock(mol))
        CtabModel.objects.create(ctab='rubbish') 
開發者ID:rdkit,項目名稱:django-rdkit,代碼行數:6,代碼來源:tests.py

示例12: canon_smile

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def canon_smile(smile):
    return MolToSmiles(MolFromSmiles(smile)) 
開發者ID:gablg1,項目名稱:ORGAN,代碼行數:4,代碼來源:mol_metrics.py

示例13: verify_sequence

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def verify_sequence(smile):
    mol = Chem.MolFromSmiles(smile)
    return smile != '' and mol is not None and mol.GetNumAtoms() > 1


# def build_vocab(smiles, pad_char='_', start_char='^'):
#     i = 1
#     char_dict, ord_dict = {start_char: 0}, {0: start_char}
#     for smile in smiles:
#         for c in smile:
#             if c not in char_dict:
#                 char_dict[c] = i
#                 ord_dict[i] = c
#                 i += 1
#     char_dict[pad_char], ord_dict[i] = i, pad_char
#     return char_dict, ord_dict


# def pad(smile, n, pad_char='_'):
#     if n < len(smile):
#         return smile
#     return smile + pad_char * (n - len(smile))


# def unpad(smile, pad_char='_'): return smile.rstrip(pad_char)


# def encode(smile, max_len, char_dict): return [
#     char_dict[c] for c in pad(smile, max_len)]


# def decode(ords, ord_dict): return unpad(
#     ''.join([ord_dict[o] for o in ords])) 
開發者ID:gablg1,項目名稱:ORGAN,代碼行數:35,代碼來源:mol_metrics.py

示例14: batch_diversity

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def batch_diversity(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]
    vals = [diversity(s, fps) if verify_sequence(s)
            else 0.0 for s in smiles]
    return vals 
開發者ID:gablg1,項目名稱:ORGAN,代碼行數:10,代碼來源:mol_metrics.py

示例15: diversity

# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def diversity(smile, fps):
    val = 0.0
    low_rand_dst = 0.9
    mean_div_dst = 0.945
    ref_mol = Chem.MolFromSmiles(smile)
    ref_fps = Chem.GetMorganFingerprintAsBitVect(ref_mol, 4, nBits=2048)
    dist = DataStructs.BulkTanimotoSimilarity(
        ref_fps, fps, returnDistance=True)
    mean_dist = np.mean(np.array(dist))
    val = remap(mean_dist, low_rand_dst, mean_div_dst)
    val = np.clip(val, 0.0, 1.0)
    return val

#============== 
開發者ID:gablg1,項目名稱:ORGAN,代碼行數:16,代碼來源:mol_metrics.py


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