def __init__(self, psc_file, variable_names, v_name, ranges, psc_string=None): self.psc_file = psc_file self.psc_string = psc_string self.variable_names = variable_names self.v_name = 'J_{0}'.format(v_name) if v_name[0:2] != 'J_' else v_name self.ranges = ranges import pysces if self.psc_string is None: self.mod = pysces.model(self.psc_file) else: self.mod = pysces.model(self.psc_file, loader='string', fString=self.psc_string) self.mod.SetQuiet() self.variables = None self.v = numpy.array([]) self.scanner = pysces.Scanner(self.mod) for n, r in zip(self.variable_names, self.ranges): self.scanner.addScanParameter(n, r[0], r[1], r[2]) self.scanner.addUserOutput(self.v_name) self.scanner.Run() results = self.scanner.getResultMatrix() self.variables = results[:, 0:-1] self.v = results[:, -1]
def P_SCAN(self, *args): """Args: (par, out, par*[str(p),float(start),float(end),int(points), log=(int(0/1)),follower=(int(0/1))], [out*str(o)]) """ self.setStatus('SCANNING') args = args[0] print('Args', args) commands = [] cpoint = 1 shift = 0 for set in range(int(args[0])): ctmp = [] for t in range(2, 8): cpoint += 1 ctmp.append(args[t + shift].strip()) commands.append(ctmp) shift += 6 output = [] for out in range(int(args[1])): cpoint += 1 output.append(args[cpoint].strip()) print('\n', commands) print(output, '\n') scan = pysces.Scanner(self.model) scan.quietRun = True for gen in commands: print(gen) print( gen[0], float(gen[1]), float(gen[2]), int(gen[3]), bool(int(gen[4])), bool(int(gen[5])), ) scan.addGenerator( gen[0], float(gen[1]), float(gen[2]), int(gen[3]), log=bool(int(gen[4])), follower=bool(int(gen[5])), ) scan.addUserOutput(*output) scan.Run() self.RESULT = scan.UserOutputResults self.setStatus('DONE_SCAN') del scan return True
def do_mca_scan(self): ecs = [] ccs = [] prc_names = [] rc_names = [] rc_pos = [] reagent_of = [each[2:] for each in self.scan_results.flux_names] all_reactions = reagent_of + \ getattr(self._model_map, self.scan_results.fixed).isModifierOf() arl = len(all_reactions) strt = 0 stp = arl for flux_reaction in self.scan_results.flux_names: reaction = flux_reaction[2:] rc_names.append('rcJ%s_%s' % (reaction, self.scan_results.fixed)) rc_pos.append(range(strt, stp)) strt += arl stp += arl for route_reaction in all_reactions: ec = 'ec' + route_reaction + '_' + self.scan_results.fixed cc = 'ccJ' + reaction + '_' + route_reaction name = 'prcJ%s_%s_%s' % (reaction, self.scan_results.fixed, route_reaction) # ecs.append(ec) if ec not in ecs: ecs.append(ec) ccs.append(cc) prc_names.append(name) ec_len = len(ecs) user_output = [self.scan_results.fixed] + ecs + ccs scanner = pysces.Scanner(self.mod) scanner.quietRun = True scanner.addScanParameter(self.scan_results.fixed, self.scan_results.scan_min, self.scan_results.scan_max, self.scan_results.scan_points, log=True) scanner.addUserOutput(*user_output) scanner.Run() ax_properties = {'ylabel': 'Coefficient Value', 'xlabel': '[%s]' % self.scan_results.fixed.replace('_', ' '), 'xscale': 'log', 'yscale': 'linear', 'xlim': [self.scan_results.scan_min, self.scan_results.scan_max]} cc_ec_data_obj = Data2D(mod=self.mod, column_names=user_output, data_array=scanner.UserOutputResults, ltxe=self._ltxe, analysis_method=self._analysis_method, ax_properties=ax_properties, file_name='cc_ec_scan', num_of_groups=ec_len, working_dir=path.split(self._working_dir)[0]) rc_data = [] all_outs = scanner.UserOutputResults[:, 1:] ec_outs = all_outs[:, :ec_len] cc_outs = all_outs[:, ec_len:] ec_positions = range(ec_len) * (len(prc_names)/ec_len) for i, prc_name in enumerate(prc_names): ec_col_data = ec_outs[:, ec_positions[i]] cc_col_data = cc_outs[:, i] # ec_col_data = outs[:, i] # cc_col_data = outs[:, i + cc_s_pos] col = ec_col_data * cc_col_data rc_data.append(col) temp = numpy.vstack(rc_data).transpose() rc_data += [numpy.sum(temp[:, rc_pos[i]], axis=1) for i in range(len(rc_names))] rc_out_arr = [scanner.UserOutputResults[:, 0]] + rc_data rc_out_arr = numpy.vstack(rc_out_arr).transpose() rc_data_obj = Data2D(mod=self.mod, column_names=[self.scan_results.fixed] + prc_names + rc_names, data_array=rc_out_arr, ltxe=self._ltxe, analysis_method=self._analysis_method, ax_properties=ax_properties, file_name='prc_scan', num_of_groups=ec_len, working_dir=path.split(self._working_dir)[0]) #rc_data_obj._working_dir = path.split(self._working_dir)[0] #cc_ec_data_obj._working_dir = path.split(self._working_dir)[0] return rc_data_obj, cc_ec_data_obj
#!/usr/bin/env python # Testing the new parallel scanner class import os backupdir = os.getcwd() import numpy as np import pysces tbox=pysces.PyscesUtils.TimerBox() import time m=pysces.model('isola2a') ser = pysces.Scanner(m) print("Serial execution...") print("Start: ", tbox.normal_timer('SER')) print(next(tbox.SER)) t1=time.time() ser.quietRun = True ser.addScanParameter('V4',60,100,11) ser.addScanParameter('V1',100,160,16) ser.addScanParameter('V2',100,130,16,slave=True) ser.addScanParameter('V3',80,90,6) ser.addUserOutput('J_R1', 'A', 'ecR4_X','ccJR1_R1') #ser.addUserOutput('J_R1', 'A') ser.Run() print("Done: ", next(tbox.SER)) t2=time.time() print("Duration: %.2f seconds" % (t2-t1))