def _visualize(self, obj, **args): import os fnCmd = self.protocol._getPath('result_strain_chimera.cmd') if os.path.exists(fnCmd): self._views.append(ChimeraView(fnCmd)) fnCmd = self.protocol._getPath('result_localrot_chimera.cmd') if os.path.exists(fnCmd): self._views.append(ChimeraView(fnCmd)) fnCmd = self.protocol._getPath('result_morph_chimera.cmd') if os.path.exists(fnCmd): self._views.append(ChimeraView(fnCmd)) return self._views
def _doShowStrain(self, param=None): scriptFile = self.protocol._getPath('strain_chimera.cxc') fhCmd = open(scriptFile, 'w') fnbase = removeExt(self.protocol._getFileName('fnInputVol')) ext = getExt(self.protocol._getFileName('fnInputVol')) fninput = abspath(fnbase + ext[0:4]) smprt = self.protocol.outputVolume.getSamplingRate() fnbase2 = removeExt(self.protocol._getFileName('fnOutVol')) fnStrain = abspath(fnbase2) fhCmd.write(self.OPEN_FILE % fninput) fhCmd.write(self.OPEN_FILE % (fnStrain + "_strain.mrc")) counter = 1 fhCmd.write(self.VOXEL_SIZE % (counter, str(smprt))) counter += 1 fhCmd.write(self.VOXEL_SIZE % (counter, str(smprt))) fhCmd.write(self.VOL_HIDE % counter) fhCmd.write('color sample #%d map #%d palette rainbow\n' % (counter - 1, counter)) fhCmd.write(self.VIEW) fhCmd.close() view = ChimeraView(scriptFile) return [view]
def _showVolumesChimera(self): tmpFileNameCMD = self.protocol._getExtraPath("chimera.cxc") f = open(tmpFileNameCMD, "w") dim = self.protocol.inputVolumes.get().getDim()[0] sampling = self.protocol.inputVolumes.get().getSamplingRate() tmpFileName = os.path.abspath(self.protocol._getExtraPath("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 #2 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 #3 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 = {} innerRadius = self.protocol.innerRadius.get() d['outerRadius'] = self.protocol.outerRadius.get() * sampling if innerRadius < 0: innerRadius = 0 d['innerRadius'] = innerRadius * sampling d['innerRadius'] = self.protocol.innerRadius.get() * sampling d['symmetry'] = Chimera.getSymmetry(XMIPP_TO_SCIPION[self.protocol.symmetryGroup.get()]) if self.protocol.symmetryGroup >= XMIPP_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("color radial #3 center 0,0,0 palette -") 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 _doShowDeformedOrigRef(self, param=None): scriptFile = self.protocol._getPath('morph_deformed_ref_chimera.cxc') fhCmd = open(scriptFile, 'w') fnbase = removeExt(self.protocol._getFileName('fnOutVol')) ext = getExt(self.protocol._getFileName('fnOutVol')) fninput = abspath(fnbase + ext[0:4]) smprt = self.protocol.outputVolume.getSamplingRate() fnbase2 = removeExt(self.protocol._getFileName('fnRefVol')) ext2 = getExt(self.protocol._getFileName('fnRefVol')) fnref = abspath(fnbase2 + ext2[0:4]) fhCmd.write(self.OPEN_FILE % fninput) fhCmd.write(self.OPEN_FILE % fnref) counter = 1 fhCmd.write(self.VOXEL_SIZE % (counter, str(smprt))) fhCmd.write(self.VOL_HIDE % counter) counter += 1 fhCmd.write(self.VOXEL_SIZE % (counter, str(smprt))) # fhCmd.write("focus\n") fhCmd.write(self.VOL_HIDE % counter) fhCmd.write("volume morph #%d,%d frames 500\n" % (counter - 1, counter)) fhCmd.write(self.VIEW) fhCmd.close() view = ChimeraView(scriptFile) return [view]
def _visualize_norm_pdb(self, obj, **args): self._create_legend(1.5); fnCmd = self.protocol._getExtraPath("chimera_output.py") f = open(fnCmd, 'a') f.write("run(session, 'open %s')\n" % self.protocol._getFileName(PDB_NORM_FILE)) if self.displayNormPDB == self.RESIDUE: f.write("run(session, 'cartoon')\n") f.write("run(session, 'hide target ab')\n") f.write("run(session, 'color byattribute occupancy palette" " -1.5,red:-1.0,orange:-0.5,gold:0,yellow:0.5,lime:1.0,cyan:1.5,#1e90ff" " ave residue')\n") else: f.write("run(session, 'cartoon hide')\n") f.write("run(session, 'show target ab')\n") f.write("run(session, 'style stick')\n") f.write("run(session, 'color byattribute occupancy palette" " -1.5,red:-1.0,orange:-0.5,gold:0,yellow:0.5,lime:1.0,cyan:1.5,#1e90ff')\n") f.close() view = ChimeraView(fnCmd) return [view]
def _showChimera(self, param=None): if (exists(self.protocol._getExtraPath("MG_Chimera_resolution.mrc"))): fnResVol = self.protocol._getExtraPath("MG_Chimera_resolution.mrc") else: fnResVol = self.protocol._getExtraPath(OUTPUT_RESOLUTION_FILE_CHIMERA) if self.sharpenedMap.get(): fnOrigMap = self.sharpenedMap.get().getFileName() sampRate = self.sharpenedMap.get().getSamplingRate() else: if self.protocol.useHalfVolumes.get(): if self.protocol.hasHalfVolumesFile.get(): vol = self.protocol.associatedHalves.get().getHalfMaps() fnOrigMap, _unused = vol.split(',') sampRate = self.protocol.associatedHalves.get().getSamplingRate() else: vol = self.protocol.halfMap1.get() fnOrigMap = vol.getFileName() sampRate = vol.getSamplingRate() else: vol = self.protocol.fullMap.get() fnOrigMap = vol.getFileName() sampRate = vol.getSamplingRate() cmdFile = self.protocol._getExtraPath('chimera_resolution_map.py') self.createChimeraScript(cmdFile, fnResVol, fnOrigMap, sampRate, numColors=self.intervals.get(), lowResLimit=self.highest.get(), highResLimit=self.lowest.get()) view = ChimeraView(cmdFile) return [view]
def _viewStrain(self, e=None): import os protToShow = self.protToShow.get() protId = protToShow.getObjId() views = [] fnCmd = self.protocol._getPath('%d_result_strain_chimera.cmd' % protId) if os.path.exists(fnCmd): views.append(ChimeraView(fnCmd)) fnCmd = self.protocol._getPath('%d_result_localrot_chimera.cmd' % protId) if os.path.exists(fnCmd): views.append(ChimeraView(fnCmd)) fnCmd = protToShow._getPath('result_morph_chimera.cmd') if os.path.exists(fnCmd): views.append(ChimeraView(fnCmd)) return views
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ tmpFileNameCMD = self.protocol._getExtraPath("chimera.cxc") f = open(tmpFileNameCMD, "w") sampling, _setOfVolumes = self._createSetOfVolumes() count = 1 # chimeraX stars counting in 1 (chimera in 0) if len(_setOfVolumes) == 1: # 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._getExtraPath("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 = 2 # skip first model because is not a 3D map for vol in _setOfVolumes: localVol = os.path.abspath( image.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 level 0.001 voxelSize %f\n" % (count, sampling)) count += 1 if len(_setOfVolumes) > 1: f.write('tile\n') else: x, y, z = vol.getShiftsFromOrigin() f.write("volume #2 origin %0.2f,%0.2f,%0.2f\n" % (x, y, z)) if vol.getHalfMaps(): for halfMap in vol.getHalfMaps().split(','): if not os.path.abspath(halfMap).endswith(".mrc"): f.write( "open %s\n" % (os.path.abspath(halfMap).split(".")[0] + ".mrc")) else: f.write("open %s\n" % os.path.abspath(halfMap)) f.write( "volume #%d style surface level 0.001 voxelSize %f\n" % (count, sampling)) f.write("volume #%d origin %0.2f,%0.2f,%0.2f\n" % (count, x, y, z)) f.write("tile\n") count += 1 f.write("view\n") f.close() return [ChimeraView(tmpFileNameCMD)]
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ volume = self._getVolumeName() cmdFile = self.protocol._getExtraPath('chimera_volumes.cxc') with open(cmdFile, 'w+') as f: localVol = os.path.relpath(volume, self.protocol._getExtraPath()) if os.path.exists(volume): f.write("open %s\n" % localVol) view = ChimeraView(cmdFile) return [view]
def _showChimera(self, param=None): fnResVol = self.protocol._getFileName(FN_RESOLMAP) fnOrigMap = self.protocol.inputVolume.get().getFileName() cmdFile = self.protocol._getExtraPath('chimera_resolution_map.py') sampRate = self.protocol.resolution_Volume.getSamplingRate() self.createChimeraScript(cmdFile, fnResVol, fnOrigMap, sampRate, numColors=self.intervals.get(), lowResLimit=self.highest.get(), highResLimit=self.lowest.get()) view = ChimeraView(cmdFile) return [view]
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ volumes = self._getVolumeNames() cmdFile = self.protocol._getExtraPath('chimera_volumes.cmd') with open(cmdFile, 'w+') as f: for vol in volumes: # We assume that the chimera script will be generated # at the same folder as 3DFSC volumes if os.path.exists(vol): localVol = os.path.relpath(vol, self.protocol._getExtraPath()) f.write("open %s\n" % localVol) f.write('tile\n') view = ChimeraView(cmdFile) return [view]
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ volumes = self.getVolumeNames() cmdFile = self._getFinalPath('chimera_volumes.cxc') with open(cmdFile, 'w+') as f: for vol in volumes: # We assume that the chimera script will be generated # at the same folder than spider volumes localVol = os.path.basename(vol) if os.path.exists(vol): f.write("open %s format spider\n" % localVol) f.write('tile\n') view = ChimeraView(cmdFile) return [view]
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ volumes = self._getVolumeNames() cmdFile = self.protocol._getExtraPath('chimera_volumes.cxc') with open(cmdFile, 'w+') as f: for vol in volumes: # remove ":mrc" extension needed by xmipp vol = vol.replace(":mrc", "") # We assume that the chimera script will be generated # at the same folder as relion volumes localVol = os.path.basename(vol) if os.path.exists(vol): f.write("open %s\n" % localVol) f.write('tile\n') view = ChimeraView(cmdFile) return [view]
def _showChimera(self, param=None): fnResVol = self.protocol._getFileName(OUTPUT_RESOLUTION_FILE_CHIMERA) fnOrigMap = self.protocol._getFileName(RESIZE_VOL) sampRate = 1.0 # Res volume and original volume are at different scales cmdFile = self.protocol._getExtraPath('chimera_resolution_map.py') self.createChimeraScript(cmdFile, fnResVol, fnOrigMap, sampRate, numColors=self.intervals.get(), lowResLimit=self.highest.get(), highResLimit=self.lowest.get()) view = ChimeraView(cmdFile) return [view]
def _doShowPDB(self, obj, **kwargs): scriptFile = self.protocol._getPath('pdb_deform_chimera.cxc') fhCmd = open(scriptFile, 'w') inputFile = os.path.abspath(self.protocol.inputPDB.get().getFileName()) outputFile = os.path.abspath(self.protocol.outputPDB.getFileName()) fhCmd.write(self.OPEN_FILE % inputFile) fhCmd.write(self.OPEN_FILE % outputFile) # fhCmd.write("start Model Panel\n") fhCmd.write("show cartoons\n") fhCmd.write("cartoon style width 1.5 thick 1.5\n") fhCmd.write("style stick\n") fhCmd.write("color bymodel\n") fhCmd.close() view = ChimeraView(scriptFile) return [view]
def _showTomogramsChimera(self): """ Create a chimera script to visualize selected tomograms. """ tmpFileNameCMD = self._getExtraFolder("chimera.cxc") f = open(tmpFileNameCMD, "w") sampling, _setOfObjects = self._getSetAndSampling() count = 1 # first model in chimera is a tomogram if len(_setOfObjects) == 1: count = 2 # first model in chimera is the bild file # if we have a single tomogram 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 = _setOfObjects.getDim()[0] tmpFileNameBILD = os.path.abspath( self._getExtraFolder("axis.bild")) viewers.viewer_chimera.Chimera.createCoordinateAxisFile( dim, bildFileName=tmpFileNameBILD, sampling=sampling) f.write("open %s\n" % tmpFileNameBILD) f.write("cofr 0,0,0\n") # set center of coordinates oldFileName = "" for tomo in _setOfObjects: fileName = tomo.getFileName() if fileName == oldFileName: continue else: oldFileName = fileName localTomo = os.path.abspath( ImageHandler.removeFileType(tomo.getFileName())) if localTomo.endswith("stk"): self.showError("Extension .stk is not supported") f.write("open %s\n" % localTomo) f.write("volume #%d style surface voxelSize %f\n" % (count, sampling)) f.write("volume #%d level 1\n" % count) count += 1 if len(_setOfObjects) > 1: f.write('tile\n') else: x, y, z = tomo.getShiftsFromOrigin() f.write("volume #2 origin %0.2f,%0.2f,%0.2f\n" % (x, y, z)) f.close() view = ChimeraView(tmpFileNameCMD) return [view]
def _doShowMorph(self, obj, **kwargs): scriptFile = self.protocol._getPath('pdb_deform_chimera.cxc') fhCmd = open(scriptFile, 'w') inputFile = os.path.abspath(self.protocol.inputPDB.get().getFileName()) outputFile = os.path.abspath(self.protocol.outputPDB.getFileName()) fhCmd.write(self.OPEN_FILE % inputFile) fhCmd.write(self.OPEN_FILE % outputFile) fhCmd.write("hide models\n") fhCmd.write("morph #1,2 frames 50 play false\n") fhCmd.write("coordset #3 1,\n") fhCmd.write("wait 50\n") fhCmd.write("coordset #3 50,1\n") fhCmd.close() view = ChimeraView(scriptFile) return [view]
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ prot = self.protocol volumes = self._getVolumeNames() extra = prot._getExtraPath() cmdFile = prot._getExtraPath('chimera_volumes.cxc') with open(cmdFile, 'w+') as f: for vol in volumes: localVol = os.path.relpath(vol, extra) if os.path.exists(vol): f.write("open %s\n" % localVol) f.write('tile\n') view = ChimeraView(cmdFile) return [view]
def _showVolumesChimera(self, volumes): """ Create a chimera script to visualize selected volumes. """ if len(volumes) > 1: cmdFile = self.protocol._getExtraPath('chimera_volumes.cxc') f = open(cmdFile, 'w+') f.write('windowsize 800 600\n') for volFn in volumes: vol = os.path.relpath(volFn, self.protocol._getExtraPath()) f.write("open %s\n" % vol) f.write('tile\n') f.close() view = ChimeraView(cmdFile) else: #view = CommandView('xmipp_chimera_client --input "%s" --mode projector 256 &' % volumes[0]) view = ChimeraClientView(volumes[0], showProjection=True) return [view]
def _showVolumesChimera(self): """ Create a chimera script to visualize selected volumes. """ volumes = self._getVolumeNames() if len(volumes) > 1: cmdFile = self.protocol._getExtraPath('chimera_volumes.cmd') f = open(cmdFile, 'w+') for volFn in volumes: # We assume that the chimera script will be generated # in the same folder as xmipp volumes localVol = os.path.basename(volFn) if exists(volFn): f.write("open %s\n" % localVol) f.write('tile\n') f.close() view = ChimeraView(cmdFile) else: view = ChimeraClientView(volumes[0]) return [view]
def _visualize_norm_vol(self, obj, **args): self._create_legend(1.5); fnCmd = self.protocol._getExtraPath("chimera_output.py") f = open(fnCmd, 'a') f.write("run(session, 'open %s')\n" % self.protocol._getFileName(OUTPUT_PDBMRC_FILE)) f.write("run(session, 'open %s')\n" % self.protocol._getFileName(RESTA_FILE_NORM)) f.write("run(session, 'volume #2 voxelSize %s step 1')\n" % self.protocol.inputVolume.get().getSamplingRate() ) f.write("run(session, 'volume #3 voxelSize %s')\n" % self.protocol.inputVolume.get().getSamplingRate() ) f.write("run(session, 'vol #3 hide')\n") f.write("run(session, 'color sample #2 map #3 palette" " -1.5,red:-1.0,orange:-0.5,gold:0,yellow:0.5,lime:1.0,cyan:1.5,#1e90ff')\n") f.close() view = ChimeraView(fnCmd) return [view]
def _showChimera(self, param=None): self.createChimeraScriptDoA(OUTPUT_DOA_FILE_CHIMERA, CHIMERA_CMD_DOA, CHIMERA_ELLIP) cmdFile = self.protocol._getPath('chimera_DoA.cmd') view = ChimeraView(cmdFile) return [view]
def _visualize(self, obj, **args): # Input map(s) are a parameter from the protocol dim = 150. sampling = 1. _inputVol = None _inputHalf1 = None _inputHalf2 = None listVol = [] directory = self.protocol._getExtraPath() if self.protocol.useHalfMapsInsteadVol.get(): if self.protocol.halfMapsAttached.get(): if self.protocol.inputVolume.get() is not None: _inputVol = self.protocol.inputVolume.get() dim = _inputVol.getDim()[0] sampling = _inputVol.getSamplingRate() listVol.append(_inputVol) else: if self.protocol.inputHalf1.get() is not None: _inputHalf1 = self.protocol.inputHalf1.get() _inputHalf2 = self.protocol.inputHalf2.get() dim = _inputHalf1.getDim()[0] sampling = _inputHalf1.getSamplingRate() listVol.append(_inputHalf1) listVol.append(_inputHalf2) else: if self.protocol.inputVolume.get() is not None: _inputVol = self.protocol.inputVolume.get() dim = _inputVol.getDim()[0] sampling = _inputVol.getSamplingRate() listVol.append(_inputVol) bildFileName = self.protocol._getExtraPath("axis_output.bild") Chimera.createCoordinateAxisFile(dim, bildFileName=bildFileName, sampling=sampling) fnCxc = self.protocol._getExtraPath("chimera_output.cxc") f = open(fnCxc, 'w') # change to workingDir # If we do not use cd and the project name has an space # the protocol fails even if we pass absolute paths f.write('cd %s\n' % os.getcwd()) f.write("open %s\n" % bildFileName) f.write("cofr 0,0,0\n") # set center of coordinates counter = 1 for vol in listVol: counter += 1 self._visInputVolume(f, vol, counter) for filename in sorted(os.listdir(directory)): if filename.endswith(".mrc"): counter += 1 volFileName = os.path.join(directory, filename) vol = Volume() vol.setFileName(volFileName) if self.protocol.useHalfMapsInsteadVol.get(): if self.protocol.halfMapsAttached.get(): inVol = self.protocol.inputVolume.get() else: inVol = self.protocol.inputHalf1.get() else: inVol = self.protocol.inputVolume.get() vol.setSamplingRate(inVol.getSamplingRate()) vol.setOrigin(inVol.getOrigin(True)) self._visInputVolume(f, vol, counter) f.write("volume #%d level %0.3f\n" % (counter, 0.001)) f.close() return [ChimeraView(fnCxc)]