Exemple #1
0
def Create_Example(pdb_file, folder):
    """Parse pdb files into files containing individual pairwise interactions
    Input:
    -pdb_file = target pdb file
    -folder = target folder housing the output
    Output:
    -folder containing the parsed files containing individual pairwise interactions
    """

    pdb_parser = pdb.PDBParser(PERMISSIVE=s.options.strict, QUIET=True)
    file_name = os.path.basename(pdb_file)
    s.Check_folder(folder)
    output_folder = os.path.join(folder, file_name[:-4])
    s.Check_folder(output_folder)
    pdb_structure = pdb_parser.get_structure(file_name, pdb_file)
    s.argprint("File have been parsed.", s.options.verbose, s.options.quiet, 1)
    chain_names = []
    for model in pdb_structure:
        empty_model = cp.deepcopy(pdb_structure[model.get_id()])
        for chain in model:
            id_name = chain.get_id()
            chain_names.append(id_name)
            empty_model.detach_child(id_name)

        for number in range(len(chain_names)):
            if number % 2 == 1 and number != 0:
                interaction = chain_names[number - 1] + chain_names[number]
                new_model = cp.deepcopy(empty_model)
                new_model.add(model[chain_names[number - 1]])
                new_model.add(model[chain_names[number]])
                io = pdb.PDBIO()
                io.set_structure(new_model)
                io.save(
                    os.path.join(output_folder,
                                 "%s_%s.pdb" % (file_name, interaction)))
                s.argprint("%s_%s.pdb created" % (file_name, interaction),
                           s.options.verbose, s.options.quiet, 2)
                try:
                    interaction = chain_names[number] + chain_names[number + 1]
                    new_model = cp.deepcopy(empty_model)
                    new_model.add(model[chain_names[number]])
                    new_model.add(model[chain_names[number + 1]])
                    io = pdb.PDBIO()
                    io.set_structure(new_model)
                    io.save(
                        os.path.join(output_folder,
                                     "%s_%s.pdb" % (file_name, interaction)))
                    s.argprint("%s_%s.pdb created" % (file_name, interaction),
                               s.options.verbose, s.options.quiet, 2)
                except:
                    s.argprint("Example complete!", s.options.verbose,
                               s.options.quiet, 0)
Exemple #2
0
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
Exemple #3
0
def save_results(out_models, output, directory, verbose):
    """Saves the resulting models into PDB files. Creates a specific directory for the model if it does not exist.
    Additionally, each chain receives a new ID in order to distinguish those chains that were equivalent.

    Keyword arguments:
    out_models -- list of the resulting model objects created by the program
    output -- name of the output model/file given by the user
    verbose -- boolean, prints to stderr the progress of the program"""
    u = 1
    if verbose:
        sys.stderr.write("Saving models...\n")
    io = PDB.PDBIO()
    if not os.path.exists(directory):
        os.makedirs(directory)
    for i in range(len(out_models)):
        id_list = []
        final_model = UpdModel(str(i))
        old_model = out_models[i]
        for chain in old_model.get_chains():
            new_chain = chain.copy()
            new_chain.id = new_id(id_list)
            id_list.append(new_chain.id)
            final_model.add(new_chain)
        io.set_structure(final_model)
        io.save(directory + "/" + output + "_" + str(u) + ".pdb")
        if verbose:
            sys.stderr.write("  " + output + "_" + str(u) + ".pdb saved\n")
        u += 1
Exemple #4
0
def write_model(coords, target_seq, filename):
    cc_model = new_cc(target_seq, coords)

    io = PDB.PDBIO()
    io.set_structure(cc_model)
    io.save(filename + ".pdb")
    return
Exemple #5
0
def capture_mutant_pdb(out_name, mutant, chain_letter):
    parser = PDB.PDBParser()
    structure = parser.get_structure('working_pdb', mutant)

    writer = PDB.PDBIO()
    writer.set_structure(structure)
    writer.save(out_name, select=SelectChains(chain_letter))
