Open meowcat opened 1 year ago
@michaelwitting
Not out of scope. We can add changes for this. In my opion charged formulas should be supplied exactly in the format you mentioned, e.g. [C6H12]+
. Multiple charges would be 2+
, 3+
or 2-
.
@jorainer would that be okay as input?
IMHO it would be best if calculateMass
would identify the charge automatically and return the correct mass.
maybe best to have one function
charge
that takes formulas (character
) and returns their charges (integer
) - (function name might not be ideal though).stripCharge
)? - and along that line, maybe also one that adds charges to formulas (so that we can ensure that they have the correct format)happy for a PR :)
I can fiddle around a bit, but what do we want as input?
[C6H12]+
calculateMass
, e.g. calculateMass("C6H12", charge = "1+")
I would prefer the first option
I would also say the first option (i.e. "[C6H12]+"
) - ideally also supporting a character
vector of several formulas and not just a single one.
The way I think it through now, calculateMass()
would in future only accept character
and no preparsed lists. Except we put the parsing of charges in the countElements()
function
we also have isotope detection/parsing in there (calculateMass
? countElements
?), right? maybe would make most sense to do that in the same function?
don't know if the previous comment made sense... what I mean: put that into the same function that does already the parsing to avoid needing to parse the input twice (once e.g. counting elements and once getting the charge). but this will also depend a bit how complicated it would be - if it's too difficult or blows up the code we could do it in two separate steps (i.e. a dedicated function that retrieves the charge from a character
). maybe it would even be good to just focus first on the latter, to have a clean (separate) implementation to derive the charge from a character
so that we can test and then later improve?
Currently
calculateMass("[C6H12]+") == calculateMass("C6H12")
Strictly, this should becalculateMass("[C6H12]+") == calculateMass("C6H12") - .emass
where.emass == 0.0005485799
Questions:calculateMass("[C6H12]+")
out-of-scope for this function, and should this throw a warning or error?calculateMass(x, charge)
?Note: the
rcdk
equivalent isget.formula(formula, charge)@mass
. Notably, get.formula("[C6H6]+") also does not account for the charge (but creates the neutral formula). However here the user can specify the charge manually.