Ejemplo n.º 1
0
    def setup(self):
        """
        Performs initial setup for VaspJob, including overriding any settings
        and backing up.
        """
        decompress_dir('.')

        if self.backup:
            for f in VASP_INPUT_FILES:
                shutil.copy(f, "{}.orig".format(f))

        if self.auto_npar:
            try:
                incar = Incar.from_file("INCAR")
                # Only optimized NPAR for non-HF and non-RPA calculations.
                if not (incar.get("LHFCALC") or incar.get("LRPA") or
                        incar.get("LEPSILON")):
                    if incar.get("IBRION") in [5, 6, 7, 8]:
                        # NPAR should not be set for Hessian matrix
                        # calculations, whether in DFPT or otherwise.
                        del incar["NPAR"]
                    else:
                        import multiprocessing
                        # try sge environment variable first
                        # (since multiprocessing counts cores on the current
                        # machine only)
                        ncores = os.environ.get('NSLOTS') or \
                            multiprocessing.cpu_count()
                        ncores = int(ncores)
                        for npar in range(int(math.sqrt(ncores)),
                                          ncores):
                            if ncores % npar == 0:
                                incar["NPAR"] = npar
                                break
                    incar.write_file("INCAR")
            except:
                pass

        if self.auto_continue:
            if os.path.exists("continue.json"):
                actions = loadfn("continue.json").get("actions")
                logger.info("Continuing previous VaspJob. Actions: {}".format(actions))
                backup(VASP_BACKUP_FILES, prefix="prev_run")
                VaspModder().apply_actions(actions)

            else:
                # Default functionality is to copy CONTCAR to POSCAR and set
                # ISTART to 1 in the INCAR, but other actions can be specified
                if self.auto_continue is True:
                    actions = [{"file": "CONTCAR",
                                "action": {"_file_copy": {"dest": "POSCAR"}}},
                               {"dict": "INCAR",
                                "action": {"_set": {"ISTART": 1}}}]
                else:
                    actions = self.auto_continue
                dumpfn({"actions": actions}, "continue.json")

        if self.settings_override is not None:
            VaspModder().apply_actions(self.settings_override)
Ejemplo n.º 2
0
    def setup(self):
        """
        Performs initial setup for VaspJob, including overriding any settings
        and backing up.
        """
        decompress_dir('.')

        if self.backup:
            for f in VASP_INPUT_FILES:
                shutil.copy(f, "{}.orig".format(f))

        if self.auto_npar:
            try:
                incar = Incar.from_file("INCAR")
                # Only optimized NPAR for non-HF and non-RPA calculations.
                if not (incar.get("LHFCALC") or incar.get("LRPA") or
                        incar.get("LEPSILON")):
                    if incar.get("IBRION") in [5, 6, 7, 8]:
                        # NPAR should not be set for Hessian matrix
                        # calculations, whether in DFPT or otherwise.
                        del incar["NPAR"]
                    else:
                        import multiprocessing
                        # try sge environment variable first
                        # (since multiprocessing counts cores on the current
                        # machine only)
                        ncores = os.environ.get('NSLOTS') or \
                            multiprocessing.cpu_count()
                        ncores = int(ncores)
                        for npar in range(int(math.sqrt(ncores)),
                                          ncores):
                            if ncores % npar == 0:
                                incar["NPAR"] = npar
                                break
                    incar.write_file("INCAR")
            except:
                pass

        if self.auto_continue:
            if os.path.exists("continue.json"):
                actions = loadfn("continue.json").get("actions")
                logger.info("Continuing previous VaspJob. Actions: {}".format(actions))
                backup(VASP_BACKUP_FILES, prefix="prev_run")
                VaspModder().apply_actions(actions)

            else:
                # Default functionality is to copy CONTCAR to POSCAR and set
                # ISTART to 1 in the INCAR, but other actions can be specified
                if self.auto_continue is True:
                    actions = [{"file": "CONTCAR",
                                "action": {"_file_copy": {"dest": "POSCAR"}}},
                               {"dict": "INCAR",
                                "action": {"_set": {"ISTART": 1}}}]
                else:
                    actions = self.auto_continue
                dumpfn({"actions": actions}, "continue.json")

        if self.settings_override is not None:
            VaspModder().apply_actions(self.settings_override)
