Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when converting physics constant in atomic units #11

Closed
mesonepigreco opened this issue Sep 8, 2024 · 2 comments
Closed

Bug when converting physics constant in atomic units #11

mesonepigreco opened this issue Sep 8, 2024 · 2 comments

Comments

@mesonepigreco
Copy link

Dear developers,
When trying to convert physics constants into atomic units, I get the wrong behaviour:

julia> using Unitful, UnitfulAtomic
julia> using PhysicsConstants.CODATA2018: m_u
julia> m_u
Atomic mass constant (m_u)
Value                         = 1.6605390666e-27 kg
Standard uncertainty          = 5.0e-37 kg
Relative standard uncertainty = 3.0e-10
Reference                     = CODATA 2018

julia> aunit(m_u)
mₑ

julia> uconvert(u"kg", 1.0 * aunit(m_u))
9.1093837015e-31 kg

Which is indeed wrong, as m_u should be 1.6605390666e-27 kg, as specified by physics constants. Is this a bug of UnitfulAtomic?

@sostock
Copy link
Owner

sostock commented Sep 8, 2024

m_u should be 1.6605390666e-27 kg

Yes, m_u should be (and is in fact) equal to 1.6605390666e-27 kg. But aunit(m_u) is not the same thing as m_u.

julia> aunit(m_u)
mₑ

Maybe it is difficult to see, but the result has a subscript e (not u), referring to the electron rest mass. In Hartree atomic units, the unit of mass is the electron rest mass, not the atomic mass constant.

So the result is correct: aunit(m_u) returns the electron rest mass (UnitfulAtomics.me_au, printed as mₑ), which is equal to 9.1093837015e-31 kg.

@mesonepigreco
Copy link
Author

Hi, thanks for the explanation. I was confusing auconvert(m_u) with aunit(m_u).
Indeed, aunit returns only the unit type, which is the electron mass, while auconvert does what I was expecting (converting into atomic units).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants