当前位置: 首页>>代码示例>>Python>>正文


Python pybel.Molecule方法代码示例

本文整理汇总了Python中pybel.Molecule方法的典型用法代码示例。如果您正苦于以下问题:Python pybel.Molecule方法的具体用法?Python pybel.Molecule怎么用?Python pybel.Molecule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybel的用法示例。


在下文中一共展示了pybel.Molecule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: determine_rotors

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def determine_rotors(mol_list):
    """
    Determine possible unique rotors in the species to be treated as hindered rotors.

    Args:
        mol_list (list): Localized structures (Molecule objects) by which all rotors will be determined.

    Returns:
        list: A list of indices of scan pivots.
    Returns:
        list: A list of indices of top atoms (including one of the pivotal atoms) corresponding to the torsions.
    """
    torsions, tops = list(), list()
    for mol in mol_list:
        rotors = find_internal_rotors(mol)
        for new_rotor in rotors:
            for existing_torsion in torsions:
                if existing_torsion == new_rotor['scan']:
                    break
            else:
                torsions.append(new_rotor['scan'])
                tops.append(new_rotor['top'])
    return torsions, tops 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:25,代码来源:conformers.py

示例2: check_special_non_rotor_cases

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def check_special_non_rotor_cases(mol, top1, top2):
    """
    Check whether one of the tops correspond to a special case which does not have a torsional mode.
    Checking for ``R-[C,N]#[N,[CH],[C]]`` groups, such as: in cyano groups (`R-C#N``),
    C#C groups (``R-C#CH`` or ``R-C#[C]``), and azide groups: (``R-N#N``).

    Args:
        mol (Molecule): The RMG molecule.
        top1 (list): Entries are atom indices (1-indexed) on one side of the torsion, inc. one of the pivotal atoms.
        top2 (list): Entries are atom indices (1-indexed) on the other side of the torsion, inc. the other pivotal atom.

    Returns:
        bool: ``True`` if this is indeed a special case which should **not** be treated as a torsional mode.
    """
    for top in [top1, top2]:
        if mol.atoms[top[0] - 1].atomtype.label in ['Ct', 'N3t', 'N5tc'] \
                and mol.atoms[top[1] - 1].atomtype.label in ['Ct', 'N3t'] and \
                (len(top) == 2 or (len(top) == 3 and mol.atoms[top[2] - 1].is_hydrogen())):
            return True
    return False 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:22,代码来源:conformers.py

示例3: update_mol

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def update_mol(mol):
    """
    Update atom types, multiplicity, and atom charges in the molecule.

    Args:
        mol (Molecule): The molecule to update.

    Returns:
        Molecule: the updated molecule.
    """
    for atom in mol.atoms:
        atom.update_charge()
    mol.update_atomtypes(log_species=False, raise_exception=False)
    mol.update_multiplicity()
    mol.identify_ring_membership()
    return mol 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:18,代码来源:conformers.py

示例4: read_stream

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def read_stream(filelike, format, name=None):
    """ Read a molecule from a file-like object

    Note:
        Currently only reads the first conformation in a file

    Args:
        filelike: a file-like object to read a file from
        format (str): File format: pdb, sdf, mol2, bbll, etc.
        name (str): name to assign to molecule

    Returns:
        moldesign.Molecule: parsed result
    """
    molstring = str(filelike.read())  # openbabel chokes on unicode
    return read_string(molstring, format, name=name) 
开发者ID:Autodesk,项目名称:molecular-design-toolkit,代码行数:18,代码来源:openbabel.py

示例5: read_string

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def read_string(molstring, format, name=None):
    """ Read a molecule from a file-like object

    Note:
        Currently only reads the first conformation in a file

    Args:
        molstring (str): string containing file contents
        format (str): File format: pdb, sdf, mol2, bbll, etc.
        name (str): name to assign to molecule

    Returns:
        moldesign.Molecule: parsed result
    """
    import pybel as pb
    pbmol = pb.readstring(format, molstring)
    mol = pybel_to_mol(pbmol, name=name)
    return mol 
开发者ID:Autodesk,项目名称:molecular-design-toolkit,代码行数:20,代码来源:openbabel.py

示例6: write_string

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def write_string(mol, format):
    """ Create a file from the passed molecule

    Args:
        mol (moldesign.Molecule): molecule to write
        format (str): File format: pdb, sdf, mol2, bbll, etc.

    Returns:
        str: contents of the file

    References:
        https://openbabel.org/docs/dev/FileFormats/Overview.html
    """
    pbmol = mol_to_pybel(mol)
    if format == 'smi':  # TODO: always kekulize, never aromatic
        outstr = pbmol.write(format=format).strip()
    else:
        outstr = pbmol.write(format=format)
    return str(outstr) 
