def crete_bonds_list(self): b = self.read_psf() list_of_bonds = [] atom_list = self.create_atom_list() for i in range(len(b)): if len(b[i]) % 2 == 0: for j in range(len(b[i])): if j == 0: atom_1 = Tools.find_atom(b[i][j], atom_list) atom_2 = Tools.find_atom(b[i][j + 1], atom_list) if atom_1 is not None and atom_2 is not None: bond = Bond(atom_1, atom_2).create_bond() list_of_bonds.append(bond) else: if ((j * 2) + 1) < len(b[i]): atom_1 = Tools.find_atom(b[i][j * 2], atom_list) atom_2 = Tools.find_atom(b[i][(j * 2) + 1], atom_list) if atom_1 is not None and atom_2 is not None: bond = Bond(atom_1, atom_2).create_bond() list_of_bonds.append(bond) else: logging.info('The number of bonds is odd') break return list_of_bonds
def read_psf(self): can_print = False b = [] try: psf_file = open(self.psf_filename, 'r') for line in psf_file: if "bonds\n" in line: can_print = True elif "angles" in line: can_print = False if can_print: b.append(line.split(' ')) psf_file.close() b.pop(0) bond_list = [[] for i in range(len(b))] for i in range(len(b)): for j in range(len(b[i])): if b[i][j] == '': logging.info('Space found, line passed...') else: bond_list[i].append(str.rstrip(b[i][j])) return bond_list except FileNotFoundError as error: logging.error(error.strerror)
def create_commands_list(self, frames): comands_frames = [] completed = 0 self.option.progress.setRange(0, len(frames)) for frame in frames: commands_list = [] completed += 1 self.option.progress.setValue(completed) for key, value in frame.colors_command_list.items(): if value: if len(value) >= 96: logging.info( 'To much atoms to color, list mast be truncated') truncated_command_list = self.truncate_command( key, value) for command in truncated_command_list: commands_list.append(command) else: color_command = ColorCommand(key, value) color_command.create_color_command() commands_list.append(color_command) command_frame = CommandFrame(frame.number, commands_list) comands_frames.append(command_frame) return comands_frames
def truncate_command(key, value): truncated_command_list = [] while value: logging.info('Truncate in progress...') atoms = value[0:95] del value[0:95] color_command = ColorCommand(key, atoms) color_command.create_color_command() truncated_command_list.append(color_command) return truncated_command_list
def create_frames_list(self, residue): frames = [] completed = 0 self.option.progress.setRange(0, self.p1.cmd.count_frames() + 1) for i in range((self.p1.cmd.count_frames()) + 1): completed += 1 self.option.progress.setValue(completed) self.p1.cmd.frame(i) logging.info('Processing frame number ' + str(i) + '...') bonds = [] index = 0 for bond in residue: d0 = residue[index].distance atom_1_coords = self.p1.cmd.get_atom_coords('id ' + bond.atom_1.number) atom_2_coords = self.p1.cmd.get_atom_coords('id ' + bond.atom_2.number) di = Tools.calculate_distance( atom_1_coords[0], atom_1_coords[1], atom_1_coords[2], atom_2_coords[0], atom_2_coords[1], atom_2_coords[2]) atom_1 = Atom(bond.atom_1.number, bond.atom_1.element, bond.atom_1.residue, atom_1_coords[0], atom_1_coords[1], atom_1_coords[2]) atom_2 = Atom(bond.atom_2.number, bond.atom_2.element, bond.atom_2.residue, atom_2_coords[0], atom_2_coords[1], atom_2_coords[2]) delta_d_percent = Tools.distance_percent_change(d0, di) color = Color(delta_d_percent, self.config) new_bond = Bond(atom_1.create_atom(), atom_2.create_atom(), color.return_color()) bonds.append(new_bond.create_bond()) index += 1 colors_command_list = Frames.create_color_list(bonds) frame = Frame(i, bonds, colors_command_list) frames.append(frame.create_frame()) return frames
def read_pdb(self): try: pdb_file = open(self.pdb_filename, 'r') a = [] for line in pdb_file: if "ATOM" in line: if 'TIP3W' in line: logging.info('Water was reached, scanning completed.') break else: a.append(line.split(' ')) pdb_file.close() logging.info('File ' + self.pdb_filename + 'closed.') atom_list = [[] for i in range(len(a))] for i in range(len(a)): for j in range(len(a[i])): if a[i][j] == '': logging.info('Space found, line passed...') else: atom_list[i].append(a[i][j]) return atom_list except FileNotFoundError as error: logging.error(error.strerror)
def run_option(self): if self.file_pdb and self.file_psf and self.file_dcd: input_files = InputFiles(self.file_pdb, self.file_psf) bonds = input_files.crete_bonds_list() select_residue = SelectAtomGroup(bonds) if str(self.combo_box_option) == 'Backbone': selected_atoms = select_residue.backbone() elif str(self.combo_box_option) == 'All': selected_atoms = select_residue.all_atoms() else: QMessageBox.information(self, 'ADIST', 'Something gone wrong !') self.p1 = pymol2.PyMOL() self.p1.start() self.p1.cmd.util.performance(100) self.p1.cmd.set('defer_builds_mode', 10) self.p1.cmd.load(self.file_pdb, 'loaded_protein') self.p1.cmd.load_traj(self.file_dcd, 'loaded_protein') self.p1.cmd.remove('solvent') self.frames_list = self.create_frames_list(selected_atoms) self.p1.stop() if self.option.file_check.isChecked(): if self.frames_list: Tools.export_to_file(self.frames_list) QMessageBox.information(self, 'ADIST', 'CSV file created!') logging.info('CSV file created!') if self.option.chart_check.isChecked(): if self.frames_list: atom_1 = self.option.atom_1_input.text() atom_2 = self.option.atom_2_input.text() if atom_1.isdigit() and atom_2.isdigit(): Tools.plot(self.frames_list, atom_1, atom_2) QMessageBox.information(self, 'ADIST', 'Plot created!') logging.info('Plot created!') if self.option.ten_colors_check.isChecked(): if self.frames_list: self.comand_frames = self.create_commands_list( self.frames_list) with open("frames.file", "wb") as f: pickle.dump(self.comand_frames, f, pickle.HIGHEST_PROTOCOL) f.close() if os.path.isfile('frames.file'): logging.info('File dropped') QMessageBox.information( self, 'ADIST', 'Done,Hit CapsLock to watch result in PyMOL') subprocess.call([ 'python', 'ten_colors.py', self.file_pdb, self.file_dcd, 'frames.file' ]) else: QMessageBox.critical(self, 'Error', 'File not found!') logging.error('File not found') else: QMessageBox.critical(self, 'Error', 'None file selected!') logging.error('None file selected')