Example #1
0
def build_flow(options):
    # Path of the pseudopotential to test.
    #pseudo = data.pseudo("14si.pspnc")
    pseudo = data.pseudo("Si.GGA_PBE-JTH-paw.xml")

    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    # Initialize the flow.
    flow = abilab.Flow(workdir=workdir, manager=options.manager, remove=options.remove)

    # Build the workflow for the computation of the deltafactor.
    # The calculation is done with the parameters and the cif files
    # used in the original paper. We only have to specify 
    # the cutoff energy ecut (Ha) for the pseudopotential.
    # The workflow will produce a pdf file with the equation of state 
    # and a file deltafactor.txt with the final results in the 
    # outdir directory DELTAFACTOR/work_0/outdir.
    factory = DeltaFactory()

    kppa = 6750  # Use this to have the official k-point sampling
    kppa = 50    # this value is for testing purpose.

    ecut = 8
    pawecutdg = ecut * 2 if pseudo.ispaw else None

    work = factory.work_for_pseudo(pseudo, accuracy="normal", kppa=kppa, 
                                   ecut=ecut, pawecutdg=pawecutdg,
                                   toldfe=1.e-8, smearing="fermi_dirac:0.0005")

    # Register the workflow.
    flow.register_work(work)
    return flow
Example #2
0
    def add_pseudo(self, pseudo):
        """Add a pseudo to the Dojo."""
        pseudo = Pseudo.as_pseudo(pseudo)
        dojo_report = pseudo.dojo_report

        # Construct the flow 
        flow_workdir = os.path.join(self.workdir, pseudo.basename)
        flow = Flow(workdir=flow_workdir, manager=self.manager)

        # Construct the flow according to the info found in the dojo report.
        if not pseudo.has_hints:
            # We need the hints in order to run the other tests
            factory = PPConvergenceFactory()
            ecut_work = factory.work_for_pseudo(pseudo, ecut_slice=slice(4, None, 1), nlaunch=4)
            flow.register_work(ecut_work)

        else:
            # Hints are available --> construct a flow for the different trials.
            dojo_trial = "deltafactor"
            if dojo_trial in self.trials:
                # Do we have this element in the deltafactor database?
                #if not df_database().has_symbol(pseudo.symbol):
                #    logger.warning("Cannot find %s in deltafactor database." % pseudo.symbol)

                delta_factory = DeltaFactory()
                kppa = 6750 # 6750 is the value used in the deltafactor code.
                kppa = 1

                for accuracy in self.accuracies:
                    if dojo_report.has_trial(dojo_trial, accuracy): continue
                    ecut, pawecutdg = self._ecut_pawecutdg(pseudo, accuracy)
                    work = delta_factory.work_for_pseudo(pseudo, accuracy=accuracy, kppa=kppa, ecut=ecut, pawecutdg=pawecutdg)

                    logger.info("Adding work for %s with accuracy %s" % (dojo_trial, accuracy))
                    work.set_dojo_accuracy(accuracy)
                    flow.register_work(work)

            # Test if GBRV tests are wanted.
            gbrv_structs = [s.split("_")[1] for s in self.trials if s.startswith("gbrv_")]

            if gbrv_structs:
                gbrv_factory = GbrvFactory()
                for struct_type in gbrv_structs:
                    dojo_trial = "gbrv_" + struct_type
                    for accuracy in self.accuracies:
                        if dojo_report.has_trial(dojo_trial, accuracy): continue
                        ecut, pawecutdg = self._ecut_pawecutdg(pseudo, accuracy)
                        work = gbrv_factory.relax_and_eos_work(pseudo, struct_type, ecut=ecut, pawecutdg=pawecutdg)

                        logger.info("Adding work for %s with accuracy %s" % (dojo_trial, accuracy))
                        work.set_dojo_accuracy(accuracy)
                        flow.register_work(work)

        flow.allocate()
        self.pseudos.append(pseudo)
        self.flows.append(flow)
