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 cr=restraints.ConnectivityRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
30 Multistate support =No
31 Selection type=selection tuple
46 if self.label ==
"None":
47 self.label = str(selection_tuples)
48 self.m = representation.prot.get_model()
53 for s
in selection_tuples:
54 particles = IMP.pmi.tools.select_by_tuple(representation, s,
55 resolution=resolution, name_is_ambiguous=
True)
63 self.rs.add_restraint(cr)
65 def set_label(self, label):
67 self.rs.set_name(label)
68 for r
in self.rs.get_restraints():
71 def add_to_model(self):
74 def get_restraint(self):
77 def get_restraints(self):
79 for r
in self.rs.get_restraints():
80 rlist.append(IMP.core.PairRestraint.get_from(r))
83 def set_weight(self, weight):
85 self.rs.set_weight(weight)
89 score = self.weight * self.rs.unprotected_evaluate(
None)
90 output[
"_TotalScore"] = str(score)
91 output[
"ConnectivityRestraint_" + self.label] = str(score)
100 handleparticles is a selection tuple
101 compositeparticles is a list of selection tuples
107 handleparticles_tuples,
108 compositeparticles_tuple_list,
117 self.m = representation.prot.get_model()
120 self.handleparticles = []
121 for s
in handleparticles_tuples:
122 self.handleparticles += IMP.pmi.tools.select_by_tuple(
124 resolution=resolution, name_is_ambiguous=
True)
125 self.compositeparticles = []
126 compositeparticle_list = []
127 for list
in compositeparticles_tuple_list:
130 tmplist += IMP.pmi.tools.select_by_tuple(
132 resolution=resolution, name_is_ambiguous=
True)
133 compositeparticle_list.append(tmplist)
134 self.compositeparticles += tmplist
138 self.handleparticles,
144 for ps
in compositeparticle_list:
146 ln.add_composite_particle(ps)
148 self.rs.add_restraint(ln)
150 def set_label(self, label):
153 def get_handle_particles(self):
154 return self.handleparticles
156 def get_composite_particles(self):
157 return self.compositeparticles
159 def get_restraint(self):
162 def add_to_model(self):
165 def get_output(self):
167 score = self.rs.unprotected_evaluate(
None)
168 output[
"_TotalScore"] = str(score)
169 output[
"CompositeRestraint_" + self.label] = str(score)
177 this restraint allows ambiguous crosslinking between multiple copies
178 excluding between symmetric copies
179 It allows name ambiguity
193 self.m = representation.prot.get_model()
198 self.outputlevel =
"low"
199 self.cut_off = cut_off
201 self.plateau = plateau
203 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
207 tokens = line.split()
209 if (tokens[0] ==
"#"):
218 resolution=resolution,
220 name_is_ambiguous=
True,
222 hrc1 = [representation.hier_db.particle_to_name[p]
for p
in ps1]
227 hrc1nosym = [representation.hier_db.particle_to_name[p]
232 "AmbiguousCompositeRestraint: residue %d of chain %s "
238 resolution=resolution,
240 name_is_ambiguous=
True,
242 hrc2 = [representation.hier_db.particle_to_name[p]
for p
in ps2]
247 hrc2nosym = [representation.hier_db.particle_to_name[p]
252 "AmbiguousCompositeRestraint: residue %d of chain %s "
263 cr.add_composite_particle(ps2)
265 self.rs.add_restraint(cr)
284 cr.add_composite_particle(ps2nosym)
286 self.rs.add_restraint(cr)
314 cr.add_composite_particle([p2])
317 for i
in range(npoints):
321 scores.append(cr.unprotected_evaluate(
None))
322 IMP.pmi.output.plot_xy_data(dists, scores)
324 def set_label(self, label):
326 self.rs.set_name(label)
327 for r
in self.rs.get_restraints():
330 def add_to_model(self):
333 def get_hierarchies(self):
336 def get_restraint_sets(self):
339 def get_restraint(self):
342 def set_output_level(self, level="low"):
344 self.outputlevel = level
346 def set_weight(self, weight):
348 self.rs.set_weight(weight)
350 def get_output(self):
354 score = self.weight * self.rs.unprotected_evaluate(
None)
355 output[
"_TotalScore"] = str(score)
356 output[
"AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
357 for n, p
in enumerate(self.pairs):
368 for n1, p1
in enumerate(ps1):
371 for n2, p2
in enumerate(ps2):
375 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
376 output[
"AmbiguousCompositeRestraint_Distance_" +
379 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
380 output[
"AmbiguousCompositeRestraint_Score_" +
381 label] = str(self.weight * cr.unprotected_evaluate(
None))
387 class SimplifiedPEMAP(object):
397 self.m = representation.prot.get_model()
402 self.outputlevel =
"low"
403 self.expdistance = expdistance
404 self.strength = strength
406 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
410 tokens = line.split()
412 if (tokens[0] ==
"#"):
418 pcc = float(tokens[4])
422 resolution=resolution,
424 name_is_ambiguous=
False,
428 "SimplifiedPEMAP: residue %d of chain %s is not there "
433 "SimplifiedPEMAP: residue %d of chain %s selected "
439 resolution=resolution,
441 name_is_ambiguous=
False,
445 "SimplifiedPEMAP: residue %d of chain %s is not there "
450 "SimplifiedPEMAP: residue %d of chain %s selected "
458 upperdist = self.get_upper_bond(pcc)
459 limit = self.strength * (upperdist + 15) ** 2 + 10.0
472 self.rs.add_restraint(dr)
473 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
476 lowerdist = self.get_lower_bond(pcc)
477 limit = self.strength * (lowerdist - 15) ** 2 + 10.0
490 self.rs.add_restraint(dr2)
491 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
493 def get_upper_bond(self, pearsoncc):
495 return (pearsoncc - .5) / (-0.005415)
497 def get_lower_bond(self, pearsoncc):
498 return (pearsoncc - 1.) / -0.0551
500 def set_label(self, label):
503 def add_to_model(self):
506 def get_hierarchies(self):
509 def get_restraint_sets(self):
512 def set_output_level(self, level="low"):
514 self.outputlevel = level
516 def get_output(self):
520 score = self.rs.unprotected_evaluate(
None)
521 output[
"_TotalScore"] = str(score)
522 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
523 for i
in range(len(self.pairs)):
525 p0 = self.pairs[i][0]
526 p1 = self.pairs[i][1]
527 crosslinker =
'standard'
528 ln = self.pairs[i][2]
529 resid1 = self.pairs[i][3]
530 chain1 = self.pairs[i][4]
531 resid2 = self.pairs[i][5]
532 chain2 = self.pairs[i][6]
534 label = str(resid1) +
":" + chain1 +
"_" + \
535 str(resid2) +
":" + chain2
536 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
537 label] = str(ln.unprotected_evaluate(
None))
541 output[
"SimplifiedPEMAP_Distance_" +
550 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
552 cr=restraints.ConnectivityNetworkRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
556 Multistate support =No
557 Selection type=selection tuple
572 if self.label ==
"None":
573 self.label = str(selection_tuples)
577 if representation
is None:
583 self.m=hiers[0][0].get_model()
585 self.m = representation.m
587 hiers.append(IMP.pmi.tools.select_by_tuple(representation, s,
588 resolution=resolution,
589 name_is_ambiguous=
False))
594 cr.add_particles([h.get_particle()
for h
in hs])
596 self.rs.add_restraint(cr)
598 def set_label(self, label):
600 self.rs.set_name(label)
601 for r
in self.rs.get_restraints():
604 def add_to_model(self):
607 def get_restraint(self):
610 def get_restraints(self):
612 for r
in self.rs.get_restraints():
613 rlist.append(IMP.core.PairRestraint.get_from(r))
616 def set_weight(self, weight):
618 self.rs.set_weight(weight)
620 def get_output(self):
622 score = self.weight * self.rs.unprotected_evaluate(
None)
623 output[
"_TotalScore"] = str(score)
624 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
631 a python restraint that computes the score for a composite of proteins
632 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
635 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001, linear_slope=0.015):
637 input a list of particles, the slope and theta of the sigmoid potential
638 theta is the cutoff distance for a protein-protein contact
643 self.networkx = networkx
644 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
647 self.linear_slope = linear_slope
648 self.plateau = plateau
649 self.particles_blocks = []
650 self.particle_list = []
652 def get_number_of_particle_blocks(self):
653 return len(self.particles_blocks)
655 def get_number_of_particles_for_block(self, block_index):
656 return len(self.particles_blocks[block_index])
659 self.particles_blocks.append(particles)
660 self.particle_list += particles
664 get the full graph of distances between every particle pair
667 pdist_array = numpy.array(
669 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
670 pdist_mat[pdist_mat < 0] = 0
671 graph = self.networkx.Graph(pdist_mat)
676 return the minimum spanning tree
679 graph = self.networkx.minimum_spanning_tree(graph)
684 a sigmoid function that scores the probability of a contact
689 argvalue = (x - self.theta) / self.slope
690 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
692 def unprotected_evaluate(self, da):
695 for e
in graph.edges():
696 dist = graph.get_edge_data(*e)[
'weight']
698 score += -numpy.log(prob)
699 score += self.linear_slope * dist
703 return self.particle_list
709 Fully Ambiguous Restraint that can be built using boolean logic
710 R. Pellarin. Pasteur Institute.
715 input a list of particles, the slope and theta of the sigmoid potential
716 theta is the cutoff distance for a protein-protein contact
718 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
719 self.operations = [p1, operator, p2]
725 def __or__(self, FuzzyBoolean2):
728 def __and__(self, FuzzyBoolean2):
731 def and_(self, a, b):
735 return 1.0 - (1.0 - a) * (1.0 - b)
739 if len(self.operations) == 0:
741 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
743 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
749 Fully Ambiguous Restraint that can be built using boolean logic
750 R. Pellarin. Pasteur Institute.
752 plateau = 0.00000000000001
759 input a list of particles, the slope and theta of the sigmoid potential
760 theta is the cutoff distance for a protein-protein contact
762 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
764 self.min = sys.float_info.min
765 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
766 self.operations = [p1, operator, p2]
767 self.particle_pair =
None
768 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
769 self.operations = [p1, operator,
None]
770 self.particle_pair =
None
773 self.particle_pair = (p1, p2)
775 def __or__(self, FuzzyRestraint2):
778 def __and__(self, FuzzyRestraint2):
781 def __invert__(self):
784 def and_(self, a, b):
789 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
792 def invert_(self, a):
793 c = 1.0 - math.exp(-a)
797 if len(self.operations) == 0:
798 return self.distance()
799 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
801 if FuzzyRestraint2
is not None:
802 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
804 return op(FuzzyRestraint1.evaluate())
810 argvalue = (d-self.theta)/self.slope
811 return -math.log(1.0 -(1.0-self.plateau)/(1.0+math.exp(-argvalue)))+self.innerslope*d
813 def add_to_model(self):
816 def unprotected_evaluate(self, da):
817 return self.evaluate()
820 if len(self.operations) == 0:
821 return str(self.particle_pair)
822 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
823 if FuzzyRestraint2
is not None:
824 return str(FuzzyRestraint1) +str(op)+str(FuzzyRestraint2)
826 return str(FuzzyRestraint1) +str(op)
829 if len(self.operations) == 0:
830 return list(self.particle_pair)
831 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
832 if FuzzyRestraint2
is not None:
833 return list(set(FuzzyRestraint1.do_get_inputs() +FuzzyRestraint2.do_get_inputs()))
835 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: cr=restraints...
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 ...
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 is a selection tuple compositeparticles is a list of selection tuples ...
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.