def make_electronic_structure_flow(ngkpts_for_dos=((2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8))): """Band structure calculation.""" multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"), ndtset=2 + len(ngkpts_for_dos)) # Global variables multi.set_vars(ecut=10) # Dataset 1 multi[0].set_vars(tolvrs=1e-9) multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0]) # Dataset 2 multi[1].set_vars(tolwfr=1e-15) multi[1].set_kpath(ndivsm=5) # Dataset 3 for i, ngkpt in enumerate(ngkpts_for_dos): multi[2 + i].set_vars(tolwfr=1e-15) multi[2 + i].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0]) inputs = multi.split_datasets() scf_input, nscf_input, dos_input = inputs[0], inputs[1], inputs[2:] return flowtk.bandstructure_flow(workdir="flow_dos_bands", scf_input=scf_input, nscf_input=nscf_input, dos_inputs=dos_input)
def build_ebands_flow(options): """ Band structure calculation. First, a SCF density computation, then a non-SCF band structure calculation. Similar to tbase3_5.in """ multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"), ndtset=2) # Global variables shiftk = [ float(s) for s in "0.5 0.5 0.5 0.5 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.5".split() ] multi.set_vars(ecut=8, diemac=12, iomode=3) # Dataset 1 multi[0].set_vars(tolvrs=1e-9) multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=shiftk) # Dataset 2 multi[1].set_vars(tolwfr=1e-15) multi[1].set_kpath(ndivsm=5) scf_input, nscf_input = multi.split_datasets() workdir = options.workdir if (options and options.workdir) else "flow_base3_ebands" return flowtk.bandstructure_flow(workdir, scf_input=scf_input, nscf_input=nscf_input)
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_mgb2_edoses.py") 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) inputs = make_scf_nscf_inputs(structure, pseudos) scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:] return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input, dos_inputs=dos_inputs, manager=options.manager)
def run_flow(options): """Run test flow, return exit code.""" import tempfile workdir = tempfile.mkdtemp(dir=options.flow_dir) cprint("Running small flow in workdir: %s" % workdir, "yellow") print() # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs() # Build the flow. flow = flowtk.bandstructure_flow(workdir, scf_input, nscf_input, manager=None) flow.build_and_pickle_dump() scheduler = flow.make_scheduler() retcode = scheduler.start() if retcode != 0: cprint("Scheduler returned retcode %s" % retcode, "red") return retcode flow.show_status() if not flow.all_ok: cprint("Not all tasks in flow reached all_ok", "red") retcode = 1 return retcode
def itest_bandstructure_schedflow(fwp, tvars): """ Testing bandstructure flow with the scheduler. """ #print("tvars:\n %s" % str(tvars)) # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs( tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml") # Build the flow and create the database. flow = flowtk.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager) # Will remove output files (WFK) flow.set_garbage_collector() flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) #print(fwp.scheduler) # scheduler cannot handle more than one flow. with pytest.raises(fwp.scheduler.Error): fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions assert fwp.scheduler.nlaunch == 2 flow.show_status() assert flow.all_ok assert all(work.finalized for work in flow) # The WFK files should have been removed because we called set_garbage_collector for task in flow[0]: assert not task.outdir.has_abiext("WFK") # Test if GSR files are produced and are readable. for i, task in enumerate(flow[0]): with task.open_gsr() as gsr: assert gsr.nsppol == 1 assert gsr.to_string(verbose=2) #assert gsr.structure == structure # TODO: This does not work yet because GSR files do not contain # enough info to understand if we have a path or a mesh. if i == 0: # DOS case assert gsr.ebands.has_bzmesh assert not gsr.ebands.has_bzpath edos = gsr.ebands.get_edos() assert abs(edos.tot_idos.values[-1] - edos.nelect) < 1e-3 if i == 1: # Bandstructure case assert gsr.ebands.has_bzpath assert not gsr.ebands.has_bzmesh with pytest.raises(ValueError): gsr.ebands.get_edos()
def itest_bandstructure_schedflow(fwp, tvars): """ Testing bandstructure flow with the scheduler. """ #print("tvars:\n %s" % str(tvars)) # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml") # Build the flow and create the database. flow = flowtk.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager) # Will remove output files (WFK) flow.set_garbage_collector() flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) #print(fwp.scheduler) # scheduler cannot handle more than one flow. with pytest.raises(fwp.scheduler.Error): fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions assert fwp.scheduler.nlaunch == 2 flow.show_status() assert flow.all_ok assert all(work.finalized for work in flow) # The WFK files should have been removed because we called set_garbage_collector for task in flow[0]: assert not task.outdir.has_abiext("WFK") # Test if GSR files are produced and are readable. for i, task in enumerate(flow[0]): with task.open_gsr() as gsr: assert gsr.nsppol == 1 assert gsr.to_string(verbose=2) #assert gsr.structure == structure # TODO: This does not work yet because GSR files do not contain # enough info to understand if we have a path or a mesh. if i == 0: # DOS case assert gsr.ebands.has_bzmesh assert not gsr.ebands.has_bzpath edos = gsr.ebands.get_edos() assert abs(edos.tot_idos.values[-1] - edos.nelect) < 1e-3 if i == 1: # Bandstructure case assert gsr.ebands.has_bzpath assert not gsr.ebands.has_bzmesh with pytest.raises(ValueError): gsr.ebands.get_edos()
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(__file__).replace(".py", "").replace("run_", "flow_") # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs() # Build the flow. return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input, manager=options.manager)
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(__file__).replace(".py", "").replace("run_", "flow_") # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs() # Build the flow. return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input, manager=options.manager)
def test_with_flow(self): """Testing abirun.py commands with flow (no execution)""" env = self.get_env(check_help_version=False) no_logo_colors = ["--no-logo", "--no-colors"] # Build a flow. flowdir = env.base_path scf_input, nscf_input = make_scf_nscf_inputs() flow = flowtk.bandstructure_flow(flowdir, scf_input, nscf_input, manager=None) flow.build_and_pickle_dump() # Test abirun commands requiring a flow (no submission) for command in [ "status", "debug", "debug_reset", "deps", "inputs", "corrections", "events", "history", "handlers", "cancel", "tail", "inspect", "structures", "ebands", "hist", "cycles", "dims", "tricky", ]: r = env.run(self.script, flowdir, command, self.loglevel, self.verbose, *no_logo_colors, expect_stderr=self.expect_stderr) assert r.returncode == 0 r = env.run(self.script, flowdir, "abivars", "-vn", "ecut,nband", self.loglevel, self.verbose, *no_logo_colors, expect_stderr=self.expect_stderr) assert r.returncode == 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: if os.getenv("READTHEDOCS", False): __file__ = os.path.join(os.getcwd(), "run_si_ebands.py") options.workdir = os.path.basename(__file__).replace( ".py", "").replace("run_", "flow_") # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs() # Build the flow. return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input, manager=options.manager)
def itest_bandstructure_schedflow(fwp, tvars): """ Testing bandstructure flow with the scheduler. """ print("tvars:\n %s" % str(tvars)) # Get the SCF and the NSCF input. scf_input, nscf_input = make_scf_nscf_inputs( tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml") # Build the flow and create the database. flow = flowtk.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager) # Will remove output files (WFK) flow.set_garbage_collector() flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) print(fwp.scheduler) # scheduler cannot handle more than one flow. with pytest.raises(fwp.scheduler.Error): fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions assert fwp.scheduler.nlaunch == 2 flow.show_status() assert flow.all_ok assert all(work.finalized for work in flow) # The WFK files should have been removed because we called set_garbage_collector for task in flow[0]: assert not task.outdir.has_abiext("WFK") # Test if GSR files are produced and are readable. for i, task in enumerate(flow[0]): with task.open_gsr() as gsr: print(gsr) assert gsr.nsppol == 1 #assert gsr.structure == structure ebands = gsr.ebands
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) inputs = make_scf_nscf_inputs(structure, pseudos) scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:] return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input, dos_inputs=dos_inputs, manager=options.manager)
def make_ebands_flow(): """Band structure calculation.""" multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"), pseudos=abidata.pseudos("14si.pspnc"), ndtset=2) # Global variables multi.set_vars(ecut=10) # Dataset 1 multi[0].set_vars(tolvrs=1e-9) multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0]) # Dataset 2 multi[1].set_vars(tolwfr=1e-15) multi[1].set_kpath(ndivsm=5) scf_input, nscf_input = multi.split_datasets() return flowtk.bandstructure_flow(workdir="flow_base3_ebands", scf_input=scf_input, nscf_input=nscf_input)
def test_with_flow(self): """Testing abirun.py commands with flow (no execution)""" env = self.get_env(check_help_version=False) no_logo_colors = ["--no-logo", "--no-colors"] # Build a flow. flowdir = env.base_path scf_input, nscf_input = make_scf_nscf_inputs() flow = flowtk.bandstructure_flow(flowdir, scf_input, nscf_input, manager=None) flow.build_and_pickle_dump() # Test abirun commands requiring a flow (no submission) for command in ["status", "debug", "debug_reset", "deps", "inputs", "corrections", "events", "history", "handlers", "cancel", "tail", "inspect", "structures", "ebands", "hist", "cycles", "dims", "tricky",]: r = env.run(self.script, flowdir, command, self.loglevel, self.verbose, *no_logo_colors, expect_stderr=self.expect_stderr) assert r.returncode == 0 r = env.run(self.script, flowdir, "abivars", "-vn", "ecut,nband", self.loglevel, self.verbose, *no_logo_colors, expect_stderr=self.expect_stderr) assert r.returncode == 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")
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") # 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(): assert t0.inspect(show=False) # Test get_results t0.get_results() t1.get_results() # Build tarball file. tarfile = flow.make_tarfile() # 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()
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()
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)
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)