本文整理汇总了Python中openbabel.OBMol方法的典型用法代码示例。如果您正苦于以下问题:Python openbabel.OBMol方法的具体用法?Python openbabel.OBMol怎么用?Python openbabel.OBMol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openbabel
的用法示例。
在下文中一共展示了openbabel.OBMol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def __init__(self, OBMol=None, source=None, protein=False):
# lazy
self._source = source # dict with keys: n, fmt, string, filename
if OBMol and not isinstance(OBMol, (Molecule, pybel.Molecule, ob.OBMol)):
raise ValueError('OBMol needs to be ODDT, Pybel or OB molecule instance')
# call parent constructor
super(Molecule, self).__init__(OBMol)
self._protein = protein
# ob.DeterminePeptideBackbone(molecule.OBMol)
# percieve chains in residues
# if len(res_dict) > 1 and not molecule.OBMol.HasChainsPerceived():
# print("Dirty HACK")
# molecule = pybel.readstring('pdb', molecule.write('pdb'))
self._atom_dict = None
self._res_dict = None
self._ring_dict = None
self._coords = None
self._charges = None
# lazy Molecule parsing requires masked OBMol
示例2: _crd2mul
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def _crd2mul(symbols, crds):
atomnumber = len(symbols)
xyzstring = ''.join((f"{atomnumber}\nDPGEN\n", "\n".join(
['{:2s} {:22.15f} {:22.15f} {:22.15f}'.format(s, x, y, z)
for s, (x, y, z) in zip(symbols, crds)])))
conv = openbabel.OBConversion()
conv.SetInAndOutFormats('xyz', 'gjf')
mol = openbabel.OBMol()
conv.ReadString(mol, xyzstring)
gjfstring = conv.WriteString(mol)
try:
mul = int(gjfstring.split('\n')[4].split()[1])
except IndexError:
# openbabel 3.0
mul = int(gjfstring.split('\n')[5].split()[1])
return mul
示例3: _update_bond_orders
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def _update_bond_orders(self, idc_lists):
'''
Updates the bond orders in the underlying OBMol object.
Args:
idc_lists (list of list of int): nested list containing bonds, i.e. pairs
of row indices (list1) and column indices (list2) which shall be updated
'''
con_mat = self.get_connectivity()
self._obmol.BeginModify()
for i in range(len(idc_lists[0])):
idx1 = idc_lists[0][i]
idx2 = idc_lists[1][i]
obbond = self._obmol.GetBond(int(idx1+1), int(idx2+1))
obbond.SetBO(int(con_mat[idx1, idx2]))
self._obmol.EndModify()
# reset fingerprints etc
self._fp = None
self._can = None
self._mirror_can = None
self._inchi_key = None
示例4: guess_bond_orders
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def guess_bond_orders(mol):
"""Use OpenBabel to guess bond orders using geometry and functional group templates.
Args:
mol (moldesign.Molecule): Molecule to perceive the bonds of
Returns:
moldesign.Molecule: New molecule with assigned bonds
"""
# TODO: pH, formal charges
pbmol = mol_to_pybel(mol)
pbmol.OBMol.PerceiveBondOrders()
newmol = pybel_to_mol(pbmol)
return newmol
示例5: add_hydrogen
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def add_hydrogen(mol):
"""Add hydrogens to saturate atomic valences.
Args:
mol (moldesign.Molecule): Molecule to saturate
Returns:
moldesign.Molecule: New molecule with all valences saturated
"""
pbmol = mol_to_pybel(mol)
pbmol.OBMol.AddHydrogens()
newmol = pybel_to_mol(pbmol, reorder_atoms_by_residue=True)
mdt.helpers.assign_unique_hydrogen_names(newmol)
return newmol
示例6: to_mol2
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def to_mol2(infile,outfile):
conv = ob.OBConversion()
conv.SetInAndOutFormats("sdf","mol2")
mol = ob.OBMol()
conv.ReadFile(mol, infile)
conv.WriteFile(mol, outfile)
示例7: OBMol
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def OBMol(self):
if not self._OBMol and self._source:
self._OBMol = readstring(self._source['fmt'],
self._source['string'],
opt=self._source['opt'] if 'opt' in self._source else {}).OBMol
self._source = None
return self._OBMol
示例8: atoms
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def atoms(self):
return AtomStack(self.OBMol)
示例9: bonds
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def bonds(self):
return BondStack(self.OBMol)
# cache frequently used properties and cache them in prefixed [_] variables
示例10: addh
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def addh(self, only_polar=False):
"""Add hydrogens"""
if only_polar:
self.OBMol.AddPolarHydrogens()
else:
self.OBMol.AddHydrogens()
self._clear_cache()
示例11: make2D
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def make2D(self):
"""Generate 2D coordinates for molecule"""
pybel._operations['gen2D'].Do(self.OBMol)
self._clear_cache()
示例12: calccharges
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def calccharges(self, model='gasteiger'):
"""Calculate partial charges for a molecule. By default the Gasteiger
charge model is used.
Parameters
----------
model : str (default="gasteiger")
Method for generating partial charges. Supported models:
* gasteiger
* mmff94
* others supported by OpenBabel (`obabel -L charges`)
"""
if __version__ < '2.4.0': # TODO: Get rid of this block for new OB
if model in pybel._getpluginnames('charges'):
m = pybel._getplugins(ob.OBChargeModel.FindType, [model])[model]
if not m.ComputeCharges(self.OBMol):
raise Exception('Could not assigh partial charges for '
'molecule "%s"' % self.title)
else:
raise ValueError('Model "%s" is not supported in OpenBabel' %
model)
else:
super(Molecule, self).calccharges(model)
self._clear_cache()
# Custom ODDT properties #
示例13: clone
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def clone(self):
return Molecule(ob.OBMol(self.OBMol))
示例14: clone_coords
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def clone_coords(self, source):
self.OBMol.SetCoordinates(source.OBMol.GetCoordinates())
return self
示例15: __iter__
# 需要导入模块: import openbabel [as 别名]
# 或者: from openbabel import OBMol [as 别名]
def __iter__(self):
for i in range(self.OBMol.NumAtoms()):
yield Atom(self.OBMol.GetAtom(i + 1))