Ejemplo n.º 1
0
    def setUp(self):
        with open("mp-7000.json", "r") as f:
            dict_lse = json.load(f)
        lse = LightStructureEnvironments.from_dict(dict_lse)
        struct = lse.structure
        bva = BVAnalyzer()
        valences = bva.get_valences(structure=struct)
        lgf = LocalGeometryFinder()
        lgf.setup_structure(structure=struct)
        se = lgf.compute_structure_environments(maximum_distance_factor=1.41, only_cations=False, valences=valences)
        strategy = MultiWeightsChemenvStrategy.stats_article_weights_parameters()
        self.lse = LightStructureEnvironments.from_structure_environments(strategy=strategy, structure_environments=se)

        with open("mp-5634.json", "r") as f:
            dict_lse2 = json.load(f)
        self.lse2 = LightStructureEnvironments.from_dict(dict_lse2)
Ejemplo n.º 2
0
    def from_dict(cls, d):
        """

        Args:
            d ():

        Returns:

        """
        # Reconstructs the graph with integer as nodes (json's as_dict replaces integer keys with str keys)
        cgraph = nx.from_dict_of_dicts(d["connectivity_graph"],
                                       create_using=nx.MultiGraph,
                                       multigraph_input=True)
        cgraph = nx.relabel_nodes(
            cgraph, int
        )  # Just relabel the nodes using integer casting (maps str->int)
        # Relabel multiedges (removes multiedges with str keys and adds them back with int keys)
        edges = set(cgraph.edges())
        for n1, n2 in edges:
            new_edges = {
                int(iedge): edata
                for iedge, edata in cgraph[n1][n2].items()
            }
            cgraph.remove_edges_from([
                (n1, n2, iedge) for iedge, edata in cgraph[n1][n2].items()
            ])
            cgraph.add_edges_from([(n1, n2, iedge, edata)
                                   for iedge, edata in new_edges.items()])
        return cls(
            LightStructureEnvironments.from_dict(
                d["light_structure_environments"]),
            connectivity_graph=cgraph,
            environment_subgraphs=None,
        )
Ejemplo n.º 3
0
 def setUp(self):
     self.paulingconnetion = PaulingConnection(DISTANCE=8.0)
     self.matlist = ["mp-7000.json"]
     self.lse_dict = {}
     for mat in self.matlist:
         with open(mat, "r") as f:
             dict_lse = json.load(f)
         lse = LightStructureEnvironments.from_dict(dict_lse)
         self.lse_dict[mat] = lse
Ejemplo n.º 4
0
 def setUp(self):
     self.matlist = ["mp-1788.json", "mp-7000.json", "mp-19359.json", "mp-306.json", "mp-886.json", "mp-2605.json"]
     self.lse_dict = {}
     self.Pauling_dict = {}
     for mat in self.matlist:
         with open(mat, "r") as f:
             dict_lse = json.load(f)
         lse = LightStructureEnvironments.from_dict(dict_lse)
         self.lse_dict[mat] = lse
         self.Pauling_dict[mat] = Pauling0(self.lse_dict[mat])
Ejemplo n.º 5
0
 def setUp(self):
     self.matlist = ["mp-7000.json", "mp-19359.json", "mp-1788.json", "mp-12236.json", "mp-5986.json"]
     self.lse_dict = {}
     self.Pauling_List = {}
     for mat in self.matlist:
         with open(mat, "r") as f:
             dict_lse = json.load(f)
         lse = LightStructureEnvironments.from_dict(dict_lse)
         self.lse_dict[mat] = lse
         self.Pauling_List[mat] = Pauling5()
         self.Pauling_List[mat].newsetup(lse=lse, save_to_file=False)
Ejemplo n.º 6
0
 def setUp(self):
     # test it for further candidates -> differing in CN, differing in val
     self.matlist = ["mp-7000.json", "mp-19359.json", "mp-1788.json", "mp-5986.json", "mp-19418.json"]
     self.lse_dict = {}
     self.Pauling_List = {}
     for mat in self.matlist:
         with open(mat, "r") as f:
             dict_lse = json.load(f)
         lse = LightStructureEnvironments.from_dict(dict_lse)
         self.lse_dict[mat] = lse
         self.Pauling_List[mat] = Pauling4()
         self.Pauling_List[mat].newsetup(lse=lse, save_to_file=False)
