def is_converged(self): # Check for electronic convergence in completed calculations. Returns True or False. # Verify that the last relaxation reached electronic convergence relaxation = vasp.Relax(self.calcdir, self.run_settings()) for i in range(len(relaxation.rundir)): try: vrun = vasp.io.Vasprun( os.path.join(self.calcdir, relaxation.rundir[-i - 1], "vasprun.xml")) if len(vrun.all_e_0[-1]) >= vrun.nelm: print( 'The last relaxation run (' + os.path.basename(relaxation.rundir[-i - 1]) + ') failed to achieve electronic convergence; properties.calc.json will not be written.\n' ) self.report_status('failed', 'electronic_convergence') return False break except: pass # Verify that the final static run reached electronic convergence vrun = vasp.io.Vasprun( os.path.join(self.calcdir, "run.final", "vasprun.xml")) if len(vrun.all_e_0[0]) >= vrun.nelm: print( 'The final run failed to achieve electronic convergence; properties.calc.json will not be written.\n' ) self.report_status('failed', 'electronic_convergence') return False return True
def run(self): """ Setup input files, run a vasp relaxation, and report results """ # construct the Relax object relaxation = vasp.Relax(self.calcdir, self.run_settings()) # check the current status (status, task) = relaxation.status() if status == "complete": print "Status:", status sys.stdout.flush() # mark job as complete in db if self.auto: try: pbs.complete_job() except (pbs.PBSError, pbs.JobDBError, pbs.EligibilityError) as e: print str(e) sys.stdout.flush() # write results to output.VASP self.report() return elif status == "not_converging": print "Status:", status print "Returning" sys.stdout.flush() return elif status == "incomplete": if task == "setup": self.setup() (status, task) = relaxation.run() else: raise vaspwrapper.VaspWrapperError("unexpected relaxation status: '" + status + "' and task: '" + task + "'") sys.stdout.flush() # once the run is done, update database records accordingly if status == "not_converging": # mark error if self.auto: try: pbs.error_job("Not converging") except (pbs.PBSError, pbs.JobDBError) as e: print str(e) sys.stdout.flush() print "Not Converging!" sys.stdout.flush() # print a local settings file, so that the run_limit can be extended if the # convergence problems are fixed try: os.makedirs(os.path.join(self.configdir, "settings", self.casm_settings["curr_calctype"])) except: pass settingsfile = os.path.join(self.configdir, "settings", self.casm_settings["curr_calctype"], "relax.json") vaspwrapper.write_settings(self.settings, settingsfile) print "Writing:", settingsfile print "Edit the 'run_limit' property if you wish to continue." sys.stdout.flush() return elif status == "complete": # mark job as complete in db if self.auto: try: pbs.complete_job() except (pbs.PBSError, pbs.JobDBError, pbs.EligibilityError) as e: print str(e) sys.stdout.flush() # write results to output.VASP self.report() else: raise vaspwrapper.VaspWrapperError("vasp relaxation complete with unexpected status: '" + status + "' and task: '" + task + "'") sys.stdout.flush()
def submit(self): """Submit a PBS job for this VASP relaxation""" # first, check if the job has already been submitted and is not completed db = pbs.JobDB() print "rundir", self.calcdir id = db.select_regex_id("rundir", self.calcdir) print "id:", id sys.stdout.flush() if id != []: for j in id: job = db.select_job(j) # taskstatus = ["Incomplete","Complete","Continued","Check","Error:.*","Aborted"] # jobstatus = ["C","Q","R","E","W","H","M"] if job["jobstatus"] != "C": print "JobID:", job["jobid"], " Jobstatus:", job["jobstatus"], " Not submitting." sys.stdout.flush() return #elif job["taskstatus"] in ["Complete", "Check"] or re.match( "Error:.*", job["taskstatus"]): # print "JobID:", job["jobid"], " Taskstatus:", job["taskstatus"], " Not submitting." # sys.stdout.flush() # return # second, only submit a job if relaxation status is "incomplete" # construct the Relax object relaxation = vasp.Relax(self.calcdir, self.run_settings()) # check the current status (status, task) = relaxation.status() if status == "complete": print "Status:", status, " Not submitting." sys.stdout.flush() # ensure job marked as complete in db if self.auto: for j in id: job = db.select_job(j) if job["taskstatus"] == "Incomplete": try: pbs.complete_job(jobid=j) except (pbs.PBSError, pbs.JobDBError, pbs.EligibilityError) as e: print str(e) sys.stdout.flush() # ensure results report written if not os.path.isfile(os.path.join(self.calcdir, "properties.calc.json")): self.report() return elif status == "not_converging": print "Status:", status, " Not submitting." sys.stdout.flush() return elif status != "incomplete": raise vaspwrapper.VaspWrapperError("unexpected relaxation status: '" + status + "' and task: '" + task + "'") sys.stdout.flush() return print "Preparing to submit a VASP relaxation PBS job" sys.stdout.flush() # cd to configdir, submit jobs from configdir, then cd back to currdir currdir = os.getcwd() os.chdir(self.calcdir) # determine the number of atoms in the configuration print " Counting atoms in the POSCAR" sys.stdout.flush() pos = vasp.io.Poscar(os.path.join(self.configdir,"POS")) N = len(pos.basis) print " Constructing a PBS job" sys.stdout.flush() # construct a pbs.Job job = pbs.Job(name=casm.jobname(self.configdir),\ account=self.settings["account"],\ nodes=int(math.ceil(float(N)/float(self.settings["atom_per_proc"])/float(self.settings["ppn"]))),\ ppn=int(self.settings["ppn"]),\ walltime=self.settings["walltime"],\ pmem=self.settings["pmem"],\ qos=self.settings["qos"],\ queue=self.settings["queue"],\ message=self.settings["message"],\ email=self.settings["email"],\ priority=self.settings["priority"],\ command="python -c \"import casm.vaspwrapper; casm.vaspwrapper.Relax('" + self.configdir + "').run()\"",\ auto=self.auto) print " Submitting" sys.stdout.flush() # submit the job job.submit() # return to current directory os.chdir(currdir) print "CASM VASPWrapper relaxation PBS job submission complete\n" sys.stdout.flush()