當前位置: 首頁>>代碼示例>>Python>>正文


Python openbabel.OBConversion方法代碼示例

本文整理匯總了Python中openbabel.OBConversion方法的典型用法代碼示例。如果您正苦於以下問題:Python openbabel.OBConversion方法的具體用法?Python openbabel.OBConversion怎麽用?Python openbabel.OBConversion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在openbabel的用法示例。


在下文中一共展示了openbabel.OBConversion方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _crd2mul

# 需要導入模塊: import openbabel [as 別名]
# 或者: from openbabel import OBConversion [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 
開發者ID:deepmodeling,項目名稱:dpgen,代碼行數:18,代碼來源:gaussian.py

示例2: to_mol2

# 需要導入模塊: import openbabel [as 別名]
# 或者: from openbabel import OBConversion [as 別名]
def to_mol2(infile,outfile):
    conv = ob.OBConversion()
    conv.SetInAndOutFormats("sdf","mol2")
    mol = ob.OBMol()
    conv.ReadFile(mol, infile)
    conv.WriteFile(mol, outfile) 
開發者ID:ericchansen,項目名稱:q2mm,代碼行數:8,代碼來源:sdf_to_mae.py

示例3: openbabel_force_field_on_rdkit_conformers

# 需要導入模塊: import openbabel [as 別名]
# 或者: from openbabel import OBConversion [as 別名]
def openbabel_force_field_on_rdkit_conformers(label, rd_mol, force_field='MMFF94s', optimize=True):
    """
    Optimize RDKit conformers by OpenBabel using a force field (MMFF94 or MMFF94s are recommended).
    This is a fall back method when RDKit fails to generate force field optimized conformers.

    Args:
        label (str): The species' label.
        rd_mol (RDKit RDMol): The RDKit molecule with embedded conformers to optimize.
        force_field (str, optional): The type of force field to use.
        optimize (bool, optional): Whether to first optimize the conformer using FF. True to optimize.

    Returns:
        list: Entries are optimized xyz's in a dictionary format.
    Returns:
        list: Entries are float numbers representing the energies (in kJ/mol).
    """
    xyzs, energies = list(), list()
    # Set up Openbabel input and output format
    obconversion = ob.OBConversion()
    obconversion.SetInAndOutFormats('xyz', 'xyz')
    # Set up Openbabel force field
    ff = ob.OBForceField.FindForceField(force_field)
    symbols = [rd_atom.GetSymbol() for rd_atom in rd_mol.GetAtoms()]
    for i in range(rd_mol.GetNumConformers()):
        # Convert RDKit conformer to xyz string
        conf = rd_mol.GetConformer(i)
        xyz_str = f'{conf.GetNumAtoms()}\n\n'
        for j in range(conf.GetNumAtoms()):
            xyz_str += symbols[j] + '      '
            pt = conf.GetAtomPosition(j)
            xyz_str += '   '.join([str(pt.x), str(pt.y), str(pt.z)]) + '\n'
        # Build OpenBabel molecule from xyz string
        ob_mol = ob.OBMol()
        obconversion.ReadString(ob_mol, xyz_str)
        ff.Setup(ob_mol)
        # Optimize the molecule if needed
        if optimize:
            ff.ConjugateGradients(2000)
        # Export xyzs and energies
        ob_mol.GetCoordinates()
        ff.GetCoordinates(ob_mol)
        energies.append(ff.Energy())
        xyz_str = '\n'.join(obconversion.WriteString(ob_mol).splitlines()[2:])
        xyzs.append(converter.str_to_xyz(xyz_str))
    return xyzs, energies 
開發者ID:ReactionMechanismGenerator,項目名稱:ARC,代碼行數:47,代碼來源:conformers.py


注:本文中的openbabel.OBConversion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。