def EuclideanDistanceConstraint(self, ATargetPoints, AProbePoints, Dist):
        tres = 1 / self.FTargetResolution
        pres = 1 / self.FProbeResolution
        targetpoints = geomutils.Multiply(
            geomutils.Add(self.FTargetTransVec, ATargetPoints), tres)
        probepoints = geomutils.Add(
            basetypes.TCoord(self.FDomainBlock.XOffset,
                             self.FDomainBlock.YOffset,
                             self.FDomainBlock.ZOffset),
            geomutils.Multiply(
                geomutils.Add(self.FProbeTransVec, AProbePoints), pres))
        mit = basetypes.Min(targetpoints)
        mat = basetypes.Max(targetpoints)
        mip = basetypes.Min(probepoints)
        map = basetypes.Max(probepoints)
        griddist = Dist / self.FTargetResolution
        distsquare = griddist**2

        lx1 = round(mit[0] - map[0] - 0.5 - griddist)
        lx2 = round(mat[0] - mip[0] + 0.5 + griddist)
        linegrids.Intersect(self.FXDomain, lx1, lx2)
        # Clear FYDomainAtX outside FXDomain
        oldix = 0
        for x in range(len(self.FXDomain)):
            for xx in range(oldix, self.FXDomain[x][0]):
                self.FYDomainAtX[xx] = []
            oldix = self.FXDomain[x][1] + 1
        for xx in range(oldix, len(self.FYDomainAtX)):
            self.FYDomainAtX[xx] = []

        # Set FYDomainAtX
        for x in range(len(self.FXDomain)):
            for xx in range(self.FXDomain[x][0], self.FXDomain[x][1] + 1):
                ly1, ly2 = self.SetYLimits(xx, targetpoints, probepoints,
                                           griddist, distsquare)
                linegrids.Intersect(self.FYDomainAtX[xx], ly1, ly2)

                # Clear FZDomainAtXY outside FYDomainAtX
                oldix = 0
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(oldix, self.FYDomainAtX[xx][y][0]):
                        self.FZDomainAtXY[xx][yy] = []
                    oldix = self.FYDomainAtX[xx][y][1] + 1
                for yy in range(oldix, len(self.FZDomainAtXY[xx])):
                    self.FZDomainAtXY[xx][yy] = []

                # Set FZDomainAtXY
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(self.FYDomainAtX[xx][y][0],
                                    self.FYDomainAtX[xx][y][1]):
                        lz1, lz2 = self.SetZLimits(xx, yy, targetpoints,
                                                   probepoints, griddist,
                                                   distsquare)
                        linegrids.Intersect(self.FZDomainAtXY[xx][yy], lz1,
                                            lz2)
    def LinearDistanceConstraint(self, ATargetPoints, AProbePoints, Dist):
        targetpoints = geomutils.Add(self.FTargetTransVec, ATargetPoints)
        probepoints = geomutils.Add(self.FProbeTransVec, AProbePoints)
        tres = 1 / self.FTargetResolution
        pres = 1 / self.FProbeResolution

        mit = geomutils.Multiply(basetypes.Min(targetpoints), tres)
        mat = geomutils.Multiply(basetypes.Max(targetpoints), tres)
        mip = geomutils.Multiply(basetypes.Min(probepoints), tres)
        map = geomutils.Multiply(basetypes.Max(probepoints), tres)
        d = Dist / self.FTargetResolution

        lx1 = round(mit[0] - map[0] - self.FDomainBlock.XOffset - 0.5 - d)
        lx2 = round(mat[0] - mip[0] - self.FDomainBlock.XOffset + 0.5 + d)
        ly1 = round(mit[1] - map[1] - self.FDomainBlock.YOffset - 0.5 - d)
        ly2 = round(mat[1] - mip[1] - self.FDomainBlock.YOffset + 0.5 + d)
        lz1 = round(mit[2] - map[2] - self.FDomainBlock.ZOffset - 0.5 - d)
        lz2 = round(mat[2] - mip[2] - self.FDomainBlock.ZOffset + 0.5 + d)
        linegrids.Intersect(self.FXDomain, lx1, lx2)

        # Clear FYDomainAtX outside FXDomain
        oldix = 0
        for x in range(len(self.FXDomain)):
            for xx in range(oldix, self.FXDomain[x][0]):
                self.FYDomainAtX[xx] = []
            oldix = self.FXDomain[x][1] + 1
        for xx in range(oldix, len(self.FYDomainAtX)):
            self.FYDomainAtX[xx] = []

        # Set FYDomainAtX
        for x in range(len(self.FXDomain)):
            for xx in range(self.FXDomain[x][0], self.FXDomain[x][1] + 1):
                linegrids.Intersect(self.FYDomainAtX[xx], ly1, ly2)
                # Clear FZDomainAtXY outside FYDomainAtX
                oldix = 0
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(oldix, self.FYDomainAtX[xx][y][0]):
                        self.FZDomainAtXY[xx][yy] = []
                    oldix = self.FYDomainAtX[xx][y][1] + 1
                for yy in range(oldix, len(self.FYDomainAtX[xx])):
                    self.FZDomainAtXY[xx][yy] = []

                # Set FZDomainAtXY
                for y in range(len(self.FYDomainAtX[xx])):
                    for yy in range(self.FYDomainAtX[xx][y][0],
                                    self.FYDomainAtX[xx][y][1] + 1):
                        linegrids.Intersect(self.FZDomainAtXY[xx][yy], lz1,
                                            lz2)
Exemple #3
0
 def InPlaceIntersect(self, Line1, Line2, Displace):
     self.FIntersectHigh = -1
     if (Line1 is not None) and (len(Line1) != 0) and (
             Line2 is not None) and (len(Line2) != 0):
         ll1 = len(Line1) + len(Line2)
         if len(self.FIntersect) < ll1:
             for f in range(len(self.FIntersect), ll1):
                 if f >= len(self.FIntersect):
                     self.FIntersect.append(linegrids.TLineSegment())
         i1 = 0
         i2 = 0
         ll1 = len(Line1)
         ll2 = len(Line2)
         while (i1 < ll1) and (i2 < ll2):
             top = basetypes.Min(Line1[i1][1] + Displace, Line2[i2][1])
             bot = basetypes.Max(Line1[i1][0] + Displace, Line2[i2][0])
             if top >= bot:
                 self.FIntersectHigh = self.FIntersectHigh + 1
                 self.FIntersect[self.FIntersectHigh][0] = bot
                 self.FIntersect[self.FIntersectHigh][1] = top
             if Line1[i1][1] + Displace >= Line2[i2][1]:
                 ni2 = i2 + 1
             else:
                 ni2 = i2
             if Line1[i1][1] + Displace <= Line2[i2][1]:
                 ni1 = i1 + 1
             else:
                 ni1 = i1
             i1 = ni1
             i2 = ni2
Exemple #4
0
    def BuildBaseGrid(self):
        # Adjust coordinates
        maxrad = basetypes.Max(basetypes.Max(self.FRads), self.FResolution)
        # Translate and size guaranteeing one layer of empty grid cells
        self.FTransVec = basetypes.Min(self.FCoords)
        self.FTransVec = geomutils.Add(geomutils.Simmetric(self.FTransVec),
                                       maxrad + self.FResolution)
        self.FCoords = geomutils.Add(self.FTransVec, self.FCoords)
        top = geomutils.Add(basetypes.Max(self.FCoords),
                            maxrad + 1.5 * self.FResolution)
        self.FBase.Grid = []
        for f in range(round(top[0] / self.FResolution)):
            self.FBase.Grid.append([])
            for g in range(round(top[1] / self.FResolution)):
                self.FBase.Grid[f].append([])

        zline = []
        for f in range(round(top[2] / self.FResolution)):
            zline.append(0)
        self.FBase.ZMax = len(zline) - 1
        hash = geomhash.TGeomHasher(self.FCoords, maxrad, self.FRads)
        halfres = 0.5 * self.FResolution
        xyzpoint = basetypes.TCoord()
        for x in range(len(self.FBase.Grid)):
            xyzpoint[0] = x * self.FResolution + halfres
            for y in range(len(self.FBase.Grid[x])):
                xyzpoint[1] = y * self.FResolution + halfres
                for z in range(len(zline)):
                    xyzpoint[2] = z * self.FResolution + halfres
                    if hash.IsInnerPoint(xyzpoint):
                        zline[z] = 1
                    else:
                        zline[z] = 0
                    self.FBase.Grid[x][y] = IntegersToLine(zline)
Exemple #5
0
def ScoreSequencePair(Seq1,
                      Seq2,
                      SubMat,
                      SubGapMarker=DefaultSubstitutionGapMarker):
    Result = 0
    if isinstance(Seq1[0], sequence.TOCCompressedSequenceRec):
        assert Seq1[len(Seq1) - 1].Last is Seq2[len(Seq2) - 1].Last, 'Error in scoring sequence pair: sequences must' \
                                                                     'have equal lengths'
        ix1 = 0
        ix2 = 0
        while ix1 < len(Seq1):
            st = basetypes.Max(Seq1[ix1].First, Seq2[ix2].First)
            en = basetypes.Min(Seq1[ix1].Last, Seq2[ix2].Last) + 1
            tmp = GetSubScore(SubMat, Seq1[ix1].Symbol, Seq2[ix2].Symbol,
                              SubGapMarker) * (en - st)
            Result = Result + tmp
            if en > Seq1[ix1].Last:
                ix1 = ix1 + 1
            if en > Seq2[ix2].Last:
                ix2 = ix2 + 1
    else:
        assert len(Seq1) == len(
            Seq2
        ), 'Error in scoring sequence pair: sequences must have equal lengths'
        for f in range(len(Seq1)):
            Result = Result + GetSubScore(SubMat, Seq1[f], Seq2[f],
                                          SubGapMarker)
    # Return TFloat
    return Result
Exemple #6
0
def CountCellsBetween(Line, MinZ, MaxZ):
    Result = 0
    for z in range(len(Line)):
        if (Line[z][0] <= MaxZ) and (Line[z][1] >= MinZ):
            Result = Result + basetypes.Min(MaxZ, Line[z][1]) - basetypes.Max(
                Line[z][0], MinZ) + 1
    # Return Integer
    return Result
Exemple #7
0
def Intersect(Line, NewMin, NewMax=None):
    if isinstance(NewMin, list):
        # First function
        Line1 = Line
        Line2 = NewMin
        Result = []
        i1 = 0
        i2 = 0
        ll1 = len(Line1)
        ll2 = len(Line2)
        while (i1 < ll1) and (i2 < ll2):
            top = basetypes.Min(Line1[i1][1], Line2[i2][1])
            bot = basetypes.Max(Line1[i1][0], Line2[i2][0])
            if top >= bot:
                Result.append(TLineSegment(bot, top))
            if Line1[i1][1] >= Line2[i2][1]:
                ni2 = i2 + 1
            else:
                ni2 = i2
            if Line[i1][1] <= Line2[i2][1]:
                ni1 = i1 + 1
            else:
                ni1 = i1
            i1 = ni1
            i2 = ni2
        # Return TGridLine
        return Result
    else:
        # Second function
        lastvalid = -1
        for f in range(len(Line)):
            # Line segment is inside new interval
            if (Line[f][1] > NewMin) and (Line[f][0] <= NewMax):
                Line[f][0] = basetypes.Max(NewMin, Line[f][0])
                Line[f][1] = basetypes.Min(NewMax, Line[f][1])
                lastvalid = lastvalid + 1
                if lastvalid < f:
                    Line[lastvalid] = Line[f]
        for f in range(len(Line) - 1, lastvalid, -1):
            del Line[f]
