def update_settings(self): idxs = self.inp_box.ctr.GetItemCount() items = [self.inp_box.ctr.GetItemData(i) for i in range(idxs)] inputs = [] reference = None sequence = None for i in items: inp_type = i.type.type.GetString(i.type_selection) if inp_type in ('processed pickle list', 'processed pickle folder', 'processed pickle'): inputs.append(i.path) elif inp_type == 'reference MTZ': reference = i.path elif inp_type == 'sequence': sequence = i.path self.pparams.data = inputs if reference is not None: self.pparams.hklisoin = reference if self.opt_chk_useref.GetValue(): self.pparams.hklrefin = reference self.out_dir = self.out_box.ctr.GetValue() self.pparams.run_no = misc.set_base_dir( out_dir=self.out_dir) # Need to change self.pparams.title = self.project_title.ctr.GetValue() self.pparams.n_residues = self.opt_spc_nres.ctr.GetValue() self.pparams.n_processors = self.opt_spc_nproc.ctr.GetValue() update_phil = master_phil.format(python_object=self.pparams) self.regenerate_params(update_phil)
def onRun(self, e): # Run full processing self.init_settings() prime_phil = master_phil.format(python_object=self.pparams) with misc.Capturing() as output: prime_phil.show() txt_out = '' for one_output in output: txt_out += one_output + '\n' prime_file = os.path.join(self.out_dir, self.prime_filename) out_file = os.path.join(self.out_dir, 'stdout.log') with open(prime_file, 'w') as pf: pf.write(txt_out) self.prime_run_window = PRIMERunWindow(self, -1, title='PRIME Output', params=self.pparams, prime_file=prime_file, out_file=out_file) self.prime_run_window.prev_pids = easy_run.fully_buffered('pgrep -u {} {}' ''.format(user, python)).stdout_lines self.prime_run_window.Show(True)
def onRun(self, e): # Run full processing self.init_settings() if self.sanity_check(): prime_phil = master_phil.format(python_object=self.pparams) with misc.Capturing() as output: prime_phil.show() txt_out = '' for one_output in output: txt_out += one_output + '\n' source_dir = os.path.dirname(self.out_dir) prime_file = os.path.join(source_dir, self.prime_filename) out_file = os.path.join(self.out_dir, 'stdout.log') with open(prime_file, 'w') as pf: pf.write(txt_out) self.prime_run_window = frm.PRIMERunWindow(self, -1, title='PRIME Output', params=self.pparams, prime_file=prime_file) self.prime_run_window.prev_pids = easy_run.fully_buffered('pgrep -u {} {}' ''.format(user, python)).stdout_lines self.prime_run_window.Show(True)
def regenerate_params(self, phil=None): if phil is not None: current_phil = master_phil.format(python_object=phil) else: current_phil = master_phil # Generate Python object and text of parameters self.generate_phil_string(current_phil) self.pparams = current_phil.extract()
def regenerate_params(self, phil=None): if phil is not None: current_phil = master_phil.format(python_object=phil) else: current_phil = master_phil # Generate Python object and text of parameters self.pparams = current_phil.extract() with misc.Capturing() as txt_output: current_phil.show() self.phil_string = '' for one_output in txt_output: self.phil_string += one_output + '\n'
def onSaveScript(self, e): self.init_settings() # Generate text of params final_phil = master_phil.format(python_object=self.pparams) with misc.Capturing() as txt_output: final_phil.show() txt_out = '' for one_output in txt_output: txt_out += one_output + '\n' # Save param file save_dlg = wx.FileDialog(self, message="Save PRIME Script", defaultDir=os.curdir, defaultFile="*.phil", wildcard="*.phil", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if save_dlg.ShowModal() == wx.ID_OK: with open(save_dlg.GetPath(), 'w') as savefile: savefile.write(txt_out) save_dlg.Destroy()
def onSaveScript(self, e): self.init_settings() # Generate text of params final_phil = master_phil.format(python_object=self.pparams) with misc.Capturing() as txt_output: final_phil.show() txt_out = '' for one_output in txt_output: txt_out += one_output + '\n' # Save param file save_dlg = wx.FileDialog(self, message="Save PRIME Script", defaultDir=os.curdir, defaultFile="*.phil", wildcard="*.phil", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT ) if save_dlg.ShowModal() == wx.ID_OK: with open(save_dlg.GetPath(), 'w') as savefile: savefile.write(txt_out) save_dlg.Destroy()
def __init__(self, parent, phil=None): self.parent = parent super(PRIMEInputWindow, self).__init__(self.parent) #Generate default parameters if phil is not None: self.pparams = master_phil.format(python_object=phil).extract() else: self.pparams = master_phil.extract() main_box = wx.StaticBox(self, label='Main Settings') vbox = wx.StaticBoxSizer(main_box, wx.VERTICAL) # Input file box self.inp_box = ct.InputCtrl(self, label='Input: ', label_size=(120, -1), label_style='bold', button=True) vbox.Add(self.inp_box, flag=wx.LEFT | wx.TOP | wx.RIGHT| wx.EXPAND, border=15) # Output file box self.out_box = ct.InputCtrl(self, label='Output: ', label_size=(120, -1), label_style='bold', button=True) vbox.Add(self.out_box, flag=wx.LEFT | wx.TOP | wx.RIGHT| wx.EXPAND, border=15) # # Sequence file box # self.seq_box = ct.InputCtrl(self, label='Sequence: ', # label_size=(120, -1), # button=True) # vbox.Add(self.seq_box, # flag=wx.LEFT | wx.TOP | wx.RIGHT| wx.EXPAND, # border=15) # Isomorphous reference file box self.ref_box = ct.InputCtrl(self, label='Reference: ', label_size=(120, -1), button=True) vbox.Add(self.ref_box, flag=wx.LEFT | wx.TOP | wx.RIGHT| wx.EXPAND, border=15) # Title box self.title_box = ct.InputCtrl(self, label='Job Title: ', label_size=(120, -1)) vbox.Add(self.title_box, flag=wx.LEFT | wx.TOP | wx.RIGHT| wx.EXPAND, border=15) # Options and number of processors opt_box = wx.FlexGridSizer(2, 4, 15, 10) self.opt_chk_useref = wx.CheckBox(self, label='Use reference in refinement') self.opt_chk_useref.SetValue(False) self.opt_chk_useref.Disable() self.opt_txt_nres = wx.StaticText(self, label='No. of Residues: ') self.opt_spc_nres = wx.SpinCtrl(self, value='500', max=(15000), size=(80,-1)) self.opt_txt_nproc = wx.StaticText(self, label='No. of Processors: ') self.opt_spc_nproc = wx.SpinCtrl(self, value='8', size=(80, -1)) self.opt_btn = wx.Button(self, label='Advanced Options...') opt_box.Add((120, -1)) opt_box.Add(self.opt_chk_useref) opt_box.Add(self.opt_txt_nres, flag=wx.ALIGN_RIGHT) opt_box.Add(self.opt_spc_nres, flag=wx.ALIGN_RIGHT) opt_box.Add((120, -1)) opt_box.Add(self.opt_btn) opt_box.Add(self.opt_txt_nproc, flag=wx.ALIGN_RIGHT) opt_box.Add(self.opt_spc_nproc, flag=wx.ALIGN_RIGHT) opt_box.AddGrowableCol(1, 1) vbox.Add(opt_box, flag=wx.LEFT | wx.TOP | wx.RIGHT| wx.EXPAND, border=15) vbox.Add((-1, 15)) self.SetSizer(vbox) # Button bindings self.inp_box.btn_browse.Bind(wx.EVT_BUTTON, self.onInputBrowse) self.out_box.btn_browse.Bind(wx.EVT_BUTTON, self.onOutputBrowse) # self.seq_box.btn_browse.Bind(wx.EVT_BUTTON, self.onSequenceBrowse) self.ref_box.btn_browse.Bind(wx.EVT_BUTTON, self.onIsoRefBrowse) self.opt_btn.Bind(wx.EVT_BUTTON, self.onAdvancedOptions)
def onAdvancedOptions(self, e): advanced = dlg.PRIMEAdvancedOptions( self, title='Advanced PRIME Options', style=wx.DEFAULT_DIALOG_STYLE | wx.STAY_ON_TOP | wx.RESIZE_BORDER) advanced.SetMinSize((600, -1)) advanced.Fit() # Populate the PHIL textbox current_phil = master_phil.format(python_object=self.pparams) self.generate_phil_string(current_phil=current_phil) 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()