def createOutput(self):
        # Check vol and pdb files
        directory = self._getExtraPath()
        for filename in sorted(os.listdir(directory)):
            if filename.endswith(".mrc"):
                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)
                vol.setOrigin(origin)
                vol.setSamplingRate(sampling)
                keyword = filename.split(".mrc")[0]
                kwargs = {keyword: vol}
                self._defineOutputs(**kwargs)

            elif filename.endswith(".pdb") or filename.endswith(".cif"):
                path = os.path.join(directory, filename)
                pdb = AtomStruct()
                pdb.setFileName(path)
                keyword = filename.split(".pdb")[0].replace(".","_")
                kwargs = {keyword: pdb}
                self._defineOutputs(**kwargs)
Exemple #2
0
    def createOutput(self):
        """ Copy the PDB structure and register the output object.
        """
        # Check vol and pdb files
        directory = self._getExtraPath()
        for filename in sorted(os.listdir(directory)):
            if not filename.startswith("tmp"):
                # files starting with "tmp" will not be converted in scipion objects
                if filename.endswith(".mrc"):
                    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)
                    vol.setOrigin(origin)
                    vol.setSamplingRate(sampling)
                    keyword = filename.split(".mrc")[0]
                    kwargs = {keyword: vol}
                    self._defineOutputs(**kwargs)

                if filename.endswith(".pdb") or filename.endswith(".cif"):
                    path = os.path.join(directory, filename)
                    pdb = AtomStruct()
                    pdb.setFileName(path)
                    if filename.endswith(".cif"):
                        keyword = filename.split(".cif")[0].replace(".", "_")
                    else:
                        keyword = filename.split(".pdb")[0].replace(".", "_")
                    kwargs = {keyword: pdb}
                    self._defineOutputs(**kwargs)
Exemple #3
0
    def importTomogramsStep(self, pattern, samplingRate):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        self.info("Using pattern: '%s'" % pattern)

        # Create a Volume template object
        tomo = Tomogram()
        tomo.setSamplingRate(samplingRate)

        imgh = ImageHandler()

        tomoSet = self._createSetOfTomograms()
        tomoSet.setSamplingRate(samplingRate)

        self._parseAcquisitionData()
        for fileName, fileId in self.iterFiles():
            x, y, z, n = imgh.getDimensions(fileName)
            if fileName.endswith('.mrc') or fileName.endswith('.map'):
                fileName += ':mrc'
                if z == 1 and n != 1:
                    zDim = n
                    n = 1
                else:
                    zDim = z
            else:
                zDim = z

            origin = Transform()

            if self.setOrigCoord.get():
                origin.setShiftsTuple(self._getOrigCoord())
            else:
                origin.setShifts(x / -2. * samplingRate,
                                 y / -2. * samplingRate,
                                 zDim / -2. * samplingRate)

            tomo.setOrigin(origin)  # read origin from form

            newFileName = _getUniqueFileName(self.getPattern(),
                                             fileName.split(':')[0])
            tsId = removeExt(newFileName)
            tomo.setTsId(tsId)

            if fileName.endswith(':mrc'):
                fileName = fileName[:-4]
            createAbsLink(fileName, abspath(self._getExtraPath(newFileName)))
            tomo.setAcquisition(self._extractAcquisitionParameters(fileName))

            if n == 1:  # One volume per file
                tomo.cleanObjId()
                tomo.setFileName(self._getExtraPath(newFileName))
                tomoSet.append(tomo)
            else:  # A stack of volumes per file (not common)
                for index in range(1, n + 1):
                    tomo.cleanObjId()
                    tomo.setLocation(index, self._getExtraPath(newFileName))
                    tomoSet.append(tomo)

        self._defineOutputs(outputTomograms=tomoSet)
    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 createOutput(self):
     volume = Volume()
     volume.setSamplingRate(self.sampling.get())
     volume.setFileName(self._getVolName())
     if self.vol:
         origin = Transform()
         origin.setShiftsTuple(self.shifts)
         volume.setOrigin(origin)
     self._defineOutputs(outputVolume=volume)
     if self.inputPdbData == self.IMPORT_OBJ:
         self._defineSourceRelation(self.pdbObj, volume)
 def createOutputStep(self):
     vol1 = self.vol1.get()
     volume = Volume()
     volume.setSamplingRate(vol1.getSamplingRate())
     if vol1.getFileName().endswith('mrc'):
         origin = Transform()
         ccp4header = headers.Ccp4Header(vol1.getFileName(), readHeader=True)
         shifts = ccp4header.getOrigin()
         origin.setShiftsTuple(shifts)
         volume.setOrigin(origin)
     volume.setFileName(self._getExtraPath("output_volume.mrc"))
     filename = volume.getFileName()
     if filename.endswith('.mrc') or filename.endswith('.map'):
         volume.setFileName(filename + ':mrc')
     self._defineOutputs(outputVolume=volume)
    def createOutputStep(self):
        """ Copy the PDB structure and register the output object.
        """

        # Check vol and pdb files
        directory = self._getExtraPath()
        for filename in sorted(os.listdir(directory)):
            if filename.endswith(".mrc"):
                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)
                vol.setOrigin(origin)
                vol.setSamplingRate(sampling)
                keyword = filename.split(".mrc")[0]
                kwargs = {keyword: vol}
                self._defineOutputs(**kwargs)

            if filename.endswith(".pdb") or filename.endswith(".cif"):
                path = os.path.join(directory, filename)
                pdb = AtomStruct()
                pdb.setFileName(path)
                if filename.endswith(".cif"):
                    keyword = filename.split(".cif")[0].replace(".", "_")
                else:
                    keyword = filename.split(".pdb")[0].replace(".", "_")
                kwargs = {keyword: pdb}
                self._defineOutputs(**kwargs)

        # upodate config file flag enablebundle
        # so scipionwrite is disabled
        config = configparser.ConfigParser()
        config.read(self._getExtraPath(CHIMERA_CONFIG_FILE))
        config.set('chimerax', 'enablebundle', 'False')
        with open(self._getExtraPath(CHIMERA_CONFIG_FILE), 'w') as configfile:
            config.write(configfile)
Exemple #8
0
    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 []