Пример #1
0
 def iterate(self, nested_dict=None):
     """http://stackoverflow.com/questions/10756427/loop-through-all-nested-dictionary-values"""
     d = self if nested_dict is None else nested_dict
     if nested_dict is None:
         self.level = 0
     for key in list(d.keys()):
         value = d[key]
         if isinstance(value, _Mapping):
             if value.get('@class') == 'Structure':
                 from pymatgen import Structure
                 yield key, Structure.from_dict(value)
                 continue
             yield (self.level, key), None
             if value.get('@class') == 'Table':
                 from mpcontribs.io.core.components.tdata import Table
                 yield key, Table.from_dict(value)
                 continue
             if Quantity is not None and value.get('@class') == 'Quantity':
                 quantity = Quantity.from_dict(value)
                 yield key, quantity
                 continue
             self.level += 1
             for inner_key, inner_value in self.iterate(nested_dict=value):
                 yield inner_key, inner_value
             self.level -= 1
         else:
             yield (self.level, key), value
Пример #2
0
def test_components():
    d = {k: {} for k in mp_level01_titles}
    d["data"] = {"a": 3.5, "b": {"display": "6 eV", "value": 6, "unit": "eV"}}
    exp = HierarchicalData([("data", RecursiveDict([("a", 3.5),
                                                    ("b", "6 eV")]))])
    assert HierarchicalData(d) == exp

    fn = os.path.join(os.path.dirname(__file__), "test_table.json")
    with open(fn, "r") as f:
        d = json.load(f)
        table = Table.from_dict(d)
        assert table.render()
        plot = Plot.from_dict(d)
        assert plot.get_figure()
Пример #3
0
 def from_dict(cls, d):
     return cls(Table.from_dict(d), config=d.get("config"))
Пример #4
0
 def from_dict(cls, d):
     return cls(Table.from_dict(d), config=d.get('config'), tid=d['id'])