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

@@ -7,7 +7,7 @@ import unittest
# Setting this up as a direct translation of the original runtest.py script # Setting this up as a direct translation of the original runtest.py script
# that will be run as part of 'python setup.py test'. This takes on the # that will be run as part of 'python setup.py test'. This takes on the
# order of 30s to run. # order of 10s to run.
class SystemTest(unittest.TestCase): class SystemTest(unittest.TestCase):
""" """

View File

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

View File

@@ -364,12 +364,11 @@ def radial_volume_desolvation(parameters, group):
# desolvation # desolvation
if sq_dist < parameters.desolv_cutoff_squared: if sq_dist < parameters.desolv_cutoff_squared:
# use a default relative volume of 1.0 if the volume of the element is not found in parameters # use a default relative volume of 1.0 if the volume of the element is not found in parameters
dv = 1.0
if atom.element in parameters.VanDerWaalsVolume.keys():
dv = parameters.VanDerWaalsVolume[atom.element]
# insert check for methyl groups # insert check for methyl groups
if atom.element == 'C' and atom.name not in ['CA','C']: if atom.element == 'C' and atom.name not in ['CA','C']:
dv = parameters.VanDerWaalsVolume['C4'] dv = parameters.VanDerWaalsVolume['C4']
else:
dv = parameters.VanDerWaalsVolume.get(atom.element, 1.0)
dv_inc = dv/max(min_distance_4th, sq_dist*sq_dist) dv_inc = dv/max(min_distance_4th, sq_dist*sq_dist)
# dv_inc = dv/(sq_dist*sq_dist) - dv/(parameters.desolv_cutoff_squared*parameters.desolv_cutoff_squared) # dv_inc = dv/(sq_dist*sq_dist) - dv/(parameters.desolv_cutoff_squared*parameters.desolv_cutoff_squared)

View File

@@ -390,19 +390,12 @@ class Conformation_container:
def top_up(self, other): def top_up(self, other):
""" Tops up self with all atoms found in other but not in self """ """ Tops up self with all atoms found in other but not in self """
my_residue_labels = { a.residue_label for a in self.atoms }
for atom in other.atoms: for atom in other.atoms:
if not self.have_atom(atom): if not atom.residue_label in my_residue_labels:
self.copy_atom(atom) self.copy_atom(atom)
return return
def have_atom(self, atom):
res = False
for a in self.atoms:
if a.residue_label == atom.residue_label:
res = True
break
return res
def find_group(self, group): def find_group(self, group):
for g in self.groups: for g in self.groups:
if g.atom.residue_label == group.atom.residue_label: if g.atom.residue_label == group.atom.residue_label:

View File

@@ -50,11 +50,17 @@ def protein_precheck(conformations, names):
for name in names: for name in names:
atoms = conformations[name].atoms atoms = conformations[name].atoms
res_ids = [] # Group the atoms by their residue:
[res_ids.append(resid_from_atom(a)) for a in atoms if not res_ids.count(resid_from_atom(a))] atoms_by_residue = {}
for a in atoms:
if a.element != 'H':
res_id = resid_from_atom(a)
try:
atoms_by_residue[res_id].append(a)
except KeyError:
atoms_by_residue[res_id] = [a]
for res_id in res_ids: for res_id, res_atoms in atoms_by_residue.items():
res_atoms = [a for a in atoms if resid_from_atom(a) == res_id and a.element != 'H']
resname = res_atoms[0].resName resname = res_atoms[0].resName
residue_label = '%3s%5s'%(resname, res_id) residue_label = '%3s%5s'%(resname, res_id)