Exemple #1
0
    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 _visualize(self, obj, **args):
        # The input pdb is a parameter from the protocol
        # and from the parent protocol.
        inputAtomStruct = self.protocol.pdbFileToBeRefined.get()

        # To show pdbs only
        dim = 150.
        sampling = 1.

        bildFileName = os.path.abspath(self.protocol._getTmpPath(
            "axis_output.bild"))
        Chimera.createCoordinateAxisFile(dim,
                                 bildFileName=bildFileName,
                                 sampling=sampling)
        fnCmd = self.protocol._getTmpPath("chimera_output.cxc")
        f = open(fnCmd, 'w')
        f.write("open %s\n" % bildFileName)
        f.write("cofr 0,0,0\n")  # set center of coordinates
        f.write("open %s\n"
                % os.path.abspath(inputAtomStruct.getFileName()))
        f.write("style stick\n")
        if self.protocol.hasAttribute('rotatedAtomStruct'):
            outputAtomStruct = self.protocol.rotatedAtomStruct.getFileName()
            f.write("open %s\n" % os.path.abspath(outputAtomStruct))

        f.close()

        # run in the background
        chimeraPlugin = Domain.importFromPlugin('chimera', 'Plugin', doRaise=True)
        chimeraPlugin.runChimeraProgram(chimeraPlugin.getProgram(), fnCmd + "&")
        return []
    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 _displayMapModel(self, e=None):
        bildFileName = self.protocol._getExtraPath("axis_output.bild")

        _inputVol = self.protocol.inputVolume.get()
        if _inputVol is None:
            _inputVol = self.protocol.inputStructure.get().getVolume()

        dim = _inputVol.getDim()[0]
        sampling = _inputVol.getSamplingRate()

        Chimera.createCoordinateAxisFile(dim,
                                         bildFileName=bildFileName,
                                         sampling=sampling)
        counter = 1
        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())
        # reference axis model = 0
        f.write("open %s\n" % bildFileName)
        f.write("cofr 0,0,0\n")  # set center of coordinates

        # input 3D map
        counter += 1  # 1
        fnVol = self._getInputVolume()
        if fnVol is not None:
            EMRINGERFILENAME = self.protocol._getExtraPath(
                self.protocol.EMRINGERFILE)
            f.write("open %s\n" % EMRINGERFILENAME)
            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  # 2
        pdbFileName = self.protocol.inputStructure.get().getFileName()
        f.write("open %s\n" % pdbFileName)

        f.close()
        # run in the background
        chimeraPlugin = Domain.importFromPlugin('chimera',
                                                'Plugin',
                                                doRaise=True)
        chimeraPlugin.runChimeraProgram(chimeraPlugin.getProgram(),
                                        fnCmd + "&",
                                        cwd=os.getcwd())

        return []
    def _visualize(self, obj, **args):
        fnCmd = self.protocol._getExtraPath("chimera_output.cxc")

        self._getVols()
        self._getPdbs()
        dim = float()
        sampling = float()
        if len(self.vols) > 0:
            if self.vols[0] is not None:
                dim, sampling = self._getDimSamplingFromVol(self.vols[0])
            elif self.vols[1] is not None:
                dim, sampling = self._getDimSamplingFromVol(self.vols[1])
        else:
            # To show pdbs only
            dim = 150.
            sampling = 1.

        bildFileName = self.protocol._getExtraPath("axis_output.bild")
        Chimera.createCoordinateAxisFile(dim,
                                         bildFileName=bildFileName,
                                         sampling=sampling)

        with open(fnCmd, 'w') as f:
            # 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
            if len(self.vols) > 0:
                for vol in self.vols:
                    sampling, volFileName, x, y, z = self._getXYZFromVol(vol)
                    f.write("open %s\n" % volFileName)
                    f.write("volume #2 style surface voxelSize %f\n"
                            "volume #2 origin %0.2f,%0.2f,%0.2f\n" %
                            (sampling, x, y, z))
            for filename in self.pdbList:
                f.write("open %s\n" % filename)

        # run in the background
        chimeraPlugin = Domain.importFromPlugin('chimera',
                                                'Plugin',
                                                doRaise=True)
        chimeraPlugin.runChimeraProgram(chimeraPlugin.getProgram(),
                                        fnCmd + "&",
                                        cwd=os.getcwd())
        return []
 def _validate(self):
     if (self.displayVol == VOLUME_CHIMERA
             and find_executable(Chimera.getProgram()) is None):
         return [
             "chimera is not available. "
             "Either install it or choose option 'slices'. "
         ]
     return []
