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 cr=restraints.ConnectivityRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
29 Multistate support =No
30 Selection type=selection tuple
45 if self.label ==
"None":
46 self.label = str(selection_tuples)
47 self.m = representation.prot.get_model()
52 for s
in selection_tuples:
53 particles = IMP.pmi.tools.select_by_tuple(representation, s,
54 resolution=resolution, name_is_ambiguous=
True)
62 self.rs.add_restraint(cr)
64 def set_label(self, label):
66 self.rs.set_name(label)
67 for r
in self.rs.get_restraints():
70 def add_to_model(self):
73 def get_restraint(self):
76 def get_restraints(self):
78 for r
in self.rs.get_restraints():
79 rlist.append(IMP.core.PairRestraint.get_from(r))
82 def set_weight(self, weight):
84 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):
168 score = self.rs.unprotected_evaluate(
None)
169 output[
"_TotalScore"] = str(score)
170 output[
"CompositeRestraint_" + self.label] = str(score)
178 this restraint allows ambiguous crosslinking between multiple copies
179 excluding between symmetric copies
180 It allows name ambiguity
194 self.m = representation.prot.get_model()
199 self.outputlevel =
"low"
200 self.cut_off = cut_off
202 self.plateau = plateau
204 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
208 tokens = line.split()
210 if (tokens[0] ==
"#"):
219 resolution=resolution,
221 name_is_ambiguous=
True,
223 hrc1 = [representation.hier_db.particle_to_name[p]
for p
in ps1]
228 hrc1nosym = [representation.hier_db.particle_to_name[p]
233 "AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" %
239 resolution=resolution,
241 name_is_ambiguous=
True,
243 hrc2 = [representation.hier_db.particle_to_name[p]
for p
in ps2]
248 hrc2nosym = [representation.hier_db.particle_to_name[p]
253 "AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" %
264 cr.add_composite_particle(ps2)
266 self.rs.add_restraint(cr)
285 cr.add_composite_particle(ps2nosym)
287 self.rs.add_restraint(cr)
315 cr.add_composite_particle([p2])
318 for i
in range(npoints):
322 scores.append(cr.unprotected_evaluate(
None))
323 IMP.pmi.output.plot_xy_data(dists, scores)
325 def set_label(self, label):
327 self.rs.set_name(label)
328 for r
in self.rs.get_restraints():
331 def add_to_model(self):
334 def get_hierarchies(self):
337 def get_restraint_sets(self):
340 def get_restraint(self):
343 def set_output_level(self, level="low"):
345 self.outputlevel = level
347 def set_weight(self, weight):
349 self.rs.set_weight(weight)
351 def get_output(self):
357 score = self.weight * self.rs.unprotected_evaluate(
None)
358 output[
"_TotalScore"] = str(score)
359 output[
"AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
360 for n, p
in enumerate(self.pairs):
371 for n1, p1
in enumerate(ps1):
374 for n2, p2
in enumerate(ps2):
378 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
379 output[
"AmbiguousCompositeRestraint_Distance_" +
382 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
383 output[
"AmbiguousCompositeRestraint_Score_" +
384 label] = str(self.weight * cr.unprotected_evaluate(
None))
390 class SimplifiedPEMAP(object):
400 self.m = representation.prot.get_model()
405 self.outputlevel =
"low"
406 self.expdistance = expdistance
407 self.strength = strength
409 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
413 tokens = line.split()
415 if (tokens[0] ==
"#"):
421 pcc = float(tokens[4])
425 resolution=resolution,
427 name_is_ambiguous=
False,
431 "SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" %
436 "SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" %
442 resolution=resolution,
444 name_is_ambiguous=
False,
448 "SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" %
453 "SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" %
461 upperdist = self.get_upper_bond(pcc)
462 limit = self.strength * (upperdist + 15) ** 2 + 10.0
475 self.rs.add_restraint(dr)
476 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
479 lowerdist = self.get_lower_bond(pcc)
480 limit = self.strength * (lowerdist - 15) ** 2 + 10.0
493 self.rs.add_restraint(dr2)
494 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
496 def get_upper_bond(self, pearsoncc):
498 return (pearsoncc - .5) / (-0.005415)
500 def get_lower_bond(self, pearsoncc):
501 return (pearsoncc - 1.) / -0.0551
503 def set_label(self, label):
506 def add_to_model(self):
509 def get_hierarchies(self):
512 def get_restraint_sets(self):
515 def set_output_level(self, level="low"):
517 self.outputlevel = level
519 def get_output(self):
525 score = self.rs.unprotected_evaluate(
None)
526 output[
"_TotalScore"] = str(score)
527 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
528 for i
in range(len(self.pairs)):
530 p0 = self.pairs[i][0]
531 p1 = self.pairs[i][1]
532 crosslinker =
'standard'
533 ln = self.pairs[i][2]
534 resid1 = self.pairs[i][3]
535 chain1 = self.pairs[i][4]
536 resid2 = self.pairs[i][5]
537 chain2 = self.pairs[i][6]
539 label = str(resid1) +
":" + chain1 +
"_" + \
540 str(resid2) +
":" + chain2
541 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
542 label] = str(ln.unprotected_evaluate(
None))
546 output[
"SimplifiedPEMAP_Distance_" +
555 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
557 cr=restraints.ConnectivityNetworkRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
561 Multistate support =No
562 Selection type=selection tuple
577 if self.label ==
"None":
578 self.label = str(selection_tuples)
582 if representation
is None:
588 self.m=hiers[0][0].get_model()
590 self.m = representation.m
592 hiers.append(IMP.pmi.tools.select_by_tuple(representation, s,
593 resolution=resolution,
594 name_is_ambiguous=
False))
599 cr.add_particles([h.get_particle()
for h
in hs])
601 self.rs.add_restraint(cr)
603 def set_label(self, label):
605 self.rs.set_name(label)
606 for r
in self.rs.get_restraints():
609 def add_to_model(self):
612 def get_restraint(self):
615 def get_restraints(self):
617 for r
in self.rs.get_restraints():
618 rlist.append(IMP.core.PairRestraint.get_from(r))
621 def set_weight(self, weight):
623 self.rs.set_weight(weight)
625 def get_output(self):
628 score = self.weight * self.rs.unprotected_evaluate(
None)
629 output[
"_TotalScore"] = str(score)
630 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
637 a python restraint that computes the score for a composite of proteins
638 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
641 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001, linear_slope=0.015):
643 input a list of particles, the slope and theta of the sigmoid potential
644 theta is the cutoff distance for a protein-protein contact
649 self.networkx = networkx
650 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
653 self.linear_slope = linear_slope
654 self.plateau = plateau
655 self.particles_blocks = []
656 self.particle_list = []
658 def get_number_of_particle_blocks(self):
659 return len(self.particles_blocks)
661 def get_number_of_particles_for_block(self, block_index):
662 return len(self.particles_blocks[block_index])
665 self.particles_blocks.append(particles)
666 self.particle_list += particles
670 get the full graph of distances between every particle pair
673 pdist_array = numpy.array(
675 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
676 pdist_mat[pdist_mat < 0] = 0
677 graph = self.networkx.Graph(pdist_mat)
682 return the minimum spanning tree
685 graph = self.networkx.minimum_spanning_tree(graph)
690 a sigmoid function that scores the probability of a contact
695 argvalue = (x - self.theta) / self.slope
696 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
698 def unprotected_evaluate(self, da):
701 for e
in graph.edges():
702 dist = graph.get_edge_data(*e)[
'weight']
704 score += -numpy.log(prob)
705 score += self.linear_slope * dist
709 return self.particle_list
718 def get_from_selection_tuple(self,tuples):
721 ps = IMP.pmi.tools.select_by_tuple(
722 self.representation, s,
723 resolution=self.resolution, name_is_ambiguous=
True)
739 self.resolution=resolution
743 self.representation = representation
744 self.thickness = thickness
753 hierarchies_above = []
754 hierarchies_inside = []
755 hierarchies_below = []
757 if representation
is None:
758 hierarchies_above, hierarchies_inside, hierarchies_below = (
761 flatten=
True)
for objects
in [objects_above, objects_inside, objects_below])
762 for h
in hierarchies_above, hierarchies_inside, hierarchies_below:
764 self.m=hierarchies_above[0].get_model()
767 self.m = representation.prot.get_model()
768 if objects_above
is not None:
769 hierarchies_above = self.get_from_selection_tuple(objects_above)
771 if objects_below
is not None:
772 particles_below = self.get_from_selection_tuple(objects_below)
774 if objects_inside
is not None:
775 particles_inside = self.get_from_selection_tuple(objects_inside)
777 self.z_center = IMP.pmi.tools.SetupNuisance(
778 self.m, self.z_init, z_min, z_max, isoptimized=
True).get_particle()
780 self.m, self.z_center.get_particle_index(), self.thickness, softness, plateau, linear)
781 mr.add_particles_inside([h.get_particle().
get_index()
782 for h
in hierarchies_inside])
783 mr.add_particles_above([h.get_particle().
get_index()
784 for h
in hierarchies_above])
785 mr.add_particles_below([h.get_particle().
get_index()
786 for h
in hierarchies_below])
789 self.rs.add_restraint(mr)
791 def create_box(self, x_center, y_center, hierarchy):
793 z = self.z_center.get_nuisance()
796 h.set_name(
"Membrane_" + self.label)
797 hierarchy.add_child(h)
804 d.set_coordinates((x_center, y_center, 0))
807 h.add_child(h_origin)
808 particles_box.append(p_origin)
813 d.set_coordinates((x_center, y_center, z + 100))
817 particles_box.append(p1)
822 d.set_coordinates((x_center, y_center, z - 100))
826 particles_box.append(p2)
833 p1.set_name(
"z_positive")
834 p2.set_name(
"z_negative")
837 for offs
in [self.thickness / 2, -self.thickness / 2]:
841 d.set_coordinates((-100 + x_center, -100 + y_center, z + offs))
845 particles_box.append(p1)
850 d.set_coordinates((-100 + x_center, 100 + y_center, z + offs))
854 particles_box.append(p2)
859 d.set_coordinates((100 + x_center, -100 + y_center, z + offs))
863 particles_box.append(p3)
868 d.set_coordinates((100 + x_center, 100 + y_center, z + offs))
872 particles_box.append(p4)
886 for p
in particles_box:
887 smp = self._MembraneSingletonModifier(
IMP.core.XYZ(p).get_z(),self.z_init, self.z_center)
890 lcp.add(p.get_index())
892 self.m.add_score_state(c)
897 """A class that updates the membrane particles
900 def __init__(self,z, z_init, z_nuisance):
901 IMP.SingletonModifier.__init__(
902 self,
"MembraneSingletonModifier%1%")
905 self.z_nuisance = z_nuisance
907 def apply_index(self, m, pi):
908 new_z = self.z_nuisance.get_nuisance()
910 d.set_z(self.z + new_z-self.z_init)
914 def do_get_inputs(self, m, pis):
917 def do_get_outputs(self, m, pis):
918 return self.do_get_inputs(m, pis)
920 def set_label(self, label):
922 self.rs.set_name(label)
923 for r
in self.rs.get_restraints():
926 def add_to_model(self):
929 def get_restraint(self):
932 def set_weight(self, weight):
934 self.rs.set_weight(weight)
936 def get_particles_to_sample(self):
939 ps[
"Nuisances_MembraneRestraint_Z_" +
940 self.label] = ([self.z_center], 2.0)
943 def get_movers(self):
945 mover_name=
"Nuisances_MembraneRestraint_Z_" + self.label
946 particle=self.z_center
950 mv.set_name(mover_name)
956 def get_output(self):
959 score = self.weight * self.rs.unprotected_evaluate(
None)
960 output[
"_TotalScore"] = str(score)
961 output[
"MembraneRestraint_" + self.label] = str(score)
962 output[
"MembraneRestraint_Z_" +
963 self.label] = str(self.z_center.get_nuisance())
970 Fully Ambiguous Restraint that can be built using boolean logic
971 R. Pellarin. Pasteur Institute.
976 input a list of particles, the slope and theta of the sigmoid potential
977 theta is the cutoff distance for a protein-protein contact
979 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
980 self.operations = [p1, operator, p2]
986 def __or__(self, FuzzyBoolean2):
989 def __and__(self, FuzzyBoolean2):
992 def and_(self, a, b):
996 return 1.0 - (1.0 - a) * (1.0 - b)
1000 if len(self.operations) == 0:
1002 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
1004 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
1010 Fully Ambiguous Restraint that can be built using boolean logic
1011 R. Pellarin. Pasteur Institute.
1013 plateau = 0.00000000000001
1020 input a list of particles, the slope and theta of the sigmoid potential
1021 theta is the cutoff distance for a protein-protein contact
1023 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
1025 self.min = sys.float_info.min
1026 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
1027 self.operations = [p1, operator, p2]
1028 self.particle_pair =
None
1029 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
1030 self.operations = [p1, operator,
None]
1031 self.particle_pair =
None
1033 self.operations = []
1034 self.particle_pair = (p1, p2)
1036 def __or__(self, FuzzyRestraint2):
1039 def __and__(self, FuzzyRestraint2):
1042 def __invert__(self):
1045 def and_(self, a, b):
1049 def or_(self, a, b):
1050 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
1053 def invert_(self, a):
1054 c = 1.0 - math.exp(-a)
1058 if len(self.operations) == 0:
1059 return self.distance()
1060 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1062 if FuzzyRestraint2
is not None:
1063 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
1065 return op(FuzzyRestraint1.evaluate())
1071 argvalue = (d-self.theta)/self.slope
1072 return -math.log(1.0 -(1.0-self.plateau)/(1.0+math.exp(-argvalue)))+self.innerslope*d
1074 def add_to_model(self):
1077 def unprotected_evaluate(self, da):
1078 return self.evaluate()
1081 if len(self.operations) == 0:
1082 return str(self.particle_pair)
1083 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1084 if FuzzyRestraint2
is not None:
1085 return str(FuzzyRestraint1) +str(op)+str(FuzzyRestraint2)
1087 return str(FuzzyRestraint1) +str(op)
1090 if len(self.operations) == 0:
1091 return list(self.particle_pair)
1092 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1093 if FuzzyRestraint2
is not None:
1094 return list(set(FuzzyRestraint1.do_get_inputs() +FuzzyRestraint2.do_get_inputs()))
1096 return list(set(FuzzyRestraint1.do_get_inputs()))
A base class for modifiers of ParticlesTemp.
A function that is harmonic over an interval.
Apply a SingletonFunction to a SingletonContainer to maintain an invariant.
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)
A decorator for a particle which has bonds.
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.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
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")
Bond create_bond(Bonded a, Bonded b, Bond o)
Connect the two wrapped particles by a custom bond.
Object used to hold a set of restraints.
a python restraint that computes the score for a composite of proteins Authors: G.
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
Store a list of ParticleIndexes.
static Mass setup_particle(Model *m, ParticleIndex pi, Float mass)
static Bonded setup_particle(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 is a selection tuple compositeparticles is a list of selection tuples ...
Modify a set of continuous variables using a normal distribution.
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.