def getlssparameters(self, trtab, tg, init_B, final_B, alpha): self.trtab = trtab self.tg = tg self.init_B = init_B self.final_B = final_B alphainit = [] asides = [] for i in range(len(alpha)): alphainit.append(1.0) asides.append(0.1) self.alpha = fmin(self.iterfunalpha, alphainit, side=asides, tol=1e-10) for i in range(len(self.trtab)): self.tr = trtab[i] lssinit = [0.1, 0.1] logkw, s = fmin(self.iterfun, lssinit, side=[0.1, 0.1], tol=1e-3) self.logkw.append(logkw) self.s.append(s) return self.logkw, self.s, self.alpha
def getlogssparameters(self, tr, tg, init_B, final_B): """ Return the logKw and S parameters for logarithmic gradient conditions""" self.tr = tr self.tg = tg self.init_B = init_B self.final_B = final_B lssinit = [0.1, 0.1] #simplex optimization self.lss_logkw, self.lss_s = fmin(self.logiterfun, lssinit, side=[0.1, 0.1], tol=1e-10) return self.lss_logkw, self.lss_s
def getloggradientconditions(self, tr_min, tr_max): """ Optimize the logarithmic gradient conditions finding different value of flow rate, initial and final organic solvent and time gradient. The equation to be used are these and the equation for the resolution it is the same of the isocratic conditions. """ self.maxtg = tr_max self.tr_min = tr_min self.tr_max = tr_max best_ss = None best_gcond = None for init_b in drange(0.00, 1.0, 0.1): for final_b in drange(init_b+0.1, 1.0, 0.1): for tg in drange(1, self.maxtg, 1): gcond = [init_b, final_b, tg] tmp_bestgcond = fmin(self.optloggradfun, gcond, side=[0.05, 0.05, 1], tol=1e-10) tmp_ssmax = self.optloggradfun(tmp_bestgcond) if best_ss != None: if tmp_ssmax < best_ss: best_ss = tmp_ssmax best_gcond = tmp_bestgcond else: continue else: best_gcond = tmp_bestgcond best_ss = tmp_ssmax """ self.maxtg = 15 gcond = [0.05, 1., 15] best_gcond = fmin(self.optloggradfun, gcond, side=[0.05, 0.05, 1], tol=1e-10) best_ss = self.optloggradfun(best_gcond) """ init_b = best_gcond[0] final_b = best_gcond[1] tg = best_gcond[2] # Function calculation t0 = self.v_m/self.flow td = self.v_d/self.flow logssmol = SSGenerator(None, None, None, t0, self.v_d, self.flow) tr = [] for i in range(len(self.logkw_s_tab)): logkw = self.logkw_s_tab[i][0] s = self.logkw_s_tab[i][1] tr.append(logssmol.logrtpred(logkw, s, tg, init_b, final_b, t0, td)) # return the best condition, the retention times and the best rs average return best_gcond, tr, 1/best_ss
def getisoconditions(self): """ Optimizer function starting from the 10% of organic modifier""" if len(self.temp) > 1: # Two temperature experiments according to de Vant Hoff return 0 else: # one temperature experiment phi = fmin(self.isocratic_iterfun, [0.2], side=[0.1], tol=1e-10) tr = [] for row in self.logkw_s_tab: logk = row[0] - row[1]*phi k = pow(10, logk) t0 = self.v_m/self.flow tr.append((k * t0) + t0) return phi*100, tr
def getlssparameters(self, tr, tg, init_B, final_B): """ Return the logKw and S parameters """ self.tr = tr self.tg = tg self.init_B = init_B self.final_B = final_B # fast static optimization param_init = [1.0, 1.0, 1.0] best_param = fmin(self.iterfun, param_init, side=[1.0, 1.0, 1.0], tol=1e-6, iterations=1000) self.logkw = best_param[0] self.S = best_param[1] c = best_param[1] return self.logkw, self.S, c
def getgradientconditions(self, tr_min, tr_max): """ Optimize the gradient conditions finding different value of flow rate, initial and final organic solvent and time gradient. The equation to be used are these and the equation for the resolution it is the same of the isocratic conditions. """ self.tr_min = tr_min self.tr_max = tr_max best_rsmax = None best_gcond = None for init_b in drange(0.00, 1.0, 0.1): for final_b in drange(init_b+0.1, 1.0, 0.1): for tg in drange(1, self.maxtg, 9): gcond = [init_b, final_b, tg] tmp_bestgcond = fmin(self.optgradfun, gcond, side=[0.05, 0.05, 1], tol=1e-10) tmp_rsmax = self.optgradfun(tmp_bestgcond) if best_rsmax != None: if tmp_rsmax < best_rsmax: best_rsmax = tmp_rsmax best_gcond = tmp_bestgcond else: continue else: best_gcond = tmp_bestgcond best_rsmax = tmp_rsmax init_b = best_gcond[0] final_b = best_gcond[1] tg = best_gcond[2] # Function calculation deltafi = final_b - init_b t0 = self.v_m/self.flow td = self.v_d/self.flow tr = [] for row in self.logkw_s_tab: b = float((self.v_m * deltafi * row[1]) / (tg*self.flow)) k0 = pow(10, row[0] - (row[1] * init_b)) tr.append(((t0/b) * log10(2.3*k0*b)) + t0 + td) # return the best condition, the retention times and the best rs average return best_gcond, tr, 1/best_rsmax
def getgradientconditions(self, tr_min, tr_max): """ Optimize the gradient conditions finding different value of flow rate, initial and final organic solvent and time gradient. The equation to be used are these and the equation for the resolution it is the same of the isocratic conditions. """ self.tr_min = tr_min self.tr_max = tr_max best_rsmax = None best_gcond = None for init_b in drange(0.0, 0.2, 0.05): for final_b in drange(0.7, 1.0, 0.05): for tg in drange(self.tr_min, self.tr_max, 2.): gcond = [init_b, final_b, tg] tmp_bestgcond = fmin(self.optgradfun, gcond, side=[0.05, 0.05, 1], tol=1e-2) tmp_rsmax = self.optgradfun(tmp_bestgcond) if best_rsmax != None: if tmp_rsmax < best_rsmax: best_rsmax = tmp_rsmax best_gcond = tmp_bestgcond else: continue else: best_gcond = tmp_bestgcond best_rsmax = tmp_rsmax init_b = best_gcond[0] final_b = best_gcond[1] tg = best_gcond[2] # Function calculation deltafi = final_b - init_b t0 = self.v_m/self.flow td = self.v_d/self.flow tr = [] for row in self.logkw_s_tab: b = float((self.v_m * deltafi * row[1]) / (tg*self.flow)) k0 = pow(10, row[0] - (row[1] * init_b)) tr.append(((t0/b) * log10(2.3*k0*b)) + t0 + td) # return the best condition, the retention times and the best rs average return best_gcond, tr, 1/best_rsmax
def iterfunalpha(self, alpha): """ Return the logKw and S parameters """ self.alpha = alpha rmsd = 0. for i in range(len(self.trtab)): self.tr = self.trtab[i] lssinit = [0.1, 0.1] #simplex optimization logkw, s = fmin(self.iterfun, lssinit, side=[0.1, 0.1], tol=1e-10) #calcualte retention time of all compounds with this alpha sz_grad = len(self.flow) for j in range(len(self.trtab[i])): trpred = self.rtpred(logkw, s, self.tg[j % sz_grad], self.init_B[j % sz_grad], self.final_B[j % sz_grad], self.alpha[j % sz_grad], self.t0[j % sz_grad], self.td[j % sz_grad]) rmsd += square(self.trtab[i][j] - trpred) print("%.2f %.2f [%f %f]") % (self.trtab[i][j], trpred, self.t0[j % sz_grad], self.td[j % sz_grad]) #print alpha print ("-"*20) sleep(1) rmsd /= float(len(self.trtab)) rmsd = sqrt(rmsd) return rmsd