本文整理匯總了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
示例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
示例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,
)
示例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,
)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()))
示例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')
示例12: canon_smile
# 需要導入模塊: from rdkit.Chem import AllChem [as 別名]
# 或者: from rdkit.Chem.AllChem import MolFromSmiles [as 別名]
def canon_smile(smile):
return MolToSmiles(MolFromSmiles(smile))
示例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]))
示例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
示例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
#==============