Example #1
0
    def setUp(self):
        # Si ebands
        self.si_structure = abidata.structure_from_cif("si.cif")
        self.si_pseudo = abidata.pseudos("14si.pspnc")

        self.gan_structure = abidata.structure_from_cif("gan.cif")
        self.n_pseudo = abidata.pseudos("7n.pspnc")
        self.ga_pseudo = abidata.pseudos("31ga.pspnc")
Example #2
0
    def setUp(self):
        # Si ebands
        self.si_structure = abidata.structure_from_cif("si.cif")
        self.si_pseudo = abidata.pseudos("14si.pspnc")

        self.gan_structure = abidata.structure_from_cif("gan.cif")
        self.n_pseudo = abidata.pseudos("7n.pspnc")
        self.ga_pseudo = abidata.pseudos("31ga.pspnc")
Example #3
0
    def test_effmassline_work(self):
        """Testing EffMassLineWork."""
        si_structure = abidata.structure_from_cif("si.cif")

        scf_input = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), ecut=4, spin_mode="unpolarized")
        flow = flowtk.Flow.temporary_flow()

        with self.assertRaises(ValueError):
            work = EffMassLineWork.from_scf_input(scf_input, k0_list=(0, 0, 0), step=0.01, npts=2)

        # Run SCF from scratch.
        work = EffMassLineWork.from_scf_input(scf_input, k0_list=(0, 0, 0), step=0.01, npts=9)

        t0, t1 = work[0], work[1]
        assert t1.depends_on(t0)
        assert t1.input["kptopt"] == 0
        assert t1.input["iscf"] == -2

        flow.register_work(work)
        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok

        # From DEN file
        flow = flowtk.Flow.temporary_flow()
        work = EffMassLineWork.from_scf_input(scf_input, k0_list=(0, 0, 0), step=0.01, npts=10,
                                              red_dirs=(1, 0, 0),
                                              cart_dirs=[(1, 0, 0), (1, 1, 0)],
                                              den_node=abidata.ref_file("si_DEN.nc"))
        flow.register_work(work)
        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok
Example #4
0
    def test_gruneisen_work(self):
        """Testing GruneisenWork."""
        si_structure = abidata.structure_from_cif("si.cif")

        gs_inp = gs_input(si_structure,
                          pseudos=abidata.pseudos("14si.pspnc"),
                          ecut=4,
                          spin_mode="unpolarized")
        flow = flowtk.Flow.temporary_flow()
        voldelta = gs_inp.structure.volume * 0.02
        work = GruneisenWork.from_gs_input(gs_inp,
                                           voldelta,
                                           ngqpt=[2, 2, 2],
                                           with_becs=False)
        flow.register_work(work)

        assert len(work.relax_tasks) == 3
        assert all(t.input["optcell"] == 3 for t in work)
        assert all(t.input["ionmov"] == 3 for t in work)
        assert all(t.input["ecutsm"] == 0.5 for t in work)
        assert all(t.input["dilatmx"] == 1.05 for t in work)

        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok

        with self.assertRaises(ValueError):
            GruneisenWork.from_gs_input(gs_inp,
                                        voldelta,
                                        ngqpt=[3, 3, 3],
                                        with_becs=False)
Example #5
0
    def test_phonopy_work(self):
        """Testing PhononWork."""
        self.skip_if_not_phonopy()
        si_structure = abidata.structure_from_cif("si.cif")
        same_structure = abiph.structure_from_atoms(abiph.atoms_from_structure(si_structure))
        assert si_structure == same_structure

        # TODO: Spin
        gsinp = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), ecut=4, spin_mode="unpolarized")
        #gsinp = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), ecut=4, spin_mode="polarized")
        flow = flowtk.Flow.temporary_flow()
        scdims = [2, 2, 2]
        phpy_work = abiph.PhonopyWork.from_gs_input(gsinp, scdims=scdims, phonopy_kwargs=None, displ_kwargs=None)
        flow.register_work(phpy_work)

        self.assert_equal(scdims, phpy_work.scdims)
        assert hasattr(phpy_work, "phonon")
        assert len(phpy_work.phonopy_tasks) == len(phpy_work)
        assert len(phpy_work.phonopy_tasks) == 1
        assert len(phpy_work.bec_tasks) == 0

        # Gruneisen with phonopy
        grun_work = abiph.PhonopyGruneisenWork.from_gs_input(gsinp, voldelta=0.1, scdims=scdims,
                                                             phonopy_kwargs=None, displ_kwargs=None)
        flow.register_work(grun_work)

        self.assert_equal(scdims, grun_work.scdims)

        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok
Example #6
0
def itest_phonopy_flow(fwp, tvars):
    """
    Testing phonopy flow with the scheduler.
    """
    if not has_phonopy():
        raise unittest.SkipTest("This test requires phonopy")

    #print("tvars:\n %s" % str(tvars))
    si_structure = abidata.structure_from_cif("si.cif")

    gsinp = gs_input(si_structure,
                     pseudos=abidata.pseudos("14si.pspnc"),
                     kppa=10,
                     ecut=2,
                     spin_mode="unpolarized")
    gsinp["paral_kgb"] = tvars.paral_kgb

    flow = flowtk.Flow(workdir=fwp.workdir, manager=fwp.manager)
    scdims = [2, 2, 2]
    phpy_work = abiph.PhonopyWork.from_gs_input(gsinp,
                                                scdims=scdims,
                                                phonopy_kwargs=None,
                                                displ_kwargs=None)
    flow.register_work(phpy_work)

    assert hasattr(phpy_work, "phonon")
    assert len(phpy_work.phonopy_tasks) == len(phpy_work)
    assert len(phpy_work.phonopy_tasks) == 1
    assert len(phpy_work.bec_tasks) == 0
    nptu.assert_equal(scdims, phpy_work.scdims)

    # Will remove output files (WFK)
    flow.set_garbage_collector()
    flow.use_smartio()

    flow.build_and_pickle_dump(abivalidate=True)
    scheduler = flow.make_scheduler()
    assert scheduler.start() == 0

    assert not scheduler.exceptions
    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    # The WFK files should have been removed because we called set_garbage_collector
    for task in flow[0]:
        assert not task.outdir.has_abiext("WFK")

    out_filenames = set(
        [os.path.basename(f) for f in phpy_work.outdir.list_filepaths()])
    nmiss = 0
    for f in [
            "POSCAR", "disp.yaml", "FORCE_SETS", "band.conf", "dos.conf",
            "band-dos.conf", "README.md"
    ]:
        if f not in out_filenames:
            nmiss += 1
            print("Cannot find %s in work.outdir" % f)
    assert nmiss == 0
Example #7
0
def itest_phonopy_flow(fwp, tvars):
    """
    Testing phonopy Gruneisen flow with the scheduler.
    """
    if not has_phonopy():
        raise unittest.SkipTest("This test requires phonopy")

    #print("tvars:\n %s" % str(tvars))
    si_structure = abidata.structure_from_cif("si.cif")

    gsinp = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), kppa=10, ecut=2, spin_mode="unpolarized")
    gsinp["paral_kgb"] = tvars.paral_kgb

    flow = flowtk.Flow(workdir=fwp.workdir, manager=fwp.manager)
    scdims = [2, 2, 2]

    # Grunesein with phonopy
    grun_work = abiph.PhonopyGruneisenWork.from_gs_input(gsinp, voldelta=0.1, scdims=scdims,
                                                         phonopy_kwargs=None, displ_kwargs=None)
    flow.register_work(grun_work)
    assert len(grun_work) == 3
    nptu.assert_equal(scdims, grun_work.scdims)

    # Will remove output files (WFK)
    flow.set_garbage_collector()
    flow.use_smartio()

    flow.build_and_pickle_dump(abivalidate=True)
    scheduler = flow.make_scheduler()
    assert scheduler.start() == 0

    assert not scheduler.exceptions
    flow.show_status()
    assert flow.all_ok
    # Initialial work + 3 phonopy works.
    assert len(flow) == 4
    assert all(work.finalized for work in flow)

    # The WFK files should have been removed because we called set_garbage_collector
    # FIXME: This does not work because new works that have been created.
    #for task in flow.iflat_tasks():
    #    assert not task.outdir.has_abiext("WFK")

    for work in flow[1:]:
        out_filenames = set([os.path.basename(f) for f in work.outdir.list_filepaths()])
        nmiss = 0
        for f in ["POSCAR", "disp.yaml", "FORCE_SETS", "band.conf", "dos.conf", "band-dos.conf", "README.md"]:
            if f not in out_filenames:
                nmiss += 1
                print("Cannot find %s in work.outdir" % f)
        assert nmiss == 0
