def fix(self, err_jobdir, new_jobdir, settings): """ Try to fix by making kpoints subdivisions odd or changing kpoint length""" continue_job(err_jobdir, new_jobdir, settings) kpt = io.Kpoints(os.path.join(new_jobdir, "KPOINTS")) if kpt.automode[0].lower() == "a": old_kpt = kpt.subdivisions[0] ocr = io.Outcar(os.path.join(err_jobdir, "OUTCAR")) max_k = max(ocr.kpts) kpt.automode = "GAMMA" kpt.subdivisions = [max_k, max_k, max_k] kpt.shift = [0.0, 0.0, 0.0] print " Changed KPOINTS from AUTO (%s) to GAMMA (%s)" % ( old_kpt, kpt.subdivisions) # kpt.subdivisions[0]+=1 # print " Increased KPOINTS length from ", kpt.subdivisions[0]-1, " to ", kpt.subdivisions[0] kpt.write(os.path.join(new_jobdir, "KPOINTS")) else: odd = True for i in range(len(kpt.subdivisions)): if kpt.subdivisions[i] % 2 == 0: odd = False kpt.subdivisions[i] += 1 if odd == False: print " Set KPOINTS subdivision to be odd:", kpt.subdivisions, "and mode to Gamma" kpt.automode = "Gamma" kpt.write(os.path.join(new_jobdir, "KPOINTS"))
def complete(self): """Check if the VASP relaxation is complete. Completion criteria: .../config/vasp/relax/run.final/OUTCAR exists and is complete """ outcarfile = os.path.join(self.finaldir, "OUTCAR") if not os.path.isfile(outcarfile): return False if not io.Outcar(outcarfile).complete(): return False return True
def complete(self): """Check if the VASP convergence is complete. Completion criteria: .../config/calctype/prop/prop_value/run.final/OUTCAR exists and is complete """ outcarfile = os.path.join(self.finaldir, "OUTCAR") if not os.path.isfile(outcarfile): return False if not io.Outcar(outcarfile).complete(): return False return True
def error(self, line=None, jobdir=None): """ Check if VASP appears frozen Returns true if: 1) no file has been modified for 5 minutes 2) 'LOOP+' exists in OUTCAR and no output file has been modified in 5x the time for the slowest loop """ # Check if any files modified in last 300 s most_recent = None most_recent_file = None for f in os.listdir(jobdir): t = time.time() - os.path.getmtime(os.path.join(jobdir, f)) if most_recent == None: most_recent = t most_recent_file = f elif t < most_recent: most_recent = t most_recent_file = f print "Most recent file output (" + f + "):", most_recent, " seconds ago." sys.stdout.flush() if t < 300: return False outcar = io.Outcar(os.path.join(jobdir, "OUTCAR")) if outcar.complete: print "outcar.complete:", outcar.complete sys.stdout.flush() return False elif outcar.slowest_loop != None and most_recent > 5.0 * outcar.slowest_loop: print "slowest_loop:", outcar.slowest_loop print "5.0*slowest_loop:", 5.0 * outcar.slowest_loop print "most_recent:", most_recent sys.stdout.flush() return True return False
def run(self): """ Perform a series of vasp jobs to relax a structure. Performs a series of vasp calculations until convergence is reached according to the criteria in 'status()'. Then performs a final constant volume run {"ISIF":2, "ISMEAR":-5, "NSW":0, "IBRION":-1}. """ print "Begin VASP convergence run" sys.stdout.flush() # get current status of the relaxation: (status, task) = self.status() print "\n++ status:", status, " next task:", task sys.stdout.flush() while status == "incomplete": if task == "setup": self.add_rundir() self.setup(self.rundir[-1]) elif task == "relax": self.add_rundir() vasp.continue_job(self.rundir[-2], self.rundir[-1], self.settings) shutil.copyfile(os.path.join(self.propdir, "INCAR.base"), os.path.join(self.rundir[-1], "INCAR")) elif task == "constant": self.add_rundir() vasp.continue_job(self.rundir[-2], self.rundir[-1], self.settings) # set INCAR to ISIF = 2, ISMEAR = -5, NSW = 0, IBRION = -1 if (self.settings["final"] != None) and (os.path.isfile(os.path.join(self.propdir, self.settings["final"]))): new_values = io.Incar(os.path.join(self.propdir, self.settings["final"])).tags else: new_values = {"ISIF":2, "ISMEAR":-5, "NSW":0, "IBRION":-1} # set INCAR system tag to denote 'final' if io.get_incar_tag("SYSTEM", self.rundir[-1]) is None: new_values["SYSTEM"] = "final" else: new_values["SYSTEM"] = io.get_incar_tag("SYSTEM", self.rundir[-1]) + " final" io.set_incar_tag(new_values, self.rundir[-1]) print " Set INCAR tags:", new_values, "\n" sys.stdout.flush() else: # probably hit walltime self.add_rundir() vasp.continue_job(self.rundir[-2], self.rundir[-1], self.settings) while True: # run vasp result = vasp.run(self.rundir[-1], npar=self.settings["npar"], ncore=self.settings["ncore"], command=self.settings["vasp_cmd"], ncpus=self.settings["ncpus"], kpar=self.settings["kpar"], err_types=self.settings["err_types"]) # if no errors, continue if result is None or self.not_converging(): # Check for actions that should be taken after the initial run if len(self.rundir) == 1: if self.settings["fine_ngx"]: outcarfile = os.path.join(self.rundir[-1], "OUTCAR") if not os.path.isfile(outcarfile): # This is an error but I'm not sure what to do about it pass else: init_outcar = io.Outcar(outcarfile) if not init_outcar.complete: # This is an error but I'm not sure what to do about it pass elif (init_outcar.ngx is None or init_outcar.ngy is None or init_outcar.ngz is None): # This is an error but I'm not sure what to do about it pass else: ng_tags = { "ngx" : init_outcar.ngx*2, "ngy" : init_outcar.ngy*2, "ngz" : init_outcar.ngz*2} print ng_tags io.set_incar_tag(ng_tags, self.propdir, "INCAR.base") break # else, attempt to fix first error self.add_errdir() os.mkdir(self.rundir[-1]) # self.add_rundir() err = result.itervalues().next() print "\n++ status:", "error", " next task:", "fix_error" sys.stdout.flush() print "Attempting to fix error:", str(err) err.fix(self.errdir[-1], self.rundir[-1], self.settings) print "" sys.stdout.flush() if (self.settings["backup"] != None) and len(self.rundir) > 1: print "Restoring from backups:" for my_file in self.settings["backup"]: if os.path.isfile(os.path.join(self.rundir[-2], my_file + "_BACKUP.gz")): f_in = gzip.open(os.path.join(self.rundir[-2], my_file + "_BACKUP.gz", 'rb')) f_out = open(os.path.join(self.rundir[-1], my_file, 'wb')) f_out.write(f_in.read()) f_in.close() f_out.close() print my_file, " restored!" sys.stdout.flush() (status, task) = self.status() print "\n++ status:", status, " next task:", task sys.stdout.flush() if status == "complete": if not os.path.isdir(self.finaldir): # mv final results to relax.final print "mv", os.path.basename(self.rundir[-1]), os.path.basename(self.finaldir) sys.stdout.flush() os.rename(self.rundir[-1], self.finaldir) self.rundir.pop() vasp.complete_job(self.finaldir, self.settings) return (status, task)