Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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 : pygmin.system.BaseSystem
        system class to process
    database : pygmin.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
    pygmin.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.session.query(Minimum).filter(Minimum._id == id1).one()
#        min2 = self.db.session.query(Minimum).filter(Minimum._id == id2).one()
        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 childs
        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() 
Exemplo n.º 4
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 : pygmin.system.BaseSystem
        system class to process
    database : pygmin.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
    pygmin.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.session.query(Minimum).filter(Minimum._id == id1).one()
        #        min2 = self.db.session.query(Minimum).filter(Minimum._id == id2).one()
        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 childs
        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()