Example #3
0
def itest_deltafactor_gga_pawxml(fwp, tvars):
    """
    Testing the flow used for the computation of the deltafactor with PAW and GGA XC.
    """
    # Path of the pseudopotential to test.
    pseudo = pdj_data.pseudo("Si.GGA_PBE-JTH-paw.xml").as_tmpfile(
        tmpdir=fwp.workdir)
    assert pseudo is not None
    assert pseudo.has_dojo_report
    assert not pseudo.dojo_report.exceptions

    flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager)

    # Build the workflow for the computation of the deltafactor.
    # The workflow will produce a pdf file with the equation of state
    # and a file deltafactor.txt with the final results in the
    # outdir directory DELTAFACTOR/work_0/outdir.
    kppa = 20  # this value is for testing purpose (6570 is the correct one)
    ecut = 2
    pawecutdg = ecut * 2 if pseudo.ispaw else None

    assert not pseudo.dojo_report.has_trial("deltafactor", ecut=ecut)
    work = DeltaFactory(pseudo.xc).work_for_pseudo(pseudo,
                                                   kppa=kppa,
                                                   ecut=ecut,
                                                   pawecutdg=pawecutdg,
                                                   include_soc=False,
                                                   paral_kgb=tvars.paral_kgb)

    # Register the workflow.
    flow.register_work(work)
    flow.build_and_pickle_dump(abivalidate=True)

    for task in flow[0]:
        task.start_and_wait()

    flow.check_status(show=True)
    assert flow.all_ok
    assert all(work.finalized for work in flow)
    results = flow[0].get_results()

    #20.453 ang^3 88.545 GPa 4.31 20.8658081501 336.680999051 GPa -35.681897152
    #delta Equation of State: deltafactor_polyfit
    #Minimum volume = 20.87 Ang^3
    #modulus = 2.10 eV/Ang^3 = 336.68 GPa, b1 = -35.68
    #Deltafactor = 15.681 meV
    assert pseudo.dojo_report.has_trial("deltafactor", ecut=ecut)
    assert not pseudo.dojo_report.exceptions
Example #4
0
def itest_deltafactor_gga_ncsoc(fwp, tvars):
    """
    Testing the flow used for the computation of the deltafactor with GGA and NC+SOC.
    """
    # return
    # Path of the pseudopotential to test.
    pseudo = pdj_data.pseudo("Pb-d-3_r.psp8").as_tmpfile(tmpdir=fwp.workdir)
    assert pseudo.has_dojo_report
    assert pseudo.supports_soc
    assert not pseudo.dojo_report.exceptions

    flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager)

    # Build the workflow for the computation of the deltafactor.
    # The workflow will produce a pdf file with the equation of state
    # and a file deltafactor.txt with the final results in the
    # outdir directory DELTAFACTOR/work_0/outdir.
    kppa = 40  # this value is for testing purpose (6570 is the correct one)
    ecut = 8
    pawecutdg = ecut * 2 if pseudo.ispaw else None

    assert pseudo.dojo_report.has_trial("deltafactor", ecut=12)
    assert not pseudo.dojo_report.has_trial("deltafactor_soc", ecut=ecut)

    work = DeltaFactory(pseudo.xc).work_for_pseudo(pseudo,
                                                   kppa=kppa,
                                                   ecut=ecut,
                                                   pawecutdg=pawecutdg,
                                                   include_soc=True,
                                                   paral_kgb=tvars.paral_kgb)

    # Register the workflow.
    flow.register_work(work)
    flow.build_and_pickle_dump(abivalidate=True)

    for task in flow[0]:
        task.start_and_wait()

    flow.check_status(show=True)
    assert flow.all_ok
    assert all(work.finalized for work in flow)
    results = flow[0].get_results()

    assert pseudo.dojo_report.has_trial("deltafactor_soc", ecut=ecut)
    assert not pseudo.dojo_report.exceptions
