コード例 #1
0
ファイル: _graph.py プロジェクト: wwwtyro/PyGMIN
def create_random_database(nmin=20, nts=None, natoms=2):
    """
    create a database for test purposes
    """
    from pygmin.storage import Database
    import numpy as np
    
    if nts is None:
        nts = nmin
    db = Database()
    #generate random structures
    minlist = []
    for i in range(nmin):
        coords = np.random.uniform(-1,1,natoms*3)
        e = float(i) #make up a fake energy
        minlist.append( db.addMinimum(e, coords) )
    #add random transition states
    for i in range(nts):
        j1, j2 = 1, 1
        while j1 == j2:
            j1, j2 = np.random.randint(0, nmin, 2)
        m1, m2 = minlist[j1], minlist[j2] 
        coords = np.random.uniform(-1,1,natoms*3)
        e = float(j1 + j2)
        db.addTransitionState(e, coords, m1, m2)
    return db
コード例 #2
0
ファイル: _graph.py プロジェクト: yfyh2013/PyGMIN
def create_random_database(nmin=20, nts=None, natoms=2):
    """
    create a database for test purposes
    """
    from pygmin.storage import Database
    import numpy as np
    
    if nts is None:
        nts = nmin
    db = Database()
    #generate random structures
    minlist = []
    for i in range(nmin):
        coords = np.random.uniform(-1,1,natoms*3)
        e = float(i) #make up a fake energy
        minlist.append( db.addMinimum(e, coords) )
    #add random transition states
    for i in range(nts):
        j1, j2 = 1, 1
        while j1 == j2:
            j1, j2 = np.random.randint(0, nmin, 2)
        m1, m2 = minlist[j1], minlist[j2] 
        coords = np.random.uniform(-1,1,natoms*3)
        e = float(j1 + j2)
        db.addTransitionState(e, coords, m1, m2)
    return db
コード例 #3
0
ファイル: local_connect.py プロジェクト: yfyh2013/PyGMIN
def test():
    from pygmin.storage import Database
    coords1, coords2, pot, mindist, E1, E2 = getPairLJ()
    db = Database()
    min1 = db.addMinimum(E1, coords1)
    min2 = db.addMinimum(E2, coords2)

    local_connect = LocalConnect(pot, mindist)
    local_connect.connect(min1, min2)
コード例 #4
0
ファイル: local_connect.py プロジェクト: js850/PyGMIN
def test():
    from pygmin.storage import Database
    coords1, coords2, pot, mindist, E1, E2 = getPairLJ()
    db = Database()
    min1 = db.addMinimum(E1, coords1)
    min2 = db.addMinimum(E2, coords2)
    
    
    local_connect = LocalConnect(pot, mindist)
    local_connect.connect(min1, min2)
コード例 #5
0
    def create_database(self, *args, **kwargs):
        """return a new database object
        
        See Also
        --------
        pygmin.storage
        """
        kwargs = dict_copy_update(self.params["database"], kwargs)
        #note this syntax is quite ugly, but we would like to be able to
        #create a new database by passing the filename as the first arg,
        #not as a kwarg.
        if len(args) > 1:
            raise ValueError(
                "create_database can only take one non-keyword argument")
        if len(args) == 1:
            if "db" not in kwargs:
                kwargs["db"] = args[0]

        #get a routine to compare the minima as exact
        try:
            if not "compareMinima" in kwargs:
                try:
                    compare_minima = self.get_compare_minima()
                    kwargs["compareMinima"] = compare_minima
                except NotImplementedError:
                    pass
        except NotImplementedError:
            #compareMinima is optional
            pass

        return Database(**kwargs)
コード例 #6
0
ファイル: neb_explorer.py プロジェクト: js850/PyGMIN
 def create_neb(self, coords1, coords2):
     """setup the NEB object"""
     system = self.system
     
     throwaway_db = Database()
     min1 = throwaway_db.addMinimum(0., coords1)
     min2 = throwaway_db.addMinimum(1., coords2)
     #use the functions in DoubleEndedConnect to set up the NEB in the proper way
     double_ended = system.get_double_ended_connect(min1, min2, 
                                                    throwaway_db, 
                                                    fresh_connect=True)
     local_connect = double_ended._getLocalConnectObject()
 
     self.local_connect = local_connect
     
     return local_connect.create_neb(system.get_potential(),
                                       coords1, coords2,
                                       **local_connect.NEBparams)        
