| 1 |
.. _using: |
| 2 |
|
| 3 |
*********** |
| 4 |
Basic usage |
| 5 |
*********** |
| 6 |
|
| 7 |
The periodic table is available on `PyPI <http://pypi.python.org/pypi>`_, |
| 8 |
and can be obtained simply with:: |
| 9 |
|
| 10 |
easy_install periodictable |
| 11 |
|
| 12 |
This will install pyparsing if it is not already available. The numpy |
| 13 |
package must already be installed. |
| 14 |
|
| 15 |
Access particular elements by name: |
| 16 |
|
| 17 |
.. doctest:: |
| 18 |
|
| 19 |
>>> from periodictable import hydrogen |
| 20 |
>>> print("H mass %s %s"%(hydrogen.mass, hydrogen.mass_units)) |
| 21 |
H mass 1.008 u |
| 22 |
|
| 23 |
Access particular elements as symbols: |
| 24 |
|
| 25 |
.. doctest:: |
| 26 |
|
| 27 |
>>> from periodictable import H,B,Cu,Ni |
| 28 |
>>> print("B absorption %s"%B.neutron.absorption) |
| 29 |
B absorption 767.0 |
| 30 |
>>> print("Ni f1/f2 for Cu K-alpha X-rays f'=%.5f f''=%.5f" |
| 31 |
... % Ni.xray.scattering_factors(wavelength=Cu.K_alpha)) |
| 32 |
Ni f1/f2 for Cu K-alpha X-rays f'=25.02293 f''=0.52491 |
| 33 |
|
| 34 |
Access isotopes using mass number subscripts: |
| 35 |
|
| 36 |
.. doctest:: |
| 37 |
|
| 38 |
>>> print("58-Ni vs 62-Ni scattering %s:%s"%(Ni[58].neutron.coherent, Ni[62].neutron.coherent)) |
| 39 |
58-Ni vs 62-Ni scattering 26.1:9.5 |
| 40 |
|
| 41 |
Access elements indirectly: |
| 42 |
|
| 43 |
.. doctest:: |
| 44 |
|
| 45 |
>>> import periodictable |
| 46 |
>>> print("Cd density %.2f %s"%(periodictable.Cd.density, periodictable.Cd.density_units)) |
| 47 |
Cd density 8.65 g/cm^3 |
| 48 |
|
| 49 |
Import all elements: |
| 50 |
|
| 51 |
.. doctest:: |
| 52 |
|
| 53 |
>>> from periodictable import * |
| 54 |
>>> print(periodictable.H) |
| 55 |
H |
| 56 |
>>> print(periodictable.H.mass) |
| 57 |
1.008 |
| 58 |
|
| 59 |
Deuterium and tritium are special isotopes named D and T: |
| 60 |
|
| 61 |
.. doctest:: |
| 62 |
|
| 63 |
>>> print("D mass %s"%D.mass) |
| 64 |
D mass 2.01410177784 |
| 65 |
|
| 66 |
Process all the elements: |
| 67 |
|
| 68 |
.. doctest:: |
| 69 |
|
| 70 |
>>> import periodictable |
| 71 |
>>> for el in periodictable.elements: # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 72 |
... print("%s %s"%(el.symbol,el.name)) |
| 73 |
H hydrogen |
| 74 |
He helium |
| 75 |
... |
| 76 |
Og oganesson |
| 77 |
|
| 78 |
Another example for processing all elements: |
| 79 |
|
| 80 |
.. doctest:: |
| 81 |
|
| 82 |
>>> from periodictable import elements |
| 83 |
>>> for el in elements: # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 84 |
... print("%s %s"%(el.symbol,el.number)) |
| 85 |
H 1 |
| 86 |
He 2 |
| 87 |
... |
| 88 |
|
| 89 |
Process all the :class:`isotopes <periodictable.core.Isotope>` for an element: |
| 90 |
|
| 91 |
.. doctest:: |
| 92 |
|
| 93 |
>>> for iso in periodictable.H: |
| 94 |
... print("%s %s"%(iso,iso.mass)) |
| 95 |
1-H 1.0078250319 |
| 96 |
D 2.01410177784 |
| 97 |
T 3.01604928132 |
| 98 |
4-H 4.02643 |
| 99 |
5-H 5.03531 |
| 100 |
6-H 6.04496 |
| 101 |
|
| 102 |
You can create a unique handle to an individual ion. In addition to storing |
| 103 |
the ion charge, this can be used to reference the underlying properties of |
| 104 |
the element or isotope: |
| 105 |
|
| 106 |
.. doctest:: |
| 107 |
|
| 108 |
>>> Ni58_2 = periodictable.Ni[58].ion[2] |
| 109 |
>>> Ni_2 = periodictable.Ni.ion[2] |
| 110 |
>>> print("charge for Ni2+ is %d"%Ni_2.charge) |
| 111 |
charge for Ni2+ is 2 |
| 112 |
>>> print("mass for Ni[58] and for natural abundance: %.4f %.4f"%(Ni58_2.mass, Ni_2.mass)) |
| 113 |
mass for Ni[58] and for natural abundance: 57.9342 58.6923 |
| 114 |
|
| 115 |
The ion specific properties can be accessed from the ion using ion.charge |
| 116 |
for the ion index: |
| 117 |
|
| 118 |
.. doctest:: |
| 119 |
|
| 120 |
>>> import periodictable |
| 121 |
>>> Fe_2 = periodictable.Fe.ion[2] |
| 122 |
>>> print("[%.5f, %.5f, %.5f]" |
| 123 |
... % tuple(Fe_2.magnetic_ff[Fe_2.charge].M_Q([0,0.1,0.2]))) |
| 124 |
[1.00000, 0.99935, 0.99741] |
| 125 |
|
| 126 |
The following is a plot of the magnetic form factor vs. Q: |
| 127 |
|
| 128 |
.. doctest:: |
| 129 |
|
| 130 |
>>> import pylab # doctest: +SKIP |
| 131 |
>>> Q = pylab.linspace(0,16,200) # doctest: +SKIP |
| 132 |
>>> M = Fe_2.magnetic_ff[Fe_2.charge].j0_Q(Q) # doctest: +SKIP |
| 133 |
>>> pylab.xlabel(r'Magnetic Form Factor for Fe') # doctest: +SKIP |
| 134 |
>>> pylab.ylabel(r'$\AA^{-1}$') # doctest: +SKIP |
| 135 |
>>> pylab.title('Ion specific property for Fe') # doctest: +SKIP |
| 136 |
>>> pylab.plot(Q,M) # doctest: +SKIP |
| 137 |
|
| 138 |
.. plot:: plots/magnetic_ff.py |
| 139 |
|
| 140 |
Missing properties generally evaluate to *None*: |
| 141 |
|
| 142 |
.. doctest:: |
| 143 |
|
| 144 |
>>> print("Radon density %s"%periodictable.Rn.density) |
| 145 |
Radon density None |
| 146 |
|
| 147 |
|
| 148 |
Specific defined properties related to elements can be accessed in a table format as shown in following example : |
| 149 |
|
| 150 |
.. doctest:: |
| 151 |
|
| 152 |
>>> elements.list('symbol','K_alpha',format="%s K-alpha = %s") # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 153 |
Ne K-alpha = 14.6102 |
| 154 |
Na K-alpha = 11.9103 |
| 155 |
Mg K-alpha = 9.8902 |
| 156 |
Al K-alpha = 8.3402 |
| 157 |
... |
| 158 |
Cf K-alpha = 0.1094 |
| 159 |
Es K-alpha = 0.1067 |
| 160 |
Fm K-alpha = 0.104 |