def onRun(self, e): # Run full processing self.init_settings() if self.sanity_check(): prime_phil = master_phil.format(python_object=self.pparams) with 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.place_and_size(set_by='parent') self.prime_run_window.Show(True)
def run_proc(args, data, info, filename, number=1): processor = ZMQProcessor(last_stage=args.last_stage, phil_file=args.phil) with Capturing() as junk: t_start = time.time() info = processor.run(data, filename, info) proc_time = time.time() - t_start n_spots = info["n_spots"] if args.verbose: print("\n*** channel # {}".format(number)) print("{} spots found".format(n_spots)) print("Trial: {}. Time: {:.2f} sec".format(number, proc_time)) return proc_time
def reset_settings(self): self.prime_phil = master_phil self.pparams = self.prime_phil.extract() self.input_window.inp_box.delete_all() self.input_window.out_box.reset_default() self.input_window.project_title.reset_default() self.input_window.opt_chk_useref.SetValue(False) self.input_window.opt_spc_nproc.reset_default() self.input_window.opt_spc_nres.reset_default() # Generate Python object and text of parameters with Capturing() as txt_output: master_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 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 run(self, idx, img): if self.meta_parent.terminated: raise IOTATermination( 'IOTA_TRACKER: SPF Termination signal received!') else: with Capturing() as junk_output: fail = False sg = None uc = None try: experiments = ExperimentListFactory.from_filenames([img ])[0] observed = self.processor.find_spots( experiments=experiments) except Exception: fail = True observed = [] pass # TODO: Indexing / lattice determination very slow (how to speed up?) if self.run_indexing: if not fail: try: experiments, indexed = self.processor.index( experiments=experiments, reflections=observed) except Exception: fail = True pass if not fail: try: solution = self.processor.refine_bravais_settings( reflections=indexed, experiments=experiments) # Only reindex if higher-symmetry solution found if solution is not None: experiments, indexed = self.processor.reindex( reflections=indexed, experiments=experiments, solution=solution) lat = experiments[0].crystal.get_space_group( ).info() sg = str(lat).replace(' ', '') except Exception: fail = True pass if not fail: unit_cell = experiments[0].crystal.get_unit_cell( ).parameters() uc = ' '.join(['{:.4f}'.format(i) for i in unit_cell]) if self.run_integration: if not fail: try: # Run refinement experiments, indexed = self.processor.refine( experiments=experiments, centroids=indexed) except Exception: fail = True pass if not fail: try: print(experiments) print(indexed) integrated = self.processor.integrate( experiments=experiments, indexed=indexed) except Exception: pass return [idx, int(len(observed)), img, sg, uc]
def generate_phil_string(self): with Capturing() as txt_output: self.prime_phil.show() self.phil_string = '' for one_output in txt_output: self.phil_string += one_output + '\n'
def process_image(self): if os.path.isfile(self.termfile): raise IOTATermination('IOTA_TRACKER: Termination signal received!') else: with Capturing() as junk_output: # if True: err = [] start = time.time() fail = False sg = None uc = None status = None score = 0 try: datablock = DataBlockFactory.from_filenames([self.img])[0] observed = self.processor.find_spots(datablock=datablock) status = 'spots found' except Exception, e: fail = True observed = [] err.append('SPOTFINDING ERROR: {}'.format(e)) pass # TODO: Indexing / lattice determination very slow (how to speed up?) if self.run_indexing: if not fail: try: experiments, indexed = self.processor.index( datablock=datablock, reflections=observed) score = len(indexed) except Exception, e: fail = True err.append('INDEXING ERROR: {}'.format(e)) pass if not fail: try: solution = self.processor.refine_bravais_settings( reflections=indexed, experiments=experiments) # Only reindex if higher-symmetry solution found if solution is not None: experiments, indexed = self.processor.reindex( reflections=indexed, experiments=experiments, solution=solution) obs = experiments lat = experiments[0].crystal.get_space_group( ).info() sg = str(lat).replace(' ', '') status = 'indexed' except Exception, e: fail = True err.append('LATTICE ERROR: {}'.format(e)) pass if not fail: unit_cell = experiments[0].crystal.get_unit_cell( ).parameters() uc = ' '.join(['{:.4f}'.format(i) for i in unit_cell]) if self.run_integration: if not fail: try: # Run refinement experiments, indexed = self.processor.refine( experiments=experiments, centroids=indexed) except Exception, e: fail = True err.append('REFINEMENT ERROR: {}'.format(e)) pass if not fail: try: print(experiments) print(indexed) integrated = self.processor.integrate( experiments=experiments, indexed=indexed) frame = ConstructFrame( integrated, experiments[0]).make_frame() status = 'integrated' except Exception, e: err.append('INTEGRATION ERROR: {}'.format(e)) pass