本文整理汇总了Python中rdkit.Chem.GetSymmSSSR方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.GetSymmSSSR方法的具体用法?Python Chem.GetSymmSSSR怎么用?Python Chem.GetSymmSSSR使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.GetSymmSSSR方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_clusters
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [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
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [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_leaves
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [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: leaf_rings.extend( [i for i in r if mol.GetAtomWithIdx(i).GetDegree() == 2] )
return leaf_atoms + leaf_rings
示例4: find_rings
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [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]
示例5: get_overlapped_edge_feature
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def get_overlapped_edge_feature(edge_mask, color, new_mol):
overlapped_edge_feature=[]
for node_in_focus, neighbor in edge_mask:
if color[neighbor] == 1:
# attempt to add the edge
new_mol.AddBond(int(node_in_focus), int(neighbor), number_to_bond[0])
# Check whether there are two cycles having more than two overlap edges
try:
ssr = Chem.GetSymmSSSR(new_mol)
except:
ssr = []
overlap_flag = False
for idx1 in range(len(ssr)):
for idx2 in range(idx1+1, len(ssr)):
if len(set(ssr[idx1]) & set(ssr[idx2])) > 2:
overlap_flag=True
# remove that edge
new_mol.RemoveBond(int(node_in_focus), int(neighbor))
if overlap_flag:
overlapped_edge_feature.append((node_in_focus, neighbor))
return overlapped_edge_feature
# adj_list [3, v, v] or defaultdict. bfs distance on a graph
示例6: shape_count
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def shape_count(dataset, remove_print=False, all_smiles=None):
if all_smiles==None:
with open('generated_smiles_%s' % dataset, 'rb') as f:
all_smiles=set(pickle.load(f))
geometry_counts=[0]*len(geometry_numbers)
geometry_counts_per_molecule=[] # record the geometry counts for each molecule
for smiles in all_smiles:
nodes, edges = to_graph(smiles, dataset)
if len(edges)<=0:
continue
new_mol=Chem.MolFromSmiles(smiles)
ssr = Chem.GetSymmSSSR(new_mol)
counts_for_molecule=[0] * len(geometry_numbers)
for idx in range(len(ssr)):
ring_len=len(list(ssr[idx]))
if ring_len in geometry_numbers:
geometry_counts[geometry_numbers.index(ring_len)]+=1
counts_for_molecule[geometry_numbers.index(ring_len)]+=1
geometry_counts_per_molecule.append(counts_for_molecule)
return len(all_smiles), geometry_counts, geometry_counts_per_molecule
示例7: sssr_metric
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def sssr_metric(dataset):
with open('generated_smiles_%s' % dataset, 'rb') as f:
all_smiles=set(pickle.load(f))
overlapped_molecule=0
for smiles in all_smiles:
new_mol=Chem.MolFromSmiles(smiles)
ssr = Chem.GetSymmSSSR(new_mol)
overlap_flag=False
for idx1 in range(len(ssr)):
for idx2 in range(idx1+1, len(ssr)):
if len(set(ssr[idx1]) & set(ssr[idx2])) > 2:
overlap_flag=True
if overlap_flag:
overlapped_molecule+=1
return overlapped_molecule/len(all_smiles)
# select the best based on shapes and probs
示例8: fingerprint_mols
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [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
示例9: FragIndicesToMol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def FragIndicesToMol(oMol,indices):
em = Chem.EditableMol(Chem.Mol())
newIndices={}
for i,idx in enumerate(indices):
em.AddAtom(oMol.GetAtomWithIdx(idx))
newIndices[idx]=i
for i,idx in enumerate(indices):
at = oMol.GetAtomWithIdx(idx)
for bond in at.GetBonds():
if bond.GetBeginAtomIdx()==idx:
oidx = bond.GetEndAtomIdx()
else:
oidx = bond.GetBeginAtomIdx()
# make sure every bond only gets added once:
if oidx<idx:
continue
em.AddBond(newIndices[idx],newIndices[oidx],bond.GetBondType())
res = em.GetMol()
res.ClearComputedProps()
Chem.GetSymmSSSR(res)
res.UpdatePropertyCache(False)
res._idxMap=newIndices
return res
示例10: get_ring_counts
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def get_ring_counts(self):
'''
Retrieve a list containing the sizes of rings in the symmetric smallest set
of smallest rings (S-SSSR from RdKit) in the molecule (e.g. [5, 6, 5] for two
rings of size 5 and one ring of size 6).
Returns:
List of int: list with ring sizes
'''
if self._rings is None:
# calculate symmetric SSSR with RdKit using the canonical smiles
# representation as input
can = self.get_can()
mol = Chem.MolFromSmiles(can)
if mol is not None:
ssr = Chem.GetSymmSSSR(mol)
self._rings = [len(ssr[i]) for i in range(len(ssr))]
else:
self._rings = [] # cannot count rings
return self._rings
示例11: find_clusters
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [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)
if 0 not in clusters[0]: #root is not node[0]
for i,cls in enumerate(clusters):
if 0 in cls:
clusters = [clusters[i]] + clusters[:i] + clusters[i+1:]
#clusters[i], clusters[0] = clusters[0], clusters[i]
break
atom_cls = [[] for i in range(n_atoms)]
for i in range(len(clusters)):
for atom in clusters[i]:
atom_cls[atom].append(i)
return clusters, atom_cls
示例12: construct_atom_ring_vec
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def construct_atom_ring_vec(mol, num_max_atoms=WEAVE_DEFAULT_NUM_MAX_ATOMS):
nAtom = mol.GetNumAtoms()
sssr = Chem.GetSymmSSSR(mol)
ring_feature = numpy.zeros((num_max_atoms, 6,), dtype=numpy.float32)
for ring in sssr:
ring = list(ring)
for i in range(nAtom):
if i in ring:
ring_size = len(ring)
if ring_size >= 3 and ring_size <= 8:
ring_feature[i, ring_size - 3] = 1.0
return ring_feature
示例13: construct_ring_feature_vec
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def construct_ring_feature_vec(mol, num_max_atoms=WEAVE_DEFAULT_NUM_MAX_ATOMS):
n_atom = mol.GetNumAtoms()
sssr = Chem.GetSymmSSSR(mol)
ring_feature_vec = numpy.zeros(
(num_max_atoms ** 2, 1,), dtype=numpy.float32)
for ring in sssr:
ring = list(ring)
n_atom_in_ring = len(ring)
for i in range(n_atom_in_ring):
for j in range(n_atom_in_ring):
a0 = ring[i]
a1 = ring[j]
ring_feature_vec[a0 * n_atom + a1] = 1
return ring_feature_vec
示例14: sssr
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def sssr(self):
return [list(path) for path in list(Chem.GetSymmSSSR(self.Mol))]
示例15: compute_cation_pi
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import GetSymmSSSR [as 别名]
def compute_cation_pi(mol1, mol2, charge_tolerance=0.01, **kwargs):
"""Finds aromatic rings in mo1 and cations in mol2 that interact with each
other.
Parameters:
-----------
mol1: rdkit.rdchem.Mol
Molecule to look for interacting rings
mol2: rdkit.rdchem.Mol
Molecule to look for interacting cations
charge_tolerance: float
Atom is considered a cation if its formal charge is greater than
1 - charge_tolerance
**kwargs:
Arguments that are passed to is_cation_pi function
Returns:
--------
mol1_pi: dict
Dictionary that maps atom indices (from mol1) to the number of cations
(in mol2) they interact with
mol2_cation: dict
Dictionary that maps atom indices (from mol2) to the number of aromatic
atoms (in mol1) they interact with
"""
mol1_pi = Counter()
mol2_cation = Counter()
conformer = mol2.GetConformer()
aromatic_atoms = set(atom.GetIdx() for atom in mol1.GetAromaticAtoms())
from rdkit import Chem
rings = [list(r) for r in Chem.GetSymmSSSR(mol1)]
for ring in rings:
# if ring from mol1 is aromatic
if set(ring).issubset(aromatic_atoms):
ring_center = compute_ring_center(mol1, ring)
ring_normal = compute_ring_normal(mol1, ring)
for atom in mol2.GetAtoms():
# ...and atom from mol2 is a cation
if atom.GetFormalCharge() > 1.0 - charge_tolerance:
cation_position = np.array(conformer.GetAtomPosition(atom.GetIdx()))
# if angle and distance are correct
if is_cation_pi(cation_position, ring_center, ring_normal, **kwargs):
# count atoms forming a contact
mol1_pi.update(ring)
mol2_cation.update([atom.GetIndex()])
return mol1_pi, mol2_cation