def __init__(self, system, database, parent=None, app=None): super(ConnectAllDialog, self).__init__(system, database, app=app, parent=parent) self.wgt_dgraph = DGraphWidget(database=self.database, parent=self) self.view_dgraph = self.new_view("Disconnectivity Graph", self.wgt_dgraph, QtCore.Qt.TopDockWidgetArea) self.view_dgraph.hide() self.ui.actionD_Graph.setVisible(True) self.ui.actionD_Graph.setChecked(False) self.textEdit_summary = QtGui.QTextEdit(parent=self) self.textEdit_summary.setReadOnly(True) self.view_summary = self.new_view("Summary", self.textEdit_summary, pos=QtCore.Qt.TopDockWidgetArea) self.connect_summary = ConnectAllSummary() self.ui.actionSummary.setVisible(True) self.view_summary.hide() self.ui.actionSummary.setChecked(False) self.ui.action3D.setChecked(False) self.view_3D.hide() self.ui.actionEnergy.setChecked(False) self.view_energies.hide() self.ui.actionPause.setVisible(True) self.is_running = False self.failed_pairs = set()
def __init__(self, system, database, parent=None, app=None): super(ConnectAllDialog, self).__init__(system, database, app=app, parent=parent) self.wgt_dgraph = DGraphWidget(database=self.database, parent=self) self.view_dgraph = self.new_view("Disconnectivity Graph", self.wgt_dgraph, QtCore.Qt.TopDockWidgetArea) self.view_dgraph.hide() self.ui.actionD_Graph.setVisible(True) self.ui.actionD_Graph.setChecked(False) self.textEdit_summary = QtGui.QTextEdit(parent=self) self.textEdit_summary.setReadOnly(True) self.view_summary = self.new_view("Summary", self.textEdit_summary, pos=QtCore.Qt.TopDockWidgetArea) self.connect_summary = ConnectAllSummary() self.ui.actionSummary.setVisible(True) self.view_summary.hide() self.ui.actionSummary.setChecked(False) self.ui.actionRandom_connect.setVisible(True) self.ui.actionRandom_connect.setChecked(False) self.ui.action3D.setChecked(False) self.view_3D.hide() self.ui.actionEnergy.setChecked(False) self.view_energies.hide() self.ui.actionPause.setVisible(True) self.is_running = False self.failed_pairs = set()
class ConnectAllDialog(ConnectViewer): def __init__(self, system, database, parent=None, app=None): super(ConnectAllDialog, self).__init__(system, database, app=app, parent=parent) self.wgt_dgraph = DGraphWidget(database=self.database, parent=self) self.view_dgraph = self.new_view("Disconnectivity Graph", self.wgt_dgraph, QtCore.Qt.TopDockWidgetArea) self.view_dgraph.hide() self.ui.actionD_Graph.setVisible(True) self.ui.actionD_Graph.setChecked(False) self.textEdit_summary = QtGui.QTextEdit(parent=self) self.textEdit_summary.setReadOnly(True) self.view_summary = self.new_view("Summary", self.textEdit_summary, pos=QtCore.Qt.TopDockWidgetArea) self.connect_summary = ConnectAllSummary() self.ui.actionSummary.setVisible(True) self.view_summary.hide() self.ui.actionSummary.setChecked(False) self.ui.actionRandom_connect.setVisible(True) self.ui.actionRandom_connect.setChecked(False) self.ui.action3D.setChecked(False) self.view_3D.hide() self.ui.actionEnergy.setChecked(False) self.view_energies.hide() self.ui.actionPause.setVisible(True) self.is_running = False self.failed_pairs = set() def do_one_connection(self, min1, min2): self.textEdit.insertPlainText("\n\n") self.textEdit_summary.insertPlainText( "\nNow connecting minima %d %d\n" % (self.min1._id, self.min2._id)) self.decrunner = DECRunner(self.system, self.database, min1, min2, outstream=self.textEdit_writer, return_smoothed_path=True) self.decrunner.on_finished.connect(self.on_finished) self.tstart = time.clock() self.decrunner.start() def get_next_pair_gmin(self): minima = self.database.minima() min1 = minima[0] graph = TSGraph(self.database) all_connected = True for m2 in minima[1:]: if not graph.areConnected(min1, m2): if (min1, m2) in self.failed_pairs or ( m2, min1) in self.failed_pairs: continue all_connected = False break if all_connected: print "minima are all connected, ending" self.textEdit_summary.insertPlainText( "minima are all connected, ending\n") return None, None return min1, m2 def get_next_pair_random(self): ''' get a new connect job ''' query = self.database.session.query(Minimum) # if self.Emax is not None: # query.filter(Minimum.energy < self.Emax) while True: min1 = query.order_by(sqlalchemy.func.random()).first() min2 = query.order_by(sqlalchemy.func.random()).first() if (min1, min2) not in self.failed_pairs and ( min2, min1) not in self.failed_pairs: return min1, min2 def do_next_connect(self): self.is_running = True if self.ui.actionRandom_connect.isChecked(): self.min1, self.min2 = self.get_next_pair_random() else: self.min1, self.min2 = self.get_next_pair_gmin() if self.min1 is None or self.min2 is None: self.is_running = False return self.do_one_connection(self.min1, self.min2) def start(self): self.do_next_connect() def update_energy_view(self): # plot the energies if self.view_energies.isVisible(): self.wgt_energies.update_gui(self.S, self.energies) def update_graph_view(self): # show the graph view if self.view_graphview.isVisible(): self.wgt_graphview.make_graph() self.wgt_graphview.show_graph() def update_3D_view(self): # show the smoothed path in the ogl viewer if self.view_3D.isVisible(): self.ogl.setCoordsPath(self.smoothed_path) def update_dgraph_view(self): if self.view_dgraph.isVisible(): self.wgt_dgraph.rebuild_disconnectivity_graph() def update_summary_view(self): self.textEdit_summary.clear() summary = self.connect_summary.get_summary() self.textEdit_summary.insertPlainText(summary) def on_finished(self): print "finished connecting", self.min1._id, "and", self.min2._id tend = time.clock() elapsed_time = tend - self.tstart # print "\n" # add this run to the summary self.connect_summary.add(self.min1, self.min2, self.decrunner.success, self.decrunner.newminima, self.decrunner.newtransition_states, elapsed_time=elapsed_time) if not self.isVisible(): self.is_running = False return if self.decrunner.success: # get the path data self.smoothed_path = np.array(self.decrunner.smoothed_path) self.S = np.array(self.decrunner.S) self.energies = np.array(self.decrunner.energies) # print self.smoothed_path.shape self.update_3D_view() self.update_energy_view() self.update_graph_view() self.update_dgraph_view() else: print "connection run failed" # summary "connection run failed" if not self.decrunner.killed_early: self.failed_pairs.add((self.min1, self.min2)) self.update_summary_view() if self.ui.actionPause.isChecked(): self.is_running = False return self.do_next_connect() def on_actionEnergy_toggled(self, checked): self.toggle_view(self.view_energies, checked) self.update_energy_view() def on_actionGraph_toggled(self, checked): self.toggle_view(self.view_graphview, checked) self.update_graph_view() def on_action3D_toggled(self, checked): self.toggle_view(self.view_3D, checked) self.update_3D_view() def on_actionD_Graph_toggled(self, checked): self.toggle_view(self.view_dgraph, checked) self.update_dgraph_view() def on_actionSummary_toggled(self, checked): self.toggle_view(self.view_summary, checked) def on_actionPause_toggled(self, checked): if checked is None: return if not checked: if not self.is_running: self.start() def on_actionKill_triggered(self, checked=None): if checked is None: return self.ui.actionPause.setChecked(True) self.is_running = False self.decrunner.terminate_early()
class ConnectAllDialog(ConnectViewer): def __init__(self, system, database, parent=None, app=None): super(ConnectAllDialog, self).__init__(system, database, app=app, parent=parent) self.wgt_dgraph = DGraphWidget(database=self.database, parent=self) self.view_dgraph = self.new_view("Disconnectivity Graph", self.wgt_dgraph, QtCore.Qt.TopDockWidgetArea) self.view_dgraph.hide() self.ui.actionD_Graph.setVisible(True) self.ui.actionD_Graph.setChecked(False) self.textEdit_summary = QtGui.QTextEdit(parent=self) self.textEdit_summary.setReadOnly(True) self.view_summary = self.new_view("Summary", self.textEdit_summary, pos=QtCore.Qt.TopDockWidgetArea) self.connect_summary = ConnectAllSummary() self.ui.actionSummary.setVisible(True) self.view_summary.hide() self.ui.actionSummary.setChecked(False) self.ui.action3D.setChecked(False) self.view_3D.hide() self.ui.actionEnergy.setChecked(False) self.view_energies.hide() self.ui.actionPause.setVisible(True) self.is_running = False self.failed_pairs = set() def do_one_connection(self, min1, min2): self.textEdit.insertPlainText("\n\n") self.textEdit_summary.insertPlainText("\nNow connecting minima %d %d\n" % (self.min1._id, self.min2._id)) self.decrunner = DECRunner(self.system, self.database, min1, min2, outstream=self.textEdit_writer, return_smoothed_path=True) self.decrunner.on_finished.connect(self.on_finished) self.tstart = time.clock() self.decrunner.start() def do_next_connect(self): self.is_running = True minima = self.database.minima() self.min1 = minima[0] graph = Graph(self.database) all_connected = True for m2 in minima[1:]: if not graph.areConnected(self.min1, m2): if (self.min1, m2) in self.failed_pairs or (m2, self.min1) in self.failed_pairs: continue all_connected = False break if all_connected: print "minima are all connected, ending" self.textEdit_summary.insertPlainText("minima are all connected, ending\n") self.is_running = False return self.min2 = m2 self.do_one_connection(self.min1, m2) def start(self): self.do_next_connect() def update_energy_view(self): # plot the energies if self.view_energies.isVisible(): self.wgt_energies.update_gui(self.S, self.energies) def update_graph_view(self): # show the graph view if self.view_graphview.isVisible(): self.wgt_graphview.make_graph() self.wgt_graphview.show_graph() def update_3D_view(self): # show the smoothed path in the ogl viewer if self.view_3D.isVisible(): self.ogl.setCoordsPath(self.smoothed_path) def update_dgraph_view(self): if self.view_dgraph.isVisible(): self.wgt_dgraph.rebuild_disconnectivity_graph() def update_summary_view(self): self.textEdit_summary.clear() summary = self.connect_summary.get_summary() self.textEdit_summary.insertPlainText(summary) def on_finished(self): print "finished connecting", self.min1._id, "and", self.min2._id tend = time.clock() elapsed_time = tend - self.tstart # print "\n" # add this run to the summary self.connect_summary.add(self.min1, self.min2, self.decrunner.success, self.decrunner.newminima, self.decrunner.newtransition_states, elapsed_time=elapsed_time) if not self.isVisible(): self.is_running = False return if self.decrunner.success: # get the path data self.smoothed_path = np.array(self.decrunner.smoothed_path) self.S = np.array(self.decrunner.S) self.energies = np.array(self.decrunner.energies) # print self.smoothed_path.shape self.update_3D_view() self.update_energy_view() self.update_graph_view() self.update_dgraph_view() else: print "connection run failed" # summary "connection run failed" if not self.decrunner.killed_early: self.failed_pairs.add( (self.min1, self.min2) ) self.update_summary_view() if self.ui.actionPause.isChecked(): self.is_running = False return self.do_next_connect() def on_actionEnergy_toggled(self, checked): self.toggle_view(self.view_energies, checked) self.update_energy_view() def on_actionGraph_toggled(self, checked): self.toggle_view(self.view_graphview, checked) self.update_graph_view() def on_action3D_toggled(self, checked): self.toggle_view(self.view_3D, checked) self.update_3D_view() def on_actionD_Graph_toggled(self, checked): self.toggle_view(self.view_dgraph, checked) self.update_dgraph_view() def on_actionSummary_toggled(self, checked): self.toggle_view(self.view_summary, checked) def on_actionPause_toggled(self, checked): if checked is None: return if not checked: if not self.is_running: self.start() def on_actionKill_triggered(self, checked=None): if checked is None: return self.ui.actionPause.setChecked(True) self.is_running = False self.decrunner.terminate_early()