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 crosslinking 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
490 if self.label ==
"None":
491 self.label = str(selection_tuples)
495 if representation
is None:
501 self.m=hiers[0][0].get_model()
503 self.m = representation.m
505 hiers.append(IMP.pmi.tools.select_by_tuple(representation, s,
506 resolution=resolution,
507 name_is_ambiguous=
False))
512 cr.add_particles([h.get_particle()
for h
in hs])
514 self.rs.add_restraint(cr)
516 def set_label(self, label):
518 self.rs.set_name(label)
519 for r
in self.rs.get_restraints():
522 def add_to_model(self):
525 def get_restraint(self):
528 def get_restraints(self):
530 for r
in self.rs.get_restraints():
531 rlist.append(IMP.core.PairRestraint.get_from(r))
534 def set_weight(self, weight):
536 self.rs.set_weight(weight)
538 def get_output(self):
540 score = self.weight * self.rs.unprotected_evaluate(
None)
541 output[
"_TotalScore"] = str(score)
542 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
549 a python restraint that computes the score for a composite of proteins
550 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
553 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001, linear_slope=0.015):
555 input a list of particles, the slope and theta of the sigmoid potential
556 theta is the cutoff distance for a protein-protein contact
561 self.networkx = networkx
562 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
565 self.linear_slope = linear_slope
566 self.plateau = plateau
567 self.particles_blocks = []
568 self.particle_list = []
570 def get_number_of_particle_blocks(self):
571 return len(self.particles_blocks)
573 def get_number_of_particles_for_block(self, block_index):
574 return len(self.particles_blocks[block_index])
577 self.particles_blocks.append(particles)
578 self.particle_list += particles
582 get the full graph of distances between every particle pair
585 pdist_array = numpy.array(
587 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
588 pdist_mat[pdist_mat < 0] = 0
589 graph = self.networkx.Graph(pdist_mat)
594 return the minimum spanning tree
597 graph = self.networkx.minimum_spanning_tree(graph)
602 a sigmoid function that scores the probability of a contact
607 argvalue = (x - self.theta) / self.slope
608 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
610 def unprotected_evaluate(self, da):
613 for e
in graph.edges():
614 dist = graph.get_edge_data(*e)[
'weight']
616 score += -numpy.log(prob)
617 score += self.linear_slope * dist
621 return self.particle_list
627 Fully Ambiguous Restraint that can be built using boolean logic
628 R. Pellarin. Pasteur Institute.
633 input a list of particles, the slope and theta of the sigmoid potential
634 theta is the cutoff distance for a protein-protein contact
636 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
637 self.operations = [p1, operator, p2]
643 def __or__(self, FuzzyBoolean2):
646 def __and__(self, FuzzyBoolean2):
649 def and_(self, a, b):
653 return 1.0 - (1.0 - a) * (1.0 - b)
657 if len(self.operations) == 0:
659 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
661 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
667 Fully Ambiguous Restraint that can be built using boolean logic
668 R. Pellarin. Pasteur Institute.
670 plateau = 0.00000000000001
677 input a list of particles, the slope and theta of the sigmoid potential
678 theta is the cutoff distance for a protein-protein contact
680 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
682 self.min = sys.float_info.min
683 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
684 self.operations = [p1, operator, p2]
685 self.particle_pair =
None
686 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
687 self.operations = [p1, operator,
None]
688 self.particle_pair =
None
691 self.particle_pair = (p1, p2)
693 def __or__(self, FuzzyRestraint2):
696 def __and__(self, FuzzyRestraint2):
699 def __invert__(self):
702 def and_(self, a, b):
707 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
710 def invert_(self, a):
711 c = 1.0 - math.exp(-a)
715 if len(self.operations) == 0:
716 return self.distance()
717 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
719 if FuzzyRestraint2
is not None:
720 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
722 return op(FuzzyRestraint1.evaluate())
728 argvalue = (d-self.theta)/self.slope
729 return -math.log(1.0 -(1.0-self.plateau)/(1.0+math.exp(-argvalue)))+self.innerslope*d
731 def add_to_model(self):
734 def unprotected_evaluate(self, da):
735 return self.evaluate()
738 if len(self.operations) == 0:
739 return str(self.particle_pair)
740 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
741 if FuzzyRestraint2
is not None:
742 return str(FuzzyRestraint1) +str(op)+str(FuzzyRestraint2)
744 return str(FuzzyRestraint1) +str(op)
747 if len(self.operations) == 0:
748 return list(self.particle_pair)
749 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
750 if FuzzyRestraint2
is not None:
751 return list(set(FuzzyRestraint1.do_get_inputs() +FuzzyRestraint2.do_get_inputs()))
753 return list(set(FuzzyRestraint1.do_get_inputs()))
A function that is harmonic over an interval.
this restraint allows ambiguous crosslinking between multiple copies excluding between symmetric copi...
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.