"""Jobs for defect calculations."""from__future__importannotationsimportloggingfromjobflowimportjobfrompymatgen.io.vaspimportIncarfrompymatgen.io.vasp.outputsimportWSWQfromatomate2.common.filesimportcopy_files,gunzip_files,gzip_files,rename_filesfromatomate2.common.jobs.defectimport(# noqa: F401bulk_supercell_calculation,get_ccd_documents,get_charged_structures,get_supercell_from_prv_calc,spawn_defect_q_jobs,spawn_energy_curve_calcs,)fromatomate2.utils.file_clientimportFileClientfromatomate2.utils.pathimportstrip_hostnamefromatomate2.vasp.filesimportcopy_vasp_outputsfromatomate2.vasp.runimportrun_vaspfromatomate2.vasp.schemas.defectimportFiniteDifferenceDocumentlogger=logging.getLogger(__name__)
[docs]@job(data=WSWQ,output_schema=FiniteDifferenceDocument)defcalculate_finite_diff(distorted_calc_dirs:list[str],ref_calc_index:int,run_vasp_kwargs:dict|None=None,)->FiniteDifferenceDocument:"""Run a post-processing VASP job for the finite difference overlap. Reads the WAVECAR file and computes the desired quantities. This can be used in cases where data from the same calculation is used multiple times. Since all of the standard outputs are presumably already stored in the database, the make function here should only store new data. Parameters ---------- distorted_calc_dirs: List[str] List of directories containing distorted calculations. ref_calc_index: int Index of the reference (distortion=0) calculation. run_vasp_kwargs : dict kwargs to pass to run_vasp (should be copied from the static maker used for previous calculations). """ref_calc_dir=distorted_calc_dirs[ref_calc_index]run_vasp_kwargs=run_vasp_kwargsor{}fc=FileClient()copy_vasp_outputs(ref_calc_dir,additional_vasp_files=["WAVECAR"],file_client=fc)# Update the INCAR for the WSWQ calculationincar=Incar.from_file("INCAR")incar.update(ALGO="None",NSW=0,LWAVE=False,LWSWQ=True)incar.write_file("INCAR")d_dir_names=[strip_hostname(d)fordindistorted_calc_dirs]foridx,dir_nameinenumerate(d_dir_names):# Copy a distorted WAVECAR to WAVECAR.qqqcopy_files(dir_name,include_files=["WAVECAR.gz"],prefix="qqq.")gunzip_files(include_files="qqq.WAVECAR*",allow_missing=True)rename_files({"qqq.WAVECAR":"WAVECAR.qqq"})run_vasp(**run_vasp_kwargs)fc.copy("WSWQ",f"WSWQ.{idx}")fd_doc=FiniteDifferenceDocument.from_directory(".",ref_dir=ref_calc_dir,distorted_dirs=d_dir_names)gzip_files(".",force=True)returnfd_doc