def plot_bar_charts(runtypes, ligands): series_data = {i: {} for i in ligands} for rt in runtypes: rtd = runtypes[rt] for ser in series_data: a_energy = rtd['energies'][f'{ser.lower()}_A'] b_energy = rtd['energies'][f'{ser.lower()}_B'] c_energy = rtd['energies'][f'{ser.lower()}_C'] d_energy = rtd['energies'][f'{ser.lower()}_D'] energy_sep = c_energy - min([a_energy, b_energy, d_energy]) energy_sep = -1 * energy_sep * 2625.5 series_data[ser][rt] = energy_sep bar_chart( energies=[series_data[s]['xtb'] for s in series_data], filename='previous_xtb.pdf', x_labels=[s for s in series_data], y_title=r'xTB $cis$ energy preference [kJmol$^{-1}$]', facecolor=colors_i_like()[4], ) bar_chart( energies=[series_data[s]['pbenoecp'] for s in series_data], filename='previous_dft.pdf', x_labels=[s for s in series_data], y_title=r'DFT $cis$ energy preference [kJmol$^{-1}$]', facecolor=colors_i_like()[3], )
def opposing_bar_chart( xtbenergies, dftenergies, filename, x_labels, ): c_expt = colors_i_like()[3] c_selec = colors_i_like()[4] xs = [1, 2, 3, 4] fig, ax = plt.subplots(nrows=2, sharex=True, figsize=(8, 10)) ax[0].bar(xs, xtbenergies, width=1, color=c_selec, edgecolor='k', linewidth=1.5, label='GFN2-xTB') ax[1].bar(xs, dftenergies, width=1, color=c_expt, edgecolor='k', linewidth=1.5, label='PBE0-D3/def2-SVP/SDD/PCM(DMSO) [CHKTHIS]') ax[1].set_xticks(xs) ax[1].set_xticklabels(x_labels) ax[0].tick_params(axis='both', which='major', labelsize=16) ax[0].set_ylabel(r'xTB $cis$ energy preference [kJmol$^{-1}$]', fontsize=16) ax[0].set_xlim(0, 5) ax[0].set_ylim(None, None) # ax[0].legend(fontsize=16) ax[1].tick_params(axis='both', which='major', labelsize=16) ax[1].set_ylabel(r'DFT $cis$ energy preference [kJmol$^{-1}$]', fontsize=16) ax[1].set_xlim(0, 5) ax[1].set_ylim(None, None) # ax[1].legend(fontsize=16) ax[1].invert_yaxis() # ax[0].set(yticks=df_male_1['age']) # ax[0].xaxis.tick_right() fig.tight_layout() fig.savefig(filename, dpi=720, bbox_inches='tight') plt.close()
def main(): if (not len(sys.argv) == 1): print(""" Usage: plot_experimental_cases.py """) sys.exit() raise Exception('This script is outdated.') experimental_cases = { '5D1': { 'new': False, 'p': 1 }, '4D2': { 'new': False, 'p': 2 }, '5D3': { 'new': False, 'p': 3 }, '3D1': { 'new': False, 'p': 4 }, '5A3': { 'new': True, 'p': 5 }, '5A1': { 'new': True, 'p': 6 }, '4B3': { 'new': True, 'p': 7 }, '4B1': { 'new': True, 'p': 8 }, '5C2': { 'new': True, 'p': 9 }, '4C2': { 'new': True, 'p': 10 }, '5D7': { 'new': True, 'p': 11 }, '5B4': { 'new': True, 'p': 12 }, } print(experimental_cases) data = pd.read_csv('all_cage_results.txt') data = data[data['lig'].isin(experimental_cases)] print(data) print(data.columns) plot_properties = { 'energies': { 'ylim': (0, 40), 'ytitle': 'energy separation [kJmol$^{-1}$]', 'data_f': get_energy_sep, 'ycut': 6, }, 'pds': { 'ylim': (0, 0.2), 'ytitle': r'max. plane deviation [$\mathrm{\AA}$]', 'data_f': get_C_pd, 'ycut': 0.3, }, 'qsps': { 'ylim': (0.9, 1), 'ytitle': r'min. $q_{\mathrm{sp}}$', 'data_f': get_C_op, 'ycut': 0.95, } } fig, (ax0, ax1, ax2) = plt.subplots( 3, 1, figsize=(8, 10), sharex=True, ) ax0_dict = plot_properties['energies'] ax0_data = [(row['lig'], ax0_dict['data_f'](row)) for i, row in data.iterrows()] ax0.bar( x=[experimental_cases[i[0]]['p'] for i in ax0_data], height=[i[1] for i in ax0_data], width=0.9, color=[get_c(experimental_cases[i[0]]['new']) for i in ax0_data], tick_label=[get_xtick(i[0]) for i in ax0_data], ) ax0.axhline(y=ax0_dict['ycut'], c='k', lw=2) ax0.tick_params(axis='both', which='major', labelsize=16) ax0.set_ylabel(ax0_dict['ytitle'], fontsize=16) ax0.set_ylim(ax0_dict['ylim']) ax1_dict = plot_properties['pds'] ax1_data = [(row['lig'], ax1_dict['data_f'](row)) for i, row in data.iterrows()] ax1.bar( x=[experimental_cases[i[0]]['p'] for i in ax1_data], height=[i[1] for i in ax1_data], width=0.9, color=[get_c(experimental_cases[i[0]]['new']) for i in ax1_data], tick_label=[get_xtick(i[0]) for i in ax1_data], ) ax1.axhline(y=ax1_dict['ycut'], c='k', lw=2) ax1.tick_params(axis='both', which='major', labelsize=16) ax1.set_ylabel(ax1_dict['ytitle'], fontsize=16) ax1.set_ylim(ax1_dict['ylim']) ax2_dict = plot_properties['qsps'] ax2_data = [(row['lig'], ax2_dict['data_f'](row)) for i, row in data.iterrows()] ax2.bar( x=[experimental_cases[i[0]]['p'] for i in ax2_data], height=[i[1] for i in ax2_data], width=0.9, color=[get_c(experimental_cases[i[0]]['new']) for i in ax2_data], tick_label=[get_xtick(i[0]) for i in ax2_data], ) ax2.axhline(y=ax2_dict['ycut'], c='k', lw=2) ax2.tick_params(axis='both', which='major', labelsize=16) ax2.set_xlabel('ligand', fontsize=16) ax2.set_ylabel(ax2_dict['ytitle'], fontsize=16) ax2.set_ylim(ax2_dict['ylim']) legend_elements = [ Patch(facecolor=colors_i_like()[4], edgecolor='none', label='new'), Patch(facecolor=colors_i_like()[3], edgecolor='none', label='published'), ] plt.xticks(rotation=45) ax0.legend(handles=legend_elements, fontsize=16) fig.tight_layout() fig.savefig('experimental_tests.pdf', dpi=720, bbox_inches='tight')
def get_c(b): if b: return colors_i_like()[4] else: return colors_i_like()[3]
def plot( x, y, xlabel, ylabel, xlim, ylim, expt_x, expt_y, sele_x, sele_y, filename, exam_x, exam_y, ): fig, ax = plt.subplots(figsize=(8, 5)) full = ax.scatter( x, y, c=colors_i_like('IBM')[2], edgecolors='none', marker='o', alpha=1, s=150, # label='new in this work' ) exam = ax.scatter( exam_x, exam_y, c=colors_i_like('IBM')[2], edgecolors='black', linewidths=2, marker='o', alpha=1, s=150, # label='highlighted examples' ) sele2 = ax.scatter( sele_x, sele_y, c='white', edgecolors='black', linewidths=2, marker='o', alpha=1, s=190, # label='synthesised in this work' ) sele = ax.scatter( sele_x, sele_y, c=colors_i_like('IBM')[2], edgecolors='white', linewidths=2, marker='o', alpha=1, s=150, # label='synthesised in this work' ) publ = ax.scatter( expt_x, expt_y, c=colors_i_like('IBM')[4], edgecolors='white', marker='D', alpha=1, s=120, # label='published examples' ) # ax.axhline(y=0, lw=2, linestyle='--', c='k') ax.legend( [ publ, full, exam, (sele2, sele) ], [ 'published examples', 'new in this work', 'highlighted examples', 'synthesised in this work' ], fontsize=16 ) # Set number of ticks for x-axis ax.tick_params(axis='both', which='major', labelsize=16) ax.set_xlabel(xlabel, fontsize=16) ax.set_ylabel(ylabel, fontsize=16) ax.set_xlim(xlim) ax.set_ylim(ylim) # ax.legend(fontsize=16) fig.tight_layout() fig.savefig(filename, dpi=720, bbox_inches='tight') plt.close()
def bar_figure(selected_ligands, experimental_ligands, data): c_expt = colors_i_like()[3] c_selec = colors_i_like()[4] x_expt = {} x_selec = {} for i, li in enumerate(selected_ligands): row = data[data['lig'] == li] print(row) print(row['energy_C']) energy_sep = min([ float(row['energy_A']), float(row['energy_B']), float(row['energy_D']), ]) C_qsp = float(row['sqpl_op_C']) short_name = li if li in experimental_ligands: x_expt[i] = (short_name, energy_sep, C_qsp) else: x_selec[i] = (short_name, energy_sep, C_qsp) x_ticks = [i for i in x_expt]+[i for i in x_selec] x_ticklabels = ( [x_expt[i][0] for i in x_expt]+[x_selec[i][0] for i in x_selec] ) print(x_ticks, x_ticklabels) width = 0.9 fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(8, 8)) ax1.barh( y=[i for i in x_expt], width=[x_expt[i][1] for i in x_expt], height=width, facecolor=c_expt, edgecolor='none', alpha=1, label='published examples' ) ax1.barh( y=[i for i in x_selec], width=[x_selec[i][1] for i in x_selec], height=width, facecolor=c_selec, edgecolor='none', alpha=1, label='selected cage ligands' ) # Set number of ticks for x-axis ax1.tick_params(axis='both', which='major', labelsize=16) # ax.set_xlabel(names[name]['xtitle'], fontsize=16) # ax1.set_xticks(x_ticks) # ax1.set_xticklabels(x_ticklabels) ax1.set_xlabel('stability of C isomer [kJmol$^{-1}$]', fontsize=16) # ax.set_xlim(names[name]['xlim']) ax1.set_xlim(0, 30) ax1.axvline(x=6.0, c='k', alpha=0.6, lw=2) ax2.barh( y=[i for i in x_expt], height=width, width=[x_expt[i][2] for i in x_expt], facecolor=c_expt, edgecolor='none', alpha=1, ) ax2.barh( y=[i for i in x_selec], height=width, width=[x_selec[i][2] for i in x_selec], facecolor=c_selec, edgecolor='none', alpha=1, ) # Set number of ticks for x-axis ax2.tick_params(axis='both', which='major', labelsize=16) ax2.set_xticks([0.9, 1]) ax2.set_xticklabels(['0.9', '1.0']) ax2.set_yticks(x_ticks) ax2.set_yticklabels(x_ticklabels, rotation=45) ax2.set_xlabel(r'$q_{\mathrm{sqp,min}}$', fontsize=16) ax2.set_xlim(0.9, 1) ax1.legend(fontsize=16) fig.tight_layout() fig.savefig( 'selected_ligands.pdf', dpi=720, bbox_inches='tight' ) plt.close()
def single_bar_figure(selected_ligands, experimental_ligands, data): c_expt = 'lightgray' c_selec = colors_i_like('IBM')[3] x_expt = {} x_selec = {} for i, li in enumerate(selected_ligands): row = data[data['lig'] == li] print(row, row['energy_C']) energy_sep = min([ float(row['energy_A']), float(row['energy_B']), float(row['energy_D']), ]) C_qsp = float(row['sqpl_op_C']) short_name = ( li.replace( '_li', '-' ).replace('_lk', '-').replace('li', '') ) if li in experimental_ligands: x_expt[i] = (short_name, energy_sep, C_qsp) else: x_selec[i] = (short_name, energy_sep, C_qsp) x_ticks = [i for i in x_expt]+[i for i in x_selec] x_ticklabels = ( [x_expt[i][0] for i in x_expt]+[x_selec[i][0] for i in x_selec] ) print(x_ticks, x_ticklabels) hatch_patterns = [ '' if x_selec[i][0] != '4B3' else '//' for i in x_selec ] width = 0.9 fig, ax = plt.subplots(figsize=(4, 8)) ex = ax.barh( y=[i for i in x_expt], width=[x_expt[i][1] for i in x_expt], height=width, facecolor=c_expt, # hatch='none', edgecolor='k', alpha=1, # label='published examples' ) for i, j in enumerate(x_selec): if x_selec[j][0] == '4B3': ssel = ax.barh( y=j, width=x_selec[j][1], height=width, facecolor=c_selec, hatch=hatch_patterns[i], edgecolor='k', alpha=1, # label='selected cage ligands' ) else: sel = ax.barh( y=j, width=x_selec[j][1], height=width, facecolor=c_selec, hatch=hatch_patterns[i], edgecolor='k', alpha=1, # label='selected cage ligands' ) ax.axvline(x=6.0, c='k', alpha=0.6, lw=2) # Set number of ticks for x-axis ax.tick_params(axis='both', which='major', labelsize=16) # ax.set_xlabel(names[name]['xtitle'], fontsize=16) # ax1.set_xticks(x_ticks) # ax1.set_xticklabels(x_ticklabels) # ax.set_xlabel( # r'stability of $cis$ isomer [kJmol$^{-1}$]', # fontsize=16, # ) ax.set_xlabel( r'$\Delta E_{\mathrm{cis}}$ [kJmol$^{-1}$]', fontsize=16, ) # ax.set_xlim(names[name]['xlim']) ax.set_xlim(0, 30) # Set number of ticks for x-axis ax.set_yticks(x_ticks) ax.set_yticklabels(x_ticklabels) ax.legend( [ex, sel, ssel], ['published examples', 'forms single isomer', 'forms mixture'], fontsize=16 ) fig.tight_layout() fig.savefig( 'selected_ligands_energysep.pdf', dpi=720, bbox_inches='tight' ) plt.close()
def main(): cage_data = pd.read_csv('all_cage_results.txt') mA = 'o' cA = colors_i_like()[4] # mB = 's' # cB = colors_i_like()[3] # mC = 'X' # cC = colors_i_like()[0] # mD = 'D' # cD = colors_i_like()[2] X_A = [] Y_A = [] X_B = [] Y_B = [] X_C = [] Y_C = [] X_D = [] Y_D = [] for i, row in cage_data.iterrows(): X_A.append(float(row['sqpl_op_A'])) Y_A.append(float(row['plane_dev_A'])) X_B.append(float(row['sqpl_op_B'])) Y_B.append(float(row['plane_dev_B'])) X_C.append(float(row['sqpl_op_C'])) Y_C.append(float(row['plane_dev_C'])) X_D.append(float(row['sqpl_op_D'])) Y_D.append(float(row['plane_dev_D'])) fig, ax = plt.subplots(figsize=(8, 5)) ax.scatter( X_A + X_B + X_C + X_D, Y_A + Y_B + Y_C + Y_D, c=cA, edgecolors='black', marker=mA, alpha=1, s=80, # label='a', ) # ax.scatter( # X_B, # Y_B, # c=cB, # edgecolors='white', # marker=mB, # alpha=1, # s=60, # label='b', # ) # ax.scatter( # X_C, # Y_C, # c=cC, # edgecolors='white', # marker=mC, # alpha=1, # s=60, # label='c', # ) # ax.scatter( # X_D, # Y_D, # c=cD, # edgecolors='white', # marker=mD, # alpha=1, # s=60, # label='d', # ) # Set number of ticks for x-axis ax.tick_params(axis='both', which='major', labelsize=16) ax.set_xlabel(r'$q_{\mathrm{sqp,min}}$', fontsize=16) ax.set_ylabel(r'$D_{\mathrm{max}}$ [$\mathrm{\AA}$]', fontsize=16) ax.set_xlim(0, 1) ax.set_ylim(0, None) # ax.legend(fontsize=16) fig.tight_layout() fig.savefig('all_cages_geom_parity.pdf', dpi=720, bbox_inches='tight') plt.close()