def test_bse_with_mdf(self): """Testing bse_with_mdf input factory.""" scf_kppa, scf_nband, nscf_nband, dos_kppa = 10, 10, 10, 4 ecuteps, ecutsigx = 3, 2 nscf_ngkpt, nscf_shiftk = [2, 2, 2], [[0, 0, 0]] inp = bse_with_mdf_input(self.si_structure, self.si_pseudo, scf_kppa, nscf_nband, nscf_ngkpt, nscf_shiftk, ecuteps=2, bs_loband=1, bs_nband=2, soenergy="0.1 eV", mdf_epsinf=12, ecut=2) #exc_type="TDA", bs_algo="haydock", accuracy="normal", spin_mode="polarized", #smearing="fermi_dirac:0.1 eV", charge=0.0, scf_algorithm=None): print(inp) self.validate_inp(inp) #return scf_input, nscf_input, bse_input = inp.split_datasets() flow = abilab.Flow("flow_bse_with_mdf") flow.register_work(abilab.BseMdfWork(scf_input, nscf_input, bse_input)) flow.allocate()
def build_flow(options): structure = abilab.Structure.from_file(abidata.cif_file("si.cif")) scf_kppa = 40 nscf_nband = 6 ndivsm = 5 #dos_ngkpt = [4,4,4] #dos_shiftk = [0.1, 0.2, 0.3] extra_abivars = dict( ecut=6, ) # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_") workdir = options.workdir if not options.workdir: workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") # Initialize the flow. flow = abilab.Flow(workdir=workdir, manager=options.manager) pseudos = abidata.pseudos("14si.pspnc") work = bandstructure_work(structure, pseudos, scf_kppa, nscf_nband, ndivsm, spin_mode="unpolarized", smearing=None, **extra_abivars) flow.register_work(work) return flow
def build_flow(options): # Path of the pseudopotential to test. #pseudo = data.pseudo("14si.pspnc") pseudo = data.pseudo("Si.GGA_PBE-JTH-paw.xml") # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_") workdir = options.workdir if not options.workdir: workdir = os.path.basename(__file__).replace(".py", "").replace("run_", "flow_") # Initialize the flow. flow = abilab.Flow(workdir=workdir, manager=options.manager, remove=options.remove) # Build the workflow for the computation of the deltafactor. # The calculation is done with the parameters and the cif files # used in the original paper. We only have to specify # the cutoff energy ecut (Ha) for the pseudopotential. # The workflow will produce a pdf file with the equation of state # and a file deltafactor.txt with the final results in the # outdir directory DELTAFACTOR/work_0/outdir. factory = DeltaFactory() kppa = 6750 # Use this to have the official k-point sampling kppa = 50 # this value is for testing purpose. ecut = 8 pawecutdg = ecut * 2 if pseudo.ispaw else None work = factory.work_for_pseudo(pseudo, accuracy="normal", kppa=kppa, ecut=ecut, pawecutdg=pawecutdg, toldfe=1.e-8, smearing="fermi_dirac:0.0005") # Register the workflow. flow.register_work(work) return flow
def itest_gbrvcompounds_gga_pawxml_flow(fwp, tvars): """Testing the GBRV flow with GGA and PAW-XML (relaxation + EOS)""" # Unit test flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) gbrv_factory = GbrvCompoundsFactory(xc="PBE") formula, struct_type, accuracy = "SiO", "rocksalt", "normal" pseudos = pdj_data.pseudos("Si.psp8", "O.psp8") work = gbrv_factory.relax_and_eos_work(accuracy, pseudos, formula, struct_type, ecut=12, pawecutdg=None) flow.register_work(work) flow.build_and_pickle_dump(abivalidate=True) print("Working in ", flow.workdir) assert len(flow[0]) == 1 fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions flow.check_status(show=True) assert all(work.finalized for work in flow) assert flow.all_ok assert len(flow[0]) == 1 + 9
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_") # 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 = abilab.Flow(workdir, manager=options.manager, remove=options.remove) for structure in displaced_structures: # Create the work for the band structure calculation. scf_input, nscf_input = make_scf_nscf_inputs(structure) work = abilab.BandStructureWork(scf_input, nscf_input) flow.register_work(work) return flow
def itest_scf(self, lp, fworker, fwp, tmpdir, benchmark_input_scf): wf = InputFWWorkflow(benchmark_input_scf) scf_fw_id = wf.fw.fw_id old_new = wf.add_to_db(lpad=lp) scf_fw_id = old_new[scf_fw_id] rapidfire(lp, fworker, m_dir=str(tmpdir)) fw = lp.get_fw_by_id(scf_fw_id) assert fw.state == "COMPLETED" # Build the flow flow = abilab.Flow(fwp.workdir, manager=fwp.manager) work = flow.register_task(benchmark_input_scf, task_class=abilab.ScfTask) flow.allocate() flow.build_and_pickle_dump() # Run t0, and check status t0 = work[0] t0.start_and_wait() t0.check_status() assert t0.status == t0.S_OK
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_") # Create the flow flow = abilab.Flow(workdir, manager=options.manager, remove=options.remove) # Create a relaxation work and add it to the flow. ion_inp, ioncell_inp = make_ion_ioncell_inputs() relax_work = abilab.RelaxWork(ion_inp, ioncell_inp) flow.register_work(relax_work) #bands_work = abilab.BandStructureWork(scf_input, nscf_input) bands_work = abilab.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
def itest_dilatmx_error_handler(fwp, tvars): """ Test cell relaxation with automatic restart in the presence of dilatmx error. """ # Build the flow flow = abilab.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 = abilab.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 == 1 assert t0.corrections[0]["event"]["@class"] == "DilatmxError"
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 = abilab.Flow(fwp.workdir, manager=fwp.manager) work0 = abilab.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
def itest_relaxation_with_restart_from_den(fwp, tvars): """Test structural relaxations with automatic restart from DEN files.""" # Build the flow flow = abilab.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 = abilab.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()
def itest_nc_phonons_gamma(fwp, tvars): """Testing the calculation of phonons at Gamma with/without the Asr (NC pseudos).""" #pseudo = pdj_data.pseudo("Si.GGA_PBE-JTH-paw.xml").as_tmpfile(fwp.workdir) pseudo = pdj_data.pseudo("Si.psp8").as_tmpfile(fwp.workdir) assert pseudo is not None assert pseudo.has_dojo_report assert not pseudo.dojo_report.exceptions flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) ecut = 8 pawecutdg = 2 * ecut if pseudo.ispaw else None # This one requires deltafactor! factory = GammaPhononFactory(xc=pseudo.xc) work = factory.work_for_pseudo(pseudo, kppa=20, ecut=ecut, pawecutdg=pawecutdg) flow.register_work(work) flow.build_and_pickle_dump(abivalidate=True) #return fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions flow.check_status(show=True) assert all(work.finalized for work in flow) assert flow.all_ok assert not pseudo.dojo_report.exceptions assert pseudo.dojo_report.has_trial("phgamma", ecut=ecut)
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") 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 soenergy = 0.7 mdf_epsinf = 12 max_ncpus = 1 ecuteps = 2 extra_abivars = dict( ecut=12, istwfk="*1", ) flow = abilab.Flow(workdir=workdir, manager=options.manager) # BSE calculation with model dielectric function. work = bse_with_mdf_work(structure, pseudos, scf_kppa, nscf_nband, nscf_ngkpt, nscf_shiftk, ecuteps, bs_loband, bs_nband, soenergy, mdf_epsinf, accuracy="normal", spin_mode="unpolarized", smearing=None, charge=0.0, scf_solver=None, **extra_abivars) flow.register_work(work) return flow
def itest_ghosts_gga_pawxml_flow(fwp, tvars): """Testing the ghosts flow for PAW-XML""" pseudo = pdj_data.pseudo("Si.GGA_PBE-JTH-paw.xml").as_tmpfile(tmpdir=fwp.workdir) assert pseudo is not None print(pseudo) assert pseudo.has_dojo_report assert not pseudo.dojo_report.exceptions flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) factory = GhostsFactory(xc=pseudo.xc) ecut = 10 pawecutdg = 2 * ecut if pseudo.ispaw else None # maxene 200 will make the task restart. work = factory.work_for_pseudo(pseudo, kppa=20, maxene=200, ecut=ecut, pawecutdg=pawecutdg, spin_mode="unpolarized") assert work.dojo_trial == "ghosts" flow.register_work(work) flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions flow.check_status(show=True) assert all(work.finalized for work in flow) assert flow.all_ok assert not pseudo.dojo_report.exceptions assert pseudo.dojo_report.has_trial("ghosts", ecut=ecut) key = "%.1f" % ecut data = pseudo.dojo_report["ghosts"][key] assert data["dojo_status"] == 0 assert data["ecut"] == ecut ebands = abilab.ElectronBands.from_dict(data["ebands"])
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_") flow = abilab.Flow(workdir, manager=options.manager, remove=options.remove) # 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 = abilab.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 = abilab.BandStructureWork(scf_input, nscf_input, dos_inputs=dos_input) flow.register_work(work) return flow
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 = abilab.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 = abilab.BandStructureWork(scf_input=multi[0], nscf_input=multi[1]) flow.register_work(work) return flow
def build_flow(options): 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_") workdir = options.workdir if not options.workdir: workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") # Initialize the flow. flow = abilab.Flow(workdir, manager=options.manager) scf_kppa = 10 nscf_nband = 10 #nscf_ngkpt = [4,4,4] #nscf_shiftk = [0.0, 0.0, 0.0] ecut, ecuteps, ecutsigx = 4, 2, 3 #scr_nband = 50 #sigma_nband = 50 extra_abivars = dict( ecut=ecut, istwfk="*1", ) work = g0w0_with_ppmodel_work(structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx, accuracy="normal", spin_mode="unpolarized", smearing=None, ppmodel="godby", charge=0.0, inclvkb=2, sigma_nband=None, gw_qprange=1, scr_nband=None, **extra_abivars) flow.register_work(work) return flow
def itest_lantanides_gga_flow(fwp, tvars): """Testing the ghosts flow for NC+SOC pseudos.""" pseudo = pdj_data.pseudo("Lu-sp.psp8").as_tmpfile(tmpdir=fwp.workdir) assert pseudo is not None print(pseudo) assert pseudo.has_dojo_report assert not pseudo.supports_soc assert not pseudo.dojo_report.exceptions flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) factory = RocksaltRelaxationFactory(xc=pseudo.xc) ecut_list = [33] ngkpt = [1, 1, 1] #pawecutdg = 2 * ecut if pseudo.ispaw else None work = factory.work_for_pseudo(pseudo, ecut_list, pawecutdg=None, ngkpt=ngkpt, include_soc=False) assert work.dojo_trial == "raren_relax" flow.register_work(work) #flow.build_and_pickle_dump(abivalidate=True) assert flow.make_scheduler().start() == 0 flow.check_status(show=True, verbose=1) assert all(work.finalized for work in flow) assert flow.all_ok
def build_flow(options): """ Create an `AbinitFlow` for phonon calculations: 1) One workflow for the GS run. 2) nqpt workflows for phonon calculations. Each workflow contains nirred tasks where nirred is the number of irreducible phonon perturbations for that particular q-point. """ # 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_") all_inps = scf_ph_inputs() scf_input, ph_inputs = all_inps[0], all_inps[1:] flow = abilab.Flow(workdir, manager=options.manager, remove=options.remove) from pymatgen.io.abinit.works import build_oneshot_phononwork work = build_oneshot_phononwork(scf_input, ph_inputs) flow.register_work(work) return flow
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 = data.pseudos("14si.pspnc", "8o.pspnc") base_structure = abilab.Structure.from_file(data.cif_file("si.cif")) news, uparams = [], [0.1, 0.2, 0.3] for u in uparams: new = special_positions(base_structure.lattice, u) news.append(new) flow = abilab.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
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_") 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") # 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 = abilab.Flow(workdir=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
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 = abilab.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 = abilab.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
def itest_htc_bandstructure(fwp, tvars): """Test band-structure calculations done with the HTC interface.""" structure = abilab.Structure.from_file(abidata.cif_file("si.cif")) pseudos = abidata.pseudos("14si.pspnc") # Initialize the flow. flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) # Use ebands_input factory function to build inputs. multi = abilab.ebands_input(structure, pseudos, kppa=20, nscf_nband=6, ndivsm=5, ecut=2, dos_kppa=40, spin_mode="unpolarized") work = flowtk.BandStructureWork(scf_input=multi[0], nscf_input=multi[1], dos_inputs=multi[2:]) multi.set_vars(paral_kgb=tvars.paral_kgb) flow.register_work(work) flow.allocate() flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions assert fwp.scheduler.nlaunch == 3 flow.show_status() if not flow.all_ok: flow.debug() raise RuntimeError() assert all(work.finalized for work in flow) # Test if GSR files are produced and are readable. for i, task in enumerate(work): with task.open_gsr() as gsr: assert gsr.nsppol == 1 #assert gsr.structure == structure if i == 0: gsr.to_string(verbose=2) if i == 1: # Bandstructure case assert gsr.ebands.has_bzpath assert not gsr.ebands.has_bzmesh with pytest.raises(ValueError): gsr.ebands.get_edos() if i == 2: # DOS case assert gsr.ebands.has_bzmesh assert not gsr.ebands.has_bzpath gsr.ebands.get_edos()
def itest_tolsymerror_handler(fwp): """ Test the handler of TolSymError. The test triggers: --- !TolSymError message: | Could not find the point group src_file: symptgroup.F90 src_line: 236 ... at the level of the symmetry finder and autoparal fails because it cannot find the parallel configurations. """ structure = dict( acell=(1.0, 1.0, 1.0), xred=[ 1.0001907690, 1.0040151117, 0.0099335191, 0.2501907744, 0.2540150788, 0.2599335332 ], rprim=[ -6.2733366562, 0.0000000000, -3.6219126071, -6.2733366562, 0.0000000000, 3.6219126071, -4.1822244376, 5.9145585205, 0.0000000000 ], typat=(1, 1), ntypat=1, znucl=14, natom=2, ) inp = abilab.AbinitInput(structure=structure, pseudos=abidata.pseudos("14si.pspnc")) inp.set_vars( ntime=5, tolrff=0.02, shiftk=[0, 0, 0], ngkpt=(4, 4, 4), chksymbreak=0, ecut=4, tolmxf=5e-05, nshiftk=1, ) flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) flow.register_task(inp, task_class=abilab.RelaxTask) flow.allocate() assert flow.make_scheduler().start() == 0 flow.show_status() assert flow.all_ok task = flow[0][0] assert len(task.corrections) == 1 assert task.corrections[0]["event"]["@class"] == "TolSymError"
def itest_htc_g0w0(fwp, tvars): """Testing G0W0Work.""" structure = abilab.Structure.from_file(abidata.cif_file("si.cif")) pseudos = abidata.pseudos("14si.pspnc") flow = abilab.Flow(fwp.workdir, manager=fwp.manager) scf_kppa = 10 nscf_nband = 10 #nscf_ngkpt = [4,4,4] #nscf_shiftk = [0.0, 0.0, 0.0] ecut, ecuteps, ecutsigx = 4, 2, 3 #scr_nband = 50 #sigma_nband = 50 extra_abivars = dict( ecut=ecut, istwfk="*1", paral_kgb=tvars.paral_kgb, ) multi = abilab.g0w0_with_ppmodel_inputs( structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx, ecut=ecut, pawecutdg=None, 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=tvars.paral_kgb) scf_input, nscf_input, scr_input, sigma_input = multi.split_datasets() work = abilab.G0W0Work(scf_input, nscf_input, scr_input, sigma_input) flow.register_work(work) flow.allocate() flow.connect_signals() #flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions assert fwp.scheduler.nlaunch == 4 # The sigma task should produce a SCR file. assert len(work[2].outdir.list_filepaths(wildcard="*SCR")) == 1 flow.show_status() assert flow.all_ok assert all(work.finalized for work in flow)
def raman_flow(): # Get the unperturbed structure. base_structure = abilab.Structure.from_abivars(unit_cell) pseudos = ["14si.pspnc"] workdir = os.path.join(os.path.dirname(__file__), "test_abipy_new") manager = abilab.TaskManager.from_user_config() #manager = abilab.TaskManager.from_file("bfo_manager.yml") policy = TaskPolicy(autoparal=0) gs_manager = manager.deepcopy() # Initialize flow. Each workflow in the flow defines a complete BSE calculation for given eta. flow = abilab.Flow(workdir, manager) # There will be kppa/natom kpoints in the unit cell ! kppa = 3456 # ngkpt = [12,12,12] for the primitive cell kppa_gs = 1728 # ngkpt = [8,8,8] for the primitive cell etas = [-1, 0, 1] # Anyway, it rescales everything at the end :-) eta = 0.01 scale_matrix = [[-1, 0, 1], [-1, 1, 0], [-1, -1, 0]] ph_tot = np.array([[0.01, 0.011, 0.021], [-0.01, 0.041, -0.02]]) modifier = abilab.StructureModifier(base_structure) displaced_structure = modifier.frozen_phonon([0.5, 0.5, 0.5], ph_tot, do_real=True, frac_coords=False, scale_matrix=scale_matrix) structure = displaced_structure ksampgs = KSampling.automatic_density(structure, kppa_gs, chksymbreak=0, shifts=[0, 0, 0]) gs_inp = gs_input(structure, pseudos, ksampgs) wflow = abilab.Work() gs_t = wflow.register_scf_task(gs_inp) gs_t.set_manager(gs_manager) flow.register_work(wflow, workdir="gs_task") ksamp = KSampling.automatic_density(structure, kppa, chksymbreak=0, shifts=[1 / 4, 1 / 4, 1 / 4]) flow.register_work(raman_workflow(structure, pseudos, gs_t, ksamp), workdir="bse_task") return flow.allocate()
def itest_atomic_relaxation(fwp, tvars): """Test atomic relaxation with automatic restart.""" # Build the flow flow = abilab.Flow(fwp.workdir, manager=fwp.manager) ion_input = ion_relaxation(tvars, ntime=2) work = flow.register_task(ion_input, task_class=abilab.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: print(hist) # from_file accepts HIST files as well. assert hist.structures[-1] == abilab.Structure.from_file(hist.filepath) with t0.open_gsr() as gsr: print(gsr) gsr.pressure == 1.8280 t0.get_results()
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. """ structure = abilab.Structure.from_file(abidata.cif_file("si.cif")) structure.scale_lattice(structure.volume * 0.6) # 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 = abilab.Flow(fwp.workdir, manager=fwp.manager) flow.register_task(inp, task_class=abilab.RelaxTask) flow.allocate() assert flow.make_scheduler().start() == 0 flow.show_status() assert flow.all_ok task = flow[0][0] assert len(task.corrections) == 2 for i in range(task.num_corrections): assert task.corrections[i]["event"]["@class"] == "DilatmxError"
def itest_oneshot_phonon_work(fwp): """ Test build_oneshot_phononwork i.e. computation of the phonon frequencies for all modes in a single task. """ all_inps = scf_ph_inputs() # SCF + one-shot for the first 2 qpoints. scf_input, ph_inputs = all_inps[0], all_inps[1:3] from pymatgen.io.abinit.works import build_oneshot_phononwork flow = abilab.Flow(fwp.workdir) # rfdir and rfatpol are missing! with pytest.raises(ValueError): phon_work = build_oneshot_phononwork(scf_input, ph_inputs) for phinp in ph_inputs: phinp.set_vars(rfdir=[1, 1, 1]) with pytest.raises(ValueError): phon_work = build_oneshot_phononwork(scf_input, ph_inputs) for phinp in ph_inputs: phinp.set_vars(rfatpol=[1, len(phinp.structure)]) # Now ph_inputs is ok phon_work = build_oneshot_phononwork(scf_input, ph_inputs) flow.register_work(phon_work) assert flow.make_scheduler().start() == 0 flow.check_status(show=True, verbose=1) assert all(work.finalized for work in flow) assert flow.all_ok # Read phonons from main output file. phonons_list = phon_work.read_phonons() assert len(phonons_list) == 2 ph0, ph1 = phonons_list[0], phonons_list[1] assert ph0.qpt == [0, 0, 0] assert ph1.qpt == [2.50000000E-01, 0.00000000E+00, 0.00000000E+00] assert len(ph0.freqs) == 3 * len(scf_input.structure) assert len(ph1.freqs) == 3 * len(scf_input.structure) nptu.assert_almost_equal(ph0.freqs.to("Ha"), [ -1.219120E-05, -1.201501E-05, -1.198453E-05, 1.577646E-03, 1.577647E-03, 1.577647E-03 ]) nptu.assert_almost_equal(ph1.freqs.to("Ha"), [ 2.644207E-04, 2.644236E-04, 6.420904E-04, 1.532696E-03, 1.532697E-03, 1.707196E-03 ])
def itest_gbrv_flow(fwp, tvars): """The the GBRV flow: relaxation + EOS computation.""" factory = GbrvFactory() #pseudo = "si_pbe_v1_abinit.paw" pseudo = abidata.pseudo("Si.GGA_PBE-JTH-paw.xml") ecut = 2 pawecutdg = 2 * ecut if pseudo.ispaw else None flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager, pickle_protocol=0) struct_types = ["fcc"] #, "bcc"] for struct_type in struct_types: work = factory.relax_and_eos_work(pseudo, struct_type, ecut, pawecutdg=pawecutdg, paral_kgb=tvars.paral_kgb) flow.register_work(work) flow.allocate() flow.build_and_pickle_dump() fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions #work = flow[0] #t0 = work[0] #assert len(work) == 1 #t0.start_and_wait() #flow.check_status() # At this point on_all_ok is called. #assert t0.status == t0.S_OK #assert len(flow) == 2 #assert len(flow[1]) == 9 #assert not flow.all_ok #for task in flow[1]: # task.start_and_wait() flow.check_status() flow.show_status() assert all(work.finalized for work in flow) assert flow.all_ok
def itest_metagga_ebands_flow(fwp, tvars): """ Test band structure calculation with meta-GGA """ if not fwp.abinit_build.has_libxc: pytest.skip( "itest_metagga_ebands_flow requires libxc support in Abinit.") from abipy.data.hgh_pseudos import HGH_TABLE multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"), pseudos=HGH_TABLE, 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=20, diemac=12, iomode=3, ixc=-208012, prtkden=1, usekden=1) # Dataset 1 multi[0].set_vars(tolvrs=1e-7) multi[0].set_kmesh(ngkpt=[2, 2, 2], shiftk=shiftk) # Dataset 2 multi[1].set_vars(tolwfr=1e-8) multi[1].set_kpath(ndivsm=2) scf_input, nscf_input = multi.split_datasets() work = flowtk.works.BandStructureWork(scf_input=scf_input, nscf_input=nscf_input) flow = abilab.Flow(workdir=fwp.workdir, manager=fwp.manager) flow.register_work(work) flow.build_and_pickle_dump(abivalidate=True) fwp.scheduler.add_flow(flow) assert fwp.scheduler.start() == 0 assert not fwp.scheduler.exceptions #assert fwp.scheduler.nlaunch == 3 flow.show_status() if not flow.all_ok: flow.debug() raise RuntimeError() assert all(work.finalized for work in flow)