Exemplo n.º 1
0
def get_config_file(config_folder=".", queue_script="vaspjob.pbs"):
    """
    Get the file name of the config file in config_folder and its sub-folders

    Parameter
        config_folder: str (path like)
            The folder containing the config file or containing config file in its sub-folder
        queue_script: str (filename like)
            The filename of the queue script
    Return
        config_file: dict
            The dict of the filename(key) and corresponding path(value).
            If the config file is not in config_folder, store None.
            If more than one file (the same filename), it will store the uppest file [Ref. get_shortest_path]
    """
    config_file = {}
    required_file = ["db.json", "my_launchpad.yaml"]
    option_file = ["FW_config.yaml", "my_fworker.yaml", "my_qadapter.yaml", queue_script]
    files = required_file + option_file
    for file in files:
        file_list = recursive_glob(config_folder, file)
        if len(file_list) == 0:
            if file in required_file:
                raise FileNotFoundError("{} file is required for configuration of dfttk.".format(file))
            else:
                warnings.warn("{} file does not exist, the default setting will be used.".format(file))
                config_file[file] = None
        else:
            config_file[file] = get_abspath(get_shortest_path(file_list))
    return config_file
Exemplo n.º 2
0
 def __init__(self, **kwargs):
     super(ConfigTemplate, self).__init__()
     #The input should be a dict
     PATH_TO_STORE_CONFIG = kwargs.get("path_to_store_config", ".")
     PATH_TO_STORE_CONFIG = get_abspath(PATH_TO_STORE_CONFIG)
     self.PATH_TO_STORE_CONFIG = PATH_TO_STORE_CONFIG
     self.VASP_CMD = kwargs.get("vasp_cmd", "mpirun vasp_std")
     self.NNODES = kwargs.get("nodes", 1)
     self.PPNODE = kwargs.get("ppn", 24)
     self.WALLTIME = kwargs.get("walltime", "48:00:00")
     self.QUEUE = kwargs.get("queue", "open")
     self.PMEM = kwargs.get("pmem", "8gb")
     self.PRE_ROCKET = kwargs.get("pre_rocket",
                                  "module load intel impi vasp")
     self.POST_ROCKET = kwargs.get("post_rocket", "null")
Exemplo n.º 3
0
def handle_potcar_gz(psp_dir=None,
                     path_to_store_psp="psp_pymatgen",
                     aci=True,
                     vasp_cmd="vasp_std",
                     template="vaspjob.pbs",
                     queue_type="pbs"):
    """
    Compress and move the pseudopotential to a specified path(path_to_store_psp)
    (The compress is done by running "pmg config -p psp_dir path_to_store_psp" command)

    Parameter
        psp_dir: str (path-like)
            The origial path containing psp. Both original and uncompressed are ok.
            The name of the compressed file or the sub-folder containing psps must be in the following list
            ["potpaw_PBE", "POT_GGA_PAW_PBE","potpaw_PBE_52", "POT_GGA_PAW_PBE_52","potpaw_PBE_54", "POT_GGA_PAW_PBE_54",
             "potpaw_PBE.52", "POT_GGA_PAW_PBE_52","potpaw_PBE.54", "POT_GGA_PAW_PBE_54","potpaw_LDA", "POT_LDA_PAW",
             "potpaw_LDA.52", "POT_LDA_PAW_52","potpaw_LDA.54", "POT_LDA_PAW_54","potpaw_LDA_52", "POT_LDA_PAW_52",
             "potpaw_LDA_54", "POT_LDA_PAW_54","potUSPP_LDA", "POT_LDA_US","potpaw_GGA", "POT_GGA_PAW_PW91",
             "potUSPP_GGA", "POT_GGA_US_PW91"]
            For more details, Ref:https://pymatgen.org/installation.html#potcar-setup
            The example of the structure of the psp_dir:
            e.g. psp_dir
                 ├── potpaw_LDA.54.tar.gz
                 └── potpaw_PBE.54.tar.gz
              or: psp_dir
                  ├── potpaw_LDA_54
                  │   ├── Ac
                  │   ├── Ag
                  │   └── ...
                  ├── potpaw_PBE_54
                  │   ├── Ac
                  │   ├── Ag
                  │   └── ...
                  └── ...
        path_to_store_psp: str (path-like)
            The destination to store the compressed psp. Default: psp_pymatgen
    Return
        None
    """
    def copy_potcar(psp_dir,
                    psp_uncompress,
                    aci_name_map={"USPP_GAA": "POT_GGA_US_PW91"}):
        flag_copy = False
        for potcar_path in psp_dir:
            if not os.path.exists(potcar_path):
                continue
            file_str = os.listdir(potcar_path)
            for file_i in file_str:
                dst_path_name = parse_psp_name(file_i)
                if not (dst_path_name or file_i in aci_name_map):
                    continue
                if file_i in aci_name_map:
                    dst_path_name = aci_name_map[file_i]
                psp_old = os.path.join(potcar_path, file_i)
                psp_new = os.path.join(psp_uncompress, dst_path_name)
                if os.path.isdir(psp_old):
                    if os.path.exists(psp_new):
                        warnings.warn(
                            "Potential({}) exists, and current potential will over write it."
                            .format(psp_new))
                        shutil.rmtree(psp_new)
                    flag_copy = True
                    shutil.copytree(psp_old, psp_new)
                else:
                    creat_folders(psp_new)
                    if file_i.endswith(".tar.gz") or file_i.endswith(".tgz"):
                        os.system("tar -zxvf " + psp_old + " -C " + psp_new)
                        flag_copy = True
                    elif file_i.endswith(".tar"):
                        os.system("tar -xvf " + psp_old + " -C " + psp_new)
                        flag_copy = True
                    else:
                        warnings.warn(
                            "Current file ({}) is not supported. The pseudopotential should be uncompressed \
                            or compressed file endi with .tar.gz or .tgz or .tar"
                            .format(file_i))
        if not flag_copy:
            warnings.warn("No supported pseudopotential was found in : {}.".format(", ".join(psp_dir)) + \
                "The name rule ref. https://github.com/PhasesResearchLab/dfttk/blob/master/docs/Configuration.md")
        return flag_copy

    if not psp_dir:
        psp_dir = ["pp", "pps", "psp", "potential", "pseudopotential"]
    if isinstance(psp_dir, str):
        psp_dir = []

    aci_name_map = {"USPP_GAA": "POT_GGA_US_PW91"}  #A typo in ACI cluster
    psp_uncompress = get_abspath("./psp_uncompress")
    creat_folders(psp_uncompress)

    flag_aci = False
    if aci:
        #For ACI at PSU only
        aci_pp_path = find_psppath_in_cluster(vasp_cmd=vasp_cmd,
                                              psp_pathnames=psp_dir,
                                              template=template,
                                              queue_type=queue_type)
        flag_aci = copy_potcar(aci_pp_path,
                               psp_uncompress,
                               aci_name_map=aci_name_map)

    # file_str is not abspath, is relative path
    flag_user = copy_potcar(psp_dir, psp_uncompress, aci_name_map=aci_name_map)

    if not (flag_aci or flag_user):
        raise FileNotFoundError(
            "No pseudopotential was found, plese provide correct pseudopotential \
            and use -psp parameter to point to correct position")

    # config the POTCAR
    os.system("pmg config -p " + psp_uncompress + " " + path_to_store_psp)
    # Remove the uncompress folder
    try:
        shutil.rmtree(psp_uncompress)
    except:
        os.system("chmod +w " + os.path.join(psp_uncompress, "*/*"))
        shutil.rmtree(psp_uncompress)