def get_current_contacts(G, data): cs = data['cellStates'] it = iter(cs) n = len(cs) cell_type = {} pos_dict = {} for it in cs: cell_type[cs[it].idx] = cs[it].cellType pos_dict[cs[it].idx] = cs[it].pos[0:2] modname = data['moduleName'] moduleStr = data['moduleStr'] sim = Simulator(modname, 0.0, moduleStr=moduleStr, saveOutput=False) sim.loadFromPickle(data) sim.phys.update_grid() # we assume local cell_centers is current sim.phys.bin_cells() sim.phys.cell_sqs = sim.phys.cell_sqs_dev.get() # get updated cell sqs sim.phys.sort_cells() sim.phys.sorted_ids_dev.set( sim.phys.sorted_ids) # push changes to the device sim.phys.sq_inds_dev.set(sim.phys.sq_inds) sim.phys.find_contacts(predict=False) sim.phys.get_cts() ct_pts = sim.phys.ct_pts #these are the points on the cell surface - they can be transformed into the global coordinate system ct_tos = sim.phys.ct_tos #this is the list of *some* contacts from each cell (only for lower cell_ids) ct_dists = sim.phys.ct_dists cell_cts = sim.phys.cell_n_cts #not really all the contacts of the cell, because the tos are only defined between a cell and ones with lower ids generate_network(G, n, ct_tos, cell_cts, pos_dict, cell_type)
def loadPickle(self): options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog qs, _ = QFileDialog.getOpenFileName(self, 'Load pickle file', '', '*.pickle', options=options) if qs and self.getOpenCLPlatDev(): filename = str(qs) print(filename) data = pickle.load(open(filename, 'rb')) if isinstance(data, dict): self.modName = data['moduleName'] self.moduleStr = data['moduleStr'] self.frameNo = data['stepNum'] sim = Simulator(self.modName, \ self.dt, \ moduleStr=self.moduleStr, \ clPlatformNum=self.clPlatformNum, \ clDeviceNum=self.clDeviceNum, \ is_gui=True) self.loadingFromPickle = True sim.loadFromPickle(data) self.setSimulator(sim) # Note: the pickle loaded contains the stepNum, hence we now # need to set the GUI frameNo to match self.frameNo = self.sim.stepNum if self.run: self.frameNo += 1 self.updateGL() else: print("Pickle is in an unsupported format, sorry")
def loadPickle(self): qs = QtWidgets.QFileDialog.getOpenFileName( self, 'Load pickle file', '', '*.pickle') #kk:changed QtGui to QtWidgets if qs and self.getOpenCLPlatDev(): filename = str(qs[0]) #kk: changed how to load pickle with open(filename, "rb") as input_file: data = cPickle.load(input_file) if isinstance(data, dict): self.modName = data['moduleName'] self.moduleStr = data['moduleStr'] self.frameNo = data['stepNum'] sim = Simulator(self.modName, \ self.dt, \ moduleStr=self.moduleStr, \ clPlatformNum=self.clPlatformNum, \ clDeviceNum=self.clDeviceNum, \ is_gui=True) self.setSimulator(sim) self.loadingFromPickle = True self.sim.loadFromPickle(data) # Note: the pickle loaded contains the stepNum, hence we now # need to set the GUI frameNo to match self.frameNo = self.sim.stepNum if self.run: self.frameNo += 1 self.updateGL() else: print "Pickle is in an unsupported format, sorry"
def simulate(modfilename, platform, device, steps=50): (path,name) = os.path.split(modfilename) modname = str(name).split('.')[0] sys.path.append(path) sim = Simulator(modname, 0.25, clPlatformNum=platform, clDeviceNum=device) while len(sim.cellStates) < max_cells-cell_buffer: sim.step()
def reset(self): # Note: we don't ask user to choose OpenCL platform/device on reset, only load if not self.loadingFromPickle: reload(self.sim.module) if self.loadingFromPickle: sim = Simulator(self.modName, \ self.dt, \ moduleStr=self.moduleStr, \ clPlatformNum=self.clPlatformNum, \ clDeviceNum=self.clDeviceNum) self.setSimulator(sim) else: sim = Simulator(self.modName, \ self.dt, \ clPlatformNum=self.clPlatformNum, \ clDeviceNum=self.clDeviceNum) self.setSimulator(sim) self.frameNo = 0 self.updateGL()
def loadModelFile(self, modname): if self.getOpenCLPlatDev(): self.loadingFromPickle=False (path,name) = os.path.split(modname) self.modName = str(name).split('.')[0] sys.path.append(path) sim = Simulator(self.modName, \ self.dt, \ clPlatformNum=self.clPlatformNum, \ clDeviceNum=self.clDeviceNum) self.setSimulator(sim) self.updateGL()
def simulate(mod_name, steps=50): print('simulate') sim = Simulator(mod_name, 0.25, None, pickleSteps=50, pickleFileRoot=pickleFileRoot) print('start') sim.phys.set_cells() sim.phys.calc_cell_geom() while len(sim.cellStates) < max_cells - cell_buffer: sim.step()
def simulate(mod_name, config_file): sim = Simulator(mod_name, 0.25, config_file) while len(sim.cellStates) < max_cells: sim.step()
def simulate(mod_name, ingam, fname): sim = Simulator(mod_name, 0.25, ingam, 25, fname) while len(sim.cellStates) < max_cells-cell_buffer: sim.step()
def simulate(mod_name, steps, dt): sim = Simulator(mod_name, dt) for i in range(num_steps): sim.step()
def simulate(mod_name, device): sim = Simulator(mod_name, 0.25, device) while len(sim.cellStates) < max_cells-cell_buffer: sim.step()