Exemplo n.º 1
0
    def testDPPotcar(self):

        refd = {
            '@module': 'dpgen.database.vasp',
            '@class': 'DPPotcar',
            'symbols': ['Al'],
            'elements': ['Al'],
            'hashs': '',
            'functional': 'PBE'
        }
        try:
            Potcar(['Al'])
            #ps  TITEL  = PAW_PBE Al 04Jan2001
            refd.update({'hashs': ['9aafba2c552fad8414179cae2e888e67']})
        except:
            pass

        for f in self.init_path + self.iter_path:
            fpp = os.path.join(f, 'POTCAR')
            pp = DPPotcar.from_file(fpp)
            self.assertEqual(pp.elements, refd['elements'])
            self.assertEqual(pp.symbols, refd['symbols'])
            self.assertEqual(pp.hashs, refd['hashs'])
            self.assertEqual(pp.functional, refd['functional'])
            self.assertEqual(pp.as_dict(), refd)
Exemplo n.º 2
0
    def __init__(self,
                 symbols=None,
                 functional="PBE",
                 pp_file=None,
                 pp_lists=None):
        if pp_lists and pp_file is None:
            for pp in pp_lists:
                assert isinstance(pp, PotcarSingle)
            self.potcars = pp_lists
        elif pp_file and pp_list is None:
            self.potcars = Potcar.from_file(pp_file)
        elif pp_file and pp_list:
            self.potcars = Potcar.from_file(pp_file)
        else:
            try:
                self.potcars = Potcar(symbols=symbols, functional=functional)
            except:
                warnings.warn("""Inproperly configure of POTCAR !""")
                self.potcars = None

        if self.potcars is not None:
            self.symbols = [pp.symbol for pp in self.potcars]
            self.functional = list(set([pp.functional
                                        for pp in self.potcars]))[0]
            self.hashs = [pp.get_potcar_hash() for pp in self.potcars]
        else:
            self.symbols = symbols
            self.functional = functional
            self.hashs = ''
        self.elements = self._get_elements()
    def test_gga(self) -> None:
        xc_task_potcar = XcTaskPotcar.from_options(xc=Xc.pbe,
                                                   symbol_list=["Mg", "O"])

        expected = Potcar(["Mg", "O"], functional="PBE_54").as_dict()
        self.assertEqual(expected, xc_task_potcar.potcar.as_dict())
        self.assertEqual(400.0, xc_task_potcar.max_enmax)
Exemplo n.º 4
0
def default_dict():
    return {"composition": Composition("HO2"),
            "symbol_list": ["H", "O"],
            "num_kpts": 5,
            "num_kpt_multiplication_factor": 1,
            "potcar": Potcar(["H", "O"]),
            "xc": Xc.pbe,
            "task": Task.structure_opt}
    def test_override(self) -> None:
        xc_task_potcar = \
            XcTaskPotcar.from_options(xc=Xc.pbe,
                                      symbol_list=["Mg", "O"],
                                      override_potcar_set={"O": "O_h"})

        expected = Potcar(["Mg", "O_h"], functional="PBE_54").as_dict()
        self.assertEqual(expected, xc_task_potcar.potcar.as_dict())
    def test_mp_relax_set(self) -> None:
        xc_task_potcar = \
            XcTaskPotcar.from_options(xc=Xc.pbe,
                                      symbol_list=["Mg", "O"],
                                      potcar_set_name="mp_relax_set")

        expected = Potcar(["Mg_pv", "O"], functional="PBE_54").as_dict()
        self.assertEqual(expected, xc_task_potcar.potcar.as_dict())
Exemplo n.º 7
0
def gen_potcar(dirname, filename):
    if filename == "POTCAR.spec":
        fullpath = os.path.join(dirname, filename)
        f = open(fullpath, "r")
        elements = f.readlines()
        f.close()
        symbols = [el.strip() for el in elements if el.strip() != ""]
        potcar = Potcar(symbols)
        potcar.write_file(os.path.join(dirname, "POTCAR"))
 def setUp(self) -> None:
     self.default_kwargs = {
         "potcar": Potcar(["Mg", "O"]),
         "composition": Composition({
             "Mg": 1,
             "O": 2
         }),
         "charge": 1
     }
