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)
88 score = self.weight * self.rs.unprotected_evaluate(
None)
89 output[
"_TotalScore"] = str(score)
90 output[
"ConnectivityRestraint_" + self.label] = str(score)
99 handleparticles is a selection tuple
100 compositeparticles is a list of selection tuples
106 handleparticles_tuples,
107 compositeparticles_tuple_list,
116 self.m = representation.prot.get_model()
119 self.handleparticles = []
120 for s
in handleparticles_tuples:
121 self.handleparticles += IMP.pmi.tools.select_by_tuple(
123 resolution=resolution, name_is_ambiguous=
True)
124 self.compositeparticles = []
125 compositeparticle_list = []
126 for list
in compositeparticles_tuple_list:
129 tmplist += IMP.pmi.tools.select_by_tuple(
131 resolution=resolution, name_is_ambiguous=
True)
132 compositeparticle_list.append(tmplist)
133 self.compositeparticles += tmplist
137 self.handleparticles,
143 for ps
in compositeparticle_list:
145 ln.add_composite_particle(ps)
147 self.rs.add_restraint(ln)
149 def set_label(self, label):
152 def get_handle_particles(self):
153 return self.handleparticles
155 def get_composite_particles(self):
156 return self.compositeparticles
158 def get_restraint(self):
161 def add_to_model(self):
164 def get_output(self):
166 score = self.rs.unprotected_evaluate(
None)
167 output[
"_TotalScore"] = str(score)
168 output[
"CompositeRestraint_" + self.label] = str(score)
176 this restraint allows ambiguous crosslinking between multiple copies
177 excluding between symmetric copies
178 It allows name ambiguity
192 self.m = representation.prot.get_model()
197 self.outputlevel =
"low"
198 self.cut_off = cut_off
200 self.plateau = plateau
202 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
206 tokens = line.split()
208 if (tokens[0] ==
"#"):
217 resolution=resolution,
219 name_is_ambiguous=
True,
221 hrc1 = [representation.hier_db.particle_to_name[p]
for p
in ps1]
226 hrc1nosym = [representation.hier_db.particle_to_name[p]
231 "AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" %
237 resolution=resolution,
239 name_is_ambiguous=
True,
241 hrc2 = [representation.hier_db.particle_to_name[p]
for p
in ps2]
246 hrc2nosym = [representation.hier_db.particle_to_name[p]
251 "AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" %
262 cr.add_composite_particle(ps2)
264 self.rs.add_restraint(cr)
283 cr.add_composite_particle(ps2nosym)
285 self.rs.add_restraint(cr)
313 cr.add_composite_particle([p2])
316 for i
in range(npoints):
320 scores.append(cr.unprotected_evaluate(
None))
321 IMP.pmi.output.plot_xy_data(dists, scores)
323 def set_label(self, label):
325 self.rs.set_name(label)
326 for r
in self.rs.get_restraints():
329 def add_to_model(self):
332 def get_hierarchies(self):
335 def get_restraint_sets(self):
338 def get_restraint(self):
341 def set_output_level(self, level="low"):
343 self.outputlevel = level
345 def set_weight(self, weight):
347 self.rs.set_weight(weight)
349 def get_output(self):
353 score = self.weight * self.rs.unprotected_evaluate(
None)
354 output[
"_TotalScore"] = str(score)
355 output[
"AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
356 for n, p
in enumerate(self.pairs):
367 for n1, p1
in enumerate(ps1):
370 for n2, p2
in enumerate(ps2):
374 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
375 output[
"AmbiguousCompositeRestraint_Distance_" +
378 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
379 output[
"AmbiguousCompositeRestraint_Score_" +
380 label] = str(self.weight * cr.unprotected_evaluate(
None))
386 class SimplifiedPEMAP(object):
396 self.m = representation.prot.get_model()
401 self.outputlevel =
"low"
402 self.expdistance = expdistance
403 self.strength = strength
405 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
409 tokens = line.split()
411 if (tokens[0] ==
"#"):
417 pcc = float(tokens[4])
421 resolution=resolution,
423 name_is_ambiguous=
False,
427 "SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" %
432 "SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" %
438 resolution=resolution,
440 name_is_ambiguous=
False,
444 "SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" %
449 "SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" %
457 upperdist = self.get_upper_bond(pcc)
458 limit = self.strength * (upperdist + 15) ** 2 + 10.0
471 self.rs.add_restraint(dr)
472 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
475 lowerdist = self.get_lower_bond(pcc)
476 limit = self.strength * (lowerdist - 15) ** 2 + 10.0
489 self.rs.add_restraint(dr2)
490 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
492 def get_upper_bond(self, pearsoncc):
494 return (pearsoncc - .5) / (-0.005415)
496 def get_lower_bond(self, pearsoncc):
497 return (pearsoncc - 1.) / -0.0551
499 def set_label(self, label):
502 def add_to_model(self):
505 def get_hierarchies(self):
508 def get_restraint_sets(self):
511 def set_output_level(self, level="low"):
513 self.outputlevel = level
515 def get_output(self):
519 score = self.rs.unprotected_evaluate(
None)
520 output[
"_TotalScore"] = str(score)
521 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
522 for i
in range(len(self.pairs)):
524 p0 = self.pairs[i][0]
525 p1 = self.pairs[i][1]
526 crosslinker =
'standard'
527 ln = self.pairs[i][2]
528 resid1 = self.pairs[i][3]
529 chain1 = self.pairs[i][4]
530 resid2 = self.pairs[i][5]
531 chain2 = self.pairs[i][6]
533 label = str(resid1) +
":" + chain1 +
"_" + \
534 str(resid2) +
":" + chain2
535 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
536 label] = str(ln.unprotected_evaluate(
None))
540 output[
"SimplifiedPEMAP_Distance_" +
549 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
551 cr=restraints.ConnectivityNetworkRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
555 Multistate support =No
556 Selection type=selection tuple
571 if self.label ==
"None":
572 self.label = str(selection_tuples)
576 if representation
is None:
579 hiers.append(IMP.pmi.tools.input_adaptor(obj,
582 self.m=hiers[0][0].get_model()
584 self.m = representation.m
586 hiers.append(IMP.pmi.tools.select_by_tuple(representation, s,
587 resolution=resolution,
588 name_is_ambiguous=
False))
593 cr.add_particles([h.get_particle()
for h
in hs])
595 self.rs.add_restraint(cr)
597 def set_label(self, label):
599 self.rs.set_name(label)
600 for r
in self.rs.get_restraints():
603 def add_to_model(self):
606 def get_restraint(self):
609 def get_restraints(self):
611 for r
in self.rs.get_restraints():
612 rlist.append(IMP.core.PairRestraint.get_from(r))
615 def set_weight(self, weight):
617 self.rs.set_weight(weight)
619 def get_output(self):
621 score = self.weight * self.rs.unprotected_evaluate(
None)
622 output[
"_TotalScore"] = str(score)
623 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
630 a python restraint that computes the score for a composite of proteins
631 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
634 def __init__(self, m, slope=1.0, theta=0.0, plateau=0.0000000001, linear_slope=0.015):
636 input a list of particles, the slope and theta of the sigmoid potential
637 theta is the cutoff distance for a protein-protein contact
642 self.networkx = networkx
643 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
646 self.linear_slope = linear_slope
647 self.plateau = plateau
648 self.particles_blocks = []
649 self.particle_list = []
651 def get_number_of_particle_blocks(self):
652 return len(self.particles_blocks)
654 def get_number_of_particles_for_block(self, block_index):
655 return len(self.particles_blocks[block_index])
658 self.particles_blocks.append(particles)
659 self.particle_list += particles
663 get the full graph of distances between every particle pair
666 pdist_array = numpy.array(
668 pdist_mat = scipy.spatial.distance.squareform(pdist_array)
669 pdist_mat[pdist_mat < 0] = 0
670 graph = self.networkx.Graph(pdist_mat)
675 return the minimum spanning tree
678 graph = self.networkx.minimum_spanning_tree(graph)
683 a sigmoid function that scores the probability of a contact
688 argvalue = (x - self.theta) / self.slope
689 return 1.0 - (1.0 - self.plateau) / (1.0 + math.exp(-argvalue))
691 def unprotected_evaluate(self, da):
694 for e
in graph.edges():
695 dist = graph.get_edge_data(*e)[
'weight']
697 score += -numpy.log(prob)
698 score += self.linear_slope * dist
702 return self.particle_list
705 "use IMP.restraints.basic.MembraneRestraint instead")
712 def get_from_selection_tuple(self,tuples):
715 ps = IMP.pmi.tools.select_by_tuple(
716 self.representation, s,
717 resolution=self.resolution, name_is_ambiguous=
True)
733 self.resolution=resolution
737 self.representation = representation
738 self.thickness = thickness
747 hierarchies_above = []
748 hierarchies_inside = []
749 hierarchies_below = []
751 if representation
is None:
752 hierarchies_above, hierarchies_inside, hierarchies_below = (
753 IMP.pmi.tools.input_adaptor(objects,
755 flatten=
True)
for objects
in [objects_above, objects_inside, objects_below])
756 for h
in hierarchies_above, hierarchies_inside, hierarchies_below:
758 self.m=hierarchies_above[0].get_model()
761 self.m = representation.prot.get_model()
762 if objects_above
is not None:
763 hierarchies_above = self.get_from_selection_tuple(objects_above)
765 if objects_below
is not None:
766 particles_below = self.get_from_selection_tuple(objects_below)
768 if objects_inside
is not None:
769 particles_inside = self.get_from_selection_tuple(objects_inside)
771 self.z_center = IMP.pmi.tools.SetupNuisance(
772 self.m, self.z_init, z_min, z_max, isoptimized=
True).get_particle()
774 self.m, self.z_center.get_particle_index(), self.thickness, softness, plateau, linear)
775 mr.add_particles_inside([h.get_particle().
get_index()
776 for h
in hierarchies_inside])
777 mr.add_particles_above([h.get_particle().
get_index()
778 for h
in hierarchies_above])
779 mr.add_particles_below([h.get_particle().
get_index()
780 for h
in hierarchies_below])
783 self.rs.add_restraint(mr)
785 def create_box(self, x_center, y_center, hierarchy):
787 z = self.z_center.get_nuisance()
790 h.set_name(
"Membrane_" + self.label)
791 hierarchy.add_child(h)
798 d.set_coordinates((x_center, y_center, 0))
801 h.add_child(h_origin)
802 particles_box.append(p_origin)
807 d.set_coordinates((x_center, y_center, z + 100))
811 particles_box.append(p1)
816 d.set_coordinates((x_center, y_center, z - 100))
820 particles_box.append(p2)
827 p1.set_name(
"z_positive")
828 p2.set_name(
"z_negative")
831 for offs
in [self.thickness / 2, -self.thickness / 2]:
835 d.set_coordinates((-100 + x_center, -100 + y_center, z + offs))
839 particles_box.append(p1)
844 d.set_coordinates((-100 + x_center, 100 + y_center, z + offs))
848 particles_box.append(p2)
853 d.set_coordinates((100 + x_center, -100 + y_center, z + offs))
857 particles_box.append(p3)
862 d.set_coordinates((100 + x_center, 100 + y_center, z + offs))
866 particles_box.append(p4)
880 for p
in particles_box:
881 smp = self._MembraneSingletonModifier(
IMP.core.XYZ(p).get_z(),self.z_init, self.z_center)
884 lcp.add(p.get_index())
886 self.m.add_score_state(c)
891 """A class that updates the membrane particles
894 def __init__(self,z, z_init, z_nuisance):
895 IMP.SingletonModifier.__init__(
896 self,
"MembraneSingletonModifier%1%")
899 self.z_nuisance = z_nuisance
901 def apply_index(self, m, pi):
902 new_z = self.z_nuisance.get_nuisance()
904 d.set_z(self.z + new_z-self.z_init)
908 def do_get_inputs(self, m, pis):
911 def do_get_outputs(self, m, pis):
912 return self.do_get_inputs(m, pis)
914 def set_label(self, label):
916 self.rs.set_name(label)
917 for r
in self.rs.get_restraints():
920 def add_to_model(self):
923 def get_restraint(self):
926 def set_weight(self, weight):
928 self.rs.set_weight(weight)
930 def get_particles_to_sample(self):
933 ps[
"Nuisances_MembraneRestraint_Z_" +
934 self.label] = ([self.z_center], 2.0)
937 def get_movers(self):
939 mover_name=
"Nuisances_MembraneRestraint_Z_" + self.label
940 particle=self.z_center
944 mv.set_name(mover_name)
950 def get_output(self):
952 score = self.weight * self.rs.unprotected_evaluate(
None)
953 output[
"_TotalScore"] = str(score)
954 output[
"MembraneRestraint_" + self.label] = str(score)
955 output[
"MembraneRestraint_Z_" +
956 self.label] = str(self.z_center.get_nuisance())
963 Fully Ambiguous Restraint that can be built using boolean logic
964 R. Pellarin. Pasteur Institute.
969 input a list of particles, the slope and theta of the sigmoid potential
970 theta is the cutoff distance for a protein-protein contact
972 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
973 self.operations = [p1, operator, p2]
979 def __or__(self, FuzzyBoolean2):
982 def __and__(self, FuzzyBoolean2):
985 def and_(self, a, b):
989 return 1.0 - (1.0 - a) * (1.0 - b)
993 if len(self.operations) == 0:
995 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
997 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
1003 Fully Ambiguous Restraint that can be built using boolean logic
1004 R. Pellarin. Pasteur Institute.
1006 plateau = 0.00000000000001
1013 input a list of particles, the slope and theta of the sigmoid potential
1014 theta is the cutoff distance for a protein-protein contact
1016 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
1018 self.min = sys.float_info.min
1019 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
1020 self.operations = [p1, operator, p2]
1021 self.particle_pair =
None
1022 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
1023 self.operations = [p1, operator,
None]
1024 self.particle_pair =
None
1026 self.operations = []
1027 self.particle_pair = (p1, p2)
1029 def __or__(self, FuzzyRestraint2):
1032 def __and__(self, FuzzyRestraint2):
1035 def __invert__(self):
1038 def and_(self, a, b):
1042 def or_(self, a, b):
1043 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
1046 def invert_(self, a):
1047 c = 1.0 - math.exp(-a)
1051 if len(self.operations) == 0:
1052 return self.distance()
1053 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1055 if FuzzyRestraint2
is not None:
1056 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
1058 return op(FuzzyRestraint1.evaluate())
1064 argvalue = (d-self.theta)/self.slope
1065 return -math.log(1.0 -(1.0-self.plateau)/(1.0+math.exp(-argvalue)))+self.innerslope*d
1067 def add_to_model(self):
1070 def unprotected_evaluate(self, da):
1071 return self.evaluate()
1074 if len(self.operations) == 0:
1075 return str(self.particle_pair)
1076 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1077 if FuzzyRestraint2
is not None:
1078 return str(FuzzyRestraint1) +str(op)+str(FuzzyRestraint2)
1080 return str(FuzzyRestraint1) +str(op)
1083 if len(self.operations) == 0:
1084 return list(self.particle_pair)
1085 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1086 if FuzzyRestraint2
is not None:
1087 return list(set(FuzzyRestraint1.do_get_inputs() +FuzzyRestraint2.do_get_inputs()))
1089 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.
def deprecated_pmi1_object
Mark a PMI1 class as deprecated.
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.