Example #1
0
def test():
    from pele.systems import LJCluster
    from pele.landscape import ConnectManager
    system = LJCluster(13)
    
    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    bh.run(200)
    
    manager = ConnectManager(db)
    for i in range(3):
        min1, min2 = manager.get_connect_job()
        connect = system.get_double_ended_connect(min1, min2, db)
        connect.connect()
    
#    get_thermodynamic_information(system, db)
    
    print "getting thermodynamic info", db.number_of_minima()
    get_thermodynamic_information(system, db, nproc=4)
    
    for m in db.minima():
        print m._id, m.pgorder, m.fvib
    
    print "\nnow transition states"
    for ts in db.transition_states():
        print ts._id, ts.pgorder, ts.fvib
Example #2
0
def run_double_ended_connect(system, database, strategy='random'):
    # connect the all minima to the lowest minimum
    from pele.landscape import ConnectManager
    manager = ConnectManager(database, strategy=strategy)
    for i in xrange(database.number_of_minima()-1):
        min1, min2 = manager.get_connect_job()
        connect = system.get_double_ended_connect(min1, min2, database)
        connect.connect()
Example #3
0
 def test_gmin(self):
     manager = ConnectManager(self.db, strategy="gmin")
     m0 = self.db.minima()[0]
     
     for i in range(5):
         m1, m2 = manager.get_connect_job()
         self.assertEqual(m1, m0)
         self.connect_min(m1, m2)
def main2():
    """a copy of main to clean it up a bit"""
    np.random.seed(0)
    #params=[0.1,1.0,0.0,0.0,0.0]
    #params=[0.1,1.0,0.0]
    params=[0.1,1.0,0.0,0.0,0.5*np.pi]
    model = WaveModel(params0=params,sigma=0.1)
    system = RegressionSystem(model)
    database = system.create_database(db="/home/ab2111/mydb.sqlite")
    pot = system.get_potential()

    # do basinhopping
    x0 = np.random.uniform(0.,3,[model.nparams])
    print pot.getEnergy(x0)
    pot.test_potential(x0)
    step = RandomCluster(volume=1.0)
    bh = system.get_basinhopping(database=database, takestep=step,coords=x0,temperature = 10.0)
    bh.run(100)
    
    mindist = system.get_mindist()

    #for j,m in enumerate(database.minima()):
    #    for i,mi in enumerate(database.minima()):
    #        distbest,c,minew = mindist(m.coords,mi.coords)
    #        if distbest-np.linalg.norm(mi.coords-m.coords) != 0.:
    #            print j,i,distbest,np.linalg.norm(mi.coords-m.coords),"\n",mi.coords,"\n",minew
            
        #print m.energy,m.coords
        
    for m in database.minima():
        print m.energy,m.coords    
    
    m0 = database.minima()[0]
    m1 = database.minima()[1]
    mindist(m0.coords,m1.coords)
    
    # connect the minima
    manager = ConnectManager(database, strategy="gmin")
    for i in xrange(3):
        try:
            m1, m2 = manager.get_connect_job()
        except manager.NoMoreConnectionsError:
            break
        connect = system.get_double_ended_connect(m1, m2, database)
        connect.connect()


    for m in database.minima():
        print m.energy,m.coords         
    
    database.session.commit()
    exit()    
    
    make_disconnectivity_graph(database)

        
    m1 = database.minima()[0]
    m2 = database.minima()[1]
Example #5
0
 def test_untrap(self):
     # first connect them all randomly
     manager = ConnectManager(self.db, strategy="random")
     while True:
         try:
             m1, m2 = manager.get_connect_job()
         except manager.NoMoreConnectionsError:
             break
         self.connect_min(m1, m2)
     
     for i in range(5):
         try:
             m1, m2 = manager.get_connect_job(strategy="untrap")
         except manager.NoMoreConnectionsError:
             break
         self.connect_min(m1, m2)
