IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
crosslinking.py
1 """@namespace IMP.pmi.restraints.crosslinking
2 Restraints for handling crosslinking data.
3 """
4 
5 from __future__ import print_function
6 import IMP
7 import IMP.core
8 import IMP.algebra
9 import IMP.atom
10 import IMP.container
11 import IMP.pmi.tools
12 
14 
15  '''
16  this restraint allows ambiguous crosslinking between multiple copies
17  it is a variant of the SimplifiedCrossLinkMS
18  '''
19 
20  def __init__(
21  self,
22  representation,
23  restraints_file,
24  expdistance,
25  strength=None,
26  resolution=None):
27 
28  self.m = representation.prot.get_model()
29  self.rs = IMP.RestraintSet(self.m, 'data')
30  self.weight = 1.0
31  self.label = "None"
32  self.pairs = []
33 
34  self.outputlevel = "low"
35  self.expdistance = expdistance
36  self.strength = strength
37 
38  fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
39 
40  for line in fl:
41 
42  tokens = line.split()
43  # skip character
44  if (tokens[0] == "#"):
45  continue
46  r1 = int(tokens[2])
47  c1 = tokens[0]
48  r2 = int(tokens[3])
49  c2 = tokens[1]
50 
52  representation,
53  resolution=resolution,
54  name=c1,
55  name_is_ambiguous=True,
56  residue=r1)
57  hrc1 = [representation.hier_db.particle_to_name[p] for p in ps1]
58  if len(ps1) == 0:
59  print("ConnectivityCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
60  continue
61 
63  representation,
64  resolution=resolution,
65  name=c2,
66  name_is_ambiguous=True,
67  residue=r2)
68  hrc2 = [representation.hier_db.particle_to_name[p] for p in ps2]
69  if len(ps2) == 0:
70  print("ConnectivityCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
71  continue
72 
73  s1 = IMP.atom.Selection(ps1)
74  s2 = IMP.atom.Selection(ps2)
75 
76  # calculate the radii to estimate the slope of the restraint
77  if self.strength is None:
78  rad1 = 0
79  rad2 = 0
80  for p in ps1:
81  rad1 += IMP.pmi.Uncertainty(p).get_uncertainty()
82 
83  for p in ps2:
84  rad2 += IMP.pmi.Uncertainty(p).get_uncertainty()
85 
86  rad1 = rad1 / len(ps1)
87  rad2 = rad2 / len(ps2)
88 
89  self.strength = 1 / (rad1 ** 2 + rad2 ** 2)
90 
91  sels = [s1, s2]
93  sels,
94  self.expdistance,
95  self.strength)
96 
97  self.rs.add_restraint(cr)
98  self.pairs.append((ps1, hrc1, c1, r1, ps2, hrc2, c2, r2, cr))
99 
100  def plot_restraint(
101  self,
102  uncertainty1,
103  uncertainty2,
104  maxdist=50,
105  npoints=10):
106  import IMP.pmi.output as output
107 
108  p1 = IMP.Particle(self.m)
109  p2 = IMP.Particle(self.m)
112  d1.set_radius(uncertainty1)
113  d2.set_radius(uncertainty2)
114  s1 = IMP.atom.Selection(p1)
115  s2 = IMP.atom.Selection(p2)
116  sels = [s1, s2]
117  strength = 1 / (uncertainty1 ** 2 + uncertainty2 ** 2)
119  sels,
120  self.expdistance,
121  strength)
122  dists = []
123  scores = []
124  for i in range(npoints):
125  d2.set_coordinates(
126  IMP.algebra.Vector3D(maxdist / npoints * float(i), 0, 0))
127  dists.append(IMP.core.get_distance(d1, d2))
128  scores.append(cr.unprotected_evaluate(None))
129  output.plot_xy_data(dists, scores)
130 
131  def set_label(self, label):
132  self.label = label
133  self.rs.set_name(label)
134  for r in self.rs.get_restraints():
135  r.set_name(label)
136 
137  def add_to_model(self):
138  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
139 
140  def get_restraint_sets(self):
141  return self.rs
142 
143  def get_restraint(self):
144  return self.rs
145 
146  def set_output_level(self, level="low"):
147  # this might be "low" or "high"
148  self.outputlevel = level
149 
150  def set_weight(self, weight):
151  self.weight = weight
152  self.rs.set_weight(weight)
153 
154  def get_output(self):
155  # content of the crosslink database pairs
156  # self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
157  self.m.update()
158 
159  output = {}
160  score = self.weight * self.rs.unprotected_evaluate(None)
161  output["_TotalScore"] = str(score)
162  output["ConnectivityCrossLinkMS_Score_" + self.label] = str(score)
163  for n, p in enumerate(self.pairs):
164 
165  ps1 = p[0]
166  hrc1 = p[1]
167  c1 = p[2]
168  r1 = p[3]
169  ps2 = p[4]
170  hrc2 = p[5]
171  c2 = p[6]
172  r2 = p[7]
173  cr = p[8]
174  for n1, p1 in enumerate(ps1):
175  name1 = hrc1[n1]
176 
177  for n2, p2 in enumerate(ps2):
178  name2 = hrc2[n2]
179  d1 = IMP.core.XYZR(p1)
180  d2 = IMP.core.XYZR(p2)
181  label = str(r1) + ":" + name1 + "_" + str(r2) + ":" + name2
182  output["ConnectivityCrossLinkMS_Distance_" +
183  label] = str(IMP.core.get_distance(d1, d2))
184 
185  label = str(r1) + ":" + c1 + "_" + str(r2) + ":" + c2
186  output["ConnectivityCrossLinkMS_Score_" +
187  label] = str(self.weight * cr.unprotected_evaluate(None))
188 
189  return output
190 
191 
192 class SimplifiedCrossLinkMS(object):
193 
194  def __init__(
195  self,
196  representation,
197  restraints_file,
198  expdistance,
199  strength,
200  resolution=None,
201  columnmapping=None,
202  truncated=True,
203  spheredistancepairscore=True):
204  # columnindexes is a list of column indexes for protein1, protein2, residue1, residue2
205  # by default column 0 = protein1; column 1 = protein2; column 2 =
206  # residue1; column 3 = residue2
207 
208  if columnmapping is None:
209  columnmapping = {}
210  columnmapping["Protein1"] = 0
211  columnmapping["Protein2"] = 1
212  columnmapping["Residue1"] = 2
213  columnmapping["Residue2"] = 3
214 
215  self.m = representation.prot.get_model()
216  self.rs = IMP.RestraintSet(self.m, 'data')
217  self.weight = 1.0
218  self.label = "None"
219  self.pairs = []
220  self.already_added_pairs = {}
221 
222  self.outputlevel = "low"
223  self.expdistance = expdistance
224  self.strength = strength
225  self.truncated = truncated
226  self.spheredistancepairscore = spheredistancepairscore
227 
228  # fill the cross-linker pmfs
229  # to accelerate the init the list listofxlinkertypes might contain only
230  # yht needed crosslinks
231  protein1 = columnmapping["Protein1"]
232  protein2 = columnmapping["Protein2"]
233  residue1 = columnmapping["Residue1"]
234  residue2 = columnmapping["Residue2"]
235 
236  fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
237 
238  for line in fl:
239 
240  tokens = line.split()
241  # skip character
242  if (tokens[0] == "#"):
243  continue
244  r1 = int(tokens[residue1])
245  c1 = tokens[protein1]
246  r2 = int(tokens[residue2])
247  c2 = tokens[protein2]
248 
249  ps1 = IMP.pmi.tools.select(
250  representation,
251  resolution=resolution,
252  name=c1,
253  name_is_ambiguous=False,
254  residue=r1)
255  ps2 = IMP.pmi.tools.select(
256  representation,
257  resolution=resolution,
258  name=c2,
259  name_is_ambiguous=False,
260  residue=r2)
261 
262  if len(ps1) > 1:
263  raise ValueError(
264  "residue %d of chain %s selects multiple particles; "
265  "particles are: %s"
266  % (r1, c1, "".join(p.get_name() for p in ps1)))
267  elif len(ps1) == 0:
268  print("SimplifiedCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
269  continue
270 
271  if len(ps2) > 1:
272  raise ValueError(
273  "residue %d of chain %s selects multiple particles; "
274  "particles are: %s"
275  % (r2, c2, "".join(p.get_name() for p in ps2)))
276  elif len(ps2) == 0:
277  print("SimplifiedCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
278  continue
279 
280  p1 = ps1[0]
281  p2 = ps2[0]
282 
283  if (p1, p2) in self.already_added_pairs:
284  dr = self.already_added_pairs[(p1, p2)]
285  weight = dr.get_weight()
286  dr.set_weight(weight + 1.0)
287  print("SimplifiedCrossLinkMS> crosslink %d %s %d %s was already found, adding 1.0 to the weight, weight is now %d" % (r1, c1, r2, c2, weight + 1.0))
288  continue
289 
290  else:
291 
292  if self.truncated:
293  limit = self.strength * (self.expdistance + 15) ** 2 + 10.0
295  self.expdistance,
296  self.strength,
297  self.expdistance +
298  15.,
299  limit)
300  else:
302  self.expdistance,
303  self.strength)
304  if self.spheredistancepairscore:
306  else:
308  dr = IMP.core.PairRestraint(df, (p1, p2))
309  dr.set_name(c1 + ":" + str(r1) + "-" + c2 + ":" + str(r2))
310 
311  self.rs.add_restraint(dr)
312  self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
313  self.already_added_pairs[(p1, p2)] = dr
314  self.already_added_pairs[(p2, p1)] = dr
315 
316  def set_label(self, label):
317  self.label = label
318 
319  def add_to_model(self):
320  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
321 
322  def get_restraint_sets(self):
323  return self.rs
324 
325  def get_restraint(self):
326  return self.rs
327 
328  def get_restraints(self):
329  rlist = []
330  for r in self.rs.get_restraints():
331  rlist.append(IMP.core.PairRestraint.get_from(r))
332  return rlist
333 
334  def get_particle_pairs(self):
335  ppairs = []
336  for i in range(len(self.pairs)):
337  p0 = self.pairs[i][0]
338  p1 = self.pairs[i][1]
339  ppairs.append((p0, p1))
340  return ppairs
341 
342  def set_output_level(self, level="low"):
343  # this might be "low" or "high"
344  self.outputlevel = level
345 
346  def set_weight(self, weight):
347  self.weight = weight
348  self.rs.set_weight(weight)
349 
350  def plot_restraint(self, radius1, radius2, maxdist=50, npoints=10):
351  import IMP.pmi.output as output
352 
353  p1 = IMP.Particle(self.m)
354  p2 = IMP.Particle(self.m)
357  d1.set_radius(radius1)
358  d2.set_radius(radius2)
359  if self.truncated:
360  limit = self.strength * (self.expdistance + 15) ** 2 + 10.0
362  self.expdistance,
363  self.strength,
364  self.expdistance +
365  15.,
366  limit)
367  else:
369  self.expdistance,
370  self.strength)
372  dr = IMP.core.PairRestraint(df, (p1, p2))
373  dists = []
374  scores = []
375  for i in range(npoints):
376  d2.set_coordinates(
377  IMP.algebra.Vector3D(maxdist / npoints * float(i), 0, 0))
378  dists.append(IMP.core.get_distance(d1, d2))
379  scores.append(dr.unprotected_evaluate(None))
380  output.plot_xy_data(dists, scores)
381 
382  def get_output(self):
383  # content of the crosslink database pairs
384  # self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
385  self.m.update()
386 
387  output = {}
388  score = self.weight * self.rs.unprotected_evaluate(None)
389  output["_TotalScore"] = str(score)
390  output["SimplifiedCrossLinkMS_Score_" + self.label] = str(score)
391  for i in range(len(self.pairs)):
392 
393  p0 = self.pairs[i][0]
394  p1 = self.pairs[i][1]
395  crosslinker = 'standard'
396  ln = self.pairs[i][2]
397  resid1 = self.pairs[i][3]
398  chain1 = self.pairs[i][4]
399  resid2 = self.pairs[i][5]
400  chain2 = self.pairs[i][6]
401 
402  label = str(resid1) + ":" + chain1 + "_" + \
403  str(resid2) + ":" + chain2
404  output["SimplifiedCrossLinkMS_Score_" + crosslinker + "_" +
405  label] = str(self.weight * ln.unprotected_evaluate(None))
406 
407  if self.spheredistancepairscore:
408  d0 = IMP.core.XYZR(p0)
409  d1 = IMP.core.XYZR(p1)
410  else:
411  d0 = IMP.core.XYZ(p0)
412  d1 = IMP.core.XYZ(p1)
413  output["SimplifiedCrossLinkMS_Distance_" +
414  label] = str(IMP.core.get_distance(d0, d1))
415 
416  return output
417 
418 #
419 
420 
421 class SigmoidalCrossLinkMS(object):
422 
423  def __init__(
424  self, representation, restraints_file, inflection, slope, amplitude,
425  linear_slope, resolution=None, columnmapping=None, csvfile=False,
426  filters=None, filelabel="None"):
427  # columnindexes is a list of column indexes for protein1, protein2, residue1, residue2
428  # by default column 0 = protein1; column 1 = protein2; column 2 = residue1; column 3 = residue2
429  # the filters applies to the csvfile, the format is
430  # filters=[("Field1",">|<|=|>=|<=",value),("Field2","is","String"),("Field2","in","String")]
431  import IMP.pmi.tools as tools
432 
433  if columnmapping is None:
434  columnmapping = {}
435  columnmapping["Protein1"] = 0
436  columnmapping["Protein2"] = 1
437  columnmapping["Residue1"] = 2
438  columnmapping["Residue2"] = 3
439 
440  if csvfile:
441  # in case the file is a cvs file
442  # columnmapping will contain the field names
443  # that compare in the first line of the cvs file
444  db = tools.get_db_from_csv(restraints_file)
445  else:
446  db = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
447 
448  self.m = representation.prot.get_model()
449  self.rs = IMP.RestraintSet(self.m, 'data')
450  self.weight = 1.0
451 
452  self.label = "None"
453  self.pairs = []
454  self.already_added_pairs = {}
455  self.inflection = inflection
456  self.slope = slope
457  self.amplitude = amplitude
458  self.linear_slope = linear_slope
459 
460  self.outputlevel = "low"
461 
462  # fill the cross-linker pmfs
463  # to accelerate the init the list listofxlinkertypes might contain only
464  # yht needed crosslinks
465  protein1 = columnmapping["Protein1"]
466  protein2 = columnmapping["Protein2"]
467  residue1 = columnmapping["Residue1"]
468  residue2 = columnmapping["Residue2"]
469 
470  indb = open("included." + filelabel + ".xl.db", "w")
471  exdb = open("excluded." + filelabel + ".xl.db", "w")
472  midb = open("missing." + filelabel + ".xl.db", "w")
473 
474  for entry in db:
475  if not csvfile:
476  tokens = entry.split()
477  # skip character
478  if (tokens[0] == "#"):
479  continue
480  r1 = int(tokens[residue1])
481  c1 = tokens[protein1]
482  r2 = int(tokens[residue2])
483  c2 = tokens[protein2]
484  else:
485  if filters is not None:
486  if eval(tools.cross_link_db_filter_parser(filters)) == False:
487  exdb.write(str(entry) + "\n")
488  continue
489  indb.write(str(entry) + "\n")
490  r1 = int(entry[residue1])
491  c1 = entry[protein1]
492  r2 = int(entry[residue2])
493  c2 = entry[protein2]
494 
495  ps1 = IMP.pmi.tools.select(
496  representation,
497  resolution=resolution,
498  name=c1,
499  name_is_ambiguous=False,
500  residue=r1)
501  ps2 = IMP.pmi.tools.select(
502  representation,
503  resolution=resolution,
504  name=c2,
505  name_is_ambiguous=False,
506  residue=r2)
507 
508  if len(ps1) > 1:
509  raise ValueError("residue %d of chain %s selects multiple particles %s" % (r1, c1, str(ps1)))
510  elif len(ps1) == 0:
511  print("SigmoidalCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
512  midb.write(str(entry) + "\n")
513  continue
514 
515  if len(ps2) > 1:
516  raise ValueError("residue %d of chain %s selects multiple particles %s" % (r2, c2, str(ps2)))
517  elif len(ps2) == 0:
518  print("SigmoidalCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
519  midb.write(str(entry) + "\n")
520  continue
521 
522  p1 = ps1[0]
523  p2 = ps2[0]
524 
525  if (p1, p2) in self.already_added_pairs:
526  dr = self.already_added_pairs[(p1, p2)]
527  weight = dr.get_weight()
528  dr.increment_amplitude(amplitude)
529  print("SigmoidalCrossLinkMS> crosslink %d %s %d %s was already found, adding %d to the amplitude, amplitude is now %d" % (r1, c1, r2, c2, amplitude, dr.get_amplitude()))
530  dr.set_name(c1 + ":" + str(r1) + "-" + c2 + ":" + str(r2)
531  + "-ampl:" + str(dr.get_amplitude()))
532  continue
533 
534  else:
535 
537  self.m,
538  p1,
539  p2,
540  self.inflection,
541  self.slope,
542  self.amplitude,
543  self.linear_slope)
544  dr.set_name(c1 + ":" + str(r1) + "-" + c2 + ":" + str(r2)
545  + "-ampl:" + str(dr.get_amplitude()))
546 
547  self.rs.add_restraint(dr)
548 
549  self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
550  self.already_added_pairs[(p1, p2)] = dr
551  self.already_added_pairs[(p2, p1)] = dr
552 
553  def set_label(self, label):
554  self.label = label
555 
556  def add_to_model(self):
557  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
558 
559  def get_restraint_sets(self):
560  return self.rs
561 
562  def get_restraint(self):
563  return self.rs
564 
565  def get_restraints(self):
566  rlist = []
567  for r in self.rs.get_restraints():
568  rlist.append(IMP.core.PairRestraint.get_from(r))
569  return rlist
570 
571  def get_particle_pairs(self):
572  ppairs = []
573  for i in range(len(self.pairs)):
574  p0 = self.pairs[i][0]
575  p1 = self.pairs[i][1]
576  ppairs.append((p0, p1))
577  return ppairs
578 
579  def set_output_level(self, level="low"):
580  # this might be "low" or "high"
581  self.outputlevel = level
582 
583  def set_weight(self, weight):
584  self.weight = weight
585  self.rs.set_weight(weight)
586 
587  def plot_restraint(self, radius1, radius2, maxdist=50, npoints=10):
588  import IMP.pmi.output as output
589 
590  p1 = IMP.Particle(self.m)
591  p2 = IMP.Particle(self.m)
594  d1.set_radius(radius1)
595  d2.set_radius(radius2)
597  self.m,
598  p1,
599  p2,
600  self.inflection,
601  self.slope,
602  self.amplitude,
603  self.linear_slope)
604  dists = []
605  scores = []
606  for i in range(npoints):
607  d2.set_coordinates(
608  IMP.algebra.Vector3D(maxdist / npoints * float(i), 0, 0))
609  dists.append(IMP.core.get_distance(d1, d2))
610  scores.append(dr.unprotected_evaluate(None))
611  output.plot_xy_data(dists, scores)
612 
613  def get_output(self):
614  # content of the crosslink database pairs
615  # self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
616  self.m.update()
617 
618  output = {}
619  score = self.weight * self.rs.unprotected_evaluate(None)
620  output["_TotalScore"] = str(score)
621  output["SigmoidalCrossLinkMS_Score_" + self.label] = str(score)
622  for i in range(len(self.pairs)):
623 
624  p0 = self.pairs[i][0]
625  p1 = self.pairs[i][1]
626  crosslinker = 'standard'
627  ln = self.pairs[i][2]
628  resid1 = self.pairs[i][3]
629  chain1 = self.pairs[i][4]
630  resid2 = self.pairs[i][5]
631  chain2 = self.pairs[i][6]
632 
633  label = str(resid1) + ":" + chain1 + "_" + \
634  str(resid2) + ":" + chain2
635  output["SigmoidalCrossLinkMS_Score_" + crosslinker + "_" +
636  label + "_" + self.label] = str(self.weight * ln.unprotected_evaluate(None))
637  d0 = IMP.core.XYZR(p0)
638  d1 = IMP.core.XYZR(p1)
639  output["SigmoidalCrossLinkMS_Distance_" +
640  label + "_" + self.label] = str(IMP.core.get_distance(d0, d1))
641 
642  return output
643 
644 
645 class ISDCrossLinkMS(IMP.pmi.restraints._NuisancesBase):
646  import IMP.isd
647  try:
648  import IMP.isd_emxl
649  no_isd_emxl = False
650  except:
651  no_isd_emxl = True
652  import IMP.pmi.tools
653  from math import log
654 
655  def __init__(self, representation,
656  restraints_file,
657  length,
658  jackknifing=None,
659  # jackknifing (Float [0,1]) default=None; percentage of data to be
660  # removed randomly
661  resolution=None,
662  # resolution (Non-negative Integer) default=None; percentage of data
663  # to be removed randomly
664  slope=0.0,
665  inner_slope=0.0,
666  columnmapping=None,
667  rename_dict=None,
668  offset_dict=None,
669  csvfile=False,
670  ids_map=None,
671  radius_map=None,
672  filters=None,
673  label="None",
674  filelabel="None",
675  automatic_sigma_classification=False,
676  attributes_for_label=None):
677 
678  # columnindexes is a list of column indexes for protein1, protein2, residue1, residue2,idscore, XL unique id
679  # by default column 0 = protein1; column 1 = protein2; column 2 = residue1; column 3 = residue2;
680  # column 4 = idscores
681  # attributes_for_label: anithing in the csv database that must be added to the label
682  # slope is the slope defined on the linear function
683  # inner_slope is the slope defined on the restraint dierectly
684  # suggestion: do not use both!
685 
686  if type(representation) != list:
687  representations = [representation]
688  else:
689  representations = representation
690 
691  if columnmapping is None:
692  columnmapping = {}
693  columnmapping["Protein1"] = 0
694  columnmapping["Protein2"] = 1
695  columnmapping["Residue1"] = 2
696  columnmapping["Residue2"] = 3
697  columnmapping["IDScore"] = 4
698  columnmapping["XLUniqueID"] = 5
699 
700  if csvfile:
701  # in case the file is a cvs file
702  # columnmapping will contain the field names
703  # that compare in the first line of the cvs file
704  db = IMP.pmi.tools.get_db_from_csv(restraints_file)
705  else:
706  db = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
707 
708  indb = open("included." + filelabel + ".xl.db", "w")
709  exdb = open("excluded." + filelabel + ".xl.db", "w")
710  midb = open("missing." + filelabel + ".xl.db", "w")
711 
712  self.m = representations[0].prot.get_model()
713  self.rs = IMP.RestraintSet(self.m, 'data')
714  self.rspsi = IMP.RestraintSet(self.m, 'prior_psi')
715  self.rssig = IMP.RestraintSet(self.m, 'prior_sigmas')
716  self.rslin = IMP.RestraintSet(self.m, 'prior_linear')
717  self.rslen = IMP.RestraintSet(self.m, 'prior_length')
718 
719  self.label = label
720  self.pairs = []
721  self.sigma_dictionary = {}
722  self.psi_dictionary = {}
723  self.psi_is_sampled = True
724  self.sigma_is_sampled = True
725 
726  # isd_map is a dictionary/map that is used to determine the psi
727  # parameter from identity scores (such as ID-Score, or FDR)
728  if ids_map is None:
729  self.ids_map = IMP.pmi.tools.map()
730  self.ids_map.set_map_element(20.0, 0.05)
731  self.ids_map.set_map_element(65.0, 0.01)
732  else:
733  self.ids_map = ids_map
734 
735  if radius_map is None:
736  self.radius_map = IMP.pmi.tools.map()
737  if automatic_sigma_classification:
738  self.radius_map.set_map_element(10, 10)
739  self.radius_map.set_map_element(1, 1)
740  else:
741  self.radius_map = radius_map
742 
743  self.outputlevel = "low"
744 
745  # small linear contribution for long range
746  self.linear = IMP.core.Linear(0, 0.0)
747  self.linear.set_slope(slope)
748  dps2 = IMP.core.DistancePairScore(self.linear)
749 
750  protein1 = columnmapping["Protein1"]
751  protein2 = columnmapping["Protein2"]
752  residue1 = columnmapping["Residue1"]
753  residue2 = columnmapping["Residue2"]
754  idscore = columnmapping["IDScore"]
755  try:
756  xluniqueid = columnmapping["XLUniqueID"]
757  except:
758  xluniqueid = None
759 
760  restraints = []
761 
762  # we need this dictionary to create ambiguity (i.e., multistate)
763  # if one id is already present in the dictionary, add the term to the
764  # corresponding already geenrated restraint
765 
766  uniqueid_restraints_map = {}
767 
768  for nxl, entry in enumerate(db):
769 
770  if not jackknifing is None:
771 
772  # to be implemented
773  # the problem is that in the replica exchange
774  # you have to broadcast the same restraints to every
775  # replica
776 
777  raise NotImplementedError("jackknifing not yet implemented")
778 
779  if not csvfile:
780  tokens = entry.split()
781  if len(tokens)==0:
782  continue
783 
784  # skip character
785  if (tokens[0] == "#"):
786  continue
787  try:
788  r1 = int(tokens[residue1])
789  c1 = tokens[protein1]
790  r2 = int(tokens[residue2])
791  c2 = tokens[protein2]
792 
793  if offset_dict is not None:
794  if c1 in offset_dict: r1+=offset_dict[c1]
795  if c2 in offset_dict: r2+=offset_dict[c2]
796 
797  if rename_dict is not None:
798  if c1 in rename_dict: c1=rename_dict[c1]
799  if c2 in rename_dict: c2=rename_dict[c2]
800 
801  if idscore is None:
802  ids = 1.0
803  else:
804  ids = float(tokens[idscore])
805  if xluniqueid is None:
806  xlid = str(nxl)
807  else:
808  xlid = tokens[xluniqueid]
809  except:
810  print("this line was not accessible " + str(entry))
811  if residue1 not in entry: print(str(residue1)+" keyword not in database")
812  if residue2 not in entry: print(str(residue2)+" keyword not in database")
813  if protein1 not in entry: print(str(protein1)+" keyword not in database")
814  if protein2 not in entry: print(str(protein2)+" keyword not in database")
815  if idscore not in entry: print(str(idscore)+" keyword not in database")
816  if xluniqueid not in entry: print(str(xluniqueid)+" keyword not in database")
817  continue
818 
819  else:
820  if filters is not None:
821  if eval(IMP.pmi.tools.cross_link_db_filter_parser(filters)) == False:
822  exdb.write(str(entry) + "\n")
823  continue
824 
825  try:
826  r1 = int(entry[residue1])
827  c1 = entry[protein1]
828  r2 = int(entry[residue2])
829  c2 = entry[protein2]
830 
831  if offset_dict is not None:
832  if c1 in offset_dict: r1+=offset_dict[c1]
833  if c2 in offset_dict: r2+=offset_dict[c2]
834 
835  if rename_dict is not None:
836  if c1 in rename_dict: c1=rename_dict[c1]
837  if c2 in rename_dict: c2=rename_dict[c2]
838 
839  if idscore is None:
840  ids = 1.0
841  else:
842  try:
843  ids = float(entry[idscore])
844  except ValueError:
845  ids = entry[idscore]
846  if xluniqueid is None:
847  xlid = str(nxl)
848  else:
849  xlid = entry[xluniqueid]
850 
851  except:
852  print("this line was not accessible " + str(entry))
853  if residue1 not in entry: print(str(residue1)+" keyword not in database")
854  if residue2 not in entry: print(str(residue2)+" keyword not in database")
855  if protein1 not in entry: print(str(protein1)+" keyword not in database")
856  if protein2 not in entry: print(str(protein2)+" keyword not in database")
857  if idscore not in entry: print(str(idscore)+" keyword not in database")
858  if xluniqueid not in entry: print(str(xluniqueid)+" keyword not in database")
859  continue
860 
861  for nstate, r in enumerate(representations):
862  # loop over every state
863 
864  ps1 = IMP.pmi.tools.select(
865  r,
866  resolution=resolution,
867  name=c1,
868  name_is_ambiguous=False,
869  residue=r1)
870  ps2 = IMP.pmi.tools.select(
871  r,
872  resolution=resolution,
873  name=c2,
874  name_is_ambiguous=False,
875  residue=r2)
876 
877  if len(ps1) > 1:
878  raise ValueError("residue %d of chain %s selects multiple particles %s" % (r1, c1, str(ps1)))
879  elif len(ps1) == 0:
880  print("ISDCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
881  midb.write(str(entry) + "\n")
882  continue
883 
884  if len(ps2) > 1:
885  raise ValueError("residue %d of chain %s selects multiple particles %s" % (r2, c2, str(ps2)))
886  elif len(ps2) == 0:
887  print("ISDCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
888  midb.write(str(entry) + "\n")
889  continue
890 
891  p1 = ps1[0]
892  p2 = ps2[0]
893 
894  if (p1 == p2) and (r1 == r2) :
895  print("ISDCrossLinkMS Restraint: WARNING> on the identical bead particles and the identical residues, thus skipping this cross-link.")
896  continue
897 
898  if xlid in uniqueid_restraints_map:
899  print("Appending a crosslink restraint into the uniqueID %s" % str(xlid))
900  dr = uniqueid_restraints_map[xlid]
901  else:
902  print("Generating a NEW crosslink restraint with an uniqueID %s" % str(xlid))
904  self.m,
905  length,
906  inner_slope)
907  restraints.append(dr)
908  uniqueid_restraints_map[xlid] = dr
909 
910  mappedr1 = self.radius_map.get_map_element(
911  IMP.pmi.Uncertainty(p1).get_uncertainty())
912  sigma1 = self.get_sigma(mappedr1)[0]
913  mappedr2 = self.radius_map.get_map_element(
914  IMP.pmi.Uncertainty(p2).get_uncertainty())
915  sigma2 = self.get_sigma(mappedr2)[0]
916 
917  psival = self.ids_map.get_map_element(ids)
918  psi = self.get_psi(psival)[0]
919 
920 
921  p1i = p1.get_particle_index()
922  p2i = p2.get_particle_index()
923  s1i = sigma1.get_particle().get_index()
924  s2i = sigma2.get_particle().get_index()
925 
926  #print nstate, p1i, p2i, p1.get_name(), p2.get_name()
927 
928  psii = psi.get_particle().get_index()
929 
930  dr.add_contribution((p1i, p2i), (s1i, s2i), psii)
931  print("--------------")
932  print("ISDCrossLinkMS: generating cross-link restraint between")
933  print("ISDCrossLinkMS: residue %d of chain %s and residue %d of chain %s" % (r1, c1, r2, c2))
934  print("ISDCrossLinkMS: with sigma1 %f sigma2 %f psi %s" % (mappedr1, mappedr2, psival))
935  print("ISDCrossLinkMS: between particles %s and %s" % (p1.get_name(), p2.get_name()))
936  print("==========================================\n")
937  indb.write(str(entry) + "\n")
938 
939  # check if the two residues belong to the same rigid body
942  IMP.core.RigidMember(p1).get_rigid_body() ==
943  IMP.core.RigidMember(p2).get_rigid_body()):
944  xlattribute = "intrarb"
945  else:
946  xlattribute = "interrb"
947 
948  if csvfile:
949  if not attributes_for_label is None:
950  for a in attributes_for_label:
951  xlattribute = xlattribute + "_" + str(entry[a])
952 
953  xlattribute = xlattribute + "-State:" + str(nstate)
954 
955  dr.set_name(
956  xlattribute + "-" + c1 + ":" + str(r1) + "-" + c2 + ":" + str(r2) + "_" + self.label)
957 
958  if p1i != p2i:
959  pr = IMP.core.PairRestraint(self.m, dps2, (p1i, p2i))
960  pr.set_name(
961  xlattribute + "-" + c1 + ":" + str(r1) + "-" + c2 + ":" + str(r2) + "_" + self.label)
962  self.rslin.add_restraint(pr)
963 
964 
965  self.pairs.append(
966  (p1,
967  p2,
968  dr,
969  r1,
970  c1,
971  r2,
972  c2,
973  xlattribute,
974  mappedr1,
975  mappedr2,
976  psival,
977  xlid,
978  nstate,
979  ids))
980 
981  lw = IMP.isd.LogWrapper(restraints,1.0)
982  self.rs.add_restraint(lw)
983 
984 
985  def set_slope_linear_term(self, slope):
986  self.linear.set_slope(slope)
987 
988  def set_label(self, label):
989  self.label = label
990 
991  def add_to_model(self):
992  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
993  IMP.pmi.tools.add_restraint_to_model(self.m, self.rspsi)
994  IMP.pmi.tools.add_restraint_to_model(self.m, self.rssig)
995  IMP.pmi.tools.add_restraint_to_model(self.m, self.rslen)
996  IMP.pmi.tools.add_restraint_to_model(self.m, self.rslin)
997 
998  def get_hierarchies(self):
999  return self.prot
1000 
1001  def get_restraint_sets(self):
1002  return self.rs
1003 
1004  def get_restraint(self):
1005  return self.rs
1006 
1007  def get_restraint_for_rmf(self):
1008  return self.rslin
1009 
1010  def get_restraints(self):
1011  rlist = []
1012  for r in self.rs.get_restraints():
1013  rlist.append(IMP.core.PairRestraint.get_from(r))
1014  return rlist
1015 
1016  def get_particle_pairs(self):
1017  ppairs = []
1018  for i in range(len(self.pairs)):
1019  p0 = self.pairs[i][0]
1020  p1 = self.pairs[i][1]
1021  ppairs.append((p0, p1))
1022  return ppairs
1023 
1024  def set_output_level(self, level="low"):
1025  # this might be "low" or "high"
1026  self.outputlevel = level
1027 
1028  def set_psi_is_sampled(self, is_sampled=True):
1029  self.psi_is_sampled = is_sampled
1030 
1031  def set_sigma_is_sampled(self, is_sampled=True):
1032  self.sigma_is_sampled = is_sampled
1033 
1034  def get_label(self,pairs_index):
1035  resid1 = self.pairs[pairs_index][3]
1036  chain1 = self.pairs[pairs_index][4]
1037  resid2 = self.pairs[pairs_index][5]
1038  chain2 = self.pairs[pairs_index][6]
1039  attribute = self.pairs[pairs_index][7]
1040  rad1 = self.pairs[pairs_index][8]
1041  rad2 = self.pairs[pairs_index][9]
1042  psi = self.pairs[pairs_index][10]
1043  xlid= self.pairs[pairs_index][11]
1044  label = attribute + "-" + \
1045  str(resid1) + ":" + chain1 + "_" + str(resid2) + ":" + \
1046  chain2 + "-" + str(rad1) + "-" + str(rad2) + "-" + str(psi)
1047  return label
1048 
1049  def write_db(self,filename):
1050  import IMP.pmi.output
1051  cldb=IMP.pmi.output.CrossLinkIdentifierDatabase()
1052 
1053  for pairs_index in range(len(self.pairs)):
1054 
1055  resid1 = self.pairs[pairs_index][3]
1056  chain1 = self.pairs[pairs_index][4]
1057  resid2 = self.pairs[pairs_index][5]
1058  chain2 = self.pairs[pairs_index][6]
1059  attribute = self.pairs[pairs_index][7]
1060  rad1 = self.pairs[pairs_index][8]
1061  rad2 = self.pairs[pairs_index][9]
1062  psi = self.pairs[pairs_index][10]
1063  xlid= self.pairs[pairs_index][11]
1064  nstate=self.pairs[pairs_index][12]
1065  ids=self.pairs[pairs_index][13]
1066 
1067  label=self.get_label(pairs_index)
1068  cldb.set_unique_id(label,xlid)
1069  cldb.set_protein1(label,chain1)
1070  cldb.set_protein2(label,chain2)
1071  cldb.set_residue1(label,resid1)
1072  cldb.set_residue2(label,resid2)
1073  cldb.set_idscore(label,ids)
1074  cldb.set_state(label,nstate)
1075  cldb.set_sigma1(label,rad1)
1076  cldb.set_sigma2(label,rad2)
1077  cldb.set_psi(label,psi)
1078  cldb.write(filename)
1079 
1080 
1081  def get_output(self):
1082  # content of the crosslink database pairs
1083  # self.pairs.append((p1,p2,dr,r1,c1,r2,c2))
1084  self.m.update()
1085 
1086  output = {}
1087  score = self.rs.unprotected_evaluate(None)
1088  output["_TotalScore"] = str(score)
1089  output["ISDCrossLinkMS_Data_Score_" + self.label] = str(score)
1090  output["ISDCrossLinkMS_PriorSig_Score_" +
1091  self.label] = self.rssig.unprotected_evaluate(None)
1092  output["ISDCrossLinkMS_PriorPsi_Score_" +
1093  self.label] = self.rspsi.unprotected_evaluate(None)
1094  output["ISDCrossLinkMS_Linear_Score_" +
1095  self.label] = self.rslin.unprotected_evaluate(None)
1096  for i in range(len(self.pairs)):
1097 
1098  label=self.get_label(i)
1099  ln = self.pairs[i][2]
1100  p0 = self.pairs[i][0]
1101  p1 = self.pairs[i][1]
1102  output["ISDCrossLinkMS_Score_" +
1103  label + "_" + self.label] = str(-self.log(ln.unprotected_evaluate(None)))
1104 
1105  d0 = IMP.core.XYZ(p0)
1106  d1 = IMP.core.XYZ(p1)
1107  output["ISDCrossLinkMS_Distance_" +
1108  label + "_" + self.label] = str(IMP.core.get_distance(d0, d1))
1109 
1110 
1111  for psiindex in self.psi_dictionary:
1112  output["ISDCrossLinkMS_Psi_" +
1113  str(psiindex) + "_" + self.label] = str(self.psi_dictionary[psiindex][0].get_scale())
1114 
1115  for resolution in self.sigma_dictionary:
1116  output["ISDCrossLinkMS_Sigma_" +
1117  str(resolution) + "_" + self.label] = str(self.sigma_dictionary[resolution][0].get_scale())
1118 
1119 
1120  return output
1121 
1122  def get_particles_to_sample(self):
1123  ps = {}
1124 
1125  for resolution in self.sigma_dictionary:
1126  if self.sigma_dictionary[resolution][2] and self.sigma_is_sampled:
1127  ps["Nuisances_ISDCrossLinkMS_Sigma_" + str(resolution) + "_" + self.label] =\
1128  ([self.sigma_dictionary[resolution][0]],
1129  self.sigma_dictionary[resolution][1])
1130 
1131  if self.psi_is_sampled:
1132  for psiindex in self.psi_dictionary:
1133  if self.psi_dictionary[psiindex][2]:
1134  ps["Nuisances_ISDCrossLinkMS_Psi_" +
1135  str(psiindex) + "_" + self.label] = ([self.psi_dictionary[psiindex][0]], self.psi_dictionary[psiindex][1])
1136 
1137  return ps
1138 
1139 #
1140 class CysteineCrossLinkRestraint(object):
1141 
1142  import IMP.isd
1143  import IMP.pmi.tools
1144 
1145  def __init__(self, representations, filename, cbeta=False,
1146  betatuple=(0.03, 0.1),
1147  disttuple=(0.0, 25.0, 1000),
1148  omegatuple=(1.0, 1000.0, 50),
1149  sigmatuple=(0.3, 0.3, 1),
1150  betaissampled=True,
1151  sigmaissampled=False,
1152  weightissampled=True,
1153  epsilonissampled=True
1154  ):
1155  # the file must have residue1 chain1 residue2 chain2 fractionvalue epsilonname
1156  # epsilonname is a name for the epsilon particle that must be used for that particular
1157  # residue pair, eg, "Epsilon-Intra-Solvent", or
1158  # "Epsilon-Solvent-Membrane", etc.
1159 
1160  self.representations = representations
1161  self.m = self.representations[0].prot.get_model()
1162  self.rs = IMP.RestraintSet(self.m, 'Cysteine_Crosslink')
1163  self.cbeta = cbeta
1164  self.epsilonmaxtrans = 0.01
1165  self.sigmamaxtrans = 0.1
1166  self.betamaxtrans = 0.01
1167  self.weightmaxtrans = 0.1
1168  self.label = "None"
1169  self.outputlevel = "low"
1170  self.betaissampled = betaissampled
1171  self.sigmaissampled = sigmaissampled
1172  self.weightissampled = weightissampled
1173  self.epsilonissampled = epsilonissampled
1174 
1175  betalower = betatuple[0]
1176  betaupper = betatuple[1]
1177  beta = 0.04
1178  sigma = 10.0
1179  betangrid = 30
1180  crossdataprior = 1
1181 
1182  # beta
1183  self.beta = IMP.pmi.tools.SetupNuisance(
1184  self.m,
1185  beta,
1186  betalower,
1187  betaupper,
1188  betaissampled).get_particle(
1189  )
1190  # sigma
1191  self.sigma = IMP.pmi.tools.SetupNuisance(
1192  self.m,
1193  sigma,
1194  sigmatuple[0],
1195  sigmatuple[1],
1196  sigmaissampled).get_particle()
1197  # population particle
1198  self.weight = IMP.pmi.tools.SetupWeight(
1199  self.m,
1200  weightissampled).get_particle(
1201  )
1202 
1203  # read the file
1204  fl = IMP.pmi.tools.open_file_or_inline_text(filename)
1205  # determine the upperlimit for epsilon
1206  # and also how many epsilon are needed
1207  self.epsilons = {}
1208  data = []
1209  for line in fl:
1210  t = line.split()
1211  if t[0][0] == "#":
1212  continue
1213  if t[5] in self.epsilons:
1214  if 1.0 - float(t[4]) <= self.epsilons[t[5]].get_upper():
1215  self.epsilons[t[5]].set_upper(1.0 - float(t[4]))
1216  else:
1217  self.epsilons[t[5]] = IMP.pmi.tools.SetupNuisance(self.m,
1218  0.01, 0.01, 1.0 - float(t[4]), epsilonissampled).get_particle()
1219  up = self.epsilons[t[5]].get_upper()
1220  low = self.epsilons[t[5]].get_lower()
1221  if up < low:
1222  self.epsilons[t[5]].set_upper(low)
1223 
1224  data.append((int(t[0]), t[1], int(t[2]), t[3], float(t[4]), t[5]))
1225 
1226  # create CrossLinkData
1227  if not self.cbeta:
1228  crossdata = IMP.pmi.tools.get_cross_link_data(
1229  "cysteine", "cysteine_CA_FES.txt.standard",
1230  disttuple, omegatuple, sigmatuple, disttuple[1], disttuple[1], 1)
1231  else:
1232  crossdata = IMP.pmi.tools.get_cross_link_data(
1233  "cysteine", "cysteine_CB_FES.txt.standard",
1234  disttuple, omegatuple, sigmatuple, disttuple[1], disttuple[1], 1)
1235 
1236  # create grids needed by CysteineCrossLinkData
1237  fmod_grid = IMP.pmi.tools.get_grid(0.0, 1.0, 300, True)
1238  omega2_grid = IMP.pmi.tools.get_log_grid(0.001, 10000.0, 100)
1239  beta_grid = IMP.pmi.tools.get_log_grid(betalower, betaupper, betangrid)
1240 
1241  for d in data:
1242  print("--------------")
1243  print("CysteineCrossLink: attempting to create a restraint " + str(d))
1244  resid1 = d[0]
1245  chain1 = d[1]
1246  resid2 = d[2]
1247  chain2 = d[3]
1248  fexp = d[4]
1249  epslabel = d[5]
1250 
1251  # CysteineCrossLinkData
1252 
1254  fexp,
1255  fmod_grid,
1256  omega2_grid,
1257  beta_grid)
1258 
1260  self.beta,
1261  self.sigma,
1262  self.epsilons[epslabel],
1263  self.weight,
1264  crossdata,
1265  ccldata)
1266 
1267  failed = False
1268  for i, representation in enumerate(self.representations):
1269 
1270  if not self.cbeta:
1271  p1 = None
1272  p2 = None
1273 
1274  p1 = IMP.pmi.tools.select(representation,
1275  resolution=1, name=chain1,
1276  name_is_ambiguous=False, residue=resid1)[0]
1277 
1278  if p1 is None:
1279  failed = True
1280 
1281  p2 = IMP.pmi.tools.select(representation,
1282  resolution=1, name=chain2,
1283  name_is_ambiguous=False, residue=resid2)[0]
1284 
1285  if p2 is None:
1286  failed = True
1287 
1288  else:
1289  # use cbetas
1290  p1 = []
1291  p2 = []
1292  for t in range(-1, 2):
1293  p = IMP.pmi.tools.select(representation,
1294  resolution=1, name=chain1,
1295  name_is_ambiguous=False, residue=resid1 + t)
1296 
1297  if len(p) == 1:
1298  p1 += p
1299  else:
1300  failed = True
1301  print("\033[93m CysteineCrossLink: missing representation for residue %d of chain %s \033[0m" % (resid1 + t, chain1))
1302 
1303  p = IMP.pmi.tools.select(representation,
1304  resolution=1, name=chain2,
1305  name_is_ambiguous=False, residue=resid2 + t)
1306 
1307  if len(p) == 1:
1308  p2 += p
1309  else:
1310  failed = True
1311  print("\033[93m CysteineCrossLink: missing representation for residue %d of chain %s \033[0m" % (resid2 + t, chain2))
1312 
1313  if not self.cbeta:
1314  if (p1 is not None and p2 is not None):
1315  ccl.add_contribution(p1, p2)
1316  d1 = IMP.core.XYZ(p1)
1317  d2 = IMP.core.XYZ(p2)
1318 
1319  print("Distance_" + str(resid1) + "_" + chain1 + ":" + str(resid2) + "_" + chain2, IMP.core.get_distance(d1, d2))
1320 
1321  else:
1322  if (len(p1) == 3 and len(p2) == 3):
1323  p11n = p1[0].get_name()
1324  p12n = p1[1].get_name()
1325  p13n = p1[2].get_name()
1326  p21n = p2[0].get_name()
1327  p22n = p2[1].get_name()
1328  p23n = p2[2].get_name()
1329 
1330  print("CysteineCrossLink: generating CB cysteine cross-link restraint between")
1331  print("CysteineCrossLink: residue %d of chain %s and residue %d of chain %s" % (resid1, chain1, resid2, chain2))
1332  print("CysteineCrossLink: between particles %s %s %s and %s %s %s" % (p11n, p12n, p13n, p21n, p22n, p23n))
1333 
1334  ccl.add_contribution(p1, p2)
1335 
1336  if not failed:
1337  self.rs.add_restraint(ccl)
1338  ccl.set_name("CysteineCrossLink_" + str(resid1)
1339  + "_" + chain1 + ":" + str(resid2) + "_" + chain2)
1340 
1341  def set_label(self, label):
1342  self.label = label
1343 
1344  def add_to_model(self):
1345  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
1346 
1347  def get_particles_to_sample(self):
1348  ps = {}
1349  if self.epsilonissampled:
1350  for eps in self.epsilons.keys():
1351  ps["Nuisances_CysteineCrossLinkRestraint_epsilon_" + eps + "_" +
1352  self.label] = ([self.epsilons[eps]], self.epsilonmaxtrans)
1353  if self.betaissampled:
1354  ps["Nuisances_CysteineCrossLinkRestraint_beta_" +
1355  self.label] = ([self.beta], self.betamaxtrans)
1356  if self.weightissampled:
1357  ps["Weights_CysteineCrossLinkRestraint_" +
1358  self.label] = ([self.weight], self.weightmaxtrans)
1359  if self.sigmaissampled:
1360  ps["Nuisances_CysteineCrossLinkRestraint_" +
1361  self.label] = ([self.sigma], self.sigmamaxtrans)
1362  return ps
1363 
1364  def set_output_level(self, level="low"):
1365  # this might be "low" or "high"
1366  self.outputlevel = level
1367 
1368  def get_restraint(self):
1369  return self.rs
1370 
1371  def get_sigma(self):
1372  return self.sigma
1373 
1374  def get_output(self):
1375  self.m.update()
1376  output = {}
1377  score = self.rs.unprotected_evaluate(None)
1378  output["_TotalScore"] = str(score)
1379  output["CysteineCrossLinkRestraint_Score_" + self.label] = str(score)
1380  output["CysteineCrossLinkRestraint_sigma_" +
1381  self.label] = str(self.sigma.get_scale())
1382  for eps in self.epsilons.keys():
1383  output["CysteineCrossLinkRestraint_epsilon_" + eps + "_" +
1384  self.label] = str(self.epsilons[eps].get_scale())
1385  output["CysteineCrossLinkRestraint_beta_" +
1386  self.label] = str(self.beta.get_scale())
1387  for n in range(self.weight.get_number_of_states()):
1388  output["CysteineCrossLinkRestraint_weights_" +
1389  str(n) + "_" + self.label] = str(self.weight.get_weight(n))
1390 
1391  if self.outputlevel == "high":
1392  for rst in self.rs.get_restraints():
1393  output["CysteineCrossLinkRestraint_Total_Frequency_" +
1394  IMP.isd.CysteineCrossLinkRestraint.get_from(rst).get_name() +
1395  "_" + self.label] = IMP.isd.CysteineCrossLinkRestraint.get_from(rst).get_model_frequency()
1396  output["CysteineCrossLinkRestraint_Standard_Error_" +
1397  IMP.isd.CysteineCrossLinkRestraint.get_from(
1398  rst).get_name(
1399  ) + "_"
1400  + self.label] = IMP.isd.CysteineCrossLinkRestraint.get_from(rst).get_standard_error()
1401  if len(self.representations) > 1:
1402  for i in range(len(self.prots)):
1403  output["CysteineCrossLinkRestraint_Frequency_Contribution_" +
1404  IMP.isd.CysteineCrossLinkRestraint.get_from(rst).get_name() +
1405  "_State_" + str(i) + "_" + self.label] = IMP.isd.CysteineCrossLinkRestraint.get_from(rst).get_frequencies()[i]
1406 
1407  return output
A function that is harmonic over an interval.
A restraint for ambiguous cross-linking MS data and multiple state approach.
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition: XYZR.h:48
Miscellaneous utilities.
Definition: tools.py:1
Add uncertainty to a particle.
Definition: Uncertainty.h:24
A score on the distance between the surfaces of two spheres.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:469
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Definition: XYZR.h:87
Object used to hold a set of restraints.
Definition: RestraintSet.h:36
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
def add_restraint_to_model
Add a PMI restraint to the model.
Definition: tools.py:22
Simple sigmoidal score calculated between sphere surfaces.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
this restraint allows ambiguous crosslinking between multiple copies it is a variant of the Simplifie...
Definition: crosslinking.py:13
Linear function
Definition: Linear.h:19
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
Calculate the -Log of a list of restraints.
Definition: LogWrapper.h:19
Class to handle individual model particles.
Definition: Particle.h:37
Restraint * create_connectivity_restraint(const Selections &s, double x0, double k, std::string name="Connectivity%1%")
Create a restraint connecting the selections.
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:662
def cross_link_db_filter_parser
example '"{ID_Score}" > 28 AND "{Sample}" == "%10_1%" OR ":Sample}" == "%10_2%" OR ":Sample...
Definition: tools.py:454
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
Definition: Selection.h:65
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...
A restraint for cysteine cross-linking data.
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27