1 """@namespace IMP.pmi.restraints.crosslinking
2 Restraints for handling crosslinking data.
5 from __future__
import print_function
16 this restraint allows ambiguous crosslinking between multiple copies
17 it is a variant of the SimplifiedCrossLinkMS
28 self.m = representation.prot.get_model()
34 self.outputlevel =
"low"
35 self.expdistance = expdistance
36 self.strength = strength
38 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
44 if (tokens[0] ==
"#"):
53 resolution=resolution,
55 name_is_ambiguous=
True,
57 hrc1 = [representation.hier_db.particle_to_name[p]
for p
in ps1]
59 print(
"ConnectivityCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
64 resolution=resolution,
66 name_is_ambiguous=
True,
68 hrc2 = [representation.hier_db.particle_to_name[p]
for p
in ps2]
70 print(
"ConnectivityCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
77 if self.strength
is None:
86 rad1 = rad1 / len(ps1)
87 rad2 = rad2 / len(ps2)
89 self.strength = 1 / (rad1 ** 2 + rad2 ** 2)
97 self.rs.add_restraint(cr)
98 self.pairs.append((ps1, hrc1, c1, r1, ps2, hrc2, c2, r2, cr))
112 d1.set_radius(uncertainty1)
113 d2.set_radius(uncertainty2)
117 strength = 1 / (uncertainty1 ** 2 + uncertainty2 ** 2)
124 for i
in range(npoints):
128 scores.append(cr.unprotected_evaluate(
None))
129 output.plot_xy_data(dists, scores)
131 def set_label(self, label):
133 self.rs.set_name(label)
134 for r
in self.rs.get_restraints():
137 def add_to_model(self):
140 def get_restraint_sets(self):
143 def get_restraint(self):
146 def set_output_level(self, level="low"):
148 self.outputlevel = level
150 def set_weight(self, weight):
152 self.rs.set_weight(weight)
154 def get_output(self):
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):
174 for n1, p1
in enumerate(ps1):
177 for n2, p2
in enumerate(ps2):
181 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
182 output[
"ConnectivityCrossLinkMS_Distance_" +
185 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
186 output[
"ConnectivityCrossLinkMS_Score_" +
187 label] = str(self.weight * cr.unprotected_evaluate(
None))
192 class SimplifiedCrossLinkMS(object):
203 spheredistancepairscore=
True):
208 if columnmapping
is None:
210 columnmapping[
"Protein1"] = 0
211 columnmapping[
"Protein2"] = 1
212 columnmapping[
"Residue1"] = 2
213 columnmapping[
"Residue2"] = 3
215 self.m = representation.prot.get_model()
220 self.already_added_pairs = {}
222 self.outputlevel =
"low"
223 self.expdistance = expdistance
224 self.strength = strength
225 self.truncated = truncated
226 self.spheredistancepairscore = spheredistancepairscore
231 protein1 = columnmapping[
"Protein1"]
232 protein2 = columnmapping[
"Protein2"]
233 residue1 = columnmapping[
"Residue1"]
234 residue2 = columnmapping[
"Residue2"]
236 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
240 tokens = line.split()
242 if (tokens[0] ==
"#"):
244 r1 = int(tokens[residue1])
245 c1 = tokens[protein1]
246 r2 = int(tokens[residue2])
247 c2 = tokens[protein2]
251 resolution=resolution,
253 name_is_ambiguous=
False,
257 resolution=resolution,
259 name_is_ambiguous=
False,
264 "residue %d of chain %s selects multiple particles; "
266 % (r1, c1,
"".join(p.get_name()
for p
in ps1)))
268 print(
"SimplifiedCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
273 "residue %d of chain %s selects multiple particles; "
275 % (r2, c2,
"".join(p.get_name()
for p
in ps2)))
277 print(
"SimplifiedCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
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))
293 limit = self.strength * (self.expdistance + 15) ** 2 + 10.0
304 if self.spheredistancepairscore:
309 dr.set_name(c1 +
":" + str(r1) +
"-" + c2 +
":" + str(r2))
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
316 def set_label(self, label):
319 def add_to_model(self):
322 def get_restraint_sets(self):
325 def get_restraint(self):
328 def get_restraints(self):
330 for r
in self.rs.get_restraints():
331 rlist.append(IMP.core.PairRestraint.get_from(r))
334 def get_particle_pairs(self):
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))
342 def set_output_level(self, level="low"):
344 self.outputlevel = level
346 def set_weight(self, weight):
348 self.rs.set_weight(weight)
350 def plot_restraint(self, radius1, radius2, maxdist=50, npoints=10):
357 d1.set_radius(radius1)
358 d2.set_radius(radius2)
360 limit = self.strength * (self.expdistance + 15) ** 2 + 10.0
375 for i
in range(npoints):
379 scores.append(dr.unprotected_evaluate(
None))
380 output.plot_xy_data(dists, scores)
382 def get_output(self):
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)):
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]
402 label = str(resid1) +
":" + chain1 +
"_" + \
403 str(resid2) +
":" + chain2
404 output[
"SimplifiedCrossLinkMS_Score_" + crosslinker +
"_" +
405 label] = str(self.weight * ln.unprotected_evaluate(
None))
407 if self.spheredistancepairscore:
413 output[
"SimplifiedCrossLinkMS_Distance_" +
421 class SigmoidalCrossLinkMS(object):
424 self, representation, restraints_file, inflection, slope, amplitude,
425 linear_slope, resolution=
None, columnmapping=
None, csvfile=
False,
426 filters=
None, filelabel=
"None"):
433 if columnmapping
is None:
435 columnmapping[
"Protein1"] = 0
436 columnmapping[
"Protein2"] = 1
437 columnmapping[
"Residue1"] = 2
438 columnmapping[
"Residue2"] = 3
444 db = tools.get_db_from_csv(restraints_file)
446 db = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
448 self.m = representation.prot.get_model()
454 self.already_added_pairs = {}
455 self.inflection = inflection
457 self.amplitude = amplitude
458 self.linear_slope = linear_slope
460 self.outputlevel =
"low"
465 protein1 = columnmapping[
"Protein1"]
466 protein2 = columnmapping[
"Protein2"]
467 residue1 = columnmapping[
"Residue1"]
468 residue2 = columnmapping[
"Residue2"]
470 indb = open(
"included." + filelabel +
".xl.db",
"w")
471 exdb = open(
"excluded." + filelabel +
".xl.db",
"w")
472 midb = open(
"missing." + filelabel +
".xl.db",
"w")
476 tokens = entry.split()
478 if (tokens[0] ==
"#"):
480 r1 = int(tokens[residue1])
481 c1 = tokens[protein1]
482 r2 = int(tokens[residue2])
483 c2 = tokens[protein2]
485 if filters
is not None:
486 if eval(tools.cross_link_db_filter_parser(filters)) ==
False:
487 exdb.write(str(entry) +
"\n")
489 indb.write(str(entry) +
"\n")
490 r1 = int(entry[residue1])
492 r2 = int(entry[residue2])
497 resolution=resolution,
499 name_is_ambiguous=
False,
503 resolution=resolution,
505 name_is_ambiguous=
False,
509 raise ValueError(
"residue %d of chain %s selects multiple particles %s" % (r1, c1, str(ps1)))
511 print(
"SigmoidalCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
512 midb.write(str(entry) +
"\n")
516 raise ValueError(
"residue %d of chain %s selects multiple particles %s" % (r2, c2, str(ps2)))
518 print(
"SigmoidalCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
519 midb.write(str(entry) +
"\n")
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()))
544 dr.set_name(c1 +
":" + str(r1) +
"-" + c2 +
":" + str(r2)
545 +
"-ampl:" + str(dr.get_amplitude()))
547 self.rs.add_restraint(dr)
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
553 def set_label(self, label):
556 def add_to_model(self):
559 def get_restraint_sets(self):
562 def get_restraint(self):
565 def get_restraints(self):
567 for r
in self.rs.get_restraints():
568 rlist.append(IMP.core.PairRestraint.get_from(r))
571 def get_particle_pairs(self):
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))
579 def set_output_level(self, level="low"):
581 self.outputlevel = level
583 def set_weight(self, weight):
585 self.rs.set_weight(weight)
587 def plot_restraint(self, radius1, radius2, maxdist=50, npoints=10):
594 d1.set_radius(radius1)
595 d2.set_radius(radius2)
606 for i
in range(npoints):
610 scores.append(dr.unprotected_evaluate(
None))
611 output.plot_xy_data(dists, scores)
613 def get_output(self):
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)):
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]
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))
639 output[
"SigmoidalCrossLinkMS_Distance_" +
645 class ISDCrossLinkMS(IMP.pmi.restraints._NuisancesBase):
655 def __init__(self, representation,
675 automatic_sigma_classification=
False,
676 attributes_for_label=
None):
686 if type(representation) != list:
687 representations = [representation]
689 representations = representation
691 if columnmapping
is None:
693 columnmapping[
"Protein1"] = 0
694 columnmapping[
"Protein2"] = 1
695 columnmapping[
"Residue1"] = 2
696 columnmapping[
"Residue2"] = 3
697 columnmapping[
"IDScore"] = 4
698 columnmapping[
"XLUniqueID"] = 5
704 db = IMP.pmi.tools.get_db_from_csv(restraints_file)
706 db = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
708 indb = open(
"included." + filelabel +
".xl.db",
"w")
709 exdb = open(
"excluded." + filelabel +
".xl.db",
"w")
710 midb = open(
"missing." + filelabel +
".xl.db",
"w")
712 self.m = representations[0].prot.get_model()
721 self.sigma_dictionary = {}
722 self.psi_dictionary = {}
723 self.psi_is_sampled =
True
724 self.sigma_is_sampled =
True
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)
733 self.ids_map = ids_map
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)
741 self.radius_map = radius_map
743 self.outputlevel =
"low"
747 self.linear.set_slope(slope)
750 protein1 = columnmapping[
"Protein1"]
751 protein2 = columnmapping[
"Protein2"]
752 residue1 = columnmapping[
"Residue1"]
753 residue2 = columnmapping[
"Residue2"]
754 idscore = columnmapping[
"IDScore"]
756 xluniqueid = columnmapping[
"XLUniqueID"]
766 uniqueid_restraints_map = {}
768 for nxl, entry
in enumerate(db):
770 if not jackknifing
is None:
777 raise NotImplementedError(
"jackknifing not yet implemented")
780 tokens = entry.split()
785 if (tokens[0] ==
"#"):
788 r1 = int(tokens[residue1])
789 c1 = tokens[protein1]
790 r2 = int(tokens[residue2])
791 c2 = tokens[protein2]
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]
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]
804 ids = float(tokens[idscore])
805 if xluniqueid
is None:
808 xlid = tokens[xluniqueid]
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")
820 if filters
is not None:
822 exdb.write(str(entry) +
"\n")
826 r1 = int(entry[residue1])
828 r2 = int(entry[residue2])
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]
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]
843 ids = float(entry[idscore])
846 if xluniqueid
is None:
849 xlid = entry[xluniqueid]
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")
861 for nstate, r
in enumerate(representations):
866 resolution=resolution,
868 name_is_ambiguous=
False,
872 resolution=resolution,
874 name_is_ambiguous=
False,
878 raise ValueError(
"residue %d of chain %s selects multiple particles %s" % (r1, c1, str(ps1)))
880 print(
"ISDCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
881 midb.write(str(entry) +
"\n")
885 raise ValueError(
"residue %d of chain %s selects multiple particles %s" % (r2, c2, str(ps2)))
887 print(
"ISDCrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
888 midb.write(str(entry) +
"\n")
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.")
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]
902 print(
"Generating a NEW crosslink restraint with an uniqueID %s" % str(xlid))
907 restraints.append(dr)
908 uniqueid_restraints_map[xlid] = dr
910 mappedr1 = self.radius_map.get_map_element(
912 sigma1 = self.get_sigma(mappedr1)[0]
913 mappedr2 = self.radius_map.get_map_element(
915 sigma2 = self.get_sigma(mappedr2)[0]
917 psival = self.ids_map.get_map_element(ids)
918 psi = self.get_psi(psival)[0]
921 p1i = p1.get_particle_index()
922 p2i = p2.get_particle_index()
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")
944 xlattribute =
"intrarb"
946 xlattribute =
"interrb"
949 if not attributes_for_label
is None:
950 for a
in attributes_for_label:
951 xlattribute = xlattribute +
"_" + str(entry[a])
953 xlattribute = xlattribute +
"-State:" + str(nstate)
956 xlattribute +
"-" + c1 +
":" + str(r1) +
"-" + c2 +
":" + str(r2) +
"_" + self.label)
961 xlattribute +
"-" + c1 +
":" + str(r1) +
"-" + c2 +
":" + str(r2) +
"_" + self.label)
962 self.rslin.add_restraint(pr)
982 self.rs.add_restraint(lw)
985 def set_slope_linear_term(self, slope):
986 self.linear.set_slope(slope)
988 def set_label(self, label):
991 def add_to_model(self):
998 def get_hierarchies(self):
1001 def get_restraint_sets(self):
1004 def get_restraint(self):
1007 def get_restraint_for_rmf(self):
1010 def get_restraints(self):
1012 for r
in self.rs.get_restraints():
1013 rlist.append(IMP.core.PairRestraint.get_from(r))
1016 def get_particle_pairs(self):
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))
1024 def set_output_level(self, level="low"):
1026 self.outputlevel = level
1028 def set_psi_is_sampled(self, is_sampled=True):
1029 self.psi_is_sampled = is_sampled
1031 def set_sigma_is_sampled(self, is_sampled=True):
1032 self.sigma_is_sampled = is_sampled
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)
1049 def write_db(self,filename):
1051 cldb=IMP.pmi.output.CrossLinkIdentifierDatabase()
1053 for pairs_index
in range(len(self.pairs)):
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]
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)
1081 def get_output(self):
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)):
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)))
1107 output[
"ISDCrossLinkMS_Distance_" +
1111 for psiindex
in self.psi_dictionary:
1112 output[
"ISDCrossLinkMS_Psi_" +
1113 str(psiindex) +
"_" + self.label] = str(self.psi_dictionary[psiindex][0].get_scale())
1115 for resolution
in self.sigma_dictionary:
1116 output[
"ISDCrossLinkMS_Sigma_" +
1117 str(resolution) +
"_" + self.label] = str(self.sigma_dictionary[resolution][0].get_scale())
1122 def get_particles_to_sample(self):
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])
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])
1140 class CysteineCrossLinkRestraint(object):
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),
1151 sigmaissampled=
False,
1152 weightissampled=
True,
1153 epsilonissampled=
True
1160 self.representations = representations
1161 self.m = self.representations[0].prot.get_model()
1164 self.epsilonmaxtrans = 0.01
1165 self.sigmamaxtrans = 0.1
1166 self.betamaxtrans = 0.01
1167 self.weightmaxtrans = 0.1
1169 self.outputlevel =
"low"
1170 self.betaissampled = betaissampled
1171 self.sigmaissampled = sigmaissampled
1172 self.weightissampled = weightissampled
1173 self.epsilonissampled = epsilonissampled
1175 betalower = betatuple[0]
1176 betaupper = betatuple[1]
1183 self.beta = IMP.pmi.tools.SetupNuisance(
1188 betaissampled).get_particle(
1191 self.sigma = IMP.pmi.tools.SetupNuisance(
1196 sigmaissampled).get_particle()
1198 self.weight = IMP.pmi.tools.SetupWeight(
1200 weightissampled).get_particle(
1204 fl = IMP.pmi.tools.open_file_or_inline_text(filename)
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]))
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()
1222 self.epsilons[t[5]].set_upper(low)
1224 data.append((int(t[0]), t[1], int(t[2]), t[3], float(t[4]), t[5]))
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)
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)
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)
1242 print(
"--------------")
1243 print(
"CysteineCrossLink: attempting to create a restraint " + str(d))
1262 self.epsilons[epslabel],
1268 for i, representation
in enumerate(self.representations):
1275 resolution=1, name=chain1,
1276 name_is_ambiguous=
False, residue=resid1)[0]
1282 resolution=1, name=chain2,
1283 name_is_ambiguous=
False, residue=resid2)[0]
1292 for t
in range(-1, 2):
1294 resolution=1, name=chain1,
1295 name_is_ambiguous=
False, residue=resid1 + t)
1301 print(
"\033[93m CysteineCrossLink: missing representation for residue %d of chain %s \033[0m" % (resid1 + t, chain1))
1304 resolution=1, name=chain2,
1305 name_is_ambiguous=
False, residue=resid2 + t)
1311 print(
"\033[93m CysteineCrossLink: missing representation for residue %d of chain %s \033[0m" % (resid2 + t, chain2))
1314 if (p1
is not None and p2
is not None):
1315 ccl.add_contribution(p1, p2)
1319 print(
"Distance_" + str(resid1) +
"_" + chain1 +
":" + str(resid2) +
"_" + chain2,
IMP.core.get_distance(d1, d2))
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()
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))
1334 ccl.add_contribution(p1, p2)
1337 self.rs.add_restraint(ccl)
1338 ccl.set_name(
"CysteineCrossLink_" + str(resid1)
1339 +
"_" + chain1 +
":" + str(resid2) +
"_" + chain2)
1341 def set_label(self, label):
1344 def add_to_model(self):
1347 def get_particles_to_sample(self):
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)
1364 def set_output_level(self, level="low"):
1366 self.outputlevel = level
1368 def get_restraint(self):
1371 def get_sigma(self):
1374 def get_output(self):
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))
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(
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]
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)
Add uncertainty to a particle.
A score on the distance between the surfaces of two spheres.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Object used to hold a set of restraints.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Simple sigmoidal score calculated between sphere surfaces.
A decorator for a particle with x,y,z coordinates.
this restraint allows ambiguous crosslinking between multiple copies it is a variant of the Simplifie...
Classes for writing output files and processing them.
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...
Calculate the -Log of a list of restraints.
Class to handle individual model particles.
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.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
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.