当前位置: 首页>>代码示例>>Python>>正文


Python Chem.RWMol方法代码示例

本文整理汇总了Python中rdkit.Chem.RWMol方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.RWMol方法的具体用法?Python Chem.RWMol怎么用?Python Chem.RWMol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdkit.Chem的用法示例。


在下文中一共展示了Chem.RWMol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_sub_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [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() 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:20,代码来源:chemutils.py

示例2: find_rings

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [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] 
开发者ID:wengong-jin,项目名称:nips17-rexgen,代码行数:24,代码来源:mol_graph.py

示例3: copy_edit_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [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 
开发者ID:connorcoley,项目名称:ASKCOS,代码行数:19,代码来源:eval_by_smiles.py

示例4: matrices2mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def matrices2mol(self, node_labels, edge_labels, strict=False):
        mol = Chem.RWMol()

        for node_label in node_labels:
            mol.AddAtom(Chem.Atom(self.atom_decoder_m[node_label]))

        for start, end in zip(*np.nonzero(edge_labels)):
            if start > end:
                mol.AddBond(int(start), int(end), self.bond_decoder_m[edge_labels[start, end]])

        if strict:
            try:
                Chem.SanitizeMol(mol)
            except:
                mol = None

        return mol 
开发者ID:nicola-decao,项目名称:MolGAN,代码行数:19,代码来源:sparse_molecular_dataset.py

示例5: Tensor2Mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def Tensor2Mol(A, x):
    mol = Chem.RWMol()
    # x[x < 0] = 0.
    # A[A < 0] = -1
    # atoms_exist = np.sum(x, 1) != 0
    atoms = np.argmax(x, 1)
    atoms_exist = atoms != 4
    atoms = atoms[atoms_exist]
    atoms += 6
    adj = np.argmax(A, 0)
    adj = np.array(adj)
    adj = adj[atoms_exist, :][:, atoms_exist]
    adj[adj == 3] = -1
    adj += 1
    # print('num atoms: {}'.format(sum(atoms>0)))

    for atom in atoms:
        mol.AddAtom(Chem.Atom(int(atom)))

    for start, end in zip(*np.nonzero(adj)):
        if start > end:
            mol.AddBond(int(start), int(end), bond_decoder_m[adj[start, end]])

    return mol 
开发者ID:pfnet-research,项目名称:graph-nvp,代码行数:26,代码来源:utils.py

示例6: construct_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def construct_mol(x, A, atomic_num_list):
    mol = Chem.RWMol()
    # x (ch, num_node)
    atoms = np.argmax(x, axis=1)
    # last a
    atoms_exist = atoms != len(atomic_num_list) - 1
    atoms = atoms[atoms_exist]
    # print('num atoms: {}'.format(sum(atoms>0)))

    for atom in atoms:
        mol.AddAtom(Chem.Atom(int(atomic_num_list[atom])))

    # A (edge_type, num_node, num_node)
    adj = np.argmax(A, axis=0)
    adj = np.array(adj)
    adj = adj[atoms_exist, :][:, atoms_exist]
    adj[adj == 3] = -1
    adj += 1
    for start, end in zip(*np.nonzero(adj)):
        if start > end:
            mol.AddBond(int(start), int(end), bond_decoder_m[adj[start, end]])

    return mol 
开发者ID:pfnet-research,项目名称:graph-nvp,代码行数:25,代码来源:utils.py

示例7: MolToTemplates

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def MolToTemplates(mol):
    """Prepare set of templates for a given PDB residue."""

    if mol.HasProp('_Name') and mol.GetProp('_Name') in ['DA', 'DG', 'DT', 'DC',
                                                         'A', 'G', 'T', 'C', 'U']:
        backbone = 'OP(=O)(O)OC'
    else:
        backbone = 'OC(=O)CN'

    match = mol.GetSubstructMatch(Chem.MolFromSmiles(backbone))
    mol2 = Chem.RWMol(mol)
    if match:
        mol2.RemoveAtom(match[0])

    Chem.SanitizeMol(mol2)
    mol2 = mol2.GetMol()
    return (mol, mol2) 
开发者ID:oddt,项目名称:oddt,代码行数:19,代码来源:fixer.py

示例8: __init__

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def __init__(self, avocab, batch_size, node_fdim, edge_fdim, max_nodes=100, max_edges=300, max_nb=10):
        super(IncGraph, self).__init__(batch_size, node_fdim, edge_fdim, max_nodes, max_edges, max_nb)
        self.avocab = avocab
        self.mol = Chem.RWMol()
        self.mol.AddAtom( Chem.Atom('C') ) #make sure node is 1 index, consistent to self.graph
        self.fnode = self.fnode.float()
        self.fmess = self.fmess.float()
        self.batch = defaultdict(list) 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:10,代码来源:inc_graph.py

示例9: find_fragments

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def find_fragments(mol):
    new_mol = Chem.RWMol(mol)
    for atom in new_mol.GetAtoms():
        atom.SetAtomMapNum(atom.GetIdx())

    for bond in mol.GetBonds():
        if bond.IsInRing(): continue
        a1 = bond.GetBeginAtom()
        a2 = bond.GetEndAtom()

        if a1.IsInRing() and a2.IsInRing():
            new_mol.RemoveBond(a1.GetIdx(), a2.GetIdx())

        elif a1.IsInRing() and a2.GetDegree() > 1:
            new_idx = new_mol.AddAtom(copy_atom(a1))
            new_mol.GetAtomWithIdx(new_idx).SetAtomMapNum(a1.GetIdx())
            new_mol.AddBond(new_idx, a2.GetIdx(), bond.GetBondType())
            new_mol.RemoveBond(a1.GetIdx(), a2.GetIdx())

        elif a2.IsInRing() and a1.GetDegree() > 1:
            new_idx = new_mol.AddAtom(copy_atom(a2))
            new_mol.GetAtomWithIdx(new_idx).SetAtomMapNum(a2.GetIdx())
            new_mol.AddBond(new_idx, a1.GetIdx(), bond.GetBondType())
            new_mol.RemoveBond(a1.GetIdx(), a2.GetIdx())
    
    new_mol = new_mol.GetMol()
    new_smiles = Chem.MolToSmiles(new_mol)

    hopts = []
    for fragment in new_smiles.split('.'):
        fmol = Chem.MolFromSmiles(fragment)
        indices = set([atom.GetAtomMapNum() for atom in fmol.GetAtoms()])
        fmol = get_clique_mol(mol, indices)
        fmol = sanitize(fmol, kekulize=False)
        fsmiles = Chem.MolToSmiles(fmol)
        hopts.append((fsmiles, indices))
    
    return hopts 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:40,代码来源:chemutils.py

示例10: copy_atom

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def copy_atom(atom, atommap=True):
    new_atom = Chem.Atom(atom.GetSymbol())
    new_atom.SetFormalCharge(atom.GetFormalCharge())
    if atommap: 
        new_atom.SetAtomMapNum(atom.GetAtomMapNum())
    return new_atom

#mol must be RWMol object 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:10,代码来源:chemutils.py

示例11: copy_edit_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def copy_edit_mol(mol):
    new_mol = Chem.RWMol(Chem.MolFromSmiles(''))
    for atom in mol.GetAtoms():
        new_atom = copy_atom(atom)
        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)
        #if bt == Chem.rdchem.BondType.AROMATIC and not aromatic:
        #    bt = Chem.rdchem.BondType.SINGLE
    return new_mol 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:16,代码来源:chemutils.py

示例12: nx_to_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def nx_to_mol(G):
    mol = Chem.RWMol()
    atomic_nums = nx.get_node_attributes(G, 'atomic_num')
    chiral_tags = nx.get_node_attributes(G, 'chiral_tag')
    formal_charges = nx.get_node_attributes(G, 'formal_charge')
    node_is_aromatics = nx.get_node_attributes(G, 'is_aromatic')
    node_hybridizations = nx.get_node_attributes(G, 'hybridization')
    num_explicit_hss = nx.get_node_attributes(G, 'num_explicit_hs')
    node_to_idx = {}
    for node in G.nodes():
        a=Chem.Atom(atomic_nums[node])
        a.SetChiralTag(chiral_tags[node])
        a.SetFormalCharge(formal_charges[node])
        a.SetIsAromatic(node_is_aromatics[node])
        a.SetHybridization(node_hybridizations[node])
        a.SetNumExplicitHs(num_explicit_hss[node])
        idx = mol.AddAtom(a)
        node_to_idx[node] = idx

    bond_types = nx.get_edge_attributes(G, 'bond_type')
    for edge in G.edges():
        first, second = edge
        ifirst = node_to_idx[first]
        isecond = node_to_idx[second]
        bond_type = bond_types[first, second]
        mol.AddBond(ifirst, isecond, bond_type)

    Chem.SanitizeMol(mol)
    return mol 
开发者ID:bowenliu16,项目名称:rl_graph_generation,代码行数:31,代码来源:dataset_utils.py

示例13: copy_edit_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def copy_edit_mol(mol):
    new_mol = Chem.RWMol(Chem.MolFromSmiles(''))
    for atom in mol.GetAtoms():
        new_atom = copy_atom(atom)
        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 
开发者ID:dmlc,项目名称:dgl,代码行数:13,代码来源:chemutils.py

示例14: numpy_to_rdkit

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def numpy_to_rdkit(adj, nf, ef, sanitize=False):
    """
    Converts a molecule from numpy to RDKit format.
    :param adj: binary numpy array of shape (N, N) 
    :param nf: numpy array of shape (N, F)
    :param ef: numpy array of shape (N, N, S)
    :param sanitize: whether to sanitize the molecule after conversion
    :return: an RDKit molecule
    """
    if rdc is None:
        raise ImportError('`numpy_to_rdkit` requires RDKit.')
    mol = rdc.RWMol()
    for nf_ in nf:
        atomic_num = int(nf_)
        if atomic_num > 0:
            mol.AddAtom(rdc.Atom(atomic_num))

    for i, j in zip(*np.triu_indices(adj.shape[-1])):
        if i != j and adj[i, j] == adj[j, i] == 1 and not mol.GetBondBetweenAtoms(int(i), int(j)):
            bond_type_1 = BOND_MAP[int(ef[i, j, 0])]
            bond_type_2 = BOND_MAP[int(ef[j, i, 0])]
            if bond_type_1 == bond_type_2:
                mol.AddBond(int(i), int(j), bond_type_1)

    mol = mol.GetMol()
    if sanitize:
        rdc.SanitizeMol(mol)
    return mol 
开发者ID:danielegrattarola,项目名称:spektral,代码行数:30,代码来源:chem.py

示例15: return_canoncailised_smiles_str

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RWMol [as 别名]
def return_canoncailised_smiles_str(molecule, kekuleSmiles, remove_am=True, allHsExplicit=False) -> str:
    """
    Rdkit molecule to smiles str,
    """
    mol_copy = Chem.RWMol(molecule)
    if remove_am:
        for atom in mol_copy.GetAtoms():
            atom.ClearProp('molAtomMapNumber')
    smiles = Chem.MolToSmiles(mol_copy, allHsExplicit=allHsExplicit, kekuleSmiles=kekuleSmiles, canonical=True)
    return smiles 
开发者ID:john-bradshaw,项目名称:molecule-chef,代码行数:12,代码来源:rdkit_general_ops.py


注:本文中的rdkit.Chem.RWMol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。