Example #6
0
    def test_untrap(self):
        # first connect them all randomly
        manager = ConnectManager(self.db, strategy="random")
        while True:
            try:
                m1, m2 = manager.get_connect_job()
            except manager.NoMoreConnectionsError:
                break
            self.connect_min(m1, m2)

        for i in range(5):
            try:
                m1, m2 = manager.get_connect_job(strategy="untrap")
            except manager.NoMoreConnectionsError:
                break
            self.connect_min(m1, m2)
Example #7
0
def create_random_database(system, db, nmin=20, nts=10):
    if db.number_of_minima() < nmin:
        bh = system.get_basinhopping(db, outstream=None)
        bh.run(50)
    
    if db.number_of_transition_states() < nts:
        manager = ConnectManager(db, strategy="gmin")
        for i in range(nts):
            try:
                min1, min2 = manager.get_connect_job("gmin")
            except Exception, e:
                if not "couldn't find any random minima pair to connect" in str(e):
                    raise
                
                    
            connect = system.get_double_ended_connect(min1, min2, db, verbosity=0)
            connect.connect()
Example #8
0
 def __init__(self, system, database, server_name=None, host=None, port=0):
     self.system = system
     self.db = database
     self.server_name = server_name
     self.host=host
     self.port=port
     
     self.connect_manager = ConnectManager(self.db)
Example #9
0
    def test_combine(self):
        minima = self.db.minima()
        i = 5
        for m1, m2 in zip(minima[:i-1], minima[1:i]):
            self.connect_min(m1, m2)
        for m1, m2 in zip(minima[i:], minima[i+1:]):
            self.connect_min(m1, m2)

        # at this point the minima should be in two disconnected groups
        g = database2graph(self.db)
        self.assertEqual(len(list(nx.connected_components(g))), 2)
            
        manager = ConnectManager(self.db, strategy="combine")
        m1, m2 = manager.get_connect_job()
        self.connect_min(m1, m2)
        
        # they should all be connected now
        g = database2graph(self.db)
        self.assertEqual(len(list(nx.connected_components(g))), 1)
Example #10
0
    def test_combine(self):
        minima = self.db.minima()
        i = 5
        for m1, m2 in zip(minima[:i - 1], minima[1:i]):
            self.connect_min(m1, m2)
        for m1, m2 in zip(minima[i:], minima[i + 1:]):
            self.connect_min(m1, m2)

        # at this point the minima should be in two disconnected groups
        g = database2graph(self.db)
        self.assertEqual(len(list(nx.connected_components(g))), 2)

        manager = ConnectManager(self.db, strategy="combine")
        m1, m2 = manager.get_connect_job()
        self.connect_min(m1, m2)

        # they should all be connected now
        g = database2graph(self.db)
        self.assertEqual(len(list(nx.connected_components(g))), 1)
Example #11
0
    def __init__(self, system, database, parent=None, app=None):
        ConnectViewer.__init__(self, system, database, app=app, parent=parent)
        self.setWindowTitle("Connect all")

        self.wgt_dgraph = DGraphWidget(database=self.database, parent=self)
        self.connect_manager = ConnectManager(database)
        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()

        # add combo box to toolbar
        self.combobox = Qt.QComboBox()
        self.ui.toolBar.addWidget(self.combobox)
        self.combobox.addItems(
            ["connect strategy:", "random", "global min", "untrap", "combine"])
        self.combobox.setToolTip(
            "the strategy used to select which minima to connect")
def create_random_database(nmin=20, nts=20):
    db = Database()

    for i in range(nmin):
        energy = np.random.uniform(-1., 10.)
        x = [energy]
        db.addMinimum(energy, x)

    manager = ConnectManager(db, verbosity=0)
    for i in range(old_div(nts, 2)):
        m1, m2 = manager.get_connect_job("gmin")
        energy = max([m1.energy, m2.energy]) + np.random.uniform(1, 10)
        x = [energy]
        db.addTransitionState(energy, x, m1, m2)
    for i in range(old_div(nts, 2)):
        m1, m2 = manager.get_connect_job("random")
        energy = max([m1.energy, m2.energy]) + np.random.uniform(1, 5)
        x = [energy]
        db.addTransitionState(energy, x, m1, m2)

    return db
