In [7]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
import matplotlib.pyplot as plt
import os
%matplotlib notebook
#%matplotlib inline
from ipywidgets import interact #, interactive, fixed, interact_manual
import ipywidgets as widgets
In [8]:
fol = '/home/alessio/x-last_Stuff'
subfolders = sorted([dir for dir in os.listdir(fol) if os.path.isdir(os.path.join(fol,dir)) and dir not in ['HTML','csv']])
print(''.join(['{} -> {}\n'.format(a,b) for a,b in enumerate(subfolders)]))
In [15]:
def create_df_from_files_given_name(name,fol,fs_end_pulse):
'''
This creates the excel file from the 4 files
'''
project_folder = os.path.join(fol,name)
output_norm = os.path.join(project_folder, 'output')
output_popu = os.path.join(project_folder, 'outputPopul')
output_abso = os.path.join(project_folder, 'Output_Abs')
output_regi = os.path.join(project_folder, 'Output_Regions')
df_norm2 = pd.read_csv(output_norm, delim_whitespace=True, index_col=0, names=['counter', 'steps', 'fs_1','Norm deviation','Kinetic','Potential','Total','Total Deviation','Xpulse','Ypulse','Zpulse','AbZino'])
df_popu2 = pd.read_csv(output_popu, delim_whitespace=True, names=['fs', 'S0', 'S1','S2','S3','S4','S5','S6','S7'])
df_abso2 = pd.read_csv(output_abso, delim_whitespace=True, names=['Time AU', 'Abs Tot', 'Abs S0', 'Abs S1','Abs S2','Abs S3','Abs S4','Abs S5','Abs S6','Abs S7'])
df_regi2 = pd.read_csv(output_regi, delim_whitespace=True, names=['FC','Reactants','Products'])
# I need to cut down to different file size <- this will become obsolete
dfs = [df_norm2,df_popu2,df_abso2,df_regi2]
lengths = min([x.shape[0] for x in dfs])
df_norm, df_popu, df_abso, df_regi = [ x.drop(x.index[lengths:]) for x in dfs ]
AU_dt = df_abso['Time AU'].iloc[1]
#fs_end_pulse = 15 # this is where I start to count Fc population retourning in S0 after the pulse.
fs_array = df_norm2['fs']
filtering_on_indexes = np.arange(lengths)
# number_line_after_pulse = np.where(fs_array > fs_end_pulse)[0][0]
number_line_after_pulse = 200
fs_after_pulse = df_popu['fs'].iloc[number_line_after_pulse]
s0_after_pulse = df_popu['S0'].iloc[number_line_after_pulse]
s1_after_pulse = df_popu['S1'].iloc[number_line_after_pulse]
s2_after_pulse = df_popu['S2'].iloc[number_line_after_pulse]
s3_after_pulse = df_popu['S3'].iloc[number_line_after_pulse]
s4_after_pulse = df_popu['S4'].iloc[number_line_after_pulse]
s5_after_pulse = df_popu['S5'].iloc[number_line_after_pulse]
s6_after_pulse = df_popu['S6'].iloc[number_line_after_pulse]
s7_after_pulse = df_popu['S7'].iloc[number_line_after_pulse]
all_after_pulse = np.array([s0_after_pulse,s1_after_pulse,s2_after_pulse,s3_after_pulse,s4_after_pulse,s5_after_pulse,s6_after_pulse,s7_after_pulse])
if number_line_after_pulse != 0:
value_to_subtract = df_regi['FC'].iloc[number_line_after_pulse-1]
df_regi['FC after pulse'] = np.where( filtering_on_indexes < number_line_after_pulse, 0, (df_regi['FC']-value_to_subtract))
else:
df_regi['FC after pulse'] = df_regi['FC']
df_all = pd.concat([df_norm,df_popu,df_abso,df_regi],axis=1)
csv_name = '{}.csv'.format(project_folder)
print('{} #steps {} - End pulse {} - S1: {:8.5E} - S2: {:8.5E} - S3: {:8.5E} - S4: {:8.5E} {}'.format(AU_dt,lengths, fs_after_pulse,s1_after_pulse,s2_after_pulse,s3_after_pulse,s4_after_pulse,name))
# ok this part needs comment. We want to normalize the S1 population to 1, to make the absorbed product count "fair"
# But the population in S1 is "moving" due to the other states continuosly absorbing/feeding it
# We make the assumption that all the other states are a single superstate that "feeds" only S1.
# So we sum up states from S2 to S7. Then we take the population of those states (2 to 7) after the pulse. We want to
# know after the pulse what is the CHANGE in population due to NAC of this "super state".
# our normalization factor for S1 at time T is ten the
df_all['sum_others'] = (df_all['S2'] + df_all['S3'] + df_all['S4'] + df_all['S5'] + df_all['S6'] + df_all['S7'])
df_all['sum_others_minus_after_pulse'] = sum(all_after_pulse[2:]) - df_all['sum_others']
df_all['Norm_factor (t)'] = all_after_pulse[1] + df_all['sum_others_minus_after_pulse']
df_all['P(t) Tot'] = -(np.cumsum(df_all['Abs Tot'])*AU_dt)
df_all['P(t) S0'] = -(np.cumsum(df_all['Abs S0'])*AU_dt)
df_all['P(t) S1'] = -(np.cumsum(df_all['Abs S1'])*AU_dt)
df_all['P(t) S2'] = -(np.cumsum(df_all['Abs S2'])*AU_dt)
df_all['P(t) S3'] = -(np.cumsum(df_all['Abs S3'])*AU_dt)
df_all['P(t) S4'] = -(np.cumsum(df_all['Abs S4'])*AU_dt)
df_all['P(t) S5'] = -(np.cumsum(df_all['Abs S5'])*AU_dt)
df_all['P(t) S6'] = -(np.cumsum(df_all['Abs S6'])*AU_dt)
df_all['P(t) S7'] = -(np.cumsum(df_all['Abs S7'])*AU_dt)
df_all['AU_dt'] = AU_dt
df_all['Products_F'] = df_all['Products'] + df_all['P(t) S0']
#df_all['Reactants_F'] = df_all['Reactants'] + df_all['FC after pulse']
df_all['Reactants_F'] = df_all['Reactants']
# df_all['Real Reactants'] = df_regi['Reactants'] + df_regi['FC after pulse']
# df_all['Real Products'] = df_regi['Products'] + df_abso['Norm S0']
# df_all['Real ratio'] = df_all['Real Products']/df_all['Real Reactants']
df_all.to_csv(csv_name)
#df_all.plot('fs',['Reactants','Products'])
#df_all.plot('fs','ratio')
#df_all.plot('fs',['Real Reactants','Real Products'])
#return(df_all[['fs','Norm_factor (t)','sum_others_minus_after_pulse','sum_others']])
#return(df_all[['Norm Tot','fs','ratio','Real Products','Real Reactants','Abs S0','Norm S0', 'Products', 'Reactants','Real ratio','S1','S2','S3','S0','S4','S5','S6','S7','Xpulse','Ypulse','Norm_factor (t)','sum_others_minus_after_pulse','sum_others','Norm deviation','Absorbed Normalized','FC after pulse']])
return(df_all)
number = 3
a = create_df_from_files_given_name('m-only_IR_middle140_0000',fol,26)
b = create_df_from_files_given_name('b-UV-0.22_0000',fol,15)
c = create_df_from_files_given_name('m-only_IR_middle140_div10_0000',fol,26)
d = create_df_from_files_given_name('m-IR-Polarized-NOR_0000',fol,15)
e = create_df_from_files_given_name('z-from1_0000',fol,0)
f = create_df_from_files_given_name('m-only_IR_middle140-9331_0000',fol,26)
In [16]:
colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'mediumpurple']
In [18]:
fig, [[ax0, ax1],[ax2,ax3],[ax4,ax5],[ax6,ax7]] = plt.subplots(4,2,figsize=(15,16))
# labelz = ['norm','count','inv','pi']
# runs = [c,d,e,f]
labelz = ['140','UV','div10','IR nor','FC','140-933']
runs = [a,b,c,d,e,f]
for ind,i in enumerate(runs):
ax0.plot(i['fs'].iloc[:,1], i['Products'] , label='{} Products'.format(labelz[ind]) , ls='--', color=colors[ind])
ax0.plot(i['fs'].iloc[:,1], i['Reactants'] , label='{} Reactants'.format(labelz[ind]), color=colors[ind])
#ax0.plot(i['fs'].iloc[:,1], i['FC after pulse'], label='{} FC'.format(labelz[ind]) , ls=':', lw=0.5, color=colors[ind])
ax1.plot(i['fs'].iloc[:,1], i['Products'] /i['Norm_factor (t)'] , label='{} Products'.format(labelz[ind]) , ls='--', color=colors[ind])
ax1.plot(i['fs'].iloc[:,1], i['Reactants']/i['Norm_factor (t)'] , label='{} Reactants'.format(labelz[ind]), color=colors[ind])
#ax1.plot(i['fs'].iloc[:,1], i['FC after pulse']/i['Norm_factor (t)'], label='{} FC'.format(labelz[ind]) , ls=':', lw=0.5, color=colors[ind])
ax0.set_xlabel('fs')
ax0.set_title('Regions only - Products Reactants')
ax0.legend()
ax1.set_xlabel('fs')
ax1.set_title('Regions only - Products Reactants - Normalized')
ax1.legend()
for ind,i in enumerate(runs):
ax2.plot(i['fs'].iloc[:,1], i['Abs S0'], label=r'{} dP(dt) $S_0$'.format(labelz[ind]), color=colors[ind])
ax3.plot(i['fs'].iloc[:,1], i['Abs S0']/i['Norm_factor (t)'], label=r'{} dP(dt) $S_0$'.format(labelz[ind]), color=colors[ind])
ax2.set_title('Absorbing potential - dP(dt)')
ax2.legend()
ax3.set_title('Absorbing potential - dP(dt) - Normalized')
ax3.legend()
for ind,i in enumerate(runs):
ax4.plot(i['fs'].iloc[:,1], i['P(t) S0'], label=r'{} P(t) $S_0$'.format(labelz[ind]), color=colors[ind])
ax5.plot(i['fs'].iloc[:,1], i['P(t) S0']/i['Norm_factor (t)'], label=r'{} P(t) $S_0$'.format(labelz[ind]), color=colors[ind])
ax4.set_title(r'P(t) - $S_0$ absorbed')
ax4.legend()
ax5.set_title(r'P(t) - $S_0$ absorbed - Normalized')
ax5.legend()
for ind,i in enumerate(runs):
ax6.plot(i['fs'].iloc[:,1], i['Products_F'] , label='{} Products'.format(labelz[ind]), ls='--', color=colors[ind])
ax6.plot(i['fs'].iloc[:,1], i['Reactants_F'], label='{} Reactants'.format(labelz[ind]), color=colors[ind])
ax7.plot(i['fs'].iloc[:,1], i['Products_F'] /i['Norm_factor (t)'], label='{} Products'.format(labelz[ind]), ls='--', color=colors[ind])
ax7.plot(i['fs'].iloc[:,1], i['Reactants_F']/i['Norm_factor (t)'], label='{} Reactants'.format(labelz[ind]), color=colors[ind])
ax6.set_xlabel('fs')
ax6.set_title('Products Reactants - Final graph')
ax6.legend()
ax7.set_xlabel('fs')
ax7.set_title('Products Reactants - Final graph - Normalized')
ax7.legend()
fig.tight_layout();
In [20]:
a
Out[20]:
In [20]:
fig, [[ax4,ax5],[ax6,ax7],[ax8,ax9]] = plt.subplots(3,2,figsize=(15,12))
here = a
for state in [0,1,2,3,4,5,6,7]:
ax4.plot(here['fs'].iloc[:,1], here['S{}'.format(state)], label=r'$S_{}$'.format(state), color=colors[state])
ax44 = ax4.twinx()
ax44.plot(here['fs'].iloc[:,1], here['Xpulse'], label='X_pulse', ls='--', lw=.5)
ax44.plot(here['fs'].iloc[:,1], here['Ypulse'], label='Y_pulse', ls='--', lw=.5)
ax4.set_title('Populations 140')
ax4.set_xlim(0,50)
ax4.legend()
here = b
for state in [0,1,2,3,4,5,6,7]:
ax5.plot(here['fs'].iloc[:,1], here['S{}'.format(state)], label=r'$S_{}$'.format(state), color=colors[state])
ax55 = ax5.twinx()
ax55.plot(here['fs'].iloc[:,1], here['Xpulse'], label='X_pulse', ls='--', lw=.5)
ax55.plot(here['fs'].iloc[:,1], here['Ypulse'], label='Y_pulse', ls='--', lw=.5)
ax5.set_title('Populations UV')
ax5.set_xlim(0,50)
ax5.legend()
here = c
for state in [0,1,2,3,4,5,6,7]:
ax6.plot(here['fs'].iloc[:,1], here['S{}'.format(state)], label=r'$S_{}$'.format(state), color=colors[state])
ax66 = ax6.twinx()
ax66.plot(here['fs'].iloc[:,1], here['Xpulse'], label='X_pulse', ls='--', lw=.5)
ax66.plot(here['fs'].iloc[:,1], here['Ypulse'], label='Y_pulse', ls='--', lw=.5)
ax6.set_title('Populations 140div')
ax6.set_xlim(0,50)
ax6.legend()
here = d
for state in [0,1,2,3,4,5,6,7]:
ax7.plot(here['fs'].iloc[:,1], here['S{}'.format(state)], label=r'$S_{}$'.format(state), color=colors[state])
ax77 = ax7.twinx()
ax77.plot(here['fs'].iloc[:,1], here['Xpulse'], label='X_pulse', ls='--', lw=.5)
ax77.plot(here['fs'].iloc[:,1], here['Ypulse'], label='Y_pulse', ls='--', lw=.5)
ax7.set_title('Populations IR norm')
ax7.set_xlim(0,50)
ax7.legend()
here = e
for state in [0,1,2,3,4,5,6,7]:
ax8.plot(here['fs'].iloc[:,1], here['S{}'.format(state)], label=r'$S_{}$'.format(state), color=colors[state])
ax88 = ax8.twinx()
ax88.plot(here['fs'].iloc[:,1], here['Xpulse'], label='X_pulse', ls='--', lw=.5)
ax88.plot(here['fs'].iloc[:,1], here['Ypulse'], label='Y_pulse', ls='--', lw=.5)
ax8.set_title('Populations FC')
ax8.set_xlim(0,50)
ax8.legend()
here = f
for state in [0,1,2,3,4,5,6,7]:
ax9.plot(here['fs'].iloc[:,1], here['S{}'.format(state)], label=r'$S_{}$'.format(state), color=colors[state])
ax99 = ax9.twinx()
ax99.plot(here['fs'].iloc[:,1], here['Xpulse'], label='X_pulse', ls='--', lw=.5)
ax99.plot(here['fs'].iloc[:,1], here['Ypulse'], label='Y_pulse', ls='--', lw=.5)
ax9.set_title('Populations 933')
ax9.set_xlim(0,50)
ax9.legend()
fig.tight_layout();
In [ ]: