import os import sys # Get the directory containing the current file current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(current_dir, '../buildBG/')) from buildBG import * from utilities import * import math import numpy as np file_path=os.path.join(current_dir, '../Facilitated transporter/') fmatrix=file_path+'SLC2_f.csv' rmatrix=file_path+'SLC2_r.csv' bg_components_json='../buildBG/BG_components.json' # build the bond graph model bg_dict={} direction = 'e2f' add_BG_components(bg_dict,bg_components_json, fmatrix) add_BG_connections(bg_dict, fmatrix, direction) direction = 'f2e' add_BG_connections(bg_dict, rmatrix, direction) # update the equations of the bond graph model voi={'description': 'Time', 'units': 'second', 'symbol': 't'} update_BG_eqn(bg_dict,voi) fmatrix=file_path+'SLC2_f.csv' rmatrix=file_path+'SLC2_r.csv' # update the BG parameters for the biochemical reactions eName, eID, ePort, fName, fID, fPort,N_f=load_matrix(fmatrix) eName, eID, ePort, fName, fID, fPort,N_r=load_matrix(rmatrix) V=1 V_o=90 h=0.726;g=12.1;c=1113;d=90.3;a=500000*V_o;b=a*9.5;f=3000*V_o;e=12.8459*f kf=[h, c, a, e] kr=[g, d, b, f] V_i=0.09 V_o=0.09 V_E=1 Ws=[V_i,V_o,V_E,V_E,V_E,V_E] K_c=[] N_c=[] kappa, K, K_eq, diff_, zero_est,k_est= kinetic2BGparams(N_f,N_r,kf,kr,K_c,N_c,Ws) # print the estimated results for i in range(len(kappa)): print(fName[i],kappa[i]) for i in range(len(K)): print(eName[i],K[i]) k_est_name=['h','c','a','e','g','d','b','f'] for i in range(len(k_est)): print(k_est_name[i],k_est[i]) print('sum of relative errors',diff_) update_BioBG_params(bg_dict, kappa, fName, K, eName) update_BG_params(bg_dict,[('T',293)]) # combine K and kappa to a single array param_val=np.concatenate((kappa,K)) param_fName=[] for i in fName: param_fName.append('$\kappa_{'+i+'}$') param_eName=[] for i in eName: param_eName.append('$K_{'+i+'}$') param_name=param_fName+param_eName param_units=['fmol$.s^{-1}$']*len(fName)+['fmol$^{-1}$']*len(eName) write_params_csv(param_name,param_val,param_units,csv_file=file_path+'SLC2_BG.csv') # save the bond graph model to a json file json_file=file_path+'SLC2_BG.json' save_json(bg_dict, json_file)