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)
Пример #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)
Пример #3
0
    def createOutputStep(self):

        volume = Volume()
        volume.setFileName(self._getExtraPath(POSTPROCESS_VOL_BASENAME))

        if self.useHalfMapsInsteadVol.get():
            if self.halfMapsAttached.get():
                inVol = self.inputVolume.get()
            else:
                inVol = self.inputHalf1.get()

            volume.setSamplingRate(inVol.getSamplingRate())
            volume.setOrigin(inVol.getOrigin(force=True))

            self._defineOutputs(Volume=volume)
            self._defineTransformRelation(inVol, volume)
            if not self.halfMapsAttached.get():
                self._defineTransformRelation(self.inputHalf2, volume)
        else:
            inVol = self.inputVolume.get()
            volume.setSamplingRate(inVol.getSamplingRate())
            volume.setOrigin(inVol.getOrigin(force=True))

            self._defineOutputs(Volume=volume)
            self._defineTransformRelation(self.inputVolume, volume)
    def createOutputStep(self):
        metrics = self._getMetrics()
        volume = Volume()
        volume.setFileName(self._getFileName(RESTA_FILE_MRC))
        volume.setSamplingRate(self.inputVolume.get().getSamplingRate())
        volume.setOrigin(self.inputVolume.get().getOrigin(True).clone())

        self._defineOutputs(fscq_Volume=volume, **metrics)
        self._defineTransformRelation(self.inputVolume, volume)
Пример #5
0
 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):
        vol = Volume()
        vol.setLocation(self._getOutputVol())
        sampling = self.inputVolumes.get().getSamplingRate()
        vol.setSamplingRate(sampling)
        #

        ccp4header = Ccp4Header(self._getOutputVol(), readHeader=True)
        t = Transform()

        x, y, z = ccp4header.getOrigin()  # origin output vol
        # coordinates

        t.setShifts(x, y, z)
        vol.setOrigin(t)
        #
        self._defineOutputs(outputVolume=vol)
        self._defineSourceRelation(self.inputVolumes, self.outputVolume)
Пример #8
0
    def createOutputStep(self):

        volumesSet = self._createSetOfVolumes()
        volumesSet.setSamplingRate(self.inputVolume.get().getSamplingRate())
        for i in range(self.iteration):
            vol = Volume()
            vol.setOrigin(self.inputVolume.get().getOrigin(True))
            if (self.iteration > (i + 1)):
                vol.setLocation(
                    i, self._getExtraPath('sharpenedMap_%d.mrc' % (i + 1)))
                vol.setObjComment("Sharpened Map, \n Epoch %d" % (i + 1))
            else:
                vol.setLocation(i, self._getExtraPath('sharpenedMap_last.mrc'))
                vol.setObjComment("Sharpened Map, \n Epoch last")
            volumesSet.append(vol)

        self._defineOutputs(outputVolumes=volumesSet)
        self._defineSourceRelation(self.inputVolume, volumesSet)
    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)
Пример #10
0
    def createOutputStep(self):
        inputVol = self.inputStructure.get()
        samplingRate = inputVol.getSamplingRate()
        volume = Volume()
        volume.setFileName(self._getExtraPath("pseudoatoms_approximation.vol"))
        volume.setSamplingRate(samplingRate)
        x, y, z = volume.getDim()
        xv, yv, zv = inputVol.getOrigin(force=True).getShifts()
        t = Transform()
        t.setShifts((x / 2. * samplingRate) - xv, (y / 2. * samplingRate) - yv,
                    (z / 2. * samplingRate) - zv)
        volume.setOrigin(inputVol.getOrigin())

        self._defineOutputs(outputVolume=volume)
        self._defineSourceRelation(self.inputStructure.get(), volume)

        pdb = AtomStruct(self._getPath('pseudoatoms.pdb'), pseudoatoms=True)
        pdb.setVolume(volume)
        pdb.setOrigin(t)
        self.createChimeraScript(inputVol, pdb)
        self._defineOutputs(outputPdb=pdb)
        self._defineSourceRelation(self.inputStructure, pdb)
Пример #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)]
Пример #12
0
    def createOutput(self):
        """ Copy the PDB structure and register the output object.
        """
        databasePath = self._getExtraPath(OUTPUTDATABASENAMESWITHLABELS)
        getModels(databasePath, DATABASETABLENAME)

        # open database
        conn = sqlite3.connect(databasePath)
        if not _checkTableExists(conn, DATABASETABLENAME):
            conn.close()
            return

        c = conn.cursor()

        # read atom struct filename and label in a loop
        c.execute('SELECT fileName, labelName '
                  'FROM %s '
                  'WHERE saved = 0 AND type=%d' %
                  (DATABASETABLENAME, TYPE_ATOMSTRUCT))
        for row in c:
            pdbFileName = row[0]
            pdbLabelName = row[1]
            pdb = AtomStruct()
            pdb.setFileName(pdbFileName)

            outputs = {str(pdbLabelName): pdb}
            self._defineOutputs(**outputs)
            self._defineSourceRelation(self.inputPdbFiles, pdb)

        # files has been saved
        sql = 'UPDATE %s SET saved = 1 WHERE saved=0 ' \
              'AND type=%d' % (DATABASETABLENAME, TYPE_ATOMSTRUCT)
        c.execute(sql)

        # check if normalized files are saved
        sql = "SELECT count(*) " \
              "FROM %s " \
              "WHERE saved = 0 " \
              "  AND type = %d LIMIT 1" % (DATABASETABLENAME, TYPE_3DMAP)
        c.execute(sql)
        result = c.fetchone()[0]

        # update  saved parameter
        if result > 0:
            sql = 'UPDATE %s SET saved = 1 WHERE saved=0 ' \
                  'AND type=%d' % (DATABASETABLENAME, TYPE_3DMAP)
            c.execute(sql)
        conn.commit()
        conn.close()

        # save normalized  vols...
        if result > 0:
            inVolumes, norVolumesNames = self._getVolumesList()
            counter = 1
            for inVol, norVolName in zip(inVolumes, norVolumesNames):
                outVol = Volume()
                sampling = inVol.getSamplingRate()
                origin = inVol.getOrigin(force=True)
                outVol.setSamplingRate(sampling)
                outVol.setOrigin(origin)

                if norVolName.endswith('.mrc'):
                    norVolName = norVolName + ":mrc"
                outFileName = self._getVolumeFileName(norVolName)
                outVol.setFileName(outFileName)
                outputs = {"output3DMap_%04d" % counter: outVol}
                counter += 1
                self._defineOutputs(**outputs)
                self._defineSourceRelation(inVol, outVol)
        else:
            print("skip save normalized vol")

        if os.path.isfile(self._getExtraPath('STOPPROTCOL')):
            self.setStatus(STATUS_FINISHED)
            # NOTE: (ROB) can a dirty way to make an interactive process finish but I do not
            # think there is a clean one
            self._steps[self.step - 1].setInteractive(False)