Exemple #6
0
def split_chain(pdb_filename, out_path, pdb_id, chain_letters):
    parser = PDB.PDBParser()
    writer = PDB.PDBIO()
    chain_letters = [chain.upper() for chain in chain_letters]
    struct = parser.get_structure (pdb_id, pdb_filename)
    writer.set_structure(struct)
    writer.save(out_path, select=SelectChains(chain_letters))
Exemple #7
0
def get_chain_length_and_position (pdb_filename, pdb_id):
    parser = PDB.PDBParser()
    writer = PDB.PDBIO()
    struct = parser.get_structure (pdb_id, pdb_filename)
    chain_dic = {}
    for model in struct:
        for chain in model:
            chain_id = chain.get_id()
            chain_lenth = len(chain)
            #if chain_id not in chain_dic:
            #    chain_dic[chain_id] = []
            #if chain_id in chain_dic:
            #    1/0
            chain_x_coord = 0
            chain_y_coord = 0
            chain_z_coord = 0
            total_number_of_atoms = 0
            for residue in chain:
                for atom in residue:
                    chain_x_coord += atom.get_coord()[0]      
                    chain_y_coord += atom.get_coord()[1]      
                    chain_z_coord += atom.get_coord()[2]      
                    total_number_of_atoms += 1
            average_x = chain_x_coord/(total_number_of_atoms)
            average_y = chain_y_coord/(total_number_of_atoms)
            average_z = chain_z_coord/(total_number_of_atoms)
            average_position = (average_x, average_y, average_z)
            chain_dic[chain_id] = [chain_lenth, average_position]
    return chain_dic
Exemple #8
0
 def __init__(self, out_dir=None):
     """ Create parsing and writing objects, specify output directory. """
     self.parser = PDB.PDBParser()
     self.writer = PDB.PDBIO()
     if out_dir is None:
         out_dir = os.path.join(os.getcwd(), "chain_PDBs")
     self.out_dir = out_dir
Exemple #9
0
def load_from_one_cath_pml_file(pml_file, scratch_path, superfamilies,
                                dssp_path):
    '''Load data from a .pml file of superposed
  homologous superfamilies from the CATH database.
  '''
    superfamilies.append([])
    candidate_proteins = []

    with open(pml_file, 'r') as f:
        while True:
            line = f.readline()
            if not line: break

            # Read one structure

            if line.strip().startswith('cmd.read_pdbstr'):
                pdb_lines = [line.strip()[19:].strip('\\')]
                pdb_id = ''

                while True:
                    line = f.readline()
                    if line.strip().startswith('"""'):
                        pdb_id = line.strip()[5:12]
                        break

                    pdb_line = line.strip().strip('\\')
                    if len(pdb_line) > 17:
                        pdb_line = pdb_line[0:16] + ' ' + pdb_line[
                            17:]  # Remove all altLoc flags

                    pdb_lines.append(pdb_line)  # Remove all altLoc flags

                # Make a pdb file of the structure for DSSP analysis

                structure = structure_from_pdb_string('\n'.join(pdb_lines),
                                                      pdb_id)

                # Store structures without chain breaks

                if len(topology.find_structure_chain_breaks(structure)) == 0:
                    structure_path = os.path.join(scratch_path,
                                                  pdb_id + '.pdb')

                    io = PDB.PDBIO()
                    io.set_structure(structure)
                    io.save(structure_path)

                    candidate_proteins.append({
                        'structure': structure,
                        'path': structure_path
                    })

    for p in candidate_proteins:
        try:
            find_secondary_structures(p, dssp_path)
        except:
            continue
        superfamilies[-1].append(
            p)  # Add a protein to a superfamily if there's no exception
def extract_chain(in_dir, filename, chain_of_int, out_dir):
    '''saves chain of interest as separate structure'''
    pdb_id = filename.split('.')[0]
    struct = PDB.PDBParser().get_structure(pdb_id, os.path.join(in_dir,
        filename))
    io = PDB.PDBIO()
    io.set_structure(struct[0][chain_of_int])
    io.save(os.path.join(out_dir, filename))
Exemple #11
0
 def __init__(self, crystal_file, ligand_name, pdbid):
     self._crystal = crystal_file
     self._ligand_name = ligand_name
     self._crystal_path = os.path.dirname(self._crystal)
     self._crystal_name = os.path.basename(self._crystal)
     parser = PDB.PDBParser()
     writer = PDB.PDBIO()
     self._biostruc = parser.get_structure (pdbid, crystal_file) 
Exemple #12
0
    def run_one(self, pdb_path, output_dir):

        # parse structure object (permissive flag but let's not lose any atoms by using a custom builder)
        parser = PDB.PDBParser(PERMISSIVE=1,
                               QUIET=True,
                               structure_builder=NonUniqueStructureBuilder())
        # only consider the first model in the pdb file
        structure = parser.get_structure('X', pdb_path)
        model = structure[0]

        ligand_paths = [None]
        if self.ligand_fname_pattern[0]:
            ligand_paths[0] = pdb_path.replace(self.ligand_fname_pattern[0],
                                               self.ligand_fname_pattern[1])
            ligand = parser.get_structure('L', ligand_paths[0])
            het_list = list(ligand.get_residues())
        else:
            # get het entries of interest (filter using static dictionaries)
            het_list = get_het_residues_from_pdb(
                model,
                remove_duplicates=False,
                min_lig_atoms=self.min_lig_atoms,
                allowed_names=self.allowed_lig_names)

        os.makedirs(output_dir, exist_ok=True)
        io = PDB.PDBIO()
        io.set_structure(model)
        name, ext = os.path.basename(pdb_path).split('.', 1)
        output_pockets = []

        for n, het in enumerate(het_list):
            if self.include_het_resname:
                site_name = "{0}_site_{1}_{2}.{3}".format(
                    name, n + 1, het.resname, ext)
            else:
                site_name = "{0}_site_{1}.{2}".format(name, n + 1, ext)
            fname = os.path.join(output_dir, site_name)
            output_pockets.append(fname)
            io.save(
                fname,
                NearLigandSelect(self.distance_threshold,
                                 het,
                                 keep_lig_in_site=False,
                                 keep_water=self.keep_water,
                                 keep_other_hets=self.keep_other_hets))
            if not self.ligand_fname_pattern[0]:
                if self.include_het_resname:
                    lig_name = "{0}_lig_{1}_{2}.{3}".format(
                        name, n + 1, het.resname, ext)
                else:
                    lig_name = "{0}_lig_{1}.{2}".format(name, n + 1, ext)
                io.save(os.path.join(output_dir, lig_name),
                        LigandOnlySelect(het))
                ligand_paths.append(os.path.join(output_dir, lig_name))

        if self.save_clean_structure:
            io.save(os.path.join(output_dir, '{}_clean.{}'.format(name, ext)),
                    ChainOnlySelect())
Exemple #13
0
def main():
    parser = argparse.ArgumentParser(description='Re-orders chains in the PDB \
                                     file based on the specified ordering')
    parser.add_argument('-p',
                        '--pdb',
                        action='store',
                        nargs=1,
                        dest='pdb',
                        help='PDB file with chains to be ordered')
    parser.add_argument('-r',
                        '--rank_order',
                        action='store',
                        nargs='*',
                        dest='order',
                        type=int,
                        help='Space separated rank \
                        order for chains. Top rank starts with 0 \
                        (instead of 1)')
    parser.add_argument('-i',
                        '--input_directory',
                        action='store',
                        nargs=1,
                        dest='input',
                        default=['./'],
                        help='Directory where \
                        input pdb files are stored')
    parser.add_argument('-o',
                        '--output_directory',
                        action='store',
                        nargs=1,
                        dest='output',
                        default=['./'],
                        help='Directory where \
                        output log should be written')
    args = vars(parser.parse_args())

    parser = PDB.PDBParser()
    structure = parser.get_structure('pdb',
                                     args['input'][0] + '/' + args['pdb'][0])

    chain_list = []
    for model in structure:
        for chain in model:
            chain_list.append(chain)

    for chain in chain_list:
        model.detach_child(chain.id)

    new_order = args['order']
    chain_list = [chain_list[i] for i in new_order]

    for idx, chain in enumerate(chain_list):
        model.insert(idx, chain)

    io = PDB.PDBIO()
    io.set_structure(structure)
    io.save(args['output'][0] + '/' + args['pdb'][0])
Exemple #14
0
def miscFixes(pdbfile):
    """Misc fixes to pdb"""
    parser = PDB.PDBParser(QUIET=True)
    structure = parser.get_structure(pdbfile, pdbfile)
    model = structure[0]
    chc = model['C']
    resetChainNumbering(chc)
    w = PDB.PDBIO()
    w.set_structure(structure)
    w.save(pdbfile)
    return
def get_chain_pdb(id, chain, cache):
    cache_path = './cache/data/' + id + chain + '.pdb'
    if os.path.isfile(cache_path):
        return cache_path
    if cache:
        print("CACHE MISS WHEN REQUIRED: ", id, chain)
    parser = PDB.PDBParser()
    writer = PDB.PDBIO()
    writer.set_structure(parser.get_structure(id, get_pdb(id, cache)))
    writer.save(cache_path, select=SelectChain(chain))
    return cache_path
Exemple #16
0
def insertPredsInBfactor(pdbFnameIn,
                         scoresFnameIn,
                         pdfFnameOut,
                         scale=False,
                         min_max_norm=False,
                         verbose=True):
    parser = PDBParser(QUIET=True)
    struct = parser.get_structure(os.path.basename(pdbFnameIn), pdbFnameIn)
    scores = pd.read_table(scoresFnameIn,
                           sep='\s+',
                           header='infer',
                           comment="#",
                           dtype={
                               "chainIdL": str,
                               "chainIdR": str,
                               "resIdL": str,
                               "resIdR": str,
                               "chainId": str,
                               "resId": str,
                               "resId": str
                           })

    if scale: scores["prediction"] = SCALING_RANGE * scores["prediction"]
    if min_max_norm:
        scores["prediction"] = (scores["prediction"] - np.min(
            scores["prediction"])) / (np.max(scores["prediction"]) -
                                      np.min(scores["prediction"]))

    scoresDict = {}
    for i in range(scores.shape[0]):
        scoresDict[(scores["chainId"][i],
                    scores["resId"][i])] = scores["prediction"][i]


#  print( sorted([ (key, scoresDict[key]) for key in scoresDict]))
    for chain in struct[0]:
        chainId = chain.get_id()
        if chainId == " ": chainId = UNKNOWN_CHAIN_SYMB
        for res in chain:
            resId = res.get_id()
            strResId = (str(resId[1]) + resId[2]).strip()
            if (chainId, strResId) in scoresDict:
                predVal = scoresDict[(chainId, strResId)]
            else:
                predVal = 0.0
            if verbose:
                print(chainId, strResId, (chainId, strResId) in scoresDict,
                      predVal)
            for atom in res:
                atom.set_bfactor(predVal)

    writer = PDB.PDBIO()
    writer.set_structure(struct)
    writer.save(pdfFnameOut)
def topology_backbone(topology_prefix):
    parser = PDBParser(PERMISSIVE=1)
    structure = parser.get_structure('topology', '%s.pdb' % topology_prefix)

    output = bpdb.PDBIO()
    output.set_structure(structure)
    output_filename = str(topology_prefix) + '_backbone.pdb'
    output.save('%s' % output_filename, Backboneselect())
    print("The backbone of selected topology file has been saved as %s" %
          output_filename)
    return output_filename
Exemple #18
0
    def protein_to_file(structure, fpath):
        """
        Writes a PDB to file.

        :param structure: a protein structure
        :param fpath: path for output pdb file
        :type structure: `Bio.PDB.Structure.Structure`
        :type fpath: str
        """
        io = PDB.PDBIO()
        io.set_structure(structure)
        io.save(fpath)