Example #13
0
def create_random_database(nmin=20, nts=20):
    db = Database()
    
    for i in xrange(nmin):
        energy = np.random.uniform(-1., 10.)
        x = [energy]
        db.addMinimum(energy, x)
    
    manager = ConnectManager(db, verbosity=0)
    for i in xrange(nts/2):
        m1, m2 = manager.get_connect_job("gmin")
        energy = max([m1.energy, m2.energy]) + np.random.uniform(1,10)
        x = [energy]
        db.addTransitionState(energy, x, m1, m2)
    for i in xrange(nts/2):
        m1, m2 = manager.get_connect_job("random")
        energy = max([m1.energy, m2.energy]) + np.random.uniform(1,5)
        x = [energy]
        db.addTransitionState(energy, x, m1, m2)
    
    return db
Example #14
0
def test_script():
    natoms = 24
    boxl = 3
    boxvec = np.ones(3) * boxl
    # system = MorseCluster(natoms, rho=1.6047, r0=2.8970, A=0.7102, rcut=9.5)
    radii = np.ones(natoms) * .6
    system = SoftSphereSystem(radii, boxvec, power=2.5)
    
    db = system.create_database()
    
    bh = system.get_basinhopping(db)
    bh.run(100)
    
    from pele.landscape import ConnectManager
    manager = ConnectManager(db, strategy="random")
    for i in xrange(10):
        try:
            m1, m2 = manager.get_connect_job()
        except manager.NoMoreConnectionsError:
            break
        
        connect = system.get_double_ended_connect(m1, m2, db)
        connect.connect()
Example #15
0
def test_script():
    natoms = 24
    boxl = 3
    boxvec = np.ones(3) * boxl
    # system = MorseCluster(natoms, rho=1.6047, r0=2.8970, A=0.7102, rcut=9.5)
    radii = np.ones(natoms) * .6
    system = SoftSphereSystem(radii, boxvec, power=2.5)
    
    db = system.create_database()
    
    bh = system.get_basinhopping(db)
    bh.run(100)
    
    from pele.landscape import ConnectManager
    manager = ConnectManager(db, strategy="random")
    for i in range(10):
        try:
            m1, m2 = manager.get_connect_job()
        except manager.NoMoreConnectionsError:
            break
        
        connect = system.get_double_ended_connect(m1, m2, db)
        connect.connect()
Example #16
0
    def __init__(self, system, database, parent=None, app=None):
        ConnectViewer.__init__(self, system, database, app=app, parent=parent)
        self.setWindowTitle("Connect all")

        self.wgt_dgraph = DGraphWidget(database=self.database, parent=self)
        self.connect_manager = ConnectManager(database)
        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()
        
        # add combo box to toolbar
        self.combobox = Qt.QComboBox()
        self.ui.toolBar.addWidget(self.combobox)
        self.combobox.addItems(["connect strategy:",
                                "random",
                                "global min",
                                "untrap",
                                "combine"])
        self.combobox.setToolTip("the strategy used to select which minima to connect")
Example #17
0
class ConnectServer(object):
    """
    Server which receives requests from, and passes connect jobs to the workers

    The server also receives minima and transition states from the workers
    and adds them to the database.

    Parameters
    ----------
    system : pele.system.BaseSystem
        system class to process
    database : pele.storage.Database
        working database
    server_name : string, optional
        Unique name for clients to connect to this server on current host
        (objid for pyros). None for random
    host : string, optional
        host to setup server. default is localhost which does not allow connections
        from remote machines
    port : integer, optional
        port to listen for connections

    See Also
    --------
    ConnectWorker
    pele.landscape.ConnectManager
    """
    def __init__(self, system, database, server_name=None, host=None, port=0):
        self.system = system
        self.db = database
        self.server_name = server_name
        self.host = host
        self.port = port

        self.connect_manager = ConnectManager(self.db)

    def set_connect_manager(self, connect_manager):
        """add a custom connect manager
        
        the connect manager decides which connect jobs should be performed
        """
        self.connect_manager = connect_manager