Exemple #8
0
    def AxisDistance(self, Axis1, Axis2):
        if Axis1 is Axis2:
            #Return TFloat
            return 0.0
        else:
            x, y = geomutils.OrthogonalCoords(self.FAxes[Axis1],
                                              self.FAxes[Axis2])
            dist = 0
            for g in range(len(self.FPoints)):
                a1x = self.FParaMatrix[Axis1][g]
                a1y = self.FOrtoMatrix[Axis2][g]

                # Points are parallel*(x,y)+- ortho*(y,-x)
                tmpa = self.FParaMatrix[Axis2][g] * x
                tmpb = self.FOrtoMatrix[Axis2][g] * y
                p1x = tmpa + tmpb
                p2x = tmpa - tmpb
                tmpa = self.FParaMatrix[Axis2][g] * y
                tmpb = -self.FOrtoMatrix[Axis2][g] * x
                p1y = tmpa + tmpb
                p2y = tmpa - tmpb

                sp1x = (p1x - a1x)**2
                sp2x = (p2x - a1x)**2

                dist1 = basetypes.Min(sp1x + (p1y - a1y)**2,
                                      sp2x + (p2y - a1y)**2)
                dist2 = basetypes.Min(sp1x + (p1y + a1y)**2,
                                      sp2x + (p2y + a1y)**2)
                dist = basetypes.Max(dist, basetypes.Max(dist1, dist2))

                dist1 = basetypes.Min(sp1x + (p1y - a1y)**2,
                                      sp1x + (p1y + a1y)**2)
                dist2 = basetypes.Min(sp2x + (p2y - a1y)**2,
                                      sp2x + (p2y + a1y)**2)
                dist = basetypes.Max(dist, basetypes.Max(dist1, dist2))
            # Return TFloat
            return math.sqrt(dist)
 def SetYLimits(self, XCoord, targetpoints, probepoints, griddist,
                distsquare):
     ly1 = self.FDomainBlock.DomainEndY
     ly2 = 0
     for f in range(len(targetpoints)):
         for g in range(len(probepoints)):
             dif = abs(probepoints[g][0] + XCoord - targetpoints[f][0])
             if dif <= griddist:
                 dy = math.sqrt(distsquare - (dif**2))
                 dif = targetpoints[f][1] - probepoints[g][1]
                 ly1 = basetypes.Min(ly1, round(dif - 0.5 - dy))
                 ly2 = basetypes.Max(ly2, round(dif + 0.5 + dy))
     # In Python return Integer, Integer
     return ly1, ly2
Exemple #10
0
 def GetLineLimits(self, Point, Direction):
     if self.FMaxs is not None:
         LMin = 1e-30
         LMax = -1e-30
         for f in range(len(self.FMaxs)):
             if abs(Direction[f]) > 1e-30:
                 LMin = basetypes.Min(LMin, (self.FMins[f] - Point[f]) /
                                      Direction[f])
                 LMax = basetypes.Max(LMax, (self.FMaxs[f] - Point[f]) /
                                      Direction[f])
         # In Python return TFloat, TFloat
         return LMin, LMax
     # In Python return TFloat, TFloat
     return 0, 0
Exemple #11
0
def CalcCenterHull(Atoms, Dist):
    if Atoms is None:
        # Return TCuboid
        return basetypes.TCuboid()
    else:
        c1 = Atoms[0].Coords
        c2 = c1
        for f in range(1, len(Atoms)):
            c1 = basetypes.Min(c1, Atoms[f].Coords)
            c2 = basetypes.Max(c2, Atoms[f].Coords)
        c1 = geomutils.Subtract(c1, Dist)
        c2 = geomutils.Add(c2, Dist)
        # Return TCuboid
        return basetypes.TCuboid(c1, c2)
Exemple #12
0
def CalcHull(Atoms, Rad):
    if Atoms is None:
        # Return TCuboid
        return basetypes.TCuboid()
    else:
        c1 = Atoms[0].Coords
        c2 = c1
        for f in range(1, len(Atoms)):
            c1 = basetypes.Min(c1, geomutils.Add(Atoms[f].Coords, -Atoms[f].Radius))
            c2 = basetypes.Max(c2, geomutils.Add(Atoms[f].Coords, Atoms[f].Radius))
        for f in range(3):
            c1[f] = c1[f] - Rad
            c2[f] = c2[f] + Rad
        # Return TCuboid
        return basetypes.TCuboid(c1, c2)
 def SetZLimits(self, XCoord, YCoord, targetpoints, probepoints, griddist,
                distsquare):
     lz1 = self.FDomainBlock.DomainEndZ
     lz2 = 0
     for f in range(len(targetpoints)):
         for g in range(len(probepoints)):
             dif = abs(probepoints[g][0] + XCoord - targetpoints[f][0])
             if dif <= griddist:
                 dif = (dif**2) - (probepoints[g][1] + YCoord -
                                   targetpoints[f][1])**2
                 if dif <= distsquare:
                     dz = math.sqrt(distsquare - dif)
                     dif = targetpoints[f][2] - probepoints[g][2]
                     lz1 = basetypes.Min(lz1, round(dif - 0.5 - dz))
                     lz2 = basetypes.Max(lz2, round(dif + 0.5 + dz))
     # In Python return Integer, Integer
     return lz1, lz2
