pkienzle / periodictable

Extensible periodic table for python
http://periodictable.readthedocs.org
Other
135 stars 36 forks source link

Feature proposal: Give means to represent charge in a formula #4

Closed bjodah closed 11 years ago

bjodah commented 12 years ago

Hi again!

Once more I'm trying to see if I can leverage this great package in some preliminary work. I have been looking into using periodictable.formula for parsing user provided formulas. It work great except I cannot see any easy way of incorporating information on charge (to represent ionic species in chemistry).

Consider eg. periodictable.formula('Cu(NH3)4') periodictable.formula('Cu(NH3)4+2')

where +2 would signify a positively charged ion. This is very central to chemistry and electrochemistry in particular.

Since + has already another meaning in the parsing it might be difficult. However, if a trailing sign and number is found perhaps it could be made to signify charge? This information could then be carried along as e.g. the property Formula.charge

E.g.

sodium_ion = periodictable.formula('Na+1') chloride_ion = periodictable.formula('Cl-1') sulphate_ion = periodictable.formula('SO4-2')

Would this interfere in the applications of the package?

Best regards, Björn Dahlgren

pkienzle commented 12 years ago
  1. I would prefer something unambiguous like:

    Mg{2+}Cl{-}2

I'm already using [#] for isotope so this is not out of character.

I can imagine that people will want formulas with multiple charge components, such as

Na+1 Cl-1

Unfortunately, with spaces ignored as in the current parser, this is indistinguishable from

Na + 1Cl-1 
  1. Regardless of the textual representation, there is the problem that charge is currently associated with individual atoms, not with clusters, and we don't have a way to represent something like:

    SO4{2-}

How would you use charged clusters from python? Can you make up an interface and write an example script using that interface? Don't implement it yet, just write a short tutorial on how you envision using it.

Other than the charge itself, what properties would you want to tabulate or calculate for a charged cluster?

I'm sure we can extend the formula representation with minimal impact on the rest of the system, but I'm worried about feature creep: iconic clusters feels like it is outside the scope of a periodic table package since it is no longer looking at the properties of individual elements. What other extensions will you need for you project? Will the organic chemists want an ascii representation of chemical structure next?

Note: In ticket #5 kurtforrester provided a patch to compute charge and mass fraction for a formula, which is an easy enough extension. This does not put a separate charge on the cluster, only on the individual elements, so PO4 would be P{5+}O{2-}4 rather than (PO4){3-}.

This is a small enough extension to existing functionality that I have no problem with including it. Does this satisfy your needs as well?

bjodah commented 11 years ago

Hi Paul,

Sorry for not having got back to you. After having considered your thought on the risk of a feature creep I agree with you. My solution was just to write a really simple wrapper class e.g. Molecule and let it store attributes such as charge and spin state of the molecule.

I agree that it is better to keep the scope of project to the periodic table.

Going in the other direction (instead of up: down): is it possible to in addition to isotopes specify nuclear isomers? It is useful when representing nuclear processes. I guess one could make a wrapper class based upon the isotopes in periodic table but this feature would be more low level than say e.g. the Molcule class I described.

pkienzle commented 11 years ago

I would be interested in having support for isomers. Have you tried yet?