Beispiel #1
0
    def fromXML(self, xmlObj):
        from lxml.etree import _Element

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

        if xmlObj.tag == "CTFCorrectionJob":
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('CTFCorrectionJob')
            if len(jobDescription) == 0:
                raise Exception("This XML is not a CTFCorrectionJob.")
            jobDescription = jobDescription[0]

        from pytom.basic.structures import ParticleList, Reference, Mask, SampleInformation

        particleList_element = jobDescription.xpath('ParticleList')[0]
        pl = ParticleList('.')
        pl.fromXML(particleList_element)
        self.particleList = pl

        self.reference = []
        r = jobDescription.xpath('Reference')
        for ref_obj in r:
            ref = Reference('')
            ref.fromXML(ref_obj)
            self.reference.append(ref)

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

        try:
            si = jobDescription.xpath('SampleInformation')[0]
            self.sampleInformation = SampleInformation()
            self.sampleInformation.fromXML(si)
        except:
            self._sampleInformation = SampleInformation()

        self.ctf_conv_pl = jobDescription.get('CTFConvolutedParticleList')
        self.peak_offset = int(jobDescription.get('PeakOffset'))
        self.bw_range = [
            int(i)
            for i in jobDescription.get('BandwidthRange')[1:-1].split(',')
        ]
        self.freq = int(jobDescription.get('Frequency'))
        self.destination = jobDescription.get('Destination')
        self.max_iter = int(jobDescription.get('MaxIterations'))
        self.r_score = jobDescription.get('RScore') == 'True'
        self.weighting = jobDescription.get('WeightedAverage') == 'True'
        self.bfactor = jobDescription.get('BFactor')
        self.sum_ctf_sqr = jobDescription.get('CTFSquared')
Beispiel #2
0
        raise RuntimeError('Destination directory ' + destination +
                           ' does not exist!')

    from pytom.cluster.mcoEXMXStructures import MCOEXMXJob
    from pytom.basic.structures import ParticleList, Reference, Mask, Wedge, SampleInformation, PointSymmetry
    from pytom.score.score import FLCFScore
    from pytom.frontend.serverpages.createMCOEXMXJob import createRunscripts
    from pytom.alignment.preprocessing import Preprocessing

    p = ParticleList()
    p.fromXMLFile(particleList)
    m = Mask(mask)
    w = Wedge([float(wedge1), float(wedge2)])
    pre = Preprocessing(lowestFrequency=float(lowestFrequency),
                        highestFrequency=float(highestFrequency))
    sample = SampleInformation(pixelSize=float(pixelSize),
                               particleDiameter=float(diameter))

    if symmetryN is None or symmetryAxisZ is None or symmetryAxisX is None:
        sym = None
    else:
        sym = PointSymmetry(nfold=int(symmetryN),
                            z2=float(symmetryAxisZ),
                            x=float(symmetryAxisX))

    job = MCOEXMXJob(particleList=p,numberIterations=numberIterations,\
                     destinationDirectory=destination,mask=mask,score=FLCFScore(),preprocessing=pre,\
                     wedgeInfo=w,binning=int(binning),sampleInformation=sample,numberClasses=int(numberClasses),\
                     endThreshold=float(endThreshold),symmetry = sym,doAlignment = False,frmBandwidth = None)

    job.toXMLFile(jobName)
Beispiel #3
0
    def fromXML(self, xmlObj):
        """
        read from xml file
        @param xmlObj: xml object
        @type xmlObj: L{lxml.etree.Element}
        """
        from lxml.etree import _Element

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

        if xmlObj.tag == "FRMJob":
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('FRMJob')
            if len(jobDescription) == 0:
                raise Exception("This XML is not a FRMJob.")
            jobDescription = jobDescription[0]

        from pytom.basic.structures import ParticleList, Reference, Mask, SampleInformation, MultiSymmetries

        pl = ParticleList('.')
        particleList_element = jobDescription.xpath('ParticleList')
        if len(particleList_element) > 0:
            pl.fromXML(particleList_element[0])
        else:
            list_elements = jobDescription.xpath('ParticleListLocation')
            for e in list_elements:
                sub_pl = ParticleList()
                sub_pl.fromXMLFile(e.get('Path'))
                pl += sub_pl
        self.particleList = pl

        r = jobDescription.xpath('Reference')[0]
        self.reference = Reference('')
        self.reference.fromXML(r)

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

        try:
            si = jobDescription.xpath('SampleInformation')[0]
            self.sampleInformation = SampleInformation()
            self.sampleInformation.fromXML(si)
        except:
            self.sampleInformation = SampleInformation()

        try:
            syms = jobDescription.xpath('MultiSymmetries')[0]
            self.symmetries = MultiSymmetries()
            self.symmetries.fromXML(syms)
        except:
            self.symmetries = MultiSymmetries()

        self.peak_offset = int(jobDescription.get('PeakOffset'))
        self.bw_range = [
            int(i)
            for i in jobDescription.get('BandwidthRange')[1:-1].split(',')
        ]
        self.freq = int(jobDescription.get('Frequency'))
        self.destination = jobDescription.get('Destination')
        self.max_iter = int(jobDescription.get('MaxIterations'))
        self.r_score = jobDescription.get('RScore') == 'True'
        self.weighting = jobDescription.get('WeightedAverage') == 'True'
        self.bfactor = jobDescription.get('BFactor')
        self.binning = int(jobDescription.get('binning'))
        if jobDescription.get('AdaptiveResolution'):
            adaptive_resolution = jobDescription.get('AdaptiveResolution')
            if adaptive_resolution == '+1':
                self.adaptive_res = False  # always increase by 1
            else:
                self.adaptive_res = float(adaptive_resolution)
        else:
            self.adaptive_res = 0.0  # default, if not specified
        if jobDescription.get('FSC'):
            self.fsc_criterion = float(jobDescription.get('FSC'))
        else:
            self.fsc_criterion = 0.5  # default value

        # for the constraint
        try:
            from sh_alignment.constrained_frm import AngularConstraint
            con = jobDescription.xpath('AngularConstraint')
            if len(con) != 0:
                ac = AngularConstraint()
                c = ac.fromXML(con[0])
                self.constraint = c
            else:
                self.constraint = None
        except:
            self.constraint = None
