Esempio n. 1
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations. The flow has two works.
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_phonons_wkq.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    flow = flowtk.Flow(workdir=options.workdir)

    # Build input for GS calculation and create first work with 1 ScfTask.
    scf_input = make_scf_input()
    work = flow.register_scf_task(scf_input)
    scf_task = work[0]

    # Create work for phonon calculation with WFQ files with a [4, 4, 4] q-mesh.
    # Electric field and Born effective charges are also computed.
    wfkq_work = flowtk.PhononWfkqWork.from_scf_task(scf_task,
                                                    ngqpt=[4, 4, 4],
                                                    with_becs=True)
    flow.register_work(wfkq_work)

    return flow
Esempio n. 2
0
def itest_dilatmxerror_handler(fwp):
    """Test the handler of DilatmxError. The test triggers:

        --- !DilatmxError
        message: |
            Dilatmx has been exceeded too many times (4)
            Restart your calculation from larger lattice vectors and/or a larger dilatmx
        src_file: mover.F90
        src_line: 840
        ...

    in variable cell structural optimizations.
    """
    #if fwp.on_travis:
    pytest.xfail(
        "dilatmxerror_handler is not portable and it's been disabled!")

    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    structure.scale_lattice(structure.volume * 0.8)
    # Perturb the structure (random perturbation of 0.1 Angstrom)
    #structure.perturb(distance=0.1)

    inp = abilab.AbinitInput(structure=structure,
                             pseudos=abidata.pseudos("14si.pspnc"))

    inp.set_vars(
        ecut=4,
        ngkpt=[4, 4, 4],
        shiftk=[0, 0, 0],
        nshiftk=1,
        chksymbreak=0,
        paral_kgb=1,
        optcell=1,
        ionmov=2,
        ecutsm=0.5,
        dilatmx=1.01,
        tolrff=0.02,
        tolmxf=5.0e-5,
        strfact=100,
        ntime=50,
        #ntime=5, To test the restart
    )

    # Create the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)
    flow.register_task(inp, task_class=flowtk.RelaxTask)

    flow.allocate()
    assert flow.make_scheduler().start() == 0

    flow.show_status()
    if not flow.all_ok:
        flow.debug()
        raise RuntimeError()

    task = flow[0][0]
    # Don't check the number of corrections as it's not portable.
    assert len(task.corrections)
    for i in range(task.num_corrections):
        assert task.corrections[i]["event"]["@class"] == "DilatmxError"
Esempio n. 3
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations. The flow has two works.

    The first work contains a single GS task that produces the WFK file used in DFPT
    Then we have multiple Works that are generated automatically
    in order to compute the dynamical matrix on a [4, 4, 4] mesh.
    Symmetries are taken into account: only q-points in the IBZ are generated and
    for each q-point only the independent atomic perturbations are computed.
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(),
                                    "run_becs_and_epsilon_vs_kpts.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    flow = flowtk.Flow(workdir=options.workdir)

    for ngkpt in [(2, 2, 2), (4, 4, 4), (8, 8, 8)]:
        # Build input for GS calculation
        scf_input = make_scf_input(ngkpt=ngkpt)
        flow.register_scf_task(scf_input, append=True)

    for scf_task in flow[0]:
        bec_work = flowtk.BecWork.from_scf_task(scf_task)
        flow.register_work(bec_work)

    return flow
Esempio n. 4
0
def build_flow(options=None):
    """
    Create a `Flow` for phonon calculations. The flow has one work with:

        - 1 GS Task
        - 3 DDK Task
        - 4 Phonon Tasks (Gamma point)
        - 6 Elastic tasks (3 uniaxial + 3 shear strain)

    The Phonon tasks and the elastic task will read the 3 DDK files produced at the beginning
    """
    workdir = options.workdir if (options
                                  and options.workdir) else "flow_elastic"

    flow = flowtk.Flow(workdir=workdir)

    # Build input for GS calculation and register the first work.
    scf_input = make_scf_input()

    # Build work for elastic properties (clamped-ions)
    # activate internal strain and piezoelectric part.
    elast_work = flowtk.ElasticWork.from_scf_input(scf_input,
                                                   with_relaxed_ion=True,
                                                   with_piezo=True)

    flow.register_work(elast_work)

    return flow
