Ejemplo n.º 1
0
def run_modeller(pir_alignment_file,
                 target_id,
                 template_id,
                 new_chains="ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
    """"""
    logger.debug("Calling modeller with parameters:\n" +
                 "pir_alignment_file: {}\n".format([pir_alignment_file]) +
                 "target_id: {}\n".format(target_id) +
                 "template_id: {}\n".format(template_id))
    modeller = call_modeller.Modeller([pir_alignment_file], target_id,
                                      template_id,
                                      conf.CONFIGS["unique_temp_dir"])

    with switch_paths(conf.CONFIGS["modeller_dir"]):
        norm_dope, pdb_filename = modeller.run()

    raw_model_file = op.join(conf.CONFIGS["modeller_dir"], pdb_filename)

    # If there is only one chain in the pdb, label that chain 'A'
    io = PDBIO()
    structure = structure_tools.get_pdb_structure(raw_model_file)
    chains = structure[0].child_list
    logger.debug("Modeller chain ids: " + ", ".join(chain.id
                                                    for chain in chains))
    for i in range(len(chains)):
        if chains[i].id != new_chains[i]:
            chains[i].id = new_chains[i]
    assert len(set(chain.id for chain in chains)) == len(chains)
    logger.debug("Corrected chain ids: " + ", ".join(chain.id
                                                     for chain in chains))
    io.set_structure(structure)
    model_file = op.splitext(pir_alignment_file)[0] + ".pdb"
    io.save(model_file)

    results = {
        "model_file":
        op.relpath(model_file, conf.CONFIGS["unique_temp_dir"]),
        "raw_model_file":
        op.relpath(raw_model_file, conf.CONFIGS["unique_temp_dir"]),
        "norm_dope":
        norm_dope,
        "pir_alignment_file":
        op.relpath(pir_alignment_file, conf.CONFIGS["unique_temp_dir"]),
    }
    return results
Ejemplo n.º 2
0
def renameChain():
	parser = PDBParser()
	nameStruct=pdb_name.partition('.')[0]
	structure = parser.get_structure(nameStruct, pdb_name)
	header = parser.get_header()
	trailer = parser.get_trailer()
	
	what_chain=raw_input('What is the chain you want to rename : ')
	what_chain2=raw_input('What is the new name of this chain : ')
	
	for model in structure:
		for chain in model:
			if chain.id == what_chain:
				chain.id = what_chain2
				
	w = PDBIO()
	w.set_structure(structure)
	w.save(nameStruct+'_rename.pdb')
Ejemplo n.º 3
0
    def write_helical_axes(self, filename):
        """Writes helical axes in PDB format."""

        sb = StructureBuilder()
        sb.init_structure('')
        sb.init_model('')

        for cpos, chain in enumerate(self.chains):
            sb.init_chain(str(cpos))
            sb.init_seg('')

            for pos, i in enumerate(chain.res[1:-1]):
                sb.init_residue('ALA', ' ', pos, ' ')
                sb.init_atom('CA', i.O._ar, 0, 0, " ", ' CA ', 1)

        io = PDBIO()
        io.set_structure(sb.structure)
        io.save(filename)
Ejemplo n.º 4
0
def removeHetero():# Remove all heteroatoms from a pdb and save the new structure in pdbname_noHetero.pdb
	parser = PDBParser()
	nameStruct=pdb_name.partition('.')[0]
	structure = parser.get_structure(nameStruct, pdb_name)
	header = parser.get_header()
	trailer = parser.get_trailer()
	for model in structure:
		for chain in model:
			for residue in chain:
				id = residue.id				
				if id[0] != ' ':
					chain.detach_child(residue.id)
			if len(chain) == 0:
				model.detach_child(chain.id)

	w = PDBIO()
	w.set_structure(structure)
	w.save(nameStruct+'_noHetero.pdb')
Ejemplo n.º 5
0
def modified_residues(structure):
    io = PDBIO()
    pdb_parser = PDBParser()
    new_structure = pdb_parser.get_structure(" ", structure)
    for i, residue in enumerate(new_structure.get_residues()):
        res_id = list(residue.id)
        if residue.get_resname() == "TPO":
            residue.resname = "THR"
        elif residue.get_resname() == "SEP":
            residue.resname = "SER"
        elif residue.get_resname() == "TYP":
            residue.resname = "TYR"
        elif residue.get_resname() == "HYP":
            residue.resname = "PRO"
        elif residue.get_resname() == "HID":
            residue.resname = "ALA"
    io.set_structure(new_structure)
    io.save(structure)
Ejemplo n.º 6
0
def save_microfold(microfold_name,all_neighbors):
    if not os.path.exists(microfold_root+microfold_dir):
        os.makedirs(microfold_root+microfold_dir)
    Select = Bio.PDB.Select
    class MicroSelect(Select):
        def accept_residue(self, residue):
            if residue in all_neighbors and residue.resname!='HOH':
                return 1
            else:
                return 0
    i=0
    for residue in all_neighbors:
        if residue.resname in AA:
            i=i+1
    if i>10:        
        io=PDBIO()
        io.set_structure(structure)
        io.save(microfold_root+microfold_dir+'/'+microfold_name+'.pdb', MicroSelect())
Ejemplo n.º 7
0
    def Write_PDB(self, initialPDB, Rotation, Translation, N):
        ''' Transform by rotating and translating the atom coordinates from the original PDB file and rewrite it '''
        from Bio.PDB.PDBParser import PDBParser
        from Bio.PDB import MMCIFParser, PDBIO
        Name = ntpath.basename(initialPDB).split('.')[0]

        try:
            parser = PDB.PDBParser()
            structure = parser.get_structure('%s' % (Name), initialPDB)
        except:
            parser = MMCIFParser()
            structure = parser.get_structure('%s' % (Name), initialPDB)

        for atom in structure.get_atoms():
            atom.transform(Rotation, Translation)
        io = PDBIO()
        io.set_structure(structure)
        io.save("{}_{}".format(N, ntpath.basename(initialPDB)))
Ejemplo n.º 8
0
def get_sequence(pdb, chain):
    pdb_parser = PDBParser(PERMISSIVE=0)                    # The PERMISSIVE instruction allows PDBs presenting errors.
    pdb_structure = pdb_parser.get_structure(pdb,pdb+".pdb")
    pdb_chain = pdb_structure[0][chain]
    i = 1
    lista=[]
    for residue in pdb_chain:
        if i < int(sys.argv[3]) or i > int(sys.argv[4]):
            lista.append(residue.get_id())
            #pdb_chain.detach_child(residue.get_id())
        i+=1
    for x in lista:
        pdb_chain.detach_child(x)

    io = PDBIO()
    io.set_structure(pdb_chain)
    output = sys.argv[5]+"_segment.pdb"
    io.save(output)
Ejemplo n.º 9
0
def prepare_virtual_sites(pdb_file, use_cis_proline=False):
    parser = PDBParser(QUIET=True)
    structure = parser.get_structure(
        'X',
        pdb_file,
    )
    for model in structure:
        for chain in model:
            r_im = {}
            r_i = {}
            for residue in chain:
                r_im = r_i
                r_i = {}
                for atom in residue:
                    r_i[atom.get_name()] = atom
                if use_cis_proline and residue.get_resname() == "IPR":
                    if 'N' in r_i:
                        r_i['N'].set_coord(-0.2094 * r_im['CA'].get_coord() +
                                           0.6908 * r_i['CA'].get_coord() +
                                           0.5190 * r_im['O'].get_coord())
                    if 'C' in r_im:
                        r_im['C'].set_coord(0.2196 * r_im['CA'].get_coord() +
                                            0.2300 * r_i['CA'].get_coord() +
                                            0.5507 * r_im['O'].get_coord())
                    if 'H' in r_i:
                        r_i['H'].set_coord(-0.9871 * r_im['CA'].get_coord() +
                                           0.9326 * r_i['CA'].get_coord() +
                                           1.0604 * r_im['O'].get_coord())
                else:
                    if 'N' in r_i:
                        r_i['N'].set_coord(0.48318 * r_im['CA'].get_coord() +
                                           0.70328 * r_i['CA'].get_coord() -
                                           0.18643 * r_im['O'].get_coord())
                    if 'C' in r_im:
                        r_im['C'].set_coord(0.44365 * r_im['CA'].get_coord() +
                                            0.23520 * r_i['CA'].get_coord() +
                                            0.32115 * r_im['O'].get_coord())
                    if 'H' in r_i:
                        r_i['H'].set_coord(0.84100 * r_im['CA'].get_coord() +
                                           0.89296 * r_i['CA'].get_coord() -
                                           0.73389 * r_im['O'].get_coord())
    io = PDBIO()
    io.set_structure(structure)
    io.save(pdb_file)
Ejemplo n.º 10
0
def save_output(final_complex):
    """
        If the output directory does not exists, create it. 
    """

    # Verbose
    if args.verbose:
        print("Writing the output...")

    subfolder_names = ["Structures", "Analysis"]

    # If the argument force is not selected create the output directory if it does not exists

    if not args.force:
        if not os.path.exists('FinalComplex'):
            try:
                for subfolder_name in subfolder_names:
                    os.makedirs(os.path.join('FinalComplex', subfolder_name))
            except OSError as err:
                raise err
        else:
            raise FolderAlreadyExists(os.path.join(os.getcwd(),
                                                   'FinalComplex'))

    # If the argument force is selected create the output directory if it does not exists and, if exists, override it
    elif args.force:
        if not os.path.exists('FinalComplex'):
            for subfolder_name in subfolder_names:
                os.makedirs(os.path.join('FinalComplex', subfolder_name))
        else:
            #Remove the directory
            shutil.rmtree('FinalComplex')
            for subfolder_name in subfolder_names:
                os.makedirs(os.path.join('FinalComplex', subfolder_name))

    io = PDBIO()
    io.set_structure(final_complex[0])

    if args.outfile:
        file_name = args.outfile

    # set for outputing the reconstructed complex in Structure folder
    output = f"FinalComplex/Structures/{file_name}.pdb"
    io.save(output)
Ejemplo n.º 11
0
def rewrite_pdb(pdb, CA_coords, new_name):
    parser = set_parser(pdb)
    protein = parser.get_structure(pdb[:4], pdb)

    i = 0
    for a in protein.get_atoms():
        if is_ca(a):
            try:
                a.set_coord([round(c, DIG) for c in CA_coords[i]])
                i = i + 1
            except IndexError:
                raise Exception('Unequal number of C-alpha atoms.')

    if i != len(CA_coords):
        raise Exception('Unequal number of C-alpha atoms.')

    io = PDBIO()
    io.set_structure(protein)
    io.save(new_name)
Ejemplo n.º 12
0
    def _smcra_to_str(self, smcra, temp_dir='/tmp/'):
        """
        WHATIF's input are PDB format files.
        Converts a SMCRA object to a PDB formatted string.
        """

        temp_path = tempfile.mktemp('.pdb', dir=temp_dir)

        io = PDBIO()
        io.set_structure(smcra)
        io.save(temp_path)

        f = open(temp_path, 'r')
        string = f.read()
        f.close()

        os.remove(temp_path)

        return string
Ejemplo n.º 13
0
def deleteResidue():# Delete a residue from a pdb and save the new structure in pdbname_noResidue.pdb
	parser = PDBParser()
	nameStruct=pdb_name.partition('.')[0]
	structure = parser.get_structure(nameStruct, pdb_name)
	header = parser.get_header()
	trailer = parser.get_trailer()

	rm_residue=raw_input('What residue you want to delete : ')
	for model in structure:
		for chain in model:
			for residue in chain:
				print residue.id
				if(residue.id[1]==rm_residue):
					print 'HELLO'
					chain.detach_child(residue.id)

	w = PDBIO()
	w.set_structure(structure)
	w.save(nameStruct+'_noResidue.pdb')
Ejemplo n.º 14
0
def download_and_get_chains():
    from Bio.PDB import PDBParser, PDBIO
    failed = []
    pdbs_dict = read_rostdb_entries()
    io = PDBIO()
    pdbl = PDBList()
    for pdb_e, chains in pdbs_dict.items():
        for chain_e in chains:
            try:
                pdbl.retrieve_pdb_file(pdb_e, pdir='./')
                pdb = PDBParser().get_structure(pdb_e,
                                                'pdb' + pdb_e.lower() + '.ent')
                for chain in pdb.get_chains():
                    if chain.get_id() == chain_e:
                        io.set_structure(chain)
                        io.save(pdb.get_id() + '_' + chain.get_id() + '.pdb')
            except:
                failed.append((pdb_e, chain_e))
    print("failures:", failed)
Ejemplo n.º 15
0
def get_sequence(pdb, chain):
        pdb_parser = PDBParser(PERMISSIVE=0)                    # The PERMISSIVE instruction allows PDBs presenting errors.
        pdb_structure = pdb_parser.get_structure(pdb,pdb)

	pdb_chain = pdb_structure[0][chain]
	ppb=PPBuilder()
	Sequence = ""
	for pp in ppb.build_peptides(pdb_chain):
		Sequence = Sequence + pp.get_sequence()

	io = PDBIO()
	io.set_structure(pdb_structure)
	output = pdb[-8:-4] +"_"+chain+".pdb"
#        output = pdb
	out = open(output[:-4]+chain+".fasta.txt","w")
	out.write(">"+pdb[:-4]+chain+"\n")
	out.write(str(Sequence)+"\n")
	out.close()
	io.save(output,SelectChains(chain))
Ejemplo n.º 16
0
def PDBparser(pdbdir, MDL=0, write=0, outpath=None):
    import warnings
    from Bio.PDB import PDBIO, Select
    from Bio import BiopythonWarning
    from Bio.PDB.PDBParser import PDBParser
    warnings.simplefilter('ignore', BiopythonWarning)
    pdbid = pdbdir.split('/')[-1][0:4]
    parser = PDBParser(PERMISSIVE=1)
    structure = parser.get_structure(pdbid, pdbdir)
    model = structure[MDL]
    if write == 1:
        if outpath == None:
            raise RuntimeError('out path is None!')

        class ModelSelect(Select):
            def accept_model(self, model):
                if model.get_id() == 0:
                    return True
                else:
                    return False

            def accept_chain(self, chain):
                """Overload this to reject chains for output."""
                return 1

            def accept_residue(self, residue):
                if residue.get_resname() in aa_123dict.values():
                    return True
                else:
                    return False

            def accept_atom(self, atom):
                """Overload this to reject atoms for output."""
                return 1

        io = PDBIO()
        io.set_structure(structure)
        io.save('%s/%s.pdb' % (outpath, pdbid),
                ModelSelect(),
                preserve_atom_numbering=True)
        # structure_new = parser.get_structure('mdl0', '%s/%s.pdb' % (outpath,pdbid))
        # model = structure_new[MDL]
    return model
Ejemplo n.º 17
0
    def save_pdb(self, complex_id, temp = "", name = ""):
        """
        gets coordinates of all complex components and writes them in one
        file one component = one pdb model
        
        Parameters:
        ------------
            complex_id  : number of complex from simulation
        Returns:
        --------
            pdb files with simulated components in OUTFOLDER
        """
        ##add component chain by chain not residue by residue.
        model_num = 0
        score = round(self.simulation_score, 4)
        s = Structure(complex_id) 
        my_model = Model(0)
        s.add(my_model)
        
        for component in self.components:
#@TODO: #what if more chains in one component?
            my_model.add(component.pyrystruct.struct[0][component.pyrystruct.chain])
        out = PDBIO()
        out.set_structure(s)
        outname = outfolder.outdirname.split("/")[-1]

        temp = str(temp)

        try:
            temp = round(float(temp),1)
        except: pass

        if name:
            fi_name = str(outfolder.outdirname)+'/'+name+'_'+str(score)+'_'+str(complex_id)+"_"+str(temp)+'.pdb'
            out.save(fi_name)
        else:
            fi_name = str(outfolder.outdirname)+'/'+str(outname)+"_"+str(score)+'_'+str(complex_id)+"_"+str(temp)+'.pdb'          
            out.save(fi_name)

        for comp in self.components:
            comp.pyrystruct.struct[0][comp.pyrystruct.chain].detach_parent()

        return fi_name
Ejemplo n.º 18
0
    def save(self, outfile=None, bfactor_key=None):
        from Bio.PDB import PDBIO
        __io = PDBIO()
        # write structure to file
        if outfile is None:
            outfile = self.name + ".pdb"

        if bfactor_key is not None:
            for atom in self.get_atoms():
                if bfactor_key in atom.xtra:
                    atom.bfactor = atom.xtra[bfactor_key]
                else:
                    atom.bfactor = 0.0

        logging.debug("Saving pdb file: %s", outfile)
        __io.set_structure(self.structure)
        __io.save(outfile)

        return outfile
Ejemplo n.º 19
0
def extract_binding_pocket(ligand, pdb):
    from Bio.PDB import PDBParser, PDBIO
    from Bio.PDB.PDBIO import Select
    import os
    import numpy as np
    from rdkit import Chem
    from scipy.spatial import distance_matrix

    parser = PDBParser()
    if not os.path.exists(pdb):
        #print ("AAAAAAAAAAA")
        return None
    structure = parser.get_structure("protein", pdb)
    #print (count_residue(structure))
    ligand_positions = ligand.GetConformer().GetPositions()

    class GlySelect(Select):
        def accept_residue(self, residue):
            residue_positions = np.array([np.array(list(atom.get_vector())) \
                for atom in residue.get_atoms() if "H" not in atom.get_id()])
            #print (residue_positions)
            min_dis = np.min(
                distance_matrix(residue_positions, ligand_positions))
            if min_dis < 5.0:
                return 1
            else:
                return 0

    io = PDBIO()
    io.set_structure(structure)

    np.random.seed()
    fn = "/tmp/BS_tmp_" + str(np.random.randint(0, 100000, 1)[0]) + ".pdb"
    #fd, fpath = tempfile.mkstemp(prefix="BS_tmp", dir=os.getcwd(), text=True)
    io.save(fn, GlySelect())
    #structure = parser.get_structure("protein", fn)
    #if count_residue(structure)<10: return None
    #print (count_residue(structure))
    m2 = Chem.MolFromPDBFile(fn)
    #os.unlink(fpath)
    os.system("rm -f " + fn)

    return m2
Ejemplo n.º 20
0
    def test_pdbio_missing_occupancy(self):
        """Write PDB file with missing occupancy"""

        from Bio import BiopythonWarning
        warnings.simplefilter('ignore', BiopythonWarning)

        io = PDBIO()
        structure = self.parser.get_structure("test", "PDB/occupancy.pdb")
        io.set_structure(structure)
        filenumber, filename = tempfile.mkstemp()
        os.close(filenumber)
        try:
            io.save(filename)
            struct2 = self.parser.get_structure("test", filename)
            atoms = struct2[0]['A'][(' ', 152, ' ')]
            self.assertEqual(atoms['N'].get_occupancy(), None)
        finally:
            os.remove(filename)
            warnings.filters.pop()
Ejemplo n.º 21
0
def retrieve_pdb_chain(pdbdir, MDL=0, chain_name='A', write=0, outpath=None):
    warnings.simplefilter('ignore', BiopythonWarning)
    pdbid = pdbdir.split('/')[-1][0:4]
    parser = PDBParser(PERMISSIVE=1)
    structure = parser.get_structure(pdbid, pdbdir)
    model = structure[MDL]
    if write == 1:
        if outpath == None:
            raise RuntimeError('out path is None!')
        os.makedirs(outpath, exist_ok=True)

        class ModelSelect(Select):
            def accept_model(self, model):
                if model.get_id() == 0:
                    return True
                else:
                    return False

            def accept_chain(self, chain):
                """Overload this to reject chains for output."""
                if chain.get_id() == chain_name:
                    return True
                else:
                    return False

            def accept_residue(self, residue):
                if residue.get_id()[0] == ' ':
                    return True
                else:
                    return False

            def accept_atom(self, atom):
                """Overload this to reject atoms for output."""
                return 1

        io = PDBIO()
        io.set_structure(structure)
        io.save('%s/%s.pdb' % (outpath, pdbid),
                ModelSelect(),
                preserve_atom_numbering=True)
    return model
Ejemplo n.º 22
0
def build_complex(file_1, file_2):
    """
    This function takes the complex output file (or in the first iteration one of the pairwise interactions)
    and another pairwise interaction PDB complex. Then it tries to add the chain to the complex until there is not clash

    @ Input - Two file path for a PDB interactions.
    @ Output - File path of the complex PDB file / Error: Chain cannot be added.
    """

    parser = PDBParser(PERMISSIVE=1)

    structure_1 = parser.get_structure('Complex', file_1)
    structure_2 = parser.get_structure('Complex', file_2)

    sup = Superimposer()
    io = PDBIO()

    atoms_fixed, atoms_moving = Compute_equal_chain(structure_1, structure_2)

    try:
        sup.set_atoms(atoms_fixed, atoms_moving)
    except:
        return False

    sup.apply(list(structure_2.get_atoms()))

    for chain in structure_2[0].get_chains():
        if chain.id != list(atoms_moving)[0].get_full_id()[2]:
            moved_chain = chain

    if check_clash(structure_1, moved_chain):
        with open(file_1, "wt") as out_file:

            for model in list(structure_1.get_chains()) + [moved_chain]:
                io.set_structure(model)
                io.save(out_file)

        rename_complex_chains(file_1)

        return True
    return False
Ejemplo n.º 23
0
 def test_model_numbering(self):
     """Preserve model serial numbers during I/O."""
     def confirm_numbering(struct):
         self.assertEqual(len(struct), 20)
         for idx, model in enumerate(struct):
             self.assertTrue(model.serial_num, idx + 1)
             self.assertTrue(model.serial_num, model.id + 1)
     parser = PDBParser()
     struct1 = parser.get_structure("1mot", "PDB/1MOT.pdb")
     confirm_numbering(struct1)
     # Round trip: serialize and parse again
     io = PDBIO()
     io.set_structure(struct1)
     filenumber, filename = tempfile.mkstemp()
     os.close(filenumber)
     try:
         io.save(filename)
         struct2 = parser.get_structure("1mot", filename)
         confirm_numbering(struct2)
     finally:
         os.remove(filename)
Ejemplo n.º 24
0
def structure_filtered_dca_truncate_pdb(pdb_id,
                                        chain_id,
                                        start,
                                        end,
                                        pdb_directory=os.path.join(
                                            ".", "pdbs")):

    from Bio.PDB import PDBIO

    io = PDBIO()

    structure = structure_filtered_dca_parse_pdb(pdb_id)

    structure_selector = structure_filtered_dca_pfam_is_in_structure_selection(
        chain_id, start, end)

    io.set_structure(structure)

    io.save(os.path.join(pdb_directory,
                         "%s%s_%d-%d.pdb" % (pdb_id, chain_id, start, end)),
            select=structure_selector)
Ejemplo n.º 25
0
def split_pdb_by_chain(pdb_id):
    if not os.path.isdir("pdb_chains/" + pdb_id.upper()):
        os.mkdir("pdb_chains/" + pdb_id.upper())
    actual_pdbfile = PDBParser().get_structure(
        pdb_id, "ent_files/pdb" + pdb_id.lower() + ".ent")
    return_dict = dict()
    for model in actual_pdbfile:
        for chain in model:
            outfilename = pdb_id.upper() + "-" + str(
                model.get_id() + 1) + "_" + str(chain.get_id()) + ".pdb"
            if not os.path.isfile("pdb_chains/" + pdb_id.upper() + "/" +
                                  outfilename):
                io = PDBIO()
                io.set_structure(chain)
                io.save("pdb_chains/" + pdb_id.upper() + "/" + outfilename)
            ppb = PPBuilder().build_peptides(chain)
            this_seq = Seq("", generic_protein)
            for pp in ppb:
                this_seq += pp.get_sequence()
            return_dict[outfilename] = this_seq
    return return_dict
Ejemplo n.º 26
0
def assembleChain(): # Allow to assemble 2 chains together
	parser = PDBParser()
	nameStruct=pdb_name.partition('.')[0]
	structure = parser.get_structure(nameStruct, pdb_name)
	header = parser.get_header()
	trailer = parser.get_trailer()

	what_chain=raw_input('What is the 1st chain you want to assemble : ')
	what_chain2=raw_input('What is the 2nd chain you want to assemble : ')

	for model in structure:
		for chain in model:
			if chain.id == what_chain:
				parent=chain;
			elif chain.id == what_chain2:
				for residue in chain:
					residue.get_parent().id=what_chain

	w = PDBIO()
	w.set_structure(structure)
	w.save(nameStruct+'_assemble.pdb')
Ejemplo n.º 27
0
def get_sequence(pdb, chain, first, last, output):
    pdb_parser = PDBParser(PERMISSIVE=0)                    # The PERMISSIVE instruction allows PDBs presenting errors.
    pdb_structure = pdb_parser.get_structure(pdb,pdb)

    pdb_chain = pdb_structure[0][chain]
    ppb=PPBuilder()
    Sequence = ""
    for pp in ppb.build_peptides(pdb_chain):
        Sequence = Sequence + pp.get_sequence()

    io = PDBIO()
    io.set_structure(pdb_structure)
#        if pdb[-5] == chain:
#            output = pdb
#        else:
#            output = pdb[:-4]+chain+".pdb"
### writing out sequence to fasta
#    out = open(output[:-4]+".fasta.txt","w")
#    out.write(">"+output[:-4]+"\n")
#        out.write(str(Sequence[first-1: last-2])+"\n")
#        out.close()
    io.save(output,SelectDomain(chain, first, last))
Ejemplo n.º 28
0
    def create_structure(coords, pdb_type, remove_masked):
        """Create the structure.

        Args:
            coords: 3D coordinates of structure
            pdb_type: predict or actual structure
            remove_masked: whether to include masked atoms. If false,
                           the masked atoms have coordinates of [0,0,0].

        Returns:
            structure
        """

        name = protein.id_
        structure = Structure(name)
        model = Model(0)
        chain = Chain('A')
        for i, residue in enumerate(protein.primary):
            residue = AA_LETTERS[residue]
            if int(protein.mask[i]) == 1 or remove_masked == False:
                new_residue = Residue((' ', i + 1, ' '), residue, '    ')
                j = 3 * i
                atom_list = ['N', 'CA', 'CB']
                for k, atom in enumerate(atom_list):
                    new_atom = Atom(name=atom,
                                    coord=coords[j + k, :],
                                    bfactor=0,
                                    occupancy=1,
                                    altloc=' ',
                                    fullname=" {} ".format(atom),
                                    serial_number=0)
                    new_residue.add(new_atom)
                chain.add(new_residue)
        model.add(chain)
        structure.add(model)
        io = PDBIO()
        io.set_structure(structure)
        io.save(save_dir + name + '_' + pdb_type + '.pdb')
        return structure
Ejemplo n.º 29
0
    def test_pdbio_write_custom_residue(self):
        """Write a chainless residue using PDBIO"""
        io = PDBIO()

        res = Residue.Residue((' ', 1, ' '), 'DUM', '')
        atm = Atom.Atom('CA', [0.1, 0.1, 0.1], 1.0, 1.0, ' ', 'CA', 1, 'C')
        res.add(atm)
        
        # Write full model to temp file
        io.set_structure(res)
        filenumber, filename = tempfile.mkstemp()
        os.close(filenumber)
        try:
            io.save(filename)
            struct2 = self.parser.get_structure("res", filename)
            latoms = list(struct2.get_atoms())
            self.assertEqual(len(latoms), 1)
            self.assertEqual(latoms[0].name, 'CA')
            self.assertEqual(latoms[0].parent.resname, 'DUM')
            self.assertEqual(latoms[0].parent.parent.id, 'A')
        finally:
            os.remove(filename)
Ejemplo n.º 30
0
def get_sequence(pdb, chain):
    if chain is "%":
        chain = " "
    warnings.filterwarnings('always', message='.*discontinuous at.*')
    pdb_parser = PDBParser(
        PERMISSIVE=0, QUIET=True
    )  # The PERMISSIVE instruction allows PDBs presenting errors.
    pdb_structure = pdb_parser.get_structure(pdb, pdb)

    pdb_chain = pdb_structure[0][chain]
    ppb = PPBuilder()
    Sequence = ""
    for pp in ppb.build_peptides(pdb_chain, aa_only=False):
        Sequence = Sequence + pp.get_sequence()

    io = PDBIO()
    io.set_structure(pdb_structure)
    output = pdb[0:-4] + ".pdb"
    out = open(output[:-4] + ".fasta.atom", "w")
    out.write(">" + pdb[0:-4] + "\n")
    out.write(str(Sequence) + "\n")
    out.close()