Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
def config_atomate(path_to_store_config=".",
                   config_folder="config",
                   queue_script="vaspjob.pbs",
                   queue_type="pbs",
                   vasp_cmd_flag="vasp_std"):
    """
    Configuration for atomate

    Parameter
        path_to_store_config: str (path-like)
            The path to store the configuration files. Default: .
        config_folder: str (path-like)
            The path of config files. Default: config
        queue_script: str (filename-like)
            The submitting script for the queue system. Default: vaspjob.pbs
        queue_type: str
            Th type of queue system. Now, only support pbs. Default: pbs
        vasp_cmd_flag: str
            The flag of vasp_cmd to distinguish the vasp_cmd with other commands in the queue script
    Return
        None
    """
    config_file = get_config_file(config_folder=config_folder,
                                  queue_script=queue_script)

    creat_folders(path_to_store_config + "/config")
    creat_folders(path_to_store_config + "/logs")

    if config_file[queue_script]:
        #If the pbs file exists
        param_dict = parse_queue_script(template=config_file[queue_script],
                                        queue_type=queue_type,
                                        vasp_cmd_flag=vasp_cmd_flag)
    else:
        param_dict = {}
    param_dict["path_to_store_config"] = path_to_store_config

    required_file = ["db.json", "my_launchpad.yaml"]
    option_file = ["FW_config.yaml", "my_fworker.yaml", "my_qadapter.yaml"]
    FileModule = {
        "FW_config.yaml": "ConfigFW",
        "my_fworker.yaml": "ConfigFworker",
        "my_qadapter.yaml": "ConfigQadapter",
        "db.json": "ConfigDb",
        "my_launchpad.yaml": "ConfigLaunchFile"
    }
    files = required_file + option_file
    for file in files:
        if file in option_file:
            eval(FileModule[file] + "(**param_dict).write_file()")
        if config_file[file]:
            update_configfile(
                os.path.join(param_dict["path_to_store_config"],
                             "config/" + file), config_file[file])
    #Add environment var
    FW_CONFIG_FILE_VAL = os.path.join(path_to_store_config,
                                      "config/FW_config.yaml")
    add_path_var(force_override=True, FW_CONFIG_FILE=FW_CONFIG_FILE_VAL)
Ejemplo 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)