<jupyter_start><jupyter_text>Author: <NAME>Date: 2019-05-07<jupyter_code>import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
from adjustText import adjust_text
from pymatgen.core.periodic_table import Element
plt.rc('xtick',labelsize=24)
plt.rc('ytick',labelsize=24)
font = {'size'   : 22}
params = {'legend.fontsize': 20,
          'legend.handlelength': 2}
plt.rcParams.update(params)
plt.rc('font', **font)<jupyter_output><empty_output><jupyter_text>Load elemental resistivity and molar refractivity values<jupyter_code>res = pd.read_excel("../../data/hammerfeld_criterion/Elemental_conductivities.xlsx")
ref = pd.read_csv("../../data/hammerfeld_criterion/molar_refractivities.csv")<jupyter_output><empty_output><jupyter_text>Convert conductivity units to (ohm*cm)-1<jupyter_code># res['electrical_conductivity'] = res['Electrical Conductivity Ang'] * 10**6
res['electrical_conductivity'] = res['Electrical Conductivity Wolfram']/100
res.head()
res.loc[res['Symbol']=='P', 'electrical_conductivity'] = 1e-11
res.loc[res['Symbol']=='P']
ref.head()<jupyter_output><empty_output><jupyter_text>Join the resistivity and refractivity tables together<jupyter_code>df = ref.merge(res, how='left', right_on='Symbol', left_on='Atom')
df.head()<jupyter_output><empty_output><jupyter_text>Add element group numbers<jupyter_code>def get_groups(name):
    """Find group numbers of the elements"""
    elems = ['Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb',
                  'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu',
                  'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk']
    if name in elems:
        g = 3 # Lanthanides are put into group 3
    else:
        g = Element(name).group
    return g
df['Group'] = df['Atom'].apply(get_groups)

df.head()
df.loc[df['Atom']=='Hg']<jupyter_output><empty_output><jupyter_text>Define classes for plotting purposes<jupyter_code>def get_class(name):
    """Identify whether element is metal, metalloid, or non-metal."""
    metalloids = ['B', 'Si', 'Ge', 'As', 'Sb', 'Te', 'Po', 'At']
    extra_metals = [13, 31, 49, 81, 50, 82, 83]
    group = df[df['Atom'] == name]['Group'].iloc[0]
    if name in metalloids:
        class_name = 'Metalloid'
    elif group <= 12 or df[df['Atom'] == name]['Atomic number'].iloc[0] in extra_metals:
        class_name = 'Metal'
    else:
        class_name = 'Non-metal'
    return class_name
df['Class'] = df['Atom'].apply(get_class)
df.head()<jupyter_output><empty_output><jupyter_text>Show resistivity vs. R/V<jupyter_code>fig, ax = plt.subplots(figsize=(10,10))
ax.scatter(df[df['Class'] == 'Metal']['R/V'], 
           df[df['Class'] == 'Metal']['electrical_conductivity'], 
           s=50, marker='v', 
           c='blue',
           label='Metal')
ax.scatter(df[df['Class'] == 'Metalloid']['R/V'], 
           df[df['Class'] == 'Metalloid']['electrical_conductivity'], 
           s=50, 
           marker='o', 
           c='purple',
           label='Metalloid')
ax.scatter(df[df['Class'] == 'Non-metal']['R/V'], 
           df[df['Class'] == 'Non-metal']['electrical_conductivity'], 
           s=50, 
           marker='^', 
           c='red',
           label='Non-metal')
# ax.scatter(df['R/V'], df['electrical_conductivity'], s=50)
ax.set_xlabel('R/V', fontsize=24)
ax.set_ylabel(r'Electrical conductivity ($\Omega^{-1}$cm$^{-1}$)', fontsize=24)
ax.set_yscale('log')
ax.set_ybound(lower=1e-18, upper=1e6)
labels = df['Atom']
for i in range(len(df['electrical_conductivity'])):
    if math.isnan(df['electrical_conductivity'].iloc[i]) or math.isnan(df['R/V'].iloc[i]):
        continue
    ax.annotate(labels.iloc[i], 
                (df['R/V'].iloc[i]+0.05,
                 df['electrical_conductivity'].iloc[i]-0.7*df['electrical_conductivity'].iloc[i]),
               fontsize=20)
#     if labels.iloc[i] == 'P':
#         print(labels.iloc[i])
line = plt.Line2D([1, 1], [0, 1e8], color='red', ls='dashed')
ax.add_line(line)
ax.legend()
plt.tight_layout()
plt.savefig("../../plots/goldhammer_herzfeld_elements/conductivity_RV.pdf", dpi=200, bbox_inches='tight')
plt.show()<jupyter_output><empty_output><jupyter_text>Plot R/V vs. Group<jupyter_code>fig, ax = plt.subplots(figsize=(14,8))
# scat = ax.scatter(df['Group'], df['R/V'], s=60)
ax.scatter(df[df['Class'] == 'Metal']['Group'], 
           df[df['Class'] == 'Metal']['R/V'], 
           s=60, marker='v', 
           c='#f2e052',
           label='Metal')
ax.scatter(df[df['Class'] == 'Metalloid']['Group'], 
           df[df['Class'] == 'Metalloid']['R/V'], 
           s=60, 
           marker='o', 
           c='#cc715a',
           label='Metalloid')
ax.scatter(df[df['Class'] == 'Non-metal']['Group'], 
           df[df['Class'] == 'Non-metal']['R/V'], 
           s=60, 
           marker='^', 
           c='#8cb4fa',
           label='Non-metal')
ax.set_xlabel('Group', fontsize=24)
ax.set_ylabel('R/V', fontsize=24)
ax.set_yscale('log')
ax.set_xticks(range(1, 19))
ax.set_ybound(lower=.1, upper=10)
texts = []
labels = df['Atom']
for i, txt in enumerate(df['R/V']):
    if math.isnan(txt):
        continue
#     if labels.iloc[i] in ['Ga', 'Bi', 'Sb', 'In', 'Al', 'As', 
#                           'Tl', 'B', 'Sn', 'Ge', 'Pb', 'Si', 'P']:
#         texts.append(plt.text(df['Group'].iloc[i]+0.2, 
#                               df['R/V'].iloc[i]-0.02,
#                               labels.iloc[i],
#                             clip_on=True,
#                             fontsize=20))
#     else:
    ax.annotate(labels.iloc[i], 
            (df['Group'].iloc[i]+0.2, df['R/V'].iloc[i]-0.02),
           fontsize=20, clip_on=True)

line = plt.Line2D([0, 19], [1, 1], color='red', ls='dashed')
ax.add_line(line)
ax.legend()
adjust_text(texts, arrowprops=dict(arrowstyle="->", color='r', lw=0.5), lim=500, 
            only_move={'text': 'y'})
plt.savefig("../../plots/goldhammer_herzfeld_elements/RV_groups.pdf", dpi=200, bbox_inches='tight')
plt.show()<jupyter_output><empty_output><jupyter_text>Plot Electrical conductivity vs. Group<jupyter_code>fig, ax = plt.subplots(figsize=(14,8))
# scat = ax.scatter(df['Group'], df['electrical_conductivity'], s=60)
ax.scatter(df[df['Class'] == 'Metal']['Group'], 
           df[df['Class'] == 'Metal']['electrical_conductivity'], 
           s=60, marker='v', 
           c='#f2e052',
           label='Metal')
ax.scatter(df[df['Class'] == 'Metalloid']['Group'], 
           df[df['Class'] == 'Metalloid']['electrical_conductivity'], 
           s=60, 
           marker='o', 
           c='#cc715a',
           label='Metalloid')
ax.scatter(df[df['Class'] == 'Non-metal']['Group'], 
           df[df['Class'] == 'Non-metal']['electrical_conductivity'], 
           s=60, 
           marker='^', 
           c='#8cb4fa',
           label='Non-metal')
ax.set_xlabel('Group', fontsize=24)
ax.set_ylabel(r'Electrical conductivity ($\Omega^{-1}$cm$^{-1}$)', fontsize=24)
ax.set_yscale('log')

ax.set_xbound(lower=0, upper=19)
ax.set_xticks(range(1, 19))
ax.set_ybound(lower=1e-18, upper=1e6)

texts=[]
labels = df['Atom']
for i, txt in enumerate(df['Electrical Conductivity Wolfram']):
    if math.isnan(txt):
        continue
#     texts.append(plt.text(df['Group'].iloc[i]+0.2, 
#                       df['electrical_conductivity'].iloc[i]-0.6*df['electrical_conductivity'].iloc[i],
#                       labels.iloc[i],
#                     clip_on=True,
#                     fontsize=20))
    ax.annotate(labels.iloc[i], 
                (df['Group'].iloc[i]+0.2, 
                 df['electrical_conductivity'].iloc[i]-0.6*df['electrical_conductivity'].iloc[i]),
               fontsize=20)
ax.legend()
# adjust_text(texts, arrowprops=dict(arrowstyle="->", color='r', lw=0.5), lim=500)
plt.savefig("../../plots/goldhammer_herzfeld_elements/conductivity_groups.pdf", dpi=200, bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20460033041047146, 'fraction_numerical': 0.025543271063667557, 'mean_word_length': 3.3432671081677703, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '594505', 'license': 'MIT', 'n_tokens_mistral': 3108, 'n_tokens_neox': 2877, 'n_words': 440, 'path': 'src/molar_refractivity.ipynb', 'repo_name': 'mtdg-wagner/goldhammer-herzfeld-elements', 'size': '7874'}