mp_api.client.routes.materials.phonon.PhononRester¶
- class mp_api.client.routes.materials.phonon.PhononRester(api_key: str | None = None, endpoint: str | None = None, include_user_agent: bool = True, use_document_model: bool = True, session: requests.Session | None = None, headers: dict | None = None, mute_progress_bars: bool = False, db_version: str | None = None, local_dataset_cache: str | os.PathLike = PosixPath('/home/runner/mp_datasets'), force_renew: bool = False, query_builder: QueryBuilderWithCache | None = None, delta_catalog: DeltaCatalog | None = None, s3_client: Any | None = None, timeout: int = 20, **kwargs)[source]¶
Bases:
BaseResterInitialize the REST API helper class.
s3_client: boto3 S3 client object with which to connect to the object stores. timeout: Time in seconds to wait until a request timeout error is thrown
- Parameters:
api_key – A String API key for accessing the MaterialsProject REST interface. Please obtain your API key at https://www.materialsproject.org/dashboard. If this is None, the code will check if there is a “PMG_MAPI_KEY” setting. If so, it will use that environment variable. This makes easier for heavy users to simply add this environment variable to their setups and MPRester can then be called without any arguments.
endpoint – Url of endpoint to access the MaterialsProject REST interface. Defaults to the standard Materials Project REST address at “https://api.materialsproject.org”, but can be changed to other urls implementing a similar interface.
include_user_agent – If True, will include a user agent with the HTTP request including information on pymatgen and system version making the API request. This helps MP support pymatgen users, and is similar to what most web browsers send with each page request. Set to False to disable the user agent.
session – requests Session object with which to connect to the API, for advanced usage only.
use_document_model – If False, skip the creating the document model and return data as a dictionary. This can be simpler to work with but bypasses data validation and will not give auto-complete for available fields.
headers – Custom headers for localhost connections.
mute_progress_bars – Whether to disable progress bars.
db_version (str) – Database version to use for data read from S3 (full dataset downloads, phase diagrams), e.g. “2026.04.13”. Defaults to the version currently served by the API. REST queries always use the current database. See available_db_versions() on a rester for the versions available.
local_dataset_cache – Target directory for downloading full datasets. Defaults to ‘mp_datasets’ in the user’s home directory
force_renew – Option to overwrite existing local dataset
query_builder – DEPRECATED, use delta_catalog. Instance of QueryBuilderWithCache whose catalog is used for querying delta tables. NOTE: Must be a QueryBuilderWithCache, a deltalake.QueryBuilder will be ignored.
delta_catalog – Instance of DeltaCatalog to use for querying delta tables.
s3_client – boto3 S3 client object with which to connect to the object stores.
timeout – Time in seconds to wait until a request timeout error is thrown
**kwargs – access to legacy kwargs that may be in the process of being deprecated
- __init__(api_key: str | None = None, endpoint: str | None = None, include_user_agent: bool = True, use_document_model: bool = True, session: requests.Session | None = None, headers: dict | None = None, mute_progress_bars: bool = False, db_version: str | None = None, local_dataset_cache: str | os.PathLike = PosixPath('/home/runner/mp_datasets'), force_renew: bool = False, query_builder: QueryBuilderWithCache | None = None, delta_catalog: DeltaCatalog | None = None, s3_client: Any | None = None, timeout: int = 20, **kwargs)¶
Initialize the REST API helper class.
s3_client: boto3 S3 client object with which to connect to the object stores. timeout: Time in seconds to wait until a request timeout error is thrown
- Parameters:
api_key – A String API key for accessing the MaterialsProject REST interface. Please obtain your API key at https://www.materialsproject.org/dashboard. If this is None, the code will check if there is a “PMG_MAPI_KEY” setting. If so, it will use that environment variable. This makes easier for heavy users to simply add this environment variable to their setups and MPRester can then be called without any arguments.
endpoint – Url of endpoint to access the MaterialsProject REST interface. Defaults to the standard Materials Project REST address at “https://api.materialsproject.org”, but can be changed to other urls implementing a similar interface.
include_user_agent – If True, will include a user agent with the HTTP request including information on pymatgen and system version making the API request. This helps MP support pymatgen users, and is similar to what most web browsers send with each page request. Set to False to disable the user agent.
session – requests Session object with which to connect to the API, for advanced usage only.
use_document_model – If False, skip the creating the document model and return data as a dictionary. This can be simpler to work with but bypasses data validation and will not give auto-complete for available fields.
headers – Custom headers for localhost connections.
mute_progress_bars – Whether to disable progress bars.
db_version (str) – Database version to use for data read from S3 (full dataset downloads, phase diagrams), e.g. “2026.04.13”. Defaults to the version currently served by the API. REST queries always use the current database. See available_db_versions() on a rester for the versions available.
local_dataset_cache – Target directory for downloading full datasets. Defaults to ‘mp_datasets’ in the user’s home directory
force_renew – Option to overwrite existing local dataset
query_builder – DEPRECATED, use delta_catalog. Instance of QueryBuilderWithCache whose catalog is used for querying delta tables. NOTE: Must be a QueryBuilderWithCache, a deltalake.QueryBuilder will be ignored.
delta_catalog – Instance of DeltaCatalog to use for querying delta tables.
s3_client – boto3 S3 client object with which to connect to the object stores.
timeout – Time in seconds to wait until a request timeout error is thrown
**kwargs – access to legacy kwargs that may be in the process of being deprecated
Methods
__init__([api_key, endpoint, ...])Initialize the REST API helper class.
Database versions available for this collection's full dataset on S3.
compute_thermo_quantities([material_id, ...])Compute thermodynamical quantities for a given phonon ID or material ID and phonon_method.
count([criteria])Return a count of total documents.
get_bandstructure_from_material_id(material_id)Get the phonon band structure pymatgen object associated with a given material ID.
get_bandstructure_from_phonon_id(identifier, ...)Get the phonon band structure pymatgen object associated with a given phonon ID and phonon method.
get_data_by_id(document_id[, fields])get_dos_from_material_id(material_id[, ...])Get the phonon dos pymatgen object associated with a given material ID.
get_dos_from_phonon_id(identifier, phonon_method)Get the phonon dos pymatgen object associated with a given phonon ID and phonon method.
Get the force constants associated with a given material ID and phonon method.
Get the force constants associated with a given phonon ID and phonon method.
search([identifiers, material_ids, ...])Query phonon docs using a variety of search criteria.
Attributes
available_fieldsdelta_backedThe DeltaCatalog used for delta-backed queries, created on first use.
primary_keyuse delta_catalog.
s3_clientsessionsuffixsummary_rester- document_model¶
alias of
PhononBSDOSTask
- search(identifiers: str | list[str] | None = None, material_ids: str | list[str] | None = None, phonon_method: str | None = None, num_chunks: int | None = None, chunk_size: int = 1000, all_fields: bool = True, fields: list[str] | None = None) list[PhononBSDOSTask] | list[dict][source]¶
Query phonon docs using a variety of search criteria.
Exactly one of identifiers and material_ids may be supplied. When material_ids is supplied, the summary endpoint is queried to resolve each material’s phonon_IDs into the underlying phonon task identifiers (filtered by phonon_method when provided), and those phonon IDs are then used to query the phonon endpoint.
- Parameters:
identifiers (str | list[str]) – A single Phonon Task ID string or list of strings (e.g., aaaaaaft, [aaaaaaft, aaaeguxu]).
material_ids (str | list[str]) – A single Materials Project ID or list of IDs (e.g., mp-149, [mp-149, mp-13]).
phonon_method (str) – phonon method to search (dfpt, phonopy, pheasy)
num_chunks (int) – Maximum number of chunks of data to yield. None will yield all possible.
chunk_size (int) – Number of data entries per chunk.
all_fields (bool) – Whether to return all fields in the document. Defaults to True.
fields (list[str]) – List of fields in PhononBSDOSTask to return data for. Default is identifier, last_updated, and formula_pretty if all_fields is False.
- Returns:
([PhononBSDOSTask], [dict]) List of phonon documents or dictionaries.
- get_bandstructure_from_phonon_id(identifier: str, phonon_method: str, path_type: str | BSPathType = BSPathType.setyawan_curtarolo) PhononBS | dict[str, Any][source]¶
Get the phonon band structure pymatgen object associated with a given phonon ID and phonon method.
- Parameters:
- Returns:
PhononBS object
- Return type:
bandstructure (PhononBS)
- get_bandstructure_from_material_id(material_id: str, phonon_method: Literal['pheasy', 'dfpt'] | None = None, path_type: str | BSPathType = BSPathType.setyawan_curtarolo) PhononBS | dict[str, Any][source]¶
Get the phonon band structure pymatgen object associated with a given material ID.
- Parameters:
material_id (str) – Materials Project ID for a material
phonon_method (str or None) – phonon method, i.e. pheasy or dfpt. By default, the method is chosen from the material’s data: pheasy if it has it, otherwise dfpt. If the pheasy calculation has no band structure, the dfpt one is used (with a warning). A method passed explicitly is never replaced.
path_type (BSPathType or str) – k-path selection convention for the band structure. pheasy has all conventions; dfpt only has setyawan_curtarolo.
- Returns:
PhononBS object
- Return type:
bandstructure (PhononBS)
- Raises:
MPRestError – if there’s no suitable data. The message names the methods the material does have data for.
- get_dos_from_phonon_id(identifier: str, phonon_method: str) PhononDOS | dict[str, Any][source]¶
Get the phonon dos pymatgen object associated with a given phonon ID and phonon method.
- get_dos_from_material_id(material_id: str, phonon_method: Literal['pheasy', 'dfpt'] | None = None) PhononDOS | dict[str, Any][source]¶
Get the phonon dos pymatgen object associated with a given material ID.
- Parameters:
material_id (str) – Materials Project ID for a material
phonon_method (str or None) – phonon method, i.e. pheasy or dfpt. By default, the method is chosen from the material’s data: pheasy if it has it, otherwise dfpt. If the pheasy calculation has no DOS, the dfpt one is used (with a warning). A method passed explicitly is never replaced.
- Returns:
PhononDOS object
- Return type:
dos (PhononDOS)
- Raises:
MPRestError – if there’s no suitable data. The message names the methods the material does have data for.
- get_forceconstants_from_phonon_id(identifier: str, phonon_method: str) list[list[Matrix3D]][source]¶
Get the force constants associated with a given phonon ID and phonon method.
- get_forceconstants_from_material_id(material_id: str, phonon_method: str) list[list[Matrix3D]][source]¶
Get the force constants associated with a given material ID and phonon method.
- Parameters:
- Returns:
force constants
- Return type:
- Raises:
MPRestError – if the method can’t have force constants, or the material has none.
- compute_thermo_quantities(material_id: str | None = None, phonon_method: Literal['pheasy', 'dfpt'] | None = None, identifier: str | None = None)[source]¶
Compute thermodynamical quantities for a given phonon ID or material ID and phonon_method.
Exactly one of identifier or material_id must be supplied.
- Parameters:
identifier (str) – Phonon ID to calculate quantities for. Requires phonon_method.
material_id (str) – Materials Project ID to calculate quantities for.
phonon_method (str) – phonon method, i.e. pheasy or dfpt. With material_id, the method is chosen from the material’s data (pheasy, then dfpt) unless given; the first phonon ID of the method is used.
- Returns:
thermodynamical quantities
- Return type:
quantities (dict)
- available_db_versions() list[str]¶
Database versions available for this collection’s full dataset on S3.
Read from the DeltaTable’s log, no data is downloaded. Any of these can be pinned with MPRester(db_version=…) to download that version of the dataset.
- property delta_catalog: DeltaCatalog¶
The DeltaCatalog used for delta-backed queries, created on first use.
- property query_builder: QueryBuilderWithCache¶
use delta_catalog.
- Type:
Deprecated