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()
Exemple #2
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)
    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)
    assert flow.all_ok

    # 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()
Exemple #3
0
    def test_psps_nc_silicon(self):
        """Very preliminary test for PSPS.nc file with Ga.oncvpsp"""
        pseudo = abidata.pseudo("Ga.oncvpsp")

        with pseudo.open_pspsfile(ecut=10) as psps:
            print(psps)
            r = psps.reader
            assert r.usepaw == 0 and r.ntypat == 1

            if has_matplotlib():
                psps.plot(what="all", show=False)
                psps.compare(psps, show=False)
Exemple #4
0
    def test_psps_nc_silicon(self):
        """Test PSPS.nc file with Ga.oncvpsp"""
        pseudo = abidata.pseudo("Ga.oncvpsp")

        with pseudo.open_pspsfile(ecut=10) as psps:
            print(psps)
            r = psps.reader
            assert r.usepaw == 0 and r.ntypat == 1

            if has_matplotlib():
                psps.plot(what="all", show=False)
                psps.compare(psps, show=False)
Exemple #5
0
def itest_phonon_flow(fwp, tvars):
    """
    Create an `Abinit` for phonon calculations:

        1) One work for the GS run.

        2) nqpt works for phonon calculations. Each work contains
           nirred tasks where nirred is the number of irreducible phonon perturbations
           for that particular q-point.
    """
    if tvars.paral_kgb == 1:
        pytest.xfail("Phonon flow with paral_kgb==1 is expected to fail (implementation problem)")

    all_inps = scf_ph_inputs(tvars)
    scf_input, ph_inputs = all_inps[0], all_inps[1:]

    flow = abilab.phonon_flow(fwp.workdir, scf_input, ph_inputs, manager=fwp.manager)
    flow.build_and_pickle_dump()

    t0 = flow[0][0]
    t0.start_and_wait()

    assert t0.uses_paral_kgb(tvars.paral_kgb)

    flow.check_status()
    assert t0.status == t0.S_OK
    flow.show_status()

    for work in flow[1:]:
        for task in work:
            task.start_and_wait()
            assert task.status == t0.S_DONE

    flow.check_status(show=True)

    # We should have a DDB files with IFC(q) in work.outdir
    ddb_files = []
    for work in flow[1:]:
        ddbs = work.outdir.list_filepaths(wildcard="*DDB")
        assert len(ddbs) == 1
        ddb_files.append(ddbs[0])

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

    # Merge the DDB files
    out_ddb = flow.outdir.path_in("flow_DDB")
    ddb_path = abilab.Mrgddb().merge(flow.outdir.path, ddb_files, out_ddb=out_ddb, 
                                     description="DDB generated by %s" % __file__)
    assert ddb_path == out_ddb

    # Test PhononTask inspect method
    ph_task = flow[1][0]

    # paral_kgb does not make sense for DFPT!
    assert not ph_task.uses_paral_kgb(tvars.paral_kgb)

    if has_matplotlib():
        ph_task.inspect(show=False)

    # Test get_results
    ph_task.get_results()

    # Build new work with Anaddb tasks.
    # Construct a manager with mpi_procs==1 since anaddb do not support mpi_procs > 1 (except in elphon)
    shell_manager = fwp.manager.to_shell_manager(mpi_procs=1)
    awork = abilab.Work(manager=shell_manager)

    # Phonons bands and DOS with gaussian method
    anaddb_input = abilab.AnaddbInput.phbands_and_dos(
        scf_input.structure, ngqpt=(4, 4, 4), ndivsm=5, nqsmall=10, dos_method="gaussian: 0.001 eV")

    atask = abilab.AnaddbTask(anaddb_input, ddb_node=ddb_path, manager=shell_manager)
    awork.register(atask)

    # Phonons bands and DOS with tetrahedron method
    anaddb_input = abilab.AnaddbInput.phbands_and_dos(
        scf_input.structure, ngqpt=(4, 4, 4), ndivsm=5, nqsmall=10, dos_method="tetra")

    atask = abilab.AnaddbTask(anaddb_input, ddb_node=ddb_path, manager=shell_manager)
    awork.register(atask)

    flow.register_work(awork)
    flow.allocate()
    flow.build()

    for i, atask in enumerate(awork):
        atask.history.info("about to run anaddb task: %d", i)
        atask.start_and_wait()
        assert atask.status == atask.S_DONE
        atask.check_status()
        assert atask.status == atask.S_OK