Esempio n. 5
0
def itest_flow_without_runnable_tasks(fwp):
    """
    Test the behaviour of the scheduler when we ignore errrors and
    all the task that can be executed have been submitted.
    The scheduler should detect this condition and exit.
    """
    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()

    # Build the flow.
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)
    work0 = flowtk.BandStructureWork(scf_input, nscf_input)
    flow.register_work(work0)
    scf_task, nscf_task = work0.scf_task, work0.nscf_task

    flow.allocate()

    # Mock an Errored nscf_task. This will cause a deadlock in the flow.
    nscf_task = mocks.change_task_start(nscf_task)

    sched = flow.make_scheduler()
    sched.max_num_abierrs = 10000
    assert sched.start() == 0
    flow.check_status(show=True)

    assert not flow.all_ok
    assert scf_task.status == scf_task.S_OK
    assert nscf_task.status == nscf_task.S_ERROR

    g = flow.find_deadlocks()
    assert not g.deadlocked and not g.runnables and not g.running
Esempio n. 6
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_ht_si_ebands.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # Initialize structure and pseudos.
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

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

    # Use the ebands_input factory function to build a MultiDataset.
    # keyword args are optional (default values are given or computed automatically, see docs).
    multi = abilab.ebands_input(structure,
                                pseudos,
                                kppa=40,
                                dos_kppa=80,
                                nscf_nband=6,
                                ndivsm=10,
                                ecut=6,
                                spin_mode="unpolarized")

    work = flowtk.BandStructureWork(scf_input=multi[0],
                                    nscf_input=multi[1],
                                    dos_inputs=multi[2])
    flow.register_work(work)

    return flow
Esempio n. 7
0
def itest_atomic_relaxation(fwp, tvars):
    """Test atomic relaxation with automatic restart."""
    # Build the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)

    ion_input = ion_relaxation(tvars, ntime=2)
    ion_input["chksymtnons"] = 0
    work = flow.register_task(ion_input, task_class=flowtk.RelaxTask)

    flow.allocate()
    flow.build_and_pickle_dump(abivalidate=True)

    # Run t0, and check status
    t0 = work[0]
    t0.start_and_wait()
    assert t0.returncode == 0
    t0.check_status()
    assert t0.status == t0.S_UNCONVERGED

    assert t0.initial_structure == ion_input.structure
    unconverged_structure = t0.get_final_structure()
    assert unconverged_structure != t0.initial_structure

    # Use the default value ntime=50 and we can converge the calculation.
    t0.input.set_vars(ntime=50)

    t0.build()
    assert t0.restart()
    t0.wait()
    assert t0.num_restarts == 1

    # At this point, we should have reached S_OK.
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK

    final_structure = t0.get_final_structure()
    assert final_structure != unconverged_structure

    flow.show_status()
    assert all(work.finalized for work in flow)
    if not flow.all_ok:
        flow.debug()
        raise RuntimeError()

    # post-processing tools
    if has_matplotlib():
        assert t0.inspect(show=False) is not None

    with t0.open_hist() as hist:
        hist.to_string(verbose=2)
        # from_file accepts HIST files as well.
        assert np.all(hist.structures[-1].frac_coords ==
                      abilab.Structure.from_file(hist.filepath).frac_coords)

    with t0.open_gsr() as gsr:
        gsr.to_string(verbose=2)
        gsr.pressure == 1.8280

    t0.get_results()
Esempio n. 8
0
def build_flow(options):

    # 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 structure and pseudos.
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

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

    # Use ebands_input factory function to build inputs.
    multi = abilab.ebands_input(structure,
                                pseudos,
                                kppa=40,
                                nscf_nband=6,
                                ndivsm=10,
                                ecut=6)
    work = flowtk.BandStructureWork(scf_input=multi[0], nscf_input=multi[1])

    flow.register_work(work)
    return flow
