3

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.

Adobe
  • 12,967
  • 10
  • 85
  • 126

3 Answers3

9

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
UltraInstinct
  • 43,308
  • 12
  • 81
  • 104
6

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).

Drew Gibson
  • 1,624
  • 3
  • 18
  • 22
  • 1
    I've built the sources (bodr-9). Almost no docs are found. I'll try to parse it into python using some xml parsers - to check what kind of data it possess. Or perhaps I'll first convert it to json. – Adobe Jun 01 '12 at 09:45
4

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
G M
  • 20,759
  • 10
  • 81
  • 84