1 """@namespace IMP.pmi.restraints.proteomics
2 Restraints for handling various kinds of proteomics data.
5 from __future__
import print_function
13 class ConnectivityRestraint(object):
16 generate a connectivity restraint between domains
17 setting up the restraint
19 cr=restraints.ConnectivityRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
22 Multistate support =No
23 Selection type=selection tuple
38 if self.label ==
"None":
39 self.label = str(selection_tuples)
40 self.m = representation.prot.get_model()
45 for s
in selection_tuples:
46 particles = IMP.pmi.tools.select_by_tuple(representation, s,
47 resolution=resolution, name_is_ambiguous=
True)
55 self.rs.add_restraint(cr)
57 def set_label(self, label):
59 self.rs.set_name(label)
60 for r
in self.rs.get_restraints():
63 def add_to_model(self):
66 def get_restraint(self):
69 def get_restraints(self):
71 for r
in self.rs.get_restraints():
72 rlist.append(IMP.core.PairRestraint.get_from(r))
75 def set_weight(self, weight):
77 self.rs.set_weight(weight)
82 score = self.weight * self.rs.unprotected_evaluate(
None)
83 output[
"_TotalScore"] = str(score)
84 output[
"ConnectivityRestraint_" + self.label] = str(score)
91 handleparticles is a selection tuple
92 compositeparticles is a list of selection tuples
99 handleparticles_tuples,
100 compositeparticles_tuple_list,
109 self.m = representation.prot.get_model()
112 self.handleparticles = []
113 for s
in handleparticles_tuples:
114 self.handleparticles += IMP.pmi.tools.select_by_tuple(representation, s,
115 resolution=resolution, name_is_ambiguous=
True)
116 self.compositeparticles=[]
117 compositeparticle_list = []
118 for list
in compositeparticles_tuple_list:
121 tmplist += IMP.pmi.tools.select_by_tuple(
123 resolution=resolution, name_is_ambiguous=
True)
124 compositeparticle_list.append(tmplist)
125 self.compositeparticles+=tmplist
130 self.handleparticles,
136 for ps
in compositeparticle_list:
138 ln.add_composite_particle(ps)
140 self.rs.add_restraint(ln)
142 def set_label(self, label):
145 def get_handle_particles(self):
146 return self.handleparticles
148 def get_composite_particles(self):
149 return self.compositeparticles
151 def get_restraint(self):
154 def add_to_model(self):
157 def get_output(self):
160 score = self.rs.unprotected_evaluate(
None)
161 output[
"_TotalScore"] = str(score)
162 output[
"CompositeRestraint_" + self.label] = str(score)
170 this restraint allows ambiguous crosslinking between multiple copies
171 excluding between symmetric copies
172 It allows name ambiguity
186 self.m = representation.prot.get_model()
191 self.outputlevel =
"low"
192 self.cut_off = cut_off
194 self.plateau = plateau
196 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
200 tokens = line.split()
202 if (tokens[0] ==
"#"):
211 resolution=resolution,
213 name_is_ambiguous=
True,
215 hrc1 = [representation.hier_db.particle_to_name[p]
for p
in ps1]
220 hrc1nosym = [representation.hier_db.particle_to_name[p]
224 print(
"AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" % (r1, c1))
229 resolution=resolution,
231 name_is_ambiguous=
True,
233 hrc2 = [representation.hier_db.particle_to_name[p]
for p
in ps2]
238 hrc2nosym = [representation.hier_db.particle_to_name[p]
242 print(
"AmbiguousCompositeRestraint: WARNING> residue %d of chain %s is not there" % (r2, c2))
252 cr.add_composite_particle(ps2)
254 self.rs.add_restraint(cr)
273 cr.add_composite_particle(ps2nosym)
275 self.rs.add_restraint(cr)
304 cr.add_composite_particle([p2])
307 for i
in range(npoints):
311 scores.append(cr.unprotected_evaluate(
None))
312 output.plot_xy_data(dists, scores)
314 def set_label(self, label):
316 self.rs.set_name(label)
317 for r
in self.rs.get_restraints():
320 def add_to_model(self):
323 def get_hierarchies(self):
326 def get_restraint_sets(self):
329 def get_restraint(self):
332 def set_output_level(self, level="low"):
334 self.outputlevel = level
336 def set_weight(self, weight):
338 self.rs.set_weight(weight)
340 def get_output(self):
346 score = self.weight * self.rs.unprotected_evaluate(
None)
347 output[
"_TotalScore"] = str(score)
348 output[
"AmbiguousCompositeRestraint_Score_" + self.label] = str(score)
349 for n, p
in enumerate(self.pairs):
360 for n1, p1
in enumerate(ps1):
363 for n2, p2
in enumerate(ps2):
367 label = str(r1) +
":" + name1 +
"_" + str(r2) +
":" + name2
368 output[
"AmbiguousCompositeRestraint_Distance_" +
371 label = str(r1) +
":" + c1 +
"_" + str(r2) +
":" + c2
372 output[
"AmbiguousCompositeRestraint_Score_" +
373 label] = str(self.weight * cr.unprotected_evaluate(
None))
379 class SimplifiedPEMAP(object):
389 self.m = representation.prot.get_model()
394 self.outputlevel =
"low"
395 self.expdistance = expdistance
396 self.strength = strength
398 fl = IMP.pmi.tools.open_file_or_inline_text(restraints_file)
402 tokens = line.split()
404 if (tokens[0] ==
"#"):
410 pcc = float(tokens[4])
414 resolution=resolution,
416 name_is_ambiguous=
False,
419 print(
"SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" % (r1, c1, r2, c2))
422 print(
"SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" % (r1, c1))
427 resolution=resolution,
429 name_is_ambiguous=
False,
432 print(
"SimplifiedPEMAP: WARNING> residue %d of chain %s is not there (w/ %d %s)" % (r1, c1, r2, c2))
435 print(
"SimplifiedPEMAP: WARNING> residue %d of chain %s selected multiple particles" % (r2, c2))
442 upperdist = self.get_upper_bond(pcc)
443 limit = self.strength * (upperdist + 15) ** 2 + 10.0
456 self.rs.add_restraint(dr)
457 self.pairs.append((p1, p2, dr, r1, c1, r2, c2))
460 lowerdist = self.get_lower_bond(pcc)
461 limit = self.strength * (lowerdist - 15) ** 2 + 10.0
474 self.rs.add_restraint(dr2)
475 self.pairs.append((p1, p2, dr2, r1, c1, r2, c2))
477 def get_upper_bond(self, pearsoncc):
479 return (pearsoncc - .5) / (-0.005415)
481 def get_lower_bond(self, pearsoncc):
482 return (pearsoncc - 1.) / -0.0551
484 def set_label(self, label):
487 def add_to_model(self):
490 def get_hierarchies(self):
493 def get_restraint_sets(self):
496 def set_output_level(self, level="low"):
498 self.outputlevel = level
500 def get_output(self):
506 score = self.rs.unprotected_evaluate(
None)
507 output[
"_TotalScore"] = str(score)
508 output[
"SimplifiedPEMAP_Score_" + self.label] = str(score)
509 for i
in range(len(self.pairs)):
511 p0 = self.pairs[i][0]
512 p1 = self.pairs[i][1]
513 crosslinker =
'standard'
514 ln = self.pairs[i][2]
515 resid1 = self.pairs[i][3]
516 chain1 = self.pairs[i][4]
517 resid2 = self.pairs[i][5]
518 chain2 = self.pairs[i][6]
520 label = str(resid1) +
":" + chain1 +
"_" + \
521 str(resid2) +
":" + chain2
522 output[
"SimplifiedPEMAP_Score_" + crosslinker +
"_" +
523 label] = str(ln.unprotected_evaluate(
None))
527 output[
"SimplifiedPEMAP_Distance_" +
536 generates and wraps a IMP.pmi.ConnectivityRestraint between domains
538 cr=restraints.ConnectivityNetworkRestraint(simo,["CCC",(1,100,"TTT"),(100,150,"AAA")])
542 Multistate support =No
543 Selection type=selection tuple
558 if self.label ==
"None":
559 self.label = str(selection_tuples)
561 self.m = representation.m
566 for s
in selection_tuples:
567 particles = IMP.pmi.tools.select_by_tuple(representation, s,
568 resolution=resolution,
569 name_is_ambiguous=
False)
571 cr.add_particles([p.get_particle()
for p
in particles])
573 self.rs.add_restraint(cr)
575 def set_label(self, label):
577 self.rs.set_name(label)
578 for r
in self.rs.get_restraints():
581 def add_to_model(self):
584 def get_restraint(self):
587 def get_restraints(self):
589 for r
in self.rs.get_restraints():
590 rlist.append(IMP.core.PairRestraint.get_from(r))
593 def set_weight(self, weight):
595 self.rs.set_weight(weight)
597 def get_output(self):
600 score = self.weight * self.rs.unprotected_evaluate(
None)
601 output[
"_TotalScore"] = str(score)
602 output[
"ConnectivityNetworkRestraint_" + self.label] = str(score)
609 a python restraint that computes the score for a composite of proteins
610 Authors: G. Bouvier, R. Pellarin. Pasteur Institute.
616 def __init__(self,m,slope=1.0,theta=0.0,plateau=0.0000000001,linear_slope=0.015):
618 input a list of particles, the slope and theta of the sigmoid potential
619 theta is the cutoff distance for a protein-protein contact
621 IMP.Restraint.__init__(self, m,
"ConnectivityNetworkRestraint %1%")
624 self.linear_slope=linear_slope
626 self.particles_blocks=[]
627 self.particle_list=[]
629 def get_number_of_particle_blocks(self):
630 return len(self.particles_blocks)
632 def get_number_of_particles_for_block(self,block_index):
633 return len(self.particles_blocks[block_index])
636 self.particles_blocks.append(particles)
637 self.particle_list+=particles
641 get the full graph of distances between every particle pair
647 pdist_mat=scipy.spatial.distance.squareform(pdist_array)
648 pdist_mat[pdist_mat < 0] = 0
649 graph = networkx.Graph(pdist_mat)
654 return the minimum spanning tree
658 graph = networkx.minimum_spanning_tree(graph)
663 a sigmoid function that scores the probability of a contact
667 argvalue=(x-self.theta)/self.slope
668 return 1.0-(1.0-self.plateau)/(1.0+self.math.exp(-argvalue))
670 def unprotected_evaluate(self,da):
673 for e
in graph.edges():
674 dist=graph.get_edge_data(*e)[
'weight']
676 score+=-self.numpy.log(prob)
677 score+=self.linear_slope*dist
681 return self.particle_list
694 selection_tuples_above=
None,
695 selection_tuples_inside=
None,
696 selection_tuples_below=
None,
706 self.m = representation.prot.get_model()
708 self.representation=representation
709 self.thickness=thickness
711 self.z_center=IMP.pmi.tools.SetupNuisance(self.m, z_init, z_min, z_max, isoptimized=
True).get_particle()
718 if selection_tuples_above
is not None:
720 for s
in selection_tuples_above:
721 particles = IMP.pmi.tools.select_by_tuple(self.representation, s,
722 resolution=resolution, name_is_ambiguous=
True)
723 particles_above+=particles
725 mr.add_particles_above([h.get_particle().
get_index()
for h
in particles_above])
727 if selection_tuples_below
is not None:
729 for s
in selection_tuples_below:
730 particles = IMP.pmi.tools.select_by_tuple(self.representation, s,
731 resolution=resolution, name_is_ambiguous=
True)
732 particles_below+=particles
733 mr.add_particles_below([h.get_particle().
get_index()
for h
in particles_below])
735 if selection_tuples_inside
is not None:
736 particles_inside = []
737 for s
in selection_tuples_inside:
738 particles = IMP.pmi.tools.select_by_tuple(self.representation, s,
739 resolution=resolution, name_is_ambiguous=
True)
740 particles_inside+=particles
741 mr.add_particles_inside([h.get_particle().
get_index()
for h
in particles_inside])
743 self.rs.add_restraint(mr)
745 def create_box(self, x_center, y_center):
747 z=self.z_center.get_nuisance()
750 h.set_name(
"Membrane_"+self.label)
751 self.representation.prot.add_child(h)
758 d.set_coordinates((x_center,y_center,0))
761 h.add_child(h_origin)
762 particles_box.append(p_origin)
767 d.set_coordinates((x_center,y_center,z+100))
771 particles_box.append(p1)
776 d.set_coordinates((x_center,y_center,z-100))
780 particles_box.append(p2)
787 p1.set_name(
"z_positive")
788 p2.set_name(
"z_negative")
791 for offs
in [self.thickness/2,-self.thickness/2]:
795 d.set_coordinates((-100+x_center,-100+y_center,z+offs))
799 particles_box.append(p1)
804 d.set_coordinates((-100+x_center,100+y_center,z+offs))
808 particles_box.append(p2)
813 d.set_coordinates((100+x_center,-100+y_center,z+offs))
817 particles_box.append(p3)
822 d.set_coordinates((100+x_center,100+y_center,z+offs))
826 particles_box.append(p4)
838 sm = self._MembraneSingletonModifier(p_origin,self.z_center)
840 for p
in particles_box:
842 lc.add(p.get_index())
845 self.m.add_score_state(c)
849 """A class that updates the membrane particles
852 def __init__(self, p_origin,z_nuisance):
853 IMP.SingletonModifier.__init__(self,
"MembraneSingletonModifier%1%")
854 self.p_origin_index=p_origin.get_index()
855 self.z_nuisance=z_nuisance
857 def apply_index(self, m, pi):
859 new_z=self.z_nuisance.get_nuisance()
862 d.set_z(current_z+new_z-z_center)
864 def do_get_inputs(self, m, pis):
867 def do_get_outputs(self, m, pis):
868 return self.do_get_inputs(m, pis)
870 def set_label(self, label):
872 self.rs.set_name(label)
873 for r
in self.rs.get_restraints():
876 def add_to_model(self):
879 def get_restraint(self):
882 def set_weight(self, weight):
884 self.rs.set_weight(weight)
886 def get_particles_to_sample(self):
889 ps[
"Nuisances_MembraneRestraint_Z_" + self.label] =([self.z_center],2.0)
892 def get_output(self):
895 score = self.weight * self.rs.unprotected_evaluate(
None)
896 output[
"_TotalScore"] = str(score)
897 output[
"MembraneRestraint_" + self.label] = str(score)
898 output[
"MembraneRestraint_Z_"+ self.label] = str(self.z_center.get_nuisance())
905 Fully Ambiguous Restraint that can be built using boolean logic
906 R. Pellarin. Pasteur Institute.
911 input a list of particles, the slope and theta of the sigmoid potential
912 theta is the cutoff distance for a protein-protein contact
914 if isinstance(p1, FuzzyBoolean)
and isinstance(p2, FuzzyBoolean):
915 self.operations = [p1, operator, p2]
921 def __or__(self, FuzzyBoolean2):
924 def __and__(self, FuzzyBoolean2):
931 return 1.0-(1.0-a)*(1.0-b)
935 if len(self.operations) == 0:
937 FuzzyBoolean1, op, FuzzyBoolean2 = self.operations
939 return op(FuzzyBoolean1.evaluate(),FuzzyBoolean2.evaluate())
943 Fully Ambiguous Restraint that can be built using boolean logic
944 R. Pellarin. Pasteur Institute.
947 plateau=0.00000000000001
955 input a list of particles, the slope and theta of the sigmoid potential
956 theta is the cutoff distance for a protein-protein contact
958 IMP.Restraint.__init__(self, m,
"FuzzyRestraint %1%")
960 self.min=self.sys.float_info.min
961 if isinstance(p1, FuzzyRestraint)
and isinstance(p2, FuzzyRestraint):
962 self.operations = [p1, operator, p2]
963 self.particle_pair =
None
964 elif isinstance(p1, FuzzyRestraint)
and p2
is None:
965 self.operations = [p1, operator,
None]
966 self.particle_pair =
None
969 self.particle_pair = (p1,p2)
971 def __or__(self, FuzzyRestraint2):
974 def __and__(self, FuzzyRestraint2):
977 def __invert__(self):
985 c=self.math.exp(-a)+self.math.exp(-b)-self.math.exp(-a-b)
986 return -self.math.log(c)
989 c=1.0-self.math.exp(-a)
990 return -self.math.log(c)
993 if len(self.operations) == 0:
994 return self.distance()
995 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
997 if FuzzyRestraint2
is not None:
998 return op(FuzzyRestraint1.evaluate(),FuzzyRestraint2.evaluate())
1000 return op(FuzzyRestraint1.evaluate())
1006 argvalue=(d-self.theta)/self.slope
1007 return -self.math.log(1.0-(1.0-self.plateau)/(1.0+self.math.exp(-argvalue)))+self.innerslope*d
1009 def add_to_model(self):
1012 def unprotected_evaluate(self,da):
1013 return self.evaluate()
1016 if len(self.operations) == 0:
1017 return str(self.particle_pair)
1018 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1019 if FuzzyRestraint2
is not None:
1020 return str(FuzzyRestraint1)+str(op)+str(FuzzyRestraint2)
1022 return str(FuzzyRestraint1)+str(op)
1025 if len(self.operations) == 0:
1026 return list(self.particle_pair)
1027 FuzzyRestraint1, op, FuzzyRestraint2 = self.operations
1028 if FuzzyRestraint2
is not None:
1029 return list(set(FuzzyRestraint1.do_get_inputs()+FuzzyRestraint2.do_get_inputs()))
1031 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.
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 ...
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 model particles.
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.