def test_task_history_and_events(self): si = abilab.Structure.from_file(abidata.cif_file("si.cif")) si_relax_input = ion_ioncell_relax_input(si, abidata.pseudos("14si.pspnc"), ecut=2).split_datasets()[1] th = TaskHistory() th.log_initialization(task=RelaxFWTask(si_relax_input), initialization_info={"test_info": 1}) th.log_autoparal({u'time': u'12:0:0', u'ntasks': 15, u'partition': 'defq', u'nodes': 1, u'mem_per_cpu': 3000}) th.log_finalized(final_input=si_relax_input) th.log_restart(RestartInfo(os.path.abspath('.'), reset=True, num_restarts=2)) th.log_unconverged() th.log_corrections([events.Correction(events.DilatmxErrorHandler(), {}, events.DilatmxError('', '', '',), )]) th.log_abinit_stop(run_time=100) try: raise AbinitRuntimeError("test error") except AbinitRuntimeError as exc: th.log_error(exc) try: raise RuntimeError("test error") except RuntimeError as exc: th.log_error(exc) th.log_converge_params({'dilatmx': 1.03}, si_relax_input) self.assertMSONable(th) for te in th: self.assertMSONable(te)
def inputs_relax_si_low(): pseudos = abidata.pseudos("14si.pspnc") cif_file = abidata.cif_file("si.cif") structure = abilab.Structure.from_file(cif_file) structure.apply_strain(0.005) structure.translate_sites(0, [0.001, -0.003, 0.005]) structure.translate_sites(1, [0.007, 0.006, -0.005]) return ion_ioncell_relax_input(structure, pseudos, kppa=100, ecut=4).split_datasets()
def inputs_relax_si_low(): pseudos = abidata.pseudos("14si.pspnc") structure = get_si_structure() # negative strain. This will allow to trigger dilatmx error structure.apply_strain(-0.005) structure.translate_sites(0, [0.001, -0.003, 0.005]) structure.translate_sites(1, [0.007, 0.006, -0.005]) return ion_ioncell_relax_input(structure, pseudos, kppa=100, ecut=4, spin_mode="unpolarized", accuracy="low", smearing=None).split_datasets()
def from_factory(cls, structure, pseudos, kppa=None, nband=None, ecut=None, pawecutdg=None, accuracy="normal", spin_mode="polarized", smearing="fermi_dirac:0.1 eV", charge=0.0, scf_algorithm=None, extra_abivars={}, decorators=[], autoparal=False, spec={}, initialization_info={}, target_dilatmx=None): ion_input = ion_ioncell_relax_input(structure=structure, pseudos=pseudos, kppa=kppa, nband=nband, ecut=ecut, pawecutdg=pawecutdg, accuracy=accuracy, spin_mode=spin_mode, smearing=smearing, charge=charge, scf_algorithm=scf_algorithm)[0] ioncell_fact = IoncellRelaxFromGsFactory(accuracy=accuracy) return cls(ion_input, ioncell_fact, autoparal=autoparal, spec=spec, initialization_info=initialization_info, target_dilatmx=target_dilatmx)
def test_task_history_and_events(self): si = abilab.Structure.from_file(abidata.cif_file("si.cif")) si_relax_input = ion_ioncell_relax_input(si, abidata.pseudos("14si.pspnc"), ecut=2).split_datasets()[1] th = TaskHistory() th.log_initialization(task=RelaxFWTask(si_relax_input), initialization_info={"test_info": 1}) th.log_autoparal({ u'time': u'12:0:0', u'ntasks': 15, u'partition': 'defq', u'nodes': 1, u'mem_per_cpu': 3000 }) th.log_finalized(final_input=si_relax_input) th.log_restart( RestartInfo(os.path.abspath('.'), reset=True, num_restarts=2)) th.log_unconverged() th.log_corrections([ events.Correction( events.DilatmxErrorHandler(), {}, events.DilatmxError( '', '', '', ), ) ]) th.log_abinit_stop(run_time=100) try: raise AbinitRuntimeError("test error") except AbinitRuntimeError as exc: th.log_error(exc) try: raise RuntimeError("test error") except RuntimeError as exc: th.log_error(exc) th.log_converge_params({'dilatmx': 1.03}, si_relax_input) self.assertMSONable(th) for te in th: self.assertMSONable(te)
def work_for_pseudo(self, pseudo, kppa=1000, ecut=None, pawecutdg=None, smearing="fermi_dirac:0.1 eV", include_soc=False, workdir=None, manager=None): """ Create and return a :class:`RelaxAndAddPhGammaWork` object. Args: pseudo: filepath or :class:`Pseudo` object. kppa: Number of k-points per reciprocal atom. ecut: Cutoff energy in Hartree pawecutdg: Cutoff energy of the fine grid (PAW only) smearing: Smearing technique. include_soc=True of SOC should be included. workdir: Working directory. manager: :class:`TaskManager` object. """ symbol = pseudo.symbol if pseudo.ispaw and pawecutdg is None: raise ValueError("pawecutdg must be specified for PAW calculations.") if pseudo.xc != self._dfdb.xc: raise ValueError( "Pseudo xc differs from the XC used to instantiate the factory\n" "Pseudo: %s, Database: %s" % (pseudo.xc, self._dfdb.xc)) qpt = np.zeros(3) self.include_soc = include_soc try: cif_path = self.get_cif_path(pseudo.symbol) except Exception as exc: raise self.Error(str(exc)) # DO NOT CHANGE THE STRUCTURE REPORTED IN THE CIF FILE. structure = Structure.from_file(cif_path, primitive=False) # Get spinat and spin_mode from df database. spinat, spin_mode = self._dfdb.spinat_spinmode_for_symbol(symbol) # DFPT with AFM is not supported. Could try AFM in Relax and then polarized # in WFK + DFPT but this one is safer. if spin_mode == "afm": spin_mode = "polarized" if include_soc: spin_mode = "spinor" # Build inputs for structural relaxation. multi = ion_ioncell_relax_input( structure, pseudo, kppa=kppa, nband=None, ecut=ecut, pawecutdg=pawecutdg, accuracy="normal", spin_mode=spin_mode, smearing=smearing) # Set spinat from internal database. multi.set_vars(chkprim=0, mem_test=0, spinat=spinat) # Construct a *specialized" work for structural relaxation # This work will create a new workflow for phonon calculations # with the final relaxed structure (see on_all_ok below). work = RelaxAndAddPhGammaWork(ion_input=multi[0], ioncell_input=multi[1]) # Monkey patch work work.dojo_kppa = kppa work.dojo_qpt = qpt work.ecut = ecut work.dojo_pawecutdg = pawecutdg work.dojo_include_soc = include_soc work._dojo_trial = "phgamma" if not include_soc else "phgamma_soc" work.dojo_pseudo = pseudo return work