1 """@namespace IMP.pmi.restraints.crosslinking_new
2 Restraints for handling crosslinking data.
5 from __future__
import print_function
14 class DisulfideCrossLinkRestraint(object):
15 def __init__(self, representation,
23 self.m = representation.prot.get_model()
29 self.linear.set_slope(0.0)
33 self.psi_dictionary={}
34 self.sigma_dictionary={}
35 self.psi_is_sampled =
False
36 self.sigma_is_sampled =
False
39 ps1 = IMP.pmi.tools.select_by_tuple(
42 resolution=resolution)
44 ps2 = IMP.pmi.tools.select_by_tuple(
47 resolution=resolution)
49 if len(ps1) > 1
or len(ps1) == 0:
50 raise ValueError(
"DisulfideBondRestraint: ERROR> first selection pattern selects multiple particles or sero particles")
52 if len(ps2) > 1
or len(ps2) == 0:
53 raise ValueError(
"DisulfideBondRestraint: ERROR> second selection pattern selects multiple particles or sero particles")
60 sigma=self.create_sigma(
"SIGMA_DISULFIDE_BOND")
61 psi=self.create_psi(
"PSI_DISULFIDE_BOND")
63 p1i = p1.get_particle_index()
64 p2i = p2.get_particle_index()
73 dr.add_contribution((p1i, p2i), (si, si), psii)
77 pr.set_name(
"DISULFIDE_BOND_"+self.label)
78 self.rslin.add_restraint(pr)
81 self.rs.add_restraint(lw)
83 self.xl[
"Particle1"]=p1
84 self.xl[
"Particle2"]=p2
85 self.xl[
"Sigma"]=sigma
88 def add_to_model(self):
92 def get_hierarchies(self):
95 def get_restraint_sets(self):
98 def get_restraint(self):
101 def get_restraint_for_rmf(self):
104 def get_restraints(self):
106 for r
in self.rs.get_restraints():
107 rlist.append(IMP.core.PairRestraint.get_from(r))
110 def set_psi_is_sampled(self, is_sampled=True):
111 self.psi_is_sampled = is_sampled
113 def set_sigma_is_sampled(self, is_sampled=True):
114 self.sigma_is_sampled = is_sampled
117 def create_sigma(self, name):
118 ''' a nuisance on the structural uncertainty '''
119 if name
in self.sigma_dictionary:
120 return self.sigma_dictionary[name][0]
123 sigmaminnuis = 0.0000001
124 sigmamaxnuis = 1000.0
128 sigma = IMP.pmi.tools.SetupNuisance(self.m, sigmainit,
129 sigmaminnuis, sigmamaxnuis, self.sigma_is_sampled).get_particle()
130 self.sigma_dictionary[name] = (
133 self.sigma_is_sampled)
137 def create_psi(self, name):
138 ''' a nuisance on the inconsistency '''
139 if name
in self.psi_dictionary:
140 return self.psi_dictionary[name][0]
143 psiminnuis = 0.0000001
144 psimaxnuis = 0.4999999
148 psi = IMP.pmi.tools.SetupNuisance(self.m, psiinit,
149 psiminnuis, psimaxnuis,
150 self.psi_is_sampled).get_particle()
151 self.psi_dictionary[name] = (
159 def get_output(self):
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)
170 def get_particles_to_sample(self):
171 raise NotImplementedError(
" ")
174 class CrossLinkingMassSpectrometryRestraint(object):
179 def __init__(self, representation,
186 attributes_for_label=
None):
188 if type(representation) != list:
189 representations = [representation]
191 representations = representation
193 if not isinstance(CrossLinkDataBase,IMP.pmi.io.crosslink.CrossLinkDataBase):
194 raise TypeError(
"CrossLinkingMassSpectrometryRestraint: CrossLinkDataBase should be an IMP.pmi.io.crosslink.CrossLinkDataBase object")
196 self.CrossLinkDataBase=CrossLinkDataBase
198 indb = open(
"included." + filelabel +
".xl.db",
"w")
199 exdb = open(
"excluded." + filelabel +
".xl.db",
"w")
200 midb = open(
"missing." + filelabel +
".xl.db",
"w")
202 self.m = representations[0].prot.get_model()
210 self.linear.set_slope(0.0)
214 self.psi_is_sampled =
True
215 self.sigma_is_sampled =
True
216 self.psi_dictionary={}
217 self.sigma_dictionary={}
219 self.outputlevel =
"low"
223 for xlid
in self.CrossLinkDataBase.xlid_iterator():
224 new_contribution=
True
225 for xl
in self.CrossLinkDataBase[xlid]:
227 r1 = xl[self.CrossLinkDataBase.residue1_key]
228 c1 = xl[self.CrossLinkDataBase.protein1_key]
229 r2 = xl[self.CrossLinkDataBase.residue2_key]
230 c2 = xl[self.CrossLinkDataBase.protein2_key]
232 for nstate, r
in enumerate(representations):
234 xl[self.CrossLinkDataBase.state_key]=nstate
235 xl[self.CrossLinkDataBase.data_set_name_key]=self.label
239 resolution=resolution,
241 name_is_ambiguous=
False,
245 resolution=resolution,
247 name_is_ambiguous=
False,
251 raise ValueError(
"residue %d of chain %s selects multiple particles %s" % (r1, c1, str(ps1)))
253 print(
"CrossLinkingMassSpectrometryRestraint: WARNING> residue %d of chain %s is not there" % (r1, c1))
254 midb.write(str(xl) +
"\n")
258 raise ValueError(
"residue %d of chain %s selects multiple particles %s" % (r2, c2, str(ps2)))
260 print(
"CrossLinkingMassSpectrometryRestraint: WARNING> residue %d of chain %s is not there" % (r2, c2))
261 midb.write(str(xl) +
"\n")
267 if p1 == p2
and r1 == r2:
268 print(
"CrossLinkingMassSpectrometryRestraint: WARNING> same particle and same residue, skippin cross-link")
272 print(
"generating a new crosslink restraint")
273 new_contribution=
False
278 restraints.append(dr)
281 if self.CrossLinkDataBase.sigma1_key
not in xl.keys():
283 xl[self.CrossLinkDataBase.sigma1_key]=sigma1name
285 sigma1name=xl[self.CrossLinkDataBase.sigma1_key]
286 sigma1=self.create_sigma(sigma1name)
288 if self.CrossLinkDataBase.sigma2_key
not in xl.keys():
290 xl[self.CrossLinkDataBase.sigma2_key]=sigma2name
292 sigma2name=xl[self.CrossLinkDataBase.sigma2_key]
293 sigma2=self.create_sigma(sigma2name)
295 if self.CrossLinkDataBase.psi_key
not in xl.keys():
297 xl[self.CrossLinkDataBase.psi_key]=psiname
299 psiname=xl[self.CrossLinkDataBase.psi_key]
300 psi=self.create_psi(psiname)
303 p1i = p1.get_particle_index()
305 p2i = p2.get_particle_index()
308 xl[
"Particle_sigma1"]=sigma1
310 xl[
"Particle_sigma2"]=sigma2
312 xl[
"Particle_psi"]=psi
314 print(
"B",(p1i, p2i), (s1i, s2i), psii,dr)
316 dr.add_contribution((p1i, p2i), (s1i, s2i), psii)
319 print(
"--------------")
320 print(
"CrossLinkingMassSpectrometryRestraint: generating cross-link restraint between")
321 print(
"CrossLinkingMassSpectrometryRestraint: residue %d of chain %s and residue %d of chain %s" % (r1, c1, r2, c2))
322 print(
"CrossLinkingMassSpectrometryRestraint: with sigma1 %s sigma2 %s psi %s" % (sigma1name, sigma2name, psiname))
323 print(
"CrossLinkingMassSpectrometryRestraint: between particles %s and %s" % (p1.get_name(), p2.get_name()))
324 print(
"==========================================\n")
331 xl[
"IntraRigidBody"]=
True
333 xl[
"IntraRigidBody"]=
False
335 xl_label=self.CrossLinkDataBase.get_short_cross_link_string(xl)
336 xl[
"ShortLabel"]=xl_label
337 dr.set_name(xl_label)
341 pr.set_name(xl_label)
342 self.rslin.add_restraint(pr)
344 self.xl_list.append(xl)
346 indb.write(str(xl) +
"\n")
348 if len(self.xl_list) == 0:
349 raise SystemError(
"CrossLinkingMassSpectrometryRestraint: no crosslink was constructed")
352 self.rs.add_restraint(lw)
354 def add_to_model(self):
360 def get_hierarchies(self):
363 def get_restraint_sets(self):
366 def get_restraint(self):
369 def get_restraint_for_rmf(self):
372 def get_restraints(self):
374 for r
in self.rs.get_restraints():
375 rlist.append(IMP.core.PairRestraint.get_from(r))
378 def get_particle_pairs(self):
380 for i
in range(len(self.pairs)):
381 p0 = self.pairs[i][0]
382 p1 = self.pairs[i][1]
383 ppairs.append((p0, p1))
386 def set_output_level(self, level="low"):
388 self.outputlevel = level
390 def set_psi_is_sampled(self, is_sampled=True):
391 self.psi_is_sampled = is_sampled
393 def set_sigma_is_sampled(self, is_sampled=True):
394 self.sigma_is_sampled = is_sampled
397 def create_sigma(self, name):
398 ''' a nuisance on the structural uncertainty '''
399 if name
in self.sigma_dictionary:
400 return self.sigma_dictionary[name][0]
403 sigmaminnuis = 0.0000001
404 sigmamaxnuis = 1000.0
408 sigma = IMP.pmi.tools.SetupNuisance(self.m, sigmainit,
409 sigmaminnuis, sigmamaxnuis, self.sigma_is_sampled).get_particle()
410 self.sigma_dictionary[name] = (
413 self.sigma_is_sampled)
414 self.rssig.add_restraint(
423 def create_psi(self, name):
424 ''' a nuisance on the inconsistency '''
425 if name
in self.psi_dictionary:
426 return self.psi_dictionary[name][0]
429 psiminnuis = 0.0000001
430 psimaxnuis = 0.4999999
434 psi = IMP.pmi.tools.SetupNuisance(self.m, psiinit,
435 psiminnuis, psimaxnuis,
436 self.psi_is_sampled).get_particle()
437 self.psi_dictionary[name] = (
442 self.rspsi.add_restraint(
455 def get_output(self):
459 score = self.rs.unprotected_evaluate(
None)
460 output[
"_TotalScore"] = str(score)
461 output[
"CrossLinkingMassSpectrometryRestraint_Data_Score_" + self.label] = str(score)
462 output[
"CrossLinkingMassSpectrometryRestraint_PriorSig_Score_" +
463 self.label] = self.rssig.unprotected_evaluate(
None)
464 output[
"CrossLinkingMassSpectrometryRestraint_PriorPsi_Score_" +
465 self.label] = self.rspsi.unprotected_evaluate(
None)
466 output[
"CrossLinkingMassSpectrometryRestraint_Linear_Score_" +
467 self.label] = self.rslin.unprotected_evaluate(
None)
468 for xl
in self.xl_list:
470 xl_label=xl[
"ShortLabel"]
474 output[
"CrossLinkingMassSpectrometryRestraint_Score_" +
475 xl_label] = str(-self.log(ln.unprotected_evaluate(
None)))
479 output[
"CrossLinkingMassSpectrometryRestraint_Distance_" +
483 for psiname
in self.psi_dictionary:
484 output[
"CrossLinkingMassSpectrometryRestraint_Psi_" +
485 str(psiname) +
"_" + self.label] = str(self.psi_dictionary[psiname][0].get_scale())
487 for sigmaname
in self.sigma_dictionary:
488 output[
"CrossLinkingMassSpectrometryRestraint_Sigma_" +
489 str(sigmaname) +
"_" + self.label] = str(self.sigma_dictionary[sigmaname][0].get_scale())
494 def get_particles_to_sample(self):
496 if self.sigma_is_sampled:
497 for sigmaname
in self.sigma_dictionary:
498 ps[
"Nuisances_ISDCrossLinkMS_Sigma_" + str(sigmaname) +
"_" + self.label] =\
499 ([self.sigma_dictionary[sigmaname][0]],
500 self.sigma_dictionary[sigmaname][1])
502 if self.psi_is_sampled:
503 for psiname
in self.psi_dictionary:
504 ps[
"Nuisances_ISDCrossLinkMS_Psi_" +
505 str(psiname) +
"_" + self.label] =\
506 ([self.psi_dictionary[psiname][0]], self.psi_dictionary[psiname][1])
A restraint for ambiguous cross-linking MS data and multiple state approach.
Various classes to hold sets of particles.
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)
A decorator for a particle with x,y,z coordinates.
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.
Applies a PairScore to a Pair.
Functionality for loading, creating, manipulating and scoring atomic structures.
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...