本文整理汇总了Python中rdkit.Chem.Atom方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.Atom方法的具体用法?Python Chem.Atom怎么用?Python Chem.Atom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.Atom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_edit_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例2: matrices2mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例3: test_rings
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [as 别名]
def test_rings(scaffold):
rings = scaffold.rings
assert isinstance(rings, RingStack)
assert hasattr(rings, 'owner')
assert hasattr(rings, 'info')
assert hasattr(rings, 'atom_rings')
assert hasattr(rings, 'bond_rings')
assert rings.count == 3 and len(rings) == 3
assert repr(rings) == '<RingStack at {}>'.format(hex(id(rings)))
assert isinstance(rings[0], Ring)
assert len([x for x in rings]) == 3
assert isinstance(rings.info, Chem.RingInfo)
assert len(rings.atom_rings) == 3 and len(rings.bond_rings) == 3
ring = rings[1]
assert hasattr(ring, 'owner')
assert hasattr(ring, 'aix')
assert hasattr(ring, 'bix')
assert all([isinstance(x, Chem.Bond) for x in ring.bonds])
assert all([isinstance(x, Chem.Atom) for x in ring.atoms])
assert isinstance(ring.size, int)
assert len(ring) == len(ring.atoms)
assert repr(ring) == '<Ring at {}>'.format(hex(id(ring)))
示例4: test_ring_systems
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [as 别名]
def test_ring_systems(scaffold):
rings = scaffold.ring_systems
assert isinstance(rings, RingSystemStack)
assert hasattr(rings, 'owner')
assert hasattr(rings, 'ring_indexes')
assert hasattr(rings, 'atom_rings')
assert hasattr(rings, 'bond_rings')
assert rings.count == 2 and len(rings) == 2
assert repr(rings) == '<RingSystemStack at {}>'.format(hex(id(rings)))
assert isinstance(rings[0], RingSystem)
assert len([x for x in rings]) == 2
assert len(rings.atom_rings) == 2 and len(rings.bond_rings) == 2
ring = rings[1]
assert hasattr(ring, 'owner')
assert hasattr(ring, 'aix')
assert hasattr(ring, 'bix')
assert hasattr(ring, 'rix')
assert all([isinstance(x, Chem.Bond) for x in ring.bonds])
assert all([isinstance(x, Chem.Atom) for x in ring.atoms])
assert isinstance(ring.size, int)
assert len(ring) == len(ring.atoms)
assert repr(ring) == '<RingSystem at {}>'.format(hex(id(ring)))
assert isinstance(ring[0], Ring)
assert len(list(ring.get_rings())) == 2
示例5: Tensor2Mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例6: construct_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例7: __init__
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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)
示例8: copy_atom
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例9: nx_to_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例10: copy_atom
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [as 别名]
def copy_atom(atom):
new_atom = Chem.Atom(atom.GetSymbol())
new_atom.SetFormalCharge(atom.GetFormalCharge())
new_atom.SetAtomMapNum(atom.GetAtomMapNum())
return new_atom
示例11: numpy_to_rdkit
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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
示例12: copy_edit_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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())
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: add_atoms
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [as 别名]
def add_atoms(new_mol, node_symbol, dataset):
for number in node_symbol:
if dataset=='qm9' or dataset=='cep':
idx=new_mol.AddAtom(Chem.Atom(dataset_info(dataset)['number_to_atom'][number]))
elif dataset=='zinc':
new_atom = Chem.Atom(dataset_info(dataset)['number_to_atom'][number])
charge_num=int(dataset_info(dataset)['atom_types'][number].split('(')[1].strip(')'))
new_atom.SetFormalCharge(charge_num)
new_mol.AddAtom(new_atom)
示例14: _process_molecule_rdkit
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [as 别名]
def _process_molecule_rdkit(jmol):
from rdkit import Chem
# Handle errors
if abs(jmol.molecular_charge) > 1.0e-6:
raise InputError("RDKit does not currently support charged molecules.")
if not jmol.connectivity: # Check for empty list
raise InputError("RDKit requires molecules to have a connectivity graph.")
# Build out the base molecule
base_mol = Chem.Mol()
rw_mol = Chem.RWMol(base_mol)
for sym in jmol.symbols:
rw_mol.AddAtom(Chem.Atom(sym.title()))
# Add in connectivity
bond_types = {1: Chem.BondType.SINGLE, 2: Chem.BondType.DOUBLE, 3: Chem.BondType.TRIPLE}
for atom1, atom2, bo in jmol.connectivity:
rw_mol.AddBond(atom1, atom2, bond_types[bo])
mol = rw_mol.GetMol()
# Write out the conformer
natom = len(jmol.symbols)
conf = Chem.Conformer(natom)
bohr2ang = ureg.conversion_factor("bohr", "angstrom")
for line in range(natom):
conf.SetAtomPosition(
line,
(
bohr2ang * jmol.geometry[line, 0],
bohr2ang * jmol.geometry[line, 1],
bohr2ang * jmol.geometry[line, 2],
),
)
mol.AddConformer(conf)
Chem.rdmolops.SanitizeMol(mol)
return mol
示例15: copy_edit_mol
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Atom [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()) # TODO: How to deal with changing formal charge?
new_atom.SetAtomMapNum(atom.GetAtomMapNum())
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