Miscellaneous¶
- metatomic.torch.pick_device(model_devices: List[str], desired_device: str | None) str[source]¶
Select the best device according to the list of
model_devicesfrom a model, the user-provideddesired_deviceand what’s available on the current machine.If
desired_deviceis provided, it is checked against themodel_devicesand the machine availability. If it contains a device index (e.g."cuda:1"), the base device type ("cuda") is used for these checks, and the full string is returned if successful.If
desired_deviceisNoneor an empty string, the first available device frommodel_deviceswill be picked and returned.
- metatomic.torch.pick_output(requested_output: str, outputs: Dict[str, ModelOutput], desired_variant: str | None = None) str[source]¶
Pick the output for the given
requested_outputfrom the availabilities of the model’soutputs, according to the optionaldesired_variant.
- metatomic.torch.unit_conversion_factor(from_unit: str, to_unit: str) float[source]¶
Get the multiplicative conversion factor from
from_unittoto_unit.Both
from_unitandto_unitare parsed as unit expressions supporting compound forms like"kJ/mol/A^2"or"(eV*u)^(1/2)". The parser validates that both expressions have matching physical dimensions.This function is TorchScript-compatible. The deprecated 3-argument form
unit_conversion_factor(quantity, from_unit, to_unit)is available viatorch.ops.metatomic.unit_conversion_factor.The set of recognized base units is available here.
Migration from 3-argument form
The 3-argument form
unit_conversion_factor(quantity, from_unit, to_unit)is deprecated. Thequantityparameter is no longer needed because dimensional compatibility is checked automatically by the parser.Before (deprecated):
factor = unit_conversion_factor("energy", "eV", "meV") factor = unit_conversion_factor("force", "eV/A", "Hartree/Bohr")
After (recommended):
factor = unit_conversion_factor("eV", "meV") factor = unit_conversion_factor("eV/A", "Hartree/Bohr")
The new 2-argument form also supports compound expressions that were not possible with the old API:
# Momentum conversion (fractional powers) factor = unit_conversion_factor("(eV*u)^(1/2)", "u*A/fs") # Complex compound expression factor = unit_conversion_factor("kJ/mol/A^2", "Hartree/Bohr^3")
The set of recognized base units is documented in the
C++ API reference.
The unit_conversion_factor() function accepts any valid unit expression
built from base units combined with operators. There is no need to specify a
physical quantity — the parser automatically verifies dimensional compatibility
between the source and target units.
Supported base units¶
Unit expressions are built from the following base units. Matching is case-insensitive, and whitespace is ignored.
- Length:
angstrom(A),Bohr,meter(m),centimeter(cm),millimeter(mm),micrometer(um,µm),nanometer(nm)- Energy:
eV,meV,Hartree,kcal,kJ,Joule(J),Rydberg(Ry)- Time:
second(s),millisecond(ms),microsecond(us,µs),nanosecond(ns),picosecond(ps),femtosecond(fs)- Mass:
u(Dalton),kilogram(kg),gram(g),electron_mass(m_e)- Charge:
e,Coulomb(C)- Dimensionless:
mol- Derived constants:
hbar
Expression syntax¶
Base units can be combined using the following operators:
Multiplication:
*or whitespace (kJ mol,kJ*mol)Division:
/(kJ/mol)Exponentiation:
^(A^3,m^2)Parentheses:
()for grouping ((eV*u)^(1/2))
Examples of valid compound expressions:
kJ/mol— energy per moleeV/Angstrom^3oreV/A^3— pressure(eV*u)^(1/2)— momentum (fractional powers)Hartree/Bohr— force in atomic unitsnm/fs— velocity
The parser automatically checks that both unit expressions have matching physical dimensions before computing the conversion factor.