Ejemplo n.º 1
0
    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)

        # run in the background
        cwd = os.path.abspath(self._getExtraPath())
        Plugin.runChimeraProgram(Plugin.getProgram(),
                                 os.path.abspath(parentSessionFileName),
                                 cwd=cwd,
                                 extraEnv=getEnvDictionary(self))
Ejemplo n.º 2
0
    def getHome(cls):
        """ Returns chimera home, trying first to take it from chimera plugin. If it fails it will return, the default value in the config"""
        with pwutils.weakImport("chimera"):
            from chimera import Plugin as chimeraPlugin
            return chimeraPlugin.getHome()

        return os.path.join(emConfig.EM_ROOT, 'chimerax-1.2.5')
Ejemplo n.º 3
0
    def _visualize(self, obj, **args):
        """ Visualize any saved pdb and map if none were saved
        show the input files.
        """
        _inputVolFlag = False
        _inputPDBFlag = False
        directory = self.protocol._getExtraPath()

        fnCmd = os.path.abspath(self.protocol._getTmpPath("chimera_output.cxc"))
        f = open(fnCmd, 'w')
        f.write('cd %s\n' % os.getcwd())

        counter = 0
        # Find all saved maps and pdbs from protocl. If none
        # are found show the input files to the protocol
        for filename in sorted(os.listdir(directory)):
            if filename.endswith(".mrc"):
                _inputVolFlag = True
                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]))
                # Set volume to translucent
                f.write("volume #%d transparency 0.5\n" % counter)

        for filename in os.listdir(directory):
            if filename.endswith(".pdb") or filename.endswith(".cif"):
                _inputPDBFlag = True
                path = os.path.join(directory, filename)
                f.write("open %s\n" % path)


        # If no pdbs or maps found use inputs to protocol
        if not _inputVolFlag:
            counter += 1
            f.write("open %s \n" % os.path.abspath(self.protocol.inputVolume.get().getFileName()))
            # Set volume to translucent
            f.write("volume #%d transparency 0.5\n" % counter)

        if not _inputPDBFlag:
            f.write("open %s \n" % os.path.abspath(self.protocol.pdbFileToBeRefined.get().getFileName()))


        f.close()

        # run in the background
        Chimera.runProgram(chimera.getProgram(), fnCmd + "&")
        return []
 def _viewChimera(self, e=None):
     from chimera import Plugin as chimera_plugin
     args = ""
     fnBaseDir = self.getResultsDir()
     if fnBaseDir:
         for fn in Path(fnBaseDir).rglob('model*.pdb'):
             args += str(fn) + " "
     os.system("%s %s &" % (chimera_plugin.getProgram(), args))
Ejemplo n.º 5
0
    def defineBinaries(cls, env):
        """ Install ISOLDE with Chimerax toolshed command """
        from scipion.install.funcs import \
            VOID_TGZ  # Local import to avoid having scipion-app installed when building the package.

        pathToChimera = chimera_plugin.getProgram()
        installPluginsCommand = [
            ("%s --nogui --exit "
             "--cmd 'toolshed install isolde; exit'" % pathToChimera, [])
        ]
        env.addPackage('isolde',
                       version='1.0',
                       tar=VOID_TGZ,
                       default=True,
                       commands=installPluginsCommand)
    def runChimeraStep(self):
        """ Run Chimera script to start simulation and enable scipionwrite
        """
        self.writeChimeraScript()
        fnCmd = os.path.abspath(self._getExtraPath('chimera_script.cxc'))

        # Go to extra dir and save there the output of
        # scipionwrite
        # f.write('cd %s' % os.path.abspath(
        #    self._getExtraPath()))
        # save config file with information
        # this is information is pased from scipion to chimerax
        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()
        }
        # set to True when
        # protocol finished
        # viewers will check this configuration file
        with open(self._getExtraPath(CHIMERA_CONFIG_FILE), 'w') as configfile:
            config.write(configfile)

        cwd = os.path.abspath(self._getExtraPath())
        Chimera.runProgram(chimera.getProgram(), fnCmd + "&", cwd=cwd)
