1 """@namespace IMP.pmi.restraints.proteomics
2 Restraints for handling various kinds of proteomics data.
5 from __future__
import print_function
23 generate a connectivity restraint between domains
24 setting up the restraint
26 sel1 = IMP.atom.Selection(root_hier, molecule="Rpb3",
27 residue_indexes=range(1,100))
28 sel2 = IMP.atom.Selection(root_hier, molecule="Rpb4",
29 residue_indexes=range(1,100))
30 cr=restraints.ConnectivityRestraint((sel1, sel2), label='CR1')
32 Multistate support =No
36 def __init__(self, domains, kappa=10.0, resolution=None, label="None"):
42 domains, self.kappa, self.label)
43 self.m = cr.get_model()
45 self.rs.add_restraint(cr)
47 def set_label(self, label):
49 self.rs.set_name(label)
50 for r
in self.rs.get_restraints():
53 def add_to_model(self):
56 def get_restraint(self):
59 def get_restraints(self):
61 for r
in self.rs.get_restraints():
62 rlist.append(IMP.core.PairRestraint.get_from(r))
65 def set_weight(self, weight):
67 self.rs.set_weight(weight)
71 score = self.weight * self.rs.unprotected_evaluate(
None)
72 output[
"_TotalScore"] = str(score)
73 output[
"ConnectivityRestraint_" + self.label] = str(score)
82 handleparticles a list of particles
83 compositeparticles is a list of list of particles
86 def __init__(self, handle_particles, composite_particles, cut_off=5.0,
87 lam=1.0, plateau=0.0, resolution=
None, label=
"None"):
93 self.handleparticles = [h.get_particle()
for h
in hs]
94 self.m = self.handleparticles[0].get_model()
97 self.compositeparticles = []
98 compositeparticle_list = []
99 for cp
in composite_particles:
101 tmplist = [h.get_particle()
for h
in hs]
102 compositeparticle_list.append(tmplist)
103 self.compositeparticles += tmplist
106 self.m, self.handleparticles, cut_off, lam,
True, plateau)
108 for ps
in compositeparticle_list:
110 ln.add_composite_particle(ps)
112 self.rs.add_restraint(ln)
114 def set_label(self, label):
117 def get_handle_particles(self):
118 return self.handleparticles
120 def get_composite_particles(self):
121 return self.compositeparticles
123 def get_restraint(self):
126 def add_to_model(self):
129 def get_output(self):
131 score = self.rs.unprotected_evaluate(
None)
132 output[
"_TotalScore"] = str(score)
133 output[
"CompositeRestraint_" + self.label] = str(score)
141 this restraint allows ambiguous cross-linking between multiple copies
142 excluding between symmetric copies
143 It allows name ambiguity
146 def __init__(self, root_hier, restraints_file, cut_off=5.0, lam=1.0,
147 plateau=0.01, resolution=
None, label=
"None"):
149 self.m = root_hier.get_model()
154 self.outputlevel =
"low"
155 self.cut_off = cut_off
157 self.plateau = plateau
159 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
163 tokens = line.split()
165 if (tokens[0] ==
"#"):
173 molecule=c1, residue_index=r1)
174 ps1 = ps1.get_selected_particles()
175 hrc1 = [p.get_name()
for p
in ps1]
177 def nosym_subset(ps):
180 ps1nosym = nosym_subset(ps1)
181 hrc1nosym = [p.get_name()
for p
in ps1nosym]
185 "AmbiguousCompositeRestraint: residue %d of chain %s "
190 molecule=c2, residue_index=r2)
191 ps2 = ps2.get_selected_particles()
192 hrc2 = [p.get_name()
for p
in ps2]
193 ps2nosym = nosym_subset(ps2)
194 hrc2nosym = [p.get_name()
for p
in ps2nosym]
198 "AmbiguousCompositeRestraint: residue %d of chain %s "
203 self.m, ps1nosym, self.cut_off, self.lam,
True, self.plateau)
204 cr.add_composite_particle(ps2)
206 self.rs.add_restraint(cr)
219 self.m, ps1, self.cut_off, self.lam,
True, self.plateau)
220 cr.add_composite_particle(ps2nosym)
222 self.rs.add_restraint(cr)
250 cr.add_composite_particle([p2])
253 for i
in range(npoints):
257 scores.append(cr.unprotected_evaluate(
None))
258 IMP.pmi.output.plot_xy_data(dists, scores)
260 def set_label(self, label):
262 self.rs.set_name(label)
263 for r
in self.rs.get_restraints():
266 def add_to_model(self):
269 def get_hierarchies(self):
272 def get_restraint_sets(self):
275 def get_restraint(self):
278 def set_output_level(self, level="low"):
280 self.outputlevel = level
282 def set_weight(self, weight):
284 self.rs.set_weight(weight)
286 def get_output(self):
290 score = self.weight * self.rs.unprotected_evaluate(
None)
291 output[
"_TotalScore"] = str(score)
292 output[
"AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
293 for n, p
in enumerate(self.pairs):
304 for n1, p1
in enumerate(ps1):
307 for n2, p2
in enumerate(ps2):
311 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
312 output[
"AmbiguousCompositeRestraint_Distance_" +
315 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
316 output[
"AmbiguousCompositeRestraint_Score_" +
317 label] = str(self.weight * cr.unprotected_evaluate(
None))
323 class SimplifiedPEMAP(object):
325 def __init__(self, root_hier, restraints_file, expdistance, strength,
327 self.m = root_hier.get_model()
332 self.outputlevel =
"low"
333 self.expdistance = expdistance
334 self.strength = strength
336 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
340 tokens = line.split()
342 if (tokens[0] ==
"#"):
348 pcc = float(tokens[4])
351 molecule=c1, residue_index=r1,
353 ps1 = ps1.get_selected_particles()
356 "SimplifiedPEMAP: residue %d of chain %s is not there "
361 "SimplifiedPEMAP: residue %d of chain %s selected "
366 molecule=c2, residue_index=r2,
368 ps2 = ps2.get_selected_particles()
371 "SimplifiedPEMAP: residue %d of chain %s is not there "
376 "SimplifiedPEMAP: residue %d of chain %s selected "
384 upperdist = self.get_upper_bond(pcc)
385 limit = 0.5 * self.strength * 15.0 ** 2 + 10.0
387 upperdist, self.strength, 15, limit)
392 self.rs.add_restraint(dr)
393 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
396 lowerdist = self.get_lower_bond(pcc)
397 limit = 0.5 * self.strength * 15.0 ** 2 + 10.0
399 lowerdist, self.strength, 15, limit)
404 self.rs.add_restraint(dr2)
405 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
407 def get_upper_bond(self, pearsoncc):
409 return (pearsoncc - .5) / (-0.005415)
411 def get_lower_bond(self, pearsoncc):
412 return (pearsoncc - 1.) / -0.0551
414 def set_label(self, label):
417 def add_to_model(self):
420 def get_hierarchies(self):
423 def get_restraint_sets(self):
426 def set_output_level(self, level="low"):
428 self.outputlevel = level
430 def get_output(self):
434 score = self.rs.unprotected_evaluate(
None)
435 output[
"_TotalScore"] = str(score)
436 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
437 for i
in range(len(self.pairs)):
439 p0 = self.pairs[i][0]
440 p1 = self.pairs[i][1]
441 crosslinker =
'standard'
442 ln = self.pairs[i][2]
443 resid1 = self.pairs[i][3]
444 chain1 = self.pairs[i][4]
445 resid2 = self.pairs[i][5]
446 chain2 = self.pairs[i][6]
448 label = str(resid1) +
":" + chain1 +
"_" + \
449 str(resid2) +
":" + chain2
450 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
451 label] = str(ln.unprotected_evaluate(
None))
455 output[
"SimplifiedPEMAP_Distance_" +
464 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
466 cr=restraints.ConnectivityNetworkRestraint(
467 simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
471 Multistate support =No
472 Selection type=selection tuple
476 def __init__(self, objects, kappa=10.0, resolution=1.0, label="None"):
481 if self.label ==
"None":
482 self.label = str(selection_tuples)
488 obj, resolution, flatten=
True))
489 self.m = hiers[0][0].get_model()
493 cr.add_particles([h.get_particle()
for h
in hs])
495 self.rs.add_restraint(cr)
497 def set_label(self, label):
499 self.rs.set_name(label)
500 for r
in self.rs.get_restraints():
503 def add_to_model(self):
506 def get_restraint(self):
509 def get_restraints(self):
511 for r
in self.rs.get_restraints():
512 rlist.append(IMP.core.PairRestraint.get_from(r))
515 def set_weight(self, weight):
517 self.rs.set_weight(weight)
519 def get_output(self):
521 score = self.weight * self.rs.unprotected_evaluate(
None)
522 output[
"_TotalScore"] = str(score)
523 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
530 a python restraint that computes the score for a composite of proteins
531 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
534 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001,
537 input a list of particles, the slope and theta of the sigmoid potential
538 theta is the cutoff distance for a protein-protein contact
543 self.networkx = networkx
544 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
547 self.linear_slope = linear_slope
548 self.plateau = plateau
549 self.particles_blocks = []
550 self.particle_list = []
552 def get_number_of_particle_blocks(self):
553 return len(self.particles_blocks)
555 def get_number_of_particles_for_block(self, block_index):
556 return len(self.particles_blocks[block_index])
559 self.particles_blocks.append(particles)
560 self.particle_list += particles
564 get the full graph of distances between every particle pair
567 pdist_array = numpy.array(
569 self.particles_blocks))
570 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
571 pdist_mat[pdist_mat < 0] = 0
572 graph = self.networkx.Graph(pdist_mat)
577 return the minimum spanning tree
580 graph = self.networkx.minimum_spanning_tree(graph)
585 a sigmoid function that scores the probability of a contact
590 argvalue = (x - self.theta) / self.slope
591 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
596 for e
in graph.edges():
597 dist = graph.get_edge_data(*e)[
'weight']
599 score += -numpy.log(prob)
600 score += self.linear_slope * dist
604 return self.particle_list
610 Fully Ambiguous Restraint that can be built using boolean logic
611 R. Pellarin. Pasteur Institute.
616 input a list of particles, the slope and theta of the sigmoid potential
617 theta is the cutoff distance for a protein-protein contact
619 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
620 self.operations = [p1, operator, p2]
626 def __or__(self, FuzzyBoolean2):
629 def __and__(self, FuzzyBoolean2):
632 def and_(self, a, b):
636 return 1.0 - (1.0 - a) * (1.0 - b)
640 if len(self.operations) == 0:
642 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
644 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
650 Fully Ambiguous Restraint that can be built using boolean logic
651 R. Pellarin. Pasteur Institute.
653 plateau = 0.00000000000001
660 input a list of particles, the slope and theta of the sigmoid potential
661 theta is the cutoff distance for a protein-protein contact
663 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
665 self.min = sys.float_info.min
666 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
667 self.operations = [p1, operator, p2]
668 self.particle_pair =
None
669 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
670 self.operations = [p1, operator,
None]
671 self.particle_pair =
None
674 self.particle_pair = (p1, p2)
676 def __or__(self, FuzzyRestraint2):
679 def __and__(self, FuzzyRestraint2):
682 def __invert__(self):
685 def and_(self, a, b):
690 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
693 def invert_(self, a):
694 c = 1.0 - math.exp(-a)
698 if len(self.operations) == 0:
699 return self.distance()
700 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
702 if FuzzyRestraint2
is not None:
703 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
705 return op(FuzzyRestraint1.evaluate())
711 argvalue = (d-self.theta)/self.slope
712 return (-math.log(1.0 - (1.0-self.plateau) / (1.0+math.exp(-argvalue)))
715 def add_to_model(self):
719 return self.evaluate()
722 if len(self.operations) == 0:
723 return str(self.particle_pair)
724 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
725 if FuzzyRestraint2
is not None:
726 return str(FuzzyRestraint1) + str(op) + str(FuzzyRestraint2)
728 return str(FuzzyRestraint1) + str(op)
731 if len(self.operations) == 0:
732 return list(self.particle_pair)
733 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
734 if FuzzyRestraint2
is not None:
735 return list(set(FuzzyRestraint1.do_get_inputs()
736 + FuzzyRestraint2.do_get_inputs()))
738 return list(set(FuzzyRestraint1.do_get_inputs()))
A function that is harmonic over an interval.
this restraint allows ambiguous cross-linking between multiple copies excluding between symmetric cop...
void add_particles(RMF::FileHandle fh, const ParticlesTemp &hs)
Various classes to hold sets of particles.
static XYZR setup_particle(Model *m, ParticleIndex pi)
generate a connectivity restraint between domains setting up the restraint example: sel1 = IMP...
def get_full_graph
get the full graph of distances between every particle pair
virtual double unprotected_evaluate(DerivativeAccumulator *da) const
Return the unweighted score for the restraint.
Add symmetric attribute to a particle.
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.
generates and wraps a IMP.pmi.ConnectivityRestraint between domains example: cr=restraints.ConnectivityNetworkRestraint( simo,["CCC",(1,100,"TTT"),(100,150,"AAA")]) cr.add_to_model() cr.set_label("CR1")
Object used to hold a set of restraints.
Warning related to handling of structures.
a python restraint that computes the score for a composite of proteins Authors: G.
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
static bool get_is_setup(Model *m, ParticleIndex pi)
def get_minimum_spanning_tree
return the minimum spanning tree
A restraint for ambiguous cross-linking MS data and multiple state approach.
A decorator for a particle with x,y,z coordinates.
handleparticles a list of particles compositeparticles is a list of list of particles ...
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...
Fully Ambiguous Restraint that can be built using boolean logic R.
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
Class to handle individual particles of a Model object.
Floats get_list_of_bipartite_minimum_sphere_distance(const ParticlesTemps &pss)
def sigmoid
a sigmoid function that scores the probability of a contact between two proteins
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.
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.
Fully Ambiguous Restraint that can be built using boolean logic R.
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
virtual ModelObjectsTemp do_get_inputs() const =0
A restraint is a term in an IMP ScoringFunction.
A decorator for a particle with x,y,z coordinates and a radius.