当前位置: 首页>>代码示例>>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;未经允许,请勿转载。