Esempio n. 9
0
def build_flow(options):
    # 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_")

    pseudos = abidata.pseudos("14si.pspnc", "8o.pspnc")

    base_structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    news, uparams = [], [0.2, 0.3]

    for u in uparams:
        new = special_positions(base_structure.lattice, u)
        news.append(new)

    flow = flowtk.Flow(workdir, manager=options.manager, remove=options.remove)

    # Create the list of workflows. Each workflow defines a band structure calculation.
    for new_structure, u in zip(news, uparams):
        # Generate the workflow and register it.
        flow.register_work(make_workflow(new_structure, pseudos))

    return flow
Esempio n. 10
0
def test_scf():
    atoms = build_structure(name='BaTiO3', mag='PM')
    scf_inp = make_scf_input(atoms, spin_mode='unpolarized',is_metal=False)
    ebands_inp = ebands_from_gsinput(scf_inp)

    dos_inp = dos_from_gsinput(scf_inp, dos_kppa=400)

    #scf_task = flowapi.ScfTask(scf_inp)
    #ebands_task = flowapi.NscfTask(ebands_inp)
    #dos_task = flowapi.NscfTask(dos_inp)
    band_work = flowapi.BandStructureWork(
        scf_inp, ebands_inp, dos_inp, workdir=None)

    #phonon_work=flowapi.PhononWork()
    #phonon_work.from_scf_input()

    flow = flowapi.Flow('BaTiO3_scf')
    flow.register_work(band_work)
    #flow.build_and_pickle_dump()
    #flow.plot_networkx()
    #flow.show_status()
    #flow.make_scheduler().start()

    flow_phbands = flowapi.PhononFlow.from_scf_input(
    'BaTiO3_phonon', scf_inp, ph_ngqpt=(2, 2, 2), with_becs=True)
    flow_phbands.make_scheduler().start()
    flow_phbands.show_summary()
Esempio n. 11
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_phfrozen_ebands.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # build the structures
    base_structure = abilab.Structure.from_file(data.cif_file("si.cif"))
    modifier = abilab.StructureModifier(base_structure)

    etas = [-0.1, 0, +0.1]
    ph_displ = np.reshape(np.zeros(3 * len(base_structure)), (-1, 3))
    ph_displ[0, :] = [+1, 0, 0]
    ph_displ[1, :] = [-1, 0, 0]

    displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)

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

    for structure in displaced_structures:
        # Create the work for the band structure calculation.
        scf_input, nscf_input = make_scf_nscf_inputs(structure)

        work = flowtk.BandStructureWork(scf_input, nscf_input)
        flow.register_work(work)

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

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

    for nspinor in (1, 2):
        #for nspinor in (2,):
        # Get our templates
        scf_inp, bands_inp, nscf_inp, scr_inp, sig_inp = make_inputs(nspinor)

        # Band structure work to produce the WFK file
        bands_work = flowtk.BandStructureWork(scf_inp,
                                              bands_inp,
                                              dos_inputs=[nscf_inp])
        flow.register_work(bands_work)

        # Build a work made of two SCR runs with different value of nband
        gw_work = flowtk.Work()
        scr_task = gw_work.register_scr_task(scr_inp,
                                             deps={bands_work[2]: "WFK"})
        gw_work.register_sigma_task(sig_inp,
                                    deps={
                                        bands_work[2]: "WFK",
                                        scr_task: "SCR"
                                    })
        flow.register_work(gw_work)

    return flow
Esempio n. 13
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(".py", "").replace("run_","flow_")

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

    pseudos = abidata.pseudos("14si.pspnc")

    # Get the unperturbed structure.
    base_structure = abidata.structure_from_ucell("Si")

    etas = [-.001, 0, +.001]
    ph_displ = np.reshape(np.zeros(3*len(base_structure)), (-1,3))
    ph_displ[0,:] = [+1, 0, 0]
    ph_displ[1,:] = [-1, 0, 0]

    # Build new structures by displacing atoms according to the phonon displacement
    # ph_displ (in cartesian coordinates). The Displacement is normalized so that
    # the maximum atomic diplacement is 1 Angstrom and then multiplied by eta.
    modifier = abilab.StructureModifier(base_structure)

    displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)

    # Generate the different shifts to average
    ndiv = 2
    shift1D = np.arange(1,2*ndiv+1,2)/(2*ndiv)
    all_shifts = [[x,y,z] for x in shift1D for y in shift1D for z in shift1D]
    all_shifts = [[0, 0, 0]]

    for structure, eta in zip(displaced_structures, etas):
        for shift in all_shifts:
            flow.register_work(raman_work(structure, pseudos, shift))

    return flow
