Skip to content

Commit d32840d

Browse files
author
finlayclark
committed
Make print module more modular
1 parent ca46add commit d32840d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

k2dg/_print.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,39 @@
44
from ._parse import K_UNITS
55

66

7+
def _get_dg0_str(dg0: Quantity) -> str:
8+
"""Return the free energy of binding in kcal/mol."""
9+
return f"{dg0.to('kcal/mol').magnitude:#.3g} kcal/mol"
10+
11+
712
def _print_dg0(dg0: Quantity) -> None:
813
"""Print the free energy of binding in kcal/mol."""
9-
print(f"{dg0.to('kcal/mol').magnitude:#.3g} kcal/mol")
14+
print(_get_dg0_str(dg0))
1015

1116

12-
def _print_kd0(kd0: Quantity) -> None:
17+
def _get_kd0_str(kd0: Quantity) -> str:
1318
"""
14-
Print the dissociation constant with an appropriate prefix. Note that there
15-
is an implicit conversion from the standard dissociation constant to the
16-
dissociation constant.
19+
Return the dissociation constant with an appropriate prefix. Note that
20+
there is an implicit conversion from the standard dissociation constant to
21+
the dissociation constant.
1722
"""
1823
# The appropriate prefix is the one that gives a value between 0.1 and 100
1924
# (i.e. between 1e-1 and 1e2)
2025
kd = kd0.magnitude
2126
for prefix, value in K_UNITS.items():
2227
if 1e-1 < kd / value <= 1e2:
23-
print(f"{kd / value:#.3g} {prefix}")
24-
return
28+
return f"{kd / value:#.3g} {prefix}"
2529
# The value is less than 0.1 pM or greater than 100 M
2630
if kd < 1e-10:
27-
print(f"{kd / 1e-15:#.3g} fM")
31+
return f"{kd / 1e-15:#.3g} fM"
2832
else:
29-
print(f"{kd:#.3g} M")
33+
return f"{kd:#.3g} M"
34+
35+
36+
def _print_kd0(kd0: Quantity) -> None:
37+
"""
38+
Print the dissociation constant with an appropriate prefix. Note that there
39+
is an implicit conversion from the standard dissociation constant to the
40+
dissociation constant.
41+
"""
42+
print(_get_kd0_str(kd0))

0 commit comments

Comments
 (0)