Пример #1
0
    def setup(self, initdir):
        """ mv all files and directories (besides initdir) into initdir """

        print("Moving files into initial run directory:", initdir)
        initdir = os.path.abspath(initdir)
        for my_prop in os.listdir(self.propdir):
            if (my_prop in io.VASP_INPUT_FILE_LIST +
                    self.settings["extra_input_files"]) and (os.path.join(
                        self.propdir, my_prop) != initdir):
                os.rename(os.path.join(self.propdir, my_prop),
                          os.path.join(initdir, my_prop))
        print("")
        sys.stdout.flush()

        # Keep a backup copy of the base INCAR
        shutil.copyfile(os.path.join(initdir, "INCAR"),
                        os.path.join(self.propdir, "INCAR.base"))

        # If an initial incar is called for, copy it in and set the appropriate flag
        if (self.settings["initial"] != None) and (os.path.isfile(
                os.path.join(self.propdir, self.settings["initial"]))):
            new_values = io.Incar(
                os.path.join(self.propdir, self.settings["initial"])).tags
            io.set_incar_tag(new_values, initdir)
            print("  Set INCAR tags:", new_values, "\n")
            sys.stdout.flush()
Пример #2
0
    def setup(self, initdir, settings):
        """ mv all files and directories (besides initdir) into initdir """
        ### still has to handle the images

        print("Moving files and directories into initial run directory:",
              initdir)
        initdir = os.path.abspath(initdir)
        for p in os.listdir(self.calcdir):
            if (p in (io.VASP_INPUT_FILE_LIST +
                      self.settings["extra_input_files"])) and (os.path.join(
                          self.calcdir, p) != initdir):
                os.rename(os.path.join(self.calcdir, p),
                          os.path.join(initdir, p))
        ## copying the folders with image poscars into initdir
        for i in range(settings["n_images"] + 2):
            folder_name = str(i).zfill(
                2)  #max(2, len(str(settings["n_images"]))+1 )) ##too fancy!!!
            shutil.copytree(os.path.join(self.calcdir, "poscars", folder_name),
                            os.path.join(initdir, folder_name))

        print("")
        sys.stdout.flush()

        # Keep a backup copy of the base INCAR
        shutil.copyfile(os.path.join(initdir, "INCAR"),
                        os.path.join(self.calcdir, "INCAR.base"))
        os.rename(os.path.join(initdir, "POSCAR"),
                  os.path.join(self.calcdir, "POSCAR.start"))
        # If an initial incar is called for, copy it in and set the appropriate flag
        if (self.settings["initial"] != None) and (os.path.isfile(
                os.path.join(self.calcdir, self.settings["initial"]))):
            new_values = io.Incar(
                os.path.join(self.calcdir, self.settings["initial"])).tags
            io.set_incar_tag(new_values, initdir)
            print("  Set INCAR tags:", new_values, "\n")
            sys.stdout.flush()
Пример #3
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 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()
                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()
                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()
                continue_job(self.rundir[-2], self.rundir[-1], self.settings)

            while True:
                # run vasp
                result = 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()
                complete_job(self.finaldir, self.settings)

        return (status, task)
Пример #4
0
    def run(self):
        """ Perform a series of vasp jobs to run calculations. Performs a series of vasp calculations until
            convergence is reached according to the criteria in 'status()'.
        """

        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 == "new_run":
                self.add_rundir()
                # if "n_images" in settings then image CONTCARs will be copied
                casm.vasp.continue_job(self.rundir[-2], self.rundir[-1],
                                       self.settings)
                shutil.copyfile(
                    os.path.join(self.calcdir, "INCAR.base"),
                    os.path.join(self.rundir[-1],
                                 "INCAR"))  ## should it be enforced??
            elif task == "constant":
                self.add_rundir()
                # if "n_images" in settings then image CONTCARs will be copied
                casm.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.calcdir, self.settings["final"]))):
                    new_values = io.Incar(
                        os.path.join(self.calcdir,
                                     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:  ## redundent
                self.add_rundir()
                casm.vasp.continue_job(self.rundir[-2], self.rundir[-1],
                                       self.settings)

            while True:
                # run vasp
                result = casm.vasp.run(self.rundir[-1],
                                       stdout="stdout",
                                       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"],
                                       is_neb=True)

                # 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()

            (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()
                casm.vasp.complete_job(self.finaldir, self.settings)

        return (status, task)