当前位置: 首页>>代码示例>>Python>>正文


Python storage.Database类代码示例

本文整理汇总了Python中pele.storage.Database的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: benchmark_number_of_minima

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 range(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()
开发者ID:pele-python,项目名称:pele,代码行数:29,代码来源:test_database.py

示例2: create_random_database

def create_random_database(nmin=20, nts=None, natoms=2):
    """
    create a database for test purposes
    """
    from pele.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
开发者ID:cjforman,项目名称:pele,代码行数:26,代码来源:test_graph.py

示例3: test1

    def test1(self):
        current_dir = os.path.dirname(__file__)
        db = Database()
        converter = OptimDBConverter(db, 
                                     mindata=os.path.join(current_dir, "min.data"),
                                     tsdata=os.path.join(current_dir, "ts.data"),
                                     pointsmin=os.path.join(current_dir, "points.min"),
                                     pointsts=os.path.join(current_dir, "points.ts"),
                                     endianness="<")
        converter.convert()
        self.assertEqual(db.number_of_minima(), 2)
        self.assertEqual(db.number_of_transition_states(), 1)
        
        ts = db.transition_states()[0]
        self.assertAlmostEqual(ts.coords[0], 1.548324, 5)
        self.assertAlmostEqual(ts.coords[2], 0.18178001, 5)
        self.assertAlmostEqual(ts.coords[-1], -0.50953229, 5)
        self.assertEqual((180,), ts.coords.shape)

        m = db.minima()[0]
        print(repr(m.coords))
        self.assertAlmostEqual(m.coords[0], 1.53700142, 5)
        self.assertAlmostEqual(m.coords[2], 0.87783657, 5)
        self.assertAlmostEqual(m.coords[-1], -0.50953229, 5)
        self.assertEqual((180,), m.coords.shape)
开发者ID:pele-python,项目名称:pele,代码行数:25,代码来源:test_optim_compatibility.py

示例4: _get_database_params

def _get_database_params(dbname):
    db = Database(dbname, createdb=False)
    interactions = db.get_property("interactions").value()
    db_nspins = db.get_property("nspins").value()
    db_p = db.get_property("p").value()
    params = (db_nspins, db_p, interactions)
    return db, params
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:7,代码来源:start_server.py

示例5: get_database_params

def get_database_params(dbname, nspins, p):
    db = Database(dbname, createdb=False)
    interactions = db.get_property("interactions").value()
    db_nspins = db.get_property("nspins").value()
    db_p = db.get_property("p").value()
    # check that parameters match
    assert db_nspins == nspins
    assert db_p == p
    return db, interactions
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:9,代码来源:start_serial.py

示例6: test

def test():
    from pele.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)
开发者ID:borislavujo,项目名称:pele,代码行数:10,代码来源:local_connect.py

示例7: run_gui_db

def run_gui_db(dbname="xy_10x10.sqlite"):
    from pele.gui import run_gui
    from pele.storage import Database
    try:
        db = Database(dbname, createdb=False)
        phases = db.get_property("phases").value()
    except IOError:
        phases=None
    system = XYModlelSystem(dim=[10,10], phi_disorder=np.pi, phases=phases)
    run_gui(system, db=dbname)
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:10,代码来源:xy_model_system.py

示例8: run_gui_db

def run_gui_db(dbname="pspin_spherical_p3_N20.sqlite"):
    from pele.gui import run_gui
    try:
        db = Database(dbname, createdb=False)
        interactions = db.get_property("interactions").value()
        nspins = db.get_property("nspins").value()
        p = db.get_property("p").value()
    except IOError:
        interactions=None
    system = MeanFieldPSpinSphericalSystem(nspins, p=p, interactions=interactions)
    run_gui(system, db=dbname)
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:11,代码来源:pspin_spherical_system.py

示例9: create_soft_sphere_system_from_db

def create_soft_sphere_system_from_db(dbname):
    from pele.storage import Database
    db = Database(dbname, createdb=False)
    
    radii = db.get_property("radii").value()
    boxvec = db.get_property("boxvec").value()
    power = db.get_property("power").value()
    print radii
    
    system = SoftSphereSystem(radii, boxvec, power=power)
    db = system.create_database(dbname, createdb=False)
    
    return system, db
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:13,代码来源:soft_sphere_bulk.py

