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


Python Database.add_properties方法代码示例

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


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

示例1: create_database

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import add_properties [as 别名]
    def create_database(self, *args, **kwargs):
        """return a new database object
        
        See Also
        --------
        pele.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]
        
        try:
            overwrite_properties = kwargs.pop("overwrite_properties")
        except KeyError:
            overwrite_properties = True

        # 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

        db = Database(**kwargs)
        
        db.add_properties(self.get_system_properties(), overwrite=overwrite_properties)
        return db
开发者ID:dimaslave,项目名称:pele,代码行数:40,代码来源:basesystem.py

示例2: TestDB

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

#.........这里部分代码省略.........
        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):
        # add some system properties and ensure they were added correctly
        self.db.add_property("natoms", 10, dtype="int")
        p = self.db.get_property("natoms")
        self.assertEqual(p.value(), 10)
        self.db.add_property("eps", 2.1, dtype="float")
        p = self.db.get_property("eps")
        self.assertEqual(p.value(), 2.1)
        self.db.add_property("author", "Jake", dtype="string")
        p = self.db.get_property("author")
        self.assertEqual(p.value(), "Jake")
        self.db.add_property("data", [1, 2], dtype="pickle")
        p = self.db.get_property("data")
        self.assertEqual(p.value(), [1, 2])

    def test_bad_property(self):
        self.db.add_property("natoms", 10, dtype="string")
        p = self.db.get_property("natoms")
        self.assertEqual(p.value(), "10")

    def test_property_overwrite_false(self):
        self.db.add_property("natoms", 10)
        # overwriting with the same value should not raise error
        self.db.add_property("natoms", 10, overwrite=False) 
        # overwriting with a different value should raise error
        with self.assertRaises(RuntimeError):
            self.db.add_property("natoms", 11, overwrite=False)
    
    
    def test_add_properties(self):
        props = dict(natoms=10, author="jake")
        self.db.add_properties(props)
        for name, value in props.iteritems():
            p = self.db.get_property(name)
            self.assertEqual(p.value(), value)
    
    def test_load_wrong_schema(self):
        current_dir = os.path.dirname(__file__)
        dbname = current_dir + "/lj6_schema1.sqlite"
        with self.assertRaises(IOError):
            db = Database(dbname, createdb=False)
    
    def test_load_right_schema(self):
        current_dir = os.path.dirname(__file__)
        dbname = current_dir + "/lj6_schema2.sqlite"
        db = Database(dbname, createdb=False)
    
    def test_invalid(self):
        m = self.db.minima()[0]
        self.assertFalse(m.invalid)
        m.invalid = True
        self.db.session.commit()
        self.assertTrue(m.invalid)
        
        # now with a ts
        m = self.db.transition_states()[0]
        self.assertFalse(m.invalid)
        m.invalid = True
        self.db.session.commit()
        self.assertTrue(m.invalid)
    
    def test_user_data(self):
        m = self.db.minima()[0]
        m.user_data = dict(key="value")
        self.db.session.commit()
        v = m.user_data["key"]
        
        # now with a transition state
        m = self.db.transition_states()[0]
        m.user_data = dict(key="value")
        self.db.session.commit()
        v = m.user_data["key"]
开发者ID:borislavujo,项目名称:pele,代码行数:104,代码来源:test_database.py


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