cgohlke / molmass

Molecular mass calculations
https://pypi.org/project/molmass
BSD 3-Clause "New" or "Revised" License
56 stars 13 forks source link

Minor bug, possible to calculate the molar mass of not existing molecules as WQ #14

Closed WWilhelmsen closed 7 months ago

WWilhelmsen commented 7 months ago

In a test of this program it was possible to find the molar mass of WQ which does not exist: Program code:

import molar mass as mol
f = mol.Formula('WQ')
Mm=f.mass
print(mm)

The result was 332.355092 The molecular mass of AQ, CQ is also possible to calculate but not BQ. This error is not so serious in normal use of the module but should have been corrected

cgohlke commented 7 months ago

Molmass recognizes 'WQ' as a peptide of Tryptophan and Glutamine. Besides the chemical elements, Deuterium, many chemical groups, peptide sequences, and oligonucleotide sequences are recognized. There is currently no option to disable this. I'll look into that.

>>> Formula('WQ')
Formula('((C5H8N2O2)(C11H10N2O)H2O)')
cgohlke commented 7 months ago

Would this work for you?

>>> Formula('WQ', parse_oligos=False).formula
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Python311\Lib\functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "molmass\molmass.py", line 628, in formula
    return from_elements(self._elements, charge=self._charge)
                         ^^^^^^^^^^^^^^
  File "Python311\Lib\functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "molmass\molmass.py", line 541, in _elements
    raise FormulaError(
molmass.molmass.FormulaError: unexpected character 'Q'
WQ
.^