Source code for atomate2.cp2k.schemas.calc_types.utils
"""Module to define various calculation types as Enums for CP2K."""fromcollections.abcimportIterable,SequencefrompathlibimportPathfrommonty.serializationimportloadfnfrompymatgen.io.cp2k.inputsimportKeyword,KeywordListfromatomate2.cp2k.schemas.calc_typesimportCalcType,RunType,TaskType_RUN_TYPE_DATA=loadfn(str(Path(__file__).parent.joinpath("run_types.yaml").resolve()))
[docs]defrun_type(inputs:dict)->RunType:""" Determine the run_type from the CP2K input dict. This is adapted from pymatgen to be far less unstable. Args: dft: dictionary of DFT parameters (standard from task doc) """dft=inputs.get("dft")def_variant_equal(v1:Sequence,v2:Sequence)->bool:"""Determine if two run_types are equal."""ifisinstance(v1,str)andisinstance(v2,str):returnv1.strip().upper()==v2.strip().upper()ifisinstance(v1,Iterable)andisinstance(v2,Iterable):returnset(v1)==set(v2)returnv1==v2is_hubbard="+U"ifdft.get("dft_plus_u")else""vdw=f"-{dft.get('vdw')}"ifdft.get("vdw")else""parameters={"FUNCTIONAL":dft.get("functional"),"INTERACTION_POTENTIAL":dft.get("hfx",{}).get("Interaction_Potential"),"FRACTION":dft.get("hfx",{}).get("FRACTION",0),}# Standard calc will only have one functional. If there are multiple functionals# used this is either a hybrid calc or a non-generic mixed calculation.iflen(parameters["FUNCTIONAL"])==1:parameters["FUNCTIONAL"]=parameters["FUNCTIONAL"][0]# If all parameters in for the functional_class.special_type located in# run_types.yaml are met, then that is the run type.forfunctional_classin_RUN_TYPE_DATA:forspecial_type,paramsin_RUN_TYPE_DATA[functional_class].items():ifall(_variant_equal(parameters.get(param,True),value)forparam,valueinparams.items()):returnRunType(f"{special_type}{vdw}{is_hubbard}")# TODO elegant way to handle this?# This is a hack to get the non-standard hybrids to workifparameters.get("FRACTION"):returnRunType(f"HYBRID{vdw}{is_hubbard}")returnRunType(f"LDA{is_hubbard}")
[docs]defcalc_type(inputs:dict,)->CalcType:""" Determine the calc type. Args: inputs: dict from InputSummary containing necessary data for determining calc type """rt=run_type(inputs).valuett=task_type(inputs).valuereturnCalcType(f"{rt}{tt}")