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

Add formula.element to accumulate across isotopes and ions #66

Closed
wants to merge 4 commits into from

Conversation

pkienzle
Copy link
Collaborator

The existing formula.atoms attribute keeps the isotopes + charges separate when accumulating the components.

This proposal uses formula.elements to accumulate across isotopes and charges. It also adds formula.elements_hill to return a structure in hill notation order.

>>> print(formula("HDS{6+}O{2-}3O[16]{2-}").elements_hill)
H2O4S

Having written this, several questions arise:

  1. Will there be confusion between formula.elements and formula.atoms?
  2. Do we want formula.isotopes for accumulating isotopes without charge?
  3. If we are accumulating isotopes, do we want to turn natural abundance into isotope distributions?

I made the underlying count_elements() function public and gave it a by_isotopes flag.

>>> from periodictable.formulas import count_elements, formula
>>> print(formula(count_elements("HDS{6+}O{2-}3O[16]{2-}")))
H2O4S
>>> print(formula(count_elements("HDS{6+}O{2-}3O[16]{2-}", by_isotope=True)))
HDO3O[16]S

I'll await comments from those who can use this functionality before merging.

Refs #14

@pkienzle pkienzle changed the base branch from master to R1.7 February 13, 2024 22:01
@pkienzle pkienzle changed the base branch from R1.7 to master February 13, 2024 22:17
@pkienzle
Copy link
Collaborator Author

Backing off on the elements/elements_hill attributes, and only providing the count_elements function. This keeps the interface slightly smaller and maybe less confusing than having both .elements and .atoms.

@pkienzle pkienzle closed this Feb 26, 2024
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

Successfully merging this pull request may close these issues.

1 participant