Beispiel #4
0
class FRMJob(PyTomClass):  # i need to rename the class, but for now it works
    def __init__(self,
                 pl=None,
                 ref=None,
                 mask=None,
                 peak_offset=0,
                 sample_info=None,
                 bw_range=None,
                 freq=None,
                 dest='.',
                 max_iter=10,
                 r_score=False,
                 weighting=False,
                 bfactor=None,
                 symmetries=None,
                 adaptive_res=0.1,
                 fsc_criterion=0.5,
                 constraint=None,
                 binning=1):
        """
        initiate FRM job
        @param pl: particle list
        @type ps: L{pytom.basic.structures.ParticleList}
        @param ref: reference density
        @type ref: L{pytom.basic.structures.Reference}
        @param mask: mask 
        @type ref: L{pytom.basic.structures.Mask}
        @param peak_offset: peak offset in voxel
        @type peak_offset: C{int}
        @param sample_info: ?? (Default: None)
        @type sample_info: ??
        @param bw_range: bandwidth range in pixel (2-dim vector)
        @type bw_range: C{list}
        @param freq: frequency (default: None)
        @type: C{int}
        @param dest: distination directory (default: '.')
        @type: C{str}
        @param max_iter: maximum number of iterations
        @type max_iter: C{int}
        @param r_score: use r_score (??) (default: False)
        @type r_score: C{bool}
        @param weighting: weighting (default: False)
        @type weighting: C{bool}
        @param bfactor: B-factor (default: None)
        @type bfactor: C{float}?
        @param symmetries: symmetry (default: None)
        @type L{pytom.basic.structures.Symmetries}
        @param adaptive_res: adaptive resolution - add to resolution for filtering
        @type adaptive_res: C{float}
        @param fsc_criterion: FSC criterion (default: 0.5)
        @type fsc_criterion: C{float}
        @param constraint: Constraint on orientations (deafult: None)
        @type constraint: ??
        @param binning: Perform binning (downscale) of subvolumes by factor. Default=1.
        @type binning C{float}
        """
        self.particleList = pl
        self.reference = ref
        self.mask = mask
        self.peak_offset = peak_offset
        self.sampleInformation = sample_info
        self.bw_range = bw_range
        self.freq = freq
        self.destination = dest
        self.max_iter = max_iter
        self.r_score = r_score
        self.weighting = weighting
        self.bfactor = bfactor
        self.symmetries = symmetries
        self.adaptive_res = adaptive_res
        self.fsc_criterion = fsc_criterion
        self.constraint = constraint
        self.binning = binning

    def fromXML(self, xmlObj):
        """
        read from xml file
        @param xmlObj: xml object
        @type xmlObj: L{lxml.etree.Element}
        """
        from lxml.etree import _Element

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

        if xmlObj.tag == "FRMJob":
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('FRMJob')
            if len(jobDescription) == 0:
                raise Exception("This XML is not a FRMJob.")
            jobDescription = jobDescription[0]

        from pytom.basic.structures import ParticleList, Reference, Mask, SampleInformation, MultiSymmetries

        pl = ParticleList('.')
        particleList_element = jobDescription.xpath('ParticleList')
        if len(particleList_element) > 0:
            pl.fromXML(particleList_element[0])
        else:
            list_elements = jobDescription.xpath('ParticleListLocation')
            for e in list_elements:
                sub_pl = ParticleList()
                sub_pl.fromXMLFile(e.get('Path'))
                pl += sub_pl
        self.particleList = pl

        r = jobDescription.xpath('Reference')[0]
        self.reference = Reference('')
        self.reference.fromXML(r)

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

        try:
            si = jobDescription.xpath('SampleInformation')[0]
            self.sampleInformation = SampleInformation()
            self.sampleInformation.fromXML(si)
        except:
            self.sampleInformation = SampleInformation()

        try:
            syms = jobDescription.xpath('MultiSymmetries')[0]
            self.symmetries = MultiSymmetries()
            self.symmetries.fromXML(syms)
        except:
            self.symmetries = MultiSymmetries()

        self.peak_offset = int(jobDescription.get('PeakOffset'))
        self.bw_range = [
            int(i)
            for i in jobDescription.get('BandwidthRange')[1:-1].split(',')
        ]
        self.freq = int(jobDescription.get('Frequency'))
        self.destination = jobDescription.get('Destination')
        self.max_iter = int(jobDescription.get('MaxIterations'))
        self.r_score = jobDescription.get('RScore') == 'True'
        self.weighting = jobDescription.get('WeightedAverage') == 'True'
        self.bfactor = jobDescription.get('BFactor')
        self.binning = int(jobDescription.get('binning'))
        if jobDescription.get('AdaptiveResolution'):
            adaptive_resolution = jobDescription.get('AdaptiveResolution')
            if adaptive_resolution == '+1':
                self.adaptive_res = False  # always increase by 1
            else:
                self.adaptive_res = float(adaptive_resolution)
        else:
            self.adaptive_res = 0.0  # default, if not specified
        if jobDescription.get('FSC'):
            self.fsc_criterion = float(jobDescription.get('FSC'))
        else:
            self.fsc_criterion = 0.5  # default value

        # for the constraint
        try:
            from sh_alignment.constrained_frm import AngularConstraint
            con = jobDescription.xpath('AngularConstraint')
            if len(con) != 0:
                ac = AngularConstraint()
                c = ac.fromXML(con[0])
                self.constraint = c
            else:
                self.constraint = None
        except:
            self.constraint = None

    def toXML(self):
        """
        copy to xml structure
        @return: xml object for job
        @rtype L{lxml.etree.Element}
        """
        from lxml import etree

        jobElement = etree.Element("FRMJob")
        jobElement.append(self.particleList.toXML())
        jobElement.append(self.reference.toXML())
        jobElement.append(self.mask.toXML())
        jobElement.append(self.sampleInformation.toXML())
        if self.symmetries is not None:
            jobElement.append(self.symmetries.toXML())
        jobElement.set("PeakOffset", str(self.peak_offset))
        jobElement.set("BandwidthRange", str(self.bw_range))
        jobElement.set("Frequency", str(self.freq))
        jobElement.set("Destination", self.destination)
        jobElement.set("MaxIterations", str(self.max_iter))
        jobElement.set("RScore", str(self.r_score))
        jobElement.set("WeightedAverage", str(self.weighting))
        jobElement.set("BFactor", str(self.bfactor))
        jobElement.set("binning", str(self.binning))
        if self.adaptive_res is False:
            jobElement.set("AdaptiveResolution", '+1')
        else:
            jobElement.set("AdaptiveResolution", str(self.adaptive_res))
        jobElement.set("FSC", str(self.fsc_criterion))
        if self.constraint:
            jobElement.append(self.constraint.toXML())

        return jobElement

    def check(self):
        from pytom.tools.files import checkDirExists
        self.particleList.check()
        self.reference.check()
        self.mask.check()
        if not checkDirExists(self.destination):
            raise RuntimeError('Destination path not found! ' +
                               self.destination)