Esempio n. 14
0
def build_flow(options):
    # Set working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(
            ".py", "").replace("run_", "flow_")

    # Get the SCF input (here NC with SOC)
    scf_input = make_scf_input(nspinor=2, usepaw=0)

    # Build the flow with different steps.
    from abipy.flowtk.effmass_works import EffMassLineWork
    flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)

    # Multiple calculations with different step for finite difference.
    for i, step in enumerate((0.01, 0.005)):
        if i == 0: den_node = None
        work = EffMassLineWork.from_scf_input(scf_input,
                                              k0_list=(0, 0, 0),
                                              step=step,
                                              npts=10,
                                              red_dirs=[[1, 0, 0], [1, 1, 0]],
                                              cart_dirs=[[1, 0, 0], [1, 1, 1],
                                                         [1, 1, 0]],
                                              den_node=den_node)
        # Will start from the DEN file produced in the first iteration.
        if i == 0: den_node = work[0]
        flow.register_work(work)

    return flow
Esempio n. 15
0
def itest_relaxation_with_target_dilatmx(fwp, tvars):
    """Test structural relaxations with automatic restart from DEN files."""
    # Build the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)

    # Use small value for ntime to trigger restart, then disable the output of the WFK file.
    ion_input, ioncell_input = make_ion_ioncell_inputs(tvars, dilatmx=1.05)

    target_dilatmx = 1.03
    relax_work = flowtk.RelaxWork(ion_input, ioncell_input, target_dilatmx=target_dilatmx)
    flow.register_work(relax_work)

    assert flow.make_scheduler().start() == 0
    flow.show_status()

    assert all(work.finalized for work in flow)
    if not flow.all_ok:
        flow.debug()
        raise RuntimeError()
    #assert relax_work.last_dilatmx <= target_dilatmx

    # we should have (0, 1) restarts
    for i, task in enumerate(relax_work):
        assert task.status == task.S_OK
        assert task.num_restarts == i
        assert task.num_corrections == 0

    assert relax_work[1].input["dilatmx"] == 1.03

    # check that when decreasing the dilatmx it actually takes the previously relaxed
    # structure and does not start from scratch again: the lattice should not be the same.
    assert not np.allclose(relax_work.ion_task.get_final_structure().lattice_vectors(),
                           relax_work.ioncell_task.input.structure.lattice_vectors())

    flow.rmtree()
Esempio n. 16
0
def build_flow(options):
    # Set working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(".py", "").replace("run_", "flow_")

    # Build GS input file.
    pseudos = abidata.pseudos("Si.GGA_PBE-JTH-paw.xml")
    #silicon = abilab.Structure.zincblende(5.431, ["Si", "Si"], units="ang")
    silicon = abidata.cif_file("si.cif")

    scf_input = abilab.AbinitInput(silicon, pseudos)
    ecut = 12
    scf_input.set_vars(
        ecut=ecut,
        pawecutdg=40,
        nband=6,
        paral_kgb=0,
        iomode=3,
        toldfe=1e-9,
    )

    # K-point sampling (shifted)
    scf_input.set_autokmesh(nksmall=4)

    from abipy.flowtk.gs_works import EosWork
    flow = flowtk.Flow(options.workdir, manager=options.manager)

    # Si is cubic and atomic positions are fixed by symmetry so we
    # use move_atoms=False to compute E(V) with SCF-GS tasks instead of
    # performing a constant-volume optimization of the cell geometry.
    work = EosWork.from_scf_input(scf_input, move_atoms=False, ecutsm=0.5)
    flow.register_work(work)
    flow.allocate(use_smartio=True)

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

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

    # Create the work for the band structure calculation.
    structure = abidata.structure_from_ucell("NiO")
    pseudos = abidata.pseudos("28ni.paw", "8o.2.paw")

    # The code below set up the parameters for the LDA+U calculation in NiO.
    #usepawu   1
    #lpawu   2 -1
    #upawu  8.0 0.0 eV
    #jpawu  0.8 0.0 eV
    usepawu = 1
    u_values = [5.0, 8.0]

    for u in u_values:
        # Apply U-J on Ni only.
        luj_params = LdauParams(usepawu, structure)
        luj_params.luj_for_symbol("Ni", l=2, u=u, j=0.1 * u, unit="eV")

        scf_input, nscf_input, dos_input = make_scf_nscf_dos_inputs(
            structure, pseudos, luj_params)

        work = flowtk.BandStructureWork(scf_input,
                                        nscf_input,
                                        dos_inputs=dos_input)
        flow.register_work(work)

    return flow
