Ejemplo n.º 1
0
    def fromXML(self, xmlObj):
        """
        fromXML:
        @param xmlObj: A xml object  
        @type xmlObj: L{lxml.etree._Element}
        @author: Thomas Hrabe 
        """

        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XMLobject.'
            )

        if xmlObj.tag == 'GrowingAverageJob':
            job_element = xmlObj
        else:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a GrowingAverageJobXML! You must provide a valid GrowingAverageJobXML object.'
            )

        from pytom.angles.angle import AngleObject
        from pytom.score.score import fromXML as scoreFromXML
        from pytom.basic.structures import ParticleList
        from pytom.alignment.preprocessing import Preprocessing

        self.startParticleNumber = int(job_element.get('StartParticleNumber'))

        mask = job_element.xpath('Mask')[0]
        from pytom.basic.structures import Mask
        self.maskFile = Mask('')
        self.maskFile.fromXML(mask)

        self.destinationDirectory = job_element.get('DestinationDirectory')

        particleXML = job_element.xpath('ParticleList')[0]

        self.particleList = ParticleList('/', [])
        self.particleList.fromXML(particleXML)

        angleXML = job_element.xpath('Angles')[0]
        ang = AngleObject()
        self.angleObject = ang.fromXML(angleXML)

        scoreXML = job_element.xpath('Score')[0]

        self.score = scoreFromXML(scoreXML)

        self.preprocessing = Preprocessing()
        preprocessingXML = job_element.xpath('Preprocessing')[0]
        self.preprocessing.fromXML(preprocessingXML)
Ejemplo n.º 2
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to job attributes from XML object
        @param xmlObj: A xml object  
        @author: Thomas Hrabe 
        """
        from lxml.etree import _Element, tostring

        if xmlObj.__class__ != _Element:

            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML-CorrelationVectorMessage object.'
            )

        from pytom.cluster.correlationMatrixStructures import CorrelationVector

        main = xmlObj.xpath('/CorrelationVectorMessage')

        message = main[0].xpath('Message')
        message = message[0]
        self._sender = message.get('Sender')
        self._recipient = message.get('Recipient')
        self._timestamp = message.get('Timestamp')

        vectorXML = main[0].xpath('CorrelationVector')

        v = CorrelationVector()
        v.fromXML(vectorXML[0])
        self.setVector(v)
Ejemplo n.º 3
0
    def fromXML(self, xmlObj):
        """
        @param xmlObj: A xml object  
        @type xmlObj: L{lxml.etree._Element}
        @author: Thomas Hrabe 
        """

        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML-WedgeInfo object.'
            )

        from pytom.alignment.structures import MaximisationResult

        if xmlObj.tag == 'AlignmentList':
            list_element = xmlObj
        else:
            list_element = xmlObj.xpath('AlignmentList')
            list_element = list_element[0]

        self._alignmentList = []

        for child in list_element.iter('Result'):
            result = MaximisationResult()
            result.fromXML(child)
            self._alignmentList.append(result)
Ejemplo n.º 4
0
 def fromXML(self,xmlObj):
     """
     fromXML : Assigns values to job attributes from XML object
     @param xmlObj: A xml object  
     @type xmlObj: L{lxml.etree._Element}
     @author: Thomas Hrabe 
     """
     from lxml.etree import _Element
     
     if xmlObj.__class__ != _Element:
         raise ParameterError('You must provide a valid XML-CorrelationMatrixJob object.')
     
     
     from pytom.basic.structures import ParticleList,Mask
     
     particleListObject = xmlObj.xpath('ParticleList')
     self._particleList = ParticleList('/')
     self._particleList.fromXML(particleListObject[0]) 
     
     maskObject = xmlObj.xpath('Mask')[0]
     self._mask = Mask()
     self._mask.fromXML(maskObject)
     
     self._resultMatrixName = xmlObj.get('ResultMatrixName')
     self._applyWedge = xmlObj.get('ApplyWedge') == 'True'
     self._binningFactor = float(xmlObj.get('Binning'))
     
     self._lowestFrequency = float(xmlObj.get('LowestFrequency'))
     self._highestFrequency = float(xmlObj.get('HighestFrequency'))
Ejemplo n.º 5
0
 def fromXML(self,xmlObj):
     """
     fromXML : Assigns values to job attributes from XML object
     @param xmlObj: A xml object  
     @type xmlObj: L{lxml.etree._Element}
     @author: Thomas Hrabe 
     """
     from lxml.etree import _Element,tostring
     
     if xmlObj.__class__ != _Element:
         raise ParameterError('You must provide a valid XML-CorrelationVector object.')
     
     from pytom.basic.structures import Particle,ParticleList
     
     self._particleIndex = int(xmlObj.get('ParticleIndex'))
     
     particleObject = xmlObj.xpath('Particle')
     self._particle = Particle('.')
     self._particle.fromXML(particleObject[0])
     
     particleListObject = xmlObj.xpath('ParticleList')
     self._particleList = ParticleList('/')
     self._particleList.fromXML(particleListObject[0])
     
     values = xmlObj.xpath('Correlation')
     
     self._correlations = [0  for _ in range(len(values))]
     
     for v in values:
         
         index = int(v.get('Index'))
         self._correlations[index] = float(v.get('Value'))
Ejemplo n.º 6
0
    def fromXML(self,xmlObj):
        """
        @param xmlObj: A xml object  
        @type xmlObj: L{lxml.etree._Element}
        @author: chen
        """
        
        from lxml.etree import _Element
        
        if xmlObj.__class__ != _Element :
            from pytom.basic.exceptions import ParameterError
            raise ParameterError('Is not a lxml.etree._Element! You must provide a valid XML-Volume object.')
    
        if xmlObj.tag == 'Volume':
            e = xmlObj
        else:
            e = xmlObj.xpath('Volume')
            e = e[0]
    
        self._filename = e.get('Filename')
        
        s = e.get('Subregion')
        if s != None and s!= 'None':
            s = s[1:-1]
            self.subregion = [int(float(i)) for i in s.split(',')]

        s = e.get('Sampling')
        if s != None and s!= 'None':
            s = s[1:-1]        
            self.sampling = [int(i) for i in s.split(',')]

        s = e.get('Binning')
        if s != None and s!= 'None':
            s = s[1:-1]
            self.binning = [int(i) for i in s.split(',')]
Ejemplo n.º 7
0
 def fromXML(self, xmlObj):
     from lxml.etree import _Element
     
     if xmlObj.__class__ != _Element:
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('You must provide a valid XML object.')
     
     if xmlObj.tag == "FoundParticle":
         main = xmlObj
     else:  
         main = xmlObj.xpath('FoundParticle')
         if len(main) == 0:
             from pytom.basic.exceptions import PyTomClassError
             raise PyTomClassError("This XML is not a FoundParticle.")
         main = main[0]
         
     from pytom.basic.structures import PickPosition, Rotation
     from pytom.score.score import fromXML as fromXMLScore
     
     self.filename = main.get('Filename')
     
     p = main.xpath('PickPosition')[0]
     self.pos = PickPosition()
     self.pos.fromXML(p)
     
     o = main.xpath('Rotation')[0]
     self.orient = Rotation()
     self.orient.fromXML(o)
     
     s = main.xpath('Score')[0]
     self.score = fromXMLScore(s)
Ejemplo n.º 8
0
 def fromXML(self,xmlObj):
     """
     fromXML : Assigns values to job attributes from XML object
     @param xmlObj: A xml object  
     @author: Thomas Hrabe 
     """
     from lxml.etree import _Element,tostring;
     
     if xmlObj.__class__ != _Element :
         
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('Is not a lxml.etree._Element! You must provide a valid XML-MaximisationJobMsg object.')
         
     main = xmlObj.xpath('/GrowingAverageJobMsg')
 
     message = main[0].xpath('Message')
     message = message[0]
     
     self._sender = int(message.get('Sender'))
     self._recipient = int(message.get('Recipient'))
     self._timestamp = message.get('Timestamp')
     
     jobDescription = main[0].xpath('GrowingAverageJob')
     
     j = GrowingAverageJob()
     j.fromXML(jobDescription[0])
     self.setJob(j)
Ejemplo n.º 9
0
def FSFWrapper(self, volume, reference):
    from pytom.tompy.correlation import weightedXCF

    if self.numberOfBands == 0:
        from pytom.basic.exceptions import ParameterError
        raise ParameterError('Bands attribute is empty. Abort.')

    return weightedXCF(volume, reference, self.bands, self.wedgeAngle)
Ejemplo n.º 10
0
 def __init__(self,particle=None,particleList=None,mask=None,particleIndex = None,applyWedge = True,binningFactor=0,lowestFrequency=-1,highestFrequency=-1):
     """
     __init__:
     @param particle: Particle
     @type particle: pytom.alignment.structures.Particle
     @param particleList: ParticleList of all particles will be correlated with self._particle
     @type particleList: pytom.alignment.structures.ParticleList
     @param mask: Mask used for correlation
     @type mask: str
     @param applyWedge: Apply wedge during correlation. True by default, disable for rotation classification.
     @type applyWedge: Bool  
     @param binningFactor: Binning factor accroding to libtomc definition. 0 by default.
     @type binningFactor: unsigned int
     @param lowestFrequency: Lowest frequency for bandpass in nyquist
     @type lowestFrequency: float
     @param highestFrequency: Highest frequency for bandpass in nyquist
     @type highestFrequency: float  
     """
     from pytom.basic.structures import Particle,ParticleList,Mask
     
     if particle and particle.__class__ != Particle:
         raise ParameterError('You must provide a Particle object.')
     
     if particleList and particleList.__class__ != ParticleList:
         raise ParameterError('You must provide a ParticleList object.')
     
     self._particle = particle
     self._particleList = particleList
     
     if not mask:
         mask = Mask()
     elif mask.__class__ == str:
         mask = Mask(mask)
     elif mask.__class__ != Mask:
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('Mask must be a string or Mask object!')
     
     self._mask = mask
     self._particleIndex = particleIndex
     self._applyWedge = applyWedge
     self._binningFactor = binningFactor
     self._lowestFrequency = lowestFrequency
     self._highestFrequency = highestFrequency
Ejemplo n.º 11
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to result attributes from XML object
        @param xmlObj: A xml object  
        @author: Thomas Hrabe 
        """
        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML object.'
            )

        from pytom.score.score import fromXML as fromXMLScore
        from pytom.angles.angle import AngleObject

        if xmlObj.tag == "Result":
            result = xmlObj
        else:
            result = xmlObj.xpath('Result')

            if len(result) == 0:
                raise PyTomClassError(
                    "This XML is not an MaximisationResult. No Result provided."
                )

            result = result[0]
        from pytom.basic.structures import Particle, Reference, Rotation, Shift
        particle_element = result.xpath('Particle')[0]
        p = Particle('')
        p.fromXML(particle_element)
        self._particle = p

        r = result.xpath('Reference')
        ref = Reference('')
        ref.fromXML(r[0])
        self._reference = ref

        scoreXML = result.xpath('Score')[0]
        self._score = fromXMLScore(scoreXML)

        shiftXML = result.xpath('Shift')[0]
        self._shift = Shift()
        self._shift.fromXML(shiftXML)

        rotationXML = result.xpath('Rotation')[0]
        self._rotation = Rotation()
        self._rotation.fromXML(rotationXML)

        angleElement = result.xpath('Angles')
        ang = AngleObject()
        self._angleObject = ang.fromXML(angleElement[0])
Ejemplo n.º 12
0
    def fromXML(self, xmlObj):
        """
        fromXML: Sets attributes of self to those defined by xmlObj
        @param xmlObj: A XML attribute as generated by toXML 
        @author: Thomas Hrabe
        """
        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:
            raise ParameterError(
                'You must provide a valid XML-GlobalSampling object.')

        if xmlObj.tag == 'Angles':
            angles = xmlObj
        else:
            angles = xmlObj.xpath('Angles')

            if len(angles) == 0:
                from pytom.basic.exceptions import ParameterError
                raise ParameterError("This XML is not an GlobalSampling DOM.")
            angles = angles[0]

        self._currentIndex = 0

        parameters = angles.xpath('RefinementParameters')
        self._refinementParameters = []
        if len(parameters) == 1:
            parameters = parameters[0]

            self._refinementParameters.append(float(parameters.get('Shells')))
            self._refinementParameters.append(
                float(parameters.get('Increment')))
        else:
            self._refinementParameters.append(self._defaultShells)
            self._refinementParameters.append(self._defaultIncrement)

        self._filename = angles.get('File')

        self.readRotationsFromEMFile(self._filename)
Ejemplo n.º 13
0
 def __init__(self,particleList=None,mask='',resultMatrixName='',applyWedge = True,binningFactor=0,lowestFrequency=-1,highestFrequency=-1):
     """
     __init__:
     @param particleList: ParticleList of all particles that will be correlated 
     @type particleList: L{pytom.basic.structures.ParticleList}
     @param mask: Mask used for correlation
     @type mask: str or L{pytom.basic.structures.Mask}
     @param resultMatrixName: Result filename
     @type resultMatrixName: str  
     @param applyWedge: Apply wedge weighting if available?
     @type applyWedge: boolean, False by default  
     @param binningFactor: Binning factor accroding to libtomc definition. 0 by default.
     @type binningFactor: unsigned int
     @param lowestFrequency: Lowest frequency for bandpass in nyquist
     @type lowestFrequency: float
     @param highestFrequency: Highest frequency for bandpass in nyquist
     @type highestFrequency: float
     """
     from pytom.basic.structures import ParticleList,Mask
     from pytom.tools.files import checkFileExists
     
     if not particleList:
         particleList = ParticleList('/')
     elif particleList.__class__ != ParticleList:
         raise ParameterError('You must provide a ParticleList object!')
     
     self._particleList = particleList
     
     if mask.__class__ == str:
         mask = Mask(mask)
     elif mask.__class__ != Mask:
         raise ParameterError('Mask must be a string or Mask object!')
     
     self._mask = mask
     self._resultMatrixName = resultMatrixName
     self._applyWedge = applyWedge
     self._binningFactor = binningFactor
     self._lowestFrequency = lowestFrequency
     self._highestFrequency = highestFrequency
Ejemplo n.º 14
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to job attributes from XML object
        @param xmlObj: A xml object
        @type xmlObj: L{lxml.etree._Element}

        @author: Thomas Hrabe 
        """
        from lxml import etree
        from lxml.etree import _Element
        from pytom.basic.structures import ParticleList

        if xmlObj.__class__ != _Element:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML object.'
            )

        if not xmlObj.tag == 'ExpectationJob':
            jobElement = xmlObj.xpath('ExpectationJob')

            if len(jobElement) == 0:
                from pytom.basic.exceptions import ParameterError
                raise ParameterError(
                    'You must provide a valid XML-ExpectationJob object.')
            else:
                jobElement = jobElement[0]
        else:
            jobElement = xmlObj

        self._newAverageName = jobElement.get('AverageName').__str__()

        particleListXML = xmlObj.xpath('ParticleList')
        self._particleList = ParticleList('/')
        if len(particleListXML) > 0:
            self._particleList.fromXML(particleListXML[0])
Ejemplo n.º 15
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to result attributes from XML object
        @param xmlObj: A xml object  
        @author: Thomas Hrabe 
        """
        from lxml.etree import _Element, tostring

        if xmlObj.__class__ != _Element:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML object.'
            )

        self.resultFileName = xmlObj.get('ResultFileName')
        self.wedgeSumName = xmlObj.get('WedgeSumName')
Ejemplo n.º 16
0
 def fromXML(self, xmlObj):
     from lxml.etree import _Element
     
     if xmlObj.__class__ != _Element:
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('You must provide a valid XML object.')
     
     if xmlObj.tag == "ParticleList":
         main = xmlObj
     else:  
         main = xmlObj.xpath('ParticleList')
         if len(main) == 0:
             from pytom.basic.exceptions import PyTomClassError
             raise PyTomClassError("This XML is not a ParticleList.")
         main = main[0]
         
     for p in main.xpath('FoundParticle'):
         particle = FoundParticle()
         particle.fromXML(p)
         self.pl.append(particle)
     
     for p in main.xpath('ClassifiedParticle'):
         particle = ClassifiedParticle()
         particle.fromXML(p)
         self.pl.append(particle)
         
     for p in main.xpath('SimulatedParticle'):
         from pytom.localization.simulation import SimulatedParticle
         particle = SimulatedParticle()
         particle.fromXML(p)
         self.pl.append(particle)
         
     for p in main.xpath('IdentifiedParticle'):
         from pytom.localization.simulation import IdentifiedParticle
         particle = IdentifiedParticle()
         particle.fromXML(p)
         self.pl.append(particle)
     
     for p in main.xpath('Particle'): # now also support reading class Particle, but will convert to FoundParticle
         from pytom.basic.structures import Particle
         pp = Particle()
         pp.fromXML(p)
         
         # convert to FoundParticle
         particle = FoundParticle()
         particle.fromParticle(pp)
         self.pl.append(particle)