#    def set_emax(self, Emax):
#        raise Exception("set_emax is not implemented yet in the new ConnectManager scheme")
#        self.Emax = None

    def get_connect_job(self, strategy="random"):
        """ get a new connect job """
        min1, min2 = self.connect_manager.get_connect_job(strategy)
        return min1.id(), min1.coords, min2.id(), min2.coords

    def get_system(self):
        """ provide system class to worker """
        return self.system

    def add_minimum(self, E, coords):
        """ called by worker if a new minimum is found

        Returns
        -------
        ID : global id of minimum added.
        """
        print("a client found a minimum", E)
        m = self.db.addMinimum(E, coords)
        return m.id()

    def add_ts(self, id1, id2, E, coords, eigenval=None, eigenvec=None):
        """called by worker if a new transition state is found

        Parameters
        ----------
        id1, id2 : int
            The server-side (global) ID's of the minima on either side of the transition state.
            The worker is responsible for knowing the global id of the minima.  This ID is returned
            to the worker when a minimum is added
        E : float
            energy of transition state
        coords : array
            coordinates of transition state

        Returns
        -------
        ID : global id of transition state added
        """
        print("a client found a transition state", E)
        min1 = self.db.getMinimum(id1)
        min2 = self.db.getMinimum(id2)

        ts = self.db.addTransitionState(E,
                                        coords,
                                        min1,
                                        min2,
                                        eigenval=eigenval,
                                        eigenvec=eigenvec)
        return ts.id()

    def run(self):
        """ start the server and listen for incoming connections """
        print("Starting Pyros daemon")
        daemon = Pyro4.Daemon(host=self.host, port=self.port)
        # make the connect_server available to Pyros children
        uri = daemon.register(self, objectId=self.server_name)
        print("The connect server can be accessed by the following uri: ", uri)

        print("Ready to accept connections")
        daemon.requestLoop()
Example #18
0
#
# first use the logging module to turn off the status messages
logger = logging.getLogger("pele.connect")
logger.setLevel("WARNING")
# now create the double ended connect object
connect = system.get_double_ended_connect(m1, m2, db)
connect.connect()
mints, S, energies = connect.returnPath()
nts = (len(mints) - 1) / 2
print "\nprint found a connection with", nts, "transition states"

# connect all minima to the lowest minimum
print "now connecting all the minima to the lowest energy minimum"
from pele.landscape import ConnectManager

manager = ConnectManager(db, strategy="gmin")
for i in xrange(db.number_of_minima() - 1):
    print "connecting minima with id's", m1._id, m2._id
    m1, m2 = manager.get_connect_job()
    connect = system.get_double_ended_connect(m1, m2, db)
    connect.connect()

# print some data about the database
print "database summary:"
print "    ", len(db.minima()), "minima"
print "    ", len(db.transition_states()), "transition states"