Esempio n. 18
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_relax.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # Create the flow
    flow = flowtk.Flow(options.workdir, manager=options.manager)

    # Create a relaxation work and add it to the flow.
    ion_inp, ioncell_inp = make_ion_ioncell_inputs()

    relax_work = flowtk.RelaxWork(ion_inp, ioncell_inp)
    flow.register_work(relax_work)

    #bands_work = flowtk.BandStructureWork(scf_input, nscf_input)
    bands_work = flowtk.Work()
    deps = {relax_work[-1]: "@structure"}
    deps = {
        relax_work[-1]: ["DEN", "@structure"]
    }  # --> This is not possible because the file ext is changed!
    #deps = {relax_work[-1]: ["WFK", "@structure"]} # --> This triggers an infamous bug in abinit

    bands_work.register_relax_task(ioncell_inp, deps=deps)
    flow.register_work(bands_work)

    return flow
Esempio n. 19
0
def build_flow(options):
    # Set working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(
            ".py", "").replace("run_", "flow_")

    # Get the SCF input (without SOC)
    scf_input = make_scf_input(nspinor=1, usepaw=1)

    # Build the flow.
    from abipy.flowtk.effmass_works import EffMassDFPTWork, EffMassAutoDFPTWork
    flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)

    # Compute effective masses for each k in k0_list.
    # effmass_bands_f90 defines the band range for each k in k0_list
    # Here we are interested in the effective masses at the Gamma point for the valence bands
    effmass_bands_f90 = [1, 4] if scf_input["nspinor"] == 1 else [1, 8]
    work = EffMassDFPTWork.from_scf_input(scf_input,
                                          k0_list=(0, 0, 0),
                                          effmass_bands_f90=effmass_bands_f90)
    flow.register_work(work)

    # or use this Work to detect band edges automatically but increase ndivsm and decrease tolwfr!
    work = EffMassAutoDFPTWork.from_scf_input(scf_input,
                                              ndivsm=5,
                                              tolwfr=1e-12)
    flow.register_work(work)

    return flow
Esempio n. 20
0
def build_flow(options):
    # Init structure and pseudos.
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

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

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

    scf_kppa = 120
    nscf_nband = 40
    ecut, ecuteps, ecutsigx = 6, 2, 4
    #scr_nband = 50
    #sigma_nband = 50

    multi = abilab.g0w0_with_ppmodel_inputs(
        structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx,
        ecut=ecut, shifts=(0, 0, 0), # By default the k-mesh is shifted! TODO: Change default?
        accuracy="normal", spin_mode="unpolarized", smearing=None,
        #ppmodel="godby", charge=0.0, scf_algorithm=None, inclvkb=2, scr_nband=None,
        #sigma_nband=None, gw_qprange=1):
    )
    #multi.set_vars(paral_kgb=1)

    scf_input, nscf_input, scr_input, sigma_input = multi.split_datasets()
    work = flowtk.G0W0Work(scf_input, nscf_input, scr_input, sigma_input)
    flow.register_work(work)

    return flow
