diff --git a/pyext/src/restraints/__init__.py b/pyext/src/restraints/__init__.py index 90ccbfdb..c1bc57e0 100644 --- a/pyext/src/restraints/__init__.py +++ b/pyext/src/restraints/__init__.py @@ -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 @@ -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 @@ -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.""" @@ -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) @@ -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) diff --git a/pyext/src/restraints/basic.py b/pyext/src/restraints/basic.py index 7d9e7474..af1297a5 100644 --- a/pyext/src/restraints/basic.py +++ b/pyext/src/restraints/basic.py @@ -37,7 +37,7 @@ 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, @@ -45,13 +45,14 @@ def __init__(self, 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: @@ -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) @@ -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], @@ -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] @@ -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 " @@ -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])) @@ -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] @@ -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 @@ -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) diff --git a/pyext/src/restraints/crosslinking.py b/pyext/src/restraints/crosslinking.py index 756be87a..76d6ab95 100644 --- a/pyext/src/restraints/crosslinking.py +++ b/pyext/src/restraints/crosslinking.py @@ -64,15 +64,15 @@ def __init__(self, representation=None, representations = [representation] else: representations = representation - m = representations[0].prot.get_model() + model = representations[0].prot.get_model() elif root_hier is not None: representations = [] - m = root_hier.get_model() + model = root_hier.get_model() else: raise Exception("You must pass either representation or root_hier") super(CrossLinkingMassSpectrometryRestraint, self).__init__( - m, weight=weight, label=label) + model, weight=weight, label=label) if CrossLinkDataBase is None: raise Exception("You must pass a CrossLinkDataBase") @@ -231,7 +231,7 @@ def __init__(self, representation=None, print("generating a new crosslink restraint") new_contribution=False dr = IMP.isd.CrossLinkMSRestraint( - self.m, + self.model, length, slope) restraints.append(dr) @@ -300,7 +300,7 @@ def __init__(self, representation=None, dr.set_name(xl_label) if p1i != p2i: - pr = IMP.core.PairRestraint(self.m, dps2, (p1i, p2i)) + pr = IMP.core.PairRestraint(self.model, dps2, (p1i, p2i)) pr.set_name(xl_label) self.rslin.add_restraint(pr) @@ -369,7 +369,7 @@ def create_sigma(self, name): sigmamin = 0.01 sigmamax = 100.0 sigmatrans = 0.5 - sigma = IMP.pmi.tools.SetupNuisance(self.m, sigmainit, + sigma = IMP.pmi.tools.SetupNuisance(self.model, sigmainit, sigmaminnuis, sigmamaxnuis, self.sigma_is_sampled).get_particle() self.sigma_dictionary[name] = ( sigma, @@ -377,7 +377,7 @@ def create_sigma(self, name): self.sigma_is_sampled) self.rssig.add_restraint( IMP.isd.UniformPrior( - self.m, + self.model, sigma, 1000000000.0, sigmamax, @@ -396,7 +396,7 @@ def create_psi(self, name): psimin = 0.01 psimax = 0.49 psitrans = 0.1 - psi = IMP.pmi.tools.SetupNuisance(self.m, psiinit, + psi = IMP.pmi.tools.SetupNuisance(self.model, psiinit, psiminnuis, psimaxnuis, self.psi_is_sampled).get_particle() self.psi_dictionary[name] = ( @@ -406,13 +406,13 @@ def create_psi(self, name): self.rspsi.add_restraint( IMP.isd.UniformPrior( - self.m, + self.model, psi, 1000000000.0, psimax, psimin)) - self.rspsi.add_restraint(IMP.isd.JeffreysRestraint(self.m, psi)) + self.rspsi.add_restraint(IMP.isd.JeffreysRestraint(self.model, psi)) return psi def get_output(self): @@ -609,7 +609,7 @@ def __init__(self, psip = self.psi_dictionary['psi'][0].get_particle_index() else: psip = self.psi_dictionary[unique_id][0].get_particle_index() - r = IMP.isd.AtomicCrossLinkMSRestraint(self.m, + r = IMP.isd.AtomicCrossLinkMSRestraint(self.model, self.length, psip, slope, @@ -699,7 +699,7 @@ def _create_sigma(self, name,sigmainit): sigmamin = 0.01 sigmamax = 100.0 sigmatrans = 0.5 - sigma = IMP.pmi.tools.SetupNuisance(self.m, + sigma = IMP.pmi.tools.SetupNuisance(self.model, sigmainit, sigmaminnuis, sigmamaxnuis, @@ -710,7 +710,7 @@ def _create_sigma(self, name,sigmainit): self.sigma_is_sampled) self.rs_sig.add_restraint( IMP.isd.UniformPrior( - self.m, + self.model, sigma, 1000000000.0, sigmamax, @@ -728,7 +728,7 @@ def _create_psi(self, name,psiinit): psimin = 0.01 psimax = 0.49 psitrans = 0.1 - psi = IMP.pmi.tools.SetupNuisance(self.m, + psi = IMP.pmi.tools.SetupNuisance(self.model, psiinit, psiminnuis, psimaxnuis, @@ -740,13 +740,13 @@ def _create_psi(self, name,psiinit): self.rs_psi.add_restraint( IMP.isd.UniformPrior( - self.m, + self.model, psi, 1000000000.0, psimax, psimin)) - self.rs_psi.add_restraint(IMP.isd.JeffreysRestraint(self.m, psi)) + self.rs_psi.add_restraint(IMP.isd.JeffreysRestraint(self.model, psi)) return psi def create_restraints_for_rmf(self): @@ -759,15 +759,15 @@ def __init__(self,rs): def get_restraint_for_rmf(self): return self.rs - dummy_mdl=IMP.Model() + dummy_model=IMP.Model() hps = IMP.core.HarmonicDistancePairScore(self.length,1.0) dummy_rs=[] for nxl in range(self.get_number_of_restraints()): xl=IMP.isd.AtomicCrossLinkMSRestraint.get_from(self.rs.get_restraint(nxl)) - rs = IMP.RestraintSet(dummy_mdl, 'atomic_xl_'+str(nxl)) + rs = IMP.RestraintSet(dummy_model, 'atomic_xl_'+str(nxl)) for ncontr in range(xl.get_number_of_contributions()): ps=xl.get_contribution(ncontr) - dr = IMP.core.PairRestraint(hps,[self.m.get_particle(p) for p in ps], + dr = IMP.core.PairRestraint(hps,[self.model.get_particle(p) for p in ps], 'xl%i_contr%i'%(nxl,ncontr)) rs.add_restraint(dr) dummy_rs.append(MyGetRestraint(rs)) @@ -814,10 +814,10 @@ def load_nuisances_from_stat_file(self,in_fn,nframe): for nxl in range(self.rs.get_number_of_restraints()): xl=IMP.isd.AtomicCrossLinkMSRestraint.get_from(self.rs.get_restraint(nxl)) psip = xl.get_psi() - IMP.isd.Scale(self.m,psip).set_scale(psi_val) + IMP.isd.Scale(self.model,psip).set_scale(psi_val) for contr in range(xl.get_number_of_contributions()): sig1,sig2=xl.get_contribution_sigmas(contr) - IMP.isd.Scale(self.m,sig1).set_scale(sig_val) + IMP.isd.Scale(self.model,sig1).set_scale(sig_val) print('loaded nuisances from file') @@ -898,13 +898,13 @@ def plot_violations(self,out_prefix, r=0.365; g=0.933; b=0.365; # now only showing if UNIQUELY PASSING in this state pp = state_info[nstate][nxl]["low_pp"] - c1=IMP.core.XYZ(self.m,pp[0]).get_coordinates() - c2=IMP.core.XYZ(self.m,pp[1]).get_coordinates() + c1=IMP.core.XYZ(self.model,pp[0]).get_coordinates() + c2=IMP.core.XYZ(self.model,pp[1]).get_coordinates() - r1 = IMP.atom.get_residue(IMP.atom.Atom(self.m,pp[0])).get_index() - ch1 = IMP.atom.get_chain_id(IMP.atom.Atom(self.m,pp[0])) - r2 = IMP.atom.get_residue(IMP.atom.Atom(self.m,pp[0])).get_index() - ch2 = IMP.atom.get_chain_id(IMP.atom.Atom(self.m,pp[0])) + r1 = IMP.atom.get_residue(IMP.atom.Atom(self.model,pp[0])).get_index() + ch1 = IMP.atom.get_chain_id(IMP.atom.Atom(self.model,pp[0])) + r2 = IMP.atom.get_residue(IMP.atom.Atom(self.model,pp[0])).get_index() + ch2 = IMP.atom.get_chain_id(IMP.atom.Atom(self.model,pp[0])) cmds[nstate].add((ch1,r1)) cmds[nstate].add((ch2,r2)) @@ -933,12 +933,12 @@ def _get_contribution_info(self,xl,ncontr,use_CA=False): idx1=xl.get_contribution(ncontr)[0] idx2=xl.get_contribution(ncontr)[1] if use_CA: - idx1 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.m,idx1)), + idx1 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.model,idx1)), atom_type=IMP.atom.AtomType("CA")).get_selected_particle_indexes()[0] - idx2 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.m,idx2)), + idx2 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.model,idx2)), atom_type=IMP.atom.AtomType("CA")).get_selected_particle_indexes()[0] - dist = IMP.algebra.get_distance(IMP.core.XYZ(self.m,idx1).get_coordinates(), - IMP.core.XYZ(self.m,idx2).get_coordinates()) + dist = IMP.algebra.get_distance(IMP.core.XYZ(self.model,idx1).get_coordinates(), + IMP.core.XYZ(self.model,idx2).get_coordinates()) return idx1,idx2,dist def get_best_stats(self,limit_to_state=None,limit_to_chains=None,exclude_chains='',use_CA=False): @@ -962,21 +962,21 @@ def get_best_stats(self,limit_to_state=None,limit_to_chains=None,exclude_chains= for contr in range(xl.get_number_of_contributions()): pp = xl.get_contribution(contr) if use_CA: - idx1 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.m,pp[0])), + idx1 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.model,pp[0])), atom_type=IMP.atom.AtomType("CA")).get_selected_particle_indexes()[0] - idx2 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.m,pp[1])), + idx2 = IMP.atom.Selection(IMP.atom.get_residue(IMP.atom.Atom(self.model,pp[1])), atom_type=IMP.atom.AtomType("CA")).get_selected_particle_indexes()[0] pp = [idx1,idx2] if limit_to_state is not None: - nstate = IMP.atom.get_state_index(IMP.atom.Atom(self.m,pp[0])) + nstate = IMP.atom.get_state_index(IMP.atom.Atom(self.model,pp[0])) if nstate!=limit_to_state: continue state_contrs.append(contr) - dist = IMP.core.get_distance(IMP.core.XYZ(self.m,pp[0]), - IMP.core.XYZ(self.m,pp[1])) + dist = IMP.core.get_distance(IMP.core.XYZ(self.model,pp[0]), + IMP.core.XYZ(self.model,pp[1])) if limit_to_chains is not None: - c1 = IMP.atom.get_chain_id(IMP.atom.Atom(self.m,pp[0])) - c2 = IMP.atom.get_chain_id(IMP.atom.Atom(self.m,pp[1])) + c1 = IMP.atom.get_chain_id(IMP.atom.Atom(self.model,pp[0])) + c2 = IMP.atom.get_chain_id(IMP.atom.Atom(self.model,pp[1])) if (c1 in limit_to_chains or c2 in limit_to_chains) and ( c1 not in exclude_chains and c2 not in exclude_chains): if dist