1 """@namespace IMP.pmi1.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.pmi1.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.pmi1.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.pmi1.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.pmi1.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.pmi1.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.pmi1.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.pmi1.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:
582 self.m=hiers[0][0].get_model()
584 self.m = representation.m
586 hiers.append(IMP.pmi1.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))
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
711 def get_from_selection_tuple(self,tuples):
714 ps = IMP.pmi1.tools.select_by_tuple(
715 self.representation, s,
716 resolution=self.resolution, name_is_ambiguous=
True)
732 self.resolution=resolution
736 self.representation = representation
737 self.thickness = thickness
746 hierarchies_above = []
747 hierarchies_inside = []
748 hierarchies_below = []
750 if representation
is None:
751 hierarchies_above, hierarchies_inside, hierarchies_below = (
754 flatten=
True)
for objects
in [objects_above, objects_inside, objects_below])
755 for h
in hierarchies_above, hierarchies_inside, hierarchies_below:
757 self.m=hierarchies_above[0].get_model()
760 self.m = representation.prot.get_model()
761 if objects_above
is not None:
762 hierarchies_above = self.get_from_selection_tuple(objects_above)
764 if objects_below
is not None:
765 particles_below = self.get_from_selection_tuple(objects_below)
767 if objects_inside
is not None:
768 particles_inside = self.get_from_selection_tuple(objects_inside)
770 self.z_center = IMP.pmi1.tools.SetupNuisance(
771 self.m, self.z_init, z_min, z_max, isoptimized=
True).get_particle()
773 self.m, self.z_center.get_particle_index(), self.thickness, softness, plateau, linear)
774 mr.add_particles_inside([h.get_particle().
get_index()
775 for h
in hierarchies_inside])
776 mr.add_particles_above([h.get_particle().
get_index()
777 for h
in hierarchies_above])
778 mr.add_particles_below([h.get_particle().
get_index()
779 for h
in hierarchies_below])
782 self.rs.add_restraint(mr)
784 def create_box(self, x_center, y_center, hierarchy):
786 z = self.z_center.get_nuisance()
789 h.set_name(
"Membrane_" + self.label)
790 hierarchy.add_child(h)
797 d.set_coordinates((x_center, y_center, 0))
800 h.add_child(h_origin)
801 particles_box.append(p_origin)
806 d.set_coordinates((x_center, y_center, z + 100))
810 particles_box.append(p1)
815 d.set_coordinates((x_center, y_center, z - 100))
819 particles_box.append(p2)
826 p1.set_name(
"z_positive")
827 p2.set_name(
"z_negative")
830 for offs
in [self.thickness / 2, -self.thickness / 2]:
834 d.set_coordinates((-100 + x_center, -100 + y_center, z + offs))
838 particles_box.append(p1)
843 d.set_coordinates((-100 + x_center, 100 + y_center, z + offs))
847 particles_box.append(p2)
852 d.set_coordinates((100 + x_center, -100 + y_center, z + offs))
856 particles_box.append(p3)
861 d.set_coordinates((100 + x_center, 100 + y_center, z + offs))
865 particles_box.append(p4)
879 for p
in particles_box:
880 smp = self._MembraneSingletonModifier(
IMP.core.XYZ(p).get_z(),self.z_init, self.z_center)
883 lcp.add(p.get_index())
885 self.m.add_score_state(c)
890 """A class that updates the membrane particles
893 def __init__(self,z, z_init, z_nuisance):
894 IMP.SingletonModifier.__init__(
895 self,
"MembraneSingletonModifier%1%")
898 self.z_nuisance = z_nuisance
900 def apply_index(self, m, pi):
901 new_z = self.z_nuisance.get_nuisance()
903 d.set_z(self.z + new_z-self.z_init)
907 def do_get_inputs(self, m, pis):
910 def do_get_outputs(self, m, pis):
911 return self.do_get_inputs(m, pis)
913 def set_label(self, label):
915 self.rs.set_name(label)
916 for r
in self.rs.get_restraints():
919 def add_to_model(self):
922 def get_restraint(self):
925 def set_weight(self, weight):
927 self.rs.set_weight(weight)
929 def get_particles_to_sample(self):
932 ps[
"Nuisances_MembraneRestraint_Z_" +
933 self.label] = ([self.z_center], 2.0)
936 def get_movers(self):
938 mover_name=
"Nuisances_MembraneRestraint_Z_" + self.label
939 particle=self.z_center
943 mv.set_name(mover_name)
949 def get_output(self):
951 score = self.weight * self.rs.unprotected_evaluate(
None)
952 output[
"_TotalScore"] = str(score)
953 output[
"MembraneRestraint_" + self.label] = str(score)
954 output[
"MembraneRestraint_Z_" +
955 self.label] = str(self.z_center.get_nuisance())
962 Fully Ambiguous Restraint that can be built using boolean logic
963 R. Pellarin. Pasteur Institute.
968 input a list of particles, the slope and theta of the sigmoid potential
969 theta is the cutoff distance for a protein-protein contact
971 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
972 self.operations = [p1, operator, p2]
978 def __or__(self, FuzzyBoolean2):
981 def __and__(self, FuzzyBoolean2):
984 def and_(self, a, b):
988 return 1.0 - (1.0 - a) * (1.0 - b)
992 if len(self.operations) == 0:
994 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
996 return op(FuzzyBoolean1.evaluate(), FuzzyBoolean2.evaluate())
1002 Fully Ambiguous Restraint that can be built using boolean logic
1003 R. Pellarin. Pasteur Institute.
1005 plateau = 0.00000000000001
1012 input a list of particles, the slope and theta of the sigmoid potential
1013 theta is the cutoff distance for a protein-protein contact
1015 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
1017 self.min = sys.float_info.min
1018 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
1019 self.operations = [p1, operator, p2]
1020 self.particle_pair =
None
1021 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
1022 self.operations = [p1, operator,
None]
1023 self.particle_pair =
None
1025 self.operations = []
1026 self.particle_pair = (p1, p2)
1028 def __or__(self, FuzzyRestraint2):
1031 def __and__(self, FuzzyRestraint2):
1034 def __invert__(self):
1037 def and_(self, a, b):
1041 def or_(self, a, b):
1042 c = math.exp(-a) + math.exp(-b) - math.exp(-a - b)
1045 def invert_(self, a):
1046 c = 1.0 - math.exp(-a)
1050 if len(self.operations) == 0:
1051 return self.distance()
1052 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1054 if FuzzyRestraint2
is not None:
1055 return op(FuzzyRestraint1.evaluate(), FuzzyRestraint2.evaluate())
1057 return op(FuzzyRestraint1.evaluate())
1063 argvalue = (d-self.theta)/self.slope
1064 return -math.log(1.0 -(1.0-self.plateau)/(1.0+math.exp(-argvalue)))+self.innerslope*d
1066 def add_to_model(self):
1073 if len(self.operations) == 0:
1074 return str(self.particle_pair)
1075 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1076 if FuzzyRestraint2
is not None:
1077 return str(FuzzyRestraint1) +str(op)+str(FuzzyRestraint2)
1079 return str(FuzzyRestraint1) +str(op)
1082 if len(self.operations) == 0:
1083 return list(self.particle_pair)
1084 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1085 if FuzzyRestraint2
is not None:
1086 return list(set(FuzzyRestraint1.do_get_inputs() +FuzzyRestraint2.do_get_inputs()))
1088 return list(set(FuzzyRestraint1.do_get_inputs()))
A base class for modifiers of ParticlesTemp.
Fully Ambiguous Restraint that can be built using boolean logic R.
A function that is harmonic over an bounded interval.
generates and wraps a IMP.pmi1.ConnectivityRestraint between domains example: cr=restraints.ConnectivityNetworkRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")]) cr.add_to_model() cr.set_label("CR1")
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
Apply a SingletonFunction to a SingletonContainer to maintain an invariant.
Floats get_list_of_bipartite_minimum_sphere_distance(const ParticlesTemps &pss)
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.
Legacy PMI1 module to represent, score, sample and analyze models.
virtual double unprotected_evaluate(DerivativeAccumulator *da) const
Return the unweighted score for the restraint.
def get_full_graph
get the full graph of distances between every particle pair
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
A score on the distance between the surfaces of two spheres.
def sigmoid
a sigmoid function that scores the probability of a contact between two proteins
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
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)
Store a list of ParticleIndexes.
generate a connectivity restraint between domains setting up the restraint example: cr=restraints...
static Mass setup_particle(Model *m, ParticleIndex pi, Float mass)
Fully Ambiguous Restraint that can be built using boolean logic R.
static Bonded setup_particle(Model *m, ParticleIndex pi)
handleparticles is a selection tuple compositeparticles is a list of selection tuples ...
A decorator for a particle with x,y,z coordinates.
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
A restraint for ambiguous cross-linking MS data and multiple state approach.
Modify a set of continuous variables using a normal distribution.
this restraint allows ambiguous crosslinking between multiple copies excluding between symmetric copi...
def get_minimum_spanning_tree
return the minimum spanning tree
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...
Class to handle individual particles of a Model object.
Add symmetric attribute to a particle.
def __init__
input a list of particles, the slope and theta of the sigmoid potential theta is the cutoff distance ...
Restraint * create_connectivity_restraint(const Selections &s, double x0, double k, std::string name="Connectivity%1%")
Create a restraint connecting the selections.
double evaluate(bool calc_derivs) const
Applies a PairScore to a Pair.
Classes for writing output files and processing them.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
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.