diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fe21a5..ba90818 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,13 +4,13 @@ The following is a set of guidelines for contributing to the Chemics Python package. Submitted code that does not conform to these guidelines will not be merged into the package. Feel free to propose changes to this document in a Pull Request or Issue. -## Environment +## Development environment Use the `environment.yml` file to create a conda environment for developing the Chemics package. See the comments in the file for more details. -## Code style +## Code style, linting, and formatting -All code in the Chemics package should adhere to the style enforced by the [Flake8](https://pypi.org/project/flake8/) tool. This will ensure a consistent code format throughout the package and prevent syntax errors during development. For the Flake8 style settings, ignore the E501, W503, W605 errors and warnings. +All Python code in the Chemics package should adhere to the [PEP 8](https://peps.python.org/pep-0008/) style guide. All linting and formatting should be implemented with [ruff](https://github.com/astral-sh/ruff). Configuration for ruff is defined in the pyproject.toml file. ## Docstrings @@ -18,11 +18,11 @@ All functions, classes, and other Python components should contain docstrings wi ## Examples -Along with an example in the docstring, please provide a complete example in Sphinx documentation. Simple examples should also be provided in the docstrings. +Along with an example in the docstring, please provide a complete example in the Sphinx documentation. Simple examples should also be provided in the docstrings. ## Tests -New code for the Chemics package must include associated tests in the `tests/` folder. The [pytest](https://docs.pytest.org/en/latest/) framework is used to execute the test files. +New code for the Chemics package must include associated tests in the `tests/` folder. The [pytest](https://github.com/pytest-dev/pytest) framework is used to execute the test files. ## Changelog @@ -30,7 +30,7 @@ Don't forget to edit the changelog based on your contributions. Follow the style ## Sphinx documentation -New source code should be included in the [Sphinx documentation](http://www.sphinx-doc.org/en/stable/) located in the `docs/` folder. +New source code along with examples should be documented in the [Sphinx documentation](http://www.sphinx-doc.org/en/stable/) located in the `docs/` folder. ## Creating a pull request diff --git a/LICENSE.md b/LICENSE.md index b74f7d1..45d854d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Chemics +Copyright (c) 2024 Chemics Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 340f5c6..144b3c4 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,26 @@ $ pip install chemics ## Usage -The example below imports the Chemics package and creates a `Gas` class to calculate the density of nitrogen gas at a pressure of 101,325 Pa and 773 K. +The example below imports the Chemics package and uses the `Gas` class to calculate the density and viscosity of nitrogen gas at a temperature of 773 K and pressure of 101,325 Pa. ```python import chemics as cm -gas = cm.Gas('N2') -rho = gas.density(101325, 773) +gas = cm.Gas("N2", 773) +rho = gas.density() +mu = gas.viscosity() -print(rho) -# This prints a value of 0.4416 +print("Nitrogen gas properties at 773 K and 101,325 Pa") +print(f"density {rho:.4f} kg/m³") +print(f"viscosity {mu:.2f} μP") +``` + +This prints the following: + +``` +Nitrogen gas properties at 773 K and 101,325 Pa +density 0.4416 kg/m³ +viscosity 363.82 μP ``` This example uses the `ChemicalEquation` class to get properties of the reactants and products from a given chemical equation. @@ -29,12 +39,12 @@ This example uses the `ChemicalEquation` class to get properties of the reactant ```python import chemics as cm -ce = cm.ChemicalEquation('2 HCl + 2 Na -> 2 NaCl + H2') +ce = cm.ChemicalEquation("2 HCl + 2 Na -> 2 NaCl + H2") ce.is_balanced() -# Returns True for balanced equation +# This returns True for balanced equation ce.rct_properties -# Returns a dataframe of the reactant properties +# This returns a dataframe of the reactant properties # HCl Na # moles 2 2 # species HCl Na diff --git a/benchmarks.py b/benchmarks.py index e6ec472..3f19350 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -1,39 +1,48 @@ +""" +Benchmarks. +""" + import time import chemics as cm def run_benchmarks(): """ - Run benchmarks for the Gas methods. Elapsed time for subsequent method - calls should be near zero compared to the initial method execution. - """ + Run benchmarks for Gas methods. - gas = cm.Gas('CH4', 890.5, 120325) + Run benchmarks for Gas heat capacity, thermal conductivity, and viscosity + methods. Elapsed time for subsequent method calls should be near zero + compared to the initial method execution. + """ + gas = cm.Gas("CH4", 890.5, 120325) for i in range(5): tic = time.perf_counter() cp = gas.heat_capacity() toc = time.perf_counter() - print(f'Run {i + 1}, Elapsed time {toc - tic:.4f} s, cp {cp:.4f}') + print(f"Run {i + 1}, Elapsed time {toc - tic:.4f} s, cp {cp:.4f}") print() for i in range(5): tic = time.perf_counter() k = gas.thermal_conductivity() toc = time.perf_counter() - print(f'Run {i + 1}, Elapsed time {toc - tic:.4f} s, k {k:.4f}') + print(f"Run {i + 1}, Elapsed time {toc - tic:.4f} s, k {k:.4f}") print() for i in range(5): tic = time.perf_counter() mu = gas.viscosity() toc = time.perf_counter() - print(f'Run {i + 1}, Elapsed time {toc - tic:.4f} s, mu {mu:.4f}') + print(f"Run {i + 1}, Elapsed time {toc - tic:.4f} s, mu {mu:.4f}") def main(): + """ + Run the benchmarks. + """ run_benchmarks() -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/docs/examples/gas_properties.rst b/docs/examples/gas_properties.rst index 83bbd36..562564b 100644 --- a/docs/examples/gas_properties.rst +++ b/docs/examples/gas_properties.rst @@ -31,5 +31,3 @@ This prints the output shown below. heat capacity 31.24 J/(mol⋅K) thermal conductivity 0.054 W/(m⋅K) viscosity 363.82 microPoise (μP) - -Done. diff --git a/docs/installation.rst b/docs/installation.rst index bb4ffd7..5797120 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -12,17 +12,27 @@ Install Chemics using the pip package manager: Usage ===== -The example below imports the chemics package and creates a ``Gas`` class to calculate the density of nitrogen gas at a pressure of 101,325 Pa and 773 K. +The example below imports the Chemics package and uses the ``Gas`` class to calculate the density and viscosity of nitrogen gas at a temperature of 773 K and pressure of 101,325 Pa. -.. code-block:: python +.. testcode:: import chemics as cm - gas = cm.Gas('N2') - rho = gas.density(101325, 773) - print(rho) - # This prints a value of 0.4416 + gas = cm.Gas("N2", 773) + rho = gas.density() + mu = gas.viscosity() + + print("Nitrogen gas properties at 773 K and 101,325 Pa") + print(f"density {rho:.4f} kg/m³") + print(f"viscosity {mu:.2f} μP") + +This prints the following: + +.. testoutput:: + Nitrogen gas properties at 773 K and 101,325 Pa + density 0.4416 kg/m³ + viscosity 363.82 μP This example uses the ``ChemicalEquation`` class to get properties of the reactants and products from a given chemical equation. @@ -32,7 +42,7 @@ This example uses the ``ChemicalEquation`` class to get properties of the reacta ce = cm.ChemicalEquation('2 HCl + 2 Na -> 2 NaCl + H2') ce.is_balanced() - # The returns True for balanced equation + # This returns True for balanced equation ce.rct_properties # This returns a dataframe of the reactant properties