Example #1
0
def combine(emapX, emapY):
    # (1) Find Min/Max cartesian values of emap1 and emap2
    xmin1, ymin1, zmin1 = emapX.cartArray.min(axis=0)
    xmin2, ymin2, zmin2 = emapY.cartArray.min(axis=0)
    xmax1, ymax1, zmax1 = emapX.cartArray.max(axis=0)
    xmax2, ymax2, zmax2 = emapY.cartArray.max(axis=0)
    xmin = xmin1 if xmin1 < xmin2 else xmin2
    ymin = ymin1 if ymin1 < ymin2 else ymin2
    zmin = zmin1 if zmin1 < zmin2 else zmin2
    xmax = xmax1 if xmax1 > xmax2 else xmax2
    ymax = ymax1 if ymax1 > ymax2 else ymax2
    zmax = zmax1 if zmax1 > zmax2 else zmax2
    #
    lessX = xmin2 - xmin
    moreX = xmax2 - xmax
    lessY = ymin2 - ymin
    moreY = ymax2 - ymax
    lessZ = zmin2 - zmin
    moreZ = zmax2 - zmax
    #
    tmp = emapY.pad_mapByCart(lessX, moreX, lessY, moreY, lessZ, moreZ)
    tmp.chargeArray = ext.interpolate(emapX.cartArray, emapX.chargeArray,
                                    tmp.chargeArray3d, tmp.xres, tmp.yres,
                                    tmp.zres).flatten('F')
    return tmp
Example #2
0
def combine_maps(emap1, emap2):
    """
    Loop over all the grid points of emap1, and interpolate them into grid points of emap2.
    """
    # (1) Find Min/Max cartesian values of emap1 and emap2
    xm1, ym1, zm1 = emap1.cartArray.min(axis=0)
    xm2, ym2, zm2 = emap2.cartArray.min(axis=0)
    #
    xmin = xm1 if xm1 < xm2 else xm2
    ymin = ym1 if ym1 < ym2 else ym2
    zmin = zm1 if zm1 < zm2 else zm2
    #
    xm1, ym1, zm1 = emap1.cartArray.max(axis=0)
    xm2, ym2, zm2 = emap2.cartArray.max(axis=0)
    #
    xmax = xm1 if xm1 > xm2 else xm2
    ymax = ym1 if ym1 > ym2 else ym2
    zmax = zm1 if zm1 > zm2 else zm2

    # (2) create valid metadata
    newmap = emap2._new()

    newmap.nxstart = np.int(np.floor(xmin/emap2.xres)) - 1
    newmap.nystart = np.int(np.floor(ymin/emap2.yres)) - 1
    newmap.nzstart = np.int(np.floor(zmin/emap2.zres)) - 1
    newmap.lx = np.int(np.ceil(xmax/emap2.xres)) - newmap.nxstart + 1
    newmap.ly = np.int(np.ceil(ymax/emap2.yres)) - newmap.nystart + 1
    newmap.lz = np.int(np.ceil(zmax/emap2.zres)) - newmap.nzstart + 1

    newmap.nc = newmap.lx
    newmap.nr = newmap.ly
    newmap.ns = newmap.lz
    newmap.ncstart = newmap.nxstart
    newmap.nrstart = newmap.nystart
    newmap.nsstart = newmap.nzstart

    # (3) Create a new blank 3d array using the min/max cartesian values
    # (4) copy data from emap2
    lessX = emap2.nxstart - newmap.nxstart
    moreX = newmap.lx + newmap.nxstart - (emap2.lx + emap2.nxstart)
    lessY = emap2.nystart - newmap.nystart
    moreY = newmap.ly + newmap.nystart - (emap2.ly + emap2.nystart)
    lessZ = emap2.nzstart - newmap.nzstart
    moreZ = newmap.lz + newmap.nzstart - (emap2.lz + emap2.nzstart)

    chargeArray = ext.padZero(emap2.chargeArray3d,
                            lessX, moreX, lessY, moreY, lessZ, moreZ)
    newmap.cartArray = ext.build_cart(newmap.lx, newmap.ly, newmap.lz,
                                       newmap.nxstart, newmap.nystart, newmap.nzstart,
                                       newmap.xres, newmap.yres, newmap.zres)

    # (5) interpolate data from emap1
    newmap.chargeArray = ext.interpolate(emap1.cartArray, emap1.chargeArray, chargeArray,
                            newmap.xres, newmap.yres, newmap.zres).flatten('F')

    return newmap
Example #3
0
    #for i, charge in enumerate(emap2.chargeArray):
    #    newCharge2[i % newChargeLen2] += charge
    #newCharge2 = np.reshape(newCharge2, (emap2.shape[0], emap2.shape[1]), 'F')

    emapX = io.CCP4File.read('/home/fpickard/chien/map1.ccp4')
    emapY = copy.deepcopy(emapX)
    emapY.translations.append(np.array((-40., -40., -40.)))
    # (1) Find Min/Max cartesian values of emap1 and emap2
    xmin1, ymin1, zmin1 = emapX.cartArray.min(axis=0)
    xmin2, ymin2, zmin2 = emapY.cartArray.min(axis=0)
    xmax1, ymax1, zmax1 = emapX.cartArray.max(axis=0)
    xmax2, ymax2, zmax2 = emapY.cartArray.max(axis=0)
    xmin = xmin1 if xmin1 < xmin2 else xmin2
    ymin = ymin1 if ymin1 < ymin2 else ymin2
    zmin = zmin1 if zmin1 < zmin2 else zmin2
    xmax = xmax1 if xmax1 > xmax2 else xmax2
    ymax = ymax1 if ymax1 > ymax2 else ymax2
    zmax = zmax1 if zmax1 > zmax2 else zmax2
    #
    lessX = xmin2 - xmin
    moreX = xmax - xmax2
    lessY = ymin2 - ymin
    moreY = ymax - ymax2
    lessZ = zmin2 - zmin
    moreZ = zmax - zmax2
    #
    tmp = emapY.pad_mapByCart(lessX, moreX, lessY, moreY, lessZ, moreZ)
    tmp.chargeArray = ext.interpolate(emapX.cartArray, emapX.chargeArray,
                                    tmp.chargeArray3d, tmp.xres, tmp.yres,
                                    tmp.zres).flatten('F')