Beispiel #5
0
class FRMJob(PyTomClass):  # i need to rename the class, but for now it works
    def __init__(self,
                 pl=None,
                 ref=None,
                 mask=None,
                 peak_offset=0,
                 sample_info=None,
                 bw_range=None,
                 freq=None,
                 dest='.',
                 max_iter=10,
                 r_score=False,
                 weighting=False,
                 bfactor=None,
                 symmetries=None,
                 adaptive_res=0.1,
                 fsc_criterion=0.5,
                 constraint=None):
        self.particleList = pl
        self.reference = ref
        self.mask = mask
        self.peak_offset = peak_offset
        self.sampleInformation = sample_info
        self.bw_range = bw_range
        self.freq = freq
        self.destination = dest
        self.max_iter = max_iter
        self.r_score = r_score
        self.weighting = weighting
        self.bfactor = bfactor
        self.symmetries = symmetries
        self.adaptive_res = adaptive_res
        self.fsc_criterion = fsc_criterion
        self.constraint = constraint

    def fromXML(self, xmlObj):
        from lxml.etree import _Element

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

        if xmlObj.tag == "FRMJob":
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('FRMJob')
            if len(jobDescription) == 0:
                raise Exception("This XML is not a FRMJob.")
            jobDescription = jobDescription[0]

        from pytom.basic.structures import ParticleList, Reference, Mask, SampleInformation, MultiSymmetries

        pl = ParticleList('.')
        particleList_element = jobDescription.xpath('ParticleList')
        if len(particleList_element) > 0:
            pl.fromXML(particleList_element[0])
        else:
            list_elements = jobDescription.xpath('ParticleListLocation')
            for e in list_elements:
                sub_pl = ParticleList()
                sub_pl.fromXMLFile(e.get('Path'))
                pl += sub_pl
        self.particleList = pl

        r = jobDescription.xpath('Reference')[0]
        self.reference = Reference('')
        self.reference.fromXML(r)

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

        try:
            si = jobDescription.xpath('SampleInformation')[0]
            self.sampleInformation = SampleInformation()
            self.sampleInformation.fromXML(si)
        except:
            self.sampleInformation = SampleInformation()

        try:
            syms = jobDescription.xpath('MultiSymmetries')[0]
            self.symmetries = MultiSymmetries()
            self.symmetries.fromXML(syms)
        except:
            self.symmetries = MultiSymmetries()

        self.peak_offset = int(jobDescription.get('PeakOffset'))
        self.bw_range = [
            int(i)
            for i in jobDescription.get('BandwidthRange')[1:-1].split(',')
        ]
        self.freq = int(jobDescription.get('Frequency'))
        self.destination = jobDescription.get('Destination')
        self.max_iter = int(jobDescription.get('MaxIterations'))
        self.r_score = jobDescription.get('RScore') == 'True'
        self.weighting = jobDescription.get('WeightedAverage') == 'True'
        self.bfactor = jobDescription.get('BFactor')
        if jobDescription.get('AdaptiveResolution'):
            adaptive_resolution = jobDescription.get('AdaptiveResolution')
            if adaptive_resolution == '+1':
                self.adaptive_res = False  # always increase by 1
            else:
                self.adaptive_res = float(adaptive_resolution)
        else:
            self.adaptive_res = 0.0  # default, if not specified
        if jobDescription.get('FSC'):
            self.fsc_criterion = float(jobDescription.get('FSC'))
        else:
            self.fsc_criterion = 0.5  # default value

        # for the constraint
        try:
            from sh_alignment.constrained_frm import AngularConstraint
            con = jobDescription.xpath('AngularConstraint')
            if len(con) != 0:
                ac = AngularConstraint()
                c = ac.fromXML(con[0])
                self.constraint = c
            else:
                self.constraint = None
        except:
            self.constraint = None

    def toXML(self):
        from lxml import etree

        jobElement = etree.Element("FRMJob")
        jobElement.append(self.particleList.toXML())
        jobElement.append(self.reference.toXML())
        jobElement.append(self.mask.toXML())
        jobElement.append(self.sampleInformation.toXML())
        if self.symmetries is not None:
            jobElement.append(self.symmetries.toXML())
        jobElement.set("PeakOffset", str(self.peak_offset))
        jobElement.set("BandwidthRange", str(self.bw_range))
        jobElement.set("Frequency", str(self.freq))
        jobElement.set("Destination", self.destination)
        jobElement.set("MaxIterations", str(self.max_iter))
        jobElement.set("RScore", str(self.r_score))
        jobElement.set("WeightedAverage", str(self.weighting))
        jobElement.set("BFactor", str(self.bfactor))
        if self.adaptive_res is False:
            jobElement.set("AdaptiveResolution", '+1')
        else:
            jobElement.set("AdaptiveResolution", str(self.adaptive_res))
        jobElement.set("FSC", str(self.fsc_criterion))
        if self.constraint:
            jobElement.append(self.constraint.toXML())

        return jobElement

    def check(self):
        from pytom.tools.files import checkDirExists
        self.particleList.check()
        self.reference.check()
        self.mask.check()
        if not checkDirExists(self.destination):
            raise RuntimeError('Destination path not found! ' +
                               self.destination)
