Example #1
0
 def fix(self, err_jobdir, new_jobdir, settings):
     """ First attempt:
             Set ALGO = VeryFast
             Unset IALGO
         Second attempt:
             Set IBRION = 1 and POTIM = 0.1
         Final attempt:
             Set LREAD = .FALSE.
     """
     continue_job(err_jobdir, new_jobdir, settings)
     if io.get_incar_tag("ALGO", jobdir=new_jobdir) != "VeryFast":
         print "  Set Algo = VeryFast, and Unset IALGO"
         io.set_incar_tag({
             "IALGO": None,
             "ALGO": "VeryFast"
         },
                          jobdir=new_jobdir)
     elif io.get_incar_tag("IBRION", jobdir=new_jobdir) != 1:
         print "  Set IBRION = 1 and POTIM = 0.1"
         sys.stdout.flush()
         io.set_incar_tag({"IBRION": 1, "POTIM": 0.1}, jobdir=new_jobdir)
     elif io.get_incar_tag("LREAL", jobdir=new_jobdir) != False:
         print "  Set LREAL = .FALSE."
         sys.stdout.flush()
         io.set_incar_tag({"LREAL": False}, jobdir=new_jobdir)
Example #2
0
    def status(self):
        """ Determine the status of a vasp relaxation series of runs. Individual runs in the series
            are in directories labeled "run.0", "run.1", etc.

            Returns a tuple: (status = "incomplete" or "complete" or "not_converging",
                                task = continuedir or "relax" or "constant" or None)

            The first value is the status of the entire relaxation.

            The second value is the current task, where 'continuedir' is the path to a
            vasp job directory that is not yet completed, "relax" indicates another
            volume relaxation job is required, and "constant" that a constant volume run is required.
        """

        # check if all complete
        if io.job_complete(self.finaldir):
            return ("complete", None)

        # check status of relaxation runs
        self.update_rundir()

        # if not yet started
        if len(self.rundir) == 0:
            return ("incomplete", "setup")

        # if the latest run is complete:
        if io.job_complete(self.rundir[-1]):

            # if it is a final constant volume run
            if io.get_incar_tag("SYSTEM", self.rundir[-1]) != None:
                if io.get_incar_tag("NSW", self.rundir[-1]) == 0 and \
                   io.get_incar_tag("SYSTEM", self.rundir[-1]).split()[-1].strip().lower() == "final":
                    # if io.get_incar_tag("ISIF", self.rundir[-1]) == 2 and \
                    #    io.get_incar_tag("NSW", self.rundir[-1]) == 0 and \
                    #    io.get_incar_tag("ISMEAR", self.rundir[-1]) == -5:
                    return ("complete", None)

            # elif constant volume run (but not the final one)
            if io.get_incar_tag("ISIF", self.rundir[-1]) in [0, 1, 2]:
                return ("incomplete", "constant")

            # elif convergence criteria met
            if self.converged():
                return ("incomplete", "constant")

            # elif not converging, return 'not_converging' error
            if self.not_converging():
                return ("not_converging", None)

            # else continue relaxing
            else:
                return ("incomplete", "relax")

        # elif not converging, return 'not_converging' error
        elif self.not_converging():
            return ("not_converging", None)

        # else if the latest run is not complete, continue running it
        return ("incomplete", self.rundir[-1])
