API reference¶
Auto-generated reference for UPET’s Python API
Top-level functions¶
- upet.get_upet(*, model: str | None = None, size: str | None = None, version: str | Version | None = 'latest', checkpoint_path: str | None = None) AtomisticModel[source]¶
Get a metatomic
AtomisticModelfor a UPET MLIP.- Parameters:
model (str | None) – name of the UPET model. Required when not using checkpoint_path, or when checkpoint_path has non-standard naming.
size (str | None) – size of the UPET model. Required when not using checkpoint_path, or when checkpoint_path has non-standard naming.
version (str | Version | None) – version of the UPET model.
checkpoint_path (str | None) – path to a checkpoint file to load the model from. If the filename follows standard naming (e.g., “pet-mad-s-v1.0.2.ckpt”), model/size/version are extracted automatically, while the model and version parameters are ignored.
- Return type:
- upet.list_upet(*, model: str | None = None, size: str | None = None, print_summary: bool = True) List[dict][source]¶
List available UPET models, sizes, and versions.
When called without arguments, returns all available model/size/version combinations. When
modelis given, filters to that model. When bothmodelandsizeare given, filters to that specific combination.- Parameters:
model (str | None) – Base model name (e.g., “pet-mad”, “pet-omat”). If
None, lists all available models.size (str | None) – Model size (e.g., “s”, “m”, “l”). If
Noneandmodelis given, lists all sizes for that model.print_summary (bool) – Whether to print a human-readable summary to stdout. Defaults to
True.
- Returns:
A list of dictionaries, each with keys
"model","size", and"version".- Return type:
- upet.save_upet(*, model: str | None = None, size: str | None = None, version: str | None = 'latest', checkpoint_path: str | None = None, output: str | None = None)[source]¶
Save the UPET model to a TorchScript file. These files can be used with LAMMPS and other tools to run simulations without Python.
- Parameters:
model (str | None) – name of the UPET model.
size (str | None) – size of the UPET model.
version (str | None) – UPET version to use. Defaults to the latest stable version.
checkpoint_path (str | None) – path to a checkpoint file to load the model from.
output (str | None) – path for the output model. Defaults to “{model}-{size}-v{version}.pt” or “model.pt” for non-standard checkpoint names.
Calculators¶
- class upet.calculator.UPETCalculator(model: str | None = None, version: str | None = 'latest', dtype: dtype | None = None, checkpoint_path: str | None = None, variants: Dict[str, str | None] | None = None, rotational_average_order: int | None = None, rotational_average_batch_size: int | None = None, *, device: str | None = None, non_conservative: bool = False, check_consistency: bool = False)[source]¶
ASE Calculator for universal MLIPs based on the PET architecture.
- Parameters:
model (str | None) –
PET-MLIP model to use. Required when not using checkpoint_path. Can be one of the following:
”pet-mad-xs”: PET-MAD-1.5 model (size “xs”, materials and molecules, r2SCAN)
”pet-mad-s”: PET-MAD-1.5 model (size “s”, materials and molecules, r2SCAN)
”pet-omat-xs”: PET-OMat model (size “xs”, materials, PBE)
”pet-omat-s”: PET-OMat model (size “s”, materials, PBE)
”pet-omat-m”: PET-OMat model (size “m”, materials, PBE)
”pet-omat-l”: PET-OMat model (size “l”, materials, PBE)
”pet-omat-xl”: PET-OMat model (size “xl”, materials, PBE)
”pet-oam-l”: PET-OAM model (size “l”, materials, Materials-Project-consistent PBE)
”pet-oam-xl”: PET-OAM model (size “xl”, materials, Materials-Project-consistent PBE)
”pet-omatpes-l”: PET-OMATPES model (size “l”, materials, r2SCAN)
”pet-spice-s”: PET-SPICE model (size “s”, molecules, ωB97M-D3)
”pet-spice-l”: PET-SPICE model (size “l”, molecules, ωB97M-D3)
version (str | None) –
version of the model to use. Defaults to the latest stable version. Deprecated model versions:
”pet-mad-s-v1.0.2”: PET-MAD-1 model (size “s”, materials and molecules, PBEsol)
”pet-omad-xs-v1.0.0”: PET-OMAD model (size “xs”, materials and molecules, PBEsol)
”pet-omad-s-v1.0.0”: PET-OMAD model (size “s”, materials and molecules, PBEsol)
”pet-omad-l-v0.1.0”: PET-OMAD model (size “l”, materials and molecules, PBEsol)
dtype (dtype | None) – dtype to use for the calculations. If None, we will use the default dtype.
checkpoint_path (str | None) – path to a checkpoint file to load the model from. If the filename follows standard naming (e.g., “pet-mad-s-v1.0.2.ckpt”), model/size/version are extracted automatically, and the model, size, and version parameters are ignored.
variants (Dict[str, str | None] | None) – dictionary specifying which variant to use for each output. This option allows to choose the evaluation head when multiple variants are available for a given output. For example, if both
energy/pbeandenergy/r2scanvariants are available forenergytarget, one can select which one to use by setting thevariantsparameter to{"energy": "r2scan"}. Ifenergyis set to a variant also the uncertainty and non-conservative outputs will be taken from this variant. If not provided, the default variant for each output will be used (for example:energywith no variant specification).rotational_average_order (int | None) – order of the Lebedev-Laikov grid used for averaging the prediction over rotations.
rotational_average_batch_size (int | None) – batch size to use for the rotational averaging. If None, all rotations will be computed at once.
device (str | None) – torch device to use for the calculation. If None, we will try the options in the model’s supported_device in order.
non_conservative (bool) –
whether to use the non-conservative regime of forces and stresses prediction. Defaults to False. Available for all models, except:
PET-MAD models with version < 1.1.0
PET-SPICE models
check_consistency (bool) – whether internal consistency checks should be performed. Mainly for developers, defaults to False.
- calculate(atoms: Atoms, properties: List[str], system_changes: List[str]) None[source]¶
Compute some
propertieswith this calculator, and return them in the format expected by ASE.This is not intended to be called directly by users, but to be an implementation detail of
atoms.get_energy()and related functions. Seease.calculators.calculator.Calculator.calculate()for more information.If the rotational_average_order parameter is set during initialization, the prediction will be averaged over unique rotations in the Lebedev-Laikov grid of a chosen order.
If the rotational_average_batch_size parameter is set during initialization, averaging will be performed in batches of the given size to avoid out of memory errors.
- get_energy_uncertainty(atoms: Atoms | None = None, per_atom: bool = False) ndarray[source]¶
Get the energy uncertainty for a given
ase.Atomsobject.
- class upet.calculator.PETMADDOSCalculator(version: str = 'latest', model_path: str | None = None, bandgap_model_path: str | None = None, *, check_consistency: bool = False, device: str | None = None)[source]¶
PET-MAD DOS Calculator
- Parameters:
version (str) – PET-MAD-DOS version to use. Defaults to the latest stable version.
model_path (str | None) – path to a Torch-Scripted model file to load the model from. If provided, the version parameter is ignored.
bandgap_model_path (str | None) – path to a PyTorch checkpoint file with the bandgap model. If provided, the version parameter is ignored.
check_consistency (bool) – should we check the model for consistency when running, defaults to False.
device (str | None) – torch device to use for the calculation. If None, we will try the options in the model’s supported_device in order.
- calculate_dos(atoms: Atoms | List[Atoms], per_atom: bool = False) Tuple[Tensor, Tensor][source]¶
Calculate the density of states for a given ase.Atoms object, or a list of ase.Atoms objects.
- calculate_bandgap(atoms: Atoms | List[Atoms], dos: Tensor | None = None) Tensor[source]¶
Calculate the bandgap for a given ase.Atoms object,or a list of ase.Atoms objects. By default, the density of states is first calculated using the calculate_dos method, and the the bandgap is derived from the DOS by a BandgapModel. Alternatively, the density of states can be provided as an input parameter to avoid re-calculating the DOS.
- Parameters:
- Returns:
bandgap values for each ase.Atoms object object stored in a torch.Tensor format.
- Return type:
- calculate_efermi(atoms: Atoms | List[Atoms], dos: Tensor | None = None, temperature: float = 0.0) Tensor[source]¶
Get the Fermi energy for a given ase.Atoms object, or a list of ase.Atoms objects, based on a predicted density of states at a given temperature. By default, the density of states is first calculated using the calculate_dos method, and the Fermi level is calculated at T=0 K. Alternatively, the density of states can be provided as an input parameter to avoid re-calculating the DOS.
- Parameters:
- Returns:
Fermi energy for each ase.Atoms object stored in a torch.Tensor format.
- Return type:
Featurizer¶
- class upet.explore.PETMADFeaturizer(version: str = 'latest', checkpoint_path: str | None = None, pet_checkpoint_path: str | None = None, *, check_consistency=False, device=None, length_unit='Angstrom', batch_size: int = 1, progress_bar=<class 'tqdm.std.tqdm'>)[source]¶
Converts structures into low-dimensional projections using PET-MAD features, with dimensionality reduction based on sketch-map.
- Usage example:
>>> import ase.io >>> import chemiscope >>> from pet_mad.explore import PETMADFeaturizer
>>> # Load structures >>> frames = ase.io.read("dataset.xyz", ":")
>>> # Create visualization >>> chemiscope.explore(frames, featurize=PETMADFeaturizer(version="latest"))
- Parameters:
version (str) – PET-MAD Explorer version to use. Supported versions are “latest”, “1.0.0”.
checkpoint_path (str | None) – path to a checkpoint file to load the exploration model from. If provided, the version parameter is ignored.
pet_checkpoint_path (str | None) – path to a petmad checkpoint file to use for the model from. If not provided, the latest checkpoint is fetched from HuggingFace.
check_consistency – should we check the model for consistency when running, defaults to False.
device – torch device to use for the calculation. If None, we will try the options in the model’s supported_device in order.
length_unit – unit of length used in the structures
batch_size (int)