1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#A* -------------------------------------------------------------------
#B* This file contains source code for the PyMOL computer program
#C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific.
#D* -------------------------------------------------------------------
#E* It is unlawful to modify or remove this copyright notice.
#F* -------------------------------------------------------------------
#G* Please see the accompanying LICENSE file for further information.
#H* -------------------------------------------------------------------
#I* Additional authors of this source file include:
#-*
#-*
#-*
#Z* -------------------------------------------------------------------
import copy
class Neighbor:
def __init__(self,vect_list,spacing):
self.voxel = {}
self.neighbor = None
self.spacing = spacing
c = 0
voxel = self.voxel
for v in vect_list:
k = self.address(v)
if k not in voxel:
voxel[k] = [c]
else:
voxel[k].append(c)
c = c + 1
def optimize(self):
self.neighbor = {}
voxel = self.voxel
for k in voxel.keys():
lst = self.neighbor[k]
for a in (k[0]-1,k[0],k[0]+1):
for b in (k[1]-1,k[1],k[1]+1):
for c in (k[2]-1,k[2],k[2]+1):
k2 = (a,b,c)
if k2 in voxel:
lst.extend(voxel[k2])
def address(self,vect):
return (int(vect[0]/self.spacing),
int(vect[1]/self.spacing),
int(vect[2]/self.spacing))
def get_voxel(self,vect):
k = self.address(vect)
if k in self.voxel:
return self.voxel[k]
else:
return []
def get_neighbors(self,vect):
if self.neighbor:
k = self.address(vect)
if k in self.neighbor:
return self.neighbor[k]
else:
return []
else:
voxel = self.voxel
k = self.address(vect)
lst = []
for a in (k[0]-1,k[0],k[0]+1):
for b in (k[1]-1,k[1],k[1]+1):
for c in (k[2]-1,k[2],k[2]+1):
k2 = (a,b,c)
if k2 in voxel:
lst.extend(voxel[k2])
return lst
|