本文整理汇总了Python中rdkit.Chem.rdMolDescriptors.GetMorganFingerprint方法的典型用法代码示例。如果您正苦于以下问题:Python rdMolDescriptors.GetMorganFingerprint方法的具体用法?Python rdMolDescriptors.GetMorganFingerprint怎么用?Python rdMolDescriptors.GetMorganFingerprint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem.rdMolDescriptors
的用法示例。
在下文中一共展示了rdMolDescriptors.GetMorganFingerprint方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def main() :
model = models.KeyedVectors.load_word2vec_format("vec.txt")
embeddings = list()
# Using canonical smiles for glycine, as in original research paper
mol = Chem.MolFromSmiles("C(C(=O)O)N")
try:
info = {}
rdMolDescriptors.GetMorganFingerprint(mol, 0, bitInfo=info)
keys = info.keys()
keys_list = list(keys)
totalvec = np.zeros(200)
for k in keys_list:
wordvec = model.wv[str(k)]
totalvec = np.add(totalvec, wordvec)
embeddings.append(totalvec)
except Exception as e:
print(e)
pass
print(embeddings[0])
示例2: NP_score
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def NP_score(mol, fscore=None):
if fscore is None:
fscore =readNPModel()
if mol is None:
raise ValueError('invalid molecule')
fp = rdMolDescriptors.GetMorganFingerprint(mol, 2)
bits = fp.GetNonzeroElements()
# calculating the score
score = 0.
for bit in bits:
score += fscore.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.)
return score
示例3: _featurize
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def _featurize(self, mol):
"""
Calculate circular fingerprint.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
from rdkit import Chem
from rdkit.Chem import rdMolDescriptors
if self.sparse:
info = {}
fp = rdMolDescriptors.GetMorganFingerprint(
mol,
self.radius,
useChirality=self.chiral,
useBondTypes=self.bonds,
useFeatures=self.features,
bitInfo=info)
fp = fp.GetNonzeroElements() # convert to a dict
# generate SMILES for fragments
if self.smiles:
fp_smiles = {}
for fragment_id, count in fp.items():
root, radius = info[fragment_id][0]
env = Chem.FindAtomEnvironmentOfRadiusN(mol, radius, root)
frag = Chem.PathToSubmol(mol, env)
smiles = Chem.MolToSmiles(frag)
fp_smiles[fragment_id] = {'smiles': smiles, 'count': count}
fp = fp_smiles
else:
fp = rdMolDescriptors.GetMorganFingerprintAsBitVect(
mol,
self.radius,
nBits=self.size,
useChirality=self.chiral,
useBondTypes=self.bonds,
useFeatures=self.features)
return fp
示例4: main
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def main() :
sdf_root_path = "/media/data/pubchem/SDF"
for path, dirs, filenames in os.walk(sdf_root_path) :
for filename in filenames:
filepath = os.path.join(sdf_root_path, filename)
# This SDF file fails to parse with RDKit on Ubuntu 16.04
if "Compound_102125001_102150000" in filename:
continue
with gzip.open(filepath, 'rb') as myfile:
suppl = Chem.ForwardSDMolSupplier(myfile)
for mol in suppl:
if not mol:
continue
try :
info = {}
rdMolDescriptors.GetMorganFingerprint(mol,1,bitInfo=info)
keys = info.keys()
keys_list = list(keys)
for k in keys_list:
print(k,end=' ')
print()
except Exception:
pass
示例5: _featurize
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def _featurize(self, mol, smiles=None):
"""
Calculate circular fingerprint.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
if self.sparse:
info = {}
fp = rdMolDescriptors.GetMorganFingerprint(
mol, self.radius, useChirality=self.chiral,
useBondTypes=self.bonds, useFeatures=self.features,
bitInfo=info)
fp = fp.GetNonzeroElements() # convert to a dict
# generate SMILES for fragments
if self.calc_smiles:
fp_smiles = {}
for fragment_id, count in fp.items():
root, radius = info[fragment_id][0]
env = Chem.FindAtomEnvironmentOfRadiusN(mol, radius, root)
frag = Chem.PathToSubmol(mol, env)
smiles = Chem.MolToSmiles(frag)
fp_smiles[fragment_id] = {'smiles': smiles, 'count': count}
fp = fp_smiles
else:
fp = ComparableFingerprint(mol, self.radius, nBits=self.size, useChirality=self.chiral,
useBondTypes=self.bonds, useFeatures=self.features, smiles=smiles)
return fp
示例6: scoreMolWConfidence
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def scoreMolWConfidence(mol, fscore):
"""Next to the NP Likeness Score, this function outputs a confidence value
between 0..1 that descibes how many fragments of the tested molecule
were found in the model data set (1: all fragments were found).
Returns namedtuple NPLikeness(nplikeness, confidence)"""
if mol is None:
raise ValueError('invalid molecule')
fp = rdMolDescriptors.GetMorganFingerprint(mol, 2)
bits = fp.GetNonzeroElements()
# calculating the score
score = 0.0
bits_found = 0
for bit in bits:
if bit in fscore:
bits_found += 1
score += fscore[bit]
score /= float(mol.GetNumAtoms())
confidence = float(bits_found / len(bits))
# preventing score explosion for exotic molecules
if score > 4:
score = 4. + math.log10(score - 4. + 1.)
elif score < -4:
score = -4. - math.log10(-4. - score + 1.)
NPLikeness = namedtuple("NPLikeness", "nplikeness,confidence")
return NPLikeness(score, confidence)
示例7: calculateScore
# 需要导入模块: from rdkit.Chem import rdMolDescriptors [as 别名]
# 或者: from rdkit.Chem.rdMolDescriptors import GetMorganFingerprint [as 别名]
def calculateScore(m):
if _fscores is None: readFragmentScores()
# fragment score
fp = rdMolDescriptors.GetMorganFingerprint(m,2) #<- 2 is the *radius* of the circular fingerprint
fps = fp.GetNonzeroElements()
score1 = 0.
nf = 0
for bitId,v in iteritems(fps):
nf += v
sfp = bitId
score1 += _fscores.get(sfp,-4)*v
score1 /= nf
# features score
nAtoms = m.GetNumAtoms()
nChiralCenters = len(Chem.FindMolChiralCenters(m,includeUnassigned=True))
ri = m.GetRingInfo()
nBridgeheads,nSpiro=numBridgeheadsAndSpiro(m,ri)
nMacrocycles=0
for x in ri.AtomRings():
if len(x)>8: nMacrocycles+=1
sizePenalty = nAtoms**1.005 - nAtoms
stereoPenalty = math.log10(nChiralCenters+1)
spiroPenalty = math.log10(nSpiro+1)
bridgePenalty = math.log10(nBridgeheads+1)
macrocyclePenalty = 0.
# ---------------------------------------
# This differs from the paper, which defines:
# macrocyclePenalty = math.log10(nMacrocycles+1)
# This form generates better results when 2 or more macrocycles are present
if nMacrocycles > 0: macrocyclePenalty = math.log10(2)
score2 = 0. -sizePenalty -stereoPenalty -spiroPenalty -bridgePenalty -macrocyclePenalty
# correction for the fingerprint density
# not in the original publication, added in version 1.1
# to make highly symmetrical molecules easier to synthetise
score3 = 0.
if nAtoms > len(fps):
score3 = math.log(float(nAtoms) / len(fps)) * .5
sascore = score1 + score2 + score3
# need to transform "raw" value into scale between 1 and 10
min = -4.0
max = 2.5
sascore = 11. - (sascore - min + 1) / (max - min) * 9.
# smooth the 10-end
if sascore > 8.: sascore = 8. + math.log(sascore+1.-9.)
if sascore > 10.: sascore = 10.0
elif sascore < 1.: sascore = 1.0
return sascore