deepmodeling / abacus-develop

An electronic structure package based on either plane wave basis or numerical atomic orbitals.
http://abacus.ustc.edu.cn
GNU Lesser General Public License v3.0
163 stars 128 forks source link

[APNS] on the inclusion of pseudopotentials of Actinides: requires enhanced flexibility of file management #3882

Closed kirk0830 closed 5 months ago

kirk0830 commented 5 months ago

Background

Based on need of Actinides pseudopotential test, now APNS collects

We also have DIY pseudopotentials for extreme high pressure condition generated by @Chentao168 . Other users and developers are encouraged to suggest pseudopotential suites to test.

Describe the solution you'd like

Now APNS will let user define regular expression to distinguish pseudopotentials like:

{
    "rules": [
        {
            "kind": "sg15",
            "version": "1.0",
            "appendix": "",
            "re.folder": "sg15_oncv_upf_2020-02-06",
            "re.file": "^([A-Z][a-z]?)(_ONCV_PBE\\-1\\.0\\.upf)$"
        },
        {
            "kind": "sg15",
            "version": "1.0",
            "appendix": "fr",
            "re.folder": "sg15_oncv_upf_2020-02-06",
            "re.file": "^([A-Z][a-z]?)(_ONCV_PBE_FR\\-1\\.0\\.upf)$"
        },

in a file named as rules.json in ./download/pseudopotentials/ folder. Then a simple function can manage all pseudopotential files, like:

def load(pseudo_dir: str):

    if not os.path.exists(pseudo_dir):
        raise FileNotFoundError(f"Directory {pseudo_dir} does not exist")
    if not os.path.exists(os.path.join(pseudo_dir, "rules.json")):
        raise FileNotFoundError(f"File rules.json does not exist in {pseudo_dir}")

    with open(os.path.join(pseudo_dir, "rules.json")) as f:
        rules = json.load(f)

    pseudo_db = {}
    for root, dirs, files in os.walk(pseudo_dir):
        for file in files:
            if file.endswith(".upf") or file.endswith(".UPF"):
                folder = root.replace("\\", "/").split("/")[-1]
                for i in range(len(rules["rules"])):
                    match_file = re.match(rules["rules"][i]["re.file"], file)
                    match_folder = re.match(rules["rules"][i]["re.folder"], folder)
                    if match_file and match_folder:
                        element = match_file.group(1).capitalize()
                        id = amwi.pseudopotential(kind=rules["rules"][i]["kind"], 
                                                  version=rules["rules"][i]["version"], 
                                                  appendix=rules["rules"][i]["appendix"])
                        pseudo_db.setdefault(element, {})[id] = os.path.join(root, file)
                        break
                if match_file is None or match_folder is None:
                    raise ValueError(f"No rule found for file: {file} in folder: {folder}")

    with open(os.path.join(pseudo_dir, "pseudo_db.json"), "w") as f:
        json.dump(pseudo_db, f, indent=4)

    return pseudo_db

The content of pseudo_db would be like:

{
    "Ag": {
        "gbrv_1.5": "./download/pseudopotentials/GBRV_pbe_UPF_v1.5\\ag_pbe_v1.4.uspp.F.UPF",
        "hgh_1.0_d": "./download/pseudopotentials/hgh\\d\\Ag.pbe-d-hgh.UPF",
        "dojo_0.4_fr": "./download/pseudopotentials/nc-fr-04_pbe_standard\\Ag.upf",
        "dojo_0.4_sr": "./download/pseudopotentials/nc-sr-04_pbe_standard_upf\\Ag.upf",
        "dojo_0.5_sr": "./download/pseudopotentials/nc-sr-05_pbe_standard_upf\\Ag.upf",
        "pd_03": "./download/pseudopotentials/NCPP-PD03-PBE\\Ag.PD03.PBE.UPF",
        "pd_04_sp": "./download/pseudopotentials/NCPP-PD04-PBE\\Ag-sp.PD04.PBE.UPF",
        "dojo_0.3_sr": "./download/pseudopotentials/pbe_s_sr\\Ag.upf",
        "pslkjpaw_0.3.1": "./download/pseudopotentials/pslibrary-pbe.0.3.1\\PSEUDOPOTENTIALS_ALT\\Ag.pbe-spn-kjpaw_psl.0.3.1.UPF",
        "pslrrkjus_0.3.1": "./download/pseudopotentials/pslibrary-pbe.0.3.1\\PSEUDOPOTENTIALS_ALT\\Ag.pbe-spn-rrkjus_psl.0.3.1.UPF",
        "pslnc_0.3.1": "./download/pseudopotentials/pslibrary-pbe.0.3.1\\PSEUDOPOTENTIALS_NC\\Ag.pbe-n-nc.UPF",
        "sg15_1.0": "./download/pseudopotentials/sg15_oncv_upf_2020-02-06\\Ag_ONCV_PBE-1.0.upf",
        "sg15_1.2": "./download/pseudopotentials/sg15_oncv_upf_2020-02-06\\Ag_ONCV_PBE-1.2.upf",
        "sg15_1.0_fr": "./download/pseudopotentials/sg15_oncv_upf_2020-02-06\\Ag_ONCV_PBE_FR-1.0.upf"
    },
    "Al": {
        "gbrv_1.5": "./download/pseudopotentials/GBRV_pbe_UPF_v1.5\\al_pbe_v1.uspp.F.UPF",
        "hgh_1.0": "./download/pseudopotentials/hgh\\standard\\Al.pbe-hgh.UPF",
        "dojo_0.4_fr": "./download/pseudopotentials/nc-fr-04_pbe_standard\\Al.upf",
        "dojo_0.4_sr": "./download/pseudopotentials/nc-sr-04_pbe_standard_upf\\Al.upf",
        "dojo_0.5_sr": "./download/pseudopotentials/nc-sr-05_pbe_standard_upf\\Al.upf",
        "pd_03": "./download/pseudopotentials/NCPP-PD03-PBE\\Al.PD03.PBE.UPF",
        "pd_04_sp": "./download/pseudopotentials/NCPP-PD04-PBE\\Al-sp.PD04.PBE.UPF",
        "pd_04": "./download/pseudopotentials/NCPP-PD04-PBE\\Al.PD04.PBE.UPF",
        "dojo_0.3_sr": "./download/pseudopotentials/pbe_s_sr\\Al.upf",
        "pslkjpaw_0.3.1": "./download/pseudopotentials/pslibrary-pbe.0.3.1\\PSEUDOPOTENTIALS\\Al.pbe-n-kjpaw_psl.0.1.UPF",
        "pslrrkjus_0.3.1": "./download/pseudopotentials/pslibrary-pbe.0.3.1\\PSEUDOPOTENTIALS\\Al.pbe-n-rrkjus_psl.0.1.UPF",
        "pslnc_0.3.1": "./download/pseudopotentials/pslibrary-pbe.0.3.1\\PSEUDOPOTENTIALS_NC\\Al.pbe-n-nc.UPF",
        "sg15_1.0": "./download/pseudopotentials/sg15_oncv_upf_2020-02-06\\Al_ONCV_PBE-1.0.upf",
        "sg15_1.2": "./download/pseudopotentials/sg15_oncv_upf_2020-02-06\\Al_ONCV_PBE-1.2.upf",
        "sg15_1.0_fr": "./download/pseudopotentials/sg15_oncv_upf_2020-02-06\\Al_ONCV_PBE_FR-1.0.upf"
    },

Task list only for developers

Notice Possible Changes of Behavior (Reminder only for developers)

No response

Notice any changes of core modules (Reminder only for developers)

No response

Notice Possible Changes of Core Modules (Reminder only for developers)

No response

Additional Context

No response

Task list for Issue attackers (only for developers)

kirk0830 commented 5 months ago

Merged: https://github.com/kirk0830/ABACUS-Pseudopot-Nao-Square/pull/48