Commit 059060fd authored by eladnoor's avatar eladnoor

minor touches to code readability

parent e4bb6092
...@@ -35,19 +35,18 @@ The easiest way to get eQuilibrator-API up and running is using virtualenv, PyPI ...@@ -35,19 +35,18 @@ The easiest way to get eQuilibrator-API up and running is using virtualenv, PyPI
``` ```
virtualenv -p python3 equilibrator virtualenv -p python3 equilibrator
source equilibrator/bin/activate source equilibrator/bin/activate
pip install equilibrator-api jupyter pip install equilibrator-api
curl https://gitlab.com/elad.noor/equilibrator-api/raw/develop/scripts/equilibrator_cmd.ipynb > equilibrator_cmd.ipynb
jupyter notebook
``` ```
Then select the notebook called `equilibrator_cmd.ipynb` and follow the examples in it. You can then either follow the examples below and write your own code, or start by opening the
provided jupyter notebook:
Alternatively, you could install from source. Make sure you have [git-lfs](https://git-lfs.github.com/)
installed before cloning the repository:
```
git clone https://gitlab.com/elad.noor/equilibrator-api.git
cd equilibrator-api
python setup.py install
``` ```
pip install jupyter
curl https://gitlab.com/elad.noor/equilibrator-api/raw/develop/scripts/equilibrator_cmd.ipynb > equilibrator_cmd.ipynb
jupyter notebook
```
Then select the notebook called `equilibrator_cmd.ipynb` and follow the examples in it.
## Example Usage ## Example Usage
...@@ -63,7 +62,7 @@ You can parse a reaction from a KEGG-style reaction string. The example given ...@@ -63,7 +62,7 @@ You can parse a reaction from a KEGG-style reaction string. The example given
is ATP hydrolysis to ADP and inorganic phosphate. is ATP hydrolysis to ADP and inorganic phosphate.
```python ```python
rxn_str = "KEGG:C00002 + KEGG:C00001 = KEGG:C00008 + KEGG:C00009" rxn_str = "kegg:C00002 + kegg:C00001 = kegg:C00008 + kegg:C00009"
rxn = Reaction.parse_formula(rxn_str) rxn = Reaction.parse_formula(rxn_str)
``` ```
...@@ -84,14 +83,14 @@ calculate the standard change in Gibbs potential due to this reaction. ...@@ -84,14 +83,14 @@ calculate the standard change in Gibbs potential due to this reaction.
# You control the pH and ionic strength! # You control the pH and ionic strength!
# ionic strength is in Molar units. # ionic strength is in Molar units.
standard_dg_prime, uncertainty = eq_api.standard_dg_prime(rxn) standard_dg_prime, uncertainty = eq_api.standard_dg_prime(rxn)
print("dG0' = %s \u00B1 %s\n" % (standard_dg_prime, uncertainty)) print(f"dG0' = {standard_dg_prime:.1f} \u00B1 {uncertainty:1.f}")
``` ```
You can also calculate the [reversibility index](https://doi.org/10.1093/bioinformatics/bts317) for this reaction. You can also calculate the [reversibility index](https://doi.org/10.1093/bioinformatics/bts317) for this reaction.
```python ```python
ln_RI = eq_api.ln_reversibility_index(rxn) ln_RI = eq_api.ln_reversibility_index(rxn)
print('ln(Reversibility Index) = %s\n' % ln_RI) print(f"ln(Reversibility Index) = {ln_RI:.1f}")
``` ```
The reversibility index is a measure of the degree of the reversibility of the The reversibility index is a measure of the degree of the reversibility of the
......
...@@ -38,7 +38,6 @@ def main(args): ...@@ -38,7 +38,6 @@ def main(args):
"""Run main script, calculates the reaction Gibbs energy change.""" """Run main script, calculates the reaction Gibbs energy change."""
from equilibrator_api import ( from equilibrator_api import (
Q_, ComponentContribution, Reaction, ureg) # isort:skip Q_, ComponentContribution, Reaction, ureg) # isort:skip
ureg.default_format = ".2f"
p_h = Q_(args.ph) p_h = Q_(args.ph)
assert p_h.check(None) assert p_h.check(None)
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
......
...@@ -62,7 +62,6 @@ def main(args): ...@@ -62,7 +62,6 @@ def main(args):
from equilibrator_api import ( from equilibrator_api import (
Q_, ComponentContribution, Reaction, ureg) # isort:skip Q_, ComponentContribution, Reaction, ureg) # isort:skip
ureg.default_format = ".2f"
p_h = Q_(args.ph) p_h = Q_(args.ph)
assert p_h.check(None) assert p_h.check(None)
...@@ -80,7 +79,7 @@ def main(args): ...@@ -80,7 +79,7 @@ def main(args):
assert temperature.check("[temperature]") assert temperature.check("[temperature]")
sys.stderr.write(f"pH = {p_h}\n") sys.stderr.write(f"pH = {p_h}\n")
sys.stderr.write(f"I = {ionic_strength:.2g}\n") sys.stderr.write(f"I = {ionic_strength}\n")
sys.stderr.write(f"T = {temperature}\n") sys.stderr.write(f"T = {temperature}\n")
sys.stderr.flush() sys.stderr.flush()
......
...@@ -37,6 +37,9 @@ from equilibrator_cache.thermodynamic_constants import ( ...@@ -37,6 +37,9 @@ from equilibrator_cache.thermodynamic_constants import (
default_pMg, default_T, physiological_concentration, default_pMg, default_T, physiological_concentration,
standard_concentration, ureg) standard_concentration, ureg)
ureg.default_format = ".2f"
ureg.setup_matplotlib(True)
ccache = CompoundCache() ccache = CompoundCache()
default_phase = 'aqueous' default_phase = 'aqueous'
......
...@@ -106,7 +106,7 @@ class PhasedReaction(Reaction): ...@@ -106,7 +106,7 @@ class PhasedReaction(Reaction):
compound: Compound compound: Compound
) -> Tuple[PhasedCompound, float]: ) -> Tuple[PhasedCompound, float]:
"""Get the PhasedCompound object by the Compound object.""" """Get the PhasedCompound object by the Compound object."""
# TODO: This is not ideal. We should try to not keep to dictionaries ( # TODO: This is not ideal. We should try to not keep two dictionaries (
# one with Compounds and one with PhasedCompounds). # one with Compounds and one with PhasedCompounds).
for phased_compound, coeff in self.sparse_with_phases.items(): for phased_compound, coeff in self.sparse_with_phases.items():
if phased_compound.compound == compound: if phased_compound.compound == compound:
......
...@@ -159,8 +159,6 @@ class PathwayMDFData(object): ...@@ -159,8 +159,6 @@ class PathwayMDFData(object):
:return: matplotlib Figure :return: matplotlib Figure
""" """
ureg.setup_matplotlib(True)
data_df = self.compound_df.copy() data_df = self.compound_df.copy()
data_df['y'] = np.arange(0, data_df.shape[0]) data_df['y'] = np.arange(0, data_df.shape[0])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment