def load_script(self, out_dir): ''' Loads PRIME script ''' import iotbx.phil as ip script = os.path.join(out_dir, self.prime_filename) user_phil = ip.parse(open(script).read()) self.pparams = master_phil.fetch(sources=[user_phil]).extract() self.input_window.pparams = self.pparams self.input_window.inp_box.ctr.SetValue(str(self.pparams.data[0])) current_dir = os.path.dirname(self.pparams.run_no) self.input_window.out_box.ctr.SetValue(str(current_dir)) if str(self.input_window.out_box.ctr.GetValue).lower() == '': self.input_window.out_box.ctr.SetValue(self.out_dir) if str(self.pparams.title).lower() != 'none': self.input_window.title_box.ctr.SetValue(str(self.pparams.title)) if str(self.pparams.hklisoin).lower() != 'none': self.input_window.ref_box.ctr.SetValue(str(self.pparams.hklisoin)) elif str(self.pparams.hklrefin).lower() != 'none': self.input_window.ref_box.ctr.SetValue(str(self.pparams.hklrefin)) self.input_window.opt_chk_useref.SetValue(True) if str(self.pparams.n_residues).lower() == 'none': self.input_window.opt_spc_nres.SetValue(500) else: self.input_window.opt_spc_nres.SetValue(int(self.pparams.n_residues)) self.input_window.opt_spc_nproc.SetValue(int(self.pparams.n_processors))
def regenerate_params(self, phil=None): if phil is not None: self.prime_phil = master_phil.fetch(source=phil) else: self.prime_phil = master_phil # Generate Python object and text of parameters self.generate_phil_string(self.prime_phil) self.pparams = self.prime_phil.extract()
def onRecovery(self, e): # Find finished runs and display results p_folder = os.path.abspath('{}/prime'.format(os.curdir)) if not os.path.isdir(p_folder): open_dlg = wx.DirDialog(self, "Choose the integration run:", style=wx.DD_DEFAULT_STYLE) if open_dlg.ShowModal() == wx.ID_OK: p_folder = open_dlg.GetPath() open_dlg.Destroy() else: open_dlg.Destroy() return paths = [os.path.join(p_folder, p) for p in os.listdir(p_folder)] paths = [p for p in paths if (os.path.isdir(p) and os.path.basename(p).isdigit())] path_dlg = dlg.RecoveryDialog(self) path_dlg.insert_paths(paths) if path_dlg.ShowModal() == wx.ID_OK: selected = path_dlg.selected recovery = path_dlg.recovery_mode prime_path = selected[1] prime_status = selected[0] settings_file = os.path.join(prime_path, 'settings.phil') # If neither log-file nor stat file are found, terminate; otherwise # import settings if not os.path.isfile(settings_file): wx.MessageBox('Cannot Import This Run \n(No Files Found!)', 'Info', wx.OK | wx.ICON_ERROR) return else: self.reset_settings() with open(settings_file, 'r') as sf: phil_string = sf.read() read_phil = ip.parse(phil_string) self.prime_phil = master_phil.fetch(source=read_phil) self.pparams = self.prime_phil.extract() self.input_window.regenerate_params(self.prime_phil) self.update_input_window() # If any cycles (or full run) were completed, show results if prime_status == 'Unknown': return if recovery == 0: self.prime_run_window = frm.PRIMERunWindow(self, -1, title='PRIME Output', params=self.pparams, prime_file=settings_file, recover=True) self.prime_run_window.Show(True) self.prime_run_window.recover()
def load_script(self, out_dir): ''' Loads PRIME script ''' script = os.path.join(out_dir, self.prime_filename) with open(script, 'r') as sf: phil_string = sf.read() self.reset_settings() user_phil = ip.parse(phil_string) self.pparams = master_phil.fetch(source=user_phil).extract() self.input_window.pparams = self.pparams self.input_window.phil_string = phil_string self.update_input_window()
def test_phil(self, filepath): ''' Tests incoming PHIL file to try and determine what it's for ''' import iotbx.phil as ip try: test_phil = ip.parse(open(filepath).read()) # Test if IOTA parameter file from iota.components.iota_input import master_phil as iota_phil new_phil, unused = iota_phil.fetch(sources=[test_phil], track_unused_definitions=True) if len(unused) == 0: return 'IOTA settings' # Test if PRIME parameter file from prime.postrefine.mod_input import master_phil as prime_phil new_phil, unused = prime_phil.fetch(sources=[test_phil], track_unused_definitions=True) if len(unused) == 0: return 'PRIME settings' # Test if LABELIT target file from labelit.phil_preferences import iotbx_defs, libtbx_defs labelit_phil = ip.parse(input_string=iotbx_defs + libtbx_defs, process_includes=True) new_phil, unused = labelit_phil.fetch(sources=[test_phil], track_unused_definitions=True) if len(unused) == 0: return 'LABELIT target' # Test if DIALS target file from dials.command_line.stills_process import control_phil_str, \ dials_phil_str dials_phil = ip.parse(control_phil_str + dials_phil_str, process_includes=True) new_phil, unused = dials_phil.fetch(sources=[test_phil], track_unused_definitions=True) if len(unused) == 0: return 'DIALS target' else: return 'text' except Exception: return 'text'
def onAdvancedOptions(self, e): advanced = dlg.PRIMEAdvancedOptions(self, title='Advanced PRIME Options', style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) advanced.Fit() # Populate the PHIL textbox advanced.phil.ctr.SetValue(self.phil_string) # Set values to default parameters advanced.res.high.SetValue('{:4.2f}'.format( self.pparams.postref.allparams.d_max)) advanced.res.low.SetValue('{:4.2f}'.format( self.pparams.postref.allparams.d_min)) advanced.sg.spacegroup.SetValue(str(self.pparams.target_space_group)) if str(self.pparams.target_unit_cell).lower() != 'none': uc = ' '.join( list(map(str, self.pparams.target_unit_cell.parameters()))) advanced.uc.unit_cell.SetValue(uc) else: advanced.uc.unit_cell.SetValue(str(self.pparams.target_unit_cell)) advanced.anom.SetValue(self.pparams.target_anomalous_flag) advanced.cc.cc_cutoff.SetValue(str(self.pparams.frame_accept_min_cc)) advanced.pix.pixel_size.SetValue(str(self.pparams.pixel_size_mm)) advanced.cycles.ctr.SetValue(int(self.pparams.n_postref_cycle)) if advanced.ShowModal() == wx.ID_OK: # Read PHIL string from window, convert to params self.phil_string = advanced.phil.ctr.GetValue() new_phil = ip.parse(self.phil_string) self.pparams = master_phil.fetch(sources=[new_phil]).extract() # Param controls will override the PHIL string (clunky, but for now) if advanced.res_override.GetValue(): self.pparams.scale.d_max = float(advanced.res.high.GetValue()) self.pparams.scale.d_min = float(advanced.res.low.GetValue()) self.pparams.merge.d_max = float(advanced.res.high.GetValue()) self.pparams.merge.d_min = float(advanced.res.low.GetValue()) self.pparams.postref.scale.d_max = float( advanced.res.high.GetValue()) self.pparams.postref.scale.d_min = float( advanced.res.low.GetValue()) self.pparams.postref.crystal_orientation.d_max = float( advanced.res.high.GetValue()) self.pparams.postref.crystal_orientation.d_min = float( advanced.res.low.GetValue()) self.pparams.postref.reflecting_range.d_max = float( advanced.res.high.GetValue()) self.pparams.postref.reflecting_range.d_min = float( advanced.res.low.GetValue()) self.pparams.postref.unit_cell.d_max = float( advanced.res.high.GetValue()) self.pparams.postref.unit_cell.d_min = float( advanced.res.low.GetValue()) self.pparams.postref.allparams.d_max = float( advanced.res.high.GetValue()) self.pparams.postref.allparams.d_min = float( advanced.res.low.GetValue()) self.pparams.target_space_group = advanced.sg.spacegroup.GetValue() if advanced.uc.unit_cell.GetValue().lower() != 'none': uc = str_split(advanced.uc.unit_cell.GetValue()) self.pparams.target_unit_cell = unit_cell(list(map(float, uc))) else: self.pparams.target_unit_cell = None self.pparams.target_anomalous_flag = advanced.anom.GetValue() if advanced.cc.cc_cutoff.GetValue().lower() != 'none': self.pparams.frame_accept_min_cc = float( advanced.cc.cc_cutoff.GetValue()) else: self.pparams.frame_accept_min_cc = None if advanced.pix.pixel_size.GetValue().lower() != 'none': self.pparams.pixel_size_mm = float( advanced.pix.pixel_size.GetValue()) else: self.pparams.pixel_size_mm = None self.pparams.n_postref_cycle = int(advanced.cycles.ctr.GetValue()) self.regenerate_params(self.pparams) advanced.Destroy() e.Skip()
def test_phil(self, filepath): """Tests incoming PHIL file to try and determine what it's for.""" from iotbx import phil as ip from iotbx.file_reader import any_file as af try: if af(filepath).file_type == "phil": test_phil = ip.parse(open(filepath).read()) else: test_phil = None except RuntimeError: # If not a PHIL file or a bad PHIL file return "text" else: if test_phil: # Test if IOTA parameter file from iota.init.iota_input import master_phil as iota_phil new_phil, unused = iota_phil.fetch( sources=[test_phil], track_unused_definitions=True) len_test = len( test_phil.all_definitions(suppress_multiple=True)) percent_fit = (1 - len(unused) / len_test) * 100 if percent_fit >= 50: return "IOTA settings" # Test if PRIME parameter file from prime.postrefine.mod_input import master_phil as prime_phil new_phil, unused = prime_phil.fetch( sources=[test_phil], track_unused_definitions=True) len_test = len( test_phil.all_definitions(suppress_multiple=True)) percent_fit = (1 - len(unused) / len_test) * 100 if percent_fit >= 50: return "PRIME settings" # Test if LABELIT target file (LABELIT not always available) try: from labelit.phil_preferences import iotbx_defs, libtbx_defs except ImportError: pass else: labelit_phil = ip.parse(input_string=iotbx_defs + libtbx_defs, process_includes=True) new_phil, unused = labelit_phil.fetch( sources=[test_phil], track_unused_definitions=True) len_test = len( test_phil.all_definitions(suppress_multiple=True)) percent_fit = (1 - len(unused) / len_test) * 100 if percent_fit >= 50: return "LABELIT target" # Test if DIALS target file from dials.command_line.stills_process import ( control_phil_str, dials_phil_str, ) dials_phil = ip.parse(control_phil_str + dials_phil_str, process_includes=True) new_phil, unused = dials_phil.fetch( sources=[test_phil], track_unused_definitions=True) len_test = len( test_phil.all_definitions(suppress_multiple=True)) percent_fit = (1 - len(unused) / len_test) * 100 if percent_fit >= 50: return "DIALS target" else: return "text" else: return "text"
def onAdvancedOptions(self, e): advanced = PRIMEAdvancedOptions(self, title='Advanced PRIME Options', style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) advanced.Fit() # Populate the PHIL textbox advanced.phil.ctr.SetValue(self.phil_string) # Set values to default parameters advanced.res.high.SetValue('{:4.2f}'.format(self.pparams.scale.d_max)) advanced.res.low.SetValue('{:4.2f}'.format(self.pparams.scale.d_min)) advanced.sg.spacegroup.SetValue(str(self.pparams.target_space_group)) if str(self.pparams.target_unit_cell).lower() != 'none': uc = ' '.join(list(map(str, self.pparams.target_unit_cell.parameters()))) advanced.uc.unit_cell.SetValue(uc) else: advanced.uc.unit_cell.SetValue(str(self.pparams.target_unit_cell)) advanced.uc_override.SetValue(self.pparams.flag_override_unit_cell) advanced.anom.SetValue(self.pparams.target_anomalous_flag) advanced.cc.cc_cutoff.SetValue(str(self.pparams.frame_accept_min_cc)) advanced.pix.pixel_size.SetValue(str(self.pparams.pixel_size_mm)) advanced.cycles.ctr.SetValue(int(self.pparams.n_postref_cycle)) if advanced.ShowModal() == wx.ID_OK: # Read PHIL string from window, convert to params self.phil_string = advanced.phil.ctr.GetValue() new_phil = ip.parse(self.phil_string) self.pparams = master_phil.fetch(sources=[new_phil]).extract() # Param controls will override the PHIL string (clunky, but for now) self.pparams.scale.d_max = float(advanced.res.high.GetValue()) self.pparams.scale.d_min = float(advanced.res.low.GetValue()) self.pparams.merge.d_max = float(advanced.res.high.GetValue()) self.pparams.merge.d_min = float(advanced.res.low.GetValue()) self.pparams.postref.scale.d_max = float(advanced.res.high.GetValue()) self.pparams.postref.scale.d_min = float(advanced.res.low.GetValue()) self.pparams.postref.crystal_orientation.d_max = \ float(advanced.res.high.GetValue()) self.pparams.postref.crystal_orientation.d_min = \ float(advanced.res.low.GetValue()) self.pparams.postref.reflecting_range.d_max = \ float(advanced.res.high.GetValue()) self.pparams.postref.reflecting_range.d_min = \ float(advanced.res.low.GetValue()) self.pparams.postref.unit_cell.d_max = float(advanced.res.high.GetValue()) self.pparams.postref.unit_cell.d_min = float(advanced.res.low.GetValue()) self.pparams.postref.allparams.d_max = float(advanced.res.high.GetValue()) self.pparams.postref.allparams.d_min = float(advanced.res.low.GetValue()) self.pparams.target_space_group = advanced.sg.spacegroup.GetValue() if advanced.uc.unit_cell.GetValue().lower() != 'none': uc = str_split(advanced.uc.unit_cell.GetValue()) self.pparams.target_unit_cell = unit_cell(list(map(float, uc))) else: self.pparams.target_unit_cell = None self.pparams.flag_override_unit_cell = advanced.uc_override.GetValue() self.pparams.target_anomalous_flag = advanced.anom.GetValue() if advanced.cc.cc_cutoff.GetValue().lower() != 'none': self.pparams.frame_accept_min_cc = float(advanced.cc.cc_cutoff.GetValue()) else: self.pparams.frame_accept_min_cc = None if advanced.pix.pixel_size.GetValue().lower() != 'none': self.pparams.pixel_size_mm = float(advanced.pix.pixel_size.GetValue()) else: self.pparams.pixel_size_mm = None self.pparams.n_postref_cycle = int(advanced.cycles.ctr.GetValue()) self.regenerate_params(self.pparams) advanced.Destroy() e.Skip()