Complete Authorization Form and Initialize Settings¶
This will also determine environment and set all environment variables. We determine if we are using Jupyter Notebooks or Google Colab to run this tutorial.
If you are running this notebook from Google Colab, Colab takes ~1 min to execute the following cell.
ACCOUNT_ID and AUTH_TOKEN - Authentication parameters needed for when making requests to Mat3ra.com's API Endpoints.
MATERIALS_PROJECT_API_KEY - Authentication parameter needed for when making requests to Material Project's API
ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/
NOTE: If you are running this notebook from Jupyter, the variables ACCOUNT_ID, AUTH_TOKEN, MATERIALS_PROJECT_API_KEY, and ORGANIZATION_ID should be set in the file settings.json if you need to use these variables. To obtain API token parameters, please see the following link to the documentation explaining how to get them: https://docs.mat3ra.com/accounts/ui/preferences/api/
# @title Authorization Form
ACCOUNT_ID = "ACCOUNT_ID" # @param {type:"string"}
AUTH_TOKEN = "AUTH_TOKEN" # @param {type:"string"}
MATERIALS_PROJECT_API_KEY = "MATERIALS_PROJECT_API_KEY" # @param {type:"string"}
ORGANIZATION_ID = "ORGANIZATION_ID" # @param {type:"string"}
import os
if "COLAB_JUPYTER_IP" in os.environ:
os.environ.update(
dict(
ACCOUNT_ID=ACCOUNT_ID,
AUTH_TOKEN=AUTH_TOKEN,
MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,
ORGANIZATION_ID=ORGANIZATION_ID,
)
)
!GIT_BRANCH="dev"; export GIT_BRANCH; export IS_USING_GIT_LFS=true; curl -s "https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh" | bash
from examples.utils.notebook import get_notebook_info
os.chdir(os.path.join("api-examples", os.path.dirname(get_notebook_info()["notebook_path"])))
Imports¶
from utils.settings import ENDPOINT_ARGS
from utils.generic import display_JSON
from exabyte_api_client.endpoints.materials import MaterialEndpoints
Set Parameters¶
- NAME: material name
- POSCAR_PATH: absolute path to the POSCAR file
NAME = "My Material"
POSCAR_PATH = "../assets/mp-978534.poscar"
Import material¶
Initialize MaterialEndpoints
class and call import_from_file
function to import the material.
content = ""
with open(POSCAR_PATH) as f:
content = f.read()
print(content)
endpoint = MaterialEndpoints(*ENDPOINT_ARGS)
material = endpoint.import_from_file(NAME, content)
mp-978534 1.0 3.940618000 0.000000000 0.000000000 -1.970309000 3.412675295 0.000000000 0.000000000 0.000000000 6.508731000 Ge Si 2 2 direct 0.000000000 0.000000000 0.000000000 Ge 0.333334000 0.666666000 0.500439000 Ge 0.000000000 0.000000000 0.374560000 Si 0.333334000 0.666666000 0.874561000 Si
Print imported material¶
Print the list of imported materials in pretty JSON below.
display_JSON(material)