datamol.molar
¶
Chemical units conversion utilities¶
log_to_molar(values, unit)
¶
Convert a log-scaled molar concentration (pXC50 for example) to its unscaled value (XC50).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
Union[float, Iterable[float], numpy.ndarray] |
A log-scaled molar concentration (can be a scalar, a list or an array). |
required |
unit |
str |
The unit of the input concentration. Choose from:
|
required |
Source code in datamol/molar.py
def log_to_molar(
values: Union[float, Iterable[float], np.ndarray],
unit: str,
) -> Union[float, Iterable[float], np.ndarray]:
"""Convert a log-scaled molar concentration (pXC50 for example) to its unscaled value (XC50).
Args:
values: A log-scaled molar concentration (can be a scalar, a list or an array).
unit: The unit of the input concentration. Choose from:
`{'M', 'fM', 'mM', 'nM', 'pM', 'uM'}`.
"""
if unit not in _MOLAR_SCALES:
raise ValueError(
f"The unit '{unit}' is not supported. Choose from {set(_MOLAR_SCALES.keys())}."
)
return 10 ** (-1 * np.array(values)) / _MOLAR_SCALES[unit]
molar_to_log(values, unit)
¶
Convert a molar concentration (XC50 for example) to its log scaled value (pXC50).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
Union[float, Iterable[float], numpy.ndarray] |
A molar concentration (can be a scalar, a list or an array). |
required |
unit |
str |
The unit of the input concentration. Choose from:
|
required |
Source code in datamol/molar.py
def molar_to_log(
values: Union[float, Iterable[float], np.ndarray],
unit: str,
) -> Union[float, Iterable[float], np.ndarray]:
"""Convert a molar concentration (XC50 for example) to its log scaled value (pXC50).
Args:
values: A molar concentration (can be a scalar, a list or an array).
unit: The unit of the input concentration. Choose from:
`{'M', 'fM', 'mM', 'nM', 'pM', 'uM'}`.
"""
if unit not in _MOLAR_SCALES:
raise ValueError(
f"The unit '{unit}' is not supported. Choose from {set(_MOLAR_SCALES.keys())}."
)
return -1 * np.log10(np.array(values) * _MOLAR_SCALES[unit])