def runChimeraStep(self): # create CMD file parentSessionFileName = self.parentProt._getExtraPath(sessionFile) # if len(self.extraCommands.get()) > 2: # f.write(self.extraCommands.get()) # args = " --nogui --cmd " + self._getTmpPath( # chimeraScriptFileName) program = Chimera.getProgram() config = configparser.ConfigParser() _chimeraPdbTemplateFileName = \ os.path.abspath(self._getExtraPath( chimeraPdbTemplateFileName)) _chimeraMapTemplateFileName = \ os.path.abspath(self._getExtraPath( chimeraMapTemplateFileName)) _sessionFile = os.path.abspath(self._getExtraPath(sessionFile)) protId = self.getObjId() config['chimerax'] = { 'chimerapdbtemplatefilename': _chimeraPdbTemplateFileName % protId, 'chimeramaptemplatefilename': _chimeraMapTemplateFileName % protId, 'sessionfile': _sessionFile, 'enablebundle': True, 'protid': self.getObjId() } with open(self._getExtraPath(CHIMERA_CONFIG_FILE), 'w') as configfile: config.write(configfile) # run in the background cwd = os.path.abspath(self._getExtraPath()) Chimera.runProgram(program, os.path.abspath(parentSessionFileName), cwd=cwd)
def _displayMask(self, e=None): if self.protocol.generateMaskedVolume.get(): maskedMapFileName = os.path.abspath( self.protocol._getExtraPath( self.protocol._getMapMaskedByPdbBasedMaskFileName())) ccp4header = Ccp4Header(maskedMapFileName, readHeader=True) dim, _, _ = ccp4header.getDims() x, y, z = ccp4header.getOrigin() sampling, _, _ = ccp4header.getSampling() counter = 1 fnCmd = self.protocol._getExtraPath("chimera_mask.cxc") f = open(fnCmd, 'w') maskFileName = os.path.abspath(maskedMapFileName) f.write("open %s\n" % maskFileName) f.write("volume #%d style surface voxelSize %f\n" % (counter, sampling)) # No origin information in header :-( #f.write("volume #%d origin %0.2f,%0.2f,%0.2f\n" % # (counter, x, y, z)) f.close() # run in the background Chimera.runProgram(Chimera.getProgram(), fnCmd + "&") return [] else: errorWindow( self.getTkRoot(), "This protocol has been executed " "without the mask option") return []
def _visualizeMapModel(self, e=None): bildFileName = os.path.abspath( self.protocol._getExtraPath("axis_output.bild")) if self.protocol.inputVolume.get() is None: _inputVol = self.protocol.inputStructure.get().getVolume() dim = _inputVol.getDim()[0] sampling = _inputVol.getSamplingRate() else: dim = self.protocol.inputVolume.get().getDim()[0] sampling = self.protocol.inputVolume.get().getSamplingRate() Chimera.createCoordinateAxisFile(dim, bildFileName=bildFileName, sampling=sampling) counter = 1 fnCmd = self.protocol._getExtraPath("chimera_output.cxc") f = open(fnCmd, 'w') # reference axis model = 0 f.write("open %s\n" % bildFileName) f.write("cofr 0,0,0\n") # input 3D map counter += 1 # 2 fnVol = self.protocol._getInputVolume() fnVolName = os.path.abspath(fnVol.getFileName()) if fnVolName.endswith(":mrc"): fnVolName = fnVolName.split(":")[0] f.write("open %s\n" % fnVolName) x, y, z = fnVol.getOrigin(force=True).getShifts() sampling = fnVol.getSamplingRate() f.write("volume #%d style surface voxelSize %f\nvolume #%d origin " "%0.2f,%0.2f,%0.2f\n" % (counter, sampling, counter, x, y, z)) # input PDB (usually from coot) counter += 1 # 3 pdbFileName = os.path.abspath( self.protocol.inputStructure.get().getFileName()) f.write("open %s\n" % pdbFileName) # second refmac step output -> refined PDB counter += 1 # 4 pdbFileName = os.path.abspath(self.protocol.outputPdb.getFileName()) f.write("open %s\n" % pdbFileName) f.close() # run in the background Chimera.runProgram(Chimera.getProgram(), fnCmd + "&") return []
def _visualize(self, obj, **args): fnCmd = self.protocol._getTmpPath("chimera_restore_session.cxc") f = open(fnCmd, '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()) path1 = os.path.join(self.protocol._getExtraPath(), sessionFile) if os.path.exists(path1): # restored SESSION path = path1 else: # SESSION from inputProtocol path2 = os.path.join( self.protocol.inputProtocol.get()._getExtraPath(), sessionFile) path = path2 f.write("open %s\n" % path) Chimera.runProgram(Chimera.getProgram(), fnCmd + "&") return []
def _visualize(self, obj, **args): # Create minimalistic coordinate axis dim = 150. sampling = 1. bildFileName = self.protocol._getExtraPath("axis_output.bild") Chimera.createCoordinateAxisFile(dim, bildFileName=bildFileName, sampling=sampling) fnCmd = self.protocol._getExtraPath("chimera_output.cxc") f = open(fnCmd, '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 # show vol _showVol = self.protocol.outputVolume #.get() showVolFileName = ImageHandler.removeFileType(_showVol.getFileName()) f.write("open %s\n" % showVolFileName) if _showVol.hasOrigin(): x, y, z = _showVol.getOrigin().getShifts() else: x, y, z = _showVol.getOrigin(force=True).getShifts() f.write("volume #2 style surface voxelSize %f\n" "volume #2 origin %0.2f,%0.2f,%0.2f\n" % (_showVol.getSamplingRate(), x, y, z)) # show atom struct) atomstruct = self.protocol.atomStruct.get() if atomstruct is not None: f.write("open %s\n" % atomstruct.getFileName()) # run in the background Chimera.runProgram(Chimera.getProgram(), fnCmd + "&") return []
def chimeraInstalled(): return Chimera.getHome() and os.path.exists(Chimera.getProgram())
import pyworkflow.protocol.params as params import pyworkflow.gui.plotter as plotter import pyworkflow.gui.dialog as dialog import pwem.constants as emcts import pwem.protocols as emprot from pwem import emlib, splitRange from pwem.objects import AtomStruct, SetOfAtomStructs from pwem.viewers.viewer_chimera import mapVolsWithColorkey, Chimera, ChimeraView, generateColorLegend from pwem.convert.atom_struct import * from .plotter import EmPlotter, plt CHIMERA_ERROR = 'Chimera program is not found were it was expected: \n\n{}\n\n' \ 'Either install ChimeraX in this path or install our ' \ 'scipion-em-chimera plugin'.format(Chimera.getProgram()) class LocalResolutionViewer(pwviewer.ProtocolViewer): """ Visualization tools for local resolution results. """ binaryCondition = ('(colorMap == %d) ' % emcts.COLOR_OTHER) def __init__(self, *args, **kwargs): pwviewer.ProtocolViewer.__init__(self, **kwargs) def getImgData(self, imgFile, minMaskValue=0.1, maxMaskValue=None): import numpy as np # if image ends in .mrc or .map :mrc
def _visualize(self, obj, **args): # THe input map or pdb may be a parameter from the protocol # or from the parent protocol. dim = 150. sampling = 1. _inputVol = None directory = self.protocol._getExtraPath() try: try: if self.protocol.inputVolume.get() is not None: _inputVol = self.protocol.inputVolume.get() elif self.protocol.pdbFileToBeRefined.get().getVolume( ) is not None: _inputVol = self.protocol.pdbFileToBeRefined.get( ).getVolume() elif self.protocol.inputVolumes[0] is not None: _inputVol = self.protocol.inputVolumes[0].get() except: output3DMapList = [] for filename in sorted(os.listdir(directory)): if filename.endswith(".mrc"): output3DMapList.append(filename.split('.')[0]) output3DMap = str(output3DMapList[0]) if len(output3DMap) > 0: _inputVol = self.protocol.output3DMap except: # TODO: I do not know if we still need this part # Remark that inputProtocol does not longer exist, it has been replaced by inputProtocolDict # Compare with the previous code, specially the alternative directory for item in list(self.protocol.inputProtocolDict().values()): if item.hasAttribute( 'inputVolume') and item.inputVolume.get() is not None: _inputVol = item.inputVolume.get() break elif item.hasAttribute('pdbFileToBeRefined') and \ item.pdbFileToBeRefined.get().getVolume() is not None: _inputVol = item.pdbFileToBeRefined.get().getVolume() break # directory = item._getExtraPath() if _inputVol is not None: dim = _inputVol.getDim()[0] sampling = _inputVol.getSamplingRate() bildFileName = self.protocol._getTmpPath("axis_output.bild") Chimera.createCoordinateAxisFile(dim, bildFileName=bildFileName, sampling=sampling) fnCmd = self.protocol._getTmpPath("chimera_output.cxc") f = open(fnCmd, '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 inputVolFileName = '' counter = 2 if _inputVol is not None: # In case we have PDBs only, _inputVol is None: self.visInputVolume(f, _inputVol, counter) else: counter = 1 if (self.protocol.hasAttribute("inputVolume2") and\ self.protocol.inputVolume2.get() is not None): counter += 1 _inputVol2 = self.protocol.inputVolume2.get() self.visInputVolume(f, _inputVol2, counter) for filename in sorted(os.listdir(directory)): if filename.endswith(".mrc") and filename != inputVolFileName: counter += 1 volFileName = os.path.join(directory, filename) vol = Volume() vol.setFileName(volFileName) # fix mrc header ccp4header = Ccp4Header(volFileName, readHeader=True) sampling = ccp4header.computeSampling() origin = Transform() shifts = ccp4header.getOrigin() origin.setShiftsTuple(shifts) f.write("open %s\n" % volFileName) f.write("volume #%d style surface voxelSize %f\n" "volume #%d origin %0.2f,%0.2f,%0.2f\n" % (counter, sampling, counter, shifts[0], shifts[1], shifts[2])) f.write("volume #%d level %0.3f\n" % (counter, 0.001)) for filename in os.listdir(directory): if filename.endswith(".pdb") or filename.endswith(".cif"): path = os.path.join(directory, filename) # f.write("open %s\n" % os.path.abspath(path)) f.write("open %s\n" % path) f.close() # run in the background Chimera.runProgram(Chimera.getProgram(), fnCmd + "&") return []