Exemple #6
0
def itest_phonon_flow(fwp, tvars):
    """
    Create a flow for phonon calculations:

        1) One work for the GS run.

        2) nqpt works for phonon calculations. Each work contains
           nirred tasks where nirred is the number of irreducible phonon perturbations
           for that particular q-point.
    """
    all_inps = scf_ph_inputs(tvars)
    scf_input, ph_inputs = all_inps[0], all_inps[1:]

    ph_ngqpt = (2, 2, 2)
    flow = flowtk.PhononFlow.from_scf_input(fwp.workdir,
                                            scf_input,
                                            ph_ngqpt=ph_ngqpt,
                                            with_becs=False)

    scheduler = flow.make_scheduler()
    assert scheduler.start() == 0
    flow.check_status(show=True)
    assert all(work.finalized for work in flow)
    if not flow.all_ok:
        flow.debug()
        raise RuntimeError()

    with flow.open_final_ddb() as ddb:
        ddb_path = ddb.filepath
        ddb.to_string(verbose=2)
        assert len(ddb.structure) == 2
        #assert ddb.qpoints.frac_coords

    # Test PhononTask inspect method
    ph_task = flow[1][0]
    if has_matplotlib():
        assert ph_task.inspect(show=False)
    # Test get_results
    #ph_task.get_results()

    # Build new work with Anaddb tasks.
    # Construct a manager with mpi_procs==1 since anaddb do not support mpi_procs > 1 (except in elphon)
    shell_manager = fwp.manager.to_shell_manager(mpi_procs=1)
    awork = flowtk.Work(manager=shell_manager)

    # Phonons bands and DOS with gaussian method
    anaddb_input = abilab.AnaddbInput.phbands_and_dos(
        scf_input.structure,
        ngqpt=ph_ngqpt,
        ndivsm=5,
        nqsmall=10,
        dos_method="gaussian: 0.001 eV")

    atask = flowtk.AnaddbTask(anaddb_input,
                              ddb_node=ddb_path,
                              manager=shell_manager)
    awork.register(atask)

    # Phonons bands and DOS with tetrahedron method
    anaddb_input = abilab.AnaddbInput.phbands_and_dos(scf_input.structure,
                                                      ngqpt=ph_ngqpt,
                                                      ndivsm=5,
                                                      nqsmall=10,
                                                      dos_method="tetra")

    atask = flowtk.AnaddbTask(anaddb_input,
                              ddb_node=ddb_path,
                              manager=shell_manager)
    awork.register(atask)

    flow.register_work(awork)
    flow.allocate()
    flow.build()

    for i, atask in enumerate(awork):
        atask.history.info("About to run anaddb task: %d", i)
        atask.start_and_wait()
        assert atask.status == atask.S_DONE
        atask.check_status()
        assert atask.status == atask.S_OK

        # These output files should be produced in the task workdir.
        # Actually they should be in outdir but anaddb uses different conventions.
        assert len(atask.wdir.list_filepaths(wildcard="*PHBST.nc")) == 1
        assert len(atask.wdir.list_filepaths(wildcard="*PHDOS.nc")) == 1