示例10: create_neb

 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)        
开发者ID:borislavujo,项目名称:pele,代码行数:18,代码来源:neb_explorer.py

示例11: setUp

 def setUp(self):
     from pele.utils.optim_compatibility import OptimDBConverter
     from pele.storage import Database
     ndof = 10 # wrong, but who cares.
     self.db = Database()
     current_dir = os.path.dirname(__file__)
     converter = OptimDBConverter(self.db, ndof=ndof, mindata=current_dir+"/collagen.min.data", 
                                  tsdata=current_dir+"/collagen.ts.data", assert_coords=False)
     converter.convert_no_coords()
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:9,代码来源:test_graph_transformation_minima.py

示例12: main

def main():
    parser = argparse.ArgumentParser(description="""
convert an OPTIM database to a pele sqlite database.  Four files are needed.  Normally they are called:

    points.min : the coordinates of the minima in binary format
    min.data   : additional information about the minima (like the energy)
    points.ts  : the coordinates of the transition states
    min.ts     : additional information about transition states (like which minima they connect)

Other file names can optionally be passed.  Some fortran compilers use non-standard endianness to save the
binary data.  If your coordinates are garbage, try changing the endianness.
    """, formatter_class=argparse.RawDescriptionHelpFormatter)
    
    parser.add_argument('--ndof', help='Number of total degrees of freedom (e.g. 3*number of atoms).  This is simply the length of a coordinates vector.', 
                        type=int, default=None)
    parser.add_argument('--parentDB', help = 'Name of parent pinned database from which the system properties will be copied. Choose a small one!')
    parser.add_argument('--Database','-d', help = 'Name of database to write into', type = str, default="optimdb.sqlite")
    parser.add_argument('--Mindata','-m', help = 'Name of min.data file', type = str, default="min.data")
    parser.add_argument('--Tsdata','-t', help = 'Name of ts.data file', type = str, default="ts.data")
    parser.add_argument('--Pointsmin','-p', help = 'Name of points.min file', type = str, default="points.min")
    parser.add_argument('--Pointsts','-q', help = 'Name of points.ts file', type = str, default="points.ts")
    parser.add_argument('--endianness', help = 'set the endianness of the binary data.  Can be "<" for little-endian or ">" for big-endian', type = str, default="=")
    parser.add_argument('--nopoints', help = 'Load the metadata for minima and transition states without reading the coordinates (usually to save storage space)', action = 'store_true')
    args = parser.parse_args()
    
    system, basedb, x0 = create_frozenblj_system_from_db(args.parentDB)

    db = Database(args.Database)

    props = basedb.properties(as_dict=True)
    for key, prop in props.iteritems():
        db.add_property(key, prop)
    
    cv = OptimDBConverter(database=db, ndof=args.ndof, mindata=args.Mindata, 
                 tsdata=args.Tsdata, pointsmin=args.Pointsmin, pointsts=args.Pointsts,
                 endianness=args.endianness, coords_converter=system.coords_converter.get_reduced_coords)

    cv.setAccuracy()
     
    if args.nopoints:
        cv.convert_no_coords()
    else:
        cv.convert()
    cv.db.session.commit()
开发者ID:sniblett402,项目名称:pele,代码行数:44,代码来源:pBLJ_optim_converter.py

示例13: getNEB

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
开发者ID:pele-python,项目名称:pele,代码行数:19,代码来源:nebdlg.py

示例14: test2

    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()
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:20,代码来源:test_double_ended_connect.py

示例15: bh_no_system_class

def bh_no_system_class():
    import numpy as np
    from pele.potentials import LJ
    natoms = 17
    potential = LJ()
    x0 = np.random.uniform(-1, 1, 3*natoms)
    
    from pele.takestep import RandomDisplacement, AdaptiveStepsizeTemperature
    displace = RandomDisplacement()
    adaptive_displacement = AdaptiveStepsizeTemperature(displace)
    
    from pele.storage import Database
    database = Database("lj17.sqlite")
    
    from pele.basinhopping import BasinHopping
    bh = BasinHopping(x0, potential, adaptive_displacement, storage=database.minimum_adder)
    bh.run(10)
    
    for m in database.minima():
        print m.energy
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:20,代码来源:example2_global_optimization.py


注:本文中的pele.storage.Database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。