Ejemplo n.º 7
0
 def setUp(self):
     self.matlist = ["mp-7000.json", "mp-19418.json"]
     self.lse_dict = {}
     for mat in self.matlist:
         with open(mat, "r") as f:
             dict_lse = json.load(f)
         lse = LightStructureEnvironments.from_dict(dict_lse)
         self.lse_dict[mat] = lse
     self.pauling3and4_dist1 = Pauling3and4()
     self.pauling3and4_dist1.newsetup(self.lse_dict["mp-7000.json"], save_to_file=False, filename=False,
                                      distance=4.5)
     self.pauling3and4_dist2 = Pauling3and4()
     self.pauling3and4_dist2.newsetup(self.lse_dict["mp-7000.json"], save_to_file=False, filename=False)
     self.pauling3and4_dict3 = Pauling3and4()
     self.pauling3and4_dict3.newsetup(self.lse_dict["mp-19418.json"], save_to_file=False, filename=False, distance=4)
Ejemplo n.º 8
0
    def setUp(self):
        # TODO: initilaize normal pauling as well
        self.matlist = ["mp-7000.json", "mp-566090.json", "mp-2605.json", "mp-4056.json"]
        self.lse_dict = {}
        self.Pauling_dict = {}
        self.Pauling_dict_perc1 = {}
        self.Pauling_dict_perc02 = {}
        self.Pauling_dict_realtwo = {}

        for mat in self.matlist:
            with open(mat, "r") as f:
                dict_lse = json.load(f)
            lse = LightStructureEnvironments.from_dict(dict_lse)
            self.lse_dict[mat] = lse
            self.Pauling_dict[mat] = Pauling2_optimized_environments(self.lse_dict[mat], perc=0.3)
            self.Pauling_dict_perc02[mat] = Pauling2_optimized_environments(self.lse_dict[mat], perc=0.2)
            self.Pauling_dict_perc1[mat] = Pauling2_optimized_environments(self.lse_dict[mat], perc=1.0)
            self.Pauling_dict_realtwo[mat] = Pauling2(self.lse_dict[mat])
Ejemplo n.º 9
0
    def test_read_write_structure_environments(self):
        f = open(
            "{}/{}".format(json_files_dir, "test_T--4_FePO4_icsd_4266.json"),
            "r")
        dd = json.load(f)
        f.close()

        atom_indices = dd["atom_indices"]

        struct = Structure.from_dict(dd["structure"])
        self.lgf.setup_structure(struct)
        se = self.lgf.compute_structure_environments(
            only_indices=atom_indices,
            maximum_distance_factor=2.25,
            get_from_hints=True)

        f = open("tmp_dir/se.json", "w")
        json.dump(se.as_dict(), f)
        f.close()

        f = open("tmp_dir/se.json", "r")
        dd = json.load(f)
        f.close()

        se2 = StructureEnvironments.from_dict(dd)

        self.assertEqual(se, se2)

        strategy = SimplestChemenvStrategy()
        lse = LightStructureEnvironments.from_structure_environments(
            structure_environments=se, strategy=strategy, valences="undefined")

        f = open("tmp_dir/lse.json", "w")
        json.dump(lse.as_dict(), f)
        f.close()

        f = open("tmp_dir/lse.json", "r")
        dd = json.load(f)
        f.close()

        lse2 = LightStructureEnvironments.from_dict(dd)

        self.assertEqual(lse, lse2)