Example #5
0
def itest_deltafactor(fwp, tvars):
    """Test the flow used for the computation of the deltafactor."""

    # Path of the pseudopotential to test.
    pseudo = abidata.pseudo("Si.GGA_PBE-JTH-paw.xml")

    flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager)

    # Build the workflow for the computation of the deltafactor.
    # The workflow will produce a pdf file with the equation of state
    # and a file deltafactor.txt with the final results in the
    # outdir directory DELTAFACTOR/work_0/outdir.

    kppa = 20  # this value is for testing purpose (6570 is the correct one)
    ecut = 2
    pawecutdg = ecut * 2 if pseudo.ispaw else None

    work = DeltaFactory().work_for_pseudo(pseudo,
                                          kppa=kppa,
                                          ecut=ecut,
                                          pawecutdg=pawecutdg,
                                          paral_kgb=tvars.paral_kgb)

    # Register the workflow.
    flow.register_work(work)
    flow.allocate()
    flow.build_and_pickle_dump()

    for task in flow[0]:
        task.start_and_wait()

    flow.check_status()
    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)
    results = flow[0].get_results()
Example #6
0
def build_flow(pseudo, options):
    """Build the flow, returns None if no calculation must be performed.""" 
    pseudo = Pseudo.as_pseudo(pseudo)

    workdir = pseudo.basename + "_DOJO"
    if os.path.exists(workdir): 
        warn("Directory %s already exists" % workdir)
        return None
        #raise ValueError("%s exists" % workdir)

    flow = abilab.Flow(workdir=workdir, manager=options.manager)

    extra_abivars = {
            "mem_test": 0,
            "fband": 2,
            "nstep": 100,
            "paral_kgb": options.paral_kgb
            #"nsym": 1,
    }

    report = pseudo.read_dojo_report()
    #print(report)
    #hints = report["hints"]

    # Build ecut mesh.
    try:
        ppgen_ecut = int(report["ppgen_hints"]["high"]["ecut"])

        ecut_list = copy.copy(report["ecuts"])
    except KeyError:
        print('New pseudo without report from the generator, the convergence study is started from 16H')
        report["ppgen_hints"] = {}
        report["ppgen_hints"]["high"] = {} 
        report["ppgen_hints"]["high"]["ecut"] = 16.0
        report["ecuts"] = [16.0, 20.0, 24.0]
        pseudo.write_dojo_report(report)
        ppgen_ecut = int(report["ppgen_hints"]["high"]["ecut"])
        ecut_list = copy.copy(report["ecuts"])

    #if 'extend' in options:
    #    next_ecut = max(ecut_list) + 2
    #    ecut_list.append(next_ecut)

    #if 'new-ecut' in options:
    #    ecut_list.append(options['new-ecut'])

    add_ecuts = False
    if add_ecuts:
        #dense_right = np.linspace(ppgen_ecut, ppgen_ecut + 10, num=6)
        #dense_left = np.linspace(ppgen_ecut-8, ppgen_ecut, num=4, endpoint=False)
        #coarse_high = np.linspace(ppgen_ecut + 15, ppgen_ecut + 40, num=4)

        dense_right = np.arange(ppgen_ecut, ppgen_ecut + 6*2, step=2)
        dense_left = np.arange(max(ppgen_ecut-6, 2), ppgen_ecut, step=2)
        coarse_high = np.arange(ppgen_ecut + 15, ppgen_ecut + 35, step=5)

        ecut_list = list(dense_left) + list(dense_right) + list(coarse_high)

    # Computation of the deltafactor.
    if "df" in options.trials:
        #FIXME
        #factory = DeltaFactory(xc=pseudo.xc)
        if os.path.isfile('LDA'):
            factory = DeltaFactory(xc='LDA')
        else:
            factory = DeltaFactory()
        for ecut in ecut_list:
            if "deltafactor" in report and ecut in report["deltafactor"].keys(): continue
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            # Build and register the workflow.
            work = factory.work_for_pseudo(pseudo, kppa=6750, ecut=ecut, pawecutdg=pawecutdg, **extra_abivars)
            flow.register_work(work, workdir='WDF' + str(ecut))

    # GBRV tests.
    if "gbrv" in options.trials:
        gbrv_factory = GbrvFactory()
        gbrv_structs = ("fcc", "bcc")
        for struct_type in gbrv_structs:
            dojo_trial = "gbrv_" + struct_type
            for ecut in ecut_list:
                if dojo_trial in report and ecut in report[dojo_trial].keys(): continue
                pawecutdg = 2 * ecut if pseudo.ispaw else None
                # FIXME: we use ntime=3, because structure relaxations go bananas after the third step.
                work = gbrv_factory.relax_and_eos_work(pseudo, struct_type, ecut=ecut, ntime=5, pawecutdg=pawecutdg, **extra_abivars)
                flow.register_work(work, workdir="GBRV_" + struct_type + str(ecut))

    # PHONON test
    if "phonon" in options.trials:
        phonon_factory = DFPTPhononFactory()
        for ecut in ecut_list:
            str_ecut = '%.1f' % ecut
            if "phonon" in report and str_ecut in report["phonon"].keys(): continue
            kppa = 1000
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            work = phonon_factory.work_for_pseudo(pseudo, accuracy="high", kppa=kppa, ecut=ecut, pawecutdg=pawecutdg,
                                                  tolwfr=1.e-20, smearing="fermi_dirac:0.0005", qpt=[0,0,0], mem_test=0)
            if work is not None:
                flow.register_work(work, workdir='GammaPhononsAt'+str(ecut))
            else:
                warn('cannot create GammaPhononsAt' + str(ecut) + ' work, factory returned None')

    # PHONON WihtOut Asr test
    if "phwoa" in options.trials:
        phonon_factory = DFPTPhononFactory()
        for ecut in [ecut_list[0], ecut_list[-1]]:
            str_ecut = '%.1f' % ecut
            if "phwoa" in report and str_ecut in report["phwoa"].keys(): continue
            print('phwoa')
            kppa = 1000
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            work = phonon_factory.work_for_pseudo(pseudo, accuracy="high", kppa=kppa, ecut=ecut, pawecutdg=pawecutdg,
                                                  tolwfr=1.e-20, smearing="fermi_dirac:0.0005", qpt=[0,0,0], rfasr=0)
            if work is not None:
                flow.register_work(work, workdir='GammaPhononsAt'+str(ecut)+'WOA')
            else:
                warn('cannot create GammaPhononsAt' + str(ecut) + 'WOA work, factory returned None')


    if len(flow) > 0:
        return flow.allocate()
    else:
        # Empty flow since all trials have been already performed.
        return None