Exemple #14
0
 def __init__(self, NumModels, MinOverlap, DockModels):
     self.FModels = []
     for f in range(NumModels):
         if f < len(DockModels):
             self.FModels.append(DockModels[f])
         else:
             self.FModels.append(
                 docktasks.TDockModel(basetypes.TCoord(),
                                      geomutils.IdentityQuaternion, -1))
     self.FLastModel = len(DockModels) - 1
     if self.FLastModel >= 0:
         self.FMinOverlap = basetypes.Min(
             self.FModels[self.FLastModel].OverlapScore, MinOverlap)
     else:
         self.FMinOverlap = MinOverlap
     self.CurrentRotation = geomutils.TQuaternion()
     self.GridScale = 0.0
     self.ProbeGridTransVec = basetypes.TCoord()
Exemple #15
0
def MinTest():
    fa = [4.3, 9.1, 5]
    tf = basetypes.Min(fa)
    print(str(tf))

    print('')
    ia = [4, 9, 5]
    f = basetypes.Min(ia)
    print(str(f))

    print('')
    ca = []
    c = basetypes.TCoord(3, 7, 4)
    ca.append(c)
    c = basetypes.TCoord(5, 1, 6)
    ca.append(c)
    c = basetypes.TCoord(2, 2, 9)
    ca.append(c)
    c = basetypes.Min(ca)
    print(str(c[0]) + ' ' + str(c[1]) + ' ' + str(c[2]))

    print('')
    m = [[5, 2, 7], [4, 1, 9], [3, 7, 3]]
    tf = basetypes.Min(m)
    print(str(tf))

    print('')
    f = 4
    i = 5
    f = basetypes.Min(f, i)
    print(str(f))

    print('')
    tf = 4.5
    tf2 = 5.1
    tf = basetypes.Min(tf, tf2)
    print(str(tf))

    print('')
    c = basetypes.TCoord(4, 5, 9)
    c2 = basetypes.TCoord(5, 7, 6)
    c = basetypes.Min(c, c2)
    print(str(c[0]) + ' ' + str(c[1]) + ' ' + str(c[2]))
Exemple #16
0
    def Setup(self, Points, GridStep, Rads):
        maxc = basetypes.Max(Points)
        minc = basetypes.Min(Points)
        self.FShiftToGrid = geomutils.Simmetric(minc)
        self.FHighX = math.trunc((maxc[0] - minc[0]) / GridStep)
        self.FHighY = math.trunc((maxc[1] - minc[1]) / GridStep)
        self.FHighZ = math.trunc((maxc[2] - minc[2]) / GridStep)

        if Rads is None:
            # Geomhasher used only for indexing regions
            self.FPoints = []
            self.FRads = []
        else:
            # Used to detect collisions, inner points, etc
            assert len(Points) == len(
                Rads), 'Different number of radii and points'
            self.FPoints = []
            self.FRads = []
            for f in range(len(Points)):
                self.FPoints.append(Points[f])
                self.FRads.append(Rads[f])
