You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Formula('He+42') happily executes, while the maximal charge should be 2:
In [1]: Formula('He+42').charge
Out[1]: 42
Suggested solution:
Ensure the total atomic number of Formula instance is greater or equal than the charge:
In [47]: formula = Formula('CH4+42')
...: total_atomic_number = sum(formula.atom_stoich[atom.symbol] * atom.Z for atom in formula.atoms)
...: if total_atomic_number < formula.charge:
...: raise FormulaParseError(f'Charge {formula.charge} if greater than the total atomic number {total_atomic_number}!')
...:
...:
---------------------------------------------------------------------------
FormulaParseError Traceback (most recent call last)
<ipython-input-47-b8fa6fbad41d> in <module>
2 total_atomic_number = sum(formula.atom_stoich[str(atom)] * atom.Z for atom in formula.atoms)
3 if total_atomic_number < formula.charge:
----> 4 raise FormulaParseError(f'Charge {formula.charge} if greater than the total atomic number {total_atomic_number}!')
5
FormulaParseError: Charge 42 if greater than the total atomic number 10!
Problems with the suggested solution:
Some formulas do not define charge
The mapping between the Atom and Isotope instances from Formula.atoms and their atom_symbols from Formula.atom_stoich.keys() is not defined by atom.symbol, but rather appears to be built up through a series of if ... else cases. However they appear to match.
The text was updated successfully, but these errors were encountered:
Problem:
Currently,
Formula('He+42')
happily executes, while the maximal charge should be 2:Suggested solution:
Ensure the total atomic number of Formula instance is greater or equal than the charge:
Problems with the suggested solution:
Atom
andIsotope
instances fromFormula.atoms
and theiratom_symbol
s fromFormula.atom_stoich.keys()
is not defined byatom.symbol
, but rather appears to be built up through a series ofif ... else
cases. However they appear to match.The text was updated successfully, but these errors were encountered: