1 """@namespace IMP.pmi.restraints.proteomics
2 Restraints for handling various kinds of proteomics data.
5 from __future__
import print_function
24 generate a connectivity restraint between domains
25 setting up the restraint
27 sel1 = IMP.atom.Selection(root_hier, molecule="Rpb3",
28 residue_indexes=range(1,100))
29 sel2 = IMP.atom.Selection(root_hier, molecule="Rpb4",
30 residue_indexes=range(1,100))
31 cr=restraints.ConnectivityRestraint((sel1, sel2), label='CR1')
33 Multistate support =No
37 def __init__(self, domains, kappa=10.0, resolution=None, label="None"):
43 domains, self.kappa, self.label)
44 self.m = cr.get_model()
46 self.rs.add_restraint(cr)
48 def set_label(self, label):
50 self.rs.set_name(label)
51 for r
in self.rs.get_restraints():
54 def add_to_model(self):
57 def get_restraint(self):
60 def get_restraints(self):
62 for r
in self.rs.get_restraints():
63 rlist.append(IMP.core.PairRestraint.get_from(r))
66 def set_weight(self, weight):
68 self.rs.set_weight(weight)
72 score = self.weight * self.rs.unprotected_evaluate(
None)
73 output[
"_TotalScore"] = str(score)
74 output[
"ConnectivityRestraint_" + self.label] = str(score)
83 handleparticles a list of particles
84 compositeparticles is a list of list of particles
87 def __init__(self, handle_particles, composite_particles, cut_off=5.0,
88 lam=1.0, plateau=0.0, resolution=
None, label=
"None"):
94 self.handleparticles = [h.get_particle()
for h
in hs]
95 self.m = self.handleparticles[0].get_model()
98 self.compositeparticles = []
99 compositeparticle_list = []
100 for cp
in composite_particles:
102 tmplist = [h.get_particle()
for h
in hs]
103 compositeparticle_list.append(tmplist)
104 self.compositeparticles += tmplist
109 for ps
in compositeparticle_list:
111 ln.add_composite_particle(ps)
113 self.rs.add_restraint(ln)
115 def set_label(self, label):
118 def get_handle_particles(self):
119 return self.handleparticles
121 def get_composite_particles(self):
122 return self.compositeparticles
124 def get_restraint(self):
127 def add_to_model(self):
130 def get_output(self):
132 score = self.rs.unprotected_evaluate(
None)
133 output[
"_TotalScore"] = str(score)
134 output[
"CompositeRestraint_" + self.label] = str(score)
142 this restraint allows ambiguous cross-linking between multiple copies
143 excluding between symmetric copies
144 It allows name ambiguity
147 def __init__(self, root_hier, restraints_file, cut_off=5.0, lam=1.0,
148 plateau=0.01, resolution=
None, label=
"None"):
150 self.m = root_hier.get_model()
155 self.outputlevel =
"low"
156 self.cut_off = cut_off
158 self.plateau = plateau
160 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
164 tokens = line.split()
166 if (tokens[0] ==
"#"):
174 molecule=c1, residue_index=r1)
175 ps1 = ps1.get_selected_particles()
176 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)
394 self.rs.add_restraint(dr)
395 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
398 lowerdist = self.get_lower_bond(pcc)
399 limit = 0.5 * self.strength * 15.0 ** 2 + 10.0
401 lowerdist, self.strength, 15, limit)
408 self.rs.add_restraint(dr2)
409 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
411 def get_upper_bond(self, pearsoncc):
413 return (pearsoncc - .5) / (-0.005415)
415 def get_lower_bond(self, pearsoncc):
416 return (pearsoncc - 1.) / -0.0551
418 def set_label(self, label):
421 def add_to_model(self):
424 def get_hierarchies(self):
427 def get_restraint_sets(self):
430 def set_output_level(self, level="low"):
432 self.outputlevel = level
434 def get_output(self):
438 score = self.rs.unprotected_evaluate(
None)
439 output[
"_TotalScore"] = str(score)
440 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
441 for i
in range(len(self.pairs)):
443 p0 = self.pairs[i][0]
444 p1 = self.pairs[i][1]
445 crosslinker =
'standard'
446 ln = self.pairs[i][2]
447 resid1 = self.pairs[i][3]
448 chain1 = self.pairs[i][4]
449 resid2 = self.pairs[i][5]
450 chain2 = self.pairs[i][6]
452 label = str(resid1) +
":" + chain1 +
"_" + \
453 str(resid2) +
":" + chain2
454 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
455 label] = str(ln.unprotected_evaluate(
None))
459 output[
"SimplifiedPEMAP_Distance_" +
468 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
470 cr=restraints.ConnectivityNetworkRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
474 Multistate support =No
475 Selection type=selection tuple
479 def __init__(self, objects, kappa=10.0, resolution=1.0, label="None"):
484 if self.label ==
"None":
485 self.label = str(selection_tuples)
493 self.m=hiers[0][0].get_model()
498 cr.add_particles([h.get_particle()
for h
in hs])
500 self.rs.add_restraint(cr)
502 def set_label(self, label):
504 self.rs.set_name(label)
505 for r
in self.rs.get_restraints():
508 def add_to_model(self):
511 def get_restraint(self):
514 def get_restraints(self):
516 for r
in self.rs.get_restraints():
517 rlist.append(IMP.core.PairRestraint.get_from(r))
520 def set_weight(self, weight):
522 self.rs.set_weight(weight)
524 def get_output(self):
526 score = self.weight * self.rs.unprotected_evaluate(
None)
527 output[
"_TotalScore"] = str(score)
528 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
535 a python restraint that computes the score for a composite of proteins
536 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
539 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001, linear_slope=0.015):
541 input a list of particles, the slope and theta of the sigmoid potential
542 theta is the cutoff distance for a protein-protein contact
547 self.networkx = networkx
548 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
551 self.linear_slope = linear_slope
552 self.plateau = plateau
553 self.particles_blocks = []
554 self.particle_list = []
556 def get_number_of_particle_blocks(self):
557 return len(self.particles_blocks)
559 def get_number_of_particles_for_block(self, block_index):
560 return len(self.particles_blocks[block_index])
563 self.particles_blocks.append(particles)
564 self.particle_list += particles
568 get the full graph of distances between every particle pair
571 pdist_array = numpy.array(
573 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
574 pdist_mat[pdist_mat < 0] = 0
575 graph = self.networkx.Graph(pdist_mat)
580 return the minimum spanning tree
583 graph = self.networkx.minimum_spanning_tree(graph)
588 a sigmoid function that scores the probability of a contact
593 argvalue = (x - self.theta) / self.slope
594 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
596 def unprotected_evaluate(self, da):
599 for e
in graph.edges():
600 dist = graph.get_edge_data(*e)[
'weight']
602 score += -numpy.log(prob)
603 score += self.linear_slope * dist
607 return self.particle_list
613 Fully Ambiguous Restraint that can be built using boolean logic
614 R. Pellarin. Pasteur Institute.
619 input a list of particles, the slope and theta of the sigmoid potential
620 theta is the cutoff distance for a protein-protein contact
622 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
623 self.operations = [p1, operator, p2]
629 def __or__(self, FuzzyBoolean2):
632 def __and__(self, FuzzyBoolean2):
635 def and_(self, a, b):
639 return 1.0 - (1.0 - a) * (1.0 - b)
643 if len(self.operations) == 0:
645 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
647 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
653 Fully Ambiguous Restraint that can be built using boolean logic
654 R. Pellarin. Pasteur Institute.
656 plateau = 0.00000000000001
663 input a list of particles, the slope and theta of the sigmoid potential
664 theta is the cutoff distance for a protein-protein contact
666 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
668 self.min = sys.float_info.min
669 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
670 self.operations = [p1, operator, p2]
671 self.particle_pair =
None
672 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
673 self.operations = [p1, operator,
None]
674 self.particle_pair =
None
677 self.particle_pair = (p1, p2)
679 def __or__(self, FuzzyRestraint2):
682 def __and__(self, FuzzyRestraint2):
685 def __invert__(self):
688 def and_(self, a, b):
693 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
696 def invert_(self, a):
697 c = 1.0 - math.exp(-a)
701 if len(self.operations) == 0:
702 return self.distance()
703 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
705 if FuzzyRestraint2
is not None:
706 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
708 return op(FuzzyRestraint1.evaluate())
714 argvalue = (d-self.theta)/self.slope
715 return -math.log(1.0 -(1.0-self.plateau)/(1.0+math.exp(-argvalue)))+self.innerslope*d
717 def add_to_model(self):
720 def unprotected_evaluate(self, da):
721 return self.evaluate()
724 if len(self.operations) == 0:
725 return str(self.particle_pair)
726 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
727 if FuzzyRestraint2
is not None:
728 return str(FuzzyRestraint1) +str(op)+str(FuzzyRestraint2)
730 return str(FuzzyRestraint1) +str(op)
733 if len(self.operations) == 0:
734 return list(self.particle_pair)
735 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
736 if FuzzyRestraint2
is not None:
737 return list(set(FuzzyRestraint1.do_get_inputs() +FuzzyRestraint2.do_get_inputs()))
739 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
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.