Skip to content

Commit

Permalink
Don't update model while outputting
Browse files Browse the repository at this point in the history
Updating model while getting outputs results in redundant unecessary and
potentially expensive updates. Instead, assume that model is updated
externally before writing outputs. Fixes #239
  • Loading branch information
sethaxen committed Jun 23, 2018
1 parent 4436041 commit 4c281af
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 42 deletions.
2 changes: 0 additions & 2 deletions pyext/src/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ def __init__(self,ps,label,init_coords=None):
self.init_coords = init_coords
self.label = label
def get_output(self):
self.mdl.update()
output = {}
coords = [IMP.core.XYZ(p).get_coordinates() for p in self.ps]
rmsd = IMP.algebra.get_rmsd(coords,self.init_coords)
Expand All @@ -595,7 +594,6 @@ def __init__(self,mdl):
self.mdl = mdl
self.rs = IMP.pmi.tools.get_restraint_set(self.mdl)
def get_output(self):
self.mdl.update()
score = self.rs.evaluate(False)
output = {}
output["Total_Score"] = str(score)
Expand Down
13 changes: 13 additions & 0 deletions pyext/src/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ def execute_macro(self):
output = IMP.pmi.output.Output(atomistic=self.vars["atomistic"])
low_temp_stat_file = globaldir + \
self.vars["stat_file_name_suffix"] + "." + str(myindex) + ".out"

# Ensure model is updated before saving init files
if not self.test_mode:
self.model.update()

