Skip to main content

Mat3ra API Examples

Project description

Mat3ra API Examples

Contents of this Repository

Below, we list the contents of this repository, in roughly the order that a user might want to go through it in order to learn how our API works.

Folder Notebook Description
Examples/System Get Authentication Params Demonstrates how to programatically find your user ID and access token.
Examples/Workflow Get Workflows Walks through how to query the Mat3ra API to programatically search for workflows. In this example, we search for workflows that calculate the total energy of a material.
Examples/Workflow Quantum Espresso Workflow and Job Create Quantum Espresso workflow starting from QE input file; create and submit job; after the job is finished, download output file, and finally perform postprocessing analysis.
Examples/Material Get Materials by Formula Shows how queries can be made to search for materials stored on your account by their formula. In this example, we search for a system containing Si.
Examples/Material Create Material Gives an overview of how materials can be generated in JSON format and uploaded to your user account. In this example, we create an FCC Si crystal and upload it.
Examples/Material Import Materials from Materials Project Demonstrates how materials can be imported from Materials Project, if their Materials Project ID is known. In this example, we import monoclinic and hexagonal SiGe cells.
Examples/Material Import Materials from Poscar Provides an example of how materials can be imported directly from Poscar files (a common chemical file format best-known for its use in VASP). In this example, we import the unit cell of SiGe.
Examples/Job Create and Submit Job Shows how to use the Mat3ra API to create jobs and run them on our cluster. In this example, we run a DFT calculation to get the total energy of an FCC Si unit cell using Quantum Espresso.
Examples/Job Get File from Job Uses the Mat3ra API to query for a list of files produced by a job, describes the metadata assigned to each file, and ends by demonstrating how to download any remote file generated by a job to the local disk.
Examples/Job Run Simulations and Extract Properties Demonstrates copying a bank workflow to an account and using it to calculate the properties of multiple materials. In this example, we determine the band gap of Si and Ge.
Examples/Job ML - Train Model Predict Properties Demonstrates the generation of a training dataset and subsequent training of a machine learning model. In this example, we calculate the band gaps of Si and SiGe, and using various materials properties as descriptors, train a model to predict their band gaps. Finally, we use this trained model to predict the band gap of Ge.

Setup

NOTE: tested with Python version 3.8 and 3.10, please assert that the virtual environment is created with it. Use pyenv to manage Python versions.

Follow the steps below in order to setup and view the Jupyter notebooks:

  1. Install git-lfs [3] in order to get access to the source code and notebook files.

  2. Clone repository:

    git clone https://github.com/Exabyte-io/api-examples.git
    

    Or, if you have set up SSH keys

    git clone git@github.com:Exabyte-io/api-examples.git
    

    In case for some reason git-lfs was not installed at the time of cloning, the files can be pulled after installing git-lfs, through git lfs pull.

    Related to this, please be aware that as the .ipynb and .poscar files are stored on git-lfs, they are not part of the zip archive downloaded through GitHub's web interface.

  3. Install virtualenv using pip if not already present:

    pip install virtualenv
    
  4. Create virtual environment and install required packages:

    cd api-examples
    virtualenv .env
    source .env/bin/activate
    pip install -e ."[localhost]"
    
  5. Run Jupyter and open a notebook in a browser. In order for the post-save hook feature to work properly, one must launch their Jupyter Notebook environment in the folder that contains the file config.py, which is the examples folder shown below:

    cd examples
    jupyter lab --config=config.py
    

Usage

In order to run or edit the examples:

  1. Assert an existing Mat3ra.com account. Examples require an account to run. New users can register here to obtain one.

  2. Open settings and adjust it to provide the API authentication parameters. See the corresponding example to learn how to obtain the authentication parameters. It is also possible to generate an API token by logging in to Mat3ra platform, navigating to the Account Preferences, and clicking the 'Generate new token' button under API Tokens. More details can be found here.

  3. Open the desired example notebook, adjust it as necessary and run. One can speed up the notebooks execution after running the Get Authentication Params one by reusing the kernel from the first notebook.

NOTE: The Materials Project API key should be obtained from https://legacy.materialsproject.org/open.

Contribute

This is an open-source repository and we welcome contributions for other use cases. The original set of examples is only meant to demonstrate the capabilities and can be extended.

We suggest forking this repository and introducing the adjustments there. The changes in the fork can further be considered for merging into this repository as it is commonly used on GitHub. This process is explained in more details elsewhere online [4].

If you would like to add new examples or adjust existing ones, please consider the following:

  1. Put examples into the corresponding directories by domain.

  2. Walk the readers through the examples by providing step-by-step explanation similar to this example.

  3. We use post-save hooks to automatically convert notebooks to python scripts. See config file for more information. In order to facilitate code review, we exclude notebook sources in the other/ directory from version control and store them in Git LFS [3]. Please follow this convention.

  4. Apply code formatting by installing development requirements as follows:

    pip install -e ."[dev]"
    pre-commit install
    pre-commit run --all-files
    

    Check more details about pre-commit here.

Links

  1. Mat3ra.com RESTful API, description in the online documentation: link
  2. Jupyter.org, official website: link
  3. Git Large File Storage, official website: link
  4. GitHub Standard Fork & Pull Request Workflow, online explanation: link

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mat3ra_api_examples-2024.10.19.post0.tar.gz (10.4 MB view details)

Uploaded Source

Built Distribution

File details

Details for the file mat3ra_api_examples-2024.10.19.post0.tar.gz.

File metadata

  • Download URL: mat3ra_api_examples-2024.10.19.post0.tar.gz
  • Upload date:
  • Size: 10.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/8.5.0 pkginfo/1.11.2 requests/2.32.3 requests-toolbelt/1.0.0 tqdm/4.66.5 CPython/3.8.18

File hashes

Hashes for mat3ra_api_examples-2024.10.19.post0.tar.gz
Algorithm Hash digest
SHA256 136c03d76d9a099a2ca67850eaa30ee1039e49ce3211555f01fbd9f9c16be73e
MD5 50f56491caf7b0be269330bc34730d36
BLAKE2b-256 c60a1f8fc3d241f73ad1afa4b9ea4116dbd78023df19e3ce52256d9e773dedc3

See more details on using hashes here.

File details

Details for the file mat3ra_api_examples-2024.10.19.post0-py3-none-any.whl.

File metadata

  • Download URL: mat3ra_api_examples-2024.10.19.post0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/8.5.0 pkginfo/1.11.2 requests/2.32.3 requests-toolbelt/1.0.0 tqdm/4.66.5 CPython/3.8.18

File hashes

Hashes for mat3ra_api_examples-2024.10.19.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 26d158d035c21db02a1b1a9fdc7ee25ff1a13dd2ff1bf6f900ef42b28f9d35a0
MD5 3a30e747b6f5c3063a0d72c670c1efbf
BLAKE2b-256 923ebd67be0c65d76111132231bc489e41b84d8c2915d66ffcf8ca4bdc4e9068

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page