1 """@namespace IMP.pmi.restraints.proteomics
2 Restraints for handling various kinds of proteomics data.
22 generate a connectivity restraint between domains
23 setting up the restraint
25 sel1 = IMP.atom.Selection(root_hier, molecule="Rpb3",
26 residue_indexes=range(1,100))
27 sel2 = IMP.atom.Selection(root_hier, molecule="Rpb4",
28 residue_indexes=range(1,100))
29 cr=restraints.ConnectivityRestraint((sel1, sel2), label='CR1')
31 Multistate support =No
35 def __init__(self, domains, kappa=10.0, resolution=None, label="None"):
41 domains, self.kappa, self.label)
42 self.m = cr.get_model()
44 self.rs.add_restraint(cr)
46 def set_label(self, label):
48 self.rs.set_name(label)
49 for r
in self.rs.get_restraints():
52 def add_to_model(self):
55 def get_restraint(self):
58 def get_restraints(self):
60 for r
in self.rs.get_restraints():
61 rlist.append(IMP.core.PairRestraint.get_from(r))
64 def set_weight(self, weight):
66 self.rs.set_weight(weight)
70 score = self.weight * self.rs.unprotected_evaluate(
None)
71 output[
"_TotalScore"] = str(score)
72 output[
"ConnectivityRestraint_" + self.label] = str(score)
81 handleparticles a list of particles
82 compositeparticles is a list of list of particles
85 def __init__(self, handle_particles, composite_particles, cut_off=5.0,
86 lam=1.0, plateau=0.0, resolution=
None, label=
"None"):
92 self.handleparticles = [h.get_particle()
for h
in hs]
93 self.m = self.handleparticles[0].get_model()
96 self.compositeparticles = []
97 compositeparticle_list = []
98 for cp
in composite_particles:
100 tmplist = [h.get_particle()
for h
in hs]
101 compositeparticle_list.append(tmplist)
102 self.compositeparticles += tmplist
105 self.m, self.handleparticles, cut_off, lam,
True, plateau)
107 for ps
in compositeparticle_list:
109 ln.add_composite_particle(ps)
111 self.rs.add_restraint(ln)
113 def set_label(self, label):
116 def get_handle_particles(self):
117 return self.handleparticles
119 def get_composite_particles(self):
120 return self.compositeparticles
122 def get_restraint(self):
125 def add_to_model(self):
128 def get_output(self):
130 score = self.rs.unprotected_evaluate(
None)
131 output[
"_TotalScore"] = str(score)
132 output[
"CompositeRestraint_" + self.label] = str(score)
140 this restraint allows ambiguous cross-linking between multiple copies
141 excluding between symmetric copies
142 It allows name ambiguity
145 def __init__(self, root_hier, restraints_file, cut_off=5.0, lam=1.0,
146 plateau=0.01, resolution=
None, label=
"None"):
148 self.m = root_hier.get_model()
153 self.outputlevel =
"low"
154 self.cut_off = cut_off
156 self.plateau = plateau
158 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
162 tokens = line.split()
164 if (tokens[0] ==
"#"):
172 molecule=c1, residue_index=r1)
173 ps1 = ps1.get_selected_particles()
174 hrc1 = [p.get_name()
for p
in ps1]
176 def nosym_subset(ps):
179 ps1nosym = nosym_subset(ps1)
180 hrc1nosym = [p.get_name()
for p
in ps1nosym]
184 "AmbiguousCompositeRestraint: residue %d of chain %s "
189 molecule=c2, residue_index=r2)
190 ps2 = ps2.get_selected_particles()
191 hrc2 = [p.get_name()
for p
in ps2]
192 ps2nosym = nosym_subset(ps2)
193 hrc2nosym = [p.get_name()
for p
in ps2nosym]
197 "AmbiguousCompositeRestraint: residue %d of chain %s "
202 self.m, ps1nosym, self.cut_off, self.lam,
True, self.plateau)
203 cr.add_composite_particle(ps2)
205 self.rs.add_restraint(cr)
218 self.m, ps1, self.cut_off, self.lam,
True, self.plateau)
219 cr.add_composite_particle(ps2nosym)
221 self.rs.add_restraint(cr)
249 cr.add_composite_particle([p2])
252 for i
in range(npoints):
256 scores.append(cr.unprotected_evaluate(
None))
257 IMP.pmi.output.plot_xy_data(dists, scores)
259 def set_label(self, label):
261 self.rs.set_name(label)
262 for r
in self.rs.get_restraints():
265 def add_to_model(self):
268 def get_hierarchies(self):
271 def get_restraint_sets(self):
274 def get_restraint(self):
277 def set_output_level(self, level="low"):
279 self.outputlevel = level
281 def set_weight(self, weight):
283 self.rs.set_weight(weight)
285 def get_output(self):
289 score = self.weight * self.rs.unprotected_evaluate(
None)
290 output[
"_TotalScore"] = str(score)
291 output[
"AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
292 for n, p
in enumerate(self.pairs):
303 for n1, p1
in enumerate(ps1):
306 for n2, p2
in enumerate(ps2):
310 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
311 output[
"AmbiguousCompositeRestraint_Distance_" +
314 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
315 output[
"AmbiguousCompositeRestraint_Score_" +
316 label] = str(self.weight * cr.unprotected_evaluate(
None))
322 class SimplifiedPEMAP:
324 def __init__(self, root_hier, restraints_file, expdistance, strength,
326 self.m = root_hier.get_model()
331 self.outputlevel =
"low"
332 self.expdistance = expdistance
333 self.strength = strength
335 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
339 tokens = line.split()
341 if (tokens[0] ==
"#"):
347 pcc = float(tokens[4])
350 molecule=c1, residue_index=r1,
352 ps1 = ps1.get_selected_particles()
355 "SimplifiedPEMAP: residue %d of chain %s is not there "
360 "SimplifiedPEMAP: residue %d of chain %s selected "
365 molecule=c2, residue_index=r2,
367 ps2 = ps2.get_selected_particles()
370 "SimplifiedPEMAP: residue %d of chain %s is not there "
375 "SimplifiedPEMAP: residue %d of chain %s selected "
383 upperdist = self.get_upper_bond(pcc)
384 limit = 0.5 * self.strength * 15.0 ** 2 + 10.0
386 upperdist, self.strength, 15, limit)
391 self.rs.add_restraint(dr)
392 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
395 lowerdist = self.get_lower_bond(pcc)
396 limit = 0.5 * self.strength * 15.0 ** 2 + 10.0
398 lowerdist, self.strength, 15, limit)
403 self.rs.add_restraint(dr2)
404 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
406 def get_upper_bond(self, pearsoncc):
408 return (pearsoncc - .5) / (-0.005415)
410 def get_lower_bond(self, pearsoncc):
411 return (pearsoncc - 1.) / -0.0551
413 def set_label(self, label):
416 def add_to_model(self):
419 def get_hierarchies(self):
422 def get_restraint_sets(self):
425 def set_output_level(self, level="low"):
427 self.outputlevel = level
429 def get_output(self):
433 score = self.rs.unprotected_evaluate(
None)
434 output[
"_TotalScore"] = str(score)
435 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
436 for i
in range(len(self.pairs)):
438 p0 = self.pairs[i][0]
439 p1 = self.pairs[i][1]
440 crosslinker =
'standard'
441 ln = self.pairs[i][2]
442 resid1 = self.pairs[i][3]
443 chain1 = self.pairs[i][4]
444 resid2 = self.pairs[i][5]
445 chain2 = self.pairs[i][6]
447 label = str(resid1) +
":" + chain1 +
"_" + \
448 str(resid2) +
":" + chain2
449 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
450 label] = str(ln.unprotected_evaluate(
None))
454 output[
"SimplifiedPEMAP_Distance_" +
463 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
465 cr=restraints.ConnectivityNetworkRestraint(
466 simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
470 Multistate support =No
471 Selection type=selection tuple
475 def __init__(self, objects, kappa=10.0, resolution=1.0, label="None"):
480 if self.label ==
"None":
481 self.label = str(selection_tuples)
487 obj, resolution, flatten=
True))
488 self.m = hiers[0][0].get_model()
492 cr.add_particles([h.get_particle()
for h
in hs])
494 self.rs.add_restraint(cr)
496 def set_label(self, label):
498 self.rs.set_name(label)
499 for r
in self.rs.get_restraints():
502 def add_to_model(self):
505 def get_restraint(self):
508 def get_restraints(self):
510 for r
in self.rs.get_restraints():
511 rlist.append(IMP.core.PairRestraint.get_from(r))
514 def set_weight(self, weight):
516 self.rs.set_weight(weight)
518 def get_output(self):
520 score = self.weight * self.rs.unprotected_evaluate(
None)
521 output[
"_TotalScore"] = str(score)
522 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
529 a python restraint that computes the score for a composite of proteins
530 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
533 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001,
536 input a list of particles, the slope and theta of the sigmoid potential
537 theta is the cutoff distance for a protein-protein contact
542 self.networkx = networkx
543 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
546 self.linear_slope = linear_slope
547 self.plateau = plateau
548 self.particles_blocks = []
549 self.particle_list = []
551 def get_number_of_particle_blocks(self):
552 return len(self.particles_blocks)
554 def get_number_of_particles_for_block(self, block_index):
555 return len(self.particles_blocks[block_index])
558 self.particles_blocks.append(particles)
559 self.particle_list += particles
563 get the full graph of distances between every particle pair
566 pdist_array = numpy.array(
568 self.particles_blocks))
569 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
570 pdist_mat[pdist_mat < 0] = 0
571 graph = self.networkx.Graph(pdist_mat)
576 return the minimum spanning tree
579 graph = self.networkx.minimum_spanning_tree(graph)
584 a sigmoid function that scores the probability of a contact
589 argvalue = (x - self.theta) / self.slope
590 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
595 for e
in graph.edges():
596 dist = graph.get_edge_data(*e)[
'weight']
598 score += -numpy.log(prob)
599 score += self.linear_slope * dist
603 return self.particle_list
609 Fully Ambiguous Restraint that can be built using boolean logic
610 R. Pellarin. Pasteur Institute.
615 input a list of particles, the slope and theta of the sigmoid potential
616 theta is the cutoff distance for a protein-protein contact
618 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
619 self.operations = [p1, operator, p2]
625 def __or__(self, FuzzyBoolean2):
628 def __and__(self, FuzzyBoolean2):
631 def and_(self, a, b):
635 return 1.0 - (1.0 - a) * (1.0 - b)
639 if len(self.operations) == 0:
641 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
643 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
649 Fully Ambiguous Restraint that can be built using boolean logic
650 R. Pellarin. Pasteur Institute.
652 plateau = 0.00000000000001
659 input a list of particles, the slope and theta of the sigmoid potential
660 theta is the cutoff distance for a protein-protein contact
662 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
664 self.min = sys.float_info.min
665 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
666 self.operations = [p1, operator, p2]
667 self.particle_pair =
None
668 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
669 self.operations = [p1, operator,
None]
670 self.particle_pair =
None
673 self.particle_pair = (p1, p2)
675 def __or__(self, FuzzyRestraint2):
678 def __and__(self, FuzzyRestraint2):
681 def __invert__(self):
684 def and_(self, a, b):
689 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
692 def invert_(self, a):
693 c = 1.0 - math.exp(-a)
697 if len(self.operations) == 0:
698 return self.distance()
699 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
701 if FuzzyRestraint2
is not None:
702 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
704 return op(FuzzyRestraint1.evaluate())
710 argvalue = (d-self.theta)/self.slope
711 return (-math.log(1.0 - (1.0-self.plateau) / (1.0+math.exp(-argvalue)))
714 def add_to_model(self):
721 if len(self.operations) == 0:
722 return str(self.particle_pair)
723 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
724 if FuzzyRestraint2
is not None:
725 return str(FuzzyRestraint1) + str(op) + str(FuzzyRestraint2)
727 return str(FuzzyRestraint1) + str(op)
730 if len(self.operations) == 0:
731 return list(self.particle_pair)
732 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
733 if FuzzyRestraint2
is not None:
734 return list(set(FuzzyRestraint1.do_get_inputs()
735 + FuzzyRestraint2.do_get_inputs()))
737 return list(set(FuzzyRestraint1.do_get_inputs()))
A function that is harmonic over an bounded 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.
double evaluate(bool calc_derivs) const
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.