Example #8
0
    def test_infinite_flow(self):
        si_structure = abidata.structure_from_cif("si.cif")
        gsinp = gs_input(si_structure,
                         pseudos=abidata.pseudos("14si.pspnc"),
                         ecut=4)

        flow = flowtk.Flow.temporary_flow()
        work = flowtk.Work()
        gstask = work.register_scf_task(gsinp)
        flow.register_work(work)
        flow.allocate()

        mocks.infinite_flow(flow)
        flow.check_status()
        assert (t.status == flow.S_INIT for t in flow)

        mocks.change_task_start(gstask, mocked_status="Error")
        assert gstask.start() == 1 and gstask.status == gstask.S_ERROR
Example #9
0
    def test_effmass_autodfpt_work(self):
        """Testing EffMassAutoDFPTWork."""
        si_structure = abidata.structure_from_cif("si.cif")

        scf_input = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), ecut=4, spin_mode="unpolarized")
        flow = flowtk.Flow.temporary_flow()

        # Run SCF from scratch.
        work = EffMassAutoDFPTWork.from_scf_input(scf_input)

        assert len(work) == 2
        assert work[1].depends_on(work[0])

        flow.register_work(work)
        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok
Example #10
0
    def test_data_api(self):
        """Testing abipy.data API."""
        ncpseudo_h = abidata.pseudo("01h.pspgth")
        assert ncpseudo_h.isnc
        paw_table = abidata.pseudos("1h.paw", "28ni.paw")
        assert paw_table.allpaw
        assert os.path.isfile(abidata.cif_file("al.cif"))
        assert os.path.isfile(abidata.pyscript("plot_bz.py"))

        d = abidata.get_mp_structures_dict()
        assert isinstance(d, dict) and d is abidata.get_mp_structures_dict()

        structure = abidata.structure_from_cif("gan2.cif")
        assert hasattr(structure, "to_abivars")

        structure = abidata.structure_from_mpid("mp-4820")
        assert hasattr(structure, "to_abivars")
        with self.assertRaises(KeyError):
            abidata.structure_from_mpid("foobar")
Example #11
0
    def test_phonopy_work(self):
        """Testing PhononWork."""
        self.skip_if_not_phonopy()
        si_structure = abidata.structure_from_cif("si.cif")
        same_structure = abiph.structure_from_atoms(
            abiph.atoms_from_structure(si_structure))
        assert si_structure == same_structure

        # TODO: Spin
        gsinp = gs_input(si_structure,
                         pseudos=abidata.pseudos("14si.pspnc"),
                         ecut=4,
                         spin_mode="unpolarized")
        #gsinp = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), ecut=4, spin_mode="polarized")
        flow = flowtk.Flow.temporary_flow()
        scdims = [2, 2, 2]
        phpy_work = abiph.PhonopyWork.from_gs_input(gsinp,
                                                    scdims=scdims,
                                                    phonopy_kwargs=None,
                                                    displ_kwargs=None)
        flow.register_work(phpy_work)

        self.assert_equal(scdims, phpy_work.scdims)
        assert hasattr(phpy_work, "phonon")
        assert len(phpy_work.phonopy_tasks) == len(phpy_work)
        assert len(phpy_work.phonopy_tasks) == 1
        assert len(phpy_work.bec_tasks) == 0

        # Gruneisen with phonopy
        grun_work = abiph.PhonopyGruneisenWork.from_gs_input(
            gsinp,
            voldelta=0.1,
            scdims=scdims,
            phonopy_kwargs=None,
            displ_kwargs=None)
        flow.register_work(grun_work)

        self.assert_equal(scdims, grun_work.scdims)

        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok
Example #12
0
    def test_data_api(self):
        """Testing abipy.data API."""
        ncpseudo_h = abidata.pseudo("01h.pspgth")
        assert ncpseudo_h.isnc
        paw_table = abidata.pseudos("1h.paw", "28ni.paw")
        assert paw_table.allpaw
        assert os.path.isfile(abidata.cif_file("al.cif"))
        assert os.path.isfile(abidata.pyscript("plot_bz.py"))

        d = abidata.get_mp_structures_dict()
        assert isinstance(d, dict) and d is abidata.get_mp_structures_dict()

        structure = abidata.structure_from_cif("gan2.cif")
        assert hasattr(structure, "to_abivars")

        structure = abidata.structure_from_mpid("mp-4820")
        assert hasattr(structure, "to_abivars")
        with self.assertRaises(KeyError):
            abidata.structure_from_mpid("foobar")
Example #13
0
    def test_effmass_dfpt_work(self):
        """Testing EffMassDFPTWork."""
        si_structure = abidata.structure_from_cif("si.cif")

        scf_input = gs_input(si_structure, pseudos=abidata.pseudos("14si.pspnc"), ecut=4, spin_mode="unpolarized")
        flow = flowtk.Flow.temporary_flow()

        # Run SCF from scratch.
        work = EffMassDFPTWork.from_scf_input(scf_input, k0_list=(0, 0, 0), effmass_bands_f90=[2, 4])

        assert len(work) == 3
        t0, t1, t2 = work
        assert t1.input["iscf"] == -2
        assert t2.input["kptopt"] == 0
        assert t2.input["efmas"] == 1 and t2.input["rfelfd"] == 2
        assert t2.depends_on(t1)

        flow.register_work(work)
        flow.allocate()
        flow.check_status()
        isok, checks = flow.abivalidate_inputs()
        assert isok
Example #14
0
def itest_phonopy_gruneisen_flow(fwp, tvars):
    """
    Testing phonopy Gruneisen flow with the scheduler.
    """
    if not has_phonopy():
        raise unittest.SkipTest("This test requires phonopy")

    #print("tvars:\n %s" % str(tvars))
    si_structure = abidata.structure_from_cif("si.cif")

    gsinp = gs_input(si_structure,
                     pseudos=abidata.pseudos("14si.pspnc"),
                     kppa=10,
                     ecut=2,
                     spin_mode="unpolarized")
    gsinp["paral_kgb"] = tvars.paral_kgb

    flow = flowtk.Flow(workdir=fwp.workdir, manager=fwp.manager)
    scdims = [2, 2, 2]

    # Grunesein with phonopy
    grun_work = abiph.PhonopyGruneisenWork.from_gs_input(gsinp,
                                                         voldelta=0.1,
                                                         scdims=scdims,
                                                         phonopy_kwargs=None,
                                                         displ_kwargs=None)
    flow.register_work(grun_work)
    assert len(grun_work) == 3
    nptu.assert_equal(scdims, grun_work.scdims)

    # Will remove output files (WFK)
    flow.set_garbage_collector()
    flow.use_smartio()

    flow.build_and_pickle_dump(abivalidate=True)
    scheduler = flow.make_scheduler()
    assert scheduler.start() == 0

    assert not scheduler.exceptions
    flow.show_status()
    if not flow.all_ok:
        flow.debug()
        raise RuntimeError()
    # Initialial work + 3 phonopy works.
    assert len(flow) == 4
    assert all(work.finalized for work in flow)

    # The WFK files should have been removed because we called set_garbage_collector
    # FIXME: This does not work because new works that have been created.
    #for task in flow.iflat_tasks():
    #    assert not task.outdir.has_abiext("WFK")

    for work in flow[1:]:
        out_filenames = set(
            [os.path.basename(f) for f in work.outdir.list_filepaths()])
        nmiss = 0
        for f in [
                "POSCAR", "disp.yaml", "FORCE_SETS", "band.conf", "dos.conf",
                "band-dos.conf", "README.md"
        ]:
            if f not in out_filenames:
                nmiss += 1
                print("Cannot find %s in work.outdir" % f)
        assert nmiss == 0