Ejemplo n.º 3
0
 def run_task(self, fw_spec):
     ignore_errors = self.get("ignore_errors", False)
     dest = self.get("dest", os.getcwd())
     try:
         decompress_dir(dest)
     except:
         if not ignore_errors:
             raise ValueError("There was an error performing decompression in %s." % dest)
Ejemplo n.º 4
0
 def run_task(self, fw_spec):
     ignore_errors = self.get('ignore_errors', False)
     dest = self.get("dest", os.getcwd())
     try:
         decompress_dir(dest)
     except:
         if not ignore_errors:
             raise ValueError(
                 "There was an error performing decompression in %s." % dest)
Ejemplo n.º 5
0
    def setup(self):
        """
        Performs initial setup for AimsJob, including overriding any settings
        and backing up.
        """
        decompress_dir('.')
        actions = []

        if self.backup:
            for f in AIMS_INPUT_FILES:
                shutil.copy(f, "{}.orig".format(f))

        return actions
Ejemplo n.º 6
0
    def setup(self):
        """
        Performs initial setup for FeffJob, do backing up.
        Returns:

        """
        decompress_dir('.')

        if self.backup:
            for f in FEFF_INPUT_FILES:
                shutil.copy(f, "{}.orig".format(f))

            for f in FEFF_BACKUP_FILES:
                if os.path.isfile(f):
                    shutil.copy(f, "{}.orig".format(f))
Ejemplo n.º 7
0
    def test_recursive_copy_and_compress(self):
        copy_r(os.path.join(test_dir, "cpr_src"), os.path.join(test_dir, "cpr_dst"))
        self.assertTrue(os.path.exists(os.path.join(test_dir, "cpr_dst", "test")))
        self.assertTrue(os.path.exists(os.path.join(test_dir, "cpr_dst", "sub", "testr")))

        compress_dir(os.path.join(test_dir, "cpr_src"))
        self.assertTrue(os.path.exists(os.path.join(test_dir, "cpr_src", "test.gz")))
        self.assertTrue(os.path.exists(os.path.join(test_dir, "cpr_src", "sub", "testr.gz")))

        decompress_dir(os.path.join(test_dir, "cpr_src"))
        self.assertTrue(os.path.exists(os.path.join(test_dir, "cpr_src", "test")))
        self.assertTrue(os.path.exists(os.path.join(test_dir, "cpr_src", "sub", "testr")))
        with open(os.path.join(test_dir, "cpr_src", "test")) as f:
            txt = f.read()
            self.assertEqual(txt, "what")
Ejemplo n.º 8
0
    def setup(self):
        """
        Performs initial setup for FeffJob, do backing up.
        Returns:

        """
        decompress_dir('.')

        if self.backup:
            for f in FEFF_INPUT_FILES:
                shutil.copy(f, "{}.orig".format(f))

            for f in FEFF_BACKUP_FILES:
                if os.path.isfile(f):
                    shutil.copy(f, "{}.orig".format(f))