Exemple #7
0
def main():
    fileName = sys.argv[1]

    # Clean filename in case it comes annotated like 1@xxxmrc:mrcs
    fileName = fileName.split(":")[0]

    # if contains @
    if "@" in fileName:
        fileName = fileName.split("@")[1]

    Chimera().runProgram(args=fileName)
    def _insertAllSteps(self):
        dim = 150.
        sampling = 1.

        bildFileName = os.path.abspath(self._getExtraPath("axis_output.bild"))
        Chimera.createCoordinateAxisFile(dim,
                                         bildFileName=bildFileName,
                                         sampling=sampling)
        fnCmd = self._getExtraPath("chimera_output.cxc")
        f = open(fnCmd, 'w')
        f.write("open %s\n" % bildFileName)
        f.write("cofr 0,0,0\n")  # set center of coordinates
        f.close()
        if self.Operation == self.operationsDictInv['addChain']:
            listStructFileName = []
            for aStruct in self.InputAtomStruct2:
                listStructFileName.append(aStruct.get().getFileName())
            self._insertFunctionStep(
                'addChainStep',
                self.pdbFileToBeRefined.get().getFileName(),
                listStructFileName)
        elif self.Operation == self.operationsDictInv['extractChain']:
            self._insertFunctionStep(
                'extractChainStep',
                self.pdbFileToBeRefined.get().getFileName())
        elif self.Operation == self.operationsDictInv['extractAllChains']:
            self._insertFunctionStep(
                'extractAllChainsStep',
                self.pdbFileToBeRefined.get().getFileName())
        elif self.Operation == self.operationsDictInv['reNumberChain']:
            self._insertFunctionStep(
                'reNumberChainStep',
                self.pdbFileToBeRefined.get().getFileName())
        elif self.Operation == self.operationsDictInv['reNameChain']:
            self._insertFunctionStep(
                'reNameChainStep',
                self.pdbFileToBeRefined.get().getFileName())
        else:
            raise Exception("ERROR: Invalid operation *%s* I quit" %
                            self.Operation)
    def _displayModel(self, e=None):
        # bildFileName = os.path.abspath(self.protocol._getTmpPath(
        #    "axis_output.bild"))
        bildFileName = self.protocol._getTmpPath("axis_output.bild")

        # Axis Dim
        dim = 150.
        sampling = 1.
        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())
        # reference axis model = 0
        f.write("open %s\n" % bildFileName)
        f.write("cofr 0,0,0\n")  # set center of coordinates
        # f.write("open %s\n" % os.path.abspath(
        #     self.protocol.pdbFileToBeRefined.get().getFileName()))
        f.write("open %s\n" %
                self.protocol.pdbFileToBeRefined.get().getFileName())

        if self.protocol.SYMMETRY.get() and \
                os.path.exists(self.protocol.getSymmetrizedModelName()):
            f.write("open %s\n" % self.protocol.getSymmetrizedModelName())
        f.close()
        # run in the background
        chimeraPlugin = Domain.importFromPlugin('chimera',
                                                'Plugin',
                                                doRaise=True)
        chimeraPlugin.runChimeraProgram(chimeraPlugin.getProgram(),
                                        fnCmd + "&",
                                        cwd=os.getcwd())
        return []
Exemple #10
0
        def __applyTransform(suffix, pdbFileName, shift, angles, sampling):
            """ auxiliary function, transform PDB and 3dmap files"""
            # create a Scipion transformation matrix
            from numpy import deg2rad
            rotation_matrix = emconv.euler_matrix(deg2rad(angles[0]),
                                                  deg2rad(angles[1]),
                                                  deg2rad(angles[2]), 'szyz')
            translation = emconv.translation_matrix(shift)
            M = emconv.concatenate_matrices(rotation_matrix, translation)

            # apply it to the pdb file
            # if rotation move to center
            aSH = emconv.AtomicStructHandler(pdbFileName)
            if angles[0] != 0. or angles[1] != 0. or angles[2] != 0.:
                ih = ImageHandler()
                x, y, z, n = ih.getDimensions("emd_%s.map" % EMDBID)
                x /= 2.
                y /= 2.
                z /= 2.
                localShift = [-x, -y, -z]
                rotation_matrix = emconv.euler_matrix(0., 0., 0., 'szyz')
                translation = emconv.translation_matrix(localShift)
                localM = emconv.concatenate_matrices(rotation_matrix,
                                                     translation)
                aSH.transform(localM, sampling=sampling)

            aSH.transform(M, sampling=sampling)

            if angles[0] != 0. or angles[1] != 0. or angles[2] != 0.:
                localShift = [x, y, z]
                rotation_matrix = emconv.euler_matrix(0., 0., 0., 'szyz')
                translation = emconv.translation_matrix(localShift)
                localM = emconv.concatenate_matrices(rotation_matrix,
                                                     translation)
                aSH.transform(localM, sampling=sampling)

            aSH.write("%s_%s_transformed.ent" % (suffix, PDBID.lower()))

            # get equivalent xmipp transformation
            shift, angles = __getXmippEulerAngles(M)
            # shift 3map and set sampling
            __runXmippProgram(
                "xmipp_transform_geometry", '-i emd_%s.map '
                '-o %s_emd_%s_transform.map '
                '--interp linear '
                '--shift %f %f %f '
                '--rotate_volume euler %f %f %f ' %
                (EMDBID, suffix, EMDBID, shift[0], shift[1], shift[2],
                 angles[0], angles[1], angles[2]))
            header = Ccp4Header("%s_emd_%s_transform.map" % (suffix, EMDBID),
                                readHeader=True)
            header.setSampling(sampling)
            # put the sampling back, xmipp_transform_geometry erased it
            header.writeHeader()

            # view the results with chimera
            from pwem.viewers import Chimera
            args = "%s %s %s %s" % (
                pdbFileName, "emd_%s.map" % EMDBID, "%s_%s_transformed.ent" %
                (suffix, PDBID.lower()), "%s_emd_%s_transform.map" %
                (suffix, EMDBID))
            Chimera.runProgram(args)
Exemple #11
0
    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)]
Exemple #12
0
 def _validate(self):
     if find_executable(Chimera.getProgram()) is None:
         return ["chimerax is not available. Either install it or choose"
                 " option 'slices'. "]
     return []