Ejemplo n.º 1
0
 def collect_1(self, checkboard = []):
     def getChains(s):
         ret = s.split('___')[:2]
         assert(len(ret) == 2)
         return ret
     parser = PDBParser()
     io = PDBIO()
     for f in self.files:
         if not checkboard:
             break
         if f not in checkboard:
             continue
         try:
             os.mkdir(os.path.join( self.outpath, f))
         except OSError as e:
             if e.errno != errno.EEXIST:
                 raise
         structure = parser.get_structure(f, os.path.join(self.inpath, f))
         chain_A, chain_B = getChains(f)
         io.set_structure(structure[0]['A'])
         io.save(os.path.join(self.outpath,f,chain_A + '.pdb'))
         io.set_structure(structure[0]['B'])
         io.save(os.path.join(self.outpath,f,chain_B + '.pdb'))
         #make this module can be reuse to other application
         self.then_do(f)
         #remove the finished file from checkboard
         checkboard.remove(f)
Ejemplo n.º 2
0
    def __init__(self, structure_file, file_type=None):
        PDBIO.__init__(self)

        dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
            structure_file)
        self.structure_file = structure_file

        # Unzip the file if it is zipped
        if file_type == '.gz':
            unzipped = ssbio.utils.gunzip_file(structure_file, outdir=dirname)
            dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
                unzipped)

        if not file_type:
            file_type = file_type2
        else:
            if '.' not in file_type:
                file_type = '.{}'.format(file_type)

        if file_type in ['.pdb', '.ent', '.mmcif', '.cif', '.mmtf']:
            # Load the structure
            if file_type.lower() == '.pdb' or file_type.lower() == '.ent':
                structure = pdbp.get_structure(id='ssbio_pdb',
                                               file=structure_file)
            if file_type.lower() == '.mmcif' or file_type.lower() == '.cif':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = cifp.get_structure(structure_id='ssbio_cif',
                                                   filename=structure_file)
            if file_type.lower() == '.mmtf':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = mmtfp.get_structure(file_path=structure_file)
            log.debug('{}: parsed 3D coordinates of structure'.format(
                op.basename(structure_file)))
        else:
            raise ValueError('{}: unsupported file type'.format(file_type))

        # If there are multiple models (NMR), use the first model as the representative structure
        # if len(structure) > 1:
        #     self.first_model = structure[0]
        #     structure = structure[0]
        #     self.set_structure(structure)
        #     log.debug('{}: using first model'.format(structure_file))
        # elif len(structure) == 0:
        #     log.error('{}: no models in structure!'.format(structure_file))
        # else:
        self.set_structure(structure)
        self.first_model = structure[0]
Ejemplo n.º 3
0
    def internal_water_coordinates(self, file, get_normalized=False):
        io = PDBIO()
        parser = PDBParser(QUIET=True)

        code = file[0:4]
        struct = parser.get_structure(code, file)

        plane = list(struct[0][' '].get_residues())
        up_plane = plane[1]['O'].get_coord()[2]
        down_plane = plane[0]['N'].get_coord()[2]

        if len(list(list(struct[0])[0].get_residues())) > 100:
            chain = list(struct[0])[0]
        else:
            chain = list(struct[0])[1]

        chain_id = chain.get_id()
        waters = water_in_chain(file, chain_id)
        internal_waters = [
            water for water in waters if water['O'].get_coord()[2] < up_plane
            and water['O'].get_coord()[2] > down_plane
        ]

        internal_water_coords = [
            water['O'].get_coord() for water in internal_waters
        ]

        if get_normalized:
            norm_coords = internal_water_coords / up_plane
            return norm_coords

        else:
            return internal_water_coords
Ejemplo n.º 4
0
    def __init__(self, structure_file, file_type=None):
        PDBIO.__init__(self)

        dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
            structure_file)
        self.structure_file = structure_file

        # Unzip the file if it is zipped
        if file_type == '.gz':
            unzipped = ssbio.utils.gunzip_file(structure_file, outdir=dirname)
            dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
                unzipped)

        if not file_type:
            file_type = file_type2
        else:
            if '.' not in file_type:
                file_type = '.{}'.format(file_type)

        if file_type.lower() in ['.pdb', '.ent', '.mmcif', '.cif', '.mmtf']:
            # Load the structure
            if file_type.lower() == '.pdb' or file_type.lower() == '.ent':
                structure = pdbp.get_structure(id='ssbio_pdb',
                                               file=structure_file)
            if file_type.lower() == '.mmcif' or file_type.lower() == '.cif':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = cifp.get_structure(structure_id='ssbio_cif',
                                                   filename=structure_file)
            if file_type.lower() == '.mmtf':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = mmtfp.get_structure(file_path=structure_file)
            log.debug('{}: parsed 3D coordinates of structure'.format(
                op.basename(structure_file)))
        else:
            raise ValueError('{}: unsupported file type'.format(file_type))

        self.set_structure(structure)
        try:
            self.first_model = structure[0]
        except KeyError:
            raise KeyError(
                '{}: no models contained in structure! Please check structure file contents.'
                .format(structure_file))
Ejemplo n.º 5
0
 def has_correct_dum_in_pdb(self, file_path):
     io = PDBIO()
     parser = PDBParser(QUIET=True)
     code = file_path[-8:-4]
     struct = parser.get_structure(code, file_path)
     try:
         list(struct[0][' '].get_residues())
     except KeyError:
         print('Error in file:', file_path)
Ejemplo n.º 6
0
 def collect_0(self):
     def getChains(s):
         ret = s.split('___')[:2]
         assert(len(ret) == 2)
         return ret
     parser = PDBParser()
     io = PDBIO()
     for f in self.files:
         try:
             os.mkdir(os.path.join( self.outpath, f))
         except OSError as e:
             if e.errno != errno.EEXIST:
                 raise
         structure = parser.get_structure(f, os.path.join(self.inpath, f))
         chain_A, chain_B = getChains(f)
         io.set_structure(structure[0]['A'])
         io.save(os.path.join(self.outpath,f,chain_A + '.pdb'))
         io.set_structure(structure[0]['B'])
         io.save(os.path.join(self.outpath,f,chain_B + '.pdb'))
         self.then_do(f)
Ejemplo n.º 7
0
def write_pdb(structure,
              file_name,
              selector=None,
              preserve_atom_numbering=False):
    """ Write a PDB file from a given structure with a given file_name. Optionally, write specific atoms with selector and preserve atom numbering. """
    writer = PDBIO()
    writer.set_structure(structure)
    if selector is None:
        writer.save(file_name, preserve_atom_numbering=preserve_atom_numbering)
    else:
        writer.save(file_name,
                    selector,
                    preserve_atom_numbering=preserve_atom_numbering)
    def save_structure(self, output_pdb_path: str, mod_id: str = None):
        """
        Saves structure on disk in PDB format

        Args:
            output_pdb_path: OS path to the output file
            mod_id (optional): model to write

        Errors:
            OSError: Error saving the file
        """
        if not output_pdb_path:
            raise OutputPathNotProvidedError
        pdbio = PDBIO()

        if mod_id is None:
            pdbio.set_structure(self.st)
            pdbio.save(output_pdb_path)
        else:
            pdbio.set_structure(self.st[mod_id])
            pdbio.save(output_pdb_path)
 def CreatePDB(self, coordArray, fPath, ofile):
     sloppyparser = PDBParser(PERMISSIVE=True, QUIET=True)
     structure = sloppyparser.get_structure("MD_system", fPath)
     print("\nGenerating PDB file...")
     sb = StructureBuilder()
     sb.set_header(structure.header)
     # Iterate through models
     for i in range(len(list(structure.get_models()))):
         # Iterate through chains
         models = list(structure.get_models())
         counter = 0
         for j in range(len(list(models[i].get_chains()))):
             chains = list(models[i].get_chains())
             #Iterate thgouth residues
             for k in range(len(list(chains[j].get_residues()))):
                 #Iterate through
                 residues = list(chains[j].get_residues())
                 for l in range(len(list(residues[k].get_atoms()))):
                     #Set coord for each
                     for atom in structure[i][chains[j].id][
                             residues[k].id].get_atoms():
                         structure[i][chains[j].id][residues[k].id][
                             atom.id].set_coord(
                                 np.array((float(coordArray[counter][0]),
                                           float(coordArray[counter][1]),
                                           float(coordArray[counter][2]))))
                         #print(structure[i][chains[j].id][residues[k].id][atom.id].get_vector())
                     counter += 1
     io = PDBIO()
     io.set_structure(structure)
     io.save(ofile)
     print("Transform file written to: " + ofile)
Ejemplo n.º 10
0
def write_PDB(entity: Structure,
              file: str,
              pdbid: str = None,
              chainid: str = None) -> None:
    """Write PDB file with HEADER and TITLE."""
    enumerate_atoms(entity)
    with as_handle(file, "w") as fp:
        try:
            if "S" == entity.level:
                if hasattr(entity, "header"):
                    if not pdbid:
                        pdbid = entity.header.get("idcode", None)
                    hdr = entity.header.get("head", None)
                    dd = pdb_date(entity.header.get("deposition_date", None))

                    if hdr:
                        fp.write(("HEADER    {:40}{:8}   {:4}\n").format(
                            hdr.upper(), (dd or ""), (pdbid or "")))
                    nam = entity.header.get("name", None)
                    if nam:
                        fp.write("TITLE     " + nam.upper() + "\n")
                io = PDBIO()
                io.set_structure(entity)
                io.save(fp, preserve_atom_numbering=True)

            else:
                raise PDBException("level not 'S': " + str(entity.level))
        except KeyError:
            raise Exception(
                "write_PIC: argument is not a Biopython PDB Entity " +
                str(entity))
Ejemplo n.º 11
0
    def cut_7_helix(self, source_pdb, target_folder, offset=0):
        io = PDBIO()
        parser = PDBParser(QUIET=True)

        code = source_pdb[-8:-4]
        struct = parser.get_structure(code, source_pdb)

        plane = list(struct[0][' '].get_residues())

        try:
            up_plane = plane[1]['O'].get_coord()[2] + offset
        except KeyError:
            up_plane = plane[0]['O'].get_coord()[2] + offset

        try:
            down_plane = plane[0]['N'].get_coord()[2] - offset
        except KeyError:
            down_plane = plane[1]['N'].get_coord()[2] - offset

        chain_id = self.get_TM_chain(list(struct[0]), up_plane, down_plane)
        chain = struct[0][chain_id]

        io.set_structure(struct)
        io.save(target_folder + code + '_tm.pdb',
                self.TMSelect(up_plane, down_plane, chain))
Ejemplo n.º 12
0
 def scwrl(self, altseq):
     """ Repacks sidechains using SCWRL4 and returns a copy """
     io = PDBIO()
     seqfname = "temp/%d.txt" % multidigit_rand(10)
     with open(seqfname, 'wb') as seqfile:
         structfile = "temp/%d.pdb" % multidigit_rand(10)
         seqfile.write(altseq)
         scwrlfile = structfile + ".scwrl"
         io.set_structure(self.structure)
         io.save(structfile)
     cmd = [
         "scwrl", "-0", "-i", structfile, '-s', seqfname, '-o', scwrlfile
     ]
     print "\n%s" % ' '.join(cmd)
     sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE).communicate()
     p = PDBParser()
     with open(scwrlfile, 'rb') as fin:
         filterwarnings('ignore', category=PDBConstructionWarning)
         s = p.get_structure(self.id, scwrlfile)
         resetwarnings()
     s = PDBMapStructure(s, pdb2pose={}, refseq=self.refseq)
     os.remove(structfile)
     os.remove(scwrlfile)
     os.remove(seqfname)
     return s
