Exemplo n.º 1
0
 def from_dict(cls, d: Dict) -> 'StructureGraph':
     if 'nn_strategy' in d:
         nn_strategy = d.pop('nn_strategy')
         nn_strategy_obj = local_env.deserialize(nn_strategy)
         d.update({'nn_strategy': nn_strategy_obj})
         return super().from_dict(d)
     return super().from_dict(d)
Exemplo n.º 2
0
    def test_serialization(self):
        mall = MinimumDistanceNNAll(4)
        config = serialize(mall)
        self.assertDictEqual(
            config, {"@module": "megnet.data.local_env", "@class": "MinimumDistanceNNAll", "cutoff": 4}
        )
        self.assertTrue(serialize(None) is None)

        mall2 = deserialize(config)
        self.assertTrue(isinstance(mall2, MinimumDistanceNNAll))
        self.assertTrue(mall2.cutoff == 4)
Exemplo n.º 3
0
    def test_serialization(self):
        mall = MinimumDistanceNNAll(4)
        config = serialize(mall)
        self.assertDictEqual(
            config, {
                '@module': 'megnet.data.local_env',
                '@class': 'MinimumDistanceNNAll',
                'cutoff': 4
            })
        self.assertTrue(serialize(None) is None)

        mall2 = deserialize(config)
        self.assertTrue(isinstance(mall2, MinimumDistanceNNAll))
        self.assertTrue(mall2.cutoff == 4)
Exemplo n.º 4
0
    def from_dict(cls, d: Dict) -> "StructureGraph":
        """
        Initialization from dictionary
        Args:
            d (dict): dictionary

        Returns: StructureGraph object

        """
        if "nn_strategy" in d:
            nn_strategy = d.pop("nn_strategy")
            nn_strategy_obj = local_env.deserialize(nn_strategy)
            d.update({"nn_strategy": nn_strategy_obj})
            return super().from_dict(d)
        return super().from_dict(d)