Beispiel #6
0
def interpretRequestParameters(parameters):
    """
    interpretRequestParameters
    """

    from pytom.basic.structures import ParticleList, SampleInformation, Reference, Mask, Wedge
    from pytom.alignment.preprocessing import Preprocessing
    from pytom.frontend.serverpages.serverMessages import FileMessage

    particleList = ParticleList()
    if 'plXML' in parameters:
        particleList.fromXMLFile(parameters['plXML'])
    elif 'plDIR' in parameters:
        particleList = ParticleList(parameters['plDIR'])
        particleList.loadDirectory()
    else:
        raise RuntimeError('ParticleList parameter missing in request!')

    sampleInfo = SampleInformation()

    if 'pixSize' in parameters:
        sampleInfo.setPixelSize(parameters['pixSize'])
    else:
        raise RuntimeError('Pixelsize parameter missing in request!')

    if 'partDia' in parameters:
        sampleInfo.setParticleDiameter(parameters['partDia'])
    else:
        raise RuntimeError('Particle diameter missing in request!')

    if 'wa1' in parameters:
        wedgeAngle1 = float(parameters['wa1'])
    else:
        raise RuntimeError('Wedge angle 1 parameter missing in request!')

    if 'wa2' in parameters:
        wedgeAngle2 = float(parameters['wa2'])
    else:
        raise RuntimeError('Wedge angle 2 parameter missing in request!')

    wedgeInfo = Wedge([wedgeAngle1, wedgeAngle2])

    if 'mask' in parameters:
        mask = Mask(parameters['mask'])
    else:
        raise RuntimeError('Mask parameter missing in request!')

    if not 'lowestF' in parameters:
        raise RuntimeError('Lowest frequency parameter missing in request!')

    if not 'highestF' in parameters:
        raise RuntimeError('Highest frequency parameter missing in request!')

    if not 'filtSm' in parameters:
        raise RuntimeError('Filter smooth parameter missing in request!')

    preprocessing = Preprocessing(float(parameters['lowestF']),
                                  float(parameters['highestF']),
                                  float(parameters['filtSm']))

    score = None

    if 'score' in parameters:
        if parameters['score'] == 'xcf':
            from pytom.score.score import xcfScore as scoreClass
        elif parameters['score'] == 'nxcf':
            from pytom.score.score import nxcfScore as scoreClass
        elif parameters['score'] == 'flcf':
            from pytom.score.score import FLCFScore as scoreClass
        score = scoreClass()
    else:
        raise RuntimeError('Score parameter missing in request!')

    if 'iter' in parameters:
        iterations = int(parameters['iter'])
    else:
        raise RuntimeError('Number of iterations missing in request!')

    if 'binning' in parameters:
        binning = int(parameters['binning'])
    else:
        raise RuntimeError('Scaling parameter missing in request!')

    if 'classes' in parameters:
        numberClasses = float(parameters['classes'])
    else:
        raise RuntimeError('Number classes parameter missing in request!')

    if 'conv' in parameters:
        convergence = float(parameters['conv'])
    else:
        raise RuntimeError('Convergence parameter missing in request!')

    if 'dest' in parameters:
        destination = parameters['dest']
    else:
        raise RuntimeError('Destination parameter missing in request!')

    sampleInfo = SampleInformation()
    if 'pixSize' in parameters:
        sampleInfo.setPixelSize(float(parameters['pixSize']))
    else:
        raise RuntimeError('Pixelsize parameter missing in request!')

    if 'partDia' in parameters:
        sampleInfo.setParticleDiameter(float(parameters['partDia']))
    else:
        raise RuntimeError('Particle diameter missing in request!')

    from pytom.cluster.mcoEXMXStructures import MCOEXMXJob

    job = MCOEXMXJob(particleList,
                     iterations,
                     destination,
                     mask,
                     score,
                     preprocessing,
                     wedgeInfo,
                     binning,
                     sampleInfo,
                     numberClasses,
                     convergence,
                     symmetry=None)

    jobXMLFile = ''

    if 'jobFile' in parameters:
        jobXMLFile = parameters['jobFile']
        job.toXMLFile(jobXMLFile)
        jobRunFile = jobXMLFile[0:-3]
        createRunscripts(jobRunFile + 'sh', jobXMLFile)

    return FileMessage('MCOEXMXJob', jobXMLFile, 'created')
Beispiel #7
0
def interpretRequestParameters(parameters):
    """
    interpretRequestParameters
    """

    from pytom.basic.structures import ParticleList, SampleInformation, Reference, Mask, Wedge
    from pytom.alignment.preprocessing import Preprocessing
    from pytom.frontend.serverpages.serverMessages import FileMessage
    particleList = ParticleList('.')
    if 'plXML' in parameters:
        particleList.fromXMLFile(parameters['plXML'])
    elif 'plDIR' in parameters:
        particleList = ParticleList(parameters['plDIR'])
        particleList.loadDirectory()
    else:
        raise RuntimeError('ParticleList parameter missing in request!')

    sampleInfo = SampleInformation()

    if 'pixSize' in parameters:
        sampleInfo.setPixelSize(parameters['pixSize'])
    else:
        raise RuntimeError('Pixelsize parameter missing in request!')

    if 'partDia' in parameters:
        sampleInfo.setParticleDiameter(parameters['partDia'])
    else:
        raise RuntimeError('Particle diameter missing in request!')

    if 'wa1' in parameters:
        wedgeAngle1 = float(parameters['wa1'])
    else:
        raise RuntimeError('Wedge angle 1 parameter missing in request!')

    if 'wa2' in parameters:
        wedgeAngle2 = float(parameters['wa2'])
    else:
        raise RuntimeError('Wedge angle 2 parameter missing in request!')

    wedgeInfo = Wedge([wedgeAngle1, wedgeAngle2])

    if 'mask' in parameters:
        mask = Mask(parameters['mask'])
    else:
        raise RuntimeError('Mask parameter missing in request!')

    if not 'lowestF' in parameters:
        raise RuntimeError('Lowest frequency parameter missing in request!')

    if not 'highestF' in parameters:
        raise RuntimeError('Highest frequency parameter missing in request!')

    if not 'filtSm' in parameters:
        raise RuntimeError('Filter smooth parameter missing in request!')

    preprocessing = Preprocessing(float(parameters['lowestF']),
                                  float(parameters['highestF']),
                                  float(parameters['filtSm']))

    score = None

    if 'score' in parameters:
        if parameters['score'] == 'xcf':
            from pytom.score.score import xcfScore as scoreClass
        elif parameters['score'] == 'nxcf':
            from pytom.score.score import nxcfScore as scoreClass
        elif parameters['score'] == 'flcf':
            from pytom.score.score import FLCFScore as scoreClass
        score = scoreClass()
    else:
        raise RuntimeError('Score parameter missing in request!')

    if 'binning' in parameters:
        binning = int(parameters['binning'])
    else:
        raise RuntimeError('Scaling parameter missing in request!')

    if 'classes' in parameters:
        numberClasses = float(parameters['classes'])
    else:
        raise RuntimeError('Number classes parameter missing in request!')

    if 'conv' in parameters:
        convergence = float(parameters['conv'])
    else:
        raise RuntimeError('Convergence parameter missing in request!')

    if 'dest' in parameters:
        destination = parameters['dest']
    else:
        raise RuntimeError('Destination parameter missing in request!')

    sampleInfo = SampleInformation()
    if 'pixSize' in parameters:
        sampleInfo.setPixelSize(float(parameters['pixSize']))
    else:
        raise RuntimeError('Pixelsize parameter missing in request!')

    if 'partDia' in parameters:
        sampleInfo.setParticleDiameter(float(parameters['partDia']))
    else:
        raise RuntimeError('Particle diameter missing in request!')

    temperature = None

    if 'temp' in parameters:
        temperature = parameters['temp']

        if 'stemp' in parameters:
            startTemperature = float(parameters['stemp'])
        else:
            raise RuntimeError(
                'Start temperature parameter missing in request!')

        if 'astep' in parameters:
            annealingStep = float(parameters['astep'])
        else:
            raise RuntimeError('Annealing step parameter missing in request!')

        from pytom.cluster.mcoACStructures import SigmaTemperature

        if temperature == 'sigma':
            temperature = SigmaTemperature(startTemperature, annealingStep)

    else:
        raise RuntimeError('Temperature missing in request!')

    criterion = None

    if 'crit' in parameters:
        from pytom.cluster.mcoACStructures import MetropolisCriterion, ThresholdAcceptance
        criterion = parameters['crit']

        if criterion == 'metropolis':
            criterion = MetropolisCriterion()
        elif criterion == 'threshold':
            criterion = ThresholdAcceptance()
    else:
        raise RuntimeError('Criterion missing in request!')

    if 'refin' in parameters:
        localSearchIncrement = float(parameters['refin'])
    else:
        raise RuntimeError('Number of refinement rounds missing in request!')

    from pytom.cluster.mcoACStructures import MCOACJob

    job = MCOACJob(particleList,
                   destination,
                   mask,
                   score,
                   preprocessing,
                   wedgeInfo,
                   binning,
                   sampleInfo,
                   numberClasses,
                   temperature,
                   criterion,
                   convergence,
                   localSearchIncrement,
                   symmetry=None)

    jobXMLFile = ''

    if 'jobFile' in parameters:
        jobXMLFile = parameters['jobFile']
        job.toXMLFile(jobXMLFile)
        jobRunFile = jobXMLFile[0:-3]
        createRunscripts(jobRunFile + 'sh', jobXMLFile)

    return FileMessage('MCOACJob', jobXMLFile, 'created')
