Skip to content

Commit

Permalink
Conform restraint model attribute to developer guide
Browse files Browse the repository at this point in the history
Relates #163
  • Loading branch information
sethaxen committed Jun 25, 2018
1 parent 31313b3 commit 90ea390
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 89 deletions.
18 changes: 14 additions & 4 deletions pyext/src/restraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, m, name=None, label=None, weight=1.):
particle/restraint names.
@param weight The weight to apply to all internal restraints.
"""
self.m = m
self.model = m
self.restraint_sets = []
self._label_is_set = False
self.weight = weight
Expand All @@ -41,6 +41,16 @@ def __init__(self, m, name=None, label=None, weight=1.):

self.rs = self._create_restraint_set(name=None)

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def m(self):
return self.model

@property
@IMP.deprecated_method("3.0", "Model should be accessed with `.model`.")
def mdl(self):
return self.model

def set_label(self, label):
"""Set the unique label used in outputs and particle/restraint names.
@param label Label
Expand Down Expand Up @@ -71,7 +81,7 @@ def add_to_model(self):
"""Add the restraint to the model."""
self._label_is_set = True
for rs in self.restraint_sets:
IMP.pmi.tools.add_restraint_to_model(self.m, rs)
IMP.pmi.tools.add_restraint_to_model(self.model, rs)

def evaluate(self):
"""Evaluate the score of the restraint."""
Expand Down Expand Up @@ -116,7 +126,7 @@ def _create_restraint_set(self, name=None):
name = self.name
else:
name = self.name + "_" + str(name)
rs = IMP.RestraintSet(self.m, name)
rs = IMP.RestraintSet(self.model, name)
rs.set_weight(self.weight)
self.restraint_sets.append(rs)
rs.set_was_used(True)
Expand Down Expand Up @@ -148,7 +158,7 @@ def _create_nuisance(self, init_val, min_val, max_val, max_trans, name,
\see IMP.pmi.tools.SetupNuisance
"""
nuis = IMP.pmi.tools.SetupNuisance(
self.m, init_val, min_val, max_val,
self.model, init_val, min_val, max_val,
isoptimized=is_sampled).get_particle()
nuis_name = self.name + "_" + name
nuis.set_name(nuis_name)
Expand Down
28 changes: 15 additions & 13 deletions pyext/src/restraints/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ def __init__(self,
particle/restraint names.
"""
if representation:
m = representation.prot.get_model()
model = representation.prot.get_model()
particles = IMP.pmi.tools.select(
representation,
resolution=resolution,
hierarchies=hierarchies)
elif hierarchies:
hiers = IMP.pmi.tools.input_adaptor(hierarchies, resolution,
flatten=True)
m = hiers[0].get_model()
model = hiers[0].get_model()
particles = [h.get_particle() for h in hiers]
else:
raise Exception("%s: must pass representation or hierarchies" % (
self.name))

super(ExternalBarrier, self).__init__(m, label=label, weight=weight)
super(ExternalBarrier, self).__init__(model, label=label,
weight=weight)
self.radius = radius

if center is None:
Expand All @@ -65,7 +66,7 @@ def __init__(self,

ub3 = IMP.core.HarmonicUpperBound(radius, 10.0)
ss3 = IMP.core.DistanceToSingletonScore(ub3, c3)
lsc = IMP.container.ListSingletonContainer(self.m)
lsc = IMP.container.ListSingletonContainer(self.model)

lsc.add(particles)
r3 = IMP.container.SingletonsRestraint(ss3, lsc)
Expand Down Expand Up @@ -111,7 +112,7 @@ def __init__(self,
ts2 = IMP.core.HarmonicLowerBound(distancemin, kappa)

if representation and not root_hier:
m = representation.prot.get_model()
model = representation.prot.get_model()
particles1 = IMP.pmi.tools.select(representation,
resolution=resolution,
name=tuple_selection1[2],
Expand All @@ -121,7 +122,7 @@ def __init__(self,
name=tuple_selection2[2],
residue=tuple_selection2[0])
elif root_hier and not representation:
m = root_hier.get_model()
model = root_hier.get_model()
copy_num1 = 0
if len(tuple_selection1) > 3:
copy_num1 = tuple_selection1[3]
Expand All @@ -144,7 +145,8 @@ def __init__(self,
else:
raise Exception("Pass representation or root_hier, not both")

super(DistanceRestraint, self).__init__(m, label=label, weight=weight)
super(DistanceRestraint, self).__init__(model, label=label,
weight=weight)
print(self.name)

print("Created distance restraint between "
Expand All @@ -155,11 +157,11 @@ def __init__(self,
raise ValueError("more than one particle selected")

self.rs.add_restraint(
IMP.core.DistanceRestraint(self.m, ts1,
IMP.core.DistanceRestraint(self.model, ts1,
particles1[0],
particles2[0]))
self.rs.add_restraint(
IMP.core.DistanceRestraint(self.m, ts2,
IMP.core.DistanceRestraint(self.model, ts2,
particles1[0],
particles2[0]))

Expand Down Expand Up @@ -366,13 +368,13 @@ def __init__(self,
raise Exception("You must pass a tuple_selection")

if representation and not root_hier:
m = representation.prot.get_model()
model = representation.prot.get_model()
ps = IMP.pmi.tools.select(representation,
resolution=resolution,
name=tuple_selection[2],
residue=tuple_selection[0])
elif root_hier and not representation:
m = root_hier.get_model()
model = root_hier.get_model()
copy_num1 = 0
if len(tuple_selection) > 3:
copy_num1 = tuple_selection[3]
Expand All @@ -390,7 +392,7 @@ def __init__(self,
raise ValueError("%s: more than one particle selected" %
self.name)

super(DistanceToPointRestraint, self).__init__(m, label=label,
super(DistanceToPointRestraint, self).__init__(model, label=label,
weight=weight)
self.radius = radius

Expand All @@ -405,7 +407,7 @@ def __init__(self,
self.name)
ss3 = IMP.core.DistanceToSingletonScore(ub3, c3)

lsc = IMP.container.ListSingletonContainer(self.m)
lsc = IMP.container.ListSingletonContainer(self.model)
lsc.add(ps)

r3 = IMP.container.SingletonsRestraint(ss3, lsc)
Expand Down
Loading

0 comments on commit 90ea390

Please sign in to comment.