# finally, create a disconnectivity graph from the database
print "computing and showing disconnectivity graph"
import pylab as pl
Example #19
0
class ConnectAllDialog(ConnectViewer):
    """define the Connect All dialog
    
    This class manages connecting minima in the database.  It selects which
    minima to connect and submits the job in a separate process.  It deals with
    any messages (such as new minima and transition states) sent from that process.
    When the process ends it starts a new one.
    """
    def __init__(self, system, database, parent=None, app=None):
        ConnectViewer.__init__(self, system, database, app=app, parent=parent)
        self.setWindowTitle("Connect all")

        self.wgt_dgraph = DGraphWidget(database=self.database, parent=self)
        self.connect_manager = ConnectManager(database)
        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()
        
        # add combo box to toolbar
        self.combobox = Qt.QComboBox()
        self.ui.toolBar.addWidget(self.combobox)
        self.combobox.addItems(["connect strategy:",
                                "random",
                                "global min",
                                "untrap",
                                "combine"])
        self.combobox.setToolTip("the strategy used to select which minima to connect")

    def do_one_connection(self, min1, min2):
        """start one connect job with the given minima"""
        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.process_time()
        self.decrunner.start()

    def _get_connect_strategy(self):
        """read from the combobox which connect strategy to use"""
        text = self.combobox.currentText()
        if "random" in text:
            return "random"
        elif "global" in text:
            return "gmin"
        elif "untrap" in text:
            return "untrap"
        elif "combine" in text:
            return "combine"
        else:
            return "random"

    def do_next_connect(self):
        """do another connect job"""
        self.is_running = True
        strategy = self._get_connect_strategy()
        
        self.min1, self.min2 = self.connect_manager.get_connect_job(strategy=strategy)
#        if self.ui.actionRandom_connect.isChecked():
#        else:
#            self.min1, self.min2 = self.connect_manager.get_connect_job(strategy="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):
        """this is called to start submitting jobs again"""
        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):
        """update the disconnectivity graph"""
        if self.view_dgraph.isVisible():
            self.wgt_dgraph.rebuild_disconnectivity_graph()

    def update_summary_view(self):
        """update the summary text"""
        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.process_time()
        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()
Example #20
0
class ConnectServer(object):
    """
    Server which receives requests from, and passes connect jobs to the workers

    The server also receives minima and transition states from the workers
    and adds them to the database.

    Parameters
    ----------
    system : pele.system.BaseSystem
        system class to process
    database : pele.storage.Database
        working database
    server_name : string, optional
        Unique name for clients to connect to this server on current host
        (objid for pyros). None for random
    host : string, optional
        host to setup server. default is localhost which does not allow connections
        from remote machines
    port : integer, optional
        port to listen for connections

    See Also
    --------
    ConnectWorker
    pele.landscape.ConnectManager
    """
    
    def __init__(self, system, database, server_name=None, host=None, port=0):
        self.system = system
        self.db = database
        self.server_name = server_name
        self.host=host
        self.port=port
        
        self.connect_manager = ConnectManager(self.db)

    def set_connect_manager(self, connect_manager):
        """add a custom connect manager
        
        the connect manager decides which connect jobs should be performed
        """
        self.connect_manager = connect_manager
        
#    def set_emax(self, Emax):
#        raise Exception("set_emax is not implemented yet in the new ConnectManager scheme")
#        self.Emax = None

    def get_connect_job(self, strategy="random"):
        """ get a new connect job """
        min1, min2 = self.connect_manager.get_connect_job(strategy)
        return min1.id(), min1.coords, min2.id(), min2.coords

    def get_system(self):
        """ provide system class to worker """
        return self.system
    
    def add_minimum(self, E, coords):
        """ called by worker if a new minimum is found

        Returns
        -------
        ID : global id of minimum added.
        """
        print("a client found a minimum", E)
        m = self.db.addMinimum(E, coords)
        return m.id()
    
    def add_ts(self, id1, id2, E, coords, eigenval=None, eigenvec=None):
        """called by worker if a new transition state is found

        Parameters
        ----------
        id1, id2 : int
            The server-side (global) ID's of the minima on either side of the transition state.
            The worker is responsible for knowing the global id of the minima.  This ID is returned
            to the worker when a minimum is added
        E : float
            energy of transition state
        coords : array
            coordinates of transition state

        Returns
        -------
        ID : global id of transition state added
        """
        print("a client found a transition state", E)
        min1 = self.db.getMinimum(id1)
        min2 = self.db.getMinimum(id2)
        
        ts = self.db.addTransitionState(E, coords, min1, min2, eigenval=eigenval, eigenvec=eigenvec)
        return ts.id()

    def run(self):
        """ start the server and listen for incoming connections """
        print("Starting Pyros daemon")
        daemon=Pyro4.Daemon(host=self.host, port=self.port)
        # make the connect_server available to Pyros children
        uri=daemon.register(self, objectId=self.server_name)
        print("The connect server can be accessed by the following uri: ", uri)
        
        print("Ready to accept connections")
        daemon.requestLoop() 
