<jupyter_start><jupyter_text>Move Ion Reference data into an MPContribs Project --- Header  Imports<jupyter_code>from pprint import pprint
from monty.serialization import loadfn, dumpfn
from pymatgen.core.ion import Ion<jupyter_output><empty_output><jupyter_text>--- Main Code  Load the ion reference data from the .json file and examine its format`aqeuous_ions.json` can be downloaded from https://github.com/materialsproject/pymatpro/blob/master/pymatpro/pourbaix_tools/aqueous_ions.json<jupyter_code>ion_ref_data = loadfn("aqueous_ions.json")
# NOTE: all energy units are eV/formula unit
ion_ref_data[0]<jupyter_output><empty_output><jupyter_text>Path one entry according to `patch_aqueous_ions.json` on pymatprohttps://github.com/materialsproject/pymatpro/blob/master/pymatpro/pourbaix_tools/patch_aqueous_ions.json<jupyter_code>for i, e in enumerate(ion_ref_data):
    if e["Name"] == "HGaO2[2-]":
        ion_ref_data[i] = {
            "Energy": -7.1099,
            "Major_Elements": [
                "Ga"
            ],
            "Name": "HGaO3[2-]",
            "Reference Solid": "Ga2O3",
            "Reference solid energy": -10.347724703224722,
            "Source": "<NAME> et al., Selected values for inorganic and C1 and C2 Organic substances in SI units, The NBS table of chemical thermodynamic properties, Washington (1982)"
        }
        print("Replaced entry at index {}".format(i))
ion_ref_data[121]<jupyter_output><empty_output><jupyter_text>Initialize the MPContribs client<jupyter_code>from mpcontribs.client import Client
name = 'ion_ref_data' # this should be your project, see from the project URL
client = Client()<jupyter_output><empty_output><jupyter_text>Reshape the data<jupyter_code>ion_contribs =[]

for d in ion_ref_data:
    ret = {}
    ret["project"] = name
    ret["is_public"] = True
    ret["identifier"] = d["Name"]
    ret["data"] = {}
    ret["data"]["charge"] = Ion.from_formula(d["Name"]).charge
    ret["data"]["ΔGᶠ"] = "{:.5g} kJ/mol".format(d["Energy"]*96.485) # convert from eV/f.u. to kJ/mol
    ret["data"]["MajElements"] = d["Major_Elements"][0]
    ret["data"]["RefSolid"] = d["Reference Solid"]
    ret["data"]["ΔGᶠRefSolid"] = "{:.4g} kJ/mol".format(d["Reference solid energy"]*96.485)# convert from eV/f.u. to kJ/mol
    ret["data"]["reference"] = d["Source"]
    
    ion_contribs.append(ret)
# did we miss any data?
len(ion_ref_data) - len(ion_contribs)
pprint(ion_contribs[30])<jupyter_output><empty_output><jupyter_text>Update project references, column descriptions, etc.<jupyter_code>client.projects.update_entry(
    pk="ion_ref_data", project={"other": 
                                         {"formula": "Chemical formula of the aqueous species",
                                          "charge": "Charge on the aqueous species",
                                          "ΔGᶠ": "Gibbs free energy of formation of the aqueous species from the elements",
                                          "MajElementsᶠ": None,
                                          "MajElements": "Elements contained in the aqueous species",
                                         "RefSolid": "Solid compound to which the aqueous species energy is referenced",
                                          "ΔGᶠRefSolid": "Gibbs free energy of formation of the reference solid compound",
                                          "Ion": None
                                         },
                                "description": "This project contains experimental ion dissolution energies that are used by pymatgen when constructing Pourbaix diagrams. See the Persson2012 reference for a detailed description of the thermodynamic framework used."
                                        }
).result()
client.projects.update_entry(
    pk="ion_ref_data", project={"authors": "Various authors (see references). Data compiled by the Materials Project team."
                                        }
).result()
client.projects.update_entry(
    pk="ion_ref_data", project={"title": "Aqueous Ion Reference Data"
                                        }
).result()
client.projects.update_entry(
    pk="ion_ref_data", project={"references": [
        {"label":"Persson2012", 'url':"https://doi.org/10.1103/PhysRevB.85.235438"},
        {'label': 'NBS1', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-1.pdf'},
    {'label': 'NBS2', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-2.pdf'},
    {'label': 'NBS3', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-3.pdf'},
    {'label': 'NBS4', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-4.pdf'},
    {'label': 'NBS5', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-5.pdf'},
    {'label': 'NBS6', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-6.pdf'},
    {'label': 'NBS7', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-7.pdf'},
    {'label': 'NBS8', 'url': 'https://nvlpubs.nist.gov/nistpubs/Legacy/TN/nbstechnicalnote270-8.pdf'},
    {"label":"Pourbaix", 'url':"https://www.worldcat.org/title/atlas-of-electrochemical-equilibria-in-aqueous-solutions/oclc/563921897"}]
                                        }
).result()<jupyter_output><empty_output><jupyter_text>Check the project<jupyter_code>client.get_project(name)<jupyter_output><empty_output><jupyter_text>Submit to MPContribs<jupyter_code># need to delete contributions first due to unique_identifiers=False
client.delete_contributions(name)
client.submit_contributions(ion_contribs, per_page=10, skip_dupe_check=True)
#client.contributions.create_entries(contributions=ion_contribs[0:100]).result()<jupyter_output><empty_output><jupyter_text>Appendix----<jupyter_code>break<jupyter_output><empty_output><jupyter_text>Note that `Ion.reduced_formula` generates the same formula for a few distinct entries in the database, e.g. "Fe2(OH)2[4+]" vs. "FeOH[2+]"<jupyter_code>[e["Name"] for e in ion_ref_data if "Fe" in e["Name"]]
[Ion.from_formula(e["Name"]).reduced_formula for e in ion_ref_data if "Fe" in e["Name"]]
[e for e in ion_ref_data if e["Name"] == "Fe2(OH)2[4+]"]
[e for e in ion_ref_data if e["Name"] == "FeOH[2+]"]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1397456279809221, 'fraction_numerical': 0.021939586645468998, 'mean_word_length': 3.3030095759233924, 'pattern_counts': {'":': 22, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 12, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '245156', 'license': 'MIT', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2035, 'n_words': 409, 'path': 'mpcontribs-portal/notebooks/contribs.materialsproject.org/ion_ref_data.ipynb', 'repo_name': 'rkingsbury/MPContribs', 'size': '6296'}