Ejemplo n.º 10
0
    def test_read_structure_environments(self):
        f = open("{}/{}".format(json_files_dir, 'test_T--4_FePO4_icsd_4266.json'), 'r')
        dd = json.load(f)
        f.close()

        atom_indices = dd['atom_indices']

        struct = Structure.from_dict(dd['structure'])
        self.lgf.setup_structure(struct)
        se = self.lgf.compute_structure_environments_detailed_voronoi(only_indices=atom_indices,
                                                                      maximum_distance_factor=2.25)

        f = open('tmp_dir/se.json', 'w')
        json.dump(se.as_dict(), f)
        f.close()

        f = open('tmp_dir/se.json', 'r')
        dd = json.load(f)
        f.close()

        se2 = StructureEnvironments.from_dict(dd)

        self.assertEqual(se, se2)

        _strategy = SimplestChemenvStrategy()
        light_se = LightStructureEnvironments(_strategy, se)

        f = open('tmp_dir/light_se.json', 'w')
        json.dump(light_se.as_dict(), f)
        f.close()

        f = open('tmp_dir/light_se.json', 'r')
        dd = json.load(f)
        f.close()

        light_se2 = LightStructureEnvironments.from_dict(dd)

        self.assertEqual(light_se._strategy, light_se2._strategy)
        self.assertEqual(light_se._structure, light_se2._structure)
        self.assertEqual(light_se._bva_valences, light_se2._bva_valences)
        self.assertEqual(light_se._coordination_environments, light_se2._coordination_environments)
        self.assertEqual(light_se._neighbors, light_se2._neighbors)
        self.assertEqual(light_se, light_se2)
Ejemplo n.º 11
0
    def test_read_write_structure_environments(self):
        f = open(
            "{}/{}".format(json_files_dir, 'test_T--4_FePO4_icsd_4266.json'),
            'r')
        dd = json.load(f)
        f.close()

        atom_indices = dd['atom_indices']

        struct = Structure.from_dict(dd['structure'])
        self.lgf.setup_structure(struct)
        se = self.lgf.compute_structure_environments(
            only_indices=atom_indices, maximum_distance_factor=2.25)

        f = open('tmp_dir/se.json', 'w')
        json.dump(se.as_dict(), f)
        f.close()

        f = open('tmp_dir/se.json', 'r')
        dd = json.load(f)
        f.close()

        se2 = StructureEnvironments.from_dict(dd)

        self.assertEqual(se, se2)

        strategy = SimplestChemenvStrategy()
        lse = LightStructureEnvironments.from_structure_environments(
            structure_environments=se, strategy=strategy, valences='undefined')

        f = open('tmp_dir/lse.json', 'w')
        json.dump(lse.as_dict(), f)
        f.close()

        f = open('tmp_dir/lse.json', 'r')
        dd = json.load(f)
        f.close()

        lse2 = LightStructureEnvironments.from_dict(dd)

        self.assertEqual(lse, lse2)
Ejemplo n.º 12
0
    def test_read_write_structure_environments(self):
        f = open("{}/{}".format(json_files_dir, 'test_T--4_FePO4_icsd_4266.json'), 'r')
        dd = json.load(f)
        f.close()

        atom_indices = dd['atom_indices']

        struct = Structure.from_dict(dd['structure'])
        self.lgf.setup_structure(struct)
        se = self.lgf.compute_structure_environments(only_indices=atom_indices,
                                                     maximum_distance_factor=2.25,
                                                     get_from_hints=True)

        f = open('tmp_dir/se.json', 'w')
        json.dump(se.as_dict(), f)
        f.close()

        f = open('tmp_dir/se.json', 'r')
        dd = json.load(f)
        f.close()

        se2 = StructureEnvironments.from_dict(dd)

        self.assertEqual(se, se2)

        strategy = SimplestChemenvStrategy()
        lse = LightStructureEnvironments.from_structure_environments(structure_environments=se, strategy=strategy,
                                                                     valences='undefined')

        f = open('tmp_dir/lse.json', 'w')
        json.dump(lse.as_dict(), f)
        f.close()

        f = open('tmp_dir/lse.json', 'r')
        dd = json.load(f)
        f.close()

        lse2 = LightStructureEnvironments.from_dict(dd)

        self.assertEqual(lse, lse2)
 def from_dict(cls, d):
     return cls(LightStructureEnvironments.from_dict(d['light_structure_environments']),
                connectivity_graph=nx.from_dict_of_dicts(d['connectivity_graph'], multigraph_input=True),
                environment_subgraphs={env_key: nx.from_dict_of_dicts(subgraph, multigraph_input=True)
                                       for env_key, subgraph in d['environment_subgraphs'].items()})