Example #7
0
def build_flow(options):
    # Path of the pseudopotential to test.
    #pseudo = data.pseudo("14si.pspnc")
    #pseudo = data.pseudo("Si.GGA_PBE-JTH-paw.xml")
    here = os.path.abspath(os.path.curdir)
    ps_name = options['name']

    # the ocvpsps output file
    pseudo = os.path.join(here, ps_name+".out")
    print(pseudo)

    with open(pseudo, 'r') as fi:
        lines = fi.readlines()

    fo = open(ps_name + '.psp8', 'w')
    data = False
    for line in lines:
        if data:
            fo.write(line)
        if 'Begin PSPCODE8' in line:
            data = True
    fo.close()

    pseudo = os.path.join(here, ps_name + '.psp8')

    if options['strip']:
        sys.exit()

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config() 

    # Build the workflow for the computation of the deltafactor.
    # The calculation is done with the parameters and the cif files
    # used in the original paper. We only have to specify
    # the cutoff energy ecut (Ha) for the pseudopotential.
    # The workflow will produce a pdf file with the equation of state
    # and a file deltafactor.txt with the final results in the
    # outdir directory DELTAFACTOR/Wnn/outdir.

    if options['df']:
        factory = DeltaFactory()
        name = '_df'
    elif options['phonon']:
        factory = DFPTPhononFactory()
        name = '_phon'
    else:
        print('no mode selected ...')
        sys.exit()

    #extra = {}

    if options['test']:
        workdir = ps_name+'_df_run_test'
        flow = abilab.Flow(workdir=workdir, manager=manager, pickle_protocol=0)
        kppa = 1000
        ecut = 40
        pawecutdg = ecut * 2
        work = factory.work_for_pseudo(pseudo, accuracy="normal", kppa=kppa,
                                       ecut=ecut, pawecutdg=pawecutdg,
                                       toldfe=1.e-8, smearing="fermi_dirac:0.0005")
        flow.register_work(work, workdir='W'+str(ecut))
    else:
        workdir = ps_name+'_df_run_full'
        flow = abilab.Flow(workdir=workdir, manager=manager, pickle_protocol=0)
        kppa = 6750  # Use this to have the official k-point sampling
        for ecut in [12, 16, 20, 24, 28, 32, 36, 40, 44, 48]:
            pawecutdg = ecut * 2
            work = factory.work_for_pseudo(pseudo, accuracy="high", kppa=kppa,
                                           ecut=ecut, pawecutdg=pawecutdg,
                                           toldfe=1.e-10, smearing="fermi_dirac:0.0005")
            #this needs to be done in the loop over ecut ...
            flow.register_work(work, workdir='W'+str(ecut))

    flow.allocate()

    return flow.build_and_pickle_dump()
