def test_superimposer_structure(): from Bio import SeqIO from Bio.PDB import PDBParser code = '1ptq' fileName = testFilePath + code + '.pdb' refStructure = PDBParser().get_structure(code, fileName) sequences = [] with open(fileName, 'r') as f: sequences = [r.seq for r in SeqIO.parse(f, "pdb-seqres")] pass ds = Distructure('test', sequences, [[ r.get_id() for r in refStructure.get_residues() if r.get_id()[0] == ' ' ]]) ds.generate_primary_contacts() ds.run() refStructure = PDBParser().get_structure(code, fileName) sup = Superimposer() sup.set_structures(refStructure, ds) return
def get_PDB_length(pdbFileLocation): from Bio.PDB.PDBParser import PDBParser # pdbFileLocation = '/Users/weilu/Research/database/chosen/T0869-D1.pdb' structure = PDBParser().get_structure("a", pdbFileLocation) return len(list(structure.get_residues()))
def launch(self) -> int: """Execute the :class:`ExtractResidues <utils.extract_residues.ExtractResidues>` utils.extract_residues.ExtractResidues object.""" self.io_dict['in']['input_structure_path'] = check_input_path( self.io_dict['in']['input_structure_path'], self.out_log, self.__class__.__name__) self.io_dict['out']['output_residues_path'] = check_output_path( self.io_dict['out']['output_residues_path'], self.out_log, self.__class__.__name__) # Setup Biobb if self.check_restart(): return 0 self.stage_files() # Business code # get list of Residues from properties list_residues = create_residues_list(self.residues, self.out_log) # load input into BioPython structure structure = PDBParser(QUIET=True).get_structure( 'structure', self.stage_io_dict['in']['input_structure_path']) new_structure = [] # get desired residues for residue in structure.get_residues(): r = { 'model': str(residue.get_parent().get_parent().get_id() + 1), 'chain': residue.get_parent().get_id(), 'name': residue.get_resname(), 'res_id': str(residue.get_id()[1]) } if list_residues: for res in list_residues: match = True for code in res['code']: if res[code].strip() != r[code].strip(): match = False break if match: new_structure.append(r) else: new_structure.append(r) # if not residues found in structure, raise exit if not new_structure: fu.log( self.__class__.__name__ + ': The residues given by user were not found in input structure', self.out_log) raise SystemExit( self.__class__.__name__ + ': The residues given by user were not found in input structure' ) # parse PDB file and get residues line by line new_file_lines = [] curr_model = 0 with open(self.stage_io_dict['in']['input_structure_path']) as infile: for line in infile: if line.startswith("MODEL "): curr_model = line.rstrip()[-1] if int(curr_model) > 1: new_file_lines.append('ENDMDL\n') new_file_lines.append('MODEL ' + "{:>4}".format(curr_model) + '\n') if line.startswith("ATOM"): name = line[17:20].strip() chain = line[21:22].strip() res_id = line[22:27].strip() if curr_model != 0: model = curr_model.strip() else: model = "1" if chain == "": chain = " " for nstr in new_structure: if nstr['res_id'] == res_id and nstr[ 'name'] == name and nstr[ 'chain'] == chain and nstr[ 'model'] == model: new_file_lines.append(line) if int(curr_model) > 0: new_file_lines.append('ENDMDL\n') # save new file with heteroatoms with open(self.stage_io_dict['out']['output_residues_path'], 'w') as outfile: for line in new_file_lines: outfile.write(line) self.return_code = 0 ########## # Copy files to host self.copy_to_host() # Remove temporal files self.tmp_files.append(self.stage_io_dict.get("unique_dir")) self.remove_tmp_files() return self.return_code