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 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 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 simulate(modfilename, steps=50): (path,name) = os.path.split(modfilename) modname = str(name).split('.')[0] sys.path.append(path) sim = Simulator(modname, 0.25, None) while len(sim.cellStates) < max_cells-cell_buffer: sim.step()
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 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, 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 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 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 loadFile(self, modstr): (path,name) = os.path.split(modstr) modname = str(name).split('.')[0] self.modname = modname sys.path.append(path) if self.sim: self.sim.reset(modname) else: self.sim = Simulator(modname, self.dt) #self.draw() self.paintGL()
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, device): sim = Simulator(mod_name, 0.25, device) 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, config_file): sim = Simulator(mod_name, 0.25, config_file) while len(sim.cellStates) < max_cells: sim.step()
def simulate(modstr, platform, device, steps=50): sim = Simulator('fracbatch_var', 0.1, clPlatformNum=platform, clDeviceNum=device, moduleStr=modstr, saveOutput=True) sim.saveOutput=True while len(sim.cellStates) < max_cells-cell_buffer: 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=50): sim = Simulator(mod_name, 0.25) while len(sim.cellStates) < max_cells-cell_buffer: sim.step()
def reset(self): self.sim = Simulator(self.modname, self.dt) #if self.sim: # self.sim.reset() self.frameNo = 0
class PyGLCMViewer(PyGLWidget): selectedCell = pyqtSignal(str)#CellState, name='selectedCell') selectedName = -1 dt = 0.25 def __init__(self, parent = None): PyGLWidget.__init__(self,parent) self.animTimer = QTimer() self.animTimer.timeout.connect(self.animate) self.renderInfo = None self.sim= None self.modfile = None self.record = False self.set_radius(32) self.frameNo = 0 def help(self): pass def setSimulator(self, sim): self.sim = sim @pyqtSlot(bool) def toggleRun(self, run): if run: self.animTimer.start(0) else: self.animTimer.stop() @pyqtSlot(bool) def toggleRecord(self, rec): self.record = rec self.sim.savePickle = rec @pyqtSlot() def reset(self): self.sim = Simulator(self.modname, self.dt) #if self.sim: # self.sim.reset() self.frameNo = 0 @pyqtSlot() def load(self): qs = QtGui.QFileDialog.getOpenFileName(self, 'Load Python module', '', '*.py') self.modfile = str(qs) self.loadFile(self.modfile) def loadFile(self, modstr): (path,name) = os.path.split(modstr) modname = str(name).split('.')[0] self.modname = modname sys.path.append(path) if self.sim: self.sim.reset(modname) else: self.sim = Simulator(modname, self.dt) #self.draw() self.paintGL() def animate(self): if self.sim: self.sim.step() self.updateSelectedCell() self.frameNo += 1 if self.record: if (self.frameNo%5)==0: #self.setSnapshotCounter(self.frameNo) self.updateGL() self.saveSnapshot() def saveSnapshot(self): print "saving snapshot", self.frameNo buf = self.grabFrameBuffer() return buf.save(os.path.join( self.sim.pickleDir,"{0:07}-frame.png".format(self.frameNo)), "png") def updateSelectedCell(self): if self.sim: states = self.sim.cellStates cid = self.selectedName txt = '' if states.has_key(cid): s = states[cid] for (name,val) in s.__dict__.items(): if name not in CellState.excludeAttr: vals = str(val) #if len(vals)>6: vals = vals[0:6] txt = txt + name + ': ' + vals + '\n' self.selectedCell.emit(txt) if self.sim.stepNum%100==0: self.updateGL() def postSelection(self, name): self.selectedName = name self.updateSelectedCell() def paintGL(self): PyGLWidget.paintGL(self) glClearColor(0.5,0.5,0.5,0.0) glClear(GL_COLOR_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glPushMatrix() #s = self.renderInfo.scale #glScalef(s,s,s) if self.sim: for r in self.sim.renderers: if r != None: r.render_gl(self.selectedName) glPopMatrix() def drawWithNames(self): glMatrixMode(GL_MODELVIEW) glPushMatrix() #s = self.renderInfo.scale #glScalef(s,s,s) if self.sim: for r in self.sim.renderers: if r: r.renderNames_gl() glPopMatrix()