Exemplo n.º 9
0
def test_ldau_option(default_dict):
    generator = IncarSettingsGenerator(composition=Composition("Zn"),
                                       symbol_list=["Zn"],
                                       potcar=Potcar(["Zn"]),
                                       num_kpts=5,
                                       num_kpt_multiplication_factor=1,
                                       xc=Xc.pbe,
                                       task=Task.structure_opt,
                                       ldau=False)
    assert "LDAU" not in generator.incar_settings
Exemplo n.º 10
0
def test_nbands():
    composition = Composition("KH2")
    potcar = Potcar(symbols=["Mn", "O"])
    nelect_mn_pv = 7
    nelect_o = 6
    unoccupied_band_mn = 9
    unoccupied_band_o = 4
    expected = (ceil((nelect_mn_pv + nelect_o * 2) / 2) + unoccupied_band_mn +
                unoccupied_band_o * 2)
    assert num_bands(composition, potcar) == expected
Exemplo n.º 11
0
def generate_potcar(args):
    if args.recursive:
        proc_dir(args.spec, gen_potcar)
    elif args.symbols:
        try:
            p = Potcar(args.symbols, functional=args.functional)
            p.write_file("POTCAR")
        except Exception as ex:
            print("An error has occurred: {}".format(str(ex)))

    else:
        print("No valid options selected.")
Exemplo n.º 12
0
    def test_modify_potcar(self):
        Potcar(["Si"]).write_file("POTCAR")
        potcar = Potcar.from_file("POTCAR")
        self.assertFalse("alt" in potcar[0].header)

        # modify/test
        ft = ModifyPotcar(potcar_symbols={"Si": "O"})
        ft = load_object(ft.to_dict())  # simulate database insertion
        ft.run_task({})

        new_potcar = Potcar.from_file("POTCAR")
        self.assertEqual(len(new_potcar), 1)
        self.assertEqual(new_potcar[0].symbol, "O")
Exemplo n.º 13
0
 def setUp(self) -> None:
     mgo = self.get_structure_by_name("MgO64atoms")
     potcar = Potcar(["Mg", "O"], functional="PBE_54")
     self.defect = TaskIncarSettings.from_options(
         task=Task.defect,
         structure=mgo,
         potcar=potcar,
         num_kpoints=10,
         max_enmax=400.0,
         is_magnetization=False,
         band_gap=5.0,
         vbm_cbm=[2.0, 7.0],
         npar_kpar=False,
         encut=None,
         structure_opt_encut_factor=1.3)
Exemplo n.º 14
0
def gen_potcar(dirname, filename):
    """
    Generate POTCAR from POTCAR.spec in directories.

    Args:
        dirname (str): Directory name.
        filename (str): Filename in directory.
    """
    if filename == "POTCAR.spec":
        fullpath = os.path.join(dirname, filename)
        with open(fullpath, "r") as f:
            elements = f.readlines()
        symbols = [el.strip() for el in elements if el.strip() != ""]
        potcar = Potcar(symbols)
        potcar.write_file(os.path.join(dirname, "POTCAR"))
 def setUp(self) -> None:
     mgo = self.get_structure_by_name("MgO")
     self.default_kwargs = {
         "task": Task.structure_opt,
         "structure": mgo,
         "potcar": Potcar(["Mg", "O"]),
         "num_kpoints": 8,
         "max_enmax": 400.0,
         "is_magnetization": False,
         "vbm_cbm": [3.0, 8.0],
         "npar_kpar": True,
         "num_nodes": 1,
         "encut": None,
         "structure_opt_encut_factor": 1.3,
         "dos_step_size": 0.01
     }
Exemplo n.º 16
0
def generate_potcar(args):
    """
    Generate POTCAR.

    Args:
        args (dict): Args from argparse.
    """
    if args.recursive:
        proc_dir(args.recursive, gen_potcar)
    elif args.symbols:
        try:
            p = Potcar(args.symbols, functional=args.functional)
            p.write_file("POTCAR")
        except Exception as ex:
            print("An error has occurred: {}".format(str(ex)))

    else:
        print("No valid options selected.")