Exemple #17
0
 def AddResidueContacts(self, ContactFile, MaxContacts = 0):
     sl = []
     with open(ContactFile) as f:
         sl = f.read().splitlines()
     if MaxContacts == 0:
         MaxContacts = len(sl)
     else:
         MaxContacts = basetypes.Min(MaxContacts, len(sl))
     for f in range(MaxContacts):
         contact = stringutils.SplitString(sl[f], ' ')
         cset = TConstraintSet()
         cset.NumModels = int(contact[5])
         cset.MinOverlap = int(contact[6])
         cset.Name = sl[f]
         cdef = TConstraintDef()
         cdef.Name = 'Euclidean ' + contact[0] + contact[1] + ':' + contact[2] + contact[3]
         cdef.TargetPoints = molutils.ListCoords(self.FTarget.GetGroup(contact[0]).GetGroupById(int(contact[1])))
         cdef.ProbePoints = molutils.ListCoords(self.FProbe.GetGroup(contact[2]).GetGroupById(int(contact[3])))
         cdef.Distance = float(contact[4])
         cdef.ConstraintType = CEuclideanDistance
         cset.Constraints.append(cdef)
         self.FDockRuns[self.FCurrentDock].ConstraintSets.append(cset)
Exemple #18
0
 def SetDomainYLines(self):
     for f in range(self.FDomainGrid.Block.DomainEndX + 1):
         self.FDomainGrid.Shape.NonEmpty.append([])
         self.FCoreContacts.append([])
     xdomain = self.FConstraintManager.FXDomain
     for xx in range(len(xdomain)):
         for x in range(xdomain[xx][0], xdomain[xx][1]):
             self.CountX = self.CountX + 1
             limit1, limit2 = linegrids.GetLineExtremes(
                 self.FConstraintManager.YDomainAtX(x))
             if limit1 > limit2:
                 self.FDomainGrid.Shape.NonEmpty[x] = []
                 self.FCoreContacts[x] = []
             else:
                 pix1, pix2, tix1, tix2 = GetIndexes(
                     self.FDomainGrid.Block.ProbeEndX,
                     self.FDomainGrid.Block.TargetEndX,
                     self.FDomainGrid.Block.XOffset, x)
                 tmpmin = limit2 + 1
                 tmpmax = -1
                 coremin = limit2 + 1
                 coremax = -1
                 while tix1 <= tix2:
                     # Surface overlap Y range
                     if (self.FProbe.FSurf.NonEmpty[pix1] is not None) and (len(self.FProbe.FSurf.NonEmpty[pix1]) != 0) \
                             and (self.FTarget.FSurf.NonEmpty[tix1] is not None) and \
                             (len(self.FTarget.FSurf.NonEmpty[tix1]) != 0):
                         p1, p2 = linegrids.GetLineExtremes(
                             self.FProbe.FSurf.NonEmpty[pix1])
                         t1, t2 = linegrids.GetLineExtremes(
                             self.FTarget.FSurf.NonEmpty[tix1])
                         mi, ma = OverlapRegion(
                             p1, p2, t1, t2, self.FDomainGrid.Block.YOffset,
                             limit2)
                         tmpmin = basetypes.Min(mi, tmpmin)
                         tmpmax = basetypes.Max(ma, tmpmax)
                     # Core overlap Y range
                     if (self.FProbe.FCore.NonEmpty[pix1] is not None) and (len(self.FProbe.FCore.NonEmpty[pix1]) != 0) \
                             and (self.FTarget.FCore.NonEmpty[tix1] is not None) and \
                             (len(self.FTarget.FCore.NonEmpty[tix1]) != 0):
                         p1, p2 = linegrids.GetLineExtremes(
                             self.FProbe.FCore.NonEmpty[pix1])
                         t1, t2 = linegrids.GetLineExtremes(
                             self.FTarget.FCore.NonEmpty[tix1])
                         mi, ma = OverlapRegion(
                             p1, p2, t1, t2, self.FDomainGrid.Block.YOffset,
                             limit2)
                         coremin = basetypes.Min(mi, coremin)
                         coremax = basetypes.Max(ma, coremax)
                     tix1 = tix1 + 1
                     pix1 = pix1 + 1
                 tmpmin = basetypes.Max(limit1, tmpmin)
                 tmpmax = basetypes.Min(limit2, tmpmax)
                 coremin = basetypes.Max(limit1, coremin)
                 coremax = basetypes.Min(limit2, coremax)
                 if tmpmax < tmpmin:
                     self.FDomainGrid.Shape.NonEmpty[x] = []
                 else:
                     self.FDomainGrid.Shape.NonEmpty[x] = linegrids.NewLine(
                         tmpmin, tmpmax)
                 if coremax < coremin:
                     self.FCoreContacts[x] = None
                 else:
                     self.FCoreContacts[x] = linegrids.NewLine(
                         coremin, coremax)
