bjodah / chempy

⚗ A package useful for chemistry written in Python
BSD 2-Clause "Simplified" License
545 stars 78 forks source link

balance_stoichiometry raises "ValueError: Component '0' not among reactants" when using the examples provided #92

Closed alibonati closed 5 years ago

alibonati commented 6 years ago

Hi Bjørn

I've used chempy for quite some time (v. 0.4.1). Now I've updated the package as I contemplate including the package in a course I'm teaching. I am, however, now faced with the following issue: I can no longer use balance_stoichiometry in my script. I get the following return: "" File ".....\Python\Python35\site-packages\chempy\chemistry.py", line 1209, in balance_stoichiometry raise ValueError("Component '%s' not among reactants" % ck)"

ValueError: Component '0' not among reactants ""

I've tried with a completely reduced script with photosynthesis: "" import chempy from chempy import balance_stoichiometry from chempy import Substance

substrates = ['CO2','H2O'] products = ['O2','C6H12O6']

bal_reac, bal_prod = balance_stoichiometry(substrates, products) ""

Still the same ValueError is raised. I've tried with executing the examples provided in 'chemistry.py' but I get the same error. I'm using Spyder 3.2.6 and Python 3.6.4. I reverted to v. 0.4.1 and there it works just fine.

I'll look more into it next week, but I just wanted to let you know that there might be a small issue here (maybe the issue is me and not something in the package :))

Have a nice weekend, Andreas

bjodah commented 6 years ago

Hi Andreas,

Glad to hear that you have found the package useful. And thank you for reporting this issue. I don't seem to be able to reproduce this on my end, however.

Running the script you provided:

import chempy
from chempy import balance_stoichiometry
from chempy import Substance

substrates = ['CO2','H2O']
products = ['O2','C6H12O6']

print(balance_stoichiometry(substrates, products))

using ChemPy v0.4.1 I get:

$ git checkout v0.4.1
Previous HEAD position was a8447b9... About to release v0.6.7
HEAD is now at 62f98b5... Merge pull request #35 from bjodah/more-features
✔ ~/vc/chempy [v0.4.1|⚑ 1] 
$ PYTHONPATH=$(pwd) python3 ~/doc/src/repo/chempy/gh92.py 
({'H2O': 6, 'CO2': 6}, {'C6H12O6': 1, 'O2': 6})

and using 0.6.7 I get:

$ git checkout v0.6.7
Previous HEAD position was 62f98b5... Merge pull request #35 from bjodah/more-features
HEAD is now at a8447b9... About to release v0.6.7
✔ ~/vc/chempy [v0.6.7|⚑ 1] 
$ PYTHONPATH=$(pwd) python3 ~/doc/src/repo/chempy/gh92.py 
(OrderedDict([('CO2', 6), ('H2O', 6)]), OrderedDict([('O2', 6), ('C6H12O6', 1)]))

(I also tried all tagged versions in between without errors)

I wonder if there is some issue with a particular version among the dependencies...

bjodah commented 6 years ago

@alibonati you could use binder to create a reproducible example of the error you're experiencing (that way we eliminate differences in setup)

alibonati commented 6 years ago

Hi Bjorn

Sorry for the late reply, I've been busy attending a conference.

Thank you for the suggestion - I've used binder and cannot recreate the problem . The problem is definitely something in my setup. I suspect that it might be because I use conda as my package manager on a Windows system + that I might not have all the necessary libraries (SUNDIALS etc.).

Andreas

bjodah commented 6 years ago

what versions of pyparsing, pulp & sympy do you have in your conda environment?

alibonati commented 6 years ago

pyparsing = 2.2.0 pulp = 1.6.8 sympy = 1.1.1

I tried reinstalling as per the instructions you've provided, and I can now see that I actually get the following error: " AttributeError: '_NamespacePath' object has no attribute 'sort' " which I didn't notice before. This error has been handled (amongst many threads) in https://github.com/pypa/pip/issues/4216 I will try some of the suggestions given there/rid my system of anything python and re-install from scratch and see how that goes.

Andreas