Beispiel #8
0
class CTFCorrectionJob(PyTomClass):
    """For the worker to actually run.
    """
    def __init__(self,
                 pl=None,
                 ctf_conv_pl=None,
                 ref=None,
                 mask=None,
                 peak_offset=0,
                 sample_info=None,
                 bw_range=None,
                 freq=None,
                 dest='.',
                 max_iter=10,
                 r_score=False,
                 weighting=False,
                 bfactor=None,
                 sum_ctf_sqr=None):
        self.particleList = pl
        self.ctf_conv_pl = ctf_conv_pl
        if ref is None:
            self.reference = []
        else:
            self.reference = ref
        self.mask = mask
        self.peak_offset = peak_offset
        self.sampleInformation = sample_info
        self.bw_range = bw_range
        self.freq = freq
        self.destination = dest
        self.max_iter = max_iter
        self.r_score = r_score
        self.weighting = weighting
        self.bfactor = bfactor
        self.sum_ctf_sqr = sum_ctf_sqr

    def fromXML(self, xmlObj):
        from lxml.etree import _Element

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

        if xmlObj.tag == "CTFCorrectionJob":
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('CTFCorrectionJob')
            if len(jobDescription) == 0:
                raise Exception("This XML is not a CTFCorrectionJob.")
            jobDescription = jobDescription[0]

        from pytom.basic.structures import ParticleList, Reference, Mask, SampleInformation

        particleList_element = jobDescription.xpath('ParticleList')[0]
        pl = ParticleList('.')
        pl.fromXML(particleList_element)
        self.particleList = pl

        self.reference = []
        r = jobDescription.xpath('Reference')
        for ref_obj in r:
            ref = Reference('')
            ref.fromXML(ref_obj)
            self.reference.append(ref)

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

        try:
            si = jobDescription.xpath('SampleInformation')[0]
            self.sampleInformation = SampleInformation()
            self.sampleInformation.fromXML(si)
        except:
            self._sampleInformation = SampleInformation()

        self.ctf_conv_pl = jobDescription.get('CTFConvolutedParticleList')
        self.peak_offset = int(jobDescription.get('PeakOffset'))
        self.bw_range = [
            int(i)
            for i in jobDescription.get('BandwidthRange')[1:-1].split(',')
        ]
        self.freq = int(jobDescription.get('Frequency'))
        self.destination = jobDescription.get('Destination')
        self.max_iter = int(jobDescription.get('MaxIterations'))
        self.r_score = jobDescription.get('RScore') == 'True'
        self.weighting = jobDescription.get('WeightedAverage') == 'True'
        self.bfactor = jobDescription.get('BFactor')
        self.sum_ctf_sqr = jobDescription.get('CTFSquared')

    def toXML(self):
        from lxml import etree

        jobElement = etree.Element("CTFCorrectionJob")
        jobElement.append(self.particleList.toXML())
        for ref in self.reference:
            jobElement.append(ref.toXML())
        jobElement.append(self.mask.toXML())
        jobElement.append(self.sampleInformation.toXML())
        jobElement.set("CTFConvolutedParticleList", self.ctf_conv_pl)
        jobElement.set("PeakOffset", str(self.peak_offset))
        jobElement.set("BandwidthRange", str(self.bw_range))
        jobElement.set("Frequency", str(self.freq))
        jobElement.set("Destination", self.destination)
        jobElement.set("MaxIterations", str(self.max_iter))
        jobElement.set("RScore", str(self.r_score))
        jobElement.set("WeightedAverage", str(self.weighting))
        jobElement.set("BFactor", str(self.bfactor))
        jobElement.set("CTFSquared", str(self.sum_ctf_sqr))

        return jobElement