Ejemplo n.º 9
0
    def _setup_file_for_parsing(self, path):
        #make a "kyle_file" for parsing out relevant data
        #returns True if file setup correctly
        files_to_copy = [
            'CONTCAR', 'OUTCAR', 'POTCAR', 'WAVECAR', 'vasprun.xml'
        ]

        kyle_path = os.path.join(path, 'kyle_file')
        if os.path.exists(kyle_path):
            print('KYLE FILE ALREADY! Removing and rebuilding...')
            rmtree(kyle_path)

        #make kyle file
        os.makedirs(kyle_path)

        #copy relevant files to kyle path
        for file in files_to_copy:
            filepat = os.path.join(path, file + '.relax2.gz')
            if not os.path.exists(filepat):
                filepat = os.path.join(path, file + '.relax1.gz')
            if not os.path.exists(filepat):
                filepat = os.path.join(path, file + '.gz')
            if not os.path.exists(filepat):
                filepat = os.path.join(path, file)
            if not os.path.exists(filepat):
                print(
                    'Could not find {}! Skipping this defect...'.format(file))
                return False

            #COPY file to kyle_file
            if '.gz' in filepat:
                shutil.copy(filepat, os.path.join(kyle_path, file + '.gz'))
            else:
                shutil.copy(filepat, os.path.join(kyle_path, file))

        decompress_dir(kyle_path)
        return True
Ejemplo n.º 10
0
    def _setup_file_for_parsing(self, path):
        # make a "kyle_file" for parsing out relevant data
        # returns True if file setup correctly
        files_to_copy = [
            "CONTCAR", "OUTCAR", "POTCAR", "WAVECAR", "vasprun.xml"
        ]

        kyle_path = os.path.join(path, "kyle_file")
        if os.path.exists(kyle_path):
            print("KYLE FILE ALREADY! Removing and rebuilding...")
            rmtree(kyle_path)

        # make kyle file
        os.makedirs(kyle_path)

        # copy relevant files to kyle path
        for file in files_to_copy:
            filepat = os.path.join(path, file + ".relax2.gz")
            if not os.path.exists(filepat):
                filepat = os.path.join(path, file + ".relax1.gz")
            if not os.path.exists(filepat):
                filepat = os.path.join(path, file + ".gz")
            if not os.path.exists(filepat):
                filepat = os.path.join(path, file)
            if not os.path.exists(filepat):
                print(f"Could not find {file}! Skipping this defect...")
                return False

            # COPY file to kyle_file
            if ".gz" in filepat:
                shutil.copy(filepat, os.path.join(kyle_path, file + ".gz"))
            else:
                shutil.copy(filepat, os.path.join(kyle_path, file))

        decompress_dir(kyle_path)
        return True
Ejemplo n.º 11
0
    def test_recursive_copy_and_compress(self):
        copy_r(os.path.join(test_dir, "cpr_src"),
               os.path.join(test_dir, "cpr_dst"))
        self.assertTrue(
            os.path.exists(os.path.join(test_dir, "cpr_dst", "test")))
        self.assertTrue(
            os.path.exists(os.path.join(test_dir, "cpr_dst", "sub", "testr")))

        compress_dir(os.path.join(test_dir, "cpr_src"))
        self.assertTrue(
            os.path.exists(os.path.join(test_dir, "cpr_src", "test.gz")))
        self.assertTrue(
            os.path.exists(os.path.join(test_dir, "cpr_src", "sub",
                                        "testr.gz")))

        decompress_dir(os.path.join(test_dir, "cpr_src"))
        self.assertTrue(
            os.path.exists(os.path.join(test_dir, "cpr_src", "test")))
        self.assertTrue(
            os.path.exists(os.path.join(test_dir, "cpr_src", "sub",
                                        "testr")))
        with open(os.path.join(test_dir, "cpr_src", "test")) as f:
            txt = f.read()
            self.assertEqual(txt, "what")
Ejemplo n.º 12
0
 def test_compress_dir(self):
     c = CompressDirTask(compression="gz")
     c.run_task({})
     self.assertTrue(os.path.exists("delete.yaml.gz"))
     self.assertFalse(os.path.exists("delete.yaml"))
     decompress_dir(".")
Ejemplo n.º 13
0
 def test_compress_dir(self):
     c = CompressDirTask(compression="gz")
     c.run_task({})
     self.assertTrue(os.path.exists("delete.yaml.gz"))
     self.assertFalse(os.path.exists("delete.yaml"))
     decompress_dir(".")