Esempio n. 21
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations with phonopy:
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    # Initialize structure and pseudos
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))
    pseudos = abidata.pseudos("14si.pspnc")

    # Build input for GS calculation.
    gsinp = abilab.AbinitInput(structure, pseudos)
    gsinp.set_vars(ecut=4, nband=4, toldff=1.e-6)

    # This gives ngkpt = 4x4x4 with 4 shifts for the initial unit cell.
    # The k-point sampling will be rescaled when we build the supercell in PhonopyWork.
    gsinp.set_autokmesh(nksmall=4)
    #gsinp.set_vars(ngkpt=[4, 4, 4])

    flow = flowtk.Flow(workdir=options.workdir)

    # Use a 2x2x2 supercell to compute phonons with phonopy
    work = PhonopyWork.from_gs_input(gsinp, scdims=[2, 2, 2])
    flow.register_work(work)

    return flow
Esempio n. 22
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(
            ".py", "").replace("run_", "flow_")

    # Init structure from internal database.
    structure = abidata.structure_from_ucell("MgB2")

    # Our pseudopotentials.
    pseudos = abilab.PseudoTable(["Mg-low.psp8", "B.psp8"])

    flow = flowtk.Flow(workdir=options.workdir)

    # Build work of GS task. Each gs_task uses different (ngkpt, tsmear) values
    # and represent the starting point of the phonon works.
    ngkpt = [12, 12, 12]
    tsmear = 0.02
    scf_input, nscf_input = make_scf_nscf_inputs(structure, ngkpt, tsmear,
                                                 pseudos)

    gs_work = flowtk.Work()
    scf_task = gs_work.register_scf_task(scf_input)
    nscf_task = gs_work.register_nscf_task(nscf_input, deps={scf_task: "DEN"})
    flow.register_work(gs_work)

    # This call uses the information reported in the GS task to
    # compute all the independent atomic perturbations corresponding to a [6, 6, 6] q-mesh.
    ph_work = flowtk.PhononWork.from_scf_task(scf_task,
                                              qpoints=[4, 4, 4],
                                              is_ngqpt=True)
    flow.register_work(ph_work)

    return flow.allocate(use_smartio=True)
Esempio n. 23
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations. The flow has one work with:

        - 1 GS Task
        - 3 DDK Task
        - 4 Phonon Tasks (Gamma point)
        - 6 Elastic tasks (3 uniaxial + 3 shear strain)

    The Phonon tasks and the elastic task will read the DDK produced at the beginning
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        if os.getenv("READTHEDOCS", False):
            __file__ = os.path.join(os.getcwd(), "run_elastic.py")
        options.workdir = os.path.basename(__file__).replace(
            ".py", "").replace("run_", "flow_")

    flow = flowtk.Flow(workdir=options.workdir)

    # Build input for GS calculation and register the first work.
    scf_input = make_scf_input()

    elast_work = flowtk.ElasticWork.from_scf_input(scf_input,
                                                   with_relaxed_ion=True,
                                                   with_piezo=True)

    flow.register_work(elast_work)

    return flow
