[docs]@_sig_kwargs(vp.gen2numpy,skip_params=("gen",))@_sub_doc(vp.gen2numpy,{"gen :.*shape :":"path : Path to file containing data.\nshape :"},)defparse_text(path,shape,slice,**kwargs):p=Path(path)ifnotp.is_file():raiseFileNotFoundError(f"File {path!r} does not exists")withp.open("r",encoding="utf-8")asf:gen=islice(f,0,None)data=vp.gen2numpy(gen,shape,slice,**kwargs)# should be under open file contextreturndata
[docs]defget_bib(DOI):"Get bibligraphy entry from DOI"response=requests.get(f'http://dx.doi.org/{DOI}',headers={'Accept':'text/bibliography;style=bibtex'})ifresponse.status_code==200:returnresponse.content.decode('utf-8')returnresponse.status_code
[docs]defget_E0(path:Path='OSZICAR',nsteps=0):"Get the E0 from the last line of OSZICAR. If `nsteps > 0`, returns as many available last steps ."fh=Path(path)iffh.is_file():lines=fh.read_text().splitlines()else:raiseFileNotFoundError(f"File: {path!r} does not exists!")ifnotlines:raiseValueError(f"File: {path!r} is empty!")line=lines[-1]if'F='notinline:raiseValueError(f"File: {path!r} is not a valid OSZICAR file or calculation is not finished!")ifnotline.lstrip().startswith('1'):print(f"Calculation may not be converged for {path!r}\n{line}")ifnsteps>0:# not allow negative oneslines=[float(line.split()[2])forlineinlinesif(not'dE'inline)and(not'F='inline)]returnnp.array(lines[-nsteps:])# as many last stepsreturnfloat(line.split('=')[1].split()[0])
[docs]classOUTCAR:"Parse some required data from OUTCAR file."def__init__(self,path=None):self._path=Path(pathor"OUTCAR")self._data=vp.export_outcar(self._path)@propertydefdata(self):returnself._data@propertydefpath(self):returnself._path
[docs]@_sub_doc(vp.read)defread(self,start_match,stop_match=r'\n',nth_match=1,skip_last=False,apply=None):kws={k:vfork,vinlocals().items()ifk!='self'}returnvp.read(self.path,**kws)# Pass all the arguments to the function