Beispiel #9
0
    def fromXML(self, xmlObj):  # only rewrite this function
        from lxml.etree import _Element

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

        if xmlObj.tag == "FRMJob":  # the name is not changed here!
            jobDescription = xmlObj
        else:
            jobDescription = xmlObj.xpath('FRMJob')
            if len(jobDescription) == 0:
                raise Exception("This XML is not a FRMJob.")
            jobDescription = jobDescription[0]

        from pytom.basic.structures import Reference, Mask, SampleInformation, MultiSymmetries

        particleList_element = jobDescription.xpath('ParticleListSet')[0]
        pl = ParticleListSet()
        pl.fromXML(particleList_element)
        self.particleList = pl  # here i still use the original name!

        self.reference = []
        r = jobDescription.xpath('Reference')
        for ref_obj in r:
            ref = Reference('')
            ref.fromXML(ref_obj)
            self.reference.append(ref)

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

        try:
            si = jobDescription.xpath('SampleInformation')[0]
            self.sampleInformation = SampleInformation()
            self.sampleInformation.fromXML(si)
        except:
            self.sampleInformation = SampleInformation()

        try:
            syms = jobDescription.xpath('MultiSymmetries')[0]
            self.symmetries = MultiSymmetries()
            self.symmetries.fromXML(syms)
        except:
            self.symmetries = MultiSymmetries()

        self.peak_offset = int(jobDescription.get('PeakOffset'))
        self.bw_range = [
            int(i)
            for i in jobDescription.get('BandwidthRange')[1:-1].split(',')
        ]
        self.freq = int(jobDescription.get('Frequency'))
        self.destination = jobDescription.get('Destination')
        self.max_iter = int(jobDescription.get('MaxIterations'))
        self.r_score = jobDescription.get('RScore') == 'True'
        self.weighting = jobDescription.get('WeightedAverage') == 'True'
        self.bfactor = jobDescription.get('BFactor')
        if jobDescription.get('AdaptiveResolution'):
            adaptive_resolution = jobDescription.get('AdaptiveResolution')
            if adaptive_resolution == '+1':
                self.adaptive_res = False  # always increase by 1
            else:
                self.adaptive_res = float(adaptive_resolution)
        else:
            self.adaptive_res = 0.0  # default, if not specified
        if jobDescription.get('FSC'):
            self.fsc_criterion = float(jobDescription.get('FSC'))
        else:
            self.fsc_criterion = 0.5  # default value
