bjodah / chempy

⚗ A package useful for chemistry written in Python
BSD 2-Clause "Simplified" License
544 stars 78 forks source link

How to get molar masses of elements? #165

Closed spizwhiz closed 3 years ago

spizwhiz commented 4 years ago

Thanks for putting this package together, it is useful!

I'm trying to get the mass fraction of each constituent element of a substance, which I had hoped I could do from the substance object itself but haven't figured that one out.

More generally, how can I access the text name or attributes of an element.

I could do this using the dict from Substance.composition, but it returns a dict with keys of z number rather than element name, which seems to be required by chempy.mass_fractions

any way to map z number back to the text element name? it seems like this dictionary probably exits in the code somewhere to return the Substance.composition dictionary in the first place..

Thanks,

bjodah commented 4 years ago

Glad to hear that you find it useful,

You can split the composition dictionary into multiple ones with just a single key in each, and then use: https://github.com/bjodah/chempy/blob/6e2008577f0d8b866fa31852e99912e8bd90e568/chempy/util/periodic.py#L94

bjodah commented 4 years ago

Oh and the symbol names are in the same file: from chempy.util.periodic import symbols

matecsaj commented 4 years ago

See issue #172 for a relevant bit of code.

bjodah commented 3 years ago

I'm closing this, feel free to re-open if need be. Also, a PR with additions to e.g. documentation or README is of course always welcomed.