def normalize_pdb(inp_fn, out_fn, reverse=False, reverse_id=False, limit=None):
    """generate out_fn and returns array of tuples
       (old_chain,old_res_id), (new_chain, new_res_id)"""
    numbers = []

    parser = PDB.PDBParser()
    if re.match("^.*.gz",inp_fn):
        inp = gzip.open(inp_fn)
    else:
        inp = open(inp_fn)
    s = parser.get_structure("c",inp)
    inp.close()
    total = 0
    for model in list(s):
        n = len([r for r in model.get_residues()])
        for chain in list(model):
            for i, r in enumerate(list(chain)):
                total += 1
                if limit is not None and total>limit:
                    chain.detach_child(r.get_id())
                    continue
                old_id = r.get_id()
                old_num = (str(old_id[1])+str(old_id[2])).strip()
                old_chain = r.get_parent().get_id()
                if reverse_id:
                    new_num = n-i
                else:
                    new_num = i
                new_id = (old_id[0], new_num, ' ') # we ignore old_id[2]
                numbers.append(((old_chain, old_num), (old_chain, str(new_num))))
                # print old_id, new_id
                r.id = new_id
            if len(chain)==0:
                model.detach_child(chain.id)
        if len(model)==0:
            s.detach_child(model.id)
    if reverse:
        s = reverse_structure(s)
    if limit is not None:
        c = len(list(s.get_residues()))
        print("number of residues=%s" % c)
        assert c<=limit

    # from http://biopython.org/wiki/Remove_PDB_disordered_atoms
    class NotDisordered(PDB.Select):
        def accept_atom(self, atom):
            return not atom.is_disordered() or atom.get_altloc()=='A'

    io = PDB.PDBIO()
    io.set_structure(s)
    io.save(out_fn, select=NotDisordered())

    return numbers
Exemple #20
0
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)
Exemple #21
0
def preparePDB(pdbfile, start=3):
    """Prepare an MHC pdb for use in docking by removing unused atoms,
       combining A+B chains and renumbering chain C"""

    print pdbfile
    parser = PDB.PDBParser(QUIET=True)
    structure = parser.get_structure(pdbfile, pdbfile)
    model = structure[0]
    remove = string.uppercase[3:]
    for chain in model.child_list[:]:
        if chain.id in remove:
            model.detach_child(chain.id)
        else:
            for residue in chain.child_list[:]:
                #remove all non-standard residues
                if residue.id[0] != " ":
                    chain.detach_child(residue.id)

    removeresidues = [('A', range(86,200)), ('B', range(96,200))]
    for c in removeresidues:
        chain = model[c[0]]
        remove = c[1]
        for residue in chain.child_list[:]:
            id = residue.id
            if id[1] in remove:
                chain.detach_child(id)
    #renumber chain A
    chaina = model['A']
    renumberChain(chaina)
    #renumber chain B
    chainb = model['B']
    i = chaina.child_list[-1].id[1] + 1
    for residue in chainb:
        residue.id = (' ', i, ' ')
        i+=1
    chainb.id = 'A'
    #model.detach_child('B')
    #print '%s chains, length chain a=%s' %(len(model.child_list), len(chaina.child_list))
    #renumber chain c
    renumberChain(model['C'])
    w = PDB.PDBIO()
    w.set_structure(structure)
    name = os.path.splitext(pdbfile)[0]
    filename = name+'_alt.pdb'
    w.save(filename, write_end=1)
    #print 'saved file %s' %filename

    #save unbound
    model.detach_child('C')
    filename2 = name+'_unbound.pdb'
    w.save(filename2, write_end=1)
    return filename, filename2
Exemple #22
0
def superimpose(first, second):
    superimpose = PDB.Superimposer()
    superimpose.set_atoms(first, second)
    model = second_model
    superimpose.apply(model.get_atoms())
    print("The RMSD is: ")
    print(superimpose.rms)
    structure = second_structure
    io = PDB.PDBIO()
    io.set_structure(structure)
    saved_file = input("Name of output file (.pdb)?")
    io.save(saved_file)
    return saved_file 
def save_structure(structure, filename, quiet=False):
    """Write a PDB file from structure"""
    if not quiet:
        print_line = "Writing " + filename + "..."
        print(print_line, end="\r")
        longest_line_len = max(longest_line_len, len(print_line))
    io = PDB.PDBIO()
    io.set_structure(structure)
    io.save(filename)
    if not quiet:
        final_print_str = "Wrote " + filename + "."
        num_spaces = max(0, longest_line_len - len(final_print_str))
        print(final_print_str + " " * num_spaces)
def Read_PDB(filePtr):
    parser = PDB.PDBParser()
    io = PDB.PDBIO()
    struct = parser.get_structure('temp', filePtr)

    xyz = []
    for model in struct:
        for chain in model:
            for residue in chain:
                for atom in residue:
                    x, y, z = atom.get_coord()
                    xyz.append(np.array([x, y, z]))

    return np.asarray(xyz)
Exemple #25
0
def Separate_Chains(pdb_file):
    """Separate the two chains and return their name in a list
    Input: 
    -pdb file = target file 
    Output:
    -interaction = list with chain information
    """
    folder = "pdb_chains"

    if not Check_folder(folder):

        return False

    pdb_parser = pdb.PDBParser(PERMISSIVE=True, QUIET=True)

    pdb_structure = pdb_parser.get_structure("pdb_file", pdb_file)

    interaction = list(
        pdb_file[:-4].split("_")[-1]
    )  # Obtain 2 length lists with the chain names from file name, the order of the letters need match with the order in the pdb file(format= something_chains.pdb)

    if len(interaction) != 2:  #if the length is not true, something goes wrong

        print(settings.IncorrectName(interaction))

    for model in pdb_structure:
        for chain in model:

            id = chain.get_id()

            class chain(pdb.Select):
                def accept_chain(self, chain):
                    if chain.get_id() == id:
                        return True
                    else:
                        return False

            io = pdb.PDBIO()

            io.set_structure(pdb_structure)

            name = "%s_chain_%s.pdb" % (interaction[0] + interaction[1],
                                        interaction[i])

            file_name = os.path.join(folder, name)

            io.save(file_name, chain())

    return interaction
    def save_pdb(self, file_name):
        '''Save the sheet to a PDB file.'''
        c = PDB.Chain.Chain('A')
        for strand in self.strand_list:
            for r in strand.residue_list:
                c.add(r)

        m = PDB.Model.Model(0)
        m.add(c)
        s = PDB.Structure.Structure('s')
        s.add(m)

        io = PDB.PDBIO()
        io.set_structure(s)
        io.save(file_name)
 def PDBToNPY(self, fpathin):
     parser = PDB.PDBParser()
     io = PDB.PDBIO()
     struct = parser.get_structure('1ABZ', fpathin)
     allcoords1 = []
     for model in struct:
         for chain in model:
             for residue in chain:
                 for atom in residue:
                     x, y, z = atom.get_coord()
                     cSet = []
                     cSet.append(x)
                     cSet.append(y)
                     cSet.append(z)
                     allcoords1.append(cSet)
     return allcoords1
def get_cropped_pdb_subcluster(namechainres, length, is_pos, cluster,
                               subcluster, hetlist):
    name = (namechainres)[0:4]
    chain = (namechainres)[10:11]
    #print(namechainres)
    res = (namechainres)[12:15]
    resid = (namechainres)[15:]
    #print(type(resid))
    resid = int(resid)
    length = int(length)
    print(name + '_chain' + str(chain) + '_' + str(res) + str(resid) +
          '_cropped.pdb')

    hetlist_full = ast.literal_eval(hetlist)
    hetlist = []
    for subl in hetlist_full:
        hetlist.append(subl[1])

    os.chdir("C:/Users/Shaheer Rizwan/Documents/ramachandran/ids_xray")
    io = PDB.PDBIO()
    structure = PDBParser().get_structure(name, 'pdb' + name + ".ent")

    class HeterochiralSelect(Select):
        def accept_residue(self, residue):
            #print(residue.id)
            if ((residue.id[1] in range(resid, length + resid))
                    or residue.id[1] in hetlist):
                #print(residue['CA'].get_serial_number())
                return 1
            else:
                return 0

    io.set_structure(structure[0][chain])
    if not os.path.exists(
            "C:/Users/Shaheer Rizwan/Documents/ramachandran/cropped_pdb_subcluster_rev2/"
            + str(length) + str(is_pos) + str(cluster) + "_" +
            str(subcluster)):
        os.makedirs(
            "C:/Users/Shaheer Rizwan/Documents/ramachandran/cropped_pdb_subcluster_rev2/"
            + str(length) + str(is_pos) + str(cluster) + "_" + str(subcluster))
    os.chdir(
        "C:/Users/Shaheer Rizwan/Documents/ramachandran/cropped_pdb_subcluster_rev2/"
        + str(length) + str(is_pos) + str(cluster) + "_" + str(subcluster))
    io.save(
        name + '_chain' + str(chain) + '_' + str(res) + str(resid) +
        '_cropped.pdb', HeterochiralSelect())