Example #8
0
def build_flow(pseudo, options):
    """
    Build the flow, returns None if the test has been already performed.
    """
    print(pseudo)
    if not pseudo.has_dojo_report:
        raise ValueError("Cannot find dojo_report")

    if options.soc and not pseudo.supports_soc:
        raise TypeError(
            "SOC is on but pseudo does not support spin-orbit coupling")

    if not options.soc and pseudo.supports_soc and pseudo.path.endswith(
            "psp8"):
        cprint(
            "[STRANGE]: Your psp8 pseudo supports SOC but options.soc is off",
            "magenta")

    report = pseudo.dojo_report
    if options.verbose > 1: print(report)

    workdir = pseudo.basename + "_DOJO" if options.workdir is None else options.workdir
    if os.path.exists(workdir):
        cprint("Directory %s already exists" % workdir, "red")
        return None

    flow = abilab.Flow(workdir=workdir, manager=options.manager)

    extra_abivars = {
        "mem_test": 0,
        #"nstep": 100,
        "paral_kgb": options.paral_kgb
    }
    #flow.walknset_vars(extra_abivars)

    # Build ecut mesh.
    try:
        ppgen_ecut = int(report["ppgen_hints"]["high"]["ecut"])
        ecut_list = copy.copy(report["ecuts"])

    except KeyError:
        cprint(
            'New pseudo without report from the generator, the convergence study is started from 16H',
            "yellow")
        #raise NotImplementedError()
        # TODO
        #report = DojoReport.from_pseudo(pseudo)
        report["ppgen_hints"] = {}
        report["ppgen_hints"]["high"] = {}
        report["ppgen_hints"]["high"]["ecut"] = 16.0
        report["ecuts"] = [16.0, 20.0, 24.0]
        report.json_write(pseudo.djrepo_path)
        #pseudo.write_dojo_report(report)
        ppgen_ecut = int(report["ppgen_hints"]["high"]["ecut"])
        ecut_list = copy.copy(report["ecuts"])

    try:
        ecut_hint = int(report["hints"]["normal"]["ecut"])
    except KeyError:
        try:
            ecut_hint = int(report["ppgen_hints"]["normal"]["ecut"])
        except KeyError:
            ecut_hint = ppgen_ecut

    #if options.extend:
    #    next_ecut = max(ecut_list) + 2
    #    ecut_list.append(next_ecut)
    #if options.new_ecut:
    #    ecut_list.append(options['new-ecut'])

    add_ecuts = False
    if add_ecuts:
        #dense_right = np.linspace(ppgen_ecut, ppgen_ecut + 10, num=6)
        #dense_left = np.linspace(ppgen_ecut-8, ppgen_ecut, num=4, endpoint=False)
        #coarse_high = np.linspace(ppgen_ecut + 15, ppgen_ecut + 40, num=4)

        dense_right = np.arange(ppgen_ecut, ppgen_ecut + 6 * 2, step=2)
        dense_left = np.arange(max(ppgen_ecut - 6, 2), ppgen_ecut, step=2)
        coarse_high = np.arange(ppgen_ecut + 15, ppgen_ecut + 35, step=5)

        ecut_list = list(dense_left) + list(dense_right) + list(coarse_high)

    # Computation of the deltafactor.
    if "df" in options.trials or "deltafactor" in options.trials:
        factory = DeltaFactory(xc=pseudo.xc)
        dojo_trial = "deltafactor" if not options.soc else "deltafactor_soc"
        #ecut_list = [75]

        for ecut in ecut_list:
            if report.has_trial(dojo_trial, ecut=ecut):
                cprint(
                    "[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT"
                    % (dojo_trial, ecut), "magenta")
                continue

            # Build and register the work.
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            work = factory.work_for_pseudo(pseudo,
                                           kppa=6750,
                                           ecut=ecut,
                                           pawecutdg=pawecutdg,
                                           include_soc=options.soc,
                                           **extra_abivars)
            flow.register_work(work, workdir='WDF' + str(ecut))

    # GBRV tests.
    if "gbrv" in options.trials:
        gbrv_factory = GbrvFactory(xc=pseudo.xc)
        gbrv_structs = ("fcc", "bcc")

        for struct_type in gbrv_structs:
            dojo_trial = "gbrv_" + struct_type
            if options.soc: dojo_trial += "_soc"
            for ecut in ecut_list:
                if report.has_trial(dojo_trial, ecut=ecut):
                    cprint(
                        "[gbrv]: ignoring ecut=%s because it's already in the DOJO_REPORT"
                        % ecut, "magenta")
                    continue

                # Build and register the work.
                pawecutdg = 2 * ecut if pseudo.ispaw else None
                work = gbrv_factory.relax_and_eos_work(pseudo,
                                                       struct_type,
                                                       ecut=ecut,
                                                       pawecutdg=pawecutdg,
                                                       include_soc=options.soc,
                                                       ntime=50,
                                                       **extra_abivars)
                flow.register_work(work,
                                   workdir="GBRV_" + struct_type + str(ecut))

    # GHOSTS test
    if "ghosts" in options.trials:
        assert not options.soc
        dojo_trial = "ghosts" if not options.soc else "ghosts_soc"
        ghosts_factory = GhostsFactory(pseudo.xc)
        ecut = int(report["ppgen_hints"]["high"]["ecut"])
        pawecutdg = None if not pseudo.ispaw else int(
            report["ppgen_hints"]["high"]["pawecutdg"])

        #str_ecut = '%.1f' % ecut
        #print(report["ghosts"].pop(ecut, None))

        if report.has_trial(dojo_trial, ecut=ecut):
            cprint(
                "[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT"
                % (dojo_trial, ecut), "magenta")
        else:
            # Build and register the work.
            work = ghosts_factory.work_for_pseudo(pseudo,
                                                  kppa=2000,
                                                  maxene=250,
                                                  ecut=ecut,
                                                  pawecutdg=pawecutdg,
                                                  **extra_abivars)
            if work is not None:
                flow.register_work(work, workdir='GhostsAt' + str(ecut))
            else:
                cprint(
                    'Cannot create GhostsAt%s work, factory returned None' %
                    str(ecut), "magenta")

    # phonons at gamma test.
    if "phgamma" in options.trials:
        phg_factory = GammaPhononFactory(pseudo.xc)
        dojo_trial = "phgamma" if not options.soc else "phgamma_soc"

        for ecut in ecut_list:
            if report.has_trial(dojo_trial, ecut=ecut):
                cprint(
                    "[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT"
                    % (dojo_trial, ecut), "magenta")
                continue

            # Build and register the work.
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            work = phg_factory.work_for_pseudo(pseudo,
                                               kppa=1000,
                                               ecut=ecut,
                                               pawecutdg=pawecutdg,
                                               include_soc=options.soc)
            if work is not None:
                flow.register_work(work)
            else:
                cprint(
                    'Cannot create phgamma work for ecut %s, factory returned None'
                    % str(ecut), "magenta")

    if "raren_relax" in options.trials:
        nirer_factory = RocksaltRelaxationFactory(pseudo.xc)
        dojo_trial = "raren_relax" if not options.soc else "raren_relax_soc"
        l = []
        for ecut in ecut_list:
            if report.has_trial(dojo_trial, ecut=ecut):
                cprint(
                    "[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT"
                    % (dojo_trial, ecut), "magenta")
                continue
            l.append(ecut)
        ecut_list = l

        # Build and register the work.
        pawecutdg = 2 * ecut if pseudo.ispaw else None
        work = nirer_factory.work_for_pseudo(pseudo,
                                             ecut_list,
                                             pawecutdg=pawecutdg,
                                             include_soc=options.soc)
        if work is not None:
            flow.register_work(work)
        else:
            cprint('Cannot create nirer work, factory returned None',
                   "magenta")

    if len(flow) > 0:
        return flow.allocate()
    else:
        # Empty flow since all trials have been already performed.
        return None
