本文整理汇总了Python中rdkit.Chem方法的典型用法代码示例。如果您正苦于以下问题:Python rdkit.Chem方法的具体用法?Python rdkit.Chem怎么用?Python rdkit.Chem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit
的用法示例。
在下文中一共展示了rdkit.Chem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_clusters
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def find_clusters(self):
mol = self.mol
n_atoms = mol.GetNumAtoms()
if n_atoms == 1: #special case
return [(0,)], [[0]]
clusters = []
for bond in mol.GetBonds():
a1 = bond.GetBeginAtom().GetIdx()
a2 = bond.GetEndAtom().GetIdx()
if not bond.IsInRing():
clusters.append( (a1,a2) )
ssr = [tuple(x) for x in Chem.GetSymmSSSR(mol)]
clusters.extend(ssr)
return clusters
示例2: get_leaves
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def get_leaves(mol):
leaf_atoms = [atom.GetIdx() for atom in mol.GetAtoms() if atom.GetDegree() == 1]
clusters = []
for bond in mol.GetBonds():
a1 = bond.GetBeginAtom().GetIdx()
a2 = bond.GetEndAtom().GetIdx()
if not bond.IsInRing():
clusters.append( set([a1,a2]) )
rings = [set(x) for x in Chem.GetSymmSSSR(mol)]
clusters.extend(rings)
leaf_rings = []
for r in rings:
inters = [c for c in clusters if r != c and len(r & c) > 0]
if len(inters) > 1: continue
nodes = [i for i in r if mol.GetAtomWithIdx(i).GetDegree() == 2]
leaf_rings.append( max(nodes) )
return leaf_atoms + leaf_rings
示例3: get_assm_cands
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def get_assm_cands(mol, atoms, inter_label, cluster, inter_size):
atoms = list(set(atoms))
mol = get_clique_mol(mol, atoms)
atom_map = [idxfunc(atom) for atom in mol.GetAtoms()]
mol = set_atommap(mol)
rank = Chem.CanonicalRankAtoms(mol, breakTies=False)
rank = { x:y for x,y in zip(atom_map, rank) }
pos, icls = zip(*inter_label)
if inter_size == 1:
cands = [pos[0]] + [ x for x in cluster if rank[x] != rank[pos[0]] ]
elif icls[0] == icls[1]: #symmetric case
shift = cluster[inter_size - 1:] + cluster[:inter_size - 1]
cands = zip(cluster, shift)
cands = [pos] + [ (x,y) for x,y in cands if (rank[min(x,y)],rank[max(x,y)]) != (rank[min(pos)], rank[max(pos)]) ]
else:
shift = cluster[inter_size - 1:] + cluster[:inter_size - 1]
cands = zip(cluster + shift, shift + cluster)
cands = [pos] + [ (x,y) for x,y in cands if (rank[x],rank[y]) != (rank[pos[0]], rank[pos[1]]) ]
return cands
示例4: get_inter_label
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def get_inter_label(mol, atoms, inter_atoms, atom_cls):
new_mol = get_clique_mol(mol, atoms)
if new_mol.GetNumBonds() == 0:
inter_atom = list(inter_atoms)[0]
for a in new_mol.GetAtoms():
a.SetAtomMapNum(0)
return new_mol, [ (inter_atom, Chem.MolToSmiles(new_mol)) ]
inter_label = []
for a in new_mol.GetAtoms():
idx = idxfunc(a)
if idx in inter_atoms and is_anchor(a, inter_atoms):
inter_label.append( (idx, get_anchor_smiles(new_mol, idx)) )
for a in new_mol.GetAtoms():
idx = idxfunc(a)
if idx in inter_atoms:
a.SetAtomMapNum(1)
elif len(atom_cls[idx]) > 1:
a.SetAtomMapNum(2)
else:
a.SetAtomMapNum(0)
return new_mol, inter_label
示例5: get_sub_mol
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def get_sub_mol(mol, sub_atoms):
new_mol = Chem.RWMol()
atom_map = {}
for idx in sub_atoms:
atom = mol.GetAtomWithIdx(idx)
atom_map[idx] = new_mol.AddAtom(atom)
sub_atoms = set(sub_atoms)
for idx in sub_atoms:
a = mol.GetAtomWithIdx(idx)
for b in a.GetNeighbors():
if b.GetIdx() not in sub_atoms: continue
bond = mol.GetBondBetweenAtoms(a.GetIdx(), b.GetIdx())
bt = bond.GetBondType()
if a.GetIdx() < b.GetIdx(): #each bond is enumerated twice
new_mol.AddBond(atom_map[a.GetIdx()], atom_map[b.GetIdx()], bt)
return new_mol.GetMol()
示例6: test_single_carbon
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def test_single_carbon(self):
"""Test that single carbon atom is featurized properly."""
raw_smiles = ['C']
import rdkit
mols = [rdkit.Chem.MolFromSmiles(s) for s in raw_smiles]
featurizer = ConvMolFeaturizer()
mol_list = featurizer.featurize(mols)
mol = mol_list[0]
# Only one carbon
assert mol.get_num_atoms() == 1
# No bonds, so degree adjacency lists are empty
deg_adj_lists = mol.get_deg_adjacency_lists()
assert np.array_equal(deg_adj_lists[0], np.zeros([1, 0], dtype=np.int32))
assert np.array_equal(deg_adj_lists[1], np.zeros([0, 1], dtype=np.int32))
assert np.array_equal(deg_adj_lists[2], np.zeros([0, 2], dtype=np.int32))
assert np.array_equal(deg_adj_lists[3], np.zeros([0, 3], dtype=np.int32))
assert np.array_equal(deg_adj_lists[4], np.zeros([0, 4], dtype=np.int32))
assert np.array_equal(deg_adj_lists[5], np.zeros([0, 5], dtype=np.int32))
assert np.array_equal(deg_adj_lists[6], np.zeros([0, 6], dtype=np.int32))
示例7: test_alkane
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def test_alkane(self):
"""Test on simple alkane"""
raw_smiles = ['CCC']
import rdkit.Chem
mols = [rdkit.Chem.MolFromSmiles(s) for s in raw_smiles]
featurizer = ConvMolFeaturizer()
mol_list = featurizer.featurize(mols)
mol = mol_list[0]
# 3 carbonds in alkane
assert mol.get_num_atoms() == 3
deg_adj_lists = mol.get_deg_adjacency_lists()
assert np.array_equal(deg_adj_lists[0], np.zeros([0, 0], dtype=np.int32))
# Outer two carbonds are connected to central carbon
assert np.array_equal(deg_adj_lists[1], np.array(
[[2], [2]], dtype=np.int32))
# Central carbon connected to outer two
assert np.array_equal(deg_adj_lists[2], np.array([[0, 1]], dtype=np.int32))
assert np.array_equal(deg_adj_lists[3], np.zeros([0, 3], dtype=np.int32))
assert np.array_equal(deg_adj_lists[4], np.zeros([0, 4], dtype=np.int32))
assert np.array_equal(deg_adj_lists[5], np.zeros([0, 5], dtype=np.int32))
assert np.array_equal(deg_adj_lists[6], np.zeros([0, 6], dtype=np.int32))
示例8: decode_test
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def decode_test():
wrong = 0
for tot,s in enumerate(sys.stdin):
s = s.split()[0]
tree = MolTree(s)
tree.recover()
cur_mol = copy_edit_mol(tree.nodes[0].mol)
global_amap = [{}] + [{} for node in tree.nodes]
global_amap[1] = {atom.GetIdx():atom.GetIdx() for atom in cur_mol.GetAtoms()}
dfs_assemble(cur_mol, global_amap, [], tree.nodes[0], None)
cur_mol = cur_mol.GetMol()
cur_mol = Chem.MolFromSmiles(Chem.MolToSmiles(cur_mol))
set_atommap(cur_mol)
dec_smiles = Chem.MolToSmiles(cur_mol)
gold_smiles = Chem.MolToSmiles(Chem.MolFromSmiles(s))
if gold_smiles != dec_smiles:
print gold_smiles, dec_smiles
wrong += 1
print wrong, tot + 1
示例9: get_bond_feat
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def get_bond_feat(bond, sanitized):
bt = bond.GetBondType()
t = 0
if bt == rdkit.Chem.rdchem.BondType.SINGLE:
t = 0
elif bt == rdkit.Chem.rdchem.BondType.DOUBLE:
t = 1
elif bt == rdkit.Chem.rdchem.BondType.TRIPLE:
t = 2
elif bt == rdkit.Chem.rdchem.BondType.AROMATIC:
t = 3
feat = 2
if sanitized:
feat = 1 if bond.GetOwningMol().GetRingInfo().NumBondRings(bond.GetIdx()) > 0 else 0
feat <<= 8
feat |= int(bond.GetIsConjugated())
feat <<= 8
feat |= t
assert feat >= 0
return feat
示例10: new_mol
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [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
示例11: find_rings
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def find_rings(rmol, rbonds, core_bonds):
n_atoms = rmol.GetNumAtoms()
new_mol = Chem.RWMol(rmol)
amap = {}
for atom in rmol.GetAtoms():
amap[atom.GetIntProp('molAtomMapNumber') - 1] = atom.GetIdx()
for x,y in core_bonds:
if (x,y) not in rbonds:
new_mol.AddBond(amap[x],amap[y],bond_types[0])
old_rings = [list(x) for x in Chem.GetSymmSSSR(rmol)]
new_rings = [list(x) for x in Chem.GetSymmSSSR(new_mol)]
old_rings = [[rmol.GetAtomWithIdx(x).GetIntProp('molAtomMapNumber') - 1 for x in alist] for alist in old_rings]
new_rings = [[rmol.GetAtomWithIdx(x).GetIntProp('molAtomMapNumber') - 1 for x in alist] for alist in new_rings]
new_rmap = {tuple(sorted(x)) : x for x in new_rings}
old_rings = set([tuple(sorted(x)) for x in old_rings])
new_rings = set([tuple(sorted(x)) for x in new_rings])
new_rings = list(new_rings - old_rings)
return [new_rmap[x] for x in new_rings if 5 <= len(x) <= 6]
示例12: copy_edit_mol
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def copy_edit_mol(mol):
new_mol = Chem.RWMol(Chem.MolFromSmiles(''))
for atom in mol.GetAtoms():
new_atom = Chem.Atom(atom.GetSymbol())
new_atom.SetFormalCharge(atom.GetFormalCharge())
new_atom.SetAtomMapNum(atom.GetAtomMapNum())
if atom.GetIsAromatic() and atom.GetSymbol() == 'N':
new_atom.SetNumExplicitHs(atom.GetTotalNumHs())
new_mol.AddAtom(new_atom)
for bond in mol.GetBonds():
a1 = bond.GetBeginAtom().GetIdx()
a2 = bond.GetEndAtom().GetIdx()
bt = bond.GetBondType()
new_mol.AddBond(a1, a2, bt)
return new_mol
示例13: count_inters
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def count_inters(s):
mol = Chem.MolFromSmiles(s)
inters = [a for a in mol.GetAtoms() if a.GetAtomMapNum() > 0]
return max(1, len(inters))
示例14: load_fragments
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def load_fragments(fragments):
fragments = [Chem.MolToSmiles(Chem.MolFromSmiles(x)) for x in fragments]
MolGraph.FRAGMENTS = set(fragments)
示例15: build_mol_graph
# 需要导入模块: import rdkit [as 别名]
# 或者: from rdkit import Chem [as 别名]
def build_mol_graph(self):
mol = self.mol
graph = nx.DiGraph(Chem.rdmolops.GetAdjacencyMatrix(mol))
for atom in mol.GetAtoms():
graph.nodes[atom.GetIdx()]['label'] = (atom.GetSymbol(), atom.GetFormalCharge())
for bond in mol.GetBonds():
a1 = bond.GetBeginAtom().GetIdx()
a2 = bond.GetEndAtom().GetIdx()
btype = MolGraph.BOND_LIST.index( bond.GetBondType() )
graph[a1][a2]['label'] = btype
graph[a2][a1]['label'] = btype
return graph