Im not even sure what exactly my problem is from this error. Any information would be very helpful.
what i have so far:
def equations(specie,elements):
vectors=[]
for x in specie:
vector=extracting_columns(x,elements)
vectors.append(vector)
When i run:
equations(['OH', 'CO2','c3o3','H2O3','CO','C3H1'],
['H', 'C', 'O'])
i get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_77.py", line 10, in exec compile(u'print support.syseval(python, u"equations([\'OH\', \'CO2\',\'c3o3\',\'H2O3\',\'CO\',\'C3H1\'], unel)", SAGE_TMP_DIR) File "", line 1, in
File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/devel/sagenb-git/sagenb/misc/support.py", line 479, in syseval return system.eval(cmd, sage_globals, locals = sage_globals) File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/misc/python.py", line 56, in eval eval(z, globals) File "", line 1, in
File "", line 4, in equations
File "", line 3, in extracting_columns
ValueError: need more than 1 value to unpack
my previous functions if needed: import re def parse_formula(formula): '''Given a simple chemical formula, return a list of (element, multiplicity) tuples.
Example:
'H2SO4' --> [('H', 2.0), ('S', 1.0), ('O', 4.0)]
'''
return [ (elem, float(mul) if mul else 1.) for (elem, mul) in re.findall(r'([A-Z][a-z]*)(\d*)', formula) ]
def unique_element(group): c=[] for element in group: piece=parse_formula(element) for x in piece: c.append(x[0])
return list(set(c))
def extracting_columns(specie, elements): species_vector=zeros(len(elements)) for (el,mul) in specie: species_vector[elements.index(el)]=mul
return species_vector