开发者ID:Autodesk,项目名称:molecular-design-toolkit,代码行数:21,代码来源:openbabel.py

示例7: _filereader_mol2

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def _filereader_mol2(filename, opt=None):
    block = ''
    data = ''
    n = 0
    with gzip.open(filename) if filename.split('.')[-1] == 'gz' else open(filename) as f:
        for line in f:
            if line[:1] == '#':
                data += line
            elif line[:17] == '@<TRIPOS>MOLECULE':
                if n > 0:  # skip `zero` molecule (any preciding comments and spaces)
                    yield Molecule(source={'fmt': 'mol2', 'string': block, 'opt': opt})
                n += 1
                block = data
                data = ''
            block += line
        # open last molecule
        if block:
            yield Molecule(source={'fmt': 'mol2', 'string': block, 'opt': opt}) 
开发者ID:oddt,项目名称:oddt,代码行数:20,代码来源:ob.py

示例8: __init__

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [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 
开发者ID:oddt,项目名称:oddt,代码行数:26,代码来源:ob.py

示例9: write

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def write(self, format="smi", filename=None, overwrite=False, opt=None, size=None):
        format = format.lower()
        size = size or (200, 200)
        if format == 'png':
            format = '_png2'
            opt = opt or {}
            opt['w'] = size[0]
            opt['h'] = size[1]
        # Use lazy molecule if possible
        if self._source and 'fmt' in self._source and self._source['fmt'] == format and self._source['string']:
            return self._source['string']
        # Workaround OB 2.3.2 + Py3 PNG encoding error
        elif format == '_png2' and filename is None and PY3 and __version__ < '2.4.0':
            with NamedTemporaryFile(suffix='.png') as f:
                super(Molecule, self).write(format=format, filename=f.name, overwrite=True, opt=opt)
                output = f.read()
            return output
        else:
            return super(Molecule, self).write(format=format, filename=filename, overwrite=overwrite, opt=opt)

    # Backport code implementing resudues (by me) to support older versions of OB (aka 'stable') 
开发者ID:oddt,项目名称:oddt,代码行数:23,代码来源:ob.py

示例10: create_bond_feature

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def create_bond_feature(self, mol, bid: int, eid: int):
        """
        Create information for a bond for a pair of atoms that are not actually bonded

        Args:
            mol (pybel.Molecule): Molecule being featurized
            bid (int): Index of atom beginning of the bond
            eid (int): Index of atom at the end of the bond
        """
        a1 = mol.OBMol.GetAtom(bid + 1)
        a2 = mol.OBMol.GetAtom(eid + 1)
        same_ring = mol.OBMol.AreInSameRing(a1, a2)
        return {"a_idx": bid,
                "b_idx": eid,
                "bond_type": 0,
                "same_ring": True if same_ring else False,
                "spatial_distance": a1.GetDistance(a2)} 
开发者ID:materialsvirtuallab,项目名称:megnet,代码行数:19,代码来源:molecule.py

示例11: _get_chiral_centers

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def _get_chiral_centers(self, mol):
        """
        Use RDKit to find the chiral centers with CIP(R/S) label

        This provides the absolute stereochemistry.  The chiral label obtained
        from pybabel and rdkit.mol.getchiraltag is relative positions of the bonds as provided

        Args:
            mol (Molecule): Molecule to asses
        Return:
            (dict): Keys are the atom index and values are the CIP label
        """
        mol_rdk = self._get_rdk_mol(mol, 'smiles')
        if mol_rdk is None:
            # Conversion to RDKit has failed
            return {}
        else:
            chiral_cc = Chem.FindMolChiralCenters(mol_rdk)
            return dict(chiral_cc) 
开发者ID:materialsvirtuallab,项目名称:megnet,代码行数:21,代码来源:molecule.py

示例12: test_hydrogens

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def test_hydrogens(caffeine_smiles, caffeine_canonical, caffeine_inchi):
    m = Molecule(caffeine_smiles, 'smiles')
    m.to_smiles()
    assert isinstance(m.rdkit_molecule, Chem.Mol)
    assert m.smiles == caffeine_canonical
    # add hydrogens
    m.hydrogens('add', explicitOnly=False)
    # canonical smiles with hydrogens
    m.to_smiles()
    assert m.smiles == "[H]c1nc2c(c(=O)n(C([H])([H])[H])c(=O)n2C([H])([H])[H])n1C([H])([H])[H]"
    # test inchi
    m = Molecule(caffeine_inchi, 'inchi')
    m.to_inchi()
    assert m.inchi == caffeine_inchi
    # add hydrogens
    m.hydrogens('add')
    m.to_inchi()
    assert m.inchi == caffeine_inchi 
开发者ID:hachmannlab,项目名称:chemml,代码行数:20,代码来源:test_Molecule.py

示例13: _get_atoms_per_type_str

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def _get_atoms_per_type_str(mol):
    '''
    Get a string representing the atomic composition of a molecule (i.e. the number
    of atoms per type in the molecule, e.g. H2C3O1, where the order of types is
    determined by increasing nuclear charge).

    Args:
        mol (utility_classes.Molecule or numpy.ndarray: the molecule (or an array of
            its atomic numbers)

    Returns:
        str: the atomic composition of the molecule
    '''
    if isinstance(mol, Molecule):
        n_atoms_per_type = mol.get_n_atoms_per_type()
    else:
        # assume atomic numbers were provided
        n_atoms_per_type = np.bincount(mol, minlength=10)[
            np.array(list(Molecule.type_infos.keys()), dtype=int)]
    s = ''
    for t, n in zip(Molecule.type_infos.keys(), n_atoms_per_type):
        s += f'{Molecule.type_infos[t]["name"]}{int(n):d}'
    return s 
开发者ID:atomistic-machine-learning,项目名称:G-SchNet,代码行数:25,代码来源:qm9_filter_generated.py

示例14: determine_smallest_atom_index_in_scan

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def determine_smallest_atom_index_in_scan(atom1: Atom,
                                          atom2: Atom,
                                          mol: Molecule,
                                          ) -> int:
    """
    Determine the smallest atom index in mol connected to ``atom1`` which is not ``atom2``.
    Returns a heavy atom if available, otherwise a hydrogen atom.
    Useful for deterministically determining the indices of four atom in a scan.
    This function assumes there ARE additional atoms connected to ``atom1``, and that ``atom2`` is not a hydrogen atom.

    Args:
        atom1 (Atom): The atom who's neighbors will be searched.
        atom2 (Atom): An atom connected to ``atom1`` to exclude (a pivotal atom).
        mol (Molecule): The molecule to process.

    Returns:
        int: The smallest atom index (1-indexed) connected to ``atom1`` which is not ``atom2``.
    """
    heavy_atoms, hydrogens = list(), list()
    for atom3 in atom1.edges.keys():
        if atom3.is_hydrogen():
            hydrogens.append(mol.vertices.index(atom3))
        elif atom3 is not atom2:
            heavy_atoms.append(mol.vertices.index(atom3))
    smallest_index = len(mol.vertices)
    if len(heavy_atoms):
        for atom_index in heavy_atoms:
            if atom_index < smallest_index:
                smallest_index = atom_index
    else:
        for atom_index in hydrogens:
            if atom_index < smallest_index:
                smallest_index = atom_index
    return smallest_index + 1 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:36,代码来源:conformers.py

示例15: to_group

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import Molecule [as 别名]
def to_group(mol, atom_indices):
    """
    This method converts a defined part of a Molecule into a Group.

    Args:
        mol (Molecule): The base molecule.
        atom_indices (list): 0-indexed atom indices corresponding to atoms in mol to be included in the group.

    Returns:
        Group: A group consisting of the desired atoms in mol.
    """
    # Create GroupAtom object for each atom in the molecule
    group_atoms = list()
    index_map = dict()  # keys are Molecule atom indices, values are Group atom indices
    for i, atom_index in enumerate(atom_indices):
        atom = mol.atoms[atom_index]
        group_atoms.append(gr.GroupAtom(atomtype=[atom.atomtype], radical_electrons=[atom.radical_electrons],
                                        charge=[atom.charge], lone_pairs=[atom.lone_pairs]))
        index_map[atom_index] = i
    group = gr.Group(atoms=group_atoms, multiplicity=[mol.multiplicity])
    for atom in mol.atoms:
        # Create a GroupBond for each bond between desired atoms in the molecule
        if mol.atoms.index(atom) in atom_indices:
            for bonded_atom, bond in atom.edges.items():
                if mol.atoms.index(bonded_atom) in atom_indices:
                    group.add_bond(gr.GroupBond(atom1=group_atoms[index_map[mol.atoms.index(atom)]],
                                                atom2=group_atoms[index_map[mol.atoms.index(bonded_atom)]],
                                                order=[bond.order]))
    group.update()
    return group 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:32,代码来源:conformers.py


注:本文中的pybel.Molecule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。