Ejemplo n.º 7
0
    def runChimeraStep(self):
        # building script file including the coordinate axes and the input
        # volume with samplingRate and Origin information
        f = open(self._getTmpPath(chimeraScriptFileName), "w")
        # building coordinate axes

        dim = 150  # eventually we will create a PDB library that
        # computes PDB dim
        sampling = 1.

        tmpFileName = os.path.abspath(self._getTmpPath("axis_input.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

        # input vol with its origin coordinates
        pdbModelCounter = 1
        if (not self.addTemplate and self.inputSequence1.get() is not None
                and self._getOutFastaSequencesFile is not None):
            alignmentFile1 = self._getOutFastaSequencesFile(self.OUTFILE1)
            f.write("open %s\n" % alignmentFile1)
            f.write("blastprotein %s:%s database %s matrix %s "
                    "cutoff %.3f maxSeqs %d log true\n" %
                    (alignmentFile1.split("/")[-1], self.targetSeqID1,
                     self.OptionForDataBase[int(self.dataBase)],
                     self.OptionForMatrix[int(self.similarityMatrix)],
                     self.cutoffValue, self.maxSeqs))

        if (hasattr(self, 'pdbFileToBeRefined')
                and self.pdbFileToBeRefined.get() is not None):
            pdbModelCounter += 1
            pdbFileToBeRefined = self.pdbFileToBeRefined.get()
            f.write("open %s\n" %
                    os.path.abspath(pdbFileToBeRefined.getFileName()))
            if pdbFileToBeRefined.hasOrigin():
                x, y, z = (pdbFileToBeRefined.getOrigin().getShifts())
                f.write("move %0.2f,%0.2f,%0.2f model #%d "
                        "coord #0\n" % (x, y, z, pdbModelCounter))

        # Alignment of sequence and structure
        if (hasattr(self, 'inputSequence1')
                and hasattr(self, 'inputStructureChain')):
            if (self.inputSequence1.get() is not None
                    and self.inputStructureChain.get() is not None):
                pdbModelCounter = 2
                if str(self.selectedModel) != '0':
                    f.write("select #%s.%s/%s\n" %
                            (pdbModelCounter, str(self.selectedModel + 1),
                             str(self.selectedChain1)))
                else:
                    f.write("select #%s/%s\n" %
                            (pdbModelCounter, str(self.selectedChain1)))

                if self._getOutFastaSequencesFile is not None:
                    alignmentFile1 = self._getOutFastaSequencesFile(
                        self.OUTFILE1)
                    f.write("open %s\n" % alignmentFile1)
                    f.write("sequence disassociate #%s %s\n" %
                            (pdbModelCounter, alignmentFile1.split("/")[-1]))
                    if str(self.selectedModel) != '0':
                        f.write("sequence associate #%s.%s/%s %s:1\n" %
                                (pdbModelCounter, str(self.selectedModel + 1),
                                 str(self.selectedChain1),
                                 alignmentFile1.split("/")[-1]))
                    else:
                        f.write("sequence associate #%s/%s %s:1\n" %
                                (pdbModelCounter, str(self.selectedChain1),
                                 alignmentFile1.split("/")[-1]))

            if (self.additionalTargetSequence.get() is True
                    and self.inputSequence2.get() is not None
                    and self.inputStructureChain.get() is not None):
                f.write("select clear\n")
                f.write("select #%s/%s,%s\n" %
                        (pdbModelCounter, str(
                            self.selectedChain1), str(self.selectedChain2)))

                if self._getOutFastaSequencesFile is not None:
                    alignmentFile2 = self._getOutFastaSequencesFile(
                        self.OUTFILE2)
                    f.write("open %s\n" % alignmentFile2)
                    f.write("sequence disassociate #%s %s\n" %
                            (pdbModelCounter, alignmentFile2.split("/")[-1]))
                    if str(self.selectedModel) != '0':
                        f.write("sequence associate #%s.%s/%s %s:1\n" %
                                (pdbModelCounter, str(self.selectedModel + 1),
                                 str(self.selectedChain2),
                                 alignmentFile2.split("/")[-1]))
                    else:
                        f.write("sequence associate #%s/%s %s:1\n" %
                                (pdbModelCounter, str(self.selectedChain2),
                                 alignmentFile2.split("/")[-1]))

        # run the text:
        _chimeraScriptFileName = os.path.abspath(
            self._getTmpPath(chimeraScriptFileName))
        if len(self.extraCommands.get()) > 2:
            f.write(self.extraCommands.get())
            args = " --nogui " + _chimeraScriptFileName
        else:
            args = " " + _chimeraScriptFileName

        f.close()

        self._log.info('Launching: ' + Plugin.getProgram() + ' ' + args)

        # run in the background
        cwd = os.path.abspath(self._getExtraPath())
        Plugin.runChimeraProgram(Plugin.getProgram(),
                                 args,
                                 cwd=cwd,
                                 extraEnv=getEnvDictionary(self))
    def runChimeraStep(self):

        # building script file including the coordinate axes and the input
        # volume with samplingRate and Origin information
        f = open(self._getTmpPath(chimeraScriptFileName), "w")
        f.write("from chimerax.core.commands import run\n")

        # building coordinate axes
        dim = self.vol.getDim()[0]
        sampling = self.vol.getSamplingRate()
        bildFileName = os.path.abspath(self._getTmpPath("axis_input.bild"))
        Chimera.createCoordinateAxisFile(dim, bildFileName=bildFileName,
                                         sampling=sampling)
        # origin coordinates
        modelId = 1 # axis
        f.write("run(session, 'open %s')\n" % (bildFileName))
        f.write("run(session, 'cofr 0,0,0')\n")  # set center of coordinates
        # input volume
        modelMapM = modelId + 1 # 2, Minuend, result = minuend − subtrahend
        f.write("run(session,'open %s')\n" % self.fnVolName)
        # step = 1 -> no  binning
        f.write("run(session,'volume #%d style surface voxelSize %f')\n"
                % (modelMapM, sampling))
        x, y, z = self.vol.getShiftsFromOrigin()
        f.write("run(session,'volume #%d origin %0.2f,%0.2f,%0.2f')\n"
                % (modelMapM, x, y, z))
        modelMapS =7
        modelAtomStruct = 3
        modelAtomStructChain = 4
        modelAtomStructChainSym = 5
        modelIdZone = 6
        modelMapDiff = 8
        modelMapDiffFil = 9

        if self.mapOrModel == 0:  # subtrahend is a 3D Map
            # input map
            # with its origin coordinates
            # modelMapS = modelMapM + 1  # 3 Subtrahend
            f.write("run(session,'open %s')\n" %
                    (self.subVolName))
            f.write("run(session, 'rename #3 id #%d')\n" % modelMapS)
            f.write("run(session,'volume #%d style surface voxelSize %f step 1')\n"
                    % (modelMapS, sampling))
            x, y, z = self.subVol.getShiftsFromOrigin()
            f.write("run(session,'volume #%d origin %0.2f,%0.2f,%0.2f')\n"
                        % (modelMapS, x, y, z))
            if self.subtractOrMask == 1 and self.level.get() is not None:
                f.write("run(session,'volume #%d level %f')\n" %
                        (modelMapS, self.level))
        else:  # subtrahend is an atomic structure
            f.write("run(session,'open %s')\n" % self.atomStructName)
            # input atomic structure
            if self.selectChain == True:
                # model and chain selected
                if self.selectStructureChain.get() is not None:
                    chain = self.selectStructureChain.get()
                    self.selectedModel = chain.split(',')[0].split(':')[1].strip()
                    #TODO: Study problems with multimodels
                    if int(self.selectedModel) != 0:
                        modelId = int(modelAtomStruct +
                                                     int(self.selectedModel))

                        f.write("run(session, 'rename #%d id #%d')\n" %
                                (modelId, modelAtomStruct))
                    self.selectedChain = \
                        chain.split(',')[1].split(':')[1].strip().split('"')[1]
                    print("Selected chain: %s from model: %s from structure: %s" \
                        % (self.selectedChain, self.selectedModel,
                            os.path.basename(self.atomStructName)))
                    f.write("run(session,'sel #%d/%s')\n"
                            % (modelAtomStruct, self.selectedChain))
                    tmpPath = os.path.abspath(self._getTmpPath('chain.cif'))

                    f.write("run(session,"
                            "'save %s format mmcif models #%d relModel #%d selectedOnly true')\n"
                            % (tmpPath, modelAtomStruct, modelId))
                    f.write("run(session,'open %s')\n" % tmpPath)
                    f.write("run(session,'scipionwrite #%d prefix chain_%s_ ')\n"
                            % (modelAtomStructChain, self.selectedChain))
                    if self.selectAreaMap == True:  # mask the minuend using the atomic structure
                        if self.applySymmetry == True and self.symmetryGroup.get() is not None:
                            sym = CHIMERA_SYM_NAME[self.symmetryGroup.get()]
                            modelId = modelAtomStructChain #4
                            self.symMethod(f, modelId, sym, self.symmetryOrder)

                            f.write("run(session,'volume zone #%d nearAtoms #%d "
                                    "range %d newMap true modelId #%d')\n"
                                    % (modelMapM, modelAtomStructChainSym,
                                       self.radius, modelIdZone))
                            if not self.removeResidues:
                                f.write("run(session,'scipionwrite #%d prefix sym_  ')\n"
                                        % modelAtomStructChainSym)

                            f.write("run(session,'close #%d')\n" % (modelAtomStructChainSym))
                        else:
                            f.write("run(session,'volume zone #%d nearAtoms #%d "
                                    "range %d newMap true modelId #%d')\n"
                                    % (modelMapM, modelAtomStructChain,
                                    self.radius, modelIdZone))

                        f.write("run(session,'scipionwrite #%d prefix zone_  ')\n" % modelIdZone)

                    if self.removeResidues == True:
                        if (self.firstResidueToRemove.get() is not None and
                                self.lastResidueToRemove.get() is not None):
                            self.firstResidue = self.firstResidueToRemove.get().\
                            split(":")[1].split(",")[0].strip()
                            self.lastResidue = self.lastResidueToRemove.get(). \
                                split(":")[1].split(",")[0].strip()
                            f.write("run(session,'sel #%d/%s:%d-%d')\n"
                                    % (modelAtomStructChain, self.selectedChain,
                                       int(self.firstResidue), int(self.lastResidue)))
                            f.write("run(session,'del sel')\n")
                            f.write("run(session,'sel #%d/%s:%d-%d')\n" %
                                    (modelAtomStructChain, self.selectedChain,
                                     int(self.firstResidue) - 10,
                                     int(self.lastResidue) + 10))
                    if self.applySymmetry == True:
                        if self.symmetryGroup.get() is not None:
                            sym = CHIMERA_SYM_NAME[self.symmetryGroup.get()]
                            modelId = modelAtomStructChain
                            self.symMethod(f, modelId, sym, self.symmetryOrder, self.rangeDist)
                            f.write("run(session,'scipionwrite #%d prefix sym_  ')\n"
                                    % modelAtomStructChainSym)
                            f.write("v=run(session,'molmap #%d %0.3f gridSpacing %f')\n"
                                    % (modelAtomStructChainSym, self.resolution, sampling))
                            f.write("run(session,'rename #%d id #7' % v.id[0])\n") ## #7 is modelMapS id
                            if self.subtractOrMask == 1 and self.level.get() is not None:
                                f.write("run(session,'volume #%d level %f')\n" %
                                        (modelMapS, self.level))
                            if self.removeResidues == True:
                                if (self.firstResidueToRemove.get() is not None and
                                        self.lastResidueToRemove.get() is not None):
                                    f.write("run(session,'sel #%d:%d-%d')\n" %
                                            (modelAtomStructChainSym,
                                             int(self.firstResidue) - 10,
                                             int(self.lastResidue) + 10))

                    else:
                        f.write("v=run(session,'molmap #%d %0.3f gridSpacing %f')\n"
                                % (modelAtomStructChain, self.resolution, sampling))
                        f.write("run(session,'rename #%d id #7' % v.id[0])\n") ## #7 is modelMapS id
                        if self.subtractOrMask == 1 and self.level.get() is not None:
                            f.write("run(session,'volume #%d level %f')\n" %
                                    (modelMapS, self.level))

                    f.write("run(session,'scipionwrite #%d prefix molmap_chain%s_')\n"
                            % (modelMapS, self.selectedChain))

            else:  # use whole atomic model
                f.write("run(session,'scipionwrite #%d')\n" % modelAtomStruct)
                if self.selectAreaMap == True:
                    if self.applySymmetry == True and self.symmetryGroup.get() is not None:
                        sym = CHIMERA_SYM_NAME[self.symmetryGroup.get()]
                        modelId = modelAtomStruct
                        self.symMethod(f, modelId, sym, self.symmetryOrder, self.rangeDist)
                        f.write("run(session, 'rename #4 id #%d')\n" % modelAtomStructChainSym)
                        f.write("run(session,'volume zone #%d nearAtoms #%d "
                                "range %d newMap true modelId #%d')\n"
                                % (modelMapM, modelAtomStructChainSym,
                                   self.radius, modelIdZone))

                        f.write("run(session,'close #%d')\n" % (modelAtomStructChainSym))

                    else:
                        f.write("run(session,'volume zone #%d nearAtoms #%d "
                                "range %d newMap true modelId #%d')\n"
                                % (modelMapM, modelAtomStruct,
                                    self.radius, modelIdZone))

                    f.write("run(session,'scipionwrite #%d prefix zone_  ')\n" % modelIdZone)

                if self.removeResidues == True:
                    if (self.inputStructureChain.get() is not None and
                            self.firstResidueToRemove.get() is not None and
                            self.lastResidueToRemove.get() is not None):
                        chain = self.inputStructureChain.get()
                        self.selectedModel = chain.split(',')[0].split(':')[1].strip()
                        # TODO: Study problems with multimodels
                        if int(self.selectedModel) != 0:
                            modelId = int(modelAtomStruct +
                                          int(self.selectedModel))

                            f.write("run(session, 'rename #%d id #%d')\n" %
                                    (modelId, modelAtomStruct))
                        self.selectedChain = \
                            chain.split(',')[1].split(':')[1].strip().split('"')[1]
                        print("Selected chain: %s from model: %s from structure: %s"\
                              % (self.selectedChain, self.selectedModel,
                                 os.path.basename(self.atomStructName)))
                        f.write("run(session,'sel #%d/%s')\n"
                                % (modelAtomStruct, self.selectedChain))
                        self.firstResidue = self.firstResidueToRemove.get(). \
                            split(":")[1].split(",")[0].strip()
                        self.lastResidue = self.lastResidueToRemove.get(). \
                            split(":")[1].split(",")[0].strip()
                        f.write("run(session,'sel #%d/%s:%d-%d')\n"
                                % (modelAtomStruct, self.selectedChain,
                                   int(self.firstResidue), int(self.lastResidue)))
                        f.write("run(session,'del sel')\n")
                        f.write("run(session,'scipionwrite #%d prefix mutated_ ')\n"
                                % modelAtomStruct)

                        f.write("run(session,'sel #%d/%s:%d-%d')\n" %
                                (modelAtomStruct, self.selectedChain,
                                 int(self.firstResidue) - 10,
                                 int(self.lastResidue) + 10))

                if self.applySymmetry == True:
                    if self.symmetryGroup.get() is not None:
                        sym = CHIMERA_SYM_NAME[self.symmetryGroup.get()]
                        modelId = modelAtomStruct
                        self.symMethod(f, modelId, sym, self.symmetryOrder, self.rangeDist)
                        f.write("run(session, 'rename #4 id #%d')\n" % modelAtomStructChainSym)
                        f.write("run(session,'scipionwrite #%d prefix sym_ ')\n"
                                % modelAtomStructChainSym)
                        if (self.inputStructureChain.get() is not None and
                                self.firstResidueToRemove.get() is not None and
                                self.lastResidueToRemove.get() is not None):
                            f.write("run(session, 'sel #%d/%s:%d-%d')\n" %
                                    (modelAtomStructChainSym,
                                     self.selectedChain,
                                     int(self.firstResidue) - 10,
                                     int(self.lastResidue) + 10))
                        f.write("v=run(session,'molmap #%d %0.3f gridSpacing %f')\n"
                                % (modelAtomStructChainSym, self.resolution, sampling))
                        f.write("run(session,'rename #%d id #7' % v.id[0])\n") ## #7 is modelMapS id
                        # modelMapS = modelAtomStructChainSym + 1
                        if self.subtractOrMask == 1 and self.level.get() is not None:
                            f.write("run(session,'volume #%d level %f')\n" %
                                    (modelMapS, self.level))
                else:  # no symmetry
                    f.write("v=run(session,'molmap #%d %0.3f gridSpacing %f')\n"
                            % (modelAtomStruct, self.resolution, sampling))
                    f.write("run(session,'rename #%d id #7' % v.id[0])\n") ## #7 is modelMapS id
                    if self.subtractOrMask == 1 and self.level.get() is not None:
                        f.write("run(session,'volume #%d level %f')\n" %
                                (modelMapS, self.level))
                f.write("run(session,'scipionwrite #%d prefix molmap_  ')\n" % modelMapS)

        # Generation of the differential map
        if self.selectAreaMap == True:
            modelId = modelIdZone
        else:
            modelId = modelMapM
        if self.subtractOrMask == 0:
            f.write("run(session, 'volume subtract #%d #%d modelId #%d "
                    "minRms true onGrid #%d')\n" %
                    (modelId, modelMapS, modelMapDiff, modelId))
        else:
            f.write("run(session, 'volume mask #%d surfaces #%d invertMask "
                    "true modelId #%d')\n" %
                    (modelId, modelMapS, modelMapDiff))
        f.write("run(session,'scipionwrite #%d prefix difference_')\n" % modelMapDiff)

        # Generation of the filtered map
        if self.filterToApplyToDiffMap.get() == 0:
            f.write("run(session,'volume gaussian #%d sd %0.3f modelId %#d')\n"
                    % (modelMapDiff, self.widthFilter.get(), modelMapDiffFil))
        else:
            f.write("run(session,'volume laplacian #%d')\n" % modelMapDiff)

        f.write("run(session,'scipionwrite #%d prefix filtered_')\n" % modelMapDiffFil)
        if self.inputPdbFiles is not None:  # Other atomic models different
                                            # from the subtrahend
            for atomStruct in self.inputPdbFiles:
                f.write("run(session,'open %s')\n" %
                        os.path.abspath(atomStruct.get().getFileName()))
        # Finally save session
        f.write("run(session,'scipionss')\n")

        # run the script:
        if len(self.extraCommands.get()) > 2:
            f.write(self.extraCommands.get())
            args = " --nogui --script " + \
                   os.path.abspath(self._getTmpPath(chimeraScriptFileName))
        else:
            args = " --script " + \
                   os.path.abspath(self._getTmpPath(chimeraScriptFileName))
        f.close()

        self._log.info('Launching: ' + Plugin.getProgram() + ' ' + args)

        # run in the background
        cwd = os.path.abspath(self._getExtraPath())
        Plugin.runChimeraProgram(Plugin.getProgram(), args, cwd=cwd, extraEnv=getEnvDictionary(self))