Example #3
0
    def status(self):
        """ Determine the status of a vasp relaxation series of runs. Individual runs in the series
            are in directories labeled "run.0", "run.1", etc.

            Returns a tuple: (status = "incomplete" or "complete" or "not_converging",
                                task = continuedir or "relax" or "constant" or None)

            The first value is the status of the entire relaxation.

            The second value is the current task, where 'continuedir' is the path to a
            vasp job directory that is not yet completed, "relax" indicates another
            volume relaxation job is required, and "constant" that a constant volume run is required.
        """

        # check if all complete
        if io.job_complete(self.finaldir):
            return ("complete",None)

        # check status of relaxation runs
        self.update_rundir()

        # if not yet started
        if len(self.rundir) == 0:
            return ("incomplete", "setup")

        # if the latest run is complete:
        if io.job_complete(self.rundir[-1]):

            # if it is a final constant volume run
            if io.get_incar_tag("SYSTEM", self.rundir[-1]) != None:
                if io.get_incar_tag("NSW", self.rundir[-1]) == 0 and \
                   io.get_incar_tag("SYSTEM", self.rundir[-1]).split()[-1].strip().lower() == "final":
                # if io.get_incar_tag("ISIF", self.rundir[-1]) == 2 and \
                #    io.get_incar_tag("NSW", self.rundir[-1]) == 0 and \
                #    io.get_incar_tag("ISMEAR", self.rundir[-1]) == -5:
                    return ("complete", None)

            # elif constant volume run (but not the final one)
            if io.get_incar_tag("ISIF", self.rundir[-1]) in [0,1,2]:
                return ("incomplete", "constant")

            # elif convergence criteria met
            if self.converged():
                return ("incomplete", "constant")

            # elif not converging, return 'not_converging' error
            if self.not_converging():
                return ("not_converging", None)

            # else continue relaxing
            else:
                return ("incomplete", "relax")

        # elif not converging, return 'not_converging' error
        elif self.not_converging():
            return ("not_converging", None)

        # else if the latest run is not complete, continue running it
        return ("incomplete", self.rundir[-1])
Example #4
0
 def fix(self, err_jobdir, new_jobdir, settings):
     """ First attempt:
             Set ALGO = VeryFast
             Unset IALGO
         Second attempt:
             Set IBRION = 1 and POTIM = 0.1
         Final attempt:
             Set LREAD = .FALSE.
     """
     continue_job(err_jobdir, new_jobdir, settings)
     if io.get_incar_tag("ALGO", jobdir=new_jobdir) != "VeryFast":
         print "  Set Algo = VeryFast, and Unset IALGO"
         io.set_incar_tag({"IALGO": None, "ALGO": "VeryFast"}, jobdir=new_jobdir)
     elif io.get_incar_tag("IBRION", jobdir=new_jobdir) != 1:
         print "  Set IBRION = 1 and POTIM = 0.1"
         sys.stdout.flush()
         io.set_incar_tag({"IBRION": 1, "POTIM": 0.1}, jobdir=new_jobdir)
     elif io.get_incar_tag("LREAL", jobdir=new_jobdir) != False:
         print "  Set LREAL = .FALSE."
         sys.stdout.flush()
         io.set_incar_tag({"LREAL": False}, jobdir=new_jobdir)
Example #5
0
    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 relaxation 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], self.settings)

            elif task == "relax":
                self.add_rundir()
                vasp.continue_job(self.rundir[-2], self.rundir[-1],
                                  self.settings)
                shutil.copyfile(os.path.join(self.relaxdir, "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.relaxdir, self.settings["final"]))):
                    new_values = io.Incar(
                        os.path.join(self.relaxdir,
                                     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"])

                # if no errors, continue
                if result == None or self.not_converging():
                    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 f in self.settings["backup"]:
                        if os.path.isfile(
                                os.path.join(self.rundir[-2],
                                             f + "_BACKUP.gz")):
                            f_in = gzip.open(
                                os.path.join(self.rundir[-2], f + "_BACKUP.gz",
                                             'rb'))
                            f_out = open(os.path.join(self.rundir[-1], f,
                                                      'wb'))
                            f_out.write(f_in.read())
                            f_in.close()
                            f_out.close()
                            print f, " 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)
Example #6
0
    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 relaxation 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], self.settings)

            elif task == "relax":
                self.add_rundir()
                vasp.continue_job(self.rundir[-2], self.rundir[-1], self.settings)
                shutil.copyfile(os.path.join(self.relaxdir,"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.relaxdir,self.settings["final"]))):
                    new_values = io.Incar(os.path.join(self.relaxdir, 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():
                    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 f in self.settings["backup"]:
                        if os.path.isfile(os.path.join(self.rundir[-2], f + "_BACKUP.gz")):
                            f_in = gzip.open(os.path.join(self.rundir[-2], f + "_BACKUP.gz", 'rb'))
                            f_out = open(os.path.join(self.rundir[-1], f, 'wb'))
                            f_out.write(f_in.read())
                            f_in.close()
                            f_out.close()
                            print f, " 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)