def test_hse_structure_opt(default_dict):
    default_dict.update({
        "xc": Xc.hse,
        "composition": Composition("UO2"),
        "symbol_list": ["U", "O"],
        "potcar": Potcar(["U", "O"]),
        "exchange_ratio": 0.5,
        "set_hubbard_u": True
    })

    generator = IncarSettingsGenerator(**default_dict)
    # for k, v in generator.incar_settings.items():
    #     print(f'\"{k}\": {v}, ')
    expected = {
        "ALGO": "Damped",
        "PREC": "Normal",
        "LREAL": False,
        "EDIFF": 1e-07,
        "ENCUT": 520.0,
        "LASPH": True,
        "NELM": 100,
        "ISIF": 3,
        "IBRION": 2,
        "EDIFFG": -0.005,
        "NSW": 50,
        "ISMEAR": 0,
        "SIGMA": 0.1,
        "LWAVE": True,
        "LCHARG": False,
        "LORBIT": 10,
        "LHFCALC": True,
        "PRECFOCK": "Fast",
        "TIME": 0.4,
        "AEXX": 0.5,
        "HFSCREEN": 0.208,
        "LDAU": True,
        "LDAUTYPE": 2,
        "LMAXMIX": 6,
        "LDAUPRINT": 1,
        "LDAUU": [5, 0],
        "LDAUL": [3, -1],
        "KPAR": 1,
    }
    assert generator.incar_settings == expected
    def from_options(cls,
                     xc: Xc,
                     symbol_list: list,
                     potcar_set_name: str = None,
                     override_potcar_set: dict = None):
        """ Construct Potcar from xc and some options.

        Args: See ViseInputSet docstrings

        Return: XcTaskPotcar class object
        """

        potcar_functional = "LDA" if xc == Xc.lda else "PBE_54"
        # Currently GW calc is not supported.
        potcar_set_name = potcar_set_name or "normal"

        potcar_list = load_potcar_yaml(potcar_set_name, override_potcar_set)
        potcar_symbols = [potcar_list.get(el, el) for el in symbol_list]
        potcar = Potcar(potcar_symbols, functional=potcar_functional)

        max_enmax = max([p.enmax for p in potcar])

        return cls(potcar, max_enmax)
Exemplo n.º 19
0
    def testParsingVasp(self):
        parsing_vasp(self.cwd, id_prefix=dpgen.SHORT_CMD)
        try:
            Potcar(['Al'])
            ref = os.path.join(self.cwd, 'data/all_data_pp.json')
        except:
            ref = os.path.join(self.cwd, 'data/all_data.json')
        ret = os.path.join(self.cwd, 'dpgen_db.json')

        retd = loadfn(ret)
        retd = sorted(retd, key=lambda x: int(x.entry_id.split('_')[-1]))

        refd = loadfn(ref)
        refd = sorted(refd, key=lambda x: int(x.entry_id.split('_')[-1]))
        self.assertEqual(len(retd), len(refd))
        for i, j in zip(retd, refd):
            self.assertEqual(i.entry_id, j.entry_id)
            self.assertEqual(i.calculator, j.calculator)
            self.assertEqual(len(i.data), len(j.data))
            self.assertEqual(i.number_element, j.number_element)
            self.assertEqual(i.entry_id, j.entry_id)
            self.assertEqual(len(i.composition), len(j.composition))
            self.assertEqual(len(i.attribute), len(j.attribute))
        os.remove(os.path.join(self.cwd, 'dpgen_db.json'))
Exemplo n.º 20
0
 def setUp(self):
     self.mgo = self.get_structure_by_name("MgO")
     self.potcar = Potcar(["Mg", "O"], functional="PBE_54")
    def test_lda(self) -> None:
        xc_task_potcar = XcTaskPotcar.from_options(xc=Xc.lda,
                                                   symbol_list=["Mg", "O"])

        expected = Potcar(["Mg", "O"], functional="LDA").as_dict()
        self.assertEqual(expected, xc_task_potcar.potcar.as_dict())