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)
def BuildShapes(self): self.FDockRuns[self.FCurrentDock].Target.Coords = molutils.ListCoords(self.FTarget) self.FDockRuns[self.FCurrentDock].Probe.Coords = molutils.ListCoords(self.FProbe) self.FDockRuns[self.FCurrentDock].Target.Rads = geomutils.Add(molutils.ListRadii(self.FTarget), self.FDockRuns[self.FCurrentDock].AddedRadius) self.FDockRuns[self.FCurrentDock].Probe.Rads = geomutils.Add(molutils.ListRadii(self.FProbe), self.FDockRuns[self.FCurrentDock].AddedRadius)
def Transform(self, Center, Rotation=None, Translation=None): if Rotation is not None: if Translation is not None: # Fifth method ats = self.AllAtoms() for f in range(len(ats)): ats[f].FCoord = geomutils.Subtract(ats[f].FCoord, Center) ats[f].FCoord = geomutils.Rotate(ats[f].FCoord, Rotation) ats[f].FCoord = geomutils.Add(ats[f].FCoord, Translation) else: # Fourth method ats = self.AllAtoms() for f in range(len(ats)): ats[f].FCoord = geomutils.Add(ats[f].FCoord, Center) ats[f].FCoord = geomutils.Rotate(ats[f].FCoord, Rotation) else: if isinstance(Center, geomutils.TRotMatrix): # Second method ats = self.AllAtoms() for f in range(len(ats)): ats[f].FCoord = geomutils.Rotate(ats[f].FCoord, Center) elif isinstance(Center, geomutils.TQuaternion): # Third method ats = self.AllAtoms() for f in range(len(ats)): ats[f].FCoord = geomutils.Rotate(ats[f].FCoord, Center) else: # First method ats = self.AllAtoms() for f in range(len(ats)): ats[f].FCoord = geomutils.Add(ats[f].FCoord, Center)
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 BiggerTest(): target = FMolecules.LoadLayer('../PDB/3f6u.pdb') probe = FMolecules.LoadLayer('../PDB/4a0q.pdb') startTick = basetypes.GetTickCount() target.Transform(geomutils.Simmetric(molutils.FindCenter(target))) probe.Transform(geomutils.Simmetric(molutils.FindCenter(probe))) targetrads = geomutils.Add(molutils.ListRadii(target), 1.4) targetcoords = molutils.ListCoords(target) proberads = geomutils.Add(molutils.ListRadii(probe), 1.4) probecoords = molutils.ListCoords(probe) models = bogie.TModelManager(100, 300, []) models.GridScale = 1 targetgrid = linegrids.TDockingGrid(1) targetgrid.BuildFromSpheres(targetcoords, targetrads) domain = None tick1 = 0 MaxIters = 1 for f in range(1, MaxIters + 1): tick1 = basetypes.GetTickCount() probegrid = linegrids.TDockingGrid(1) probegrid.BuildFromSpheres(probecoords, proberads) domain = dockdomains.TDockDomain(targetgrid, probegrid, 0) domain.MinimumOverlap = models.FMinOverlap domain.AssignModelManager(models.AddModel) domain.RemoveCores = True domain.BuildInitialDomain() domain.Score() print( str(models.FModels[0].OverlapScore) + ' (' + str(models.FModels[0].TransVec[0]) + ',' + str(models.FModels[0].TransVec[1]) + ',' + str(models.FModels[0].TransVec[2]) + ')') tick2 = basetypes.GetTickCount() domain.CalcDomainStats() print((tick2 - tick1) / 1000) print(str(domain.FDomainGrid.Shape.TotalCount) + ' cells') print(str(len(targetcoords)) + ' atoms') for f in range(len(models.FModels)): print( str(models.FModels[f].OverlapScore) + ' (' + str(models.FModels[f].TransVec[0]) + ', ' + str(models.FModels[f].TransVec[1]) + ', ' + str(models.FModels[f].TransVec[2]) + ')') endTick = basetypes.GetTickCount() print('Execution time: ' + str((endTick - startTick) / 1000) + ' seconds')
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 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)
def AddModel(self, Score, X, Y, Z): if Score > self.FMinOverlap: ix1 = 0 while self.FModels[ix1].OverlapScore >= Score: ix1 = ix1 + 1 # This must stop if Score>FMinOverlap if self.FLastModel < len(self.FModels) - 1: self.FLastModel = self.FLastModel + 1 ix2 = self.FLastModel while ix2 > ix1: self.FModels[ix2].OverlapScore = self.FModels[ix2 - 1].OverlapScore self.FModels[ix2].TransVec = self.FModels[ix2 - 1].TransVec self.FModels[ix2].Rotation = self.FModels[ix2 - 1].Rotation ix2 = ix2 - 1 self.FModels[ix1].OverlapScore = Score self.FModels[ix1].TransVec = geomutils.Add( self.ProbeGridTransVec, basetypes.TCoord(X * self.GridScale, Y * self.GridScale, Z * self.GridScale)) self.FModels[ix1].Rotation = self.CurrentRotation if self.FLastModel == len(self.FModels) - 1: self.FMinOverlap = self.FModels[self.FLastModel].OverlapScore # Return Integer return self.FMinOverlap
def __init__(self, Points, GridStep, Rads=None): assert Points is not None, 'Empty points array for hashing' assert GridStep > 1e-6, 'GridStep too small' self.FShiftToGrid = basetypes.TCoord() self.FPoints = [] self.FRads = [] self.FHashGrid = [] self.FHighX = 0 self.FHighY = 0 self.FHighZ = 0 self.FInvGridStep = 1 / GridStep self.Setup(Points, GridStep, Rads) self.FHashGrid = [] for x in range(self.FHighX + 1): self.FHashGrid.append([]) for y in range(self.FHighY + 1): self.FHashGrid[x].append([]) for z in range(self.FHighZ + 1): self.FHashGrid[x][y].append([]) for f in range(len(Points)): c = geomutils.Add(Points[f], self.FShiftToGrid) x = math.trunc(c[0] * self.FInvGridStep) y = math.trunc(c[1] * self.FInvGridStep) z = math.trunc(c[2] * self.FInvGridStep) self.FHashGrid[x][y][z].append(f)
def SRSurface(Points, Radii, SpherePoints, MinHashCell=0): Result = [] if Points is None: # Return TFloats return Result else: hashcell = LargestRadius(Radii) * 2 if hashcell < MinHashCell: hashcell = MinHashCell ghash = geomhash.TGeomHasher(Points, hashcell) for f in range(len(Points)): ixs = ghash.ListNeighbours(Points[f]) countouts = 0 for g in range(len(SpherePoints)): sphere = geomutils.Add( geomutils.Scaled(SpherePoints[g], Radii[f]), Points[f]) intersect = False for h in range(len(ixs)): if (ixs[h] is not f) and (geomutils.Distance( sphere, Points[ixs[h]]) < Radii[ixs[h]]): intersect = True break if not intersect: countouts = countouts + 1 Result.append(4 * geomutils.PI * (Radii[f])**2 / len(SpherePoints) * countouts) # Return TFloats return Result
def FirstTranslation(self, InitialPoint): FF = basetypes.TCoord() for f in range(len(self.FFixed)): FF = geomutils.Add(FF, self.FFixed[f]) if len(self.FFixed) > 0: FF = geomutils.Multiply(FF, 1 / len(self.FFixed)) for f in range(3): InitialPoint[f + 3] = FF[f]
def Center(self): self.FCenterVec = basetypes.TCoord() for f in range(len(self.FMobile)): self.FCenterVec = geomutils.Add(self.FCenterVec, self.FMobile[f]) if len(self.FMobile) > 0: self.FCenterVec = geomutils.Multiply(self.FCenterVec, 1 / len(self.FMobile)) for f in range(len(self.FMobile)): self.FMobile[f] = geomutils.Subtract(self.FMobile[f], self.FCenterVec)
def AddTest(): c = basetypes.TCoord(1, 2, 3) c = geomutils.Add(c, 2) print(str(c[0]) + ' ' + str(c[1]) + ' ' + str(c[2])) c = basetypes.TCoord(1, 2, 3) c2 = basetypes.TCoord(2, 3, 4) c = geomutils.Add(c, c2) print(str(c[0]) + ' ' + str(c[1]) + ' ' + str(c[2])) print('') ca = [] c = basetypes.TCoord(3, 8, 1) ca.append(c) c = basetypes.TCoord(6, 4, 6) ca.append(c) c = basetypes.TCoord(0, 2, 5) ca.append(c) c = basetypes.TCoord(5, 1, 3) ca = geomutils.Add(c, ca) for f in range(len(ca)): print(str(ca[f][0]) + ' ' + str(ca[f][1]) + ' ' + str(ca[f][2])) print('') fa = [3.0, 6.0, 4.0] fa = geomutils.Add(fa, 2) for f in range(len(fa)): print(str(fa[f])) print('') ca = [] c = basetypes.TCoord(3, 8, 1) ca.append(c) c = basetypes.TCoord(6, 4, 6) ca.append(c) c = basetypes.TCoord(0, 2, 5) ca.append(c) fa = [3, 6, 4] ca = geomutils.Add(ca, fa) for f in range(len(ca)): print(str(ca[f][0]) + ' ' + str(ca[f][1]) + ' ' + str(ca[f][2]))
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)
def ListNeighbours(self, C): C = geomutils.Multiply(geomutils.Add(C, self.FShiftToGrid), self.FInvGridStep) Result = [] x1, x2 = self.GridBounds(C[0], self.FHighX) y1, y2 = self.GridBounds(C[1], self.FHighY) z1, z2 = self.GridBounds(C[2], self.FHighZ) for x in range(x1, x2 + 1): for y in range(y1, y2 + 1): for z in range(z1, z2 + 1): for f in range(len(self.FHashGrid[x][y][z])): Result.append(self.FHashGrid[x][y][z][f]) # Return TIntegers return Result
def PlaneConstraint(self, Point, Normal, Margin): # Scaling factors for the shapes tres = 1 / self.FTargetResolution pres = 1 / self.FProbeResolution # Plane and line variables planepoint = geomutils.Subtract( geomutils.Add(Point, geomutils.Multiply(self.FTargetTransVec, tres)), geomutils.Multiply(self.FProbeTransVec, pres)) planepoint = geomutils.Subtract( planepoint, basetypes.TCoord(self.FDomainBlock.XOffset, self.FDomainBlock.YOffset, self.FDomainBlock.ZOffset)) xflags = basetypes.FilledInts(self.FDomainBlock.DomainEndX + 1, -1) yflags = basetypes.FilledInts(self.FDomainBlock.DomainEndY + 1, -1) zflags = basetypes.FilledInts(self.FDomainBlock.DomainEndZ + 1, -1) for x in range(len(self.FXDomain)): for xx in range(self.FXDomain[x][0], self.FXDomain[x][1] + 1): self.SetYDomain(xx, yflags, zflags, planepoint, Normal, Margin) if self.FYDomainAtX[xx] is not None and (len( self.FYDomainAtX[xx]) != 0): xflags[xx] = 1 self.FXDomain = linegrids.IntegersToLine(xflags)
def IsInnerPoint(self, C): tmpc = geomutils.Multiply(geomutils.Add(C, self.FShiftToGrid), self.FInvGridStep) Result = False x1, x2 = self.GridBounds(tmpc[0], self.FHighX) y1, y2 = self.GridBounds(tmpc[1], self.FHighY) z1, z2 = self.GridBounds(tmpc[2], self.FHighZ) for x in range(x1, x2 + 1): for y in range(y1, y2 + 1): for z in range(z1, z2 + 1): for f in range(len(self.FHashGrid[x][y][z])): ix = self.FHashGrid[x][y][z][f] if geomutils.Distance( C, self.FPoints[ix]) < self.FRads[ix]: Result = True break if Result: break if Result: break if Result: break # Return Boolean return Result
def threadBigger(): startTick = basetypes.GetTickCount() loadFileButton1.disable() loadFileButton2.disable() target.Transform(geomutils.Simmetric(molutils.FindCenter(target))) probe.Transform(geomutils.Simmetric(molutils.FindCenter(probe))) targetrads = geomutils.Add(molutils.ListRadii(target), 1.4) targetcoords = molutils.ListCoords(target) proberads = geomutils.Add(molutils.ListRadii(probe), 1.4) probecoords = molutils.ListCoords(probe) textBiggerButton.value = 'Building grids...' models = bogie.TModelManager(100, 300, []) models.GridScale = 1 targetgrid = linegrids.TDockingGrid(1) targetgrid.BuildFromSpheres(targetcoords, targetrads) domain = None tick1 = 0 MaxIters = 1 for f in range(1, MaxIters + 1): tick1 = basetypes.GetTickCount() probegrid = linegrids.TDockingGrid(1) probegrid.BuildFromSpheres(probecoords, proberads) textBiggerButton.value = 'Building domain...' domain = dockdomains.TDockDomain(targetgrid, probegrid, 0) domain.MinimumOverlap = models.FMinOverlap domain.AssignModelManager(models.AddModel) domain.RemoveCores = True domain.BuildInitialDomain() textBiggerButton.value = 'Getting score...' domain.Score() print( str(models.FModels[0].OverlapScore) + ' (' + str(models.FModels[0].TransVec[0]) + ',' + str(models.FModels[0].TransVec[1]) + ',' + str(models.FModels[0].TransVec[2]) + ')') tick2 = basetypes.GetTickCount() domain.CalcDomainStats() print((tick2 - tick1) / 1000) print(str(domain.FDomainGrid.Shape.TotalCount) + ' cells') print(str(len(targetcoords)) + ' atoms') for f in range(len(models.FModels)): print( str(models.FModels[f].OverlapScore) + ' (' + str(models.FModels[f].TransVec[0]) + ', ' + str(models.FModels[f].TransVec[1]) + ', ' + str(models.FModels[f].TransVec[2]) + ')') endTick = basetypes.GetTickCount() textBiggerButton.text_color = 'green' textBiggerButton.value = 'Score: ' + str(models.FModels[0].OverlapScore) textCoordsBiggerButton.value = 'Coordinates: ' + str(models.FModels[0].TransVec[0]) + ', ' + \ str(models.FModels[0].TransVec[1]) + ', ' + str(models.FModels[0].TransVec[2]) textTimeBiggerButton.value = 'Execution time: ' + str( (endTick - startTick) / 1000) + ' seconds' loadFileButton1.enable() loadFileButton2.enable()
def Shear(self): Result = basetypes.TCoord() for f in range(len(self.FFixed)): Result = geomutils.Add(self.FDerivs[f], Result) # Return TCoord return Result