def _showVolumesChimera(self): tmpFileNameCMD = self.protocol._getTmpPath("chimera.cmd") f = open(tmpFileNameCMD, "w") dim = self.protocol.inputVolumes.get().getDim()[0] sampling = self.protocol.inputVolumes.get().getSamplingRate() tmpFileName = os.path.abspath(self.protocol._getTmpPath("axis.bild")) Chimera.createCoordinateAxisFile(dim, bildFileName=tmpFileName, sampling=sampling) f.write("open %s\n" % tmpFileName) f.write("cofr 0,0,0\n") # set center of coordinates _inputVol = self.protocol.inputVolumes.get() _outputVol = self.protocol.outputVolume inputVolFileName = os.path.abspath(ImageHandler.removeFileType( _inputVol.getFileName())) # input vol origin coordinates x_input, y_input, z_input = _inputVol.getShiftsFromOrigin() f.write("open %s\n" % inputVolFileName) f.write("volume #1 style mesh level 0.001 voxelSize %f origin " "%0.2f,%0.2f,%0.2f\n" % (_inputVol.getSamplingRate(), x_input, y_input, z_input)) outputVolFileName = os.path.abspath(ImageHandler.removeFileType( _outputVol.getFileName())) # output vol origin coordinates x_output, y_output, z_output = _outputVol.getShiftsFromOrigin() f.write("open %s\n" % outputVolFileName) f.write("volume #2 style surface level 0.001 voxelSize %f origin " "%0.2f,%0.2f,%0.2f\n" % (_outputVol.getSamplingRate(), x_output, y_output, z_output)) cMap = ['red', 'yellow', 'green', 'cyan', 'blue'] d = {} d['outerRadius'] = self.protocol.outerRadius.get() * sampling d['innerRadius'] = self.protocol.innerRadius.get() * sampling d['symmetry'] = Chimera.getSymmetry(self.protocol.symmetryGroup.get()) if self.protocol.symmetryGroup >= SYM_I222: f.write("shape icosahedron mesh true radius %(outerRadius)d " "orientation %(symmetry)s\n" % d) step = (d['outerRadius'] - d['innerRadius']) / float(len(cMap) - 1) f.write("scolor #2 geom radial center 0,0,0 cmap ") counter = 0 s = "" for color in cMap: s += "%d,%s:" % (d['innerRadius'] + counter * step, color) counter += 1 f.write(s[:-1] + '\n') f.close() return [ChimeraView(tmpFileNameCMD)]
def visualize(self, obj, **kwargs): cls = type(obj) if issubclass(cls, AtomStruct): # if attribute _chimeraScript exists then protocol # has create a script file USE IT if hasattr(obj, '_chimeraScript'): fn = obj._chimeraScript.get() ChimeraView(fn).show() return # if not create a script file with: coordinates axis, PDB and # volume (if available) else: fn = obj.getFileName() # check if tmp dir exists, if not use /tmp # tmp does not exists if you try to visualize something (eye) # before irunning the protocol tmpPath = self.protocol._getTmpPath() if not os.path.exists(tmpPath): tmpPath = "/tmp" fnCmd = os.path.join(tmpPath, "chimera.cmd") f = open(fnCmd, 'w') f.write("cofr 0,0,0\n") # set center of coordinates if obj.hasVolume(): volID = 0 volumeObject = obj.getVolume() dim = volumeObject.getDim()[0] sampling = volumeObject.getSamplingRate() f.write("open %s\n" % os.path.abspath( ImageHandler.removeFileType( volumeObject.getFileName()))) f.write("volume #%d style surface voxelSize %f\n" % (volID, sampling)) x, y, z = volumeObject.getShiftsFromOrigin() f.write("volume #%d origin %0.2f,%0.2f,%0.2f\n" % (volID, x, y, z)) else: dim = 150 # eventually we will create a PDB library that # computes PDB dim sampling = 1. # Construct the coordinate file bildFileName = os.path.abspath( os.path.join(tmpPath, "axis.bild")) Chimera.createCoordinateAxisFile(dim, bildFileName=bildFileName, sampling=sampling) f.write("open %s\n" % bildFileName) f.write("open %s\n" % os.path.abspath(fn)) f.close() ChimeraView(fnCmd).show() # FIXME: there is an asymmetry between ProtocolViewer and Viewer # for the first, the visualize method return a list of View's # (that are shown) # for the second, the visualize directly shows the objects. # the first approach is better else: raise Exception('ChimeraViewer.visualize: ' 'can not visualize class: %s' % obj.getClassName())
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ tmpFileNameCMD = self.protocol._getTmpPath("chimera.cmd") f = open(tmpFileNameCMD, "w") sampling, _setOfVolumes = self._createSetOfVolumes() count = 0 # first model in chimera is a volume if len(_setOfVolumes) == 1: count = 1 # first model in chimera is the bild file # if we have a single volume then create axis # as bild file. Chimera must read the bild file first # otherwise system of coordinates will not # be in the center of the window dim = self.protocol.outputVolume.getDim()[0] tmpFileNameBILD = os.path.abspath(self.protocol._getTmpPath( "axis.bild")) Chimera.createCoordinateAxisFile(dim, bildFileName=tmpFileNameBILD, sampling=sampling) f.write("open %s\n" % tmpFileNameBILD) f.write("cofr 0,0,0\n") # set center of coordinates count = 1 # skip first model because is not a 3D map for vol in _setOfVolumes: localVol = os.path.abspath(ImageHandler.removeFileType( vol.getFileName())) if localVol.endswith("stk"): errorWindow(None, "Extension .stk is not supported") f.write("open %s\n" % localVol) f.write("volume#%d style surface voxelSize %f\n" % (count, sampling)) count += 1 if len(_setOfVolumes) > 1: f.write('tile\n') else: x, y, z = vol.getShiftsFromOrigin() f.write("volume#1 origin %0.2f,%0.2f,%0.2f\n" % (x, y, z)) f.close() return [ChimeraView(tmpFileNameCMD)]