IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
crosslinking_new.py
1 """@namespace IMP.pmi1.restraints.crosslinking_new
2 Restraints for handling crosslinking data. This temporary module will be soon
3 deprecated and merged with IMP.pmi1.restraints.crosslinking
4 """
5 
6 from __future__ import print_function
7 import IMP
8 import IMP.core
9 import IMP.algebra
10 import IMP.atom
11 import IMP.container
12 import IMP.pmi1.tools
14 import pdb
15 
16 class DisulfideCrossLinkRestraint(object):
17  def __init__(self, representation,
18  selection_tuple1,
19  selection_tuple2,
20  length=6.5,
21  resolution=1,
22  slope=0.01,
23  label="None"):
24 
25  self.m = representation.prot.get_model()
26  self.rs = IMP.RestraintSet(self.m, 'likelihood')
27  self.rslin = IMP.RestraintSet(self.m, 'linear_dummy_restraints')
28 
29  # dummy linear restraint used for Chimera display
30  self.linear = IMP.core.Linear(0, 0.0)
31  self.linear.set_slope(0.0)
32  dps2 = IMP.core.DistancePairScore(self.linear)
33 
34  self.label = label
35  self.psi_dictionary={}
36  self.sigma_dictionary={}
37  self.psi_is_sampled = False
38  self.sigma_is_sampled = False
39  self.xl={}
40 
41  ps1 = IMP.pmi1.tools.select_by_tuple(
42  representation,
43  selection_tuple1,
44  resolution=resolution)
45 
46  ps2 = IMP.pmi1.tools.select_by_tuple(
47  representation,
48  selection_tuple2,
49  resolution=resolution)
50 
51  if len(ps1) > 1 or len(ps1) == 0:
52  raise ValueError("DisulfideBondRestraint: ERROR> first selection pattern selects multiple particles or sero particles")
53 
54  if len(ps2) > 1 or len(ps2) == 0:
55  raise ValueError("DisulfideBondRestraint: ERROR> second selection pattern selects multiple particles or sero particles")
56 
57  p1 = ps1[0]
58  p2 = ps2[0]
59 
60 
61 
62  sigma=self.create_sigma("SIGMA_DISULFIDE_BOND")
63  psi=self.create_psi("PSI_DISULFIDE_BOND")
64 
65  p1i = p1.get_particle_index()
66  p2i = p2.get_particle_index()
67  si = sigma.get_particle().get_index()
68  psii = psi.get_particle().get_index()
69 
71  self.m,
72  length,
73  slope)
74 
75  dr.add_contribution((p1i, p2i), (si, si), psii)
76 
77  if p1i != p2i:
78  pr = IMP.core.PairRestraint(self.m, dps2, (p1i, p2i))
79  pr.set_name("DISULFIDE_BOND_"+self.label)
80  self.rslin.add_restraint(pr)
81 
82  lw = IMP.isd.LogWrapper([dr],1.0)
83  self.rs.add_restraint(lw)
84 
85  self.xl["Particle1"]=p1
86  self.xl["Particle2"]=p2
87  self.xl["Sigma"]=sigma
88  self.xl["Psi"]=psi
89 
90  def add_to_model(self):
92  IMP.pmi1.tools.add_restraint_to_model(self.m, self.rslin)
93 
94  def get_hierarchies(self):
95  return self.prot
96 
97  def get_restraint_sets(self):
98  return self.rs
99 
100  def get_restraint(self):
101  return self.rs
102 
103  def get_restraint_for_rmf(self):
104  return self.rslin
105 
106  def get_restraints(self):
107  rlist = []
108  for r in self.rs.get_restraints():
109  rlist.append(IMP.core.PairRestraint.get_from(r))
110  return rlist
111 
112  def set_psi_is_sampled(self, is_sampled=True):
113  self.psi_is_sampled = is_sampled
114 
115  def set_sigma_is_sampled(self, is_sampled=True):
116  self.sigma_is_sampled = is_sampled
117 
118 
119  def create_sigma(self, name):
120  ''' a nuisance on the structural uncertainty '''
121  if name in self.sigma_dictionary:
122  return self.sigma_dictionary[name][0]
123 
124  sigmainit = 1.0
125  sigmaminnuis = 0.0000001
126  sigmamaxnuis = 1000.0
127  sigmamin = 0.01
128  sigmamax = 100.0
129  sigmatrans = 0.5
130  sigma = IMP.pmi1.tools.SetupNuisance(self.m, sigmainit,
131  sigmaminnuis, sigmamaxnuis, self.sigma_is_sampled).get_particle()
132  self.sigma_dictionary[name] = (
133  sigma,
134  sigmatrans,
135  self.sigma_is_sampled)
136 
137  return sigma
138 
139  def create_psi(self, name):
140  ''' a nuisance on the inconsistency '''
141  if name in self.psi_dictionary:
142  return self.psi_dictionary[name][0]
143 
144  psiinit=0.001
145  psiminnuis = 0.0000001
146  psimaxnuis = 0.4999999
147  psimin = 0.01
148  psimax = 0.49
149  psitrans = 0.1
150  psi = IMP.pmi1.tools.SetupNuisance(self.m, psiinit,
151  psiminnuis, psimaxnuis,
152  self.psi_is_sampled).get_particle()
153  self.psi_dictionary[name] = (
154  psi,
155  psitrans,
156  self.psi_is_sampled)
157 
158  return psi
159 
160 
161  def get_output(self):
162  output = {}
163  score = self.rs.unprotected_evaluate(None)
164  output["_TotalScore"] = str(score)
165  output["DisulfideBondRestraint_Data_Score_" + self.label] = str(score)
166  output["DisulfideBondRestraint_Linear_Score_" +
167  self.label] = self.rslin.unprotected_evaluate(None)
168  return output
169 
170  def get_particles_to_sample(self):
171  raise NotImplementedError(" ")
172 
173 
174 @IMP.deprecated_object("2.5", "Use IMP.pmi1.restraints.crosslinking.CrossLinkingMassSpectrometryRestraint instead.")
175 class CrossLinkingMassSpectrometryRestraint(IMP.pmi1.restraints.crosslinking.CrossLinkingMassSpectrometryRestraint):
176 
177  def __init__(self, *args, **kwargs):
Setup cross-link distance restraints from mass spectrometry data.
A restraint for ambiguous cross-linking MS data and multiple state approach.
Various classes to hold sets of particles.
Object used to hold a set of restraints.
Definition: RestraintSet.h:41
Miscellaneous utilities.
Definition: /tools.py:1
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Linear function
Definition: Linear.h:22
Score a pair of particles based on the distance between their centers.
def deprecated_object
Python decorator to mark a class as deprecated.
Definition: __init__.py:9522
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Restraints for handling crosslinking data.
Calculate the -Log of a list of restraints.
Definition: LogWrapper.h:26
Applies a PairScore to a Pair.
Definition: PairRestraint.h:31
def add_restraint_to_model
Add a PMI restraint to the model.
Definition: /tools.py:53
Functionality for loading, creating, manipulating and scoring atomic structures.