Example #1
0
    def test_chemical_potential(self):
        if not available:
            self.skipTest(avail_msg)

        bc = get_ternary_BC()
        ecis = {"c1_0": 0.0, "c1_1": 0.0}
        atoms = bc.atoms.copy()
        bf = bc.basis_functions
        calc = CE(atoms, bc, eci=ecis)

        groups = [{"Al": 2}, {"Mg": 1, "Si": 1}]
        symbs = ["Al", "Mg", "Si"]
        T = 400
        chem_pots = [-0.2, -0.1, 0.0, 0.1, 0.2, 1.0]
        all_al = ["Al" for _ in range(len(atoms))]
        num_atom_per_fu = 2
        for mu in chem_pots:
            calc.set_symbols(all_al)
            mc = PseudoBinarySGC(atoms,
                                 T,
                                 chem_pot=mu,
                                 symbols=symbs,
                                 groups=groups)

            # At this point the chemical potentials should
            # be updated
            changes = [(0, "Al", "Mg"), (1, "Al", "Si")]
            energy = calc.get_energy()
            for change in changes:
                calc.update_cf(change)

            new_energy = calc.get_energy()
            self.assertAlmostEqual(new_energy - energy, mu)
            mc.reset_ecis()
    def test_network(self):
        if (not available):
            self.skipTest("ASE version does not have CE!")
            return

        msg = ""
        no_throw = True
        try:
            db_name = "test_db_network.db"

            conc = Concentration(basis_elements=[["Al", "Mg"]])
            a = 4.05
            ceBulk = CEBulk(crystalstructure="fcc",
                            a=a,
                            size=[3, 3, 3],
                            concentration=conc,
                            db_name=db_name,
                            max_cluster_size=3,
                            max_cluster_dia=4.5)
            ceBulk.reconfigure_settings()

            cf = CorrFunction(ceBulk)
            atoms = ceBulk.atoms.copy()
            cf = cf.get_cf(atoms)
            eci = {key: 0.001 for key in cf.keys()}
            calc = CE(atoms, ceBulk, eci=eci)
            trans_mat = ceBulk.trans_matrix

            for name, info in ceBulk.cluster_info[0].items():
                if info["size"] == 2:
                    net_name = name
                    break
            obs = NetworkObserver(calc=calc,
                                  cluster_name=[net_name],
                                  element=["Mg"])

            # Several hard coded tests
            calc.update_cf((0, "Al", "Mg"))
            size = 2
            clusters = ceBulk.cluster_info[0][net_name]["indices"]
            for sub_clust in clusters:
                calc.update_cf((sub_clust[0], "Al", "Mg"))
                # Call the observer
                obs(None)

                res = obs.fast_cluster_tracker.get_cluster_statistics_python()
                self.assertEqual(res["cluster_sizes"][0], size)
                size += 1
            obs.get_indices_of_largest_cluster_with_neighbours()
            os.remove("test_db_network.db")

        except Exception as exc:
            msg = "{}: {}".format(type(exc).__name__, str(exc))
            no_throw = False
        self.assertTrue(no_throw, msg=msg)