コード例 #1
0
ファイル: test_distance_graph.py プロジェクト: spraharsh/pele
    def setUp(self):
        nmin = 10
        natoms = 13

        sys = LJCluster(natoms)

        pot = sys.get_potential()
        mindist = sys.get_mindist()

        db = create_random_database(nmin=nmin,
                                    natoms=natoms,
                                    nts=old_div(nmin, 2))
        min1, min2 = list(db.minima())[:2]

        self.db = db
        self.natoms = natoms
        self.connect = DoubleEndedConnect(min1,
                                          min2,
                                          pot,
                                          mindist,
                                          db,
                                          merge_minima=True,
                                          max_dist_merge=1e100)
        #        for ts in db.transition_states():
        #            self.add_ts(ts.energy, ts.coords,
        #                        ts.minimum1.energy, ts.minimum1.coords,
        #                        ts.minimum2.energy, ts.minimum2.coords)
        for m in db.minima():
            self.connect.dist_graph.addMinimum(m)
コード例 #2
0
    def setUp(self):
#        from pele.mindist import minPermDistStochastic, MinDistWrapper
#        from pele.potentials import LJ
        
        nmin = 10
        natoms=13
        
        sys = LJCluster(natoms)
        
        pot = sys.get_potential()
        mindist = sys.get_mindist()
        
        db = create_random_database(nmin=nmin, natoms=natoms, nts=nmin/2)
        min1, min2 = list(db.minima())[:2]
        
        
        self.db = db
        self.natoms = natoms
        self.connect = DoubleEndedConnect(min1, min2, pot, mindist, db,
                                          merge_minima=True, max_dist_merge=1e100)
#        for ts in db.transition_states():
#            self.add_ts(ts.energy, ts.coords, 
#                        ts.minimum1.energy, ts.minimum1.coords,
#                        ts.minimum2.energy, ts.minimum2.coords)
        for m in db.minima():
            self.connect.dist_graph.addMinimum(m)
コード例 #3
0
ファイル: basesystem.py プロジェクト: spraharsh/pele
    def get_double_ended_connect(self, min1, min2, database, **kwargs):
        """return a DoubleEndedConnect object
    
        See Also
        --------
        pele.landscape
        """
        kwargs = dict_copy_update(self.params["double_ended_connect"], kwargs)
        pot = self.get_potential()
        mindist = self.get_mindist()

        # attach the function which orthogonalizes to known zero eigenvectors.
        # This is amazingly ugly
        # vr: yea, we should polish this parameters stuff and give create policies instead!
        try:
            kwargs["local_connect_params"]["tsSearchParams"]["orthogZeroEigs"]
        except KeyError:
            if "local_connect_params" in kwargs:
                lcp = kwargs["local_connect_params"]
            else:
                lcp = kwargs["local_connect_params"] = BaseParameters()

            if "tsSearchParams" in lcp:
                tssp = lcp["tsSearchParams"]
            else:
                tssp = lcp["tsSearchParams"] = BaseParameters()

            if not "orthogZeroEigs" in tssp:
                tssp[
                    "orthogZeroEigs"] = self.get_orthogonalize_to_zero_eigenvectors(
                    )

        try:
            kwargs["local_connect_params"]["pushoff_params"]["quench"]
        except Exception:
            if not "pushoff_params" in kwargs["local_connect_params"]:
                kwargs["local_connect_params"][
                    "pushoff_params"] = BaseParameters()
            kwargs["local_connect_params"]["pushoff_params"][
                "quench"] = self.get_minimizer()

        return DoubleEndedConnect(min1, min2, pot, mindist, database, **kwargs)
コード例 #4
0
    def test2(self):
        from pele.storage import Database
        from pele.systems import LJCluster
        np.random.seed(0)

        natoms = 13
        system = LJCluster(natoms)
        pot = system.get_potential()
        mindist = system.get_mindist(niter=1)
        
        db = Database()
        db.addMinimum(pot.getEnergy(_x1), _x1)
        db.addMinimum(pot.getEnergy(_x2), _x2)
        m1, m2 = db.minima()
        
        connect = DoubleEndedConnect(m1, m2, pot, mindist, db, verbosity=10)
        connect.connect()
        self.assertTrue(connect.success())
        
        path = connect.returnPath()
