!pip install pymatgen
from pymatgen.core.periodic_table import Element
from pandas import DataFrame
Requirement already satisfied: pymatgen in /usr/local/lib/python3.6/dist-packages (2019.12.22) Requirement already satisfied: palettable>=3.1.1 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (3.3.0) Requirement already satisfied: spglib>=1.9.9.44 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.14.1.post0) Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from pymatgen) (2.21.0) Requirement already satisfied: dataclasses>=0.6; python_version < "3.7" in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.7) Requirement already satisfied: numpy>=1.14.3 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.17.4) Requirement already satisfied: sympy in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.1.1) Requirement already satisfied: ruamel.yaml>=0.15.6 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.16.5) Requirement already satisfied: monty>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (3.0.2) Requirement already satisfied: networkx>=2.2 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (2.4) Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.25.3) Requirement already satisfied: scipy>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (1.3.3) Requirement already satisfied: matplotlib>=1.5 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (3.1.2) Requirement already satisfied: pydispatcher>=2.0.5 in /usr/local/lib/python3.6/dist-packages (from pymatgen) (2.0.5) Requirement already satisfied: tabulate in /usr/local/lib/python3.6/dist-packages (from pymatgen) (0.8.6) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (2019.11.28) Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (1.24.3) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (3.0.4) Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->pymatgen) (2.8) Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.6/dist-packages (from sympy->pymatgen) (1.1.0) Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.8" in /usr/local/lib/python3.6/dist-packages (from ruamel.yaml>=0.15.6->pymatgen) (0.2.0) Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx>=2.2->pymatgen) (4.4.1) Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas->pymatgen) (2018.9) Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.6/dist-packages (from pandas->pymatgen) (2.6.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (2.4.5) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (0.10.0) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=1.5->pymatgen) (1.1.0) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.6.1->pandas->pymatgen) (1.12.0) Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver>=1.0.1->matplotlib>=1.5->pymatgen) (42.0.2)
elements_ = []
for elem in dir(Element):
if not elem.startswith('_'):
if Element(elem)is not None:
elements_.append(elem)
else:
print('# of elements:', len(elements_))
# of elements: 103
["mendeleev_no", "electrical_resistivity",
"velocity_of_sound", "reflectivity",
"refractive_index", "poissons_ratio", "molar_volume",
"electronic_structure", "thermal_conductivity",
"boiling_point", "melting_point",
"critical_temperature", "superconduction_temperature",
"liquid_range", "bulk_modulus", "youngs_modulus",
"brinell_hardness", "rigidity_modulus",
"mineral_hardness", "vickers_hardness",
"density_of_solid", "atomic_radius_calculated",
"van_der_waals_radius", "atomic_orbitals",
"coefficient_of_linear_thermal_expansion",
"ground_state_term_symbol", "valence"]
Several elements don't have the data
list_atomic_orbitals = [Element(elem).atomic_orbitals for elem in elements_]
list_atomic_orbitals = [{} if a_orbits is None else a_orbits for a_orbits in list_atomic_orbitals]
df_orbits = DataFrame(list_atomic_orbitals, index=elements_).fillna(0.)
df_orbits.sample(5)
1s | 2p | 2s | 3d | 3p | 3s | 4d | 4f | 4p | 4s | 5d | 5p | 5s | 6d | 6p | 6s | 7s | 5f | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Ge | -396.292991 | -43.720129 | -49.055282 | -1.117316 | -4.194822 | -5.961472 | 0.000000 | 0.000000 | -0.149882 | -0.426523 | 0.000000 | 0.000000 | 0.000000 | 0.0 | 0.0 | 0.000000 | 0.0 | 0.0 |
Gd | -1728.625195 | -262.081616 | -275.363130 | -43.754556 | -54.836922 | -60.764408 | -5.531835 | -0.489012 | -9.669866 | -11.986486 | -0.127220 | -0.978749 | -1.608477 | 0.0 | 0.0 | -0.143627 | 0.0 | 0.0 |
Md | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.0 | 0.0 | 0.000000 | 0.0 | 0.0 |
Sm | -1617.183426 | -242.729726 | -255.498846 | -39.528656 | -50.084260 | -55.731133 | -4.814978 | -0.217760 | -8.672685 | -10.844667 | 0.000000 | -0.835987 | -1.408552 | 0.0 | 0.0 | -0.128259 | 0.0 | 0.0 |
Ta | -2275.371387 | -357.248334 | -372.828724 | -63.942521 | -77.440942 | -84.658467 | -8.265848 | -1.199347 | -13.719810 | -16.713337 | -0.182464 | -1.376530 | -2.223807 | 0.0 | 0.0 | -0.174814 | 0.0 | 0.0 |
atomic_orbitals
¶list_attrs = ["mendeleev_no", "electrical_resistivity",
"velocity_of_sound", "reflectivity",
"refractive_index", "poissons_ratio", "molar_volume",
"electronic_structure", "thermal_conductivity",
"boiling_point", "melting_point",
"critical_temperature", "superconduction_temperature",
"liquid_range", "bulk_modulus", "youngs_modulus",
"brinell_hardness", "rigidity_modulus",
"mineral_hardness", "vickers_hardness",
"density_of_solid", "atomic_radius_calculated",
"van_der_waals_radius",
"coefficient_of_linear_thermal_expansion",
"ground_state_term_symbol", "valence"]
Identified the combination of attributes and elements that cause errors.
for elem in elements_:
e = Element(elem)
for attr in list_attrs:
try:
getattr(e, attr)
except TypeError:
print(elem, attr)
except IndexError:
print(elem, attr)
except ValueError:
print(elem, attr)
Ar ground_state_term_symbol Ba ground_state_term_symbol Ba valence Be ground_state_term_symbol Be valence Ca ground_state_term_symbol Ca valence Cd ground_state_term_symbol Cd valence Ce ground_state_term_symbol Ce valence Cm ground_state_term_symbol Cm valence Cr ground_state_term_symbol Cr valence Gd ground_state_term_symbol Gd valence He ground_state_term_symbol Hg ground_state_term_symbol Hg valence Kr ground_state_term_symbol Mg ground_state_term_symbol Mg valence Mo ground_state_term_symbol Mo valence Nb ground_state_term_symbol Nb valence Ne ground_state_term_symbol No ground_state_term_symbol No valence Np ground_state_term_symbol Np valence Pa ground_state_term_symbol Pa valence Pd ground_state_term_symbol Pd valence Pt ground_state_term_symbol Pt valence Ra ground_state_term_symbol Ra valence Rh ground_state_term_symbol Rh valence Rn ground_state_term_symbol Ru ground_state_term_symbol Ru valence Sr ground_state_term_symbol Sr valence U ground_state_term_symbol U valence Xe ground_state_term_symbol Yb ground_state_term_symbol Yb valence Zn ground_state_term_symbol Zn valence
from pymatgen.core.units import FloatWithUnit
list_attrs_numel = []
isa_ = lambda v, dtype: type(v)is dtype
for elem in elements_:
e = Element(elem)
for attr in list_attrs[:-2]:
value = getattr(e, attr)
if isa_(value,FloatWithUnit) or isa_(value,float) or isa_(value,int):
list_attrs_numel.append(attr)
else:
print(len(set(list_attrs_numel)), set(list_attrs_numel))
23 {'molar_volume', 'boiling_point', 'bulk_modulus', 'vickers_hardness', 'superconduction_temperature', 'poissons_ratio', 'rigidity_modulus', 'density_of_solid', 'mendeleev_no', 'critical_temperature', 'velocity_of_sound', 'mineral_hardness', 'van_der_waals_radius', 'electrical_resistivity', 'brinell_hardness', 'melting_point', 'liquid_range', 'coefficient_of_linear_thermal_expansion', 'youngs_modulus', 'refractive_index', 'reflectivity', 'atomic_radius_calculated', 'thermal_conductivity'}
Get attributes again.
def c_(value):
"""Safe cast from FloatWithUnit, float and int to float, float and int"""
if isa_(value, FloatWithUnit):
return float(value)
else:
return value
list_attrs_numel = list(set(list_attrs_numel)) # uniquify
data_array = [ [c_(getattr(Element(elem), attr))for attr in list_attrs_numel] for elem in elements_]
df_attrs = DataFrame(data_array, index=elements_, columns=list_attrs_numel).fillna(0.)
df_attrs.sample(10)
molar_volume | boiling_point | bulk_modulus | vickers_hardness | superconduction_temperature | poissons_ratio | rigidity_modulus | density_of_solid | mendeleev_no | critical_temperature | velocity_of_sound | mineral_hardness | van_der_waals_radius | electrical_resistivity | brinell_hardness | melting_point | liquid_range | coefficient_of_linear_thermal_expansion | youngs_modulus | refractive_index | reflectivity | atomic_radius_calculated | thermal_conductivity | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Tb | 19.30 | 3503.0 | 38.7 | 863.0 | 0.00 | 0.26 | 22.0 | 8219.0 | 26.0 | 0.0 | 2620.0 | 0 | 0.00 | 1.150000e-06 | 677.0 | 1629 | 1874.00 | 0.000010 | 56.0 | 0 | 0.0 | 2.25 | 11.0 |
Fm | 0.00 | 0.0 | 0.0 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 | 37.0 | 0.0 | 0.0 | 0 | 0.00 | 0.000000e+00 | 0.0 | 1800 | 0.00 | 0.000000 | 0.0 | 0 | 0.0 | 0.00 | 0.0 |
Lr | 0.00 | 0.0 | 0.0 | 0.0 | 0.00 | 0.00 | 0.0 | 0.0 | 34.0 | 0.0 | 0.0 | 0 | 0.00 | 0.000000e+00 | 0.0 | 1900 | 0.00 | 0.000000 | 0.0 | 0 | 0.0 | 0.00 | 0.0 |
Os | 8.42 | 5285.0 | 0.0 | 0.0 | 0.66 | 0.25 | 222.0 | 22610.0 | 63.0 | 0.0 | 4940.0 | 7 | 0.00 | 8.100000e-08 | 3920.0 | 3306 | 1979.00 | 0.000005 | 0.0 | 0 | 0.0 | 1.85 | 88.0 |
Mg | 14.00 | 1363.0 | 45.0 | 0.0 | 0.00 | 0.29 | 17.0 | 1738.0 | 73.0 | 0.0 | 4602.0 | 2.5 | 1.73 | 4.400000e-08 | 260.0 | 923 | 440.00 | 0.000008 | 45.0 | 0 | 74.0 | 1.45 | 160.0 |
Li | 13.02 | 1615.0 | 11.0 | 0.0 | 0.00 | 0.00 | 4.2 | 535.0 | 12.0 | 3223.0 | 6000.0 | 0.6 | 1.82 | 9.500000e-08 | 0.0 | 453.69 | 1161.31 | 0.000046 | 4.9 | 0 | 0.0 | 1.67 | 85.0 |
Y | 19.88 | 3609.0 | 41.0 | 0.0 | 1.30 | 0.24 | 26.0 | 4472.0 | 25.0 | 0.0 | 3300.0 | 0 | 0.00 | 6.000000e-07 | 589.0 | 1799 | 1810.00 | 0.000011 | 64.0 | 0 | 0.0 | 2.12 | 17.0 |
Np | 11.59 | 4273.0 | 0.0 | 0.0 | 0.00 | 0.00 | 0.0 | 20450.0 | 44.0 | 0.0 | 0.0 | 0 | 0.00 | 1.200000e-06 | 0.0 | 910 | 3363.00 | 0.000000 | 0.0 | 0 | 0.0 | 0.00 | 6.0 |
Si | 12.06 | 3173.0 | 100.0 | 0.0 | 0.00 | 0.00 | 0.0 | 2330.0 | 85.0 | 0.0 | 2200.0 | 6.5 | 2.10 | 1.000000e-03 | 0.0 | 1687 | 1486.00 | 0.000003 | 47.0 | 0 | 28.0 | 1.11 | 150.0 |
Pm | 20.23 | 3273.0 | 33.0 | 0.0 | 0.00 | 0.28 | 18.0 | 7264.0 | 29.0 | 0.0 | 0.0 | 0 | 0.00 | 7.500000e-07 | 0.0 | 1373 | 1900.00 | 0.000011 | 46.0 | 0 | 0.0 | 2.05 | 15.0 |