コード例 #7
0
    def create_neb(self, coords1, coords2):
        """setup the NEB object"""
        system = self.system

        throwaway_db = Database()
        min1 = throwaway_db.addMinimum(0., coords1)
        min2 = throwaway_db.addMinimum(1., coords2)
        #use the functions in DoubleEndedConnect to set up the NEB in the proper way
        double_ended = system.get_double_ended_connect(min1,
                                                       min2,
                                                       throwaway_db,
                                                       fresh_connect=True)
        local_connect = double_ended._getLocalConnectObject()

        self.local_connect = local_connect

        return local_connect.create_neb(system.get_potential(), coords1,
                                        coords2, **local_connect.NEBparams)
コード例 #8
0
ファイル: nebdlg.py プロジェクト: js850/PyGMIN
def getNEB(coords1, coords2, system):
    """setup the NEB object"""
    throwaway_db = Database()
    min1 = throwaway_db.addMinimum(0., coords1)
    min2 = throwaway_db.addMinimum(1., coords2)
    #use the functions in DoubleEndedConnect to set up the NEB in the proper way
    double_ended = system.get_double_ended_connect(min1, min2, 
                                                        throwaway_db, 
                                                        fresh_connect=True)
    local_connect = double_ended._getLocalConnectObject()

    
    
    neb =  local_connect._getNEB(system.get_potential(),
                                      coords1, coords2,
                                      verbose=True,
                                      **local_connect.NEBparams)        
    
    return neb
コード例 #9
0
ファイル: test_database.py プロジェクト: js850/PyGMIN
 def setUp(self):
     self.db = Database()
     self.nminima = 10
     for i in range(self.nminima):
         e = float(i)
         self.db.addMinimum(e, [e])
     
     
     self.nts = 3
     self.db.addTransitionState(0., [0.], self.db.minima()[0], self.db.minima()[1], eigenval=0., eigenvec=[0.])
     self.db.addTransitionState(0., [0.], self.db.minima()[1], self.db.minima()[2], eigenval=0., eigenvec=[0.])
     self.db.addTransitionState(0., [0.], self.db.minima()[0], self.db.minima()[2], eigenval=0., eigenvec=[0.])
コード例 #10
0
    def setUp(self):
        self.db = Database()
        self.nminima = 10
        for i in range(self.nminima):
            e = float(i)
            self.db.addMinimum(e, [e])

        self.nts = 3
        self.db.addTransitionState(0., [0.],
                                   self.db.minima()[0],
                                   self.db.minima()[1],
                                   eigenval=0.,
                                   eigenvec=[0.])
        self.db.addTransitionState(0., [0.],
                                   self.db.minima()[1],
                                   self.db.minima()[2],
                                   eigenval=0.,
                                   eigenvec=[0.])
        self.db.addTransitionState(0., [0.],
                                   self.db.minima()[0],
                                   self.db.minima()[2],
                                   eigenval=0.,
                                   eigenvec=[0.])
コード例 #11
0
    def __init__(self,
                 ndof,
                 db_name="Database.db",
                 mindata="min.data",
                 tsdata="ts.data",
                 pointsmin="points.min",
                 pointsts="points.ts",
                 endianness="="):
        self.ndof = ndof
        self.db_name = db_name
        self.mindata = mindata
        self.tsdata = tsdata
        self.pointsmin = pointsmin
        self.pointsts = pointsts
        self.endianness = endianness

        self.db = Database(self.db_name)
コード例 #12
0
ファイル: test_database.py プロジェクト: js850/PyGMIN
def benchmark_number_of_minima():
    import time, sys
    import numpy as np
    db = Database("test.large.db")
    
    if True:
        istart = np.random.randint(0, sys.maxint)
        for i in xrange(istart,istart+10000):
            e = float(i)
            db.addMinimum(e, [e], commit=False)
        db.session.commit()
    else:
        i=1
    
    t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock(); t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock(); t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock(); t1 = time.clock()
    e = float(i+1)
    db.addMinimum(e, [e], commit=False)
    t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock(); t1 = time.clock()

    print len(db.minima())
    print "time", t1 - time.clock(); t1 = time.clock()
コード例 #13
0
ファイル: path.py プロジェクト: wwwtyro/PyGMIN
    path_xyz.append(coords)
    
print "length of path:", len(path_xyz)

path = [ map_to_aa(xyz) for xyz in path_xyz]
#p#ath = [ x for x in IntterpolatedPath(db.minima[19], )]
#path = [ x for x in InterpolatedPath(path[0].copy(), path[-1].copy(), 34) ]
traj = open("traj.xyz", "w")
#for x in path:
#    #export_xyz(traj, x)
#    #ret = quench.mylbfgs(x, pot.getEnergyGradient)
#    #print i,pot.getEnergy(x), ret[1]
#    
#    # export_xyz(traj, ret[0])

db=Database(db="oxdna.sqlite")
path[0]=db.minima()[19].coords
path[-1]=db.minima()[0].coords

e1 = []
e2 = []

e1.append(pot.getEnergy(path[0]))
e2.append(pot.getEnergy(path[0]))

for i in xrange(1):
    for i in xrange(len(path)-1):
        e1.append(pot.getEnergy(path[i+1]))
        c1 = CoordsAdapter(nrigid=13, coords = path[i])
        c2 = CoordsAdapter(nrigid=13, coords = path[i+1])
        com1 = np.sum(c1.posRigid,axis=0) / float(13)
コード例 #14
0
    return db


def make_graph(database):
    #make a graph from the database
    graphwrapper = TSGraph(db)

    #turn the graph into a disconnectivity graph
    mydg = dg.DisconnectivityGraph(
        graphwrapper.graph,
        nlevels=5,
        center_gmin=False,
        order_by_energy=True,
        #                                   Emax=-169.
    )
    mydg.calculate()

    print "number of minima:", mydg.tree_graph.number_of_leaves()
    mydg.plot()
    plt.show()


if __name__ == "__main__":
    if True:
        db = get_database()
    else:
        db = Database("lj38.sqlite")
        #db = Database("database.sqlite.large")

    make_graph(db)
コード例 #15
0
    app = QApplication(sys.argv)

    def process_events():
        app.processEvents()

    #setup system
    natoms = 13
    system = LJCluster(natoms)
    system.params.double_ended_connect.local_connect_params.NEBparams.iter_density = 10.
    system.params.double_ended_connect.local_connect_params.NEBparams.image_density = 3.
    #    system.params.double_ended_connect.local_connect_params.NEBparams.adaptive_nimages = 5.
    system.params.double_ended_connect.local_connect_params.NEBparams.reinterpolate = 400
    system.params.double_ended_connect.local_connect_params.NEBparams.max_images = 40
    x1, e1 = system.get_random_minimized_configuration()[:2]
    x2, e2 = system.get_random_minimized_configuration()[:2]
    db = Database()
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)

    #setup neb dialog
    wnd = ConnectExplorerDialog(system, app)
    wnd.show()

    glutInit()

    #initilize the NEB and run it.
    #we have to do it through QTimer because the gui has to
    #be intitialized first... I don't really understand it
    from PyQt4.QtCore import QTimer
    QTimer.singleShot(10, start)
コード例 #16
0
ファイル: tip4p_dgraph.py プロジェクト: js850/PyGMIN
from pygmin.utils.disconnectivity_graph import DisconnectivityGraph
from pygmin.storage import Database
from pygmin.landscape import TSGraph
import pylab as pl
import numpy as np

kbT = 0.75

db = Database(db="tip4p_8.sqlite", createdb=False)

graph = TSGraph(db)

dg = DisconnectivityGraph(graph.graph, db.minima(), subgraph_size=20)
dg.calculate()
dg.plot()

for m in db.minima():
    if m.pgorder != 2:
        print m.pgorder
    m.free_energy = m.energy + kbT * 0.5*m.fvib + kbT*np.log(m.pgorder)

 
for ts in db.transition_states():
#    if ts.pgorder != 2:
    print ts.pgorder
    #assert ts.pgorder == 2    

    ts.free_energy = ts.energy + kbT * 0.5*ts.fvib + kbT*np.log(ts.pgorder) + kbT*np.log(kbT)
    if ts.free_energy > ts.minimum1.free_energy or ts.free_energy > ts.minimum2.free_energy:        
        print "warning, free energy of transition state lower than minimum"
        print ts.free_energy, ts.minimum1.free_energy, ts.minimum2.free_energy
コード例 #17
0
ファイル: test_database.py プロジェクト: js850/PyGMIN
class TestDB(unittest.TestCase):
    def setUp(self):
        self.db = Database()
        self.nminima = 10
        for i in range(self.nminima):
            e = float(i)
            self.db.addMinimum(e, [e])
        
        
        self.nts = 3
        self.db.addTransitionState(0., [0.], self.db.minima()[0], self.db.minima()[1], eigenval=0., eigenvec=[0.])
        self.db.addTransitionState(0., [0.], self.db.minima()[1], self.db.minima()[2], eigenval=0., eigenvec=[0.])
        self.db.addTransitionState(0., [0.], self.db.minima()[0], self.db.minima()[2], eigenval=0., eigenvec=[0.])

    def test_size(self):
        self.assertEqual(len(self.db.minima()), self.nminima)
        
    def test_energy(self):
        m = self.db.minima()[0]
        self.assertEqual(m.energy, 0.)

    def test_coords(self):
        m = self.db.minima()[0]
        self.assertEqual(m.coords, [0.])

    def test_sizets(self):
        self.assertEqual(len(self.db.transition_states()), self.nts)
    def test_energyts(self):
        ts = self.db.transition_states()[0]
        self.assertEqual(ts.energy, 0.)

    def test_coordsts(self):
        ts = self.db.transition_states()[0]
        self.assertEqual(ts.coords, [0.])
    
    def test_remove_minimum(self):
        m = self.db.minima()[0]
        self.db.removeMinimum(m)
        self.assertEqual(len(self.db.minima()), self.nminima-1)
        self.assertNotIn(m, self.db.minima())
        
        # m should have 2 minima.  both of those should be gone
        self.assertEqual(len(self.db.transition_states()), self.nts-2)

    def test_remove_ts(self):
        ts = self.db.transition_states()[0]
        self.db.remove_transition_state(ts)
        self.assertEqual(self.db.number_of_transition_states(), self.nts-1)
        self.assertNotIn(ts, self.db.transition_states())
        
        # m should have 2 minima.  both of those should be gone
        self.assertEqual(self.db.number_of_minima(), self.nminima)


    def test_getTransitionState(self):
        m1 = self.db.minima()[0]
        m2 = self.db.minima()[1]
        m3 = self.db.minima()[-1]
        self.assertIsNotNone(self.db.getTransitionState(m1, m2))
        self.assertIsNone(self.db.getTransitionState(m1, m3))
    
    def test_getMinimum(self):
        m = self.db.minima()[0]
        self.assertEqual(m, self.db.getMinimum(m._id))
        
    def test_minimum_adder(self):
        ma = self.db.minimum_adder()
        ma(101., [101.])
        self.assertEqual(len(self.db.minima()), self.nminima+1)
    
    def test_merge_minima(self):
        m1 = self.db.minima()[0]
        m2 = self.db.minima()[1]
        self.db.mergeMinima(m1, m2)
        self.assertEqual(len(self.db.minima()), self.nminima-1)
        # transition states shouldn't be deleted
        self.assertEqual(len(self.db.transition_states()), self.nts)
    
    def test_number_of_minima(self):
        self.assertEqual(self.nminima, self.db.number_of_minima())
    
    def test_number_of_transition_states(self):
        self.assertEqual(self.nts, self.db.number_of_transition_states())
    
    def test_highest_energy_minimum(self):
        m1 = self.db._highest_energy_minimum()
        m2 = self.db.minima()[-1]
        self.assertEqual(m1, m2)
    
    def test_maximum_number_of_minima(self):
        m = self.db.addMinimum(-1., [-1.], max_n_minima=self.nminima)
        self.assertEqual(self.nminima, self.db.number_of_minima())
        self.assertIn(m, self.db.minima())

    def test_maximum_number_of_minima_largestE(self):
        e = float(self.nminima + 1)
        m = self.db.addMinimum(e, [e], max_n_minima=self.nminima)
        self.assertEqual(self.nminima, self.db.number_of_minima())
        self.assertIsNone(m)
        
        #ensure the highest energy minimum is still in the database
        mmax = self.db._highest_energy_minimum()
        self.assertEqual(mmax.energy, float(self.nminima-1))
        
    def test_maximum_number_of_minima_minima_adder(self):
        ma = self.db.minimum_adder(max_n_minima=self.nminima)
        m = ma(-1., [-1.])
        self.assertEqual(self.nminima, self.db.number_of_minima())
        self.assertIn(m, self.db.minima())
コード例 #18
0
#p#ath = [ x for x in IntterpolatedPath(db.minima[19], )]
#path = [ x for x in InterpolatedPath(path[0].copy(), path[-1].copy(), 34) ]
traj = open("traj.xyz", "w")
#for x in path:
#    #export_xyz(traj, x)
#    #ret = quench.mylbfgs(x, pot.getEnergyGradient)
#    #print i,pot.getEnergy(x), ret[1]
#
#    # export_xyz(traj, ret[0])
for x in path:
    export_xyz(traj, x)

import pickle
pickle.dump(path, open("interpolate.pickle", "w"))
exit()
db = Database(db="oxdna.sqlite")
path[0] = db.minima()[19].coords
path[-1] = db.minima()[0].coords

e1 = []
e2 = []

e1.append(pot.getEnergy(path[0]))
e2.append(pot.getEnergy(path[0]))

for i in xrange(1):
    for i in xrange(len(path) - 1):
        e1.append(pot.getEnergy(path[i + 1]))
        c1 = CoordsAdapter(nrigid=13, coords=path[i])
        c2 = CoordsAdapter(nrigid=13, coords=path[i + 1])
        com1 = np.sum(c1.posRigid, axis=0) / float(13)
コード例 #19
0
MAXBFGS 0.1
NAB start
"""
        fout.write(odatastr)
        fout.write("\n")

# ============================ MAIN ================================ 

if __name__ == "__main__":
    
    # create new amber system    
    sysAmb  = AMBERSystem('/home/ss2029/WORK/PyGMIN/examples/amber/coords.prmtop', '/home/ss2029/WORK/PyGMIN/examples/amber/coords.inpcrd')
    
    # load existing database 
    from pygmin.storage import Database
    dbcurr = Database(db="/home/ss2029/WORK/PyGMIN/examples/amber/aladipep.db")
                        
    
    coords = sysAmb.get_random_configuration()
    aa = sysAmb.get_metric_tensor(coords)
    
    exit()  
    # ------- TEST gui 
    from pygmin.gui import run as gr    
    gr.run_gui(sysAmb)
    
    # ------ Test potential 
    sysAmb.test_potential('coords.pdb')
    
    # ------ BH 
    sysAmb.test_BH(dbcurr)
コード例 #20
0
ファイル: dgraph_dlg.py プロジェクト: js850/PyGMIN
        self.setCentralWidget(self.dgraph_widget)
    
    def rebuild_disconnectivity_graph(self):
        self.dgraph_widget.rebuild_disconnectivity_graph()
        

def reduced_db2graph(db, Emax):
    '''
    make a networkx graph from a database including only transition states with energy < Emax
    '''
    g = nx.Graph()
    ts = db.session.query(TransitionState).filter(TransitionState.energy <= Emax).all()
    for t in ts: 
        g.add_edge(t.minimum1, t.minimum2, ts=t)
    return g


if __name__ == "__main__":
    
    db = Database("lj31.db")
    if len(db.minima()) < 2:
        raise Exception("database has no minima")
    
    app = QApplication(sys.argv)        
    md = DGraphDialog(db)
    md.show()
    md.rebuild_disconnectivity_graph()
    
    sys.exit(app.exec_()) 
        
コード例 #21
0
def benchmark_number_of_minima():
    import time, sys
    import numpy as np
    db = Database("test.large.db")

    if True:
        istart = np.random.randint(0, sys.maxint)
        for i in xrange(istart, istart + 10000):
            e = float(i)
            db.addMinimum(e, [e], commit=False)
        db.session.commit()
    else:
        i = 1

    t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock()
    t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock()
    t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock()
    t1 = time.clock()
    e = float(i + 1)
    db.addMinimum(e, [e], commit=False)
    t1 = time.clock()
    print db.number_of_minima()
    print "time", t1 - time.clock()
    t1 = time.clock()

    print len(db.minima())
    print "time", t1 - time.clock()
    t1 = time.clock()
コード例 #22
0
ファイル: tip4p_dgraph.py プロジェクト: yfyh2013/PyGMIN
from pygmin.utils.disconnectivity_graph import DisconnectivityGraph
from pygmin.storage import Database
from pygmin.landscape import TSGraph
import pylab as pl
import numpy as np

kbT = 0.75

db = Database(db="tip4p_8.sqlite", createdb=False)

graph = TSGraph(db)

dg = DisconnectivityGraph(graph.graph, db.minima(), subgraph_size=20)
dg.calculate()
dg.plot()

for m in db.minima():
    if m.pgorder != 2:
        print m.pgorder
    m.free_energy = m.energy + kbT * 0.5 * m.fvib + kbT * np.log(m.pgorder)

for ts in db.transition_states():
    #    if ts.pgorder != 2:
    print ts.pgorder
    #assert ts.pgorder == 2

    ts.free_energy = ts.energy + kbT * 0.5 * ts.fvib + kbT * np.log(
        ts.pgorder) + kbT * np.log(kbT)
    if ts.free_energy > ts.minimum1.free_energy or ts.free_energy > ts.minimum2.free_energy:
        print "warning, free energy of transition state lower than minimum"
        print ts.free_energy, ts.minimum1.free_energy, ts.minimum2.free_energy
コード例 #23
0
        self.setCentralWidget(self.dgraph_widget)

    def rebuild_disconnectivity_graph(self):
        self.dgraph_widget.rebuild_disconnectivity_graph()


def reduced_db2graph(db, Emax):
    '''
    make a networkx graph from a database including only transition states with energy < Emax
    '''
    g = nx.Graph()
    ts = db.session.query(TransitionState).filter(
        TransitionState.energy <= Emax).all()
    for t in ts:
        g.add_edge(t.minimum1, t.minimum2, ts=t)
    return g


if __name__ == "__main__":

    db = Database("lj31.db")
    if len(db.minima()) < 2:
        raise Exception("database has no minima")

    app = QApplication(sys.argv)
    md = DGraphDialog(db)
    md.show()
    md.rebuild_disconnectivity_graph()

    sys.exit(app.exec_())
コード例 #24
0
    parser.add_argument("--Tmax", type=float, help="Minimum temperature for the calculation.", default=1.0)
    parser.add_argument("--Tcount", type=int, help="Number of temperature points for the calculation.", default=300)
    parser.add_argument("--OPTIM", action="store_true", help="read data from a min.data file instead."
                        "fname should be the filename of the min.data file")
    args = parser.parse_args()
    print args.fname
    print args
    k = args.k
    
    # get the list of minima
    if args.OPTIM:
        # fname is a min.data file
        minima = read_min_data(args.fname)
    else:
        dbfname = args.fname
        db = Database(dbfname, createdb=False)
        minima = [m for m in db.minima() if m.fvib is not None and m.pgorder is not None]
        if len(minima) == 0:
            print "There are not minima with the necessary thermodynamic information in the database.  Have you computed the normal mode"\
                  " frequencies and point group order for all the minima?  See pygmin.thermodynamics "\
                  " for more information"
            exit(1)
    print "computing heat capacity from", len(minima), "minima"

    Tmin = args.Tmin
    Tmax = args.Tmax
    nT = args.Tcount
    dT = (Tmax-Tmin) / nT
    
    T = np.array([Tmin + dT*i for i in range(nT)])
    Z, U, U2, Cv = minima_to_cv(minima, T, k)
コード例 #25
0
class TestDB(unittest.TestCase):
    def setUp(self):
        self.db = Database()
        self.nminima = 10
        for i in range(self.nminima):
            e = float(i)
            self.db.addMinimum(e, [e])

        self.nts = 3
        self.db.addTransitionState(0., [0.],
                                   self.db.minima()[0],
                                   self.db.minima()[1],
                                   eigenval=0.,
                                   eigenvec=[0.])
        self.db.addTransitionState(0., [0.],
                                   self.db.minima()[1],
                                   self.db.minima()[2],
                                   eigenval=0.,
                                   eigenvec=[0.])
        self.db.addTransitionState(0., [0.],
                                   self.db.minima()[0],
                                   self.db.minima()[2],
                                   eigenval=0.,
                                   eigenvec=[0.])

    def test_size(self):
        self.assertEqual(len(self.db.minima()), self.nminima)

    def test_energy(self):
        m = self.db.minima()[0]
        self.assertEqual(m.energy, 0.)

    def test_coords(self):
        m = self.db.minima()[0]
        self.assertEqual(m.coords, [0.])

    def test_sizets(self):
        self.assertEqual(len(self.db.transition_states()), self.nts)

    def test_energyts(self):
        ts = self.db.transition_states()[0]
        self.assertEqual(ts.energy, 0.)

    def test_coordsts(self):
        ts = self.db.transition_states()[0]
        self.assertEqual(ts.coords, [0.])

    def test_remove_minimum(self):
        m = self.db.minima()[0]
        self.db.removeMinimum(m)
        self.assertEqual(len(self.db.minima()), self.nminima - 1)
        self.assertNotIn(m, self.db.minima())

        # m should have 2 minima.  both of those should be gone
        self.assertEqual(len(self.db.transition_states()), self.nts - 2)

    def test_remove_ts(self):
        ts = self.db.transition_states()[0]
        self.db.remove_transition_state(ts)
        self.assertEqual(self.db.number_of_transition_states(), self.nts - 1)
        self.assertNotIn(ts, self.db.transition_states())

        # m should have 2 minima.  both of those should be gone
        self.assertEqual(self.db.number_of_minima(), self.nminima)

    def test_getTransitionState(self):
        m1 = self.db.minima()[0]
        m2 = self.db.minima()[1]
        m3 = self.db.minima()[-1]
        self.assertIsNotNone(self.db.getTransitionState(m1, m2))
        self.assertIsNone(self.db.getTransitionState(m1, m3))

    def test_getMinimum(self):
        m = self.db.minima()[0]
        self.assertEqual(m, self.db.getMinimum(m._id))

    def test_minimum_adder(self):
        ma = self.db.minimum_adder()
        ma(101., [101.])
        self.assertEqual(len(self.db.minima()), self.nminima + 1)

    def test_merge_minima(self):
        m1 = self.db.minima()[0]
        m2 = self.db.minima()[1]
        self.db.mergeMinima(m1, m2)
        self.assertEqual(len(self.db.minima()), self.nminima - 1)
        # transition states shouldn't be deleted
        self.assertEqual(len(self.db.transition_states()), self.nts)

    def test_number_of_minima(self):
        self.assertEqual(self.nminima, self.db.number_of_minima())

    def test_number_of_transition_states(self):
        self.assertEqual(self.nts, self.db.number_of_transition_states())

    def test_highest_energy_minimum(self):
        m1 = self.db._highest_energy_minimum()
        m2 = self.db.minima()[-1]
        self.assertEqual(m1, m2)

    def test_maximum_number_of_minima(self):
        m = self.db.addMinimum(-1., [-1.], max_n_minima=self.nminima)
        self.assertEqual(self.nminima, self.db.number_of_minima())
        self.assertIn(m, self.db.minima())

    def test_maximum_number_of_minima_largestE(self):
        e = float(self.nminima + 1)
        m = self.db.addMinimum(e, [e], max_n_minima=self.nminima)
        self.assertEqual(self.nminima, self.db.number_of_minima())
        self.assertIsNone(m)

        #ensure the highest energy minimum is still in the database
        mmax = self.db._highest_energy_minimum()
        self.assertEqual(mmax.energy, float(self.nminima - 1))

    def test_maximum_number_of_minima_minima_adder(self):
        ma = self.db.minimum_adder(max_n_minima=self.nminima)
        m = ma(-1., [-1.])
        self.assertEqual(self.nminima, self.db.number_of_minima())
        self.assertIn(m, self.db.minima())
コード例 #26
0
ファイル: nebdlg.py プロジェクト: js850/PyGMIN
if __name__ == "__main__":
    from pygmin.systems import LJCluster
    from pygmin.storage import Database
    import pylab as pl
    app = QApplication(sys.argv)
    
    def process_events():
        app.processEvents()
    
    #setup system
    natoms = 13
    system = LJCluster(natoms)
    system.params.double_ended_connect.local_connect_params.NEBparams.iter_density = 5.
    x1, e1 = system.get_random_minimized_configuration()[:2]
    x2, e2 = system.get_random_minimized_configuration()[:2]
    db = Database()
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)
    
    #setup neb dialog
    pl.ion()
#    pl.show()
    dlg = NEBDialog()
    wnd = dlg.nebwgt   
    dlg.show()
    wnd.process_events.connect(process_events)

    #initilize the NEB and run it.
    #we have to do it through QTimer because the gui has to 
    #be intitialized first... I don't really understand it 
    from PyQt4.QtCore import QTimer
コード例 #27
0
pot = LJ()

#import the starting and ending points and quench them, 
coords1 = np.genfromtxt("coords.A")
coords2 = np.genfromtxt("coords.B")
res1 = lbfgs_py(coords1.reshape(-1), pot)
res2 = lbfgs_py(coords2.reshape(-1), pot)
coords1 = res1.coords
coords2 = res2.coords
E1 = res1.energy
E2 = res2.energy
natoms = len(coords1)/3

#add the minima to a database
dbfile = "database.sqlite"
database = Database(dbfile)
database.addMinimum(E1, coords1)
database.addMinimum(E2, coords2)
min1 = database.minima()[0]
min2 = database.minima()[1]
    



#set up the structural alignment routine.
#we have to deal with global translational, global rotational,
#and permutational symmetry.
permlist = [range(natoms)]
mindist = MinPermDistAtomicCluster(permlist=permlist, niter=10)

#The transition state search needs to know what the eigenvector corresponding
コード例 #28
0
def main():
    if len(sys.argv) < 2:
        usage()
        exit(1)
    
    
    
    kwargs = {}
    outfile = None
    OPTIM = False

    opts, args = getopt.gnu_getopt(sys.argv[1:], "ho:", 
                                   ["help", "nlevels=", "subgraph_size=", "OPTIM",
                                    "order_by_basin_size", "order_by_energy",
                                    "include_gmin",
                                    "center_gmin",
                                    "Emax=",
                                    ])
    for o, a in opts:
        if o == "-h" or o == "--help":
            usage()
            exit(1)
        if o == "-o":
            outfile = a 
        elif o == "--nlevels":
            kwargs["nlevels"] = int(a)
        elif o == "--Emax":
            kwargs["Emax"] = float(a)
        elif o == "--subgraph_size":
            kwargs["subgraph_size"] = int(a)
        elif o == "--order_by_basin_size":
            kwargs["order_by_basin_size"] = True
        elif o == "--order_by_energy":
            kwargs["order_by_energy"] = True
        elif o == "--includer_gmin":
            kwargs["includer_gmin"] = True
        elif o == "--center_gmin":
            kwargs["center_gmin"] = True
        elif o == "--OPTIM":
            OPTIM = True
        else:
            print "don't understand", o, a
            print ""
            usage()
            exit(1)
    
    
    if OPTIM:
        #make database from min.data ts.data
        graph = make_graph_from_files()
    else:
        if len(args) == 0:
            print "you must specify database file"
            print ""
            usage()
            exit()
        dbfile = args[0]
        if not os.path.exists(dbfile):
            print "database file doesn't exist", dbfile
            exit()
        
        db = Database(dbfile)
        
    if outfile is None and use_gui:
        app = QApplication(sys.argv) 
        kwargs["show_minima"] = False
        md = DGraphDialog(db, params=kwargs)
        md.rebuild_disconnectivity_graph()
        md.show()
        sys.exit(app.exec_())
        
    if not OPTIM: 
        # make graph from database
        if "Emax" in kwargs and use_gui:
            graph = reduced_db2graph(db, kwargs['Emax'])
        else:
            graph = dg.database2graph(db)

    # do the disconnectivity graph analysis
    mydg = dg.DisconnectivityGraph(graph, **kwargs)
    print "doing disconnectivity graph analysis"
    sys.stdout.flush()
    t1 = time.time()
    mydg.calculate()
    t2 = time.time()
    print "d-graph analysis finished in", t2-t1, "seconds"
    print "number of minima:", mydg.tree_graph.number_of_leaves()
    print "plotting disconnectivigy graph"
    sys.stdout.flush()
    
    
    # make the figure and save it
    mydg.plot()
    if outfile is None:
        plt.show()
    else:
        plt.savefig(outfile)
    t3 = time.time()
    print "plotting finished in", t3-t2, "seconds"