本文整理汇总了Python中pymatgen.Structure.as_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.as_dict方法的具体用法?Python Structure.as_dict怎么用?Python Structure.as_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.Structure
的用法示例。
在下文中一共展示了Structure.as_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dict_to_object
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import as_dict [as 别名]
def test_dict_to_object(self):
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
lattice = Lattice([[3.8401979337, 0.00, 0.00],
[1.9200989668, 3.3257101909, 0.00],
[0.00, -2.2171384943, 3.1355090603]])
struct = Structure(lattice, ["Si"] * 2, coords)
d = {'structure_dict': [struct.as_dict(), struct.as_dict()]}
df = DataFrame(data=d)
df["structure"] = dict_to_object(df["structure_dict"])
self.assertEqual(df["structure"].tolist()[0], struct)
self.assertEqual(df["structure"].tolist()[1], struct)
示例2: test_conversion_multiindex_dynamic
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import as_dict [as 别名]
def test_conversion_multiindex_dynamic(self):
# test dynamic target_col_id setting with multiindex
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
lattice = Lattice([[3.8401979337, 0.00, 0.00],
[1.9200989668, 3.3257101909, 0.00],
[0.00, -2.2171384943, 3.1355090603]])
struct = Structure(lattice, ["Si"] * 2, coords)
d = {'structure_dict': [struct.as_dict(), struct.as_dict()]}
df_2lvl = DataFrame(data=d)
df_2lvl.columns = MultiIndex.from_product((["custom"],
df_2lvl.columns.values))
dto = DictToObject()
df_2lvl = dto.featurize_dataframe(df_2lvl, ('custom', 'structure_dict'),
multiindex=True)
new_col_id = ('DictToObject', 'structure_dict_object')
self.assertEqual(df_2lvl[new_col_id].tolist()[0], struct)
self.assertEqual(df_2lvl[new_col_id].tolist()[1], struct)
示例3: test_dict_to_object
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import as_dict [as 别名]
def test_dict_to_object(self):
coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
lattice = Lattice([[3.8401979337, 0.00, 0.00],
[1.9200989668, 3.3257101909, 0.00],
[0.00, -2.2171384943, 3.1355090603]])
struct = Structure(lattice, ["Si"] * 2, coords)
d = {'structure_dict': [struct.as_dict(), struct.as_dict()]}
df = DataFrame(data=d)
dto = DictToObject(target_col_id='structure')
df = dto.featurize_dataframe(df, 'structure_dict')
self.assertEqual(df["structure"].tolist()[0], struct)
self.assertEqual(df["structure"].tolist()[1], struct)
# test dynamic target_col_id setting
df = DataFrame(data=d)
dto = DictToObject()
df = dto.featurize_dataframe(df, 'structure_dict')
self.assertEqual(df["structure_dict_object"].tolist()[0], struct)
self.assertEqual(df["structure_dict_object"].tolist()[1], struct)