def __init__(self, nb): Tab.__init__(self, nb) Refinement.set_proot(self.s.proot) # plot self.dpi = 100 self.fig = Figure((5.0, 4.0), dpi=self.dpi) col = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) self.fig.patch.set_facecolor((col[0]/255.0, col[1]/255.0, col[2]/255.0)) self.canvas = FigCanvas(self, -1, self.fig) self.ax1 = self.fig.add_subplot(111) self.ax1.set_position([0.115,0.17,0.80,0.79]) [i.set_linewidth(0.5) for i in self.ax1.spines.itervalues()] self.ax2 = self.ax1.twinx() self.ax2.set_position([0.115,0.17,0.80,0.79]) self._clear_figure() # stats self.stats_sizer = wx.FlexGridSizer(cols=2, rows=9, hgap=5, vgap=5) self._labels = [ wx.StaticText(self, -1, 'Title'), wx.StaticText(self, -1, 'Status'), wx.StaticText(self, -1, 'Cycle'), wx.StaticText(self, -1, 'Resolution (A)'), wx.StaticText(self, -1, 'R-work (%)'), wx.StaticText(self, -1, 'R-free (%)'), wx.StaticText(self, -1, '# of Reflections'), wx.StaticText(self, -1, 'Parameters'), wx.StaticText(self, -1, 'Data:Parameter') ] self._labels[0].Wrap(200) self._values = [ wx.StaticText(self, -1, '') for x in range(len(self._labels)) ] rows = [1,2,3,4,6] for i in range(len(self._labels)): self.stats_sizer.Add(self._labels[i], 0, wx.EXPAND|wx.TOP, i in rows and 15 or 5) self.stats_sizer.Add(self._values[i], 0, wx.EXPAND|wx.TOP, i in rows and 15 or 5) self.vbox = wx.BoxSizer(wx.VERTICAL) self.vbox.Add(self.stats_sizer, 0, wx.ALL, 10) self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) self.vbox.Add(self.button_sizer, 0, wx.EXPAND|wx.CENTER, 10) self.hbox = wx.BoxSizer(wx.HORIZONTAL) self.hbox.Add(self.vbox, 1, wx.EXPAND|wx.ALL, 10) self.hbox.Add(self.canvas, 4, wx.EXPAND|wx.ALL, 10) self.SetSizer(self.hbox) self.hbox.Fit(self) self._refinement = None
def start_refinement(self, type, root, title, res, resl, cycles, ins, hkl, id, options): self.abortb = metallicbutton.MetallicButton(self, -1, 'Abort', '', bitmaps.fetch_icon_bitmap("actions", "stop"), size=(105, 34)) self.Bind(wx.EVT_BUTTON, self.abort, self.abortb) self.button_sizer.Add(self.abortb, 0, wx.EXPAND|wx.ALL, 2) self.Fit() self._refinement = Refinement(self, type, root, title, res, resl, cycles, ins, hkl, id, options) self._refinement.set_callbacks(self._refinement_started, self._refinement_running, self._refinement_cycle, self._refinement_finished, self._error_dialog)
def __init__(self, builder): self._builder = builder self._refinement = Refinement() self._builder.getSimulationLearner().setRefinement(self._refinement)
class RefinementDescriptor(object): def __init__(self, builder): self._builder = builder self._refinement = Refinement() self._builder.getSimulationLearner().setRefinement(self._refinement) def addMostPromisingChildren(self): admissibleSet = AdmissibleSparseGridNodeSet() self._refinement.setAdmissibleSetCreator(admissibleSet) return MostPromisingChildrenDescriptor(self._refinement) def refineMostPromisingNodes(self): admissibleSet = RefinableNodesSet() self._refinement.setAdmissibleSetCreator(admissibleSet) return RefineCurrentNodesDescriptor(self._refinement) def withBalancing(self): self._refinement.setBalancing(True) return self def withAverageWeightening(self): self._refinement.setAverageWeightening(True) return self def withAdaptTimeWindow(self, value): self._refinement.setAdaptTimeWindow(value) return self def withAdaptMaxLevel(self, level): self._refinement.setAdaptMaxLevel(level) return self
class Process(Tab): _finished_callback = None def __init__(self, nb): Tab.__init__(self, nb) Refinement.set_proot(self.s.proot) # plot self.dpi = 100 self.fig = Figure((5.0, 4.0), dpi=self.dpi) col = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) self.fig.patch.set_facecolor((col[0]/255.0, col[1]/255.0, col[2]/255.0)) self.canvas = FigCanvas(self, -1, self.fig) self.ax1 = self.fig.add_subplot(111) self.ax1.set_position([0.115,0.17,0.80,0.79]) [i.set_linewidth(0.5) for i in self.ax1.spines.itervalues()] self.ax2 = self.ax1.twinx() self.ax2.set_position([0.115,0.17,0.80,0.79]) self._clear_figure() # stats self.stats_sizer = wx.FlexGridSizer(cols=2, rows=9, hgap=5, vgap=5) self._labels = [ wx.StaticText(self, -1, 'Title'), wx.StaticText(self, -1, 'Status'), wx.StaticText(self, -1, 'Cycle'), wx.StaticText(self, -1, 'Resolution (A)'), wx.StaticText(self, -1, 'R-work (%)'), wx.StaticText(self, -1, 'R-free (%)'), wx.StaticText(self, -1, '# of Reflections'), wx.StaticText(self, -1, 'Parameters'), wx.StaticText(self, -1, 'Data:Parameter') ] self._labels[0].Wrap(200) self._values = [ wx.StaticText(self, -1, '') for x in range(len(self._labels)) ] rows = [1,2,3,4,6] for i in range(len(self._labels)): self.stats_sizer.Add(self._labels[i], 0, wx.EXPAND|wx.TOP, i in rows and 15 or 5) self.stats_sizer.Add(self._values[i], 0, wx.EXPAND|wx.TOP, i in rows and 15 or 5) self.vbox = wx.BoxSizer(wx.VERTICAL) self.vbox.Add(self.stats_sizer, 0, wx.ALL, 10) self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) self.vbox.Add(self.button_sizer, 0, wx.EXPAND|wx.CENTER, 10) self.hbox = wx.BoxSizer(wx.HORIZONTAL) self.hbox.Add(self.vbox, 1, wx.EXPAND|wx.ALL, 10) self.hbox.Add(self.canvas, 4, wx.EXPAND|wx.ALL, 10) self.SetSizer(self.hbox) self.hbox.Fit(self) self._refinement = None def set_finished_callback(self, func): self._finished_callback = func def view_log(self, event): if self._refinement is not None: p = self._refinement.parameters() log = p['input'] + '.log' if os.path.exists(log): dlg = LogFile(self, -1, 'Log File Output for Job ' + str(p['id']), log) dlg.Show(True) def load_coot(self, event): if self._refinement is not None: p = self._refinement.parameters() if 'input' in p: self._coot_client.load_refinement(p['input']) def _clear_figure(self): self.ax1.cla() self.ax2.cla() self.ax1.set_ylabel('wR2', fontsize=9) self.ax1.tick_params(labelsize=8) self.ax1.yaxis.set_major_formatter(FormatStrFormatter('%5.3f')) self.ax2.tick_params(labelsize=8) self.ax2.yaxis.set_major_formatter(FormatStrFormatter('%4.1f')) self.ax2.set_ylabel('GooF', fontsize=9) def load_refinement(self, file): self._refinement = pickle.load(open(file)) self._clear_figure() self._refinement_cycle() self.show_buttons() def show_buttons(self): if hasattr(self, 'abortb'): self.abortb.Hide() self.logb = metallicbutton.MetallicButton(self, -1, 'View Log', '', bitmaps.fetch_icon_bitmap("mimetypes", "log"), size=(105, 34)) self.cootb = metallicbutton.MetallicButton(self, -1, 'View In Coot', '', bitmaps.fetch_icon_bitmap("custom", "coot"), size=(105, 34)) self.Bind(wx.EVT_BUTTON, self.view_log, self.logb) self.Bind(wx.EVT_BUTTON, self.load_coot, self.cootb) self.button_sizer.Add(self.logb, 0, wx.EXPAND|wx.ALL, 2) self.button_sizer.Add(self.cootb, 0, wx.EXPAND|wx.ALL, 2) self.Fit() def start_refinement(self, type, root, title, res, resl, cycles, ins, hkl, id, options): self.abortb = metallicbutton.MetallicButton(self, -1, 'Abort', '', bitmaps.fetch_icon_bitmap("actions", "stop"), size=(105, 34)) self.Bind(wx.EVT_BUTTON, self.abort, self.abortb) self.button_sizer.Add(self.abortb, 0, wx.EXPAND|wx.ALL, 2) self.Fit() self._refinement = Refinement(self, type, root, title, res, resl, cycles, ins, hkl, id, options) self._refinement.set_callbacks(self._refinement_started, self._refinement_running, self._refinement_cycle, self._refinement_finished, self._error_dialog) def abort(self, event=''): if self._refinement: self._refinement.abort() def _error_dialog(self, log): #dlg = wx.MessageDialog(self, 'Shelx failed with the following message:\n' + str(log), 'Shelxl Error', wx.OK|wx.ICON_ERROR) dlg = ShelxError(self, log) dlg.ShowModal() #dlg.Destroy() def _refinement_started(self): debug_print('starting shelx...') self._refinement_cycle() def _refinement_running(self, text): pass #self._set_sb(text) def _refinement_finished(self): self._refinement_cycle() self.show_buttons() debug_print('process finished...') #if hasattr(self, '_finished_callback'): if self._finished_callback is not None: self._finished_callback() def _refinement_cycle(self): p = self._refinement.parameters() l = p['last_cycle'] debug_print('new cycle...') self._values[0].SetLabel(p['title']) self._values[1].SetLabel(p['status']) self._values[2].SetLabel(str(l) + ' of ' + str(p['total_cycles'] + 1)) self._values[3].SetLabel(str(p['res']) + ' - ' + (str(p['resl']) if 'resl' in p else '10')) self._values[5].SetLabel(str('-' if p['rfree'] == -1 else "%.4f" % p['rfree'])) self._values[4].SetLabel(str('-' if p['r'] == -1 else (p['r'] if type(p['r']) == type(str()) else "%.4f" % p['r']))) if l > 0: self._values[6].SetLabel(str(p['cycles'][l][2])) self._values[7].SetLabel(str(p['cycles'][l][3])) self._values[8].SetLabel(str(round(float(p['cycles'][l][2])/float(p['cycles'][l][3]),2))) x = range(len(p['cycles'].keys())) y = [ p['cycles'][i+1][0] for i in x ] y2 = [ p['cycles'][i+1][1] for i in x ] self.ax1.plot(x, y, 'r^-') self.ax2.plot(x,y2, 'bo-') self.ax1.set_xticks(x) self.ax1.set_xticklabels([ 'Cycle ' + str(i+1) for i in x ], rotation='vertical', size=8) self.canvas.draw() def has_finished(self): ret = False if self._refinement is not None: p = self._refinement.parameters() ret = p['status'] == 'Finished' return ret def parameters(self): if self._refinement is not None: return self._refinement.parameters()