Ejemplo n.º 17
0
 def fromXML(self, xmlObj):
     from lxml.etree import _Element
     
     if xmlObj.__class__ != _Element:
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('You must provide a valid XML object.')
     
     if xmlObj.tag == "ClassifiedParticle":
         main = xmlObj
     else:  
         main = xmlObj.xpath('ClassifiedParticle')
         if len(main) == 0:
             from pytom.basic.exceptions import PyTomClassError
             raise PyTomClassError("This XML is not a IdentifiedParticle.")
         main = main[0]
         
     self.classified = main.get('Classified')
     
     correct = main.get('Correct')
     if correct == 'True':
         self.correct = True
     elif correct == 'False':
         self.correct = False
     else:
         self.correct = None
     
     f_particle = main.xpath('FoundParticle')
     if len(f_particle) > 0:
         self.particle = FoundParticle()
         self.particle.fromXML(f_particle[0])
     
     s_particle = main.xpath('SimulatedParticle')
     if len(s_particle) > 0:
         from pytom.localization.simulation import SimulatedParticle
         self.particle = SimulatedParticle()
         self.particle.fromXML(s_particle[0])
     
     i_particle = main.xpath('IdentifiedParticle')
     if len(i_particle) > 0:
         from pytom.localization.simulation import IdentifiedParticle
         self.particle = IdentifiedParticle()
         self.particle.fromXML(i_particle[0])
Ejemplo n.º 18
0
 def fromJob(self,job):
     """
     fromJob: Initializes this object.
     @param job: 
     @type job: L{pytom.alignment.structures.GrowingAverageJob}   
     """
     
     from pytom.alignment.structures import GrowingAverageJob
     
     if not job.__class__ == GrowingAverageJob:
         
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('You must provide a GrowingAverageJob object to initialize GrowingAverage.')
     
     self._particleList = job.particleList
     self._angleObject = job.angleObject
     self._startParticleNumber = job.startParticleNumber
     self._maskFile = job.maskFile
     self._score = job.score
     self._destinationDirectory = job.destinationDirectory
     self._preprocessing = job.preprocessing
Ejemplo n.º 19
0
 def fromXML(self,xmlObj):
     """
     fromXML : Assigns values to result attributes from XML object
     @param xmlObj: A xml object  
     @author: Thomas Hrabe 
     """
     from lxml.etree import _Element,tostring
     
     if xmlObj.__class__ != _Element :
         
         from pytom.basic.exceptions import ParameterError
         raise ParameterError('Is not a lxml.etree._Element! You must provide a valid XML-StatusMessage object.')
     
     message = xmlObj.xpath('Message')
     message = message[0]
     self._sender = message.get('Sender')
     self._recipient = message.get('Recipient')
     self._timestamp = message.get('Timestamp')
     
     status = xmlObj.xpath('Status')
     status = status[0]
     self._status = status.get('Value')
Ejemplo n.º 20
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to job attributes from XML object
        @param xmlObj: A xml object  
        @author: chen
        """
        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:

            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML-PeakJobMsg object.'
            )

        from pytom.localization.peak_job import PeakJob

        main = xmlObj.xpath('/PeakJobMsg')

        if len(main) == 0:
            from pytom.parallel.messages import MessageError
            raise MessageError("This message is not a PeakJobMsg")
        main = main[0]

        message = main.xpath('Message')
        message = message[0]
        #        jobDescription = main.xpath('JobDescription')
        #        jobDescription = jobDescription[0]

        self._sender = message.get('Sender')
        self._recipient = message.get('Recipient')
        self._timestamp = message.get('Timestamp')

        jobDescription = main.xpath('/*/JobDescription')
        j = PeakJob()
        j.fromXML(jobDescription[0])
        self.setJob(j)
Ejemplo n.º 21
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to result attributes from XML object
        @param xmlObj: A xml object  
        @author: chen 
        """
        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:

            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'Is not a lxml.etree._Element! You must provide a valid XML-PeakResultMsg object.'
            )

        from pytom.localization.peak_job import PeakResult

        if xmlObj.tag == "PeakResultMsg":
            main = xmlObj
        else:
            main = xmlObj.xpath('PeakResultMsg')
            if len(main) == 0:
                from pytom.parallel.messages import MessageError
                raise MessageError("This message is not a PeakResultMsg")
            main = main[0]

        message = main.xpath('Message')
        message = message[0]

        self._sender = message.get('Sender')
        self._recipient = message.get('Recipient')
        self._timestamp = message.get('Timestamp')

        res = main.xpath('Result')[0]
        self.result = PeakResult()
        self.result.fromXML(res)
