optimize a number of functions

- Major optimization of the put_atom_in_box() function.
- Major optimization of the protein_precheck() function.
- Minor optimization in radial_volume_desolvation()
- Optimization in top_up() to scale for large structures.
This commit is contained in:
Matvey Adzhigirey
2012-12-04 17:21:24 -08:00
committed by Mike Beachy
parent e0ed5da44b
commit 73c7a2a4be
5 changed files with 24 additions and 28 deletions

View File

@@ -370,7 +370,7 @@ class bondmaker:
for x in range(self.no_box_x):
for y in range(self.no_box_y):
for z in range(self.no_box_z):
self.boxes[self.box_key(x,y,z)] = []
self.boxes[(x,y,z)] = []
# put atoms into boxes
for atom in atoms:
@@ -380,10 +380,8 @@ class bondmaker:
self.put_atom_in_box(x,y,z,atom)
# assign bonds
keys = self.boxes.keys()
for key in keys:
self.find_bonds_for_atoms(self.boxes[key])
for key, value in self.boxes.items():
self.find_bonds_for_atoms(value)
return
@@ -391,21 +389,21 @@ class bondmaker:
def put_atom_in_box(self,x,y,z,atom):
# atom in the x,y,z box and the up to 7 neighboring boxes on
# one side of the x,y,z box in each dimension
for bx in [x,x+1]:
for by in [y,y+1]:
for bz in [z,z+1]:
key = self.box_key(bx,by,bz)
if key in self.boxes.keys():
key = (bx,by,bz)
try:
self.boxes[key].append(atom)
except KeyError:
# No box exists for this coordinate
pass
#print(atom,'->',key,':',len(self.boxes[key]))
return
def box_key(self, x, y, z):
return '%d-%d-%d'%(x,y,z)
def has_bond(self, atom1, atom2):
if atom1 in atom2.bonded_atoms or atom2 in atom1.bonded_atoms:
return True