Exemple #7
0
def itest_unconverged_scf(fwp, tvars):
    """Testing the treatment of unconverged GS calculations."""
    print("tvars:\n %s" % str(tvars))

    # Build the SCF and the NSCF input (note nstep to have an unconverged run)
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc", nstep=1)

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager)
    flow.allocate()

    # Use smart-io
    flow.use_smartio()

    flow.build_and_pickle_dump()

    t0 = flow[0][0]
    t1 = flow[0][1]

    assert t0.uses_paral_kgb(tvars.paral_kgb)
    assert t1.uses_paral_kgb(tvars.paral_kgb)

    # This run should not converge.
    t0.start_and_wait()
    t0.check_status()
    assert t0.status == t0.S_UNCONVERGED
    # Unconverged with smart-io --> WFK must be there
    assert t0.outdir.has_abiext("WFK")
    #assert 0

    # Remove nstep from the input so that we use the default value.
    # Then restart the GS task and test that GS is OK.
    assert not t1.can_run
    t0.input.pop("nstep")
    assert t0.num_restarts == 0
    t0.restart()
    t0.wait()
    assert t0.num_restarts == 1
    t0.check_status()
    assert t0.status == t1.S_OK

    # Converged with smart-io --> WFK is not written
    assert not t0.outdir.has_abiext("WFK")

    # Now we can start the NSCF step
    assert t1.can_run
    t1.start_and_wait()
    t1.check_status()
    assert t1.status == t0.S_UNCONVERGED

    assert not flow.all_ok

    # Restart (same trick as the one used for the GS run)
    t1.input.pop("nstep")
    assert t1.num_restarts == 0
    assert t1.restart()
    t1.wait()
    assert t1.num_restarts == 1
    assert t1.status == t1.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK

    flow.show_status()
    assert flow.all_ok

    # Test inspect methods
    if has_matplotlib():
        t0.inspect(show=False)

    # Test get_results
    t0.get_results()
    t1.get_results()

    # Build tarball file.
    tarfile = flow.make_tarfile()

    #assert flow.validate_json_schema()

    # Test reset_from_scratch
    t0.reset_from_scratch()
    assert t0.status == t0.S_READY
    # Datetime counters shouls be set to None
    dt = t0.datetimes
    assert (dt.submission, dt.start, dt.end) == (None, None, None)

    t0.start_and_wait()
    t0.reset_from_scratch()

    # Datetime counters shouls be set to None
    dt = t0.datetimes
    assert (dt.submission, dt.start, dt.end) == (None, None, None)
Exemple #8
0
def itest_unconverged_scf(fwp, tvars):
    """Testing the treatment of unconverged GS calculations."""
    print("tvars:\n %s" % str(tvars))

    # Build the SCF and the NSCF input (note nstep to have an unconverged run)
    scf_input, nscf_input = make_scf_nscf_inputs(tvars,
                                                 pp_paths="14si.pspnc",
                                                 nstep=1)

    # Build the flow and create the database.
    flow = flowtk.bandstructure_flow(fwp.workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=fwp.manager)
    flow.allocate()

    # Use smart-io
    flow.use_smartio()

    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    assert t0.uses_paral_kgb(tvars.paral_kgb)
    assert t1.uses_paral_kgb(tvars.paral_kgb)

    # This run should not converge.
    t0.start_and_wait()
    t0.check_status()
    assert t0.status == t0.S_UNCONVERGED
    # Unconverged with smart-io --> WFK must be there
    assert t0.outdir.has_abiext("WFK")
    #assert 0

    # Remove nstep from the input so that we use the default value.
    # Then restart the GS task and test that GS is OK.
    assert not t1.can_run
    t0.input.pop("nstep")
    assert t0.num_restarts == 0
    t0.restart()
    t0.wait()
    assert t0.num_restarts == 1
    t0.check_status()
    assert t0.status == t1.S_OK

    # Converged with smart-io --> WFK is not written
    assert not t0.outdir.has_abiext("WFK")

    # Now we can start the NSCF step
    assert t1.can_run
    t1.start_and_wait()
    t1.check_status()
    assert t1.status == t0.S_UNCONVERGED

    assert not flow.all_ok

    # Restart (same trick as the one used for the GS run)
    t1.input.pop("nstep")
    assert t1.num_restarts == 0
    assert t1.restart()
    t1.wait()
    assert t1.num_restarts == 1
    assert t1.status == t1.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK

    flow.show_status()
    assert flow.all_ok

    # Test inspect methods
    if has_matplotlib():
        t0.inspect(show=False)

    # Test get_results
    t0.get_results()
    t1.get_results()

    # Build tarball file.
    tarfile = flow.make_tarfile()

    #assert flow.validate_json_schema()

    # Test reset_from_scratch
    t0.reset_from_scratch()
    assert t0.status == t0.S_READY
    # Datetime counters shouls be set to None
    # FIXME: This does not work
    #dt = t0.datetimes
    #assert (dt.submission, dt.start, dt.end) == (None, None, None)

    t0.start_and_wait()
    t0.reset_from_scratch()
