IMP  2.4.0
The Integrative Modeling Platform
pmi/restraints/proteomics.py
1 """@namespace IMP.pmi.restraints.proteomics
2 Restraints for handling various kinds of proteomics data.
3 """
4 
5 from __future__ import print_function
6 import IMP
7 import IMP.core
8 import IMP.base
9 import IMP.algebra
10 import IMP.atom
11 import IMP.container
12 
13 
14 class ConnectivityRestraint(object):
15 
16  '''
17  generate a connectivity restraint between domains
18  setting up the restraint
19  example:
20  cr=restraints.ConnectivityRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
21  cr.add_to_model()
22  cr.set_label("CR1")
23 
24 
25  Multistate support =No
26  Selection type=selection tuple
27  Resolution=Yes
28  '''
29 
30  def __init__(
31  self,
32  representation,
33  selection_tuples,
34  kappa=10.0,
35  resolution=None,
36  label="None"):
37 
38  self.weight = 1.0
39  self.kappa = kappa
40  self.label = label
41  if self.label == "None":
42  self.label = str(selection_tuples)
43  self.m = representation.prot.get_model()
44  self.rs = IMP.RestraintSet(self.m, label)
45 
46  sels = []
47 
48  for s in selection_tuples:
49  particles = IMP.pmi.tools.select_by_tuple(representation, s,
50  resolution=resolution, name_is_ambiguous=True)
51  sel = IMP.atom.Selection(particles)
52  sels.append(sel)
53 
55  sels,
56  self.kappa,
57  self.label)
58  self.rs.add_restraint(cr)
59 
60  def set_label(self, label):
61  self.label = label
62  self.rs.set_name(label)
63  for r in self.rs.get_restraints():
64  r.set_name(label)
65 
66  def add_to_model(self):
67  self.m.add_restraint(self.rs)
68 
69  def get_restraint(self):
70  return self.rs
71 
72  def get_restraints(self):
73  rlist = []
74  for r in self.rs.get_restraints():
75  rlist.append(IMP.core.PairRestraint.get_from(r))
76  return rlist
77 
78  def set_weight(self, weight):
79  self.weight = weight
80  self.rs.set_weight(weight)
81 
82  def get_output(self):
83  self.m.update()
84  output = {}
85  score = self.weight * self.rs.unprotected_evaluate(None)
86  output["_TotalScore"] = str(score)
87  output["ConnectivityRestraint_" + self.label] = str(score)
88  return output
89 
90 
91 #
92 class CompositeRestraint(object):
93 
94  '''
95  handleparticles is a selection tuple
96  compositeparticles is a list of selection tuples
97  '''
98  import IMP.pmi
99 
100  def __init__(
101  self,
102  representation,
103  handleparticles_tuples,
104  compositeparticles_tuple_list,
105  cut_off=5.0,
106  lam=1.0,
107  plateau=0.0,
108  resolution=None,
109  label="None"):
110 
111  # composite particles: all particles beside the handle
112  self.label = label
113  self.m = representation.prot.get_model()
114  self.rs = IMP.RestraintSet(self.m, 'cr')
115 
116  handleparticles = []
117  for s in handleparticles_tuples:
118  handleparticles += IMP.pmi.tools.select_by_tuple(representation, s,
119  resolution=resolution, name_is_ambiguous=True)
120 
121  compositeparticle_list = []
122  for list in compositeparticles_tuple_list:
123  compositeparticles = []
124  for s in list:
125  compositeparticles += IMP.pmi.tools.select_by_tuple(
126  representation, s,
127  resolution=resolution, name_is_ambiguous=True)
128  compositeparticle_list.append(compositeparticles)
129 
131  self.m,
132  handleparticles,
133  cut_off,
134  lam,
135  True,
136  plateau)
137  for ps in compositeparticle_list:
138  # composite particles is a list of list of particles
139  ln.add_composite_particle(ps)
140 
141  self.rs.add_restraint(ln)
142 
143  def set_label(self, label):
144  self.label = label
145 
146  def add_to_model(self):
147  self.m.add_restraint(self.rs)
148 
149  def get_output(self):
150  self.m.update()
151  output = {}
152  score = self.rs.unprotected_evaluate(None)
153  output["_TotalScore"] = str(score)
154  output["CompositeRestraint_" + self.label] = str(score)
155  return output
156 
157 
158 #
160 
161  '''
162  this restraint allows ambiguous crosslinking between multiple copies
163  excluding between symmetric copies
164  It allows name ambiguity
165  '''
166 
167  def __init__(
168  self,
169  representation,
170  restraints_file,
171  cut_off=5.0,
172  lam=1.0,
173  plateau=0.01,
174  resolution=None,
175  label="None"):
176 
177  self.weight = 1.0
178  self.m = representation.prot.get_model()
179  self.rs = IMP.RestraintSet(self.m, 'data')
180  self.label = "None"
181  self.pairs = []
182 
183  self.outputlevel = "low"
184  self.cut_off = cut_off
185  self.lam = lam
186  self.plateau = plateau
187 
188  fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
189 
190  for line in fl:
191 
192  tokens = line.split()
193  # skip character
194  if (tokens[0] == "#"):
195  continue
196  r1 = int(tokens[2])
197  c1 = tokens[0]
198  r2 = int(tokens[3])
199  c2 = tokens[1]
200 
201  ps1 = IMP.pmi.tools.select(
202  representation,
203  resolution=resolution,
204  name=c1,
205  name_is_ambiguous=True,
206  residue=r1)
207  hrc1 = [representation.hier_db.particle_to_name[p] for p in ps1]
208  ps1nosym = [
209  p for p in ps1 if IMP.pmi.Symmetric(
210  p).get_symmetric(
211  ) == 0]
212  hrc1nosym = [representation.hier_db.particle_to_name[p]
213  for p in ps1nosym]
214 
215  if len(ps1) == 0:
216  print("AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" % (r1, c1))
217  continue
218 
219  ps2 = IMP.pmi.tools.select(
220  representation,
221  resolution=resolution,
222  name=c2,
223  name_is_ambiguous=True,
224  residue=r2)
225  hrc2 = [representation.hier_db.particle_to_name[p] for p in ps2]
226  ps2nosym = [
227  p for p in ps2 if IMP.pmi.Symmetric(
228  p).get_symmetric(
229  ) == 0]
230  hrc2nosym = [representation.hier_db.particle_to_name[p]
231  for p in ps2nosym]
232 
233  if len(ps2) == 0:
234  print("AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" % (r2, c2))
235  continue
236 
238  self.m,
239  ps1nosym,
240  self.cut_off,
241  self.lam,
242  True,
243  self.plateau)
244  cr.add_composite_particle(ps2)
245 
246  self.rs.add_restraint(cr)
247  self.pairs.append(
248  (ps1nosym,
249  hrc1nosym,
250  c1,
251  r1,
252  ps2,
253  hrc2,
254  c2,
255  r2,
256  cr))
257 
259  self.m,
260  ps1,
261  self.cut_off,
262  self.lam,
263  True,
264  self.plateau)
265  cr.add_composite_particle(ps2nosym)
266 
267  self.rs.add_restraint(cr)
268  self.pairs.append(
269  (ps1,
270  hrc1,
271  c1,
272  r1,
273  ps2nosym,
274  hrc2nosym,
275  c2,
276  r2,
277  cr))
278 
279  def plot_restraint(
280  self,
281  maxdist=100,
282  npoints=100):
283  import IMP.pmi.output as output
284 
285  p1 = IMP.Particle(self.m)
286  p2 = IMP.Particle(self.m)
290  self.m,
291  [p1],
292  self.cut_off,
293  self.lam,
294  True,
295  self.plateau)
296  cr.add_composite_particle([p2])
297  dists = []
298  scores = []
299  for i in range(npoints):
300  d2.set_coordinates(
301  IMP.algebra.Vector3D(maxdist / npoints * float(i), 0, 0))
302  dists.append(IMP.core.get_distance(d1, d2))
303  scores.append(cr.unprotected_evaluate(None))
304  output.plot_xy_data(dists, scores)
305 
306  def set_label(self, label):
307  self.label = label
308  self.rs.set_name(label)
309  for r in self.rs.get_restraints():
310  r.set_name(label)
311 
312  def add_to_model(self):
313  self.m.add_restraint(self.rs)
314 
315  def get_hierarchies(self):
316  return self.prot
317 
318  def get_restraint_sets(self):
319  return self.rs
320 
321  def get_restraint(self):
322  return self.rs
323 
324  def set_output_level(self, level="low"):
325  # this might be "low" or "high"
326  self.outputlevel = level
327 
328  def set_weight(self, weight):
329  self.weight = weight
330  self.rs.set_weight(weight)
331 
332  def get_output(self):
333  # content of the crosslink database pairs
334  # self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
335  self.m.update()
336 
337  output = {}
338  score = self.weight * self.rs.unprotected_evaluate(None)
339  output["_TotalScore"] = str(score)
340  output["AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
341  for n, p in enumerate(self.pairs):
342 
343  ps1 = p[0]
344  hrc1 = p[1]
345  c1 = p[2]
346  r1 = p[3]
347  ps2 = p[4]
348  hrc2 = p[5]
349  c2 = p[6]
350  r2 = p[7]
351  cr = p[8]
352  for n1, p1 in enumerate(ps1):
353  name1 = hrc1[n1]
354 
355  for n2, p2 in enumerate(ps2):
356  name2 = hrc2[n2]
357  d1 = IMP.core.XYZR(p1)
358  d2 = IMP.core.XYZR(p2)
359  label = str(r1) + ":" + name1 + "_" + str(r2) + ":" + name2
360  output["AmbiguousCompositeRestraint_Distance_" +
361  label] = str(IMP.core.get_distance(d1, d2))
362 
363  label = str(r1) + ":" + c1 + "_" + str(r2) + ":" + c2
364  output["AmbiguousCompositeRestraint_Score_" +
365  label] = str(self.weight * cr.unprotected_evaluate(None))
366 
367  return output
368 
369 
370 #
371 class SimplifiedPEMAP(object):
372 
373  def __init__(
374  self,
375  representation,
376  restraints_file,
377  expdistance,
378  strength,
379  resolution=None):
380 
381  self.m = representation.prot.get_model()
382  self.rs = IMP.RestraintSet(self.m, 'data')
383  self.label = "None"
384  self.pairs = []
385 
386  self.outputlevel = "low"
387  self.expdistance = expdistance
388  self.strength = strength
389 
390  fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
391 
392  for line in fl:
393 
394  tokens = line.split()
395  # skip character
396  if (tokens[0] == "#"):
397  continue
398  r1 = int(tokens[2])
399  c1 = tokens[0]
400  r2 = int(tokens[3])
401  c2 = tokens[1]
402  pcc = float(tokens[4])
403 
404  ps1 = IMP.pmi.tools.select(
405  representation,
406  resolution=resolution,
407  name=c1,
408  name_is_ambiguous=False,
409  residue=r1)
410  if len(ps1) == 0:
411  print("SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" % (r1, c1, r2, c2))
412  continue
413  if len(ps1) > 1:
414  print("SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" % (r1, c1))
415  continue
416 
417  ps2 = IMP.pmi.tools.select(
418  representation,
419  resolution=resolution,
420  name=c2,
421  name_is_ambiguous=False,
422  residue=r2)
423  if len(ps2) == 0:
424  print("SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" % (r1, c1, r2, c2))
425  continue
426  if len(ps2) > 1:
427  print("SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" % (r2, c2))
428  continue
429 
430  p1 = ps1[0]
431  p2 = ps2[0]
432 
433  # This is harmonic potential for the pE-MAP data
434  upperdist = self.get_upper_bond(pcc)
435  limit = self.strength * (upperdist + 15) ** 2 + 10.0
437  upperdist,
438  self.strength,
439  upperdist +
440  15,
441  limit)
442 
443  # This is harmonic for the X-link
444  #hub= IMP.core.TruncatedHarmonicBound(17.0,self.strength,upperdist+15,limit)
445 
447  dr = IMP.core.PairRestraint(df, (p1, p2))
448  self.rs.add_restraint(dr)
449  self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
450 
451  # Lower-bound restraint
452  lowerdist = self.get_lower_bond(pcc)
453  limit = self.strength * (lowerdist - 15) ** 2 + 10.0
455  lowerdist,
456  self.strength,
457  lowerdist +
458  15,
459  limit)
460 
461  # This is harmonic for the X-link
462  #hub2= IMP.core.TruncatedHarmonicBound(17.0,self.strength,upperdist+15,limit)
463 
465  dr2 = IMP.core.PairRestraint(df2, (p1, p2))
466  self.rs.add_restraint(dr2)
467  self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
468 
469  def get_upper_bond(self, pearsoncc):
470  # return (pearsoncc-1.)/-0.0075
471  return (pearsoncc - .5) / (-0.005415)
472 
473  def get_lower_bond(self, pearsoncc):
474  return (pearsoncc - 1.) / -0.0551
475 
476  def set_label(self, label):
477  self.label = label
478 
479  def add_to_model(self):
480  self.m.add_restraint(self.rs)
481 
482  def get_hierarchies(self):
483  return self.prot
484 
485  def get_restraint_sets(self):
486  return self.rs
487 
488  def set_output_level(self, level="low"):
489  # this might be "low" or "high"
490  self.outputlevel = level
491 
492  def get_output(self):
493  # content of the crosslink database pairs
494  # self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
495  self.m.update()
496 
497  output = {}
498  score = self.rs.unprotected_evaluate(None)
499  output["_TotalScore"] = str(score)
500  output["SimplifiedPEMAP_Score_" + self.label] = str(score)
501  for i in range(len(self.pairs)):
502 
503  p0 = self.pairs[i][0]
504  p1 = self.pairs[i][1]
505  crosslinker = 'standard'
506  ln = self.pairs[i][2]
507  resid1 = self.pairs[i][3]
508  chain1 = self.pairs[i][4]
509  resid2 = self.pairs[i][5]
510  chain2 = self.pairs[i][6]
511 
512  label = str(resid1) + ":" + chain1 + "_" + \
513  str(resid2) + ":" + chain2
514  output["SimplifiedPEMAP_Score_" + crosslinker + "_" +
515  label] = str(ln.unprotected_evaluate(None))
516 
517  d0 = IMP.core.XYZ(p0)
518  d1 = IMP.core.XYZ(p1)
519  output["SimplifiedPEMAP_Distance_" +
520  label] = str(IMP.core.get_distance(d0, d1))
521 
522  return output
A function that is harmonic over an interval.
this restraint allows ambiguous crosslinking between multiple copies excluding between symmetric copi...
Various classes to hold sets of particles.
Object used to hold a set of restraints.
Low level functionality (logging, error handling, profiling, command line flags etc) that is used by ...
Add symmetric attribute to a particle.
Definition: Symmetric.h:23
kernel::RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, kernel::RestraintSet *rs)
A score on the distance between the surfaces of two spheres.
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Definition: XYZR.h:87
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZR.h:48
A restraint for ambiguous cross-linking MS data and multiple state approach.
kernel::Restraint * create_connectivity_restraint(const Selections &s, double x0, double k, std::string name="Connectivity%1%")
Create a restraint connecting the selections.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
handleparticles is a selection tuple compositeparticles is a list of selection tuples ...
Class to handle individual model particles.
Classes for writing output files and processing them.
Definition: output.py:1
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...
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Applies a PairScore to a Pair.
Definition: PairRestraint.h:29
def select
this function uses representation=SimplifiedModel it returns the corresponding selected particles rep...
Definition: tools.py:633
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
Definition: Selection.h:62
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27