def labels_atoms_w_nrg(self,score_array):
      """ will label each atoms with a nrg score """
      # label each first atom by sum of its ad3 interaction energies 
      firstAts = self.ms.get_entities(0)
      
      for i in range(len(firstAts)):
        a = firstAts[i]
        vdw_hb_estat_ds =Numeric.add.reduce(score_array[i])
        setattr(a, self.prop, vdw_hb_estat_ds)
        ## NOT sure we need the following anymore... ASK Ruth
##         vdw_hb_estat = Numeric.add.reduce(score_array[i])
##         if a.element=='O':
##           setattr(a, self.prop, .236+vdw_hb_estat)   #check this
##         elif a.element=='H':
##           setattr(a, self.prop, .118+vdw_hb_estat)   #check this
##         else:
##           setattr(a, self.prop, Numeric.add.reduce(self.dsolv_array[i])+vdw_hb_estat)

      # label each second atom by sum of its vdw interaction energies
      secondAts = self.ms.get_entities(1)
      swap_result = Numeric.swapaxes(score_array,0,1)
      for i in range(len(swap_result)):
          a = secondAts[i]
          vdw_hb_estat_ds =Numeric.add.reduce(swap_result[i])
          setattr(a, self.prop, vdw_hb_estat_ds)
    def labels_atoms_w_nrg(self,score_array):
        """ will label each atoms with a nrg score """

        # label each first atom by sum of its vdw interaction energies 
        firstAts  = self.ms.get_entities(0)
        for i in range(len(firstAts)):
            # firstAts[i].vdw_energy = Numeric.add.reduce(score_array[i])
            hbond_val =  min(self.hbond_array[i])+max(self.hbond_array[i])
            setattr(firstAts[i], self.prop, Numeric.add.reduce(score_array[i])+hbond_val)
        # label each second atom by sum of its vdw interaction energies
        secondAts = self.ms.get_entities(1)
        swap_result = Numeric.swapaxes(score_array, 0,1)
        swap_hbond_array = Numeric.swapaxes(self.hbond_array, 0, 1)
        for i in range(len(swap_result)):
            hbond_val =  min(swap_hbond_array[i])+max(swap_hbond_array[i])
            setattr(secondAts[i], self.prop, Numeric.add.reduce(swap_result[i])+hbond_val)      
Example #3
0
    def test_getSliceArray(self):

        assert hasattr(UTisocontour, 'getSliceArray')
        isovar = 0
        timestep = 0
        axis = 'x'
        sliceNum = 10
        step = 1
        sh = (1, 1, self.auC.NELEMENTS[0], self.auC.NELEMENTS[1],
              self.auC.NELEMENTS[2])
        da = Numeric.zeros(sh).astype('f')
        da[0][0] = Numeric.array(
            Numeric.reshape(Numeric.swapaxes(self.auC.array, 0, 2),
                            self.auC.NELEMENTS)).astype('f')
        daSmall = Numeric.array(da[:, :, ::step, ::step, ::step]).astype('f')
        center = Numeric.array(self.auC.CENTER).astype('f')
        dim = Numeric.array(self.auC.NELEMENTS).astype('f')
        span = Numeric.array(self.auC.SPACING).astype('f')
        print("span:", span)
        orig = center - ((dim - 1) / 2) * span
        print("orig: ", orig)
        the_data = UTisocontour.newDatasetRegFloat3D(daSmall, orig.astype('f'),
                                                     (span * step, ) * 3)
        #the_data = UTisocontour.newDatasetRegFloat3D(daSmall)

        sld = UTisocontour.getSliceArray(the_data, isovar, timestep, axis,
                                         sliceNum)
        print('sld.shape', sld.shape)
        assert sld.shape == (61, 41)
