Closed ELarrea587 closed 4 years ago
Hi,
There is no default method, but it's fairly simple to calculate the balance from the speciation using something like the method below:
def get_balance(solution):
reg = r"([+-]\d?)"
balance = 0
for st, mol in solution.species.items():
match = re.findall(reg,st) # get charge ("+", "+2", "-", "-2", etc.)
charge = match[0] if len(match) > 0 else "00" # if no charge
charge = charge+"1" if len(charge) == 1 else charge # add a 1 to + or -
balance += int(charge) * mol # calculate balance
return balance
Does that answer your question?
It answers my question very well. Thank you for your help!
Hi, Is there a method to get the charge balance in equivalents (and/or percent error) for a solution. I want to know if my solutions are electrically balanced and possibly manipulate an element to achieve balance. Thank you!