Ejemplo n.º 13
0
    def test_pdbio_write_pqr_structure(self):
        """Write a full structure using PDBIO."""
        # Create a PDBIO object in pqr mode with example_structure as an argument
        io = PDBIO(is_pqr=True)
        io.set_structure(self.example_structure)

        # Write to a temporary file
        filenumber, filename = tempfile.mkstemp()
        os.close(filenumber)
        try:
            # Export example_structure to a temp file
            io.save(filename)

            # Parse exported structure
            output_struct = self.pqr_parser.get_structure("1a8o", filename)

            # Comparisons
            self.assertEqual(len(output_struct),
                             len(self.example_structure))  # Structure Length

            original_residues = len(list(
                self.example_structure.get_residues()))
            parsed_residues = len(list(output_struct.get_residues()))
            self.assertEqual(parsed_residues,
                             original_residues)  # Number of Residues

            # Atom-wise comparison
            original_atoms = self.example_structure.get_atoms()
            for atom in output_struct.get_atoms():
                self.assertEqual(atom, next(original_atoms))

        finally:
            os.remove(filename)
Ejemplo n.º 14
0
def main(pdbfile, scheme, outfile):
    pdb_io = PDBIO()
    parser = PDBParser()
    structure = parser.get_structure('self', pdbfile)
    model = structure[0]
    chain = ' '
    anarci_dict = {}
    fastafile = Path(pdbfile).stem + '.fasta'
    with open(fastafile, 'w+') as ff:
        subprocess.run(['pdb_tofasta', '-multi', pdbfile], stdout=ff)
    out = subprocess.run(['anarci', '-i', fastafile, '--scheme', scheme],
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    output = out.stdout.decode("utf-8").splitlines()
    for line in output:
        l = line.strip()
        li = line.split()
        if line.startswith('#'):
            if re.search("PDB", l):
                ch = l.split('|')
                chain = ch[1]
                anarci_dict[chain] = []
        elif line.startswith(chain):
            if len(li) == 3:
                if li[2] == '-':
                    continue
                else:
                    ch = li[0]
                    resseq = int(li[1])
                    inscode = ' '
                    residue = li[2]
                    het = ' '
                    tuple = (het, resseq, inscode)
                    anarci_dict[chain].append(tuple)
            elif len(li) == 4:
                ch = li[0]
                resseq = int(li[1])
                inscode = str(li[2])
                residue = li[3]
                het = ' '
                tuple = (het, resseq, inscode)
                anarci_dict[chain].append(tuple)
        else:
            continue

    for residue in structure.get_residues():
        residue.id = (' ', residue.id[1] + 900, residue.id[2])

    for d in anarci_dict:
        count = 0
        for i, residue in enumerate(model[d]):
            if i < len(anarci_dict[d]):
                residue.id = anarci_dict[d][i]
                count = residue.id[1]
            else:
                count = count + 1
                residue.id = (' ', count, ' ')

    pdb_io.set_structure(structure)
    pdb_io.save(outfile)
Ejemplo n.º 15
0
def write_PDB(entity, file, pdbid=None, chainid=None):
    """Write PDB file with HEADER and TITLE."""
    with as_handle(file, 'w') as fp:
        try:
            if 'S' == entity.level:
                if not pdbid:
                    pdbid = entity.header.get('idcode', None)
                hdr = entity.header.get('head', None)
                dd = entity.header.get('deposition_date', None)
                if hdr:
                    fp.write(('HEADER    {:40}{:8}   {:4}\n'
                              ).format(hdr.upper(), (dd or ''), (pdbid or '')))
                nam = entity.header.get('name', None)
                if nam:
                    fp.write('TITLE     ' + nam.upper() + '\n')
                io = PDBIO()
                io.set_structure(entity)
                io.save(fp)

            else:
                raise PDBException("level not 'S': "
                                   + str(entity.level))
        except KeyError:
            raise Exception(
                "write_PIC: argument is not a Biopython PDB Entity "
                + str(entity))
def run_naccess(model,
                pdb_file,
                probe_size=None,
                z_slice=None,
                naccess='naccess',
                temp_path='/tmp/'):

    # make temp directory;
    tmp_path = tempfile.mkdtemp(dir=temp_path)

    # file name must end with '.pdb' to work with NACCESS
    # -> create temp file of existing pdb
    #    or write model to temp file
    handle, tmp_pdb_file = tempfile.mkstemp('.pdb', dir=tmp_path)
    os.close(handle)
    if pdb_file:
        pdb_file = os.path.abspath(pdb_file)
        shutil.copy(pdb_file, tmp_pdb_file)
    else:
        writer = PDBIO()
        writer.set_structure(model.get_parent())
        writer.save(tmp_pdb_file)

    # chdir to temp directory, as NACCESS writes to current working directory
    old_dir = os.getcwd()
    os.chdir(tmp_path)

    # create the command line and run
    # catch standard out & err
    command = [naccess, tmp_pdb_file]
    if probe_size:
        command.extend(['-p', probe_size])
    if z_slice:
        command.extend(['-z', z_slice])

    p = subprocess.Popen(command,
                         universal_newlines=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    out, err = p.communicate()
    os.chdir(old_dir)

    rsa_file = tmp_pdb_file[:-4] + '.rsa'
    asa_file = tmp_pdb_file[:-4] + '.asa'
    # Alert user for errors
    if err.strip():
        warnings.warn(err)

    if (not os.path.exists(rsa_file)) or (not os.path.exists(asa_file)):
        raise Exception('NACCESS did not execute or finish properly.')

    # get the output, then delete the temp directory
    with open(rsa_file) as rf:
        rsa_data = rf.readlines()
    with open(asa_file) as af:
        asa_data = af.readlines()

    # shutil.rmtree(tmp_path, ignore_errors=True)
    return rsa_data, asa_data
Ejemplo n.º 17
0
def writeFileBioPDB(struct,fn):
	io = PDBIO()
	io.set_structure(struct)
	try:	
		io.save(fn)
	except Exception, e:
		print " "+str(e)
		sys.exit(1)
Ejemplo n.º 18
0
def save_chain_to(chain, filename: str):
    from Bio.PDB.PDBIO import PDBIO
    io = PDBIO()
    # io.set_structure(chain.get_bio_chain())
    structure = Structure(filename)
    structure.add(chain)
    io.set_structure(structure)
    io.save(filename)
Ejemplo n.º 19
0
def extract(structure, chain_id, start, end, filename):
    """
    Write out selected portion to filename.
    """
    sel = ChainSelector(chain_id, start, end)
    io = PDBIO()
    io.set_structure(structure)
    io.save(filename, sel)
Ejemplo n.º 20
0
def filter_pdb(input_path, output_path, chain):
    """
    Filter a PDB file to the chain of interest
    """
    pdb_name = Path(input_path).stem
    pdb_parser = PDBParser()
    structure = pdb_parser.get_structure(pdb_name, input_path)
    pdbio = PDBIO()
    pdbio.set_structure(structure)
    pdbio.save(output_path, select=ChainSelect(chain))
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
    def remove_residues(self, request, claims):
        """
        Remove residues from a PDB structure

        For a detailed input description see the file:
           mdstudio_structures/schemas/endpoints/removed_residues_request_v1.json
        And for a detailed description of the output see:
           mdstudio_structures/schemas/endpoints/removed_residues_response_v1.json
        """
        request['workdir'] = os.path.abspath(request['workdir'])
        # Parse the structure
        parser = PDBParser(PERMISSIVE=True)
        struc_obj = StringIO(request.get('mol'))

        structure = parser.get_structure('mol_object', struc_obj)
        struc_obj.close()

        to_remove = [r.upper() for r in request.get('residues', [])]
        removed = []
        for model in structure:
            for chain in model:
                for residue in chain:
                    if residue.get_resname() in to_remove:
                        chain.detach_child(residue.id)
                        removed.append(residue.get_resname())
                if len(chain) == 0:
                    model.detach_child(chain.id)
        self.log.info('Removed residues: {0}'.format(','.join(removed)))

        # Save to file or string
        pdbio = PDBIO()
        pdbio.set_structure(structure)

        status = 'completed'
        if request.get('workdir'):
            result = os.path.join(request.get('workdir'), 'structure.pdb')
            pdbio.save(result)
        else:
            outfile = StringIO()
            pdbio.save(outfile)
            outfile.seek(0)
            result = outfile.read()

        return {'status': status, 'mol': result}
Ejemplo n.º 23
0
 def pose(self):
   """ Loads the PDBMapStructure as a Rosetta::Pose object """
   import_rosetta()
   io = PDBIO()
   io.set_structure(self.structure)
   with tempfile.NamedTemporaryFile('wrb',suffix='.pdb',delete=False) as tf:
     io.save(tf.name)
   pose = rosetta.Pose()
   rosetta.pose_from_pdb(pose,tf.name)
   os.remove(tf.name)
   return pose
Ejemplo n.º 24
0
def get_pdb_string(pdb_path, select=None):
    """
    Get string representation of a PDB file, filtered using select as in Bio.PDB.PDBIO
    """
    pdb_parser = PDBParser()
    structure = pdb_parser.get_structure('_', pdb_path)

    pdbio = PDBIO()
    pdbio.set_structure(structure)
    with StringIO('PDB') as virtual_pdb_file:
        pdbio.save(virtual_pdb_file, select=select)
        return virtual_pdb_file.getvalue()
Ejemplo n.º 25
0
def run_naccess(model,
                pdb_file,
                probe_size=None,
                z_slice=None,
                naccess='naccess',
                temp_path='/tmp/'):

    # make temp directory; chdir to temp directory,
    # as NACCESS writes to current working directory
    tmp_path = tempfile.mktemp(dir=temp_path)
    os.mkdir(tmp_path)
    old_dir = os.getcwd()
    os.chdir(tmp_path)

    # file name must end with '.pdb' to work with NACCESS
    # -> create temp file of existing pdb
    #    or write model to temp file
    tmp_pdb_file = tempfile.mktemp('.pdb', dir=tmp_path)
    if pdb_file:
        os.system('cp %s %s' % (pdb_file, tmp_pdb_file))
    else:
        writer = PDBIO()
        writer.set_structure(model.get_parent())
        writer.save(tmp_pdb_file)

    # create the command line and run
    # catch standard out & err
    command = '%s %s ' % (naccess, tmp_pdb_file)
    if probe_size:
        command += '-p %s ' % probe_size
    if z_slice:
        command += '-z %s ' % z_slice
    in_, out, err = os.popen3(command)
    in_.close()
    stdout = out.readlines()
    out.close()
    stderr = err.readlines()
    err.close()

    # get the output, then delete the temp directory
    rsa_file = tmp_pdb_file[:-4] + '.rsa'
    rf = open(rsa_file)
    rsa_data = rf.readlines()
    rf.close()
    asa_file = tmp_pdb_file[:-4] + '.asa'
    af = open(asa_file)
    asa_data = af.readlines()
    af.close()
    os.chdir(old_dir)
    os.system('rm -rf %s >& /dev/null' % tmp_path)
    return rsa_data, asa_data
Ejemplo n.º 26
0
def main():
    if len(sys.argv) < 2:
        print("Please input fasta filename as an argument for the script")
        sys.exit()

    filename = sys.argv[1]
    if filename.endswith('.fasta'):
        blast_result = blast_sequence(filename)
    else:
        print("Unknown file format (need to be fasta file)")
        sys.exit()

    pdb_filepath = download_pdb_support_sequence(blast_result)
    filter_pdb(pdb_filepath)
    p = PDBParser(PERMISSIVE=1)
    structure = p.get_structure('file', 'filtered.pdb')
    seqObj = generate_fasta_from_pdb(structure)
    target_seq = SeqIO.read(filename, format="fasta").seq
    alignments = pairwise_alignement(target_seq, seqObj.seq)

    #Consider CA atoms only for computing distances
    ca_atoms = [
        atom for model in structure for chain in model for residue in chain
        for atom in residue if atom.get_id() == "CA"
    ]

    gaps = insert_gaps_in_atomlist(ca_atoms, alignments[0][0])
    insertions = insert_gaps_in_atomlist(ca_atoms, alignments[0][1])

    print(gaps)
    print(insertions)

    print("Searching for best part for gaps")
    gap_parts = get_gaps_parts(gaps)
    print("Searching for best part for insertions")
    ins_parts = get_gaps_parts(
        insertions, get_insertion_type(alignments[0][0], alignments[0][1]))

    print("Completing gaps/insertions by found parts")
    complete_atoms = [
        atom for model in structure for chain in model for residue in chain
        for atom in residue
    ]
    complete_atoms = insert_gaps_insertions_in_atomlist(
        complete_atoms, ins_parts, gap_parts)

    print("Writing final pdb file in : final.pdb")
    io = PDBIO()
    io.set_structure(build_structure(complete_atoms))
    io.save('final.pdb')
Ejemplo n.º 27
0
def generate_output_file(final_model, out_name):
    """ This function takes as input both the final model created with the building algorithm and the output filename given by the user (if not defined, is macrocomplex by default). Eventually, it returns the file saved in either ".pdb" or ".mmcif" format. """
    out_name = str(out_name.strip())
    # If the output file is too big, we save it in ".mmcif" format
    if len(list(final_model[0].get_atoms())) > 99999 or len(
            list(final_model[0].get_chains())) > 62:
        mmcif_IO = MMCIFIO()
        mmcif_IO.set_structure(final_model[0])
        mmcif_IO.save(out_name + ".cif")
    # Otherwise, save it ".pdb" format
    else:
        pdb_IO = PDBIO()
        pdb_IO.set_structure(final_model[0])
        pdb_IO.save(out_name + ".pdb")
Ejemplo n.º 28
0
 def clean(self):
   p  = PDBParser()
   io = PDBIO()
   with tempfile.NamedTemporaryFile('wrb',suffix='.pdb',delete=False) as tf:
     io.set_structure(self.structure)
     io.save(tf.name)
   cmd  = ['lib/clean_pdb.py',tf.name,'ignorechain','nopdbout']
   logger.info("Shell to: %s"%' '.join(cmd))
   proc = sp.Popen(cmd,stdout=sp.PIPE)
   s = p.get_structure(self.get_id(),proc.stdout)
   p = lib.PDBMapIO.PDBMapParser()
   s = p.process_structure(s,force=True)
   s = PDBMapStructure(s,pdb2pose=self._pdb2pose,refseq=self.refseq)
   os.remove(tf.name)
   return s
Ejemplo n.º 29
0
def main(args):
    """Main script"""
    pdb_name = Path(args.pdb).stem
    # deal with FoldX repaired PDBs
    if pdb_name.endswith('_Repair'):
        pdb_name = pdb_name.replace('_Repair', '')

    pdb_parser = PDBParser()
    structure = pdb_parser.get_structure(pdb_name, args.pdb)

    sections = import_sections(args.yaml, pdb_name)

    pdbio = PDBIO()
    pdbio.set_structure(structure)
    pdbio.save(sys.stdout, select=SectionSelecter(sections))
Ejemplo n.º 30
0
def func1():
    import sys
    import re
    import gzip
    from Bio.PDB.MMCIFParser import MMCIFParser
    parser = MMCIFParser(QUIET=True)
    from Bio.PDB.PDBParser import PDBParser
    parser1 = PDBParser(PERMISSIVE=0, QUIET=True)

    from Bio.PDB.PDBIO import PDBIO

    #pathmmcif = "/Users/tarun/Documents/mmCIF"
    #pathmmcif = "/data/pdb/divided/mmCIF"
    pathmmcif = "/Volumes/BIOINFO/mmCIF"
    #pathmmcif = "/Volumes/RCSB_DATA/pdb"

    #count = 0
    #if count == 0:
    try:
        pdb1 = "{}".format(sys.argv[2])
        fol = pdb1[1:3]
        c1 = "{}".format(sys.argv[3])
        pdbfile = "{}/{}/{}.cif.gz".format(pathmmcif, fol, pdb1)
        #pdbfile = "{}/{}/pdb{}.ent.gz".format(pathmmcif,fol,pdb1)
        tar = gzip.open("{}".format(pdbfile), "rb")
        out = open("pdbprocess.cif", "wb")
        #out = open("pdbprocess.pdb","wb")
        out.write(tar.read())
        tar.close()
        out.close()
        structure_id = "{}".format(pdb1)
        filename = "pdbprocess.cif"
        #filename = "pdbprocess.pdb"
        structure = parser.get_structure(structure_id, filename)
        model = structure[0]
        chain = model["{}".format(c1)]

        io = PDBIO()
        io.set_structure(chain)
        io.save("chain1.pdb")
    except:
        print("FILE NOT FOUND")