Example #4
0
    def test_getSliceArray(self):

        assert hasattr(UTisocontour, 'getSliceArray')
        isovar=0
        timestep=0
        axis='x'
        sliceNum=10
        step=1
        sh = (1,1, self.auC.NELEMENTS[0], self.auC.NELEMENTS[1], self.auC.NELEMENTS[2])
        da = Numeric.zeros(sh).astype('f')
        da[0][0] = Numeric.array( Numeric.reshape( Numeric.swapaxes( self.auC.array, 0, 2), self.auC.NELEMENTS ) ).astype('f')
        daSmall = Numeric.array(da[:,:,::step,::step,::step]).astype('f')
        center = Numeric.array(self.auC.CENTER).astype('f')
        dim = Numeric.array(self.auC.NELEMENTS).astype('f')
        span = Numeric.array(self.auC.SPACING).astype('f')
        print("span:", span)
        orig = center - ((dim-1)/2)*span
        print("orig: ", orig)
        the_data = UTisocontour.newDatasetRegFloat3D(daSmall,
                                        orig.astype('f'), (span*step,)*3 )
        #the_data = UTisocontour.newDatasetRegFloat3D(daSmall)

        sld = UTisocontour.getSliceArray(the_data, isovar,
                                       timestep, axis, sliceNum)
        print('sld.shape' ,sld.shape)
        assert sld.shape == (61, 41)
Example #5
0
    def labels_atoms_w_nrg(self, score_array):
        """ will label each atoms with a nrg score """
        # label each first atom by sum of its ad3 interaction energies
        firstAts = self.ms.get_entities(0)

        for i in range(len(firstAts)):
            a = firstAts[i]
            vdw_hb_estat_ds = Numeric.add.reduce(score_array[i])
            setattr(a, self.prop, vdw_hb_estat_ds)
            ## NOT sure we need the following anymore... ASK Ruth
##         vdw_hb_estat = Numeric.add.reduce(score_array[i])
##         if a.element=='O':
##           setattr(a, self.prop, .236+vdw_hb_estat)   #check this
##         elif a.element=='H':
##           setattr(a, self.prop, .118+vdw_hb_estat)   #check this
##         else:
##           setattr(a, self.prop, Numeric.add.reduce(self.dsolv_array[i])+vdw_hb_estat)

# label each second atom by sum of its vdw interaction energies
        secondAts = self.ms.get_entities(1)
        swap_result = Numeric.swapaxes(score_array, 0, 1)
        for i in range(len(swap_result)):
            a = secondAts[i]
            vdw_hb_estat_ds = Numeric.add.reduce(swap_result[i])
            setattr(a, self.prop, vdw_hb_estat_ds)
Example #6
0
    def labels_atoms_w_nrg(self, score_array):
        """ will label each atoms with a nrg score """

        # label each first atom by sum of its vdw interaction energies
        firstAts = self.ms.get_entities(0)
        for i in range(len(firstAts)):
            # firstAts[i].vdw_energy = Numeric.add.reduce(score_array[i])
            hbond_val = min(self.hbond_array[i]) + max(self.hbond_array[i])
            setattr(firstAts[i], self.prop,
                    Numeric.add.reduce(score_array[i]) + hbond_val)
        # label each second atom by sum of its vdw interaction energies
        secondAts = self.ms.get_entities(1)
        swap_result = Numeric.swapaxes(score_array, 0, 1)
        swap_hbond_array = Numeric.swapaxes(self.hbond_array, 0, 1)
        for i in range(len(swap_result)):
            hbond_val = min(swap_hbond_array[i]) + max(swap_hbond_array[i])
            setattr(secondAts[i], self.prop,
                    Numeric.add.reduce(swap_result[i]) + hbond_val)
Example #7
0
    def test_newDatasetRegFloat3D(self):

        # we have to swap axes because in a grid object z varies faster then y which
        # in turn varies faster then x
        sh = (1, 3, self.auC.NELEMENTS[0], self.auC.NELEMENTS[1],
              self.auC.NELEMENTS[2])
        da = Numeric.zeros(sh).astype('f')
        da[0][0] = Numeric.array(
            Numeric.reshape(Numeric.swapaxes(self.auC.array, 0, 2),
                            self.auC.NELEMENTS)).astype('f')
        center = Numeric.array(self.auC.CENTER).astype('f')
        dim = Numeric.array(self.auC.NELEMENTS).astype('f')
        span = Numeric.array(self.auC.SPACING).astype('f')
        print("span: ", span)
        orig = center - ((dim - 1) / 2) * span
        print("orig: ", orig)
        the_data = UTisocontour.newDatasetRegFloat3D(da, orig.astype('f'),
                                                     (span, ) * 3)
        ##      the_data = UTisocontour.newDatasetRegFloat3D(da)
        ##      UTisocontour.setOrig3D(the_data, orig.astype('f'))
        ##      UTisocontour.setSpan3D(the_data, (span,)*3)
        isovar = 0
        timestep = 0
        isovalue = 0.23

        isoc = UTisocontour.getContour3d(the_data, isovar, timestep, isovalue,
                                         UTisocontour.NO_COLOR_VARIABLE)
        vert = Numeric.zeros((isoc.nvert, 3)).astype('f')
        norm = Numeric.zeros((isoc.nvert, 3)).astype('f')
        col = Numeric.zeros((isoc.nvert)).astype('f')
        tri = Numeric.zeros((isoc.ntri, 3)).astype('i')
        print("nvert:", isoc.nvert)
        print("ntri:", isoc.ntri)
        #assert isoc.nvert == 28478
        assert isoc.nvert == 7394
        assert isoc.ntri == 14220
        UTisocontour.getContour3dData(isoc, vert, norm, col, tri, 1)
        nsig = UTisocontour.getNumberOfSignatures(the_data)
        sig0 = UTisocontour.getSignatureFunctions(the_data, 0, 0)
        sig1 = UTisocontour.getSignatureFunctions(the_data, 1, 0)
        sig2 = UTisocontour.getSignatureFunctions(the_data, 2, 0)
        print(sig0.name, sig0.nval)
        print(sig1.name, sig1.nval)
        print(sig2.name, sig2.nval)

        print("signatureValues:",
              UTisocontour.getSignatureValues(the_data, 0, 0, 0.23))
        datainfo = UTisocontour.getDatasetInfo(the_data)
        orig = datainfo._orig()
        span = datainfo._span()
        print("orig: ", orig)
        print("span: ", span)
