Skip to content

datamol.molar

A set of utility functions to convert between various units and formats used in drug discovery.

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], 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: {'M', 'fM', 'mM', 'nM', 'pM', 'uM'}.

required
Source code in datamol/molar.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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, dtype="float")) / _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], ndarray]

A molar concentration (can be a scalar, a list or an array).

required
unit str

The unit of the input concentration. Choose from: {'M', 'fM', 'mM', 'nM', 'pM', 'uM'}.

required
Source code in datamol/molar.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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])