本文整理汇总了Python中rdkit.Chem.RemoveHs方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.RemoveHs方法的具体用法?Python Chem.RemoveHs怎么用?Python Chem.RemoveHs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.RemoveHs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: standardize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def standardize(self, mol):
"""Return a standardized version the given molecule.
The standardization process consists of the following stages: RDKit
:py:func:`~rdkit.Chem.rdmolops.RemoveHs`, RDKit :py:func:`~rdkit.Chem.rdmolops.SanitizeMol`,
:class:`~molvs.metal.MetalDisconnector`, :class:`~molvs.normalize.Normalizer`,
:class:`~molvs.charge.Reionizer`, RDKit :py:func:`~rdkit.Chem.rdmolops.AssignStereochemistry`.
:param mol: The molecule to standardize.
:type mol: rdkit.Chem.rdchem.Mol
:returns: The standardized molecule.
:rtype: rdkit.Chem.rdchem.Mol
"""
mol = copy.deepcopy(mol)
Chem.SanitizeMol(mol)
mol = Chem.RemoveHs(mol)
mol = self.disconnect_metals(mol)
mol = self.normalize(mol)
mol = self.reionize(mol)
Chem.AssignStereochemistry(mol, force=True, cleanIt=True)
# TODO: Check this removes symmetric stereocenters
return mol
示例2: standardize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def standardize(self, mol):
"""Return a standardized version the given molecule.
The standardization process consists of the following stages: RDKit
:rdkit:`RemoveHs <Chem.rdmolops-module.html#RemoveHs>`, RDKit
:rdkit:`SanitizeMol <Chem.rdmolops-module.html#SanitizeMol>`, :class:`~molvs.metal.MetalDisconnector`,
:class:`~molvs.normalize.Normalizer`, :class:`~molvs.charge.Reionizer`, RDKit
:rdkit:`AssignStereochemistry <Chem.rdmolops-module.html#AssignStereochemistry>`.
:param mol: The molecule to standardize.
:type mol: :rdkit:`Mol <Chem.rdchem.Mol-class.html>`
:returns: The standardized molecule.
:rtype: :rdkit:`Mol <Chem.rdchem.Mol-class.html>`
"""
mol = copy.deepcopy(mol)
Chem.RemoveHs(mol)
Chem.SanitizeMol(mol)
mol = self.disconnect_metals(mol)
mol = self.normalize(mol)
mol = self.reionize(mol)
Chem.AssignStereochemistry(mol, force=True, cleanIt=True)
# TODO: Check this removes symmetric stereocenters
return mol
示例3: _extra_docs
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def _extra_docs(self):
# method: to_smiles
self._to_smiles_core_names = ("rdkit.Chem.MolToSmarts",)
self._to_smiles_core_docs = ("http://rdkit.org/docs/source/rdkit.Chem.inchi.html?highlight=inchi#rdkit.Chem.inchi.MolToInchi",)
# method: to_smarts
self._to_smarts_core_names = ("rdkit.Chem.MolToSmarts",)
self._to_smarts_core_docs = ("http://rdkit.org/docs/source/rdkit.Chem.inchi.html?highlight=inchi#rdkit.Chem.inchi.MolToInchi",)
# method: to_inchi
self._to_inchi_core_names = ("rdkit.Chem.MolToInchi",)
self._to_inchi_core_docs = ("http://rdkit.org/docs/source/rdkit.Chem.inchi.html?highlight=inchi#rdkit.Chem.inchi.MolToInchi",)
# method: hydrogens
self._hydrogens_core_names = ("rdkit.Chem.AddHs","rdkit.Chem.RemoveHs")
self._hydrogens_core_docs = ("http://rdkit.org/docs/source/rdkit.Chem.rdmolops.html?highlight=addhs#rdkit.Chem.rdmolops.AddHs",
"http://rdkit.org/docs/source/rdkit.Chem.rdmolops.html?highlight=addhs#rdkit.Chem.rdmolops.RemoveHs")
#
self._to_xyz_core_names = ("rdkit.Chem.AllChem.MMFFOptimizeMolecule","rdkit.Chem.AllChem.UFFOptimizeMolecule")
self._to_xyz_core_docs =(
"http://rdkit.org/docs/source/rdkit.Chem.rdForceFieldHelpers.html?highlight=mmff#rdkit.Chem.rdForceFieldHelpers.MMFFOptimizeMolecule",
"http://rdkit.org/docs/source/rdkit.Chem.rdForceFieldHelpers.html?highlight=mmff#rdkit.Chem.rdForceFieldHelpers.UFFOptimizeMolecule"
)
示例4: tensorize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def tensorize(self, batch_x, batch_c):
atom_tensor = np.zeros((len(batch_x), self.num_atoms, self.get_num_features()))
adjm_tensor = np.zeros((len(batch_x), self.num_atoms, self.num_atoms))
posn_tensor = np.zeros((len(batch_x), self.num_atoms, self.num_atoms, 3))
for mol_idx, mol in enumerate(batch_x):
Chem.RemoveHs(mol)
mol_atoms = mol.GetNumAtoms()
# Atom features
atom_tensor[mol_idx, :mol_atoms, :] = self.get_atom_features(mol)
# Adjacency matrix
adjms = np.array(rdmolops.GetAdjacencyMatrix(mol), dtype="float")
# Normalize adjacency matrix by D^(-1/2) * A_hat * D^(-1/2), Kipf et al. 2016
adjms += np.eye(mol_atoms)
degree = np.array(adjms.sum(1))
deg_inv_sqrt = np.power(degree, -0.5)
deg_inv_sqrt[np.isinf(deg_inv_sqrt)] = 0.
deg_inv_sqrt = np.diag(deg_inv_sqrt)
adjms = np.matmul(np.matmul(deg_inv_sqrt, adjms), deg_inv_sqrt)
adjm_tensor[mol_idx, : mol_atoms, : mol_atoms] = adjms
# Relative position matrix
for atom_idx in range(mol_atoms):
pos_c = batch_c[mol_idx][atom_idx]
for neighbor_idx in range(mol_atoms):
pos_n = batch_c[mol_idx][neighbor_idx]
# Direction should be Neighbor -> Center
n_to_c = [pos_c[0] - pos_n[0], pos_c[1] - pos_n[1], pos_c[2] - pos_n[2]]
posn_tensor[mol_idx, atom_idx, neighbor_idx, :] = n_to_c
return [atom_tensor, adjm_tensor, posn_tensor]
示例5: coulomb_matrix
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def coulomb_matrix(self, mol):
"""
Generate Coulomb matrices for each conformer of the given molecule.
Parameters
----------
mol : RDKit Mol
Molecule.
"""
from rdkit import Chem
if self.remove_hydrogens:
mol = Chem.RemoveHs(mol)
n_atoms = mol.GetNumAtoms()
z = [atom.GetAtomicNum() for atom in mol.GetAtoms()]
rval = []
for conf in mol.GetConformers():
d = self.get_interatomic_distances(conf)
m = np.zeros((n_atoms, n_atoms))
for i in range(mol.GetNumAtoms()):
for j in range(mol.GetNumAtoms()):
if i == j:
m[i, j] = 0.5 * z[i]**2.4
elif i < j:
m[i, j] = (z[i] * z[j]) / d[i, j]
m[j, i] = m[i, j]
else:
continue
if self.randomize:
for random_m in self.randomize_coulomb_matrix(m):
random_m = pad_array(random_m, self.max_atoms)
rval.append(random_m)
else:
m = pad_array(m, self.max_atoms)
rval.append(m)
rval = np.asarray(rval)
return rval
示例6: test_coulomb_matrix_no_hydrogens
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def test_coulomb_matrix_no_hydrogens(self):
"""
Test hydrogen removal.
"""
from rdkit import Chem
mol = Chem.RemoveHs(self.mol)
assert mol.GetNumAtoms() < self.mol.GetNumAtoms()
f = cm.CoulombMatrix(
max_atoms=mol.GetNumAtoms(), remove_hydrogens=True, upper_tri=True)
rval = f([self.mol]) # use the version with hydrogens
size = np.triu_indices(mol.GetNumAtoms())[0].size
assert rval.shape == (1, mol.GetNumConformers(), size)
示例7: cano_smiles
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def cano_smiles(smiles):
try:
tmp = Chem.MolFromSmiles(smiles)
if tmp is None:
return None, smiles
tmp = Chem.RemoveHs(tmp)
if tmp is None:
return None, smiles
[a.ClearProp('molAtomMapNumber') for a in tmp.GetAtoms()]
return tmp, Chem.MolToSmiles(tmp)
except:
return None, smiles
示例8: canonicalize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def canonicalize(smiles):
try:
tmp = Chem.MolFromSmiles(smiles)
except:
print('no mol')
return smiles
if tmp is None:
return smiles
tmp = Chem.RemoveHs(tmp)
[a.ClearProp('molAtomMapNumber') for a in tmp.GetAtoms()]
return Chem.MolToSmiles(tmp)
示例9: make_feat_data
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def make_feat_data(mol, offset=1):
res = []
check_atom = set()
nohmol = Chem.RemoveHs(mol)
recap_res = Recap.RecapDecompose(nohmol)
leaves = [key.replace('*','').replace('()','') for key in recap_res.GetLeaves().keys()]
leaves = [leave.replace('[H]', '') for leave in leaves if leave != '[H]']
leaves = sorted(leaves, key=lambda x: Chem.MolFromSmarts(x).GetNumAtoms(), reverse=True)
if len(leaves) == 0:
line = [i for i in range(mol.GetNumAtoms())]
line = [str(n + offset) for n in line]
line = [Chem.MolToSmiles(mol)] + line
return [line]
for leavsmi in leaves:
leav = Chem.MolFromSmarts(leavsmi)
matches = mol.GetSubstructMatches(leav)
for i, match in enumerate(matches):
line = list(match)
if len(check_atom & set(line)) > 0:
continue
check_atom = check_atom|set(line)
for idx in match:
nei = get_neighbor_h(idx, mol)
line += nei
line = [str(j + offset) for j in line]
line = [leavsmi + '_' + str(i)] + line
res.append(line)
return res
示例10: getRMS
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def getRMS(self, prb_mol, ref_pos, useFF=False):
def optimizeWithFF(mol):
molf = Chem.AddHs(mol, addCoords=True)
AllChem.MMFFOptimizeMolecule(molf)
molf = Chem.RemoveHs(molf)
return molf
n_est = prb_mol.GetNumAtoms()
ref_cf = Chem.rdchem.Conformer(n_est)
for k in range(n_est):
ref_cf.SetAtomPosition(k, ref_pos[k].tolist())
ref_mol = copy.deepcopy(prb_mol)
ref_mol.RemoveConformer(0)
ref_mol.AddConformer(ref_cf)
if useFF:
try:
res = AllChem.AlignMol(prb_mol, optimizeWithFF(ref_mol))
except:
res = AllChem.AlignMol(prb_mol, ref_mol)
else:
res = AllChem.AlignMol(prb_mol, ref_mol)
return res
示例11: test_smiles_from_adjacent_matrix
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def test_smiles_from_adjacent_matrix(smiles):
charged_fragments = True
quick = True
# Cut apart the smiles
mol = get_mol(smiles)
atoms = get_atoms(mol)
charge = Chem.GetFormalCharge(mol)
adjacent_matrix = Chem.GetAdjacencyMatrix(mol)
#
mol = Chem.RemoveHs(mol)
canonical_smiles = Chem.MolToSmiles(mol)
# Define new molecule template from atoms
new_mol = x2m.get_proto_mol(atoms)
# reconstruct the molecule from adjacent matrix, atoms and total charge
new_mol = x2m.AC2mol(new_mol, adjacent_matrix, atoms, charge, charged_fragments, quick)
new_mol = Chem.RemoveHs(new_mol)
new_mol_smiles = Chem.MolToSmiles(new_mol)
assert new_mol_smiles == canonical_smiles
return
示例12: test_smiles_from_coord_vdw
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def test_smiles_from_coord_vdw(smiles):
# The answer
mol = Chem.MolFromSmiles(smiles)
charge = Chem.GetFormalCharge(mol)
canonical_smiles = Chem.MolToSmiles(mol, isomericSmiles=False)
# generate forcefield coordinates
atoms, coordinates = generate_structure_from_smiles(smiles)
# Generate molobj from atoms, charge and coordinates
mol = x2m.xyz2mol(atoms, coordinates, charge=charge)
# For this test, remove chira. clean and canonical
Chem.Kekulize(mol)
mol = Chem.RemoveHs(mol)
Chem.RemoveStereochemistry(mol)
smiles = Chem.MolToSmiles(mol, isomericSmiles=False)
# Please look away. A small hack that removes the explicit hydrogens
mol = Chem.MolFromSmiles(smiles)
smiles = Chem.MolToSmiles(mol)
assert smiles == canonical_smiles
return
示例13: test_smiles_from_coord_huckel
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def test_smiles_from_coord_huckel(smiles):
# The answer
mol = Chem.MolFromSmiles(smiles)
charge = Chem.GetFormalCharge(mol)
canonical_smiles = Chem.MolToSmiles(mol, isomericSmiles=False)
# generate forcefield coordinates
atoms, coordinates = generate_structure_from_smiles(smiles)
# Generate molobj from atoms, charge and coordinates
mol = x2m.xyz2mol(atoms, coordinates, charge=charge, use_huckel=True)
# For this test, remove chira. clean and canonical
Chem.Kekulize(mol)
mol = Chem.RemoveHs(mol)
Chem.RemoveStereochemistry(mol)
smiles = Chem.MolToSmiles(mol, isomericSmiles=False)
# Please look away. A small hack that removes the explicit hydrogens
mol = Chem.MolFromSmiles(smiles)
smiles = Chem.MolToSmiles(mol)
assert smiles == canonical_smiles
return
示例14: test_smiles_from_xyz_files
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def test_smiles_from_xyz_files(filename, charge, answer):
charged_fragments = True
quick = True
atoms, charge_read, coordinates = x2m.read_xyz_file(filename)
mol = x2m.xyz2mol(atoms, coordinates, charge=charge)
mol = Chem.RemoveHs(mol)
smiles = Chem.MolToSmiles(mol)
assert smiles == answer
return
示例15: ContructLFromGraphSearch
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import RemoveHs [as 别名]
def ContructLFromGraphSearch(mol):
"""
#################################################################
The last lipophilic pattern on page 55 of the book is realized as a graph
search and not as a SMARTS search.
"L" carbon atom adjacent only to carbon atoms.
The result is a list format.
#################################################################
"""
AtomIndex = []
Hmol = Chem.RemoveHs(mol)
for atom in Hmol.GetAtoms():
temp = []
if atom.GetAtomicNum() == 6:
for neighatom in atom.GetNeighbors():
if neighatom.GetAtomicNum() == 6:
temp.append(0)
elif neighatom.GetAtomicNum() == 1:
continue
else:
temp.append(1)
if sum(temp) == 0:
AtomIndex.append(atom.GetIdx())
return AtomIndex
###################################