예제 #1
0
파일: pdb.py 프로젝트: porteusconf/forgi
def output_multiple_chains(chains, filename, file_type="pdb"):
    '''
    Dump multiple chains to an output file. Remove the hydrogen atoms.

    :param chains: An iterable of Bio.PDB.Chain to dump.
    :param filename: The place to dump it.
    '''
    class HSelect(bpdb.Select):
        def accept_atom(self, atom):
            if atom.name.find('H') >= 0:
                return False
            else:
                return True
    m = bpdb.Model.Model(0)
    s = bpdb.Structure.Structure('stru')
    for chain in chains:
        log.debug("Adding chain %s with %s residues", chain.id, len(chain))
        m.add(chain)
        if file_type=="pdb" and len(chain.id)!=1:
            raise ValueError("Cannot save chain with name %s (not a single character) "
                             "in PDB format. Use cif format instead!")
    s.add(m)
    if file_type == "pdb":
        io = bpdb.PDBIO()
    else:
        io = bpdb.MMCIFIO()
    io.set_structure(s)
    try:
        io.save(filename, HSelect())
    except Exception as e:
        with log_to_exception(log, e):
            log.error("Could not output PDB with chains and residues:")
            for chain in s[0]:
                log.error("%s: %s", chain.id, [r.id for r in chain])
        raise
예제 #2
0
def split_chains(pdbid):

    if not os.path.isfile(pdbid):
        print("Error: Function split_chains: file does not exist:" + pdbid +
              "\n")
        return

    if '.gz' in pdbid:
        handle = gzip.open(pdbid, "rt")
        parser = PDB.MMCIFParser(QUIET=True)
        structure = parser.get_structure(pdbid[:-7], handle)
    else:
        handle = open(pdbid, "rt")
        parser = PDB.MMCIFParser(QUIET=True)
        structure = parser.get_structure(pdbid[:-4], handle)

    for model in structure:
        for chain in model:
            #io=PDB.PDBIO()      Section to output .pdb format
            #io.set_structure(chain)
            #chain_filename=(structure.id+chain.id+".pdb")             #Output in PDB format
            #io.save(chain_filename)
            #cmd=('gzip -f '+chain_filename)
            #subprocess.call(cmd, shell=True)

            io = PDB.MMCIFIO()
            io.set_structure(chain)
            chain_filename = (structure.id + chain.id + ".cif"
                              )  #Output in MMCIF format
            io.save(chain_filename)
            cmd = ('gzip -f ' + chain_filename)
            subprocess.call(cmd, shell=True)
예제 #3
0
def saving_file(id, struct):
    """
    saving the file in cif format
    :param id: the file's id
    :param struct: the structure we want to save
    """
    io = pdb.MMCIFIO()
    io.set_structure(struct)
    io.save("{0}.cif".format(id))
예제 #4
0
def export_structure(structure, name, format):
    """
    Writes the strucuture into a file. The file can be either a pdb or a mmcif.
    """
    if format == "pdb":
        io = PDBIO()
    elif format == "cif":
        io = pdb.MMCIFIO()
    io.set_structure(structure)
    io.save(name)
예제 #5
0
파일: utils.py 프로젝트: gabcg/SciPuzzle
def write_structure_into_file(structure, name, format):
    """
    Writes the strcuture into a file. The file can be either a pdb or a mmcif.
    Format needs to be either "pdb" or "mmcif" depending on the desired output
    file.
    """
    if format == "pdb":
        io = pdb.PDBIO()
    elif format == "mmcif":
        io = pdb.MMCIFIO()
    io.set_structure(structure)
    io.save(name)