Exemplo n.º 1
0
def create_RandomParticleList(reffile,
                              pl_filename='pl.xml',
                              pdir='./testparticles',
                              nparticles=10):
    """
    @param reffile: reference file
    @type reffile: C{str}
    @param nparticles: number of particles (default: 10)
    @type nparticles: C{int}
    @param pl_filename: particle list filename
    @type pl_filename: C{str}
    @param pdir: particle directory
    @type pdir: C{str}
    @return: particleList
    @rtype: L{pytom.basic.ParticleList}
    
    """
    from pytom.basic.structures import Particle, ParticleList, Rotation, Shift
    from pytom_volume import vol, rotate, shift, read
    from pytom.basic.transformations import general_transform_crop
    from pytom.simulation.whiteNoise import add as addNoise
    import random
    from os import mkdir
    from pytom.score.score import FLCFScore as score

    try:
        mkdir(pdir)
    except FileExistsError:
        print('directory ' + pdir + ' existed already - using this one')
    random.seed(0)

    pl = ParticleList(directory='./')
    ref = read(reffile)
    for ii in range(0, nparticles):
        rot = Rotation(random.uniform(0, 360), random.uniform(0, 360),
                       random.uniform(0, 180))
        shift = Shift(x=random.uniform(-5, 5),
                      y=random.uniform(-5, 5),
                      z=random.uniform(-5, 5))
        rotvol = general_transform_crop(v=ref,
                                        rot=rot,
                                        shift=shift,
                                        scale=None,
                                        order=[0, 1, 2])
        # add some noise
        noisy = addNoise(volume=rotvol, SNR=1)
        fname = pdir + '/particle_' + str(ii) + '.em'
        noisy.write(fname)
        p = Particle(filename=fname,
                     rotation=rot,
                     shift=shift,
                     wedge=None,
                     className=0,
                     pickPosition=None,
                     score=score,
                     sourceInfo=None)
        p.setScoreValue(0.0)
        pl.append(particle=p)

    pl.setFileName(filename=pl_filename)
    pl.toXMLFile(filename=pl_filename)
    return pl
Exemplo n.º 2
0
def create_RandomParticleList(reffile,
                              pl_filename='pl.xml',
                              pdir='./testparticles',
                              nparticles=10):
    """
    @param reffile: reference file
    @type reffile: C{str}
    @param nparticles: number of particles (default: 10)
    @type nparticles: C{int}
    @param pl_filename: particle list filename
    @type pl_filename: C{str}
    @param pdir: particle directory
    @type pdir: C{str}
    @return: particleList
    @rtype: L{pytom.basic.ParticleList}
    
    """
    from pytom.basic.structures import Particle, ParticleList, Rotation, Shift, Wedge
    from pytom_volume import vol, rotate, shift, read
    from pytom.basic.transformations import general_transform_crop
    from pytom.basic.functions import initSphere
    from pytom.simulation.whiteNoise import add as addNoise
    import random
    from os import mkdir
    from pytom.score.score import FLCFScore as score

    try:
        mkdir(pdir)
    except FileExistsError:
        print('directory ' + pdir + ' existed already - using this one')
    random.seed(0)

    a = 0

    wedge = Wedge(wedgeAngles=[30.0, 30.0], cutoffRadius=50.0)

    pl = ParticleList(directory='./')
    ref1 = read(reffile)
    ref2 = initSphere(sizeX=ref1.sizeX(),
                      sizeY=ref1.sizeY(),
                      sizeZ=ref1.sizeZ(),
                      radius=45)
    #ref2.write('testData/mask_45.em')
    parts = {0: ref1, 1: ref2}

    for ii in range(0, nparticles):
        if not ii % 2:
            ref = read(reffile)
        else:
            ref = initSphere(sizeX=ref1.sizeX(),
                             sizeY=ref1.sizeY(),
                             sizeZ=ref1.sizeZ(),
                             radius=30,
                             smooth=30 / 10)

        rot = Rotation(random.uniform(0, 360), random.uniform(0, 360),
                       random.uniform(0, 180))
        shift = Shift(x=a * random.uniform(-5, 5),
                      y=a * random.uniform(-5, 5),
                      z=a * random.uniform(-5, 5))
        rotvol = general_transform_crop(v=ref,
                                        rot=rot,
                                        shift=shift,
                                        scale=None,
                                        order=[0, 1, 2])
        # add some noise
        noisy = addNoise(volume=rotvol, SNR=1)
        fname = pdir + '/particle_' + str(ii) + '.em'

        #noisy.write( fname)
        p = Particle(filename=fname,
                     rotation=rot,
                     shift=shift,
                     wedge=wedge,
                     className=0,
                     pickPosition=None,
                     score=score,
                     sourceInfo=None)
        p.setScoreValue(0.0)

        wg = p.getWedge().getWedgeObject()
        wg.apply(noisy, Rotation(0, 0, 0)).write(fname)

        pl.append(particle=p)

    pl.setFileName(filename=pl_filename)
    pl.toXMLFile(filename=pl_filename)
    return pl