Question

I write script which needs to know atomic mass of tin. Is there a python database which has such info?

Edit:

periodictable is nice, but some libs are more rich in data. For example gperiodic program.

Était-ce utile?

La solution

You could have simply googled before asking. But anyway, you might find this useful: http://pypi.python.org/pypi/periodictable. Below is an example straight out of the page.

>>> from periodic import element
>>> hydrogen = element('hydrogen')
>>> hydrogen.mass
1.0079

Autres conseils

Not python specific, but the Blue Obelisk data repository hosted at Sourceforge is a comprehensive repo of chemistry data in XML format, in case that is of any use to you (or anyone else finding this).

A periodic table and a true chemical database are quite different I suggest you to change the title of your question! There are more then 90 million organic and inorganic substances in CAS database! A chemical database written completely in Python is not the best choice at all to deal with so many records and would be tremendously slow!

It is better to use a python wrapper to allow to use Python to access an external chemical database I like chemspipy the Python wrapper for ChemSpider. It is easy to install with Pip but you need to register (but it is free) to RSC.

Here a little example:

In [1]: from chemspipy import ChemSpider

In [2]: cs=ChemSpider('Here goes your personal code')

In [3]: tin=cs.simple_search('tin') #I use simple_search because search doesn't work for me

In [4]: print tin
[Compound(4509318)]                        

In [5]: tin[0].molecular_formula
Out[5]: u'Sn'

In [6]: tin[0].molecular_weight
Out[6]: 118.71
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top