def dGvX(self): assert len(self.boxes) == 2, 'Too many boxes {}'.format(self.boxes) file_description = '%s dG(kJ/mol) %s dG' % (self.xlabel[0], self.xlabel[1]) N = self.N[self.feed][self.run] dG = self.dG[self.feed][self.run] nIndep = self.gen_data[self.feed][self.run]['numIndep'] boxFrom, boxTo = self.boxes X = self.getX() assert 'box' in boxFrom, 'Wrong notation for box' molecules = sorted([ i for i in N.keys() if ((N[i][boxTo]['mean'] > 0.) and (N[i][boxFrom]['mean'] > 0.)) ]) for mol in molecules: file_name = 'dG-mol%s_vs_%s_%s-->%s.dat' % (mol, self.xlabel[0], boxFrom, boxTo) if (0 in self.indep) and (len(self.indep) == 1): dG_vals = dG[mol]['--'.join([boxFrom, boxTo])]['raw'] x_vals = X['raw'] writeAGR(x_vals, dG_vals, None, None, [self.feed for i in x_vals], file_name, file_description) else: dG_mean, dG_stdev = (dG[mol]['--'.join([boxFrom, boxTo])]['mean'], dG[mol]['--'.join([boxFrom, boxTo])]['stdev']) if '95conf' not in X.keys(): X['95conf'] = calc95conf(X['stdev'], nIndep) writeAGR([X['mean']], [dG_mean], [X['95conf']], [calc95conf(dG_stdev, nIndep)], [self.feed], file_name, file_description)
def Pig_xy(self): nIndep = self.gen_data[self.feed][self.run]['numIndep'] self.T = self.gen_data[self.feed][self.run]['temperature'] rho, N = self.rho[self.feed][self.run], self.N[self.feed][self.run] vapor_box = self.findVapBox(rho, self.mol) num_box = len(rho.keys()) if num_box == 3: liquid_box = 'box2' else: liquid_box = 'box1' # get pressure p_mean = 0. p_stdev = 0. factor = 1 / N_av * R['nm**3*kPa/(mol*K)'] * self.T for mol in rho.keys(): mean, stdev = rho[mol][vapor_box]['mean'], rho[mol][vapor_box][ 'stdev'] p_mean += mean * factor p_stdev += math.pow(stdev, 2) * math.pow(factor, 2) p_stdev = math.sqrt(p_stdev) file_description = '%s Pig %s dP' % (self.xlabel[0], self.xlabel[1]) file_name = 'Pig_x_mol%s' % self.mol X = self.getX(box=liquid_box) writeAGR([X['mean']], [p_mean], [calc95conf(X['stdev'], nIndep)], [calc95conf(p_stdev, nIndep)], [self.feed], file_name, file_description) file_name = 'Pig_y_mol%s' % self.mol X = self.getX(box=vapor_box) writeAGR([X['mean']], [p_mean], [calc95conf(X['stdev'], nIndep)], [calc95conf(p_stdev, nIndep)], [self.feed], file_name, file_description)
def XvX(self): if (0 in self.indep) and (len(self.indep) == 1): raise NotImplemented N = self.N[self.feed][self.run] mol_frac = self.X[self.feed][self.run] X = self.getX() nIndep = self.gen_data[self.feed][self.run]['numIndep'] if '95conf' in X.keys(): dX = X['95conf'] else: dX = calc95conf(X['stdev'], nIndep) file_description = '%s x (mol/mol) %s dx' % (self.xlabel[0], self.xlabel[1]) for box in N['1'].keys(): for mol1 in N.keys(): print(mol_frac.keys()) if mol1 in mol_frac[box].keys(): file_name = 'X_mol%s_%s-vs-%s.dat' % (mol1, box, self.xlabel[0]) x_mean, x_stdev = mol_frac[box][mol1]['mean'], mol_frac[ box][mol1]['stdev'] if box == 'box1': print(x_mean, x_stdev) if ('P-box' in self.xlabel[0]) and (x_mean < 0.75): assert self.T, 'Temperature needed for vapor p' rho = self.rho[self.feed][self.run] x_mean, x_stdev = calculateIGMolFrac( rho, mol1, box, X, self.T) writeAGR([X['mean']], [x_mean], [dX], [calc95conf(x_stdev, nIndep)], [self.feed], file_name, file_description)
def DensvX(self): assert 'box' in self.box, 'Box needed for density' if (0 in self.indep) and (len(self.indep) == 1): raise NotImplemented X = self.getX() rho = self.rho[self.feed][self.run] gen_data = self.gen_data[self.feed][self.run] nIndep = gen_data['numIndep'] file_description = '%s density(g/mL) %s dd' % ( self.xlabel[0], self.xlabel[1]) file_name = 'Dens_v_%s_%s.dat' % (self.xlabel[0], self.box) density = {'mean': 0., 'stdev': 0.} for mol in rho.keys(): factor = gen_data['molecular weight'][mol] / N_av * math.pow( 10, 21) if self.box in rho[mol]: dens_molec_nm3 = { 'mean': rho[mol][self.box]['mean'], 'stdev': rho[mol][self.box]['stdev'] } density['mean'] += dens_molec_nm3['mean'] * factor density['stdev'] += math.pow(dens_molec_nm3['stdev'] * factor, 2) density['stdev'] = math.sqrt(density['stdev']) writeAGR([X['mean']], [density['mean']], [calc95conf(X['stdev'], nIndep)], [calc95conf(density['stdev'], nIndep)], [self.feed], file_name, file_description)
def dUvX(self): U = self.U[self.feed][self.run] N = self.N[self.feed][self.run] gen_data = self.gen_data[self.feed][self.run] file_description = 'Q(%s) %s dQ %s' % ( self.units, self.xlabel[0], self.xlabel[1]) file_name = 'dU_%s_mixture.dat' % self.box X = self.getX() N1_tot = sum(N[i]['box1']['mean'] for i in N.keys()) N1 = { 'mean': N1_tot, 'stdev': math.pow(sum(N[i]['box1']['stdev']**2 for i in N.keys()), 0.5) } # mol N2_tot = sum(N[i][self.box]['mean'] for i in N.keys()) N2 = { 'mean': N2_tot, 'stdev': math.pow(sum(N[i][self.box]['stdev']**2 for i in N.keys()), 0.5) } # mol nIndep = gen_data['numIndep'] dU = (U['box1']['mean'] / N1_tot - U[self.box]['mean'] / N2_tot) * 8.314 / 1000 ddU = math.pow( (1 / N1_tot)**2 * U['box1']['stdev']**2 + (-1 * U['box1']['mean'] / N1['mean']**2)**2 * N1['stdev']**2 + (1 / N2_tot)**2 * U[self.box]['stdev']**2 + (-1 * U[self.box]['mean'] / N2['mean']**2)**2 * N2['stdev']**2, 0.5) * 8.314 / 1000 dU_mean, dU_stdev = dU, ddU writeAGR([X['mean']], [dU_mean], [calc95conf(X['stdev'], nIndep)], [calc95conf(dU_stdev, nIndep)], [self.feed], file_name, file_description)
def XvX(self): assert 'box' in self.box, 'Box needed for mole frac plot' nIndep = self.gen_data[self.feed][self.run]['numIndep'] N = self.N[self.feed][self.run] x = self.getX(box=self.box) file_description = 'x (mol/mol) x (mol/mol) dx dx' for mol in N.keys(): y = self.getX(box=self.box, myMol=mol) if y['mean'] > 0.: file_name = 'XvX_%s_%s.dat' % (self.mol, mol) writeAGR([x['mean']], [y['mean']], [calc95conf(x['stdev'], nIndep)], [calc95conf(y['stdev'], nIndep)], [self.feed], file_name, file_description)
def Txy(self): nIndep = self.gen_data[self.feed][self.run]['numIndep'] rho, N = self.rho[self.feed][self.run], self.N[self.feed][self.run] try: vapor_box = self.findVapBox(rho, self.mol) except KeyError: vapor_box = 'box2' num_box = len(rho['1'].keys()) if num_box == 3: liquid_box = 'box2' else: liquid_box = 'box1' T = self.gen_data[self.feed][self.run]['temperature'] file_description = '%s T %s ' % (self.xlabel[0], self.xlabel[1]) file_name = 'Tx_mol%s' % self.mol X = self.getX(box=liquid_box) writeAGR([X['mean']], [T], [calc95conf(X['stdev'], nIndep)], [0.], [self.feed], file_name, file_description) file_name = 'Ty_mol%s' % self.mol X = self.getX(box=vapor_box) writeAGR([X['mean']], [T], [calc95conf(X['stdev'], nIndep)], [0.], [self.feed], file_name, file_description)
def RvX(self): assert self.mol, 'Molecule needed to calculate recovery' assert self.box, 'Box needed to calculate recovery' if (0 in self.indep) and (len(self.indep) == 1): raise NotImplemented N = self.N[self.feed][self.run] # N: feed, run, mol, box, mean/stdev X = self.getX() nIndep = self.gen_data[self.feed][self.run]['numIndep'] file_name = 'R_mol%s_box%s-vs-%s.dat' % (self.mol, self.box, self.xlabel[0]) file_description = '%s Recovery %s dR' % (self.xlabel[0], self.xlabel[1]) Ni_tot = sum(N[self.mol][i]['mean'] for i in N[self.mol].keys()) R_mean = N[self.mol]['box%s' % self.box]['mean'] / Ni_tot * 100 R_stdev = pow( pow( 1 / Ni_tot - N[self.mol]['box%s' % self.box]['mean'] / pow(Ni_tot, 2), 2) * pow(N[self.mol]['box%s' % self.box]['stdev'], 2), 0.5) * 100 writeAGR([X['mean']], [R_mean], [calc95conf(X['stdev'], nIndep)], [calc95conf(R_stdev, nIndep)], [self.feed], file_name, file_description)
def rho_vapor(self): nIndep = self.gen_data[self.feed][self.run]['numIndep'] self.T = self.gen_data[self.feed][self.run]['temperature'] rho, N = self.rho[self.feed][self.run], self.N[self.feed][self.run] vapor_box = self.findVapBox(rho, self.mol) factor = 1 / N_av * R['nm**3*kPa/(mol*K)'] * self.T X = self.getX() file_description = '%s Pig %s dP' % (self.xlabel[0], self.xlabel[1]) file_name = 'rho-mol%s-%s_vs_%s.dat' % (self.mol, vapor_box, self.xlabel[0]) if (0 in self.indep) and (len(self.indep) == 1): vals = rho[self.mol][vapor_box]['raw'] x_vals = X['raw'] writeAGR(x_vals, vals, None, None, [self.feed for i in x_vals], file_name, file_description) else: mean, stdev = rho[self.mol][vapor_box]['mean'], rho[ self.mol][vapor_box]['stdev'] writeAGR([X['mean']], [mean], [calc95conf(X['stdev'], nIndep)], [calc95conf(stdev, nIndep)], [self.feed], file_name, file_description)
def dHigvX(self): U = self.U[self.feed][self.run] N = self.N[self.feed][self.run] gen_data = self.gen_data[self.feed][self.run] file_name = 'dHig_vapor_to_%s.dat' % self.box X = self.getX() N1_tot = sum(N[i][self.box]['mean'] for i in N.keys()) N1 = { 'mean': N1_tot, 'stdev': math.pow(sum(N[i][self.box]['stdev']**2 for i in N.keys()), 0.5) } # mol vapor_box = 'box3' N2_tot = sum(N[i][vapor_box]['mean'] for i in N.keys()) N2 = { 'mean': N2_tot, 'stdev': math.pow(sum(N[i][vapor_box]['stdev']**2 for i in N.keys()), 0.5) } # mol nIndep = gen_data['numIndep'] dH = (U[self.box]['mean'] / N1_tot - U[vapor_box]['mean'] / N2_tot) * 8.314 / 1000 - 8.314 / 1000 * self.T ddH = math.pow( (1 / N1_tot)**2 * U['box1']['stdev']**2 + (-1 * U['box1']['mean'] / N1['mean']**2)**2 * N1['stdev']**2 + (1 / N2_tot)**2 * U[vapor_box]['stdev']**2 + (-1 * U[vapor_box]['mean'] / N2['mean']**2)**2 * N2['stdev']**2, 0.5) * 8.314 / 1000 dH_mean, dH_stdev = dH, ddH file_description = 'dHig %s ddHig %s' % (self.xlabel[0], self.xlabel[1]) if '95conf' not in X.keys(): X['95conf'] = calc95conf(X['stdev'], nIndep) writeAGR([X['mean']], [dH_mean], [X['95conf']], [calc95conf(dH_stdev, nIndep)], [self.feed], file_name, file_description)
def dHvX(self): dH = self.dHmixt[self.feed][self.run] gen_data = self.gen_data[self.feed][self.run] file_description = 'Q(%s) %s dQ %s' % ( self.units, self.xlabel[0], self.xlabel[1]) if self.boxes: boxFrom, boxTo = self.boxes # else: # boxFrom = self.box # boxTo = 'box1' file_name = 'dH_%s_mixture.dat' % boxTo assert 'box' in boxFrom, 'Wrong notation for box' transfer = boxFrom + '-->' + boxTo X = self.getX() nIndep = gen_data['numIndep'] dH_mean, dH_stdev = dH[transfer]['mean'], dH[transfer]['stdev'] if '95conf' not in X.keys(): X['95conf'] = calc95conf(X['stdev'], nIndep) writeAGR([X['mean']], [dH_mean], [X['95conf']], [calc95conf(dH_stdev, nIndep)], [self.feed], file_name, file_description)
def SvX(self): ''' this is a special case of SvC, where we plot P as opposed to C and the boxFrom might not be the same for each molecule (ex: in the case of IG or kH adsorption) :param P: Pressure of x axis (note: not pressure data) ''' if (0 in self.indep) and (len(self.indep) == 1): raise NotImplemented rho = self.rho[self.feed][self.run] K = self.K[self.feed][self.run] if 'P-box' in self.xlabel[0]: P = self.P[self.feed][self.run] X = self.getX() file_description = '%s S(%s) %s dS' % ( self.xlabel[0], self.units, self.xlabel[1]) gen_data = self.gen_data[self.feed][self.run] nIndep = gen_data['numIndep'] for mol_pair in K['box1']: K_to = K['box1'][mol_pair] mol1, mol2 = map(int, mol_pair.split('/')) file_name = 'S_%s-vs-%s.dat' % (mol_pair, self.xlabel[0]) if (('P' in self.xlabel[0]) or ('C' in self.xlabel[0])): if 'P-box' in self.xlabel[0]: vapor_box_a = self.findVapBox(rho, '%i' % mol1) vapor_box_b = self.findVapBox(rho, '%i' % mol2) pa, pa_stdev = P[vapor_box_a]['mean'], P[vapor_box_a][ 'stdev'] pb, pb_stdev = P[vapor_box_b]['mean'], P[vapor_box_b][ 'stdev'] K_from = { 'mean': pa / pb, 'stdev': eProp_division(pa, pa_stdev, pb, pb_stdev) } elif 'P' in self.xlabel[0]: vapor_box = self.findVapBox(rho, '%i' % mol1) K_from = K[vapor_box][mol_pair] elif 'C' in self.xlabel[0]: K_from = K['box2'][mol_pair] S_mean = K_to['mean'] / K_from['mean'] S_stdev = eProp_division(K_to['mean'], K_to['stdev'], K_from['mean'], K_from['stdev']) writeAGR([X['mean']], [S_mean], [calc95conf(X['stdev'], nIndep)], [calc95conf(S_stdev, nIndep)], [self.feed], file_name, file_description) elif 'kH' in self.xlabel[0]: if mol_pair == '%s/1' % self.mol: K_to['95conf'] = calc95conf(K_to['stdev'], nIndep) MW_W = gen_data['molecular weight']['1'] MW_D = gen_data['molecular weight'][self.mol] S_mean = (K_to['mean'] * (self.density[0] / X['mean'] - 1) * MW_D / MW_W) w = X['mean'] / self.density[0] S_long = K_to['mean'] / ((w / MW_D) / ((1 - w) / MW_W)) dS_dKto = (self.density[0] / X['mean'] - 1) * MW_D / MW_W dS_drho = K_to['mean'] / X['mean'] * MW_D / MW_W dS_dC = -K_to['mean'] * self.density[0] / math.pow( X['mean'], 2) * MW_D / MW_W S_95conf = math.sqrt( math.pow(dS_dKto * K_to['95conf'], 2) + math.pow(dS_drho * self.density[1], 2) + math.pow(dS_dC * X['95conf'], 2)) writeAGR([X['mean']], [S_mean], [X['95conf']], [S_95conf], [self.feed], file_name, file_description) elif self.mol == '1': K = 1 / K_to['mean'] dK = K * K_to['stdev'] / K_to['mean'] K_to = {'stdev': dK, 'mean': K} K_to['95conf'] = calc95conf(K_to['stdev'], nIndep) MW_W = gen_data['molecular weight']['2'] MW_D = gen_data['molecular weight'][self.mol] S_mean = (K_to['mean'] * (self.density[0] / X['mean'] - 1) * MW_D / MW_W) w = X['mean'] / self.density[0] S_long = K_to['mean'] / ((w / MW_D) / ((1 - w) / MW_W)) dS_dKto = (self.density[0] / X['mean'] - 1) * MW_D / MW_W dS_drho = K_to['mean'] / X['mean'] * MW_D / MW_W dS_dC = -K_to['mean'] * self.density[0] / math.pow( X['mean'], 2) * MW_D / MW_W S_95conf = math.sqrt( math.pow(dS_dKto * K_to['95conf'], 2) + math.pow(dS_drho * self.density[1], 2) + math.pow(dS_dC * X['95conf'], 2)) writeAGR([X['mean']], [S_mean], [X['95conf']], [S_95conf], [self.feed], file_name, file_description) else: print('mol pair', mol_pair, 'will not be considered for selectivity') else: print(self.xlabel, 'not considered')
def QvX(self): ''' :var X: either solution concentration (g/mL) or pressure (kPa) ''' assert self.units, 'Units must be defined for isotherm' N = self.N[self.feed][self.run] gen_data = self.gen_data[self.feed][self.run] file_description = '%s Q(%s) %s dQ' % ( self.xlabel[0], self.units, self.xlabel[1]) X = self.getX() nIndep = gen_data['numIndep'] mols_adsorbed = self.getMolAds(N) if (self.film == True): rho = self.rho[self.feed][self.run] zeolite_mass_g = gen_data['zeolite']['mass (g)'] + extra_film_mass else: zeolite_mass_g = gen_data['zeolite']['mass (g)'] for mol in mols_adsorbed: file_name = 'Qmol%s-%s-w%sin-zeo-vs-%s.dat' % ( mol, self.units, ''.join(mols_adsorbed), self.xlabel[0][:self.xlabel[0].find('(')]) if (self.film == True): # subtract the no. of molecules in vapor space vapor_box = self.findVapBox(rho, mol) numInVap = rho[mol][vapor_box]['mean'] * film_vapor_volume if self.units == 'molec/uc': qfactor = 1 / gen_data['zeolite']['unit cells'] elif self.units == 'g/g': qfactor = ((gen_data['molecular weight'][mol] / N_av) / zeolite_mass_g) elif self.units == 'mol/kg': if self.film == True: qfactor = (1 / N_av) / (zeolite_mass_g / 1000.) else: qfactor = gen_data['zeolite'][' mol/kg / 1 mlcl adsorbed'] if (0 in self.indep) and (len(self.indep) == 1): if not self.film: Q_vals = [i * qfactor for i in N[mol]['box1']['raw']] Q_stdev = [ N[mol]['box1']['stdev'] * qfactor for i in Q_vals ] else: raise NotImplemented writeAGR( X['raw'], Q_vals, None, None, ['%s/%i' % (self.feed, j) for j in range(1, nIndep + 1)], file_name, file_description) else: if not self.film: Q_mean, Q_stdev = (N[mol]['box1']['mean'] * qfactor, N[mol]['box1']['stdev'] * qfactor) else: Q_mean, Q_stdev = ((N[mol]['box1']['mean'] - numInVap) * qfactor, (N[mol]['box1']['stdev'] - numInVap) * qfactor) if '95conf' in X.keys(): dX = X['95conf'] else: dX = calc95conf(X['stdev'], nIndep) writeAGR([X['mean']], [Q_mean], [dX], [calc95conf(Q_stdev, nIndep)], [self.feed], file_name, file_description)