Example #8
0
    def read(self, filename, normalize):
        """ Read from AutoGrid map file"""

        self.SPACING = 1.0
        self.CENTER = (0., 0., 0.)

        self.header = {'title': 'AutoGrid from %s' % filename}

        # Pmv/Grid.py, Class Grid, function ReadAutoGridMap()
        f = open(filename, 'r')
        try:
            GRID_PARAMETER_FILE = string.split(f.readline())[1]
        except:
            GRID_PARAMETER_FILE = ''
        GRID_DATA_FILE = string.split(f.readline())[1]
        MACROMOLECULE = string.split(f.readline())[1]

        # spacing
        SPACING = float(string.split(f.readline())[1])

        # number of points and center
        (nx, ny, nz) = string.split(f.readline())[1:4]
        NELEMENTS = (nx, ny, nz) = (int(nx) + 1, int(ny) + 1, int(nz) + 1)
        (cx, cy, cz) = string.split(f.readline())[1:4]
        CENTER = (float(cx), float(cy), float(cz))

        # read grid points
        points = map(lambda x: float(x), f.readlines())

        # data read as z,y,z, swapaxes to make the data x,y,z
        TMPGRIDS = N.swapaxes(N.reshape(points, (nz, ny, nx)), 0, 2)
        GRIDS = N.array(TMPGRIDS).astype('f')
        f.close()
        self.data = GRIDS
        #print "shape***:",self.data.shape
        #print "origin***:",CENTER

        origin = (CENTER[0] - (nx / 2) * SPACING,
                  CENTER[1] - (ny / 2) * SPACING,
                  CENTER[2] - (nz / 2) * SPACING)
        stepSize = (SPACING, SPACING, SPACING)

        #def __init__(self, data, origin, stepSize, header):
        grid = Grid3DF(self.data, origin, stepSize, self.header)

        #print "**", grid.dimensions

        return grid
 def read(self, filename, normalize):
     """ Read from AutoGrid map file"""   
     
     self.SPACING=1.0
     self.CENTER=(0.,0.,0.)
  
     self.header = {'title': 'AutoGrid from %s'%filename}
     
     # Pmv/Grid.py, Class Grid, function ReadAutoGridMap()        
     f = open(filename, 'r')
     try:
         GRID_PARAMETER_FILE = string.split(f.readline())[1]
     except:
         GRID_PARAMETER_FILE = ''
     GRID_DATA_FILE = string.split(f.readline())[1]
     MACROMOLECULE = string.split(f.readline())[1]
 
     # spacing
     SPACING = float(string.split(f.readline())[1])
 
     # number of points and center
     (nx,ny,nz) = string.split(f.readline())[1:4]
     NELEMENTS = (nx,ny,nz) = (int(nx)+1, int(ny)+1, int(nz)+1)
     (cx,cy,cz) = string.split(f.readline())[1:4]
     CENTER = ( float(cx),float(cy), float(cz))
     
 
     # read grid points
     points = map( lambda x: float(x), f.readlines())
    
     # data read as z,y,z, swapaxes to make the data x,y,z
     TMPGRIDS = N.swapaxes(N.reshape( points,(nz,ny,nx)), 0, 2)
     GRIDS = N.array(TMPGRIDS).astype('f')
     f.close()
     self.data = GRIDS
     #print "shape***:",self.data.shape
     #print "origin***:",CENTER
     
     origin = (CENTER[0]-(nx/2)*SPACING, CENTER[1]-(ny/2)*SPACING,
               CENTER[2]-(nz/2)*SPACING)
     stepSize = (SPACING,SPACING,SPACING)
     
     #def __init__(self, data, origin, stepSize, header):
     grid = Grid3DF(self.data, origin, stepSize, self.header)
     
     #print "**", grid.dimensions
    
     return grid
Example #10
0
    def test_newDatasetRegFloat3D(self):

        # we have to swap axes because in a grid object z varies faster then y which
        # in turn varies faster then x
        sh = (1,3,self.auC.NELEMENTS[0],self.auC.NELEMENTS[1], self.auC.NELEMENTS[2])
        da = Numeric.zeros(sh).astype('f')
        da[0][0] = Numeric.array( Numeric.reshape( Numeric.swapaxes( self.auC.array, 0, 2), self.auC.NELEMENTS ) ).astype('f')
        center = Numeric.array(self.auC.CENTER).astype('f')
        dim = Numeric.array(self.auC.NELEMENTS).astype('f')
        span = Numeric.array(self.auC.SPACING).astype('f')
        print("span: ", span)
        orig = center - ((dim-1)/2)*span
        print("orig: ", orig)
        the_data = UTisocontour.newDatasetRegFloat3D(da, orig.astype('f'), (span,)*3 )
    ##      the_data = UTisocontour.newDatasetRegFloat3D(da)
    ##      UTisocontour.setOrig3D(the_data, orig.astype('f'))
    ##      UTisocontour.setSpan3D(the_data, (span,)*3)
        isovar   = 0
        timestep = 0
        isovalue = 0.23

        isoc = UTisocontour.getContour3d(the_data, isovar, timestep, isovalue,
                                       UTisocontour.NO_COLOR_VARIABLE)
        vert = Numeric.zeros((isoc.nvert,3)).astype('f')
        norm = Numeric.zeros((isoc.nvert,3)).astype('f')
        col = Numeric.zeros((isoc.nvert)).astype('f')
        tri = Numeric.zeros((isoc.ntri,3)).astype('i')
        print("nvert:", isoc.nvert)
        print("ntri:", isoc.ntri)
        #assert isoc.nvert == 28478
        assert isoc.nvert ==7394
        assert isoc.ntri == 14220
        UTisocontour.getContour3dData(isoc, vert, norm, col, tri, 1)
        nsig = UTisocontour.getNumberOfSignatures(the_data)
        sig0 = UTisocontour.getSignatureFunctions(the_data, 0, 0)
        sig1 = UTisocontour.getSignatureFunctions(the_data, 1, 0)
        sig2 = UTisocontour.getSignatureFunctions(the_data, 2, 0)
        print(sig0.name, sig0.nval)
        print(sig1.name, sig1.nval)
        print(sig2.name, sig2.nval)

        print("signatureValues:", UTisocontour.getSignatureValues(the_data, 0, 0, 0.23))
        datainfo = UTisocontour.getDatasetInfo(the_data)
        orig=datainfo._orig()
        span=datainfo._span()
        print("orig: ", orig)
        print("span: ", span)
