[docs]defget_gradient_units(base_unit:str,gradient_name:str,length_unit:str)->str:""" Get the gradient units based on the unit of the base quantity. For example, if the base unit is "<unit>" and the gradient name is "positions", the gradient unit will be "<unit>/<length_unit>". :param base_unit: The unit of the base quantity. :param gradient_name: The name of the gradient. :param length_unit: The unit of lengths. :return: The unit of the gradient. """ifbase_unit=="":return""# unknown unit for base quantity -> unknown unit for gradientiflength_unit.lower()in["angstrom","å","ångstrom"]:length_unit="A"# prettierifgradient_name=="positions":returnbase_unit+"/"+length_unitelifgradient_name=="strain":returnbase_unit# strain is dimensionlesselse:raiseValueError(f"Unknown gradient name: {gradient_name}")
[docs]defev_to_mev(value:float,unit:str)->Tuple[float,str]:""" If the `unit` starts with eV, converts the `value` and its corresponding `unit` to meV. Otherwise, returns the input. :param value: The value (potentially in eV or a derived quantity of eV). :param unit: The unit of the value. :return: If the `value` is in meV (or a derived quantity), the value and the corresponding unit where eV is converted to meV. Otherwise, the input. """ifunit.startswith("eV")orunit.startswith("ev"):returnvalue*1000.0,(unit.replace("eV","meV")ifunit.startswith("eV")elseunit.replace("ev","mev"))else:returnvalue,unit