def make_experimental_data(jl_dir, py_dir): with open(py_dir + '/observable.py') as f: lines = f.readlines() for i, line in enumerate(lines): if line.find('class ExperimentalData') != -1: lines = lines[i:] break lines = triming_tools.replace_characters(lines) bracket = False for i, line in enumerate(lines): rep_line = line rep_line = rep_line.replace('observables.index', 'observables_index') key = line.replace(' ', '') if key.find('={') != -1: rep_line = rep_line.replace('{', 'Dict(') bracket = True if bracket: rep_line = rep_line.replace(':', ' =>') if line.find('}') != -1: rep_line = rep_line.replace('}', ')') bracket = False lines[i] = rep_line experimental_data = jl_source.experimental_data_header() experiments = triming_tools.cut_out_lines(lines, 'len(observables)', 'def get_timepoint', mode=1)[1:-1] for i, line in enumerate(experiments): experimental_data += triming_tools.indent_remover(line, 1) experimental_data += jl_source.get_timepoint_header() get_timepoint = triming_tools.cut_out_lines(lines, 'def get_timepoint', 'return')[1:] for i, line in enumerate(get_timepoint): rep_line = line rep_line = rep_line.replace('observables.index', 'observables_index') if line.find('return') != -1: break if line.replace(' ', '').find('exp_t=self.') != -1: rep_line = '' for j in range(triming_tools.space_counter(line)): rep_line += ' ' rep_line += line.replace(' ', '').replace('exp_t=self.', 'return ') experimental_data += triming_tools.indent_remover(rep_line, 1) experimental_data += jl_source.get_timepoint_footer() with open(jl_dir + '/experimental_data.jl', mode='w') as f: f.write(experimental_data)
def convert_search_parameter(jl_dir, py_dir): os.makedirs( jl_dir, exist_ok=True ) space_num = 4 with open(py_dir+'/search_parameter.py') as f: lines = f.readlines() search_parameter = jl_source.header() search_parameter += jl_source.search_idx_const_header() search_idx_const = triming_tools.cut_out_lines( lines, 'search_idx_const=[', ']' )[1:] for i, line in enumerate(search_idx_const): search_parameter += line.replace('\\', '') search_parameter += jl_source.search_idx_const_footer() search_parameter += jl_source.search_idx_init_header() search_idx_init = triming_tools.cut_out_lines( lines, 'search_idx_init=[', ']' )[1:] for i, line in enumerate(search_idx_init): search_parameter += line.replace('\\', '') search_parameter += jl_source.search_idx_init_footer() search_parameter += jl_source.get_search_region_header() lines = triming_tools.convert_comment_out(lines) lines = triming_tools.lines_triming(lines, space_num) lines = triming_tools.insert_end(lines) # for i,line in enumerate(lines): # print(line.replace('\n','')) search_region = triming_tools.cut_out_lines( lines, 'search_region=np.zeros', 'lin2log' )[1:] for i,line in enumerate(search_region): line = line.replace('for i, j', 'for (i,j)') line = line.replace('np.', '') line = line.replace('len', 'length') line = line.replace('(x)', '(p)') line = triming_tools.list_adder(line) search_parameter += line search_parameter += jl_source.get_search_region_footer() search_parameter += jl_source.lin2log() with open(jl_dir + '/search_parameter.jl', mode='w') as f: f.write(search_parameter)
def make_param_const(jl_dir, py_dir, space_num=4): jl_dir = jl_dir + '/model/param_const.jl' py_dir = py_dir + '/model/param_const.py' with open(py_dir, mode='r') as f: lines = f.readlines() lines = triming_tools.lines_triming(lines, space_num) lines = triming_tools.cut_out_lines(lines, 'len_f_params', 'return x')[1:] param_const = jl_source.param_const_header() for i, line in enumerate(lines): param_const += line param_const += jl_source.param_const_footer() with open(jl_dir, mode='w') as f: f.write(param_const)
def make_observable(jl_dir, py_dir): with open(py_dir + '/observable.py') as f: lines = f.readlines() observable = jl_source.observable_header() observables = triming_tools.cut_out_lines(lines, 'observables=[', ']')[1:] for i, line in enumerate(observables): observable += line.replace(',', '').replace('\'', '\"') observable += jl_source.observable_body() with open(jl_dir + '/observable.jl', mode='w') as f: f.write(observable)
def make_initial_condition(jl_dir, py_dir, space_num=4): jl_dir = jl_dir + '/model/initial_condition.jl' py_dir = py_dir + '/model/initial_condition.py' with open(py_dir, mode='r') as f: lines = f.readlines() lines = triming_tools.lines_triming(lines, space_num) lines = triming_tools.cut_out_lines(lines, 'len_f_vars', 'return y0')[1:] initial_condition = jl_source.initial_condition_header() for i, line in enumerate(lines): initial_condition += line initial_condition += jl_source.initial_condition_footer() with open(jl_dir, mode='w') as f: f.write(initial_condition)
def make_variables(jl_dir, py_dir, space_num=4): jl_dir = jl_dir + '/model/name2idx/variables.jl' py_dir = py_dir + '/model/name2idx/variables.py' with open(py_dir, mode='r') as f: lines = f.readlines() lines = triming_tools.lines_triming(lines, space_num) lines = triming_tools.cut_out_lines(lines, 'var_names', 'len_f_vars')[1:] variables = jl_source.variables_header() for i, line in enumerate(lines): variables += line variables = variables + jl_source.variables_footer() with open(jl_dir, mode='w') as f: f.write(variables)
def make_parameters(jl_dir, py_dir, space_num=4): jl_dir = jl_dir + '/model/name2idx/parameters.jl' py_dir = py_dir + '/model/name2idx/parameters.py' with open(py_dir, mode='r') as f: lines = f.readlines() lines = triming_tools.lines_triming(lines, space_num) lines = triming_tools.cut_out_lines(lines, 'param_names', 'len_f_params')[1:] parameters = jl_source.parameters_header() for i, line in enumerate(lines): parameters += line parameters = parameters + jl_source.parameters_footer() with open(jl_dir, mode='w') as f: f.write(parameters)
def make_simulation(jl_dir, py_dir): with open(py_dir + '/observable.py') as f: lines = f.readlines() lines = triming_tools.cut_out_lines(lines, 'class NumericalSimulation', 'class ExperimentalData') lines = triming_tools.lines_triming(lines) for i, line in enumerate(lines): lines[i] = triming_tools.copy_list(line) simulation = jl_source.simulation_header() line_tspan = triming_tools.cut_out_line(lines, 'tspan=') line_tspan = line_tspan.replace('[', '(').replace(']', ')') line_tspan = triming_tools.indent_remover(line_tspan, 1) line_t = triming_tools.cut_out_line(lines, 't=') simulation += triming_tools.insert_after_indent(line_tspan, 'const ') if line_t.find('/') != -1: line_t = line_t[line_t.find('/') + 1:] simulation += 'const t = collect(tspan[1]:1.0:tspan[end])./' + \ line_t + '\n' else: line_t = line_t[line_t.find(')') + 1:] simulation += 'const t = collect(tspan[1]:1.0:tspan[end])' + \ line_t + '\n' line_conditions = triming_tools.cut_out_line(lines, 'conditions=') simulation += triming_tools.indent_remover( triming_tools.insert_after_indent(line_conditions, 'const ') + '\n', 1) simulation += jl_source.simulation_body1() conditions1 = triming_tools.cut_out_lines(lines, 'def simulate(', 'steady_state')[1:] conditions2 = triming_tools.cut_out_lines(lines, '=copy', 'solveode', mode=1)[1:] conditions2 = triming_tools.insert_end(conditions2)[:-2] for i, line in enumerate(conditions1): simulation += line simulation += jl_source.simulation_body2() for i, line in enumerate(conditions2): simulation += line simulation += jl_source.simulation_body3() get_timepoint = triming_tools.cut_out_lines(lines, 'simulations[', 'class ExperimentalData', mode=1) for i, line in enumerate(get_timepoint): rep_line = line if rep_line.find('class ExperimentalData') != -1: break rep_line = rep_line.replace('self.', '') rep_line = rep_line.replace('observables.index', 'observables_index') if rep_line.find('Y[:, ') != -1: rep_line = rep_line.replace('Y[:, ', 'sol.u[j][') else: rep_line = rep_line.replace('Y[:,', 'sol.u[j][') if rep_line.find('simulations[') != -1: rep_line = rep_line.replace(':,', 'j,') simulation += rep_line simulation += jl_source.simulation_footer() with open(jl_dir + '/simulation.jl', mode='w') as f: f.write(simulation)