Example #11
0
    def select(self, keyAts, checkAts, cutoff=3.0, percentCutoff=1.0, 
                keyMat=None, checkMat=None):
        """ keyAts, checkAts, cutoff, percentCutoff
            keyAts: first set of atoms
            checkAts: a second set of atoms which is checked vs. keyAts
            cutoff: 
                either a single float by default 3.0 
                or a matrix with shape:
            (max(len(keyAts),len(checkAts)), min(len(keyAts),len(checkAts)))
            percentCutoff: by default 1.0 (cutoff is multiplied by this value)
            keyMat: transformation of keyAts
            checkMat: transformation of checkAts

        returns 'pairDict' whose keys are atoms used as reference points and whose 
        values are atoms within cutoff distance of corresponding key. 

        If 'return_dist' flag is set, 
        'distDict' is returned also, whose keys are 
        the same atoms which are used as reference points and whose values are 
        lists of distances to atoms  within cutoff distance of corresponding key

        """
        lenK = len(keyAts)
        lenC = len(checkAts)

        #data arrays are used to find atoms with given indices quickly
        atar = Numeric.array(checkAts.data)
        keyAtar = Numeric.array(keyAts.data)

        #basic arrays of coords used to build others
        c = Numeric.array(checkAts.coords, 'f')
        if checkMat:
            c = self.mul(c, checkMat)
        k = Numeric.array(keyAts.coords, 'f')
        if keyMat:
            k = self.mul(k, keyMat)

        # first build matrix of distances between all pairs of ats
        # rows correspond to ats in larger set, columns to those in smaller
        # first build square matrix
        if lenC >= lenK:
            bigC = Numeric.resize(c, (lenC, lenC, 3))
            k.shape = (lenK,1,3)
            bigM = bigC[:lenK]
            smallM = k

            cutoff = self.setupCutoff(checkAts, keyAts, cutoff)
            #print "0a:cutoff[0][0]=", cutoff[0][0]
            cutoff.shape = (lenK, -1)

        else:
            bigK = Numeric.resize(k, (lenK, lenK, 3))
            c.shape = (lenC,1,3)
            bigM = bigK[:lenC]
            smallM = c
            cutoff = self.setupCutoff(keyAts, checkAts, cutoff)
            #print "0b:cutoff[0][0]=", cutoff[0][0]
            cutoff.shape = (lenC, -1)

        # distance matrix
        d = bigM - smallM
        # distance squared matrix
        dSQ = d * d
        # next step sums deltaX**2, deltaY**2, deltaZ**2
        dSQMAT = Numeric.sum(dSQ,2)

        #percentCutoff lets user relax sum of radii
        #the smaller the percentCutoff the smaller the key 
        #dSQ has to be less than
        cutoff = cutoff * percentCutoff
        cutoffSQMAT = cutoff * cutoff
        #cutoffSQMAT = cutoffSQMAT * percentCutoff

        # ansMat has 1 where sq dist. is smaller than cutoff
        ansMat = Numeric.logical_and(self.func(dSQMAT, cutoffSQMAT) , \
                    Numeric.not_equal(dSQMAT, 0.))
        if lenK > lenC:
            # in this case need to rearrange matrix
            # which got shuffled in if-else above
            ansMat = Numeric.swapaxes(ansMat, 0, 1)
            dSQMAT = Numeric.swapaxes(dSQMAT, 0, 1)

        # finally, build result dictionaries which have atom keys:
        #   pairDict has values which are lists of close atoms
        #   distDict has values which are lists of distances
        pairDict = {}
        distDict = {}
        # get a list of rows which have non-zero entries 
        # to loop over in next section
        rowIndices = Numeric.nonzero(Numeric.sum(ansMat,1))
        # rows correspond to ats in keyAts
        # columns correspond to ats in checkAts
        for i in rowIndices:
            # atindex is a list [7 8 9] indexing into checkAts 
            atindex = Numeric.nonzero(ansMat[i])
            # keyAtar[i] is ith atom in keyAts
            keyAt = keyAtar[i]
            pairDict[keyAt] = Numeric.take(atar, atindex)
            if self.return_dist:
                distDict[keyAt] = []
                for ind in atindex:
                    distDict[keyAt].append(math.sqrt(dSQMAT[i][ind]))
        
        #getting distDict back is optional
        if self.return_dist: return pairDict, distDict
        else: return pairDict