コード例 #5
0
ファイル: test_distance_graph.py プロジェクト: dimaslave/pele
class TestDistanceGraph(unittest.TestCase):
    def setUp(self):
        nmin = 10
        natoms=13
        
        sys = LJCluster(natoms)
        
        pot = sys.get_potential()
        mindist = sys.get_mindist()
        
        db = create_random_database(nmin=nmin, natoms=natoms, nts=nmin/2)
        min1, min2 = list(db.minima())[:2]
        
        
        self.db = db
        self.natoms = natoms
        self.connect = DoubleEndedConnect(min1, min2, pot, mindist, db,
                                          merge_minima=True, max_dist_merge=1e100)
#        for ts in db.transition_states():
#            self.add_ts(ts.energy, ts.coords, 
#                        ts.minimum1.energy, ts.minimum1.coords,
#                        ts.minimum2.energy, ts.minimum2.coords)
        for m in db.minima():
            self.connect.dist_graph.addMinimum(m)
    
    def make_result(self, coords, energy):
        from pele.optimize import Result
        res = Result()
        res.coords = coords
        res.energy = energy
        res.eigenval = 1.
        res.eigenvec = coords.copy()
        return res

    def add_ts(self, tse, tsx, m1e, m1x, m2e, m2x):
        tsres = self.make_result(tsx, tse)
        min_ret1 = self.make_result(m1x, m1e)
        min_ret2 = self.make_result(m2x, m2e)
        return self.connect._addTransitionState(tsres, min_ret1, min_ret2)

    
    def test_merge_minima(self):
        """merge two minima and make sure the distance graph is still ok"""
        min3, min4 = list(self.db.minima())[2:4]
        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "the distance graph is broken at the start")

        print min3._id, min4._id, "are connected", self.connect.graph.areConnected(min3, min4)
        print min3._id, "number of edges", self.connect.graph.graph.degree(min3)
        print min4._id, "number of edges", self.connect.graph.graph.degree(min4)
        self.connect.mergeMinima(min3, min4)
        
        self.assertNotIn(min4, self.connect.graph.graph)
        self.assertNotIn(min4, self.connect.dist_graph.Gdist)
        self.assertNotIn(min4, self.db.minima())
        
        allok = self.connect.dist_graph.checkGraph()
        
        
        self.assertTrue(allok, "merging broke the distance graph")
        
    def test_add_TS_existing_minima(self):
        from pele.optimize import Result
        min3, min4 = list(self.db.minima())[4:6]
        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "the distance graph is broken at the start")

        print min3._id, min4._id, "are connected", self.connect.graph.areConnected(min3, min4)
        print min3._id, "number of edges", self.connect.graph.graph.degree(min3)
        print min4._id, "number of edges", self.connect.graph.graph.degree(min4)
        
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = float(min3.energy + min4.energy)
        tsres = self.make_result(coords, E)
        min_ret1 = self.make_result(min3.coords, min3.energy)
        min_ret2 = self.make_result(min4.coords, min4.energy)
        
       
        self.connect._addTransitionState(tsres, min_ret1, min_ret2)

        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "adding a transition state broke the distance graph")
        

    def test_add_TS_new_minima(self):
        min3 = list(self.db.minima())[6]
        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "the distance graph is broken at the start")

#        print min3._id, min4._id, "are connected", self.connect.graph.areConnected(min3, min4)
        print min3._id, "number of edges", self.connect.graph.graph.degree(min3)

        #create new minimum from thin air
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = np.random.rand()*10.
        min_ret1 = self.make_result(min3.coords, min3.energy)
        min_ret2 = self.make_result(coords, E)

#        min_ret2 = [coords, E]
#        min_ret1 = [min3.coords, min3.energy]


        #create new TS from thin air        
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = float(min3.energy + min_ret2.energy)
        tsres = self.make_result(coords, E)
        
        self.connect._addTransitionState(tsres, min_ret1, min_ret2)

        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "adding a transition state broke the distance graph")

    def run_add_TS(self, min3, min4, nocheck=False):
        if not nocheck:
            allok = self.connect.dist_graph.checkGraph()
            self.assertTrue(allok, "the distance graph is broken at the start")

        print min3._id, min4._id, "are connected", self.connect.graph.areConnected(min3, min4)
        print min3._id, "number of edges", self.connect.graph.graph.degree(min3)
        print min4._id, "number of edges", self.connect.graph.graph.degree(min4)
        
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = float(min3.energy + min4.energy)
        tsres = self.make_result(coords, E)
        min_ret1 = self.make_result(min3.coords, min3.energy)
        min_ret2 = self.make_result(min4.coords, min4.energy)

#        min_ret1 = [min3.coords, min3.energy]
#        min_ret2 = [min4.coords, min4.energy]
        
        self.connect._addTransitionState(tsres, min_ret1, min_ret2)

        if not nocheck:
            allok = self.connect.dist_graph.checkGraph()
            self.assertTrue(allok, "adding a transition state broke the distance graph")


    def test_add_TS_existing_not_connected(self):
        minima = list(self.db.minima())
        min3 = minima[2]
        for min4 in minima[3:]:
            if not self.connect.graph.areConnected(min3, min4):
                break
        self.run_add_TS(min3, min4)
        
    def test_add_TS_existing_already_connected(self):
        minima = list(self.db.minima())
        min3 = minima[2]
        for min4 in minima[3:]:
            if self.connect.graph.areConnected(min3, min4):
                break
        self.run_add_TS(min3, min4)
    
    def test_add_TS_multiple(self):
        minima = list(self.db.minima())
        min3 = minima[2]
        nnew = 4
        for min4 in minima[3:3+nnew]:
            self.run_add_TS(min3, min4, nocheck=True)

        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "adding multiple transition states broke the distance graph")
コード例 #6
0
class TestDistanceGraph(unittest.TestCase):
    def setUp(self):
        nmin = 10
        natoms=13
        
        sys = LJCluster(natoms)
        
        pot = sys.get_potential()
        mindist = sys.get_mindist()
        
        db = create_random_database(nmin=nmin, natoms=natoms, nts=nmin/2)
        min1, min2 = list(db.minima())[:2]
        
        
        self.db = db
        self.natoms = natoms
        self.connect = DoubleEndedConnect(min1, min2, pot, mindist, db,
                                          merge_minima=True, max_dist_merge=1e100)
#        for ts in db.transition_states():
#            self.add_ts(ts.energy, ts.coords, 
#                        ts.minimum1.energy, ts.minimum1.coords,
#                        ts.minimum2.energy, ts.minimum2.coords)
        for m in db.minima():
            self.connect.dist_graph.addMinimum(m)
    
    def make_result(self, coords, energy):
        from pele.optimize import Result
        res = Result()
        res.coords = coords
        res.energy = energy
        res.eigenval = 1.
        res.eigenvec = coords.copy()
        return res

    def add_ts(self, tse, tsx, m1e, m1x, m2e, m2x):
        tsres = self.make_result(tsx, tse)
        min_ret1 = self.make_result(m1x, m1e)
        min_ret2 = self.make_result(m2x, m2e)
        return self.connect._addTransitionState(tsres, min_ret1, min_ret2)

    
    def test_merge_minima(self):
        # merge two minima and make sure the distance graph is still ok
        min3, min4 = list(self.db.minima())[2:4]
        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "the distance graph is broken at the start")

        print min3.id(), min4.id(), "are connected", self.connect.graph.areConnected(min3, min4)
        print min3.id(), "number of edges", self.connect.graph.graph.degree(min3)
        print min4.id(), "number of edges", self.connect.graph.graph.degree(min4)
        self.connect.mergeMinima(min3, min4)
        
        self.assertNotIn(min4, self.connect.graph.graph)
        self.assertNotIn(min4, self.connect.dist_graph.Gdist)
        self.assertNotIn(min4, self.db.minima())
        
        allok = self.connect.dist_graph.checkGraph()
        
        
        self.assertTrue(allok, "merging broke the distance graph")
        
    def test_add_TS_existing_minima(self):
        min3, min4 = list(self.db.minima())[4:6]
        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "the distance graph is broken at the start")

        print min3.id(), min4.id(), "are connected", self.connect.graph.areConnected(min3, min4)
        print min3.id(), "number of edges", self.connect.graph.graph.degree(min3)
        print min4.id(), "number of edges", self.connect.graph.graph.degree(min4)
        
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = float(min3.energy + min4.energy)
        tsres = self.make_result(coords, E)
        min_ret1 = self.make_result(min3.coords, min3.energy)
        min_ret2 = self.make_result(min4.coords, min4.energy)
        
       
        self.connect._addTransitionState(tsres, min_ret1, min_ret2)

        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "adding a transition state broke the distance graph")
        

    def test_add_TS_new_minima(self):
        min3 = list(self.db.minima())[6]
        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "the distance graph is broken at the start")

#        print min3.id(), min4.id(), "are connected", self.connect.graph.areConnected(min3, min4)
        print min3.id(), "number of edges", self.connect.graph.graph.degree(min3)

        #create new minimum from thin air
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = np.random.rand()*10.
        min_ret1 = self.make_result(min3.coords, min3.energy)
        min_ret2 = self.make_result(coords, E)

#        min_ret2 = [coords, E]
#        min_ret1 = [min3.coords, min3.energy]


        #create new TS from thin air        
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = float(min3.energy + min_ret2.energy)
        tsres = self.make_result(coords, E)
        
        self.connect._addTransitionState(tsres, min_ret1, min_ret2)

        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "adding a transition state broke the distance graph")

    def run_add_TS(self, min3, min4, nocheck=False):
        if not nocheck:
            allok = self.connect.dist_graph.checkGraph()
            self.assertTrue(allok, "the distance graph is broken at the start")

        print min3.id(), min4.id(), "are connected", self.connect.graph.areConnected(min3, min4)
        print min3.id(), "number of edges", self.connect.graph.graph.degree(min3)
        print min4.id(), "number of edges", self.connect.graph.graph.degree(min4)
        
        coords = np.random.uniform(-1,1,self.natoms*3)
        E = float(min3.energy + min4.energy)
        tsres = self.make_result(coords, E)
        min_ret1 = self.make_result(min3.coords, min3.energy)
        min_ret2 = self.make_result(min4.coords, min4.energy)

#        min_ret1 = [min3.coords, min3.energy]
#        min_ret2 = [min4.coords, min4.energy]
        
        self.connect._addTransitionState(tsres, min_ret1, min_ret2)

        if not nocheck:
            allok = self.connect.dist_graph.checkGraph()
            self.assertTrue(allok, "adding a transition state broke the distance graph")


    def test_add_TS_existing_not_connected(self):
        minima = list(self.db.minima())
        min3 = minima[2]
        for min4 in minima[3:]:
            if not self.connect.graph.areConnected(min3, min4):
                break
        self.run_add_TS(min3, min4)
        
    def test_add_TS_existing_already_connected(self):
        minima = list(self.db.minima())
        min3 = minima[2]
        for min4 in minima[3:]:
            if self.connect.graph.areConnected(min3, min4):
                break
        self.run_add_TS(min3, min4)
    
    def test_add_TS_multiple(self):
        minima = list(self.db.minima())
        min3 = minima[2]
        nnew = 4
        for min4 in minima[3:3+nnew]:
            self.run_add_TS(min3, min4, nocheck=True)

        allok = self.connect.dist_graph.checkGraph()
        self.assertTrue(allok, "adding multiple transition states broke the distance graph")
コード例 #7
0
    NEBquenchParams["iprint"] = 100
    
    NEBparams = dict()
    NEBparams["k"] = 5.
    NEBparams["image_density"] = 15
    NEBparams["NEBquenchParams"] = NEBquenchParams
    
    local_connect_params = dict()
    local_connect_params["tsSearchParams"] = tsSearchParams
    local_connect_params["NEBparams"] = NEBparams




myconnect = DoubleEndedConnect(
        min1, min2, pot, mindist, database,
        local_connect_params=local_connect_params,
        )

if (myconnect.graph.areConnected(min1, min2)):
    print "ALERT: The minima are already connected in the database file", dbfile
    print "       Delete it for a fresh run."

myconnect.connect()
print ""
print "found a path!"



#the path is now saved in the database.  Lets retrieve it and 
#print it in a more visual format
#now retrieve the path for printing
コード例 #8
0
    tsSearchParams["nfail_max"] = 200

    NEBquenchParams = dict()
    NEBquenchParams["iprint"] = 100

    NEBparams = dict()
    NEBparams["k"] = 5.
    NEBparams["image_density"] = 15
    NEBparams["NEBquenchParams"] = NEBquenchParams

    local_connect_params = dict()
    local_connect_params["tsSearchParams"] = tsSearchParams
    local_connect_params["NEBparams"] = NEBparams

myconnect = DoubleEndedConnect(min1, min2, pot, mindist, database,
                               local_connect_params=local_connect_params,
)

if (myconnect.graph.areConnected(min1, min2)):
    print "ALERT: The minima are already connected in the database file", dbfile
    print "       Delete it for a fresh run."

myconnect.connect()
print ""
print "found a path!"



# the path is now saved in the database.  Lets retrieve it and 
# print it in a more visual format
# now retrieve the path for printing