Beispiel #10
0
def interpretRequestParameters(parameters):
    """
    interpretRequestParameters
    """
    from pytom.basic.structures import ParticleList, SampleInformation, Reference, Mask, Wedge, PointSymmetry
    from pytom.alignment.preprocessing import Preprocessing
    from pytom.frontend.serverpages.serverMessages import FileMessage

    particleList = ParticleList('.')

    if 'plXML' in parameters:
        particleList.fromXMLFile(parameters['plXML'])
    elif 'plDIR' in parameters:
        particleList = ParticleList(parameters['plDIR'])
        particleList.loadDirectory()
    else:
        raise RuntimeError('ParticleList parameter missing in request!')

    sampleInfo = SampleInformation()
    if 'pixSize' in parameters:
        sampleInfo.setPixelSize(parameters['pixSize'])
    else:
        raise RuntimeError('Pixelsize parameter missing in request!')

    if 'partDia' in parameters:
        sampleInfo.setParticleDiameter(parameters['partDia'])
    else:
        raise RuntimeError('Particle diameter missing in request!')

    reference = ''

    if 'ref' in parameters:
        reference = Reference(parameters['ref'])
    else:
        raise RuntimeError('Reference parameter missing in request!')

    if 'mask' in parameters:
        mask = Mask(parameters['mask'])
    else:
        raise RuntimeError('Mask parameter missing in request!')

    angles = None

    if 'sampling' in parameters:
        if parameters['sampling'] == 'GLOBAL':
            from pytom.angles.globalSampling import GlobalSampling

            if 'angFile' in parameters:
                angles = GlobalSampling(parameters['angFile'])
            else:
                raise RuntimeError('Angle file missing in request!')
        else:
            from pytom.angles.localSampling import LocalSampling

            if 'angStart' in parameters:
                startIncrement = int(parameters['angStart'])
            else:
                raise RuntimeError('Angle start missing in request!')

            if 'angShells' in parameters:
                shells = int(parameters['angShells'])
            else:
                raise RuntimeError('Angle shells missing in request!')

            if 'angInc' in parameters:
                shellIncrement = int(parameters['angInc'])
            else:
                raise RuntimeError('Angle increment missing in request!')

            angles = LocalSampling(shells=shells, increment=startIncrement)
    else:
        raise RuntimeError('Sampling completely missing in request!')

    if not 'lowestF' in parameters:
        raise RuntimeError('Lowest frequency parameter missing in request!')

    if not 'highestF' in parameters:
        raise RuntimeError('Highest frequency parameter missing in request!')

    if not 'filtSm' in parameters:
        raise RuntimeError('Filter smooth parameter missing in request!')

    preprocessing = Preprocessing(float(parameters['lowestF']),
                                  float(parameters['highestF']),
                                  float(parameters['filtSm']))

    adaptive = True

    if 'adapt' in parameters:
        fscCriterion = 0.5
        resOffset = 0.1
        angleFactor = 0.5
        adaptive = parameters['adapt'] == 'ON'

        if parameters['adapt'] == 'ON':

            if 'adResC' in parameters:
                fscCriterion = float(parameters['adResC'])
            else:
                raise RuntimeError('Resolution criterion missing in request!')

            if 'adResOf' in parameters:
                resOffset = parameters['adResOf']
            else:
                raise RuntimeError(
                    'Resolution offset parameter missing in request!')

            if 'angFac' in parameters:
                angleFactor = float(parameters['angFac'])
            else:
                raise RuntimeError(
                    'Angular factor parameter missing in request!')

    else:
        raise RuntimeError('Adaptive parameter missing in request!')

    score = None

    if 'score' in parameters:
        if parameters['score'] == 'xcf':
            from pytom.score.score import xcfScore as scoreClass
        elif parameters['score'] == 'nxcf':
            from pytom.score.score import nxcfScore as scoreClass
        elif parameters['score'] == 'flcf':
            from pytom.score.score import FLCFScore as scoreClass

        score = scoreClass()
    else:
        raise RuntimeError('Score parameter missing in request!')

    if 'pkPriRad' in parameters:
        radius = float(parameters['pkPriRad'])
    else:
        raise RuntimeError('Peak distance parameter missing in request!')

    if 'pkSmooth' in parameters:
        smooth = float(parameters['pkSmooth'])
    else:
        raise RuntimeError('Peak distance smooth missing in request!')

    score.setPeakPrior(radius=radius, smooth=smooth)

    if 'iter' in parameters:
        iterations = int(parameters['iter'])
    else:
        raise RuntimeError('Number of iterations missing in request!')

    if 'binning' in parameters:
        binning = int(parameters['binning'])
    else:
        raise RuntimeError('Scaling parameter missing in request!')

    if 'dest' in parameters:
        destination = parameters['dest']
    else:
        raise RuntimeError('Destination parameter missing in request!')

    from pytom.alignment.ExMaxAlignment import ExMaxJob

    job = ExMaxJob(particleList, destination, reference, score, angles, mask,
                   PointSymmetry(1), 1, iterations, preprocessing, -1, binning,
                   sampleInfo, fscCriterion, adaptive, resOffset, angleFactor)

    #print job
    jobXMLFile = ''

    if 'jobFile' in parameters:
        jobXMLFile = parameters['jobFile']
        job.toXMLFile(jobXMLFile)

        if jobXMLFile[-4:] == '.xml':
            jobRunFile = jobXMLFile[0:-4]
        else:
            jobRunFile = jobXMLFile
        createRunscripts(jobRunFile + '.sh', jobXMLFile)

    return FileMessage('AlignmentJob', jobXMLFile, 'created')