-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Problem:
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
AtomandIsotopeinstances fromFormula.atomsand theiratom_symbols fromFormula.atom_stoich.keys()is not defined byatom.symbol, but rather appears to be built up through a series ofif ... elsecases. However they appear to match.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels