SymbolicML / DynamicQuantities.jl

Efficient and type-stable physical quantities in Julia
https://symbolicml.org/DynamicQuantities.jl/dev/
Apache License 2.0
120 stars 15 forks source link

Molar units not supported #127

Closed TorkelE closed 3 months ago

TorkelE commented 3 months ago

Molar (different from moles) are commonly used in chemistry and biology. It would be useful to support it:

Amount in molar. Available variant: pM, nM, μM (/uM), mM.

(Molarity is defined as moles per litre, e.g. M = mol/L)

MilesCranmer commented 3 months ago

Can we call it 1 Molar instead of 1 M? Otherwise I worry about ambiguity with M for Mega (SI prefix).

But apart from that I'm happy to review a PR on this.

TorkelE commented 3 months ago

Don't think I've actually seen it written "Molar", not a full-blooded chemist/biologists though (but I could ask one how weird it would be). "Molar" is better than not having it at all though.

MilesCranmer commented 3 months ago

What do other units packages do here? If there’s precedent it’s easier to decide on. e.g., what do Unitful, Pint, AstroPy do?

Also note there is @register_unit in the meantime.

TorkelE commented 3 months ago

If I interpret it correct, it is defined as M in both Unitful and Pint: Unitful (https://github.com/PainterQubits/Unitful.jl/blob/fbf71a66d475423c65bd6e981794e9298ded79da/src/pkgdefaults.jl#L179, line 350) Pint (https://github.com/hgrecco/pint/blob/master/pint/default_en.txt, line 353

AstroPy has it defined as mol, I think (https://github.com/astropy/astropy/blob/878cc772cd648300367930707f7f6a1f1e5e4172/astropy/units/physical.py#L45, line 45), while seems bad since it is easily confused with mole.

We also use it in Catalyst's current tests for units (which depends on Unitful, but which we want to move to DynamicQuantities): https://github.com/SciML/Catalyst.jl/blob/master/test/miscellaneous_tests/units.jl

MilesCranmer commented 3 months ago

Thanks! Okay since Unitful and Pint both do M, and since you have a use case, that seems like a good enough reason to do it here as well. So happy to take a PR for this.

TorkelE commented 3 months ago

Thanks, I will try to get to it this coming week

MilesCranmer commented 3 months ago

Closed with #128