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


Python Database.add_property方法代码示例

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


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

示例1: main

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import add_property [as 别名]
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,代码行数:46,代码来源:pBLJ_optim_converter.py

示例2: create_BLJ_system_from_db

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import add_property [as 别名]
def create_BLJ_system_from_db(dbname):
    from pele.storage import Database
    db = Database(dbname, createdb=False)
    
    natoms = db.get_property("natoms").value()
    boxvec = db.get_property("boxvec").value()
    ntypeA = db.get_property("ntypeA").value()
    initial_coords = db.get_property("initial_coords").value()
    #print radii
    
    system = BLJBulk(natoms, boxvec, ntypeA=ntypeA)

    # The next line is a nasty hack to avoid an odd error.
    # When we call create_database on an exisiting database, it compares all the system properties
    # against the ones that are saved in the database. It then commits any changes to the database,
    # but that step seems to fail when trying to overwrite a sequence object (in this case the kwargs
    # dictionary) with another sequence. Instead, I overwrite with a None-type object first. Then in
    # the next command we are overwriting a None-type with a dictionary, which doesn't cause an error.
    db.add_property("potential_kwargs",{})

    db = system.create_database(dbname, createdb=False, overwrite_properties=True)
    
    return system, db, initial_coords
开发者ID:sniblett402,项目名称:pele,代码行数:25,代码来源:blj_bulk.py

示例3: TestDB

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import add_property [as 别名]

#.........这里部分代码省略.........
    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())

    def test_getTSfromID(self):
        ts = self.db.transition_states()[0]
        ts1 = self.db.getTransitionStateFromID(ts._id)
        self.assertEqual(ts, ts1)

    def test_property(self):
        # add some system properties and ensure they were added correctly
        self.db.add_property("natoms", 10)
        p = self.db.get_property("natoms")
        self.assertEqual(p.value(), 10)
        self.db.add_property("eps", 2.1)
        p = self.db.get_property("eps")
        self.assertEqual(p.value(), 2.1)
        self.db.add_property("author", "Jake")
        p = self.db.get_property("author")
        self.assertEqual(p.value(), "Jake")
        self.db.add_property("data", [1, 2])
        p = self.db.get_property("data")
        self.assertEqual(p.value(), [1, 2])
        
        # assert that the not set values are None
        p = self.db.get_property("natoms")
        self.assertIsNone(p.string_value)
        self.assertIsNone(p.float_value)
        self.assertIsNone(p.pickle_value)

        
        p = self.db.get_property("noprop")
        self.assertIsNone(p)

        props = self.db.properties(as_dict=True)
        self.assertIsInstance(props, dict)
        self.assertDictContainsSubset(dict(natoms=10), props)
        self.assertEqual(len(props.items()), 4)
        
        props = self.db.properties(as_dict=False)
        self.assertIn(("natoms", 10), [p.item() for p in props])
        self.assertEqual(len(props), 4)

    def test_property_dtype(self):
开发者ID:borislavujo,项目名称:pele,代码行数:70,代码来源:test_database.py


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