當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。