Example #12
0
    print "rw_w shown"
    sleep(3)


    rw_half_w = PixelMap2D(Numeric.array(r[:])[:], maxi=5000.)
    rw_half_w.show_image()
    print "rw_half_w shown"
    sleep(3)

    from DejaVu.colorTool import RedWhiteBlueRamp
    rwb_w = PixelMap2D(r[:], ramp=RedWhiteBlueRamp())
    rwb_w.show_image()
    print "rwb_w shown"
    sleep(3)

    s_r = Numeric.array(Numeric.swapaxes(r[:],0,1))
    s_r.shape = (100,100)
    s_r_w = PixelMap2D(s_r, ramp=RedWhiteBlueRamp())
    s_r_w.show_image()
    print "s_r_w shown"
    sleep(3)

    
    rwb_half_w = PixelMap2D(Numeric.array(r[:])[:], maxi=5000., ramp=RedWhiteBlueRamp())
    rwb_half_w.show_image()
    print "rwb_half_w shown"
    sleep(3)


## this example depends on finding data in working_directory_file 'ligand_results.py'
## stored as a dictionary 'ligand_results'
Example #13
0
    rw_w.show_image()
    print "rw_w shown"
    sleep(3)

    rw_half_w = PixelMap2D(Numeric.array(r[:])[:], maxi=5000.)
    rw_half_w.show_image()
    print "rw_half_w shown"
    sleep(3)

    from DejaVu.colorTool import RedWhiteBlueRamp
    rwb_w = PixelMap2D(r[:], ramp=RedWhiteBlueRamp())
    rwb_w.show_image()
    print "rwb_w shown"
    sleep(3)

    s_r = Numeric.array(Numeric.swapaxes(r[:], 0, 1))
    s_r.shape = (100, 100)
    s_r_w = PixelMap2D(s_r, ramp=RedWhiteBlueRamp())
    s_r_w.show_image()
    print "s_r_w shown"
    sleep(3)

    rwb_half_w = PixelMap2D(Numeric.array(r[:])[:],
                            maxi=5000.,
                            ramp=RedWhiteBlueRamp())
    rwb_half_w.show_image()
    print "rwb_half_w shown"
    sleep(3)

## this example depends on finding data in working_directory_file 'ligand_results.py'
## stored as a dictionary 'ligand_results'