if not self.test_mode:
if self.output_objects is not None:
output.init_stat2(low_temp_stat_file,
Expand Down Expand Up @@ -526,6 +531,10 @@ def execute_macro(self):
score_perc=mpivs.get_percentile("score")
save_frame=(score_perc*100.0<=75.0)

# Ensure model is updated before saving output files
if save_frame or not self.test_mode:
self.model.update()

if save_frame:
print("--- frame %s score %s " % (str(i), str(score)))

Expand Down Expand Up @@ -1406,6 +1415,7 @@ def set_coordinates(self,hier_name,xyz_tuple):
def save_rmf(self,rmfname):

o=IMP.pmi.output.Output()
self.simo.m.update()
o.init_rmf(rmfname,[self.simo.prot])
o.write_rmf(rmfname)
o.close_rmf(rmfname)
Expand Down Expand Up @@ -1907,6 +1917,7 @@ def clustering(self,
IMP.core.transform(rb,transformation)

o=IMP.pmi.output.Output()
self.model.update()
out_pdb_fn=os.path.join(dircluster,str(cnt)+"."+str(self.rank)+".pdb")
out_rmf_fn=os.path.join(dircluster,str(cnt)+"."+str(self.rank)+".rmf3")
o.init_pdb(out_pdb_fn,prot)
Expand Down Expand Up @@ -2112,6 +2123,7 @@ def clustering(self,

# pdb writing should be optimized!
o = IMP.pmi.output.Output()
self.model.update()
o.init_pdb(dircluster + str(k) + ".pdb", prot)
o.write_pdb(dircluster + str(k) + ".pdb")

Expand Down Expand Up @@ -2396,6 +2408,7 @@ def save_coordinates(self,cluster,rmf_name=None,reference="Absolute", prefix="./
rmf_name=prefix+'/'+str(cluster.cluster_id)+".rmf3"

d1=self.stath1[cluster.members[0]]
self.model.update()
o.init_rmf(rmf_name, [self.stath1])
for n1 in cluster.members:
d1=self.stath1[n1]
Expand Down
5 changes: 4 additions & 1 deletion pyext/src/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def _flatten(seq):
return l

class Output(object):
"""Class for easy writing of PDBs, RMFs, and stat files"""
"""Class for easy writing of PDBs, RMFs, and stat files
\note Model should be updated prior to writing outputs.
"""
def __init__(self, ascii=True,atomistic=False):
self.dictionary_pdbs = {}
self.dictionary_rmfs = {}
Expand Down
1 change: 0 additions & 1 deletion pyext/src/restraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def get_particles_to_sample(self):
def get_output(self):
"""Get outputs to write to stat files."""
output = {}
self.m.update()
score = self.evaluate()
output["_TotalScore"] = str(score)

Expand Down
2 changes: 0 additions & 2 deletions pyext/src/restraints/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def add_to_model(self):
IMP.pmi.tools.add_restraint_to_model(self.m, self)

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -282,7 +281,6 @@ def add_to_model(self):
IMP.pmi.tools.add_restraint_to_model(self.m, self)

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down
9 changes: 0 additions & 9 deletions pyext/src/restraints/crosslinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,6 @@ def set_weight(self, weight):
def get_output(self):
# content of the crosslink database pairs
# self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
self.m.update()

output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -1406,8 +1404,6 @@ def plot_restraint(self, radius1, radius2, maxdist=50, npoints=10):
def get_output(self):
# content of the crosslink database pairs
# self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
self.m.update()

output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -1633,8 +1629,6 @@ def plot_restraint(self, radius1, radius2, maxdist=50, npoints=10):
def get_output(self):
# content of the crosslink database pairs
# self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
self.m.update()

output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -2114,8 +2108,6 @@ def write_db(self,filename):
def get_output(self):
# content of the crosslink database pairs
# self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
self.m.update()

output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -2399,7 +2391,6 @@ def get_sigma(self):
return self.sigma

def get_output(self):
self.m.update()
output = {}
score = self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down
2 changes: 0 additions & 2 deletions pyext/src/restraints/crosslinking_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ def create_psi(self, name):


def get_output(self):
self.m.update()

output = {}
score = self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down
3 changes: 0 additions & 3 deletions pyext/src/restraints/em.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ def get_restraint_set(self):
return self.rs

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
ccc = self.gaussianEM_restraint.get_cross_correlation_coefficient()
Expand Down Expand Up @@ -458,7 +457,6 @@ def get_restraint_set(self):
return self.rs

def get_output(self):
self.mdl.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -506,7 +504,6 @@ def set_weight(self,weight):
self.rs.set_weigth(self.weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight*self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down
2 changes: 0 additions & 2 deletions pyext/src/restraints/em2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def set_weight(self,weight):
self.rs.set_weight(self.weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight*self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -236,7 +235,6 @@ def set_weight(self,weight):
self.rs.set_weight(self.weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight*self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down
8 changes: 0 additions & 8 deletions pyext/src/restraints/proteomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def set_weight(self, weight):
self.rs.set_weight(weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -163,7 +162,6 @@ def add_to_model(self):
IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)

def get_output(self):
self.m.update()
output = {}
score = self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -351,8 +349,6 @@ def set_weight(self, weight):
def get_output(self):
# content of the crosslink database pairs
# self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
self.m.update()

output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -519,8 +515,6 @@ def set_output_level(self, level="low"):
def get_output(self):
# content of the crosslink database pairs
# self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
self.m.update()

output = {}
score = self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -623,7 +617,6 @@ def set_weight(self, weight):
self.rs.set_weight(weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -954,7 +947,6 @@ def get_movers(self):


def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down
12 changes: 0 additions & 12 deletions pyext/src/restraints/stereochemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def set_weight(self, weight):
self.rs.set_weight(weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -278,7 +277,6 @@ def set_weight(self, weight):
self.rs.set_weight(weight)

def get_output(self):
self.mdl.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -347,7 +345,6 @@ def evaluate(self):
return self.weight * self.rs.unprotected_evaluate(None)

def get_output(self):
self.mdl.update()
output = {}
score = self.evaluate()
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -434,7 +431,6 @@ def get_excluded_pairs(self):
return self.pairslist

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -513,7 +509,6 @@ def get_excluded_pairs(self):
return self.pairslist

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -614,7 +609,6 @@ def get_excluded_pairs(self):
return self.pairslist

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -834,7 +828,6 @@ def get_distance_restraint(self, p0, p1, d0, kappa):

def get_output(self):
output = {}
self.m.update()
score_angle = self.anglrs.unprotected_evaluate(None)
score_dihers = self.dihers.unprotected_evaluate(None)
score_bondrs = self.bondrs.unprotected_evaluate(None)
Expand Down Expand Up @@ -926,7 +919,6 @@ def get_excluded_pairs(self):
return self.pairslist

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -1045,7 +1037,6 @@ def set_weight(self, weight):
self.rs.set_weight(weight)

def get_output(self):
self.mdl.update()
output = {}
bonds_score = self.weight * self.bonds_rs.unprotected_evaluate(None)
nonbonded_score = self.weight * self.nonbonded_rs.unprotected_evaluate(None)
Expand Down Expand Up @@ -1193,7 +1184,6 @@ def get_excluded_pairs(self):
return self.pairslist

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down Expand Up @@ -1263,7 +1253,6 @@ def get_excluded_pairs(self):
return self.pairslist

def get_output(self):
self.mdl.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["SymmetryRestraint_" + self.label] = str(score)
Expand Down Expand Up @@ -1338,7 +1327,6 @@ def set_weight(self, weight):
self.rs.set_weight(weight)

def get_output(self):
self.m.update()
output = {}
score = self.weight * self.rs.unprotected_evaluate(None)
output["_TotalScore"] = str(score)
Expand Down

0 comments on commit 4c281af

Please sign in to comment.