Exemple #19
0
 def SetZExtremes(self, DomainX, DomainY):
     self.CountXY = self.CountXY + 1
     for z in range(len(self.FOverlapIxs)):
         self.FOverlapIxs[z] = 0
     limit1, limit2 = linegrids.GetLineExtremes(
         self.FConstraintManager.ZDomainAtXY(DomainX, DomainY))
     pix1, pix2, tix1, tix2 = GetIndexes(self.FDomainGrid.Block.ProbeEndX,
                                         self.FDomainGrid.Block.TargetEndX,
                                         self.FDomainGrid.Block.XOffset,
                                         DomainX)
     displace = DomainY + self.FDomainGrid.Block.YOffset
     overlap = 0
     while tix1 <= tix2:
         self.InPlaceIntersect(self.FProbe.FSurf.NonEmpty[pix1],
                               self.FTarget.FSurf.NonEmpty[tix1], displace)
         for y in range(self.FIntersectHigh + 1):
             for yy in range(self.FIntersect[y][0],
                             self.FIntersect[y][1] + 1):
                 overlap = overlap + basetypes.Min(
                     self.FProbe.FSurf.CellCounts[pix1][yy - displace],
                     self.FTarget.FSurf.CellCounts[tix1][yy])
                 p1, p2 = linegrids.GetLineExtremes(
                     self.FProbe.FSurf.Grid[pix1][yy - displace])
                 t1, t2 = linegrids.GetLineExtremes(
                     self.FTarget.FSurf.Grid[tix1][yy])
                 p1 = p1 - self.FDomainGrid.Block.ProbeEndZ
                 p2 = p2 - self.FDomainGrid.Block.ProbeEndZ
                 st = t1 - p2
                 en = t2 - p1
                 wid1 = p2 - p1
                 wid2 = t2 - t1
                 if wid1 > wid2:
                     z = wid1
                     wid1 = wid2
                     wid2 = z
                 wid1 = st + wid1
                 wid2 = st + wid2
                 self.FOverlapIxs[st] = self.FOverlapIxs[st] + 1
                 self.FOverlapIxs[wid1 + 1] = self.FOverlapIxs[wid1 + 1] - 1
                 self.FOverlapIxs[wid2 + 1] = self.FOverlapIxs[wid2 + 1] - 1
                 self.FOverlapIxs[en + 1] = self.FOverlapIxs[en + 1] + 1
         tix1 = tix1 + 1
         pix1 = pix1 + 1
     if overlap < self.MinimumOverlap:
         self.FDomainGrid.Shape.Grid[DomainX][DomainY] = []
     else:
         acc = 0
         dif = 0
         z = -1
         while (z < len(self.FOverlapIxs) - 1) and (acc <=
                                                    self.MinimumOverlap):
             z = z + 1
             dif = dif + self.FOverlapIxs[z]
             acc = acc + dif
         tmpmin = z
         z = len(self.FOverlapIxs)
         dif = 0
         acc = 0
         while (z > 0) and (acc <= self.MinimumOverlap) and (z > tmpmin):
             z = z - 1
             dif = dif + self.FOverlapIxs[z]
             acc = acc + dif
         tmpmax = z
         # Convert from grid to domain
         tmpmin = tmpmin + self.FDomainGrid.Block.ProbeEndZ + self.FDomainGrid.Block.ZOffset
         tmpmax = tmpmax + self.FDomainGrid.Block.ProbeEndZ + self.FDomainGrid.Block.ZOffset
         tmpmin = basetypes.Max(tmpmin, limit1)
         tmpmax = basetypes.Min(tmpmax, limit2)
         if tmpmin <= tmpmax:
             self.FDomainGrid.Shape.Grid[DomainX][
                 DomainY] = linegrids.NewLine(tmpmin, tmpmax)
         else:
             self.FDomainGrid.Shape.Grid[DomainX][DomainY] = []