Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rich library in the CLI #47

Merged
merged 2 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ The package, together with the above dependencies, can be installed from

pip install overreact

Optionally, extra functionality is provided by
`thermo <https://github.com/CalebBell/thermo>`_::
Optionally, extra functionality is provided such as a command-line interface
and solvent properties::

pip install 'overreact[thermo]'
pip install 'overreact[cli,solvents]'

This last line installs thermo as well. thermo is used to calculate the
dynamic viscosity of solvents in the context of the
This last line installs `Rich <https://github.com/willmcgugan/rich>`_
and `thermo <https://github.com/CalebBell/thermo>`_ as well.
Rich is used in the command-line interface, and thermo is used
to calculate the dynamic viscosity of solvents in the context of the
:doc:`tutorials/collins-kimball` for diffusion-limited reactions.
925 changes: 466 additions & 459 deletions overreact/cli.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions overreact/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ def _get_chemical(
):
"""Wrap `thermo.Chemical`.

This function is used for obtaining property values and requires the `thermo` package.

All parameters are passed to `thermo.Chemical` and the returned object is
returned.

Expand Down
2 changes: 1 addition & 1 deletion overreact/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def liquid_viscosity(id, temperature=298.15, pressure=constants.atm):
"""Dynamic viscosity of a solvent.

This function uses the `thermo` package.
This function requires the `thermo` package for obtaining property values.

Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cclib==1.6.3
cclib>=1.6.3
scipy>=1.4.0
matplotlib>=2.1.1
pytest>=5.2.1
rich>=9.2.0
thermo>=0.1.39
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
setup(
name="overreact",
version=open("VERSION").read().strip(),
description="A Python package for constructing microkinetic models",
description="Construct precise chemical microkinetic models from first principles",
author="Felipe Silveira de Souza Schneider",
author_email="[email protected]",
url="https://github.com/schneiderfelipe/overreact",
packages=find_packages(),
entry_points={"console_scripts": ["overreact = overreact.cli:main"]},
install_requires=["cclib>=1.6.3", "scipy>=1.4.0"],
extras_require={"thermo": ["thermo>=0.1.39"]},
tests_require=["pytest>=5.2.1"],
extras_require={"cli": ["rich>=9.2.0"], "solvents": ["thermo>=0.1.39"],},
tests_require=["matplotlib>=2.1.1", "pytest>=5.2.1"],
)
40 changes: 17 additions & 23 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,25 @@ def test_private_functions_work():
assert list(core._unparse_reactions([(((1, "A"),), ((1, "B"),), True)])) == [
"A -> B"
]
assert (
list(
core._unparse_reactions(
[
(((2, "A"),), ((3, "B"),), True),
(((1, "A"),), ((2, "C"),), True),
(((50, "A"),), ((1, "D"),), True),
]
)
assert list(
core._unparse_reactions(
[
(((2, "A"),), ((3, "B"),), True),
(((1, "A"),), ((2, "C"),), True),
(((50, "A"),), ((1, "D"),), True),
]
)
== ["2 A -> 3 B", "A -> 2 C", "50 A -> D"]
)
assert (
list(
core._unparse_reactions(
[
(((1, "E"), (1, "S")), ((1, "ES"),), True),
(((1, "ES"),), ((1, "E"), (1, "S")), True),
(((1, "ES"),), ((1, "ES‡"),), False),
(((1, "ES‡"),), ((1, "E"), (1, "P")), False),
]
)
) == ["2 A -> 3 B", "A -> 2 C", "50 A -> D"]
assert list(
core._unparse_reactions(
[
(((1, "E"), (1, "S")), ((1, "ES"),), True),
(((1, "ES"),), ((1, "E"), (1, "S")), True),
(((1, "ES"),), ((1, "ES‡"),), False),
(((1, "ES‡"),), ((1, "E"), (1, "P")), False),
]
)
== ["E + S -> ES", "ES -> E + S", "ES -> ES‡", "ES‡ -> E + P"]
)
) == ["E + S -> ES", "ES -> E + S", "ES -> ES‡", "ES‡ -> E + P"]

assert list(
core._unparse_reactions(
Expand Down
34 changes: 14 additions & 20 deletions tests/test_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,21 @@ def test_liquid_viscosities_are_correct():

def test_conversion_of_rate_constants_work():
"""Ensure converting reaction rate constants work."""
assert (
rates.convert_rate_constant(
12345e5,
"cm3 mol-1 s-1",
"l mol-1 s-1",
molecularity=2,
temperature=[200, 298.15, 300, 400],
)
== pytest.approx(12345e8)
)
assert rates.convert_rate_constant(
12345e5,
"cm3 mol-1 s-1",
"l mol-1 s-1",
molecularity=2,
temperature=[200, 298.15, 300, 400],
) == pytest.approx(12345e8)

assert (
rates.convert_rate_constant(
12345e10,
"cm3 particle-1 s-1",
"atm-1 s-1",
molecularity=2,
temperature=[200, 298.15, 300, 400],
)
== pytest.approx(13.63e-23 * 12345e10 * np.array([200, 298.15, 300, 400]), 1e-3)
)
assert rates.convert_rate_constant(
12345e10,
"cm3 particle-1 s-1",
"atm-1 s-1",
molecularity=2,
temperature=[200, 298.15, 300, 400],
) == pytest.approx(13.63e-23 * 12345e10 * np.array([200, 298.15, 300, 400]), 1e-3)


def test_conversion_rates_know_about_reaction_order():
Expand Down
Loading