Skip to content

Commit

Permalink
add auph3 notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jan 27, 2022
1 parent 2bd663f commit 57819c3
Showing 1 changed file with 164 additions and 0 deletions.
164 changes: 164 additions & 0 deletions mpcontribs-portal/notebooks/contribs.materialsproject.org/auph3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "naughty-saver",
"metadata": {},
"outputs": [],
"source": [
"from mpcontribs.client import Client\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "separated-foster",
"metadata": {},
"outputs": [],
"source": [
"client = Client(project=\"auph3\") # set MPCONTRIBS_API_KEY env var"
]
},
{
"cell_type": "markdown",
"id": "disabled-footwear",
"metadata": {},
"source": [
"### update and retrieve project info"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "chinese-disposition",
"metadata": {},
"outputs": [],
"source": [
"# see docstrings for details on client functions\n",
"# client.projects.update_entry(\n",
"# # `project` contains dictionary with fields to be updated\n",
"# pk=\"auph3\", project={\"long_title\": \"new long title\"}\n",
"# ).result()\n",
"client.get_project() # client initialized for project, so no argument needed"
]
},
{
"cell_type": "markdown",
"id": "improved-lawrence",
"metadata": {},
"source": [
"### prep contributions"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "effective-thought",
"metadata": {},
"outputs": [],
"source": [
"contributions = []\n",
"xyz_paths = # TODO iterator over xyz paths\n",
"\n",
"for path in xyz_paths:\n",
" # TODO extract unique_id, formula, size, ligands, energy from path or file contents\n",
" contrib = {\n",
" \"identifier\": unique_id,\n",
" \"formula\": formula,\n",
" \"data\": {\n",
" \"size\": size,\n",
" \"ligands\": ligands,\n",
" \"energy\": f'{energy} eV'\n",
" },\n",
" \"attachments\": [Path(path)]\n",
" }\n",
" contributions.append(contrib)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ordinary-ground",
"metadata": {},
"outputs": [],
"source": [
"len(contributions)"
]
},
{
"cell_type": "markdown",
"id": "domestic-monaco",
"metadata": {},
"source": [
"### initialize columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "steady-company",
"metadata": {},
"outputs": [],
"source": [
"columns = {\n",
" \"size\": \"\",\n",
" \"ligands\": \"\",\n",
" \"energy\": \"eV\",\n",
" \"attachments\": None\n",
"}\n",
"client.init_columns(columns)"
]
},
{
"cell_type": "markdown",
"id": "peaceful-burden",
"metadata": {},
"source": [
"### submit/delete contributions"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "convinced-reference",
"metadata": {},
"outputs": [],
"source": [
"client.submit_contributions(contributions[:10], ignore_dupes=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "seven-translator",
"metadata": {},
"outputs": [],
"source": [
"client.delete_contributions() # add query to only delete subset of contributions matching query"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 57819c3

Please sign in to comment.