Skip to content

Conversation

@srmnitc
Copy link
Member

@srmnitc srmnitc commented Oct 13, 2025

This pull request introduces support for fetching crystal structures directly from the Materials Project database using their API. The main changes include a new MaterialsProject configuration class, integration of structure fetching via the Materials Project API in the input validation workflow, and an example YAML demonstrating usage. These changes make it easier to run calculations using Materials Project structures by specifying a material ID and API key.

Materials Project integration:

  • Added a new MaterialsProject class to calphy/input.py to handle API key, structure type (conventional or primitive), and target atom count. Includes validation to resolve the API key from an environment variable and provide user-friendly error messages if missing.
  • Integrated Materials Project structure fetching into the _validate_all method of calphy/input.py. If the lattice string starts with mp-, the code fetches the structure using the provided API key, repeats it to reach the target atom count, and sets up the calculation accordingly. Includes error handling for missing API key and missing mp_api package.

Configuration and usage:

  • Added an optional materials_project field to the main Calculation class, allowing users to specify Materials Project options in their input files.
  • Provided an example YAML input file (examples/example_01/input-mp.yaml) demonstrating how to set up a calculation using a Materials Project structure, including how to specify the API key and related options.

closes #188

@srmnitc srmnitc merged commit 602080e into main Oct 13, 2025
3 checks passed
@srmnitc srmnitc deleted the fetch_mp branch October 13, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pull structures directly from materials project

2 participants