Example #1
0
 def test_relax_single(self):
     sb = StructureBuilder()
     atoms, *_ = sb.get_structure("Si", "diamond")
     print(atoms)
     m_calc = MaterCalc(atoms=atoms, base_dir="../../tmp/Si-class/")
     res = m_calc.relax(fmax=0.002)  # Very tight limit!
     self.assertTrue(res)
Example #2
0
 def test_bs(self):
     sb = StructureBuilder()
     atoms, *_ = sb.get_structure("C", "diamond")
     # print(atoms)
     base_dir = os.path.join(os.path.dirname(__file__),
                             "../../tmp/C-class/")
     m_calc = MaterCalc(atoms=atoms,
                        base_dir=base_dir)
     self.assertTrue(m_calc.relax(fmax=0.002))  # Very tight limit!
     self.assertTrue(m_calc.ground_state())
     # get the PBE BS
     lattice_type = get_cellinfo(m_calc.atoms.cell).lattice
     self.assertTrue(lattice_type in special_paths.keys())
     kpts_bs = dict(path=special_paths[lattice_type],
                    npoints=120)
     # HSE06 base generate
     gs_file = os.path.join(base_dir, "gs.gpw")
     _calc = GPAW(restart=gs_file)
     atoms = _calc.atoms.copy()
     calc = GPAW(**_calc.parameters)
     calc.set(kpts=dict(gamma=True,
                        density=4))  # low density calculations
     calc.atoms = atoms
     del _calc
     calc.get_potential_energy()
     calc.write(os.path.join(base_dir, "hse.gpw"), mode="all")
     calc = GPAW(restart=os.path.join(base_dir, "hse.gpw"),
                 txt=None)
     ns = calc.get_number_of_spins()
     nk = len(calc.get_ibz_k_points())
     nbands = calc.get_number_of_bands()
     eigen_pbe = numpy.array([[calc.get_eigenvalues(spin=s,
                                                    kpt=k) \
                               for k in range(nk)]\
                              for s in range(ns)])
     parprint("EIGEN_PBE", eigen_pbe.shape)
     vxc_pbe = vxc(calc, "PBE")
     parprint("VXC_PBE", vxc_pbe.shape)
     # world.barrier()
     # HSE06 now
     calc_hse = EXX(os.path.join(base_dir, "hse.gpw"),
                    xc="HSE06",
                    bands=[0, nbands])
     calc_hse.calculate()
     vxc_hse = calc_hse.get_eigenvalue_contributions()
     parprint(vxc_hse.shape)
     parprint(vxc_hse)
     eigen_hse = eigen_pbe - vxc_pbe + vxc_hse
     
     # HSE bandgap from just kpts
     bg_hse_min, *_ = bandgap(eigenvalues=eigen_hse,
                              efermi=calc.get_fermi_level(),
                              direct=False)
     bg_hse_dir, *_ = bandgap(eigenvalues=eigen_hse,
                              efermi=calc.get_fermi_level(),
                              direct=True)
     parprint("HSE: E_min \t E_dir")
     parprint("{:.3f}\t{:.3f}".format(bg_hse_min, bg_hse_dir))
     """
Example #3
0
 def test_gs_single(self):
     sb = StructureBuilder()
     atoms, *_ = sb.get_structure("Si", "diamond")
     print(atoms)
     m_calc = MaterCalc(atoms=atoms,
                        base_dir="../../tmp/Si-class/")
     self.assertTrue(m_calc.relax(fmax=0.002))
     self.assertTrue(m_calc.ground_state())
Example #4
0
 def test_single(self):
     sb = StructureBuilder()
     atoms, *_ = sb.get_structure("Si", "diamond")
     base_dir = os.path.join(os.path.dirname(__file__),
                             "../../tmp/Si-eps-test/")
     m_calc = MaterCalc(atoms=atoms, base_dir=base_dir)
     # PBE
     parprint(m_calc.check_status())
Example #5
0
def main():
    sb = StructureBuilder()
    entries = sb.entries
    finished = 0
    for entry in entries:
        formula = entry["formula"]
        prototype = entry["prototype"]
        base_dir = os.path.join(root, "{}-{}".format(formula, prototype))
        mc = MaterCalc(atoms=None, base_dir=base_dir)
        if all([value for key, value in mc.check_status().items()]):
            finished += 1
        else:
            print("{}-{}:".format(formula, prototype), mc.check_status())
    print("Finished jobs {}".format(finished))
    return True
Example #6
0
def main():
    sb = StructureBuilder()
    entries = sb.entries
    for entry in entries:
        formula = entry["formula"]
        prototype = entry["prototype"]
        base_dir = os.path.join(root,
                                "{}-{}".format(formula, prototype))
        mc = MaterCalc(atoms=None, base_dir=base_dir)
        if all([value for key, value in mc.check_status().items()]):
            print("{}-{} calculation done!".format(formula, prototype))
        else:
            sub_job(formula=formula,
                    prototype=prototype)
    return True
Example #7
0
 def test_single(self):
     sb = StructureBuilder()
     atoms, *_ = sb.get_structure("Si", "diamond")
     base_dir = os.path.join(os.path.dirname(__file__),
                             "../../tmp/Si-eps-test/")
     m_calc = MaterCalc(atoms=atoms, base_dir=base_dir)
     self.assertTrue(m_calc.relax(fmax=0.002))
     self.assertTrue(m_calc.ground_state())
     # PBE
     Eg_min, Eg_dir, bs = m_calc.bandgap(method="PBE")
     parprint(Eg_min, Eg_dir)
     self.assertLess(abs(Eg_min - 0.61), 0.15)
     Eg_min, Eg_dir, bs = m_calc.bandgap(method="GLLB")
     parprint(Eg_min, Eg_dir)
     self.assertLess(abs(Eg_min - 1.1), 0.15)
     self.assertTrue(m_calc.excited_state())
     self.assertTrue(m_calc.dielectric())
 def test_relax_single(self):
     sb = StructureBuilder()
     atoms, *_ = sb.get_structure("C", "diamond")
     base_dir = os.path.join(os.path.dirname(__file__),
                             "../../tmp/C-module-test/")
     m_calc = MaterCalc(atoms=atoms, base_dir=base_dir)
     self.assertTrue(m_calc.relax(fmax=0.002))
     self.assertTrue(m_calc.ground_state())
     # PBE
     Eg_min, Eg_dir, bs = m_calc.bandgap("PBE")
     Eg_gllb_min, Eg_gllb_dir, bs = m_calc.bandgap("GLLB")
     with open("PBE-gap.npz", "wb") as f:
         numpy.savez(f, Eg_min=Eg_min, Eg_dir=Eg_dir, **bs)
     parprint("{:.3f}\t{:.3f}".format(Eg_min, Eg_dir))
     parprint("PBE Gap: min \t dir")
     # GLLB
     parprint("GLLB Gap: min \t dir")
     parprint("{:.3f}\t{:.3f}".format(Eg_gllb_min, Eg_gllb_dir))
Example #9
0
    def test_relax_single(self):
        sb = StructureBuilder()
        atoms, *_ = sb.get_structure("C", "diamond")
        # print(atoms)
        m_calc = MaterCalc(atoms=atoms, base_dir="../../tmp/C-class/")
        m_calc.relax(fmax=0.002)  # Very tight limit!
        m_calc.ground_state()

        # self.assertTrue(res)
        base_dir = "../../tmp/C-class/"
        gpw_name = os.path.join(base_dir, "gs.gpw")
        self.assertTrue(os.path.exists(gpw_name))
        calc = GPAW(restart=gpw_name, txt="gp.txt")
        # PBE bandgap
        bg_pbe_min, *_ = bandgap(calc, direct=False)
        bg_pbe_dir, *_ = bandgap(calc, direct=True)
        # gllbsc
        calc_gllb = GPAW(**calc.parameters)
        calc_gllb.atoms = calc.atoms
        calc_gllb.set(xc="GLLBSC", txt="gllb.txt")
        calc_gllb.get_potential_energy()  # SC calculation
        response = calc_gllb.hamiltonian.xc.xcs["RESPONSE"]
        response.calculate_delta_xc()
        EKs, Dxc = response.calculate_delta_xc_perturbation()
        gllb_gap = EKs + Dxc

        parprint("Eg-PBE-min, Eg-PBE-dir, Eg-gllb")
        parprint(bg_pbe_min, bg_pbe_dir, gllb_gap)
        # Use kpts?
        ibz_kpts = calc.get_ibz_k_points()
        e_kn = numpy.array([calc.get_eigenvalues(kpt=k) \
                            for k in range(len(ibz_kpts))])
        efermi = calc.get_fermi_level()
        e_kn[e_kn > efermi] += Dxc
        gllb_gap_min = bandgap(eigenvalues=e_kn, efermi=efermi, direct=False)
        gllb_gap_dir = bandgap(eigenvalues=e_kn, efermi=efermi, direct=True)

        parprint("Efermi", efermi)
        parprint("Eg-gllb-min, Eg-gllb-dir")
        parprint(gllb_gap_min, gllb_gap_dir)
Example #10
0
    def test_bs(self):
        sb = StructureBuilder()
        atoms, *_ = sb.get_structure("Si", "diamond")
        # print(atoms)
        base_dir = os.path.join(os.path.dirname(__file__),
                                "../../tmp/Si-class/")
        m_calc = MaterCalc(atoms=atoms, base_dir=base_dir)
        self.assertTrue(m_calc.relax(fmax=0.002))  # Very tight limit!
        self.assertTrue(m_calc.ground_state())
        # get the PBE BS
        lattice_type = get_cellinfo(m_calc.atoms.cell).lattice
        self.assertTrue(lattice_type in special_paths.keys())
        kpts_bs = dict(path=special_paths[lattice_type], npoints=120)
        gpw_name = os.path.join(base_dir, "gs.gpw")
        self.assertTrue(os.path.exists(gpw_name))
        calc_bs = GPAW(restart=gpw_name,
                       kpts=kpts_bs,
                       fixdensity=True,
                       symmetry='off',
                       txt=os.path.join(base_dir, "pbe-bs.txt"))
        calc_bs.get_potential_energy()
        # PBE bandgap
        bg_pbe_min, *_ = bandgap(calc_bs, direct=False)
        bg_pbe_dir, *_ = bandgap(calc_bs, direct=True)
        calc_bs.write(os.path.join(base_dir, "pbe-bs.gpw"))
        bs_pbe = calc_bs.band_structure()
        bs_pbe.plot(emin=-10,
                    emax=10,
                    filename=os.path.join(base_dir, "pbe-bs.png"))

        # get the gllbsc by steps
        calc_ = GPAW(restart=gpw_name)
        calc_gllb = GPAW(**calc_.parameters)
        calc_gllb.set(xc="GLLBSC", txt=os.path.join(base_dir, "gllb-gs.txt"))
        calc_gllb.atoms = calc_.atoms
        del calc_
        calc_gllb.get_potential_energy()  # SC calculation
        calc_gllb.write("gllb-gs.gpw")
        calc_gllb_bs = GPAW(restart="gllb-gs.gpw",
                            kpts=kpts_bs,
                            fixdensity=True,
                            symmetry="off",
                            txt=os.path.join(base_dir, "gllb-bs.txt"))
        world.barrier()
        calc_gllb_bs.get_potential_energy()
        homolumo = calc_gllb_bs.get_homo_lumo()
        bg_gllb_ks = homolumo[1] - homolumo[0]
        response = calc_gllb_bs.hamiltonian.xc.xcs["RESPONSE"]
        response.calculate_delta_xc(homolumo / Ha)
        EKs, Dxc = response.calculate_delta_xc_perturbation()
        bg_gllb_deltaxc = EKs + Dxc

        ibz_kpts = calc_gllb_bs.get_ibz_k_points()
        e_kn = numpy.array([calc_gllb_bs.get_eigenvalues(kpt=k) \
                            for k in range(len(ibz_kpts))])
        efermi = calc_gllb_bs.get_fermi_level()
        e_kn[e_kn > efermi] += Dxc
        bg_gllb_min, *_ = bandgap(eigenvalues=e_kn,
                                  efermi=efermi,
                                  direct=False)
        bg_gllb_dir, *_ = bandgap(eigenvalues=e_kn, efermi=efermi, direct=True)

        parprint("PBE: E_min \t E_dir")
        parprint("{:.3f}\t{:.3f}".format(bg_pbe_min, bg_pbe_dir))
        parprint("Gllb: EKS \t E_deltaxc")
        parprint("{:.3f}\t{:.3f}".format(bg_gllb_ks, bg_gllb_deltaxc))
        parprint("Gllb: E_min \t E_dir")
        parprint("{:.3f}\t{:.3f}".format(bg_gllb_min, bg_gllb_dir))
        bs_gllb = calc_gllb_bs.band_structure()
        bs_gllb.energies[bs_gllb.energies > bs_gllb.reference] += Dxc
        bs_gllb.plot(emin=-10,
                     emax=10,
                     filename=os.path.join(base_dir, "gllb-bs.png"))

        calc_gllb_bs.write(os.path.join(base_dir, "gllb-bs.gpw"))
Example #11
0
def run_single(formula,
               prototype,
               root="/cluster/scratch/ttian/bulk",
               clean=False):
    prototype = convert_name(prototype)[0]
    name = "{}-{}".format(formula, prototype)
    base_dir = join(root, name)
    # Directory manipulation
    if rank == 0:
        if clean:
            shutil.rmtree(base_dir, ignore_errors=True)

        if not exists(base_dir):
            os.makedirs(base_dir)
    world.barrier()

    sb = StructureBuilder()
    atoms, *_ = sb.get_structure(formula, prototype)
    m_calc = MaterCalc(atoms=atoms, base_dir=base_dir)
    if prototype != "perovskite":
        m_calc.relax(fmax=0.002)
    else:
        # m_calc.relax(fmax=0.02, method="UCF")
        m_calc.relax(skip=True)
    m_calc.ground_state()
    if prototype != "perovskite":
        eg_min, eg_dir, *_ = m_calc.bandgap(method="pbe")
        parprint("PBE min/dir: {:.3f}\t{:.3f}".format(eg_min, eg_dir))
        eg_min, eg_dir, *_ = m_calc.bandgap(method="gllb")
        parprint("GLLB min/dir: {:.3f}\t{:.3f}".format(eg_min, eg_dir))
    else:
        pass
        # eg_min, eg_dir, *_ = m_calc.bandgap(method="pbe", skip=True)
        # parprint("PBE min/dir: {:.3f}\t{:.3f}".format(eg_min, eg_dir))
        # eg_min, eg_dir, *_ = m_calc.bandgap(method="gllb", skip=True)
        # parprint("GLLB min/dir: {:.3f}\t{:.3f}".format(eg_min, eg_dir))
        # Use db values

    m_calc.excited_state()
    m_calc.dielectric(method="rpa")

    return 0