Esempio n. 24
0
def build_flow(options):
    """
    Create a `Flow` for phonon calculations. The flow has two works.

    The first work contains a single GS task that produces the WFK file used in DFPT
    The second work contains multiple PhononTasks that are generated automatically
    in order to compute the dynamical matrix on a [4, 4, 4] mesh.
    Symmetries are taken into account: only q-points in the IBZ are generated and
    for each q-point only the independent atomic perturbations are computed.
    """
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    flow = flowtk.Flow(workdir=options.workdir)

    # Build input for GS calculation and register the first work.
    scf_input = make_scf_input()
    work0 = flow.register_scf_task(scf_input)

    # This call uses the information reported in the GS task (work0[0]) to
    # compute all the independent atomic perturbations corresponding to a [4, 4, 4] q-mesh.
    ph_work = flowtk.PhononWork.from_scf_task(work0[0], qpoints=[4, 4, 4], is_ngqpt=True)
    flow.register_work(ph_work)

    return flow
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(sys.argv[0]).replace(
            ".py", "").replace("run_", "flow_")

    structure = abidata.structure_from_ucell("MgB2")

    # Get pseudos from a table.
    table = abilab.PseudoTable(abidata.pseudos("12mg.pspnc", "5b.pspnc"))
    pseudos = table.get_pseudos_for_structure(structure)

    flow = flowtk.Flow(workdir=options.workdir)

    # Build work of GS task. Each gs_task uses different (ngkpt, tsmear) values
    # and represent the starting point of the phonon works.
    scf_work = flowtk.Work()
    ngkpt_list = [[4, 4, 4], [8, 8, 8]]  #, [12, 12, 12]]
    tsmear_list = [0.01, 0.02]  # , 0.04]
    for ngkpt in ngkpt_list:
        for tsmear in tsmear_list:
            scf_input = make_scf_input(structure, ngkpt, tsmear, pseudos)
            scf_work.register_scf_task(scf_input)
    flow.register_work(scf_work)

    # This call uses the information reported in the GS task to
    # compute all the independent atomic perturbations corresponding to a [2, 2, 2] q-mesh.
    # For each GS task, construct a phonon work that will inherit (ngkpt, tsmear) from scf_task.
    for scf_task in scf_work:
        ph_work = flowtk.PhononWork.from_scf_task(scf_task,
                                                  qpoints=[2, 2, 2],
                                                  is_ngqpt=True)
        flow.register_work(ph_work)

    return flow.allocate(use_smartio=True)
Esempio n. 26
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    if not options.workdir:
        options.workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_")

    structure = abidata.structure_from_ucell("MgB2")

    # Get pseudos from a table.
    table = abilab.PseudoTable(abidata.pseudos("12mg.pspnc", "5b.pspnc"))
    pseudos = table.get_pseudos_for_structure(structure)

    nval = structure.num_valence_electrons(pseudos)
    #print(nval)

    flow = flowtk.Flow(workdir=options.workdir)

    scf_work = flowtk.Work()
    ngkpt_list = [[4, 4, 4], [8, 8, 8], [12, 12, 12]]
    tsmear_list = [0.01, 0.02, 0.04]
    for ngkpt in ngkpt_list:
        for tsmear in tsmear_list:
            scf_input = make_scf_input(structure, ngkpt, tsmear, pseudos)
            scf_work.register_scf_task(scf_input)
    flow.register_work(scf_work)

    # This call uses the information reported in the GS task to
    # compute all the independent atomic perturbations corresponding to a [4, 4, 4] q-mesh.
    for scf_task in scf_work:
        ph_work = flowtk.PhononWork.from_scf_task(scf_task, qpoints=[4, 4, 4], is_ngqpt=True)
        flow.register_work(ph_work)

    return flow.allocate(use_smartio=True)
Esempio n. 27
0
def itest_relaxation_with_target_dilatmx(fwp, tvars):
    """Test structural relaxations with automatic restart from DEN files."""
    # Build the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)

    # Use small value for ntime to trigger restart, then disable the output of the WFK file.
    ion_input, ioncell_input = make_ion_ioncell_inputs(tvars, dilatmx=1.05)

    target_dilatmx = 1.03
    relax_work = flowtk.RelaxWork(ion_input,
                                  ioncell_input,
                                  target_dilatmx=target_dilatmx)
    flow.register_work(relax_work)

    assert flow.make_scheduler().start() == 0
    flow.show_status()

    assert all(work.finalized for work in flow)
    assert flow.all_ok
    #assert relax_work.last_dilatmx <= target_dilatmx

    # we should have (0, 1) restarts
    for i, task in enumerate(relax_work):
        assert task.status == task.S_OK
        assert task.num_restarts == i
        assert task.num_corrections == 0

    assert relax_work[1].input["dilatmx"] == 1.03

    flow.rmtree()