Exemple #9
0
def itest_bandstructure_flow(fwp, tvars):
    """
    Testing band-structure flow with one dependency: SCF -> NSCF.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc")

    # Build the flow and create the database.
    flow = flowtk.bandstructure_flow(fwp.workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=fwp.manager)
    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    # Test initialization status, task properties and links (t1 requires t0)
    assert t0.status == t0.S_INIT
    assert t1.status == t1.S_INIT
    assert t0.can_run
    assert not t1.can_run
    assert t1.depends_on(t0)
    assert not t1.depends_on(t1)
    assert t0.isnc
    assert not t0.ispaw

    # Flow properties and methods
    assert flow.num_tasks == 2
    assert not flow.all_ok
    assert flow.ncores_reserved == 0
    assert flow.ncores_allocated == 0
    assert flow.ncores_used == 0
    flow.check_dependencies()
    flow.show_status()
    flow.show_receivers()

    # Run t0, and check status
    assert t0.returncode == 0
    t0.start_and_wait()
    assert t0.returncode == 0
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert t1.can_run

    # Cannot start t0 twice...
    with pytest.raises(t0.Error):
        t0.start()

    # But we can restart it.
    fired = t0.restart()
    assert fired
    t0.wait()
    assert t0.num_restarts == 1
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert not t0.can_run

    # Now we can run t1.
    t1.start_and_wait()
    assert t1.status == t0.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK
    assert not t1.can_run

    # This one does not work yet
    #fired = t1.restart()
    #atrue(fired)
    #t1.wait()
    #aequal(t1.num_restarts, 1)
    #aequal(t1.status, t1.S_DONE)
    #t1.check_status()
    #aequal(t1.status, t1.S_OK)
    #afalse(t1.can_run)

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

    for task in flow.iflat_tasks():
        assert len(task.outdir.list_filepaths(wildcard="*GSR.nc")) == 1

    # Test GSR robot
    with abilab.abirobot(flow, "GSR") as robot:
        table = robot.get_dataframe()
        assert table is not None
        print(table)

    # Test AbinitTimer.
    timer = t0.parse_timing()
    print(timer)

    if has_matplotlib():
        timer.plot_pie(show=False)
        timer.plot_stacked_hist(show=False)
        timer.plot_efficiency(show=False)

    # Test CUT3D API provided by DensityFortranFile.
    den_path = t0.outdir.has_abiext("DEN")
    assert den_path
    if not den_path.endswith(".nc"):
        denfile = abilab.DensityFortranFile(den_path)
        workdir = flow.outdir.path
        denfile.get_cube("den.cube", workdir=workdir)
        denfile.get_xsf("den.xsf", workdir=workdir)
        denfile.get_tecplot("den.tecplot", workdir=workdir)
        denfile.get_molekel("den.molekel", workdir=workdir)
        denfile.get_3d_indexed("den.data_indexed", workdir=workdir)
        denfile.get_3d_formatted("den.data_formatted", workdir=workdir)
Exemple #10
0
def itest_bandstructure_flow(fwp, tvars):
    """
    Testing band-structure flow with one dependency: SCF -> NSCF.
    """
    #print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc")

    # Build the flow and create the database.
    flow = flowtk.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager)
    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    # Test initialization status, task properties and links (t1 requires t0)
    assert t0.status == t0.S_INIT
    assert t1.status == t1.S_INIT
    assert t0.can_run
    assert not t1.can_run
    assert t1.depends_on(t0)
    assert not t1.depends_on(t1)
    assert t0.isnc
    assert not t0.ispaw

    # Flow properties and methods
    assert flow.num_tasks == 2
    assert not flow.all_ok
    assert flow.ncores_reserved == 0
    assert flow.ncores_allocated == 0
    assert flow.ncores_used == 0
    flow.check_dependencies()
    flow.show_status()
    flow.show_receivers()

    # Run t0, and check status
    assert t0.returncode == 0
    t0.start_and_wait()
    assert t0.returncode == 0
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert t1.can_run

    # Cannot start t0 twice...
    with pytest.raises(t0.Error):
        t0.start()

    # But we can restart it.
    fired = t0.restart()
    assert fired
    t0.wait()
    assert t0.num_restarts == 1
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert not t0.can_run

    # Now we can run t1.
    t1.start_and_wait()
    assert t1.status == t0.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK
    assert not t1.can_run

    # FIXME This one does not work yet
    #fired = t1.restart()
    #atrue(fired)
    #t1.wait()
    #aequal(t1.num_restarts, 1)
    #aequal(t1.status, t1.S_DONE)
    #t1.check_status()
    #aequal(t1.status, t1.S_OK)
    #afalse(t1.can_run)

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

    for task in flow.iflat_tasks():
        assert len(task.outdir.list_filepaths(wildcard="*GSR.nc")) == 1

    # Test GSR robot
    with abilab.Robot.from_flow(flow, ext="GSR") as robot:
        table = robot.get_dataframe()
        assert table is not None
        #print(table)

    # Test AbinitTimer.
    timer = t0.parse_timing()
    assert str(timer)

    if has_matplotlib():
        assert timer.plot_pie(show=False)
        assert timer.plot_stacked_hist(show=False)
        assert timer.plot_efficiency(show=False)

    # Test CUT3D API provided by DensityFortranFile.
    den_path = t0.outdir.has_abiext("DEN")
    assert den_path
    if not den_path.endswith(".nc"):
        denfile = abilab.DensityFortranFile(den_path)
        str(denfile)
        workdir = flow.outdir.path
        denfile.get_cube("den.cube", workdir=workdir)
        denfile.get_xsf("den.xsf", workdir=workdir)
        denfile.get_tecplot("den.tecplot", workdir=workdir)
        denfile.get_molekel("den.molekel", workdir=workdir)
        denfile.get_3d_indexed("den.data_indexed", workdir=workdir)
        denfile.get_3d_formatted("den.data_formatted", workdir=workdir)
        ae_path = os.path.join(abidata.pseudo_dir, "0.14-Si.8.density.AE")
        hc = denfile.get_hirshfeld(scf_input.structure, all_el_dens_paths=[ae_path] * 2)
        assert np.abs(hc.net_charges[0]) < 0.1
        # This feature requires Abinit 8.5.2
        if flow.manager.abinit_build.version_ge("8.5.2"):
            den = denfile.get_density(workdir=workdir)
            assert den.structure is not None and hasattr(den, "datar")
Exemple #11
0
def itest_phonon_flow(fwp, tvars):
    """
    Create a flow for phonon calculations:

        1) One work for the GS run.

        2) nqpt works for phonon calculations. Each work contains
           nirred tasks where nirred is the number of irreducible phonon perturbations
           for that particular q-point.
    """
    all_inps = scf_ph_inputs(tvars)
    scf_input, ph_inputs = all_inps[0], all_inps[1:]

    ph_ngqpt = (2, 2, 2)
    flow = flowtk.PhononFlow.from_scf_input(fwp.workdir, scf_input, ph_ngqpt=ph_ngqpt, with_becs=False)

    scheduler = flow.make_scheduler()
    assert scheduler.start() == 0
    flow.check_status(show=True)
    assert all(work.finalized for work in flow)
    assert flow.all_ok

    with flow.open_final_ddb() as ddb:
        ddb_path = ddb.filepath
        ddb.to_string(verbose=2)
        assert len(ddb.structure) == 2
        #assert ddb.qpoints.frac_coords

    # Test PhononTask inspect method
    ph_task = flow[1][0]
    if has_matplotlib():
        assert ph_task.inspect(show=False)
    # Test get_results
    #ph_task.get_results()

    # Build new work with Anaddb tasks.
    # Construct a manager with mpi_procs==1 since anaddb do not support mpi_procs > 1 (except in elphon)
    shell_manager = fwp.manager.to_shell_manager(mpi_procs=1)
    awork = flowtk.Work(manager=shell_manager)

    # Phonons bands and DOS with gaussian method
    anaddb_input = abilab.AnaddbInput.phbands_and_dos(
        scf_input.structure, ngqpt=ph_ngqpt, ndivsm=5, nqsmall=10, dos_method="gaussian: 0.001 eV")

    atask = flowtk.AnaddbTask(anaddb_input, ddb_node=ddb_path, manager=shell_manager)
    awork.register(atask)

    # Phonons bands and DOS with tetrahedron method
    anaddb_input = abilab.AnaddbInput.phbands_and_dos(
        scf_input.structure, ngqpt=ph_ngqpt, ndivsm=5, nqsmall=10, dos_method="tetra")

    atask = flowtk.AnaddbTask(anaddb_input, ddb_node=ddb_path, manager=shell_manager)
    awork.register(atask)

    flow.register_work(awork)
    flow.allocate()
    flow.build()

    for i, atask in enumerate(awork):
        atask.history.info("About to run anaddb task: %d", i)
        atask.start_and_wait()
        assert atask.status == atask.S_DONE
        atask.check_status()
        assert atask.status == atask.S_OK

        # These output files should be produced in the task workdir.
        # Actually they should be in outdir but anaddb uses different conventions.
        assert len(atask.wdir.list_filepaths(wildcard="*PHBST.nc")) == 1
        assert len(atask.wdir.list_filepaths(wildcard="*PHDOS.nc")) == 1
Exemple #12
0
def itest_bandstructure_flow(fwp, tvars):
    """
    Testing band-structure flow with one dependency: SCF -> NSCF.
    """
    #print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc")

    # Build the flow and create the database.
    flow = flowtk.bandstructure_flow(fwp.workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=fwp.manager)
    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    # Test initialization status, task properties and links (t1 requires t0)
    assert t0.status == t0.S_INIT
    assert t1.status == t1.S_INIT
    assert t0.can_run
    assert not t1.can_run
    assert t1.depends_on(t0)
    assert not t1.depends_on(t1)
    assert t0.isnc
    assert not t0.ispaw

    # Flow properties and methods
    assert flow.num_tasks == 2
    assert not flow.all_ok
    assert flow.ncores_reserved == 0
    assert flow.ncores_allocated == 0
    assert flow.ncores_used == 0
    flow.check_dependencies()
    flow.show_status()
    flow.show_receivers()

    # Run t0, and check status
    assert t0.returncode == 0
    t0.start_and_wait()
    assert t0.returncode == 0
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert t1.can_run

    # Cannot start t0 twice...
    with pytest.raises(t0.Error):
        t0.start()

    # But we can restart it.
    fired = t0.restart()
    assert fired
    t0.wait()
    assert t0.num_restarts == 1
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert not t0.can_run

    # Now we can run t1.
    t1.start_and_wait()
    assert t1.status == t0.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK
    assert not t1.can_run

    # FIXME This one does not work yet
    #fired = t1.restart()
    #atrue(fired)
    #t1.wait()
    #aequal(t1.num_restarts, 1)
    #aequal(t1.status, t1.S_DONE)
    #t1.check_status()
    #aequal(t1.status, t1.S_OK)
    #afalse(t1.can_run)

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

    assert all(work.finalized for work in flow)

    for task in flow.iflat_tasks():
        assert len(task.outdir.list_filepaths(wildcard="*GSR.nc")) == 1

    # Test GSR robot
    with abilab.Robot.from_flow(flow, ext="GSR") as robot:
        table = robot.get_dataframe()
        assert table is not None
        #print(table)

    # Test AbinitTimer.
    timer = t0.parse_timing()
    assert str(timer)

    if has_matplotlib():
        assert timer.plot_pie(show=False)
        assert timer.plot_stacked_hist(show=False)
        assert timer.plot_efficiency(show=False)

    df, ebands_plotter = flow.compare_ebands(verbose=2,
                                             with_spglib=False,
                                             printout=True,
                                             with_colors=True)

    # Test CUT3D API provided by DensityFortranFile.
    den_path = t0.outdir.has_abiext("DEN")
    assert den_path
    if not den_path.endswith(".nc"):
        denfile = abilab.DensityFortranFile(den_path)
        str(denfile)
        workdir = flow.outdir.path
        denfile.get_cube("den.cube", workdir=workdir)
        denfile.get_xsf("den.xsf", workdir=workdir)
        denfile.get_tecplot("den.tecplot", workdir=workdir)
        denfile.get_molekel("den.molekel", workdir=workdir)
        denfile.get_3d_indexed("den.data_indexed", workdir=workdir)
        denfile.get_3d_formatted("den.data_formatted", workdir=workdir)
        ae_path = os.path.join(abidata.pseudo_dir, "0.14-Si.8.density.AE")
        hc = denfile.get_hirshfeld(scf_input.structure,
                                   all_el_dens_paths=[ae_path] * 2)
        assert np.abs(hc.net_charges[0]) < 0.1
        # This feature requires Abinit 8.5.2
        if flow.manager.abinit_build.version_ge("8.5.2"):
            den = denfile.get_density(workdir=workdir)
            assert den.structure is not None and hasattr(den, "datar")

    df = flow.get_dims_dataframe(printout=False, with_colors=True)
    assert "natom" in df

    df = flow.compare_abivars(["ecut", "natom"],
                              printout=True,
                              with_colors=True)
    assert np.all(df["natom"].values == 2)