Example #9
0
def build_flow(pseudo, options):
    """
    Build the flow, returns None if the test has been already performed.
    """
    print(pseudo)
    if not pseudo.has_dojo_report:
        raise ValueError("Cannot find dojo_report")

    if options.soc and not pseudo.supports_soc:
        raise TypeError("SOC is on but pseudo does not support spin-orbit coupling")

    if not options.soc and pseudo.supports_soc and pseudo.path.endswith("psp8"):
        cprint("[STRANGE]: Your psp8 pseudo supports SOC but options.soc is off", "magenta")

    report = pseudo.dojo_report
    if options.verbose > 1: print(report)

    workdir = pseudo.basename + "_DOJO" if options.workdir is None else options.workdir
    if os.path.exists(workdir):
        cprint("Directory %s already exists" % workdir, "red")
        return None

    flow = abilab.Flow(workdir=workdir, manager=options.manager)

    extra_abivars = {
            "mem_test": 0,
            #"nstep": 100,
            "paral_kgb": options.paral_kgb
    }
    #flow.walknset_vars(extra_abivars)

    # Build ecut mesh.
    try:
        ppgen_ecut = int(report["ppgen_hints"]["high"]["ecut"])
        ecut_list = copy.copy(report["ecuts"])

    except KeyError:
        cprint('New pseudo without report from the generator, the convergence study is started from 16H', "yellow")
        #raise NotImplementedError()
        # TODO
        #report = DojoReport.from_pseudo(pseudo)
        report["ppgen_hints"] = {}
        report["ppgen_hints"]["high"] = {}
        report["ppgen_hints"]["high"]["ecut"] = 16.0
        report["ecuts"] = [16.0, 20.0, 24.0]
        report.json_write(pseudo.djrepo_path)
        #pseudo.write_dojo_report(report)
        ppgen_ecut = int(report["ppgen_hints"]["high"]["ecut"])
        ecut_list = copy.copy(report["ecuts"])

    try:
        ecut_hint = int(report["hints"]["normal"]["ecut"])
    except KeyError:
        try:
            ecut_hint = int(report["ppgen_hints"]["normal"]["ecut"])
        except KeyError:
            ecut_hint = ppgen_ecut

    #if options.extend:
    #    next_ecut = max(ecut_list) + 2
    #    ecut_list.append(next_ecut)
    #if options.new_ecut:
    #    ecut_list.append(options['new-ecut'])

    add_ecuts = False
    if add_ecuts:
        #dense_right = np.linspace(ppgen_ecut, ppgen_ecut + 10, num=6)
        #dense_left = np.linspace(ppgen_ecut-8, ppgen_ecut, num=4, endpoint=False)
        #coarse_high = np.linspace(ppgen_ecut + 15, ppgen_ecut + 40, num=4)

        dense_right = np.arange(ppgen_ecut, ppgen_ecut + 6*2, step=2)
        dense_left = np.arange(max(ppgen_ecut-6, 2), ppgen_ecut, step=2)
        coarse_high = np.arange(ppgen_ecut + 15, ppgen_ecut + 35, step=5)

        ecut_list = list(dense_left) + list(dense_right) + list(coarse_high)

    # Computation of the deltafactor.
    if "df" in options.trials or "deltafactor" in options.trials:
        factory = DeltaFactory(xc=pseudo.xc)
        dojo_trial = "deltafactor" if not options.soc else "deltafactor_soc"
        #ecut_list = [75]

        for ecut in ecut_list:
            if report.has_trial(dojo_trial, ecut=ecut):
                cprint("[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT" % (dojo_trial, ecut), "magenta")
                continue

            # Build and register the work.
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            work = factory.work_for_pseudo(pseudo, kppa=6750, ecut=ecut, pawecutdg=pawecutdg,
                                           include_soc=options.soc, **extra_abivars)
            flow.register_work(work, workdir='WDF' + str(ecut))

    # GBRV tests.
    if "gbrv" in options.trials:
        gbrv_factory = GbrvFactory(xc=pseudo.xc)
        gbrv_structs = ("fcc", "bcc")

        for struct_type in gbrv_structs:
            dojo_trial = "gbrv_" + struct_type
            if options.soc: dojo_trial += "_soc"
            for ecut in ecut_list:
                if report.has_trial(dojo_trial, ecut=ecut):
                    cprint("[gbrv]: ignoring ecut=%s because it's already in the DOJO_REPORT" % ecut, "magenta")
                    continue

                # Build and register the work.
                pawecutdg = 2 * ecut if pseudo.ispaw else None
                work = gbrv_factory.relax_and_eos_work(pseudo, struct_type, ecut=ecut, pawecutdg=pawecutdg,
                                                       include_soc=options.soc, ntime=50, **extra_abivars)
                flow.register_work(work, workdir="GBRV_" + struct_type + str(ecut))

    # GHOSTS test
    if "ghosts" in options.trials:
        assert not options.soc
        dojo_trial = "ghosts" if not options.soc else "ghosts_soc"
        ghosts_factory = GhostsFactory(pseudo.xc)
        ecut = int(report["ppgen_hints"]["high"]["ecut"])
        pawecutdg = None if not pseudo.ispaw else int(report["ppgen_hints"]["high"]["pawecutdg"])

        #str_ecut = '%.1f' % ecut
        #print(report["ghosts"].pop(ecut, None))

        if report.has_trial(dojo_trial, ecut=ecut):
            cprint("[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT" % (dojo_trial, ecut), "magenta")
        else:
            # Build and register the work.
            work = ghosts_factory.work_for_pseudo(pseudo, kppa=2000, maxene=250,
                                                  ecut=ecut, pawecutdg=pawecutdg,
                                                  **extra_abivars)
            if work is not None:
                flow.register_work(work, workdir='GhostsAt' + str(ecut))
            else:
                cprint('Cannot create GhostsAt%s work, factory returned None' % str(ecut), "magenta")

    # phonons at gamma test.
    if "phgamma" in options.trials:
        phg_factory = GammaPhononFactory(pseudo.xc)
        dojo_trial = "phgamma" if not options.soc else "phgamma_soc"

        for ecut in ecut_list:
            if report.has_trial(dojo_trial, ecut=ecut):
                cprint("[%s]: ignoring ecut=%s because it's already in the DOJO_REPORT" % (dojo_trial, ecut), "magenta")
                continue

            # Build and register the work.
            pawecutdg = 2 * ecut if pseudo.ispaw else None
            work = phg_factory.work_for_pseudo(pseudo, kppa=1000, ecut=ecut, pawecutdg=pawecutdg,
                                               include_soc=options.soc)
            if work is not None:
                flow.register_work(work)
            else:
                cprint('Cannot create phgamma work for ecut %s, factory returned None' % str(ecut), "magenta")

    if len(flow) > 0:
        return flow.allocate()
    else:
        # Empty flow since all trials have been already performed.
        return None