Esempio n. 28
0
def itest_relaxation_with_restart_from_den(fwp, tvars):
    """Test structural relaxations with automatic restart from DEN files."""
    # Build the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)

    # Use small value for ntime to trigger restart, then disable the output of the WFK file.
    ion_input, ioncell_input = make_ion_ioncell_inputs(tvars,
                                                       dilatmx=1.1,
                                                       ntime=3)
    ion_input.set_vars(prtwf=0)
    ioncell_input.set_vars(prtwf=0)

    relax_work = flowtk.RelaxWork(ion_input, ioncell_input)
    flow.register_work(relax_work)

    assert flow.make_scheduler().start() == 0
    flow.show_status()

    assert all(work.finalized for work in flow)
    assert flow.all_ok

    # we should have (0, 1) restarts and no WFK file in outdir.
    for i, task in enumerate(relax_work):
        assert task.status == task.S_OK
        assert task.num_restarts == i
        assert task.num_corrections == 0
        assert not task.outdir.has_abiext("WFK")

    if has_matplotlib:
        assert relax_work.plot_ion_relaxation(show=False) is not None
        assert relax_work.plot_ioncell_relaxation(show=False) is not None

    flow.rmtree()
Esempio n. 29
0
def itest_dilatmx_error_handler(fwp, tvars):
    """
    Test cell relaxation with automatic restart in the presence of dilatmx error.
    """
    # Build the flow
    flow = flowtk.Flow(fwp.workdir, manager=fwp.manager)

    # Decrease the volume to trigger DilatmxError
    ion_input, ioncell_input = make_ion_ioncell_inputs(tvars,
                                                       dilatmx=1.01,
                                                       scalevol=0.8)

    work = flowtk.Work()
    work.register_relax_task(ioncell_input)

    flow.register_work(work)
    flow.allocate()
    assert flow.make_scheduler().start() == 0
    flow.show_status()

    assert all(work.finalized for work in flow)
    assert flow.all_ok

    # t0 should have reached S_OK, and we should have DilatmxError in the corrections.
    t0 = work[0]
    assert t0.status == t0.S_OK
    print(t0.corrections)
    assert t0.num_corrections > 0
    assert t0.corrections[0]["event"]["@class"] == "DilatmxError"
Esempio n. 30
0
def build_flow(options):
    # 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 pseudos and Structure.
    pseudos = abidata.pseudos("14si.pspnc")
    structure = abilab.Structure.from_file(abidata.cif_file("si.cif"))

    kppa = scf_kppa = 1
    nscf_nband = 6
    nscf_ngkpt = [4, 4, 4]
    nscf_shiftk = [0.1, 0.2, 0.3]
    bs_loband = 2
    bs_nband = nscf_nband
    mbpt_sciss = 0.7
    mdf_epsinf = 12
    ecuteps = 2
    ecut = 12

    flow = flowtk.Flow(workdir=workdir,
                       manager=options.manager,
                       remove=options.remove)

    # BSE calculation with model dielectric function.
    multi = abilab.bse_with_mdf_inputs(
        structure,
        pseudos,
        scf_kppa,
        nscf_nband,
        nscf_ngkpt,
        nscf_shiftk,
        ecuteps,
        bs_loband,
        bs_nband,
        mbpt_sciss,
        mdf_epsinf,
        ecut=ecut,  #$ pawecutdg=None, 
        exc_type="TDA",
        bs_algo="haydock",
        accuracy="normal",
        spin_mode="unpolarized",
        smearing=None)
    #smearing="fermi_dirac:0.1 eV", charge=0.0, scf_algorithm=None)

    work = flowtk.BseMdfWork(scf_input=multi[0],
                             nscf_input=multi[1],
                             bse_inputs=multi[2:])

    #from pymatgen.io.abinit.calculations import bse_with_mdf_work
    #work = bse_with_mdf_work(structure, pseudos, scf_kppa, nscf_nband, nscf_ngkpt, nscf_shiftk,
    #                         ecuteps, bs_loband, bs_nband, mbpt_sciss, mdf_epsinf,
    #                         accuracy="normal", spin_mode="unpolarized", smearing=None,
    #                         charge=0.0, scf_solver=None, **extra_abivars)

    flow.register_work(work)
    return flow