Exemple #29
0
    def run_one(self, pdb_path, output_dir):

        # parse structure object (permissive flag but let's not lose any atoms by using a custom builder)
        parser = PDB.PDBParser(PERMISSIVE=1, QUIET=True, structure_builder=NonUniqueStructureBuilder())
        # only consider the first model in the pdb file
        structure = parser.get_structure('X', pdb_path)
        model = structure[0]

        # Get ligand (het) to extract the site around
        if self.ligand_fname_pattern[0]:
            ligand_path = pdb_path.replace(self.ligand_fname_pattern[0], self.ligand_fname_pattern[1])
            ligand = parser.get_structure('L', ligand_path)
            het_list = list(ligand.get_residues())
        else:
            # get het entries of interest (filter using static dictionaries)
            het_list = get_het_residues_from_pdb(model, remove_duplicates=False, min_lig_atoms=self.min_lig_atoms,
                                                 allowed_names=self.allowed_lig_names)

        # Setup a PDB writer and load protein
        io = PDB.PDBIO()
        io.set_structure(model)

        # create output directory and split input pdb_path
        os.makedirs(output_dir, exist_ok=True)
        name, ext = os.path.basename(pdb_path).rsplit('.', 1)

        for n, het in enumerate(het_list):

            # Set name of output site file
            if self.include_het_resname:
                site_name = f"{name}_site_{n+1}_{het.resname}.{ext}"
            else:
                site_name = f"{name}_site_{n+1}.{ext}"
            fname = os.path.join(output_dir, site_name)

            io.save(fname, NearLigandSelect(self.distance_threshold, het, keep_lig_in_site=False,
                                            keep_water=self.keep_water, keep_other_hets=self.keep_other_hets))
            if not self.ligand_fname_pattern[0]:
                if self.include_het_resname:
                    lig_name = f"{name}_lig_{n+1}_{het.resname}.{ext}"
                else:
                    lig_name = f"{name}_lig_{n+1}.{ext}"
                io.save(os.path.join(output_dir, lig_name), LigandOnlySelect(het))

        if self.save_clean_structure:
            io.save(os.path.join(output_dir, f'{name}_clean.{ext}'), ChainOnlySelect())
def topology_rmsfexclusion(topology_prefix, selection_residue, allatom):
    rmsf_topology_prefix = '%s_rmsf_contained' % topology_prefix
    parser = PDBParser(PERMISSIVE=1)
    structure = parser.get_structure('topology',
                                     '%s.pdb' % rmsf_topology_prefix)
    #if allatom:
    #    structure = parser.get_structure('topology', '%s_model.pdb' % topology_prefix)
    residues = structure.get_residues()

    output = bpdb.PDBIO()
    output.set_structure(structure)
    output.save('%s_rmsf_exclusion.pdb' % rmsf_topology_prefix,
                RMSFexclusion(selection_residue))
    #if allatom:
    #    output.save('%s_rmsf_exclusion_allatom.pdb' % rmsf_topology_prefix, RMSFexclusion(selection_residue))
    #else:
    #    output.save('%s_rmsf_exclusion.pdb' % rmsf_topology_prefix, RMSFexclusion(selection_residue))
    print("The pdb file with rmsf value and trimmed version has been saved")