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


Python pybel.readstring方法代码示例

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


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

示例1: xyz_to_pybel_mol

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def xyz_to_pybel_mol(xyz):
    """
    Convert xyz into an Open Babel molecule object.

    Args:
        xyz (dict): ARC's xyz dictionary format.

    Returns:
        OBmol: An Open Babel molecule.
    """
    xyz = check_xyz_dict(xyz)
    try:
        pybel_mol = pybel.readstring('xyz', xyz_to_xyz_file_format(xyz))
    except (IOError, InputError):
        return None
    return pybel_mol 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:18,代码来源:converter.py

示例2: read_string

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [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

示例3: __init__

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [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

示例4: get_pmg_mol_from_smiles

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def get_pmg_mol_from_smiles(smiles: str) -> Molecule:
    """
    Get a pymatgen molecule from smiles representation
    Args:
        smiles: (str) smiles representation of molecule

    Returns:
        pymatgen Molecule
    """
    b_mol = pb.readstring('smi', smiles)  # noqa
    b_mol.make3D()
    b_mol = b_mol.OBMol
    sp = []
    coords = []
    for atom in ob.OBMolAtomIter(b_mol):
        sp.append(atom.GetAtomicNum())
        coords.append([atom.GetX(), atom.GetY(), atom.GetZ()])
    return Molecule(sp, coords) 
开发者ID:materialsvirtuallab,项目名称:megnet,代码行数:20,代码来源:molecule.py

示例5: calcfingerprint

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def calcfingerprint(mol, args):
    '''Return a list of the bits/cnts of the fingerprint of mol.
    Uses fingerprint settings from args which should have been the result
    of a parse of addfpargs'''
    if args.fp == 'rdkit':
        fp = Chem.RDKFingerprint(mol,fpSize=args.fpbits)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp.startswith('ecfp'):
        diameter = int(args.fp.replace('ecfp',''))
        r = diameter/2
        fp = Chem.GetMorganFingerprintAsBitVect(mol,r,nBits=args.fpbits)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp == 'maccs':
        fp = MACCSkeys.GenMACCSKeys(mol)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp == 'smarts':
        if args.smartsfile:
            smarts = args.smartsfile
            ret = [0]*len(smarts)
            for (i,smart) in enumerate(smarts):
                if mol.HasSubstructMatch(smart):
                    ret[i] = 1
            return ret
        else:
            sys.stderr.write("ERROR: Must provide SMARTS file with --smarts\n")
            sys.exit(-1)
    elif args.fp == 'fp2':
        smi = Chem.MolToSmiles(mol) 
        obmol = pybel.readstring('smi',smi)
        fp = obmol.calcfp(fptype='FP2')
        ret = [0]*1021 #FP2 are mod 1021
        for setbit in fp.bits:
            #but pybel makes the bits start at 1 for some reason
            assert(setbit>0)
            ret[setbit-1] = 1
            
        return ret
        
    else:
        return [] 
开发者ID:dkoes,项目名称:qsar-tools,代码行数:42,代码来源:outputfingerprints.py

示例6: to_pybel_mol

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def to_pybel_mol(self, from_coords=True):
        """
        Convert the graph to a Pybel molecule. Currently only supports
        creating the molecule from 3D coordinates.
        """
        if from_coords:
            xyz = self.to_xyz()
            try:
                mol = pybel.readstring('xyz', xyz)
            except IOError:
                return None
            return mol
        else:
            raise NotImplementedError('Can only create Pybel molecules from 3D structure') 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:16,代码来源:xyz_to_2d.py

示例7: _string_to_3d_mol

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def _string_to_3d_mol(s, fmt, name):
    import pybel as pb
    if name is None: name = s
    pbmol = pb.readstring(fmt, str(s))  # avoid passing unicode by casting to str
    pbmol.addh()
    pbmol.make3D()
    mol = pybel_to_mol(pbmol,
                       name=name,
                       primary_structure=False)
    mdt.helpers.atom_name_check(mol)
    return mol 
开发者ID:Autodesk,项目名称:molecular-design-toolkit,代码行数:13,代码来源:openbabel.py

示例8: OBMol

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

示例9: mol_from_smiles

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def mol_from_smiles(smiles: str):
    mol = pybel.readstring(format='smi', string=smiles)
    mol.make3D()
    return mol 
开发者ID:materialsvirtuallab,项目名称:megnet,代码行数:6,代码来源:molecule.py

示例10: _convert_mol

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def _convert_mol(mol: str, molecule_format: str, converter: MolecularGraph) -> Dict:
    """Convert a molecule from string to its graph features

    Utility function used in the graph generator.

    The parse and convert operations are both in this function due to Pybel objects
    not being serializable. By not using the Pybel representation of each molecule
    as an input to this function, we can use multiprocessing to parallelize conversion
    over molecules as strings can be passed as pickle objects to the worker threads but
    but Pybel objects cannot.

    Args:
        mol (str): String representation of a molecule
        molecule_format (str): Format of the string representation
        converter (MolecularGraph): Tool used to generate graph representation
    Returns:
        (dict): Graph representation of the molecule
    """

    # Convert molecule into pybel format
    if molecule_format == 'smiles':
        mol = mol_from_smiles(mol)  # Used to generate 3D coordinates/H atoms
    else:
        mol = pybel.readstring(molecule_format, mol)

    return converter.convert(mol) 
开发者ID:materialsvirtuallab,项目名称:megnet,代码行数:28,代码来源:molecule.py

示例11: __file_reader

# 需要导入模块: import pybel [as 别名]
# 或者: from pybel import readstring [as 别名]
def __file_reader(self, filename):
        if self.reader == 'auto':
            # sys.path.insert(0, "/user/m27/pkg/openbabel/2.3.2/lib")
            import pybel
            # import openbabel
            mol = open(filename, 'r').read()
            mol = pybel.readstring("xyz", mol)
            molecule = [(a.OBAtom.GetAtomicNum(), a.OBAtom.x(), a.OBAtom.y(),
                         a.OBAtom.z()) for a in mol.atoms]
            return np.array(molecule)
        elif self.reader == 'manual':
            mol = open(filename, 'r').readlines()
            if len(mol) == 0:
                return np.array([])
            mol = mol[self.skip_lines[0]:len(mol) - self.skip_lines[1]]
            molecule = []
            for atom in mol:
                atom = atom.replace('\t', ' ')
                atom = atom.strip().split(' ')
                atom = list(filter(lambda x: x != '', atom))
                molecule.append([
                    self.Z[atom[0]],
                    float(atom[1]),
                    float(atom[2]),
                    float(atom[3])
                ])
            return np.array(molecule) 
开发者ID:hachmannlab,项目名称:chemml,代码行数:29,代码来源:initialization.py


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