Example #21
0
 def test_random(self):
     manager = ConnectManager(self.db, strategy="random")
     
     for i in range(5):
         m1, m2 = manager.get_connect_job()
         self.connect_min(m1, m2)
Example #22
0
class ConnectAllDialog(ConnectViewer):
    """define the Connect All dialog
    
    This class manages connecting minima in the database.  It selects which
    minima to connect and submits the job in a separate process.  It deals with
    any messages (such as new minima and transition states) sent from that process.
    When the process ends it starts a new one.
    """
    def __init__(self, system, database, parent=None, app=None):
        ConnectViewer.__init__(self, system, database, app=app, parent=parent)
        self.setWindowTitle("Connect all")

        self.wgt_dgraph = DGraphWidget(database=self.database, parent=self)
        self.connect_manager = ConnectManager(database)
        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()
        
        # add combo box to toolbar
        self.combobox = Qt.QComboBox()
        self.ui.toolBar.addWidget(self.combobox)
        self.combobox.addItems(["connect strategy:",
                                "random",
                                "global min",
                                "untrap",
                                "combine"])
        self.combobox.setToolTip("the strategy used to select which minima to connect")

    def do_one_connection(self, min1, min2):
        """start one connect job with the given minima"""
        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_connect_strategy(self):
        """read from the combobox which connect strategy to use"""
        text = self.combobox.currentText()
        if "random" in text:
            return "random"
        elif "global" in text:
            return "gmin"
        elif "untrap" in text:
            return "untrap"
        elif "combine" in text:
            return "combine"
        else:
            return "random"

    def do_next_connect(self):
        """do another connect job"""
        self.is_running = True
        strategy = self._get_connect_strategy()
        
        self.min1, self.min2 = self.connect_manager.get_connect_job(strategy=strategy)
#        if self.ui.actionRandom_connect.isChecked():
#        else:
#            self.min1, self.min2 = self.connect_manager.get_connect_job(strategy="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):
        """this is called to start submitting jobs again"""
        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):
        """update the disconnectivity graph"""
        if self.view_dgraph.isVisible():
            self.wgt_dgraph.rebuild_disconnectivity_graph()

    def update_summary_view(self):
        """update the summary text"""
        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()
# find a connected series of minima and transition states between m1 and m2
# 
# first use the logging module to turn off the status messages 
logger = logging.getLogger("pele.connect")
logger.setLevel("WARNING")
# now create the double ended connect object
connect = system.get_double_ended_connect(m1, m2, db)
connect.connect()
mints, S, energies = connect.returnPath()
nts = (len(mints) - 1)/2
print "\nprint found a connection with", nts, "transition states"

# connect all minima to the lowest minimum
print "now connecting all the minima to the lowest energy minimum"
from pele.landscape import ConnectManager
manager = ConnectManager(db, strategy="gmin")
for i in xrange(db.number_of_minima()-1):
    print "connecting minima with id's", m1._id, m2._id
    m1, m2 = manager.get_connect_job()
    connect = system.get_double_ended_connect(m1, m2, db)
    connect.connect()

# print some data about the database
print "database summary:"
print "    ", len(db.minima()), "minima"
print "    ", len(db.transition_states()), "transition states"

# finally, create a disconnectivity graph from the database
print "computing and showing disconnectivity graph"
import pylab as pl
graph = database2graph(db)
Example #24
0
    def test_random(self):
        manager = ConnectManager(self.db, strategy="random")

        for i in range(5):
            m1, m2 = manager.get_connect_job()
            self.connect_min(m1, m2)