"""Drones for parsing VASP calculations and related outputs."""from__future__importannotationsimportloggingimportosfrompathlibimportPathfromemmet.core.tasksimportTaskDocfrompymatgen.apps.borg.hiveimportAbstractDronelogger=logging.getLogger(__name__)
[docs]classVaspDrone(AbstractDrone):""" A VASP drone to parse VASP outputs. Parameters ---------- **task_document_kwargs Additional keyword args passed to :obj:`.TaskDoc.from_directory`. """def__init__(self,**task_document_kwargs)->None:self.task_document_kwargs=task_document_kwargs
[docs]defassimilate(self,path:str|Path|None=None)->TaskDoc:""" Parse VASP output files and return the output document. Parameters ---------- path : str or Path or None Path to the directory containing vasprun.xml and OUTCAR files. Returns ------- TaskDoc A VASP task document. """path=pathorPath.cwd()try:doc=TaskDoc.from_directory(path,**self.task_document_kwargs)exceptException:importtracebacklogger.exception(f"Error in {Path(path).absolute()}\n{traceback.format_exc()}")raisereturndoc
[docs]defget_valid_paths(self,path:tuple[str,list[str],list[str]])->list[str]:"""Get valid paths to assimilate. There are some restrictions on the valid directory structures: 1. There can be only one vasprun in each directory. Nested directories are fine. 2. Directories designated "relax1"..."relax9" are considered to be parts of a multiple-optimization run. 3. Directories containing VASP output with ".relax1"...".relax9" are also considered as parts of a multiple-optimization run. Parameters ---------- path : tuple of (str, list of str, list of str) Input path as a tuple generated from ``os.walk``, i.e., (parent, subdirs, files). Returns ------- list of str A list of paths to assimilate. """parent,subdirs,_=pathtask_names=["precondition"]+[f"relax{i}"foriinrange(9)]ifset(task_names).intersection(subdirs):return[parent]if(notany(parent.endswith(os.sep+r)forrintask_names)andlen(list(Path(parent).glob("vasprun.xml*")))>0):return[parent]return[]