diff --git a/Tests/pkacalc_test.py b/Tests/pkacalc_test.py index 04f896e..c82ce4f 100644 --- a/Tests/pkacalc_test.py +++ b/Tests/pkacalc_test.py @@ -7,7 +7,7 @@ import unittest # 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 -# order of 30s to run. +# order of 10s to run. class SystemTest(unittest.TestCase): """ diff --git a/propka/bonds.py b/propka/bonds.py index e199858..f475338 100644 --- a/propka/bonds.py +++ b/propka/bonds.py @@ -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 diff --git a/propka/calculations.py b/propka/calculations.py index 5f71f8e..88224ef 100644 --- a/propka/calculations.py +++ b/propka/calculations.py @@ -364,12 +364,11 @@ def radial_volume_desolvation(parameters, group): # desolvation 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 - dv = 1.0 - if atom.element in parameters.VanDerWaalsVolume.keys(): - dv = parameters.VanDerWaalsVolume[atom.element] # insert check for methyl groups if atom.element == 'C' and atom.name not in ['CA','C']: 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/(sq_dist*sq_dist) - dv/(parameters.desolv_cutoff_squared*parameters.desolv_cutoff_squared) diff --git a/propka/conformation_container.py b/propka/conformation_container.py index 76439d4..ab4f821 100644 --- a/propka/conformation_container.py +++ b/propka/conformation_container.py @@ -390,19 +390,12 @@ class Conformation_container: def top_up(self, other): """ 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: - if not self.have_atom(atom): + if not atom.residue_label in my_residue_labels: self.copy_atom(atom) 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): for g in self.groups: if g.atom.residue_label == group.atom.residue_label: diff --git a/propka/pdb.py b/propka/pdb.py index 9443b35..ebed33c 100644 --- a/propka/pdb.py +++ b/propka/pdb.py @@ -50,11 +50,17 @@ def protein_precheck(conformations, names): for name in names: atoms = conformations[name].atoms - res_ids = [] - [res_ids.append(resid_from_atom(a)) for a in atoms if not res_ids.count(resid_from_atom(a))] + # Group the atoms by their residue: + 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: - res_atoms = [a for a in atoms if resid_from_atom(a) == res_id and a.element != 'H'] + for res_id, res_atoms in atoms_by_residue.items(): resname = res_atoms[0].resName residue_label = '%3s%5s'%(resname, res_id)