[docs]defrestart_relaxation(submit:bool=False,file_size_limit:float=FILE_SIZE_LIMIT,old_job:pathlib.Path|None=None,*,bader:bool=False,chargemol:bool=False,auto_restart:bool=False,calc_mods:dict[str,Any]|None=None,slurm_mods:dict[str,Any]|None=None,files_to_carry_over:Iterable[str]|None=None,**_,)->pathlib.Path:"""Utility function for restarting a DFT relaxation calculation. Args: submit: Whether or not to submit the new job after creation. file_size_limit: A float specifying the threshold above which files of this size will be deleted. Size is specified in bytes. old_job: The path to the old job. bader: Whether or not to add logic to run Bader charge analysis after the calculation has converged. chargemol: Whether or not to add logic to run DDEC6 analysis with chargemol after the calculation has converged. auto_restart: Whether or not to add logic to automatically restart the calculation after the calculation has converged. calc_mods: A dictionary mapping calculator parameters to values that should be used to overwrite the existing parameters. slurm_mods: A dictionary mapping Slurm options to values that should be used to overwrite the existing parameters. files_to_carry_over: A list of strings indicating which files to carry over from the old job directory to the new job directory. Defaults to None, in which case, the files to copy are determined from the previous task. Returns: The path to the newly created job. """old_job=pathlib.Path(old_job)ifold_jobelsepathlib.Path.cwd()calc_mods=calc_modsor{}slurm_mods=slurm_modsor{}ifbaderorchargemol:calc_mods["laechg"]=calc_mods["lcharg"]=Trueprevious=Task.from_directory(old_job,magic_mode=True,strict_mode=False)context=previous.task_metadata.model_dump(exclude_none=True)context["structure"]=previous.task_inputs.atoms.info.get("structure","{structure}")mods=substitute_context(slurm_mods,context)ifisinstance(previous,Calculation):previous.calculation_inputs.parameters.update(calc_mods)scheduler_inputs=previous.scheduler_inputs.model_dump(exclude_none=True)SchedulerInputs.update_values(scheduler_inputs,mods)previous.scheduler_inputs=SchedulerInputs(**scheduler_inputs)previous.task_inputs.auto_restart=auto_restartiffiles_to_carry_overisnotNone:previous.task_inputs.files_to_carry_over=files_to_carry_overwithTemporaryDirectory()astmpdir:spec=f"{Calculation.__module__}.{Calculation.__name__}"_,new_task_dir=_create_task(src=old_job,task_type_spec=spec,parametrization=[],previous_task=previous,root=tmpdir,legacy_mode=True,is_restart=True,)dst=old_job.parent.joinpath(new_task_dir.name)shutil.copytree(src=new_task_dir,dst=dst)update_metadata_file(new_task=dst,study_dir=old_job.parents[1],legacy_mode=True,restart=True,)delete_large_files(old_job=old_job,file_size_limit=file_size_limit)logger.debug(f"New job created {'/'.join(dst.parts[-4:])}")ifsubmit:submit_new_task(new_task=dst)returndst