Ejemplo n.º 22
0
def calculate_averages(pl, binning, mask, outdir='./'):
    """
    calcuate averages for particle lists
    @param pl: particle list
    @type pl: L{pytom.basic.structures.ParticleList}
    @param binning: binning factor
    @type binning: C{int}

    last change: Jan 18 2020: error message for too few processes, FF
    """
    import os
    from pytom_volume import complexDiv, vol, pasteCenter
    from pytom.basic.fourier import fft, ifft
    from pytom.basic.correlation import FSC, determineResolution
    from pytom_fftplan import fftShift
    from pytom_volume import reducedToFull

    pls = pl.copy().splitByClass()
    res = {}
    freqs = {}
    wedgeSum = {}

    for pp in pls:
        # ignore the -1 class, which is used for storing the trash class
        class_label = pp[0].getClass()
        if class_label != '-1':
            assert len(pp) > 3
            if len(pp) >= 4 * mpi.size:
                spp = mpi._split_seq(pp, mpi.size)
            else:  # not enough particle to do averaging on one node
                spp = [None] * 2
                spp[0] = pp[:len(pp) // 2]
                spp[1] = pp[len(pp) // 2:]

            args = list(
                zip(spp, [True] * len(spp), [binning] * len(spp),
                    [False] * len(spp), [outdir] * len(spp)))
            avgs = mpi.parfor(paverage, args)

            even_a, even_w, odd_a, odd_w = None, None, None, None
            even_avgs = avgs[1::2]
            odd_avgs = avgs[::2]

            for a, w in even_avgs:
                if even_a is None:
                    even_a = a.getVolume()
                    even_w = w.getVolume()
                else:
                    even_a += a.getVolume()
                    even_w += w.getVolume()
                os.remove(a.getFilename())
                os.remove(w.getFilename())

            for a, w in odd_avgs:
                if odd_a is None:
                    odd_a = a.getVolume()
                    odd_w = w.getVolume()
                else:
                    odd_a += a.getVolume()
                    odd_w += w.getVolume()
                os.remove(a.getFilename())
                os.remove(w.getFilename())

            # determine the resolution
            # raise error message in case even_a == None - only one processor used
            if even_a == None:
                from pytom.basic.exceptions import ParameterError
                raise ParameterError(
                    'cannot split odd / even. Likely you used only one processor - use: mpirun -np 2 (or higher!)?!'
                )

            if mask and mask.__class__ == str:
                from pytom_volume import read, pasteCenter, vol

                maskBin = read(mask, 0, 0, 0, 0, 0, 0, 0, 0, 0, binning,
                               binning, binning)
                if even_a.sizeX() != maskBin.sizeX() or even_a.sizeY(
                ) != maskBin.sizeY() or even_a.sizeZ() != maskBin.sizeZ():
                    mask = vol(even_a.sizeX(), even_a.sizeY(), even_a.sizeZ())
                    mask.setAll(0)
                    pasteCenter(maskBin, mask)
                else:
                    mask = maskBin

            fsc = FSC(even_a, odd_a, int(even_a.sizeX() // 2), mask)
            band = determineResolution(fsc, 0.5)[1]

            aa = even_a + odd_a
            ww = even_w + odd_w
            fa = fft(aa)
            r = complexDiv(fa, ww)
            rr = ifft(r)
            rr.shiftscale(0.0, 1. / (rr.sizeX() * rr.sizeY() * rr.sizeZ()))

            res[class_label] = rr
            freqs[class_label] = band

            ww2 = reducedToFull(ww)
            fftShift(ww2, True)
            wedgeSum[class_label] = ww2
    print('done')
    return res, freqs, wedgeSum
Ejemplo n.º 23
0
def fromXML(xmlObj):
    """
    fromXML: Returns a score object depending on the string constant
    @param xmlObj: The DOM object provided
    @return: The score object
    @author: Thomas Hrabe
    """

    type = xmlObj.get('Type')
    value = xmlObj.get('Value')

    if value == 'NAN':
        value = []

    if type == 'xcfScore':
        score = xcfScore()
    elif type == 'nxcfScore':
        score = nxcfScore()
    elif type == 'FLCFScore':
        score = FLCFScore()
    # make FLCF default score
    elif type == 'undefined':
        score = FLCFScore()
    elif type == 'SOCScore':
        score = SOCScore()
    elif type == 'RScore':
        score = RScore()
        nb = xmlObj.get('NumberBands')
        wa = xmlObj.get('WedgeAngle')
        nb = nb
        wa = wa

        if nb.__class__ == str:
            nb = int(nb)
        if wa.__class__ == str:
            wa = int(wa)

        score.initAttributes(nb, wa)
    elif type == 'FSCScore':
        score = FSCScore()
        nb = xmlObj.get('NumberBands')
        wa = xmlObj.get('WedgeAngle')
        nb = nb
        wa = wa

        if nb.__class__ == str:
            nb = int(nb)
        if wa.__class__ == str:
            wa = int(wa)

        score.initAttributes(nb, wa)
    elif type == 'FRMScore':
        from pytom.frm.FRMAlignment import FRMScore
        score = FRMScore()
    else:
        from pytom.basic.exceptions import ParameterError
        raise ParameterError('Type ' + type +
                             ' not available in pytom.alignment.score!')

    score.setValue(value)

    prElement = xmlObj.xpath('PeakPrior')
    if prElement == None:
        prElement = xmlObj.xpath('DistanceFunction')

    if len(prElement) > 0:
        prObject = PeakPrior()
        prObject.fromXML(prElement[0])
        score._peakPrior = prObject
    else:
        score._peakPrior = PeakPrior()

    removeAutocorrelation = xmlObj.get('RemoveAutocorr')
    if removeAutocorrelation == 'True':
        removeAutocorrelation = True
    else:
        removeAutocorrelation = False
    score.setRemoveAutocorrelation(flag=removeAutocorrelation)

    return score
Ejemplo n.º 24
0
    def fromXML(self, xmlObj):
        """
        fromXML : Assigns values to job attributes from XML object
        @param xmlObj: A xml object  
        @author: Thomas Hrabe 
        """
        from lxml.etree import _Element

        if xmlObj.__class__ != _Element:
            from pytom.basic.exceptions import ParameterError
            raise ParameterError(
                'You must provide a valid XML-MaximisationJob object.')

        if xmlObj.tag == "JobDescription":
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('JobDescription')

            if len(jobDescription) == 0:
                from pytom.basic.structures import PyTomClassError
                raise PyTomClassError("This XML is not an JobDescription.")

            jobDescription = jobDescription[0]

        from pytom.angles.angle import AngleObject
        from pytom.score.score import fromXML as fromXMLScore
        from pytom.alignment.preprocessing import Preprocessing
        from pytom.basic.structures import Mask, Particle, Reference, ReferenceList

        self.binning = int(jobDescription.get('Binning'))

        particle_element = jobDescription.xpath('Particle')[0]
        p = Particle('')
        p.fromXML(particle_element)
        self.particle = p

        r = jobDescription.xpath('Reference')

        if len(r) > 0:
            ref = Reference('')
            ref.fromXML(r[0])
            self.reference = ref
        else:
            r = jobDescription.xpath('ReferenceList')
            ref = ReferenceList()
            ref.fromXML(r[0])
            self.reference = ref

        mask = jobDescription.xpath('Mask')[0]
        self.mask = Mask('')
        self.mask.fromXML(mask)

        self.numberRefinementRounds = jobDescription.get(
            'NumberRefinementRounds')
        self.numberRefinementRounds = int(self.numberRefinementRounds)

        score = jobDescription.xpath('Score')
        self.score = fromXMLScore(score[0])

        angles = jobDescription.xpath('Angles')
        ang = AngleObject()
        self.rotations = ang.fromXML(angles[0])

        preObj = xmlObj.xpath('Preprocessing')
        if len(preObj) == 0:
            self.preprocessing = Preprocessing()
        else:
            p = Preprocessing()
            p.fromXML(preObj[0])
            self.preprocessing = p