IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
stereochemistry.py
1 """@namespace IMP.pmi.restraints.stereochemistry
2 Restraints for keeping correct stereochemistry.
3 """
4 
5 from __future__ import print_function
6 import IMP
7 import IMP.core
8 import IMP.algebra
9 import IMP.atom
10 import IMP.container
11 import itertools
12 import sys
13 import IMP.pmi.tools
14 try:
15  import IMP.isd2
16  noisd2 = False
17 except:
18  noisd2 = True
19 try:
20  import IMP.isd_emxl
21  no_isd_emxl = False
22 except:
23  no_isd_emxl = True
24 
25 
26 class ExcludedVolumeSphere(object):
27 
28  '''
29  all leaves of the input hierarchies will be input in the
30  restraint. If other_hierarchies is defined, then a Bipartite container
31  between "hierarchies" and "other_hierarchies" leaves is initialized
32  '''
33 
34  def __init__(self, representation,
35  hierarchies=None,
36  other_hierarchies=None,
37  resolution=None, kappa=1.0):
38 
39  self.m = representation.prot.get_model()
40  self.rs = IMP.RestraintSet(self.m, 'excluded_volume')
41  self.weight = 1.0
42  self.kappa = kappa
43 
44  self.label = "None"
45  self.cpc = None
46 
47  ssps = IMP.core.SoftSpherePairScore(self.kappa)
49 
50  particles = IMP.pmi.tools.select(
51  representation,
52  resolution=resolution,
53  hierarchies=hierarchies)
54 
55  lsa.add(IMP.get_indexes(particles))
56 
57  if other_hierarchies is None:
59  self.cpc = IMP.container.ClosePairContainer(lsa, 0.0, rbcpf, 10.0)
60  evr = IMP.container.PairsRestraint(ssps, self.cpc)
61 
62  else:
63  other_lsa = IMP.container.ListSingletonContainer(self.m)
64  other_particles = IMP.pmi.tools.select(
65  representation,
66  resolution=resolution,
67  hierarchies=other_hierarchies)
68  other_lsa.add_particles(particles)
70  lsa,
71  other_lsa,
72  0.0,
73  10.0)
74  evr = IMP.container.PairsRestraint(ssps, self.cpc)
75 
76  self.rs.add_restraint(evr)
77 
78  def add_excluded_particle_pairs(self, excluded_particle_pairs):
79  # add pairs to be filtered when calculating the score
81  lpc.add(IMP.get_indexes(excluded_particle_pairs))
83  self.cpc.add_pair_filter(icpf)
84 
85  def set_label(self, label):
86  self.label = label
87 
88  def add_to_model(self):
90 
91  def get_restraint(self):
92  return self.rs
93 
94  def set_weight(self, weight):
95  self.weight = weight
96  self.rs.set_weight(weight)
97 
98  def get_output(self):
99  self.m.update()
100  output = {}
101  score = self.weight * self.rs.unprotected_evaluate(None)
102  output["_TotalScore"] = str(score)
103  output["ExcludedVolumeSphere_" + self.label] = str(score)
104  return output
105 
106 
107 class ResidueBondRestraint(object):
108 
109  '''
110  add bond restraint between pair of consecutive
111  residues/beads to enforce the stereochemistry.
112  '''
113  import IMP.pmi.tools
114  from math import pi as pi
115 
116  def __init__(
117  self,
118  representation,
119  selection_tuple,
120  distance=3.78,
121  strength=10.0,
122  jitter=None):
123  '''
124  jitter: defines the +- added to the optimal distance in the harmonic well restraint
125  used to increase the tolerance
126  '''
127  self.m = representation.prot.get_model()
128  self.rs = IMP.RestraintSet(self.m, "Bonds")
129  self.weight = 1
130  self.label = "None"
131  self.pairslist = []
132 
133  particles = IMP.pmi.tools.select_by_tuple(
134  representation,
135  selection_tuple,
136  resolution=1)
137 
138  if not jitter:
139  ts = IMP.core.Harmonic(distance, strength)
140  else:
142  (distance - jitter, distance + jitter), strength)
143 
144  for ps in IMP.pmi.tools.sublist_iterator(particles, 2, 2):
145  pair = []
146  if len(ps) != 2:
147  raise ValueError("wrong length of pair")
148  for p in ps:
150  raise TypeError("not a residue")
151  else:
152  pair.append(p)
153  print("ResidueBondRestraint: adding a restraint between %s %s" % (pair[0].get_name(), pair[1].get_name()))
154  self.rs.add_restraint(
155  IMP.core.DistanceRestraint(self.m, ts, pair[0], pair[1]))
156  self.pairslist.append(IMP.ParticlePair(pair[0], pair[1]))
157  self.pairslist.append(IMP.ParticlePair(pair[1], pair[0]))
158 
159  def set_label(self, label):
160  self.label = label
161  self.rs.set_name(label)
162  for r in self.rs.get_restraints():
163  r.set_name(label)
164 
165  def add_to_model(self):
166  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
167 
168  def get_restraint(self):
169  return self.rs
170 
171  def set_weight(self, weight):
172  self.weight = weight
173  self.rs.set_weight(weight)
174 
175  def get_excluded_pairs(self):
176  return self.pairslist
177 
178  def get_output(self):
179  self.m.update()
180  output = {}
181  score = self.weight * self.rs.unprotected_evaluate(None)
182  output["_TotalScore"] = str(score)
183  output["ResidueBondRestraint_" + self.label] = str(score)
184  return output
185 
186 
187 class ResidueAngleRestraint(object):
188 
189  '''
190  add angular restraint between triplets of consecutive
191  residues/beads to enforce the stereochemistry.
192  '''
193  import IMP.pmi.tools
194  from math import pi as pi
195 
196  def __init__(
197  self,
198  representation,
199  selection_tuple,
200  anglemin=100.0,
201  anglemax=140.0,
202  strength=10.0):
203  self.m = representation.prot.get_model()
204  self.rs = IMP.RestraintSet(self.m, "Angles")
205  self.weight = 1
206  self.label = "None"
207  self.pairslist = []
208 
209  particles = IMP.pmi.tools.select_by_tuple(
210  representation,
211  selection_tuple,
212  resolution=1)
213 
215  (self.pi * anglemin / 180.0,
216  self.pi * anglemax / 180.0),
217  strength)
218 
219  for ps in IMP.pmi.tools.sublist_iterator(particles, 3, 3):
220  triplet = []
221  if len(ps) != 3:
222  raise ValueError("wrong length of triplet")
223  for p in ps:
225  raise TypeError("not a residue")
226  else:
227  triplet.append(p)
228  print("ResidueAngleRestraint: adding a restraint between %s %s %s" % (triplet[0].get_name(), triplet[1].get_name(), triplet[2].get_name()))
229  self.rs.add_restraint(
230  IMP.core.AngleRestraint(triplet[0].get_model(), ts,
231  triplet[0],
232  triplet[1],
233  triplet[2]))
234  self.pairslist.append(IMP.ParticlePair(triplet[0], triplet[2]))
235  self.pairslist.append(IMP.ParticlePair(triplet[2], triplet[0]))
236 
237  def set_label(self, label):
238  self.label = label
239  self.rs.set_name(label)
240  for r in self.rs.get_restraints():
241  r.set_name(label)
242 
243  def add_to_model(self):
244  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
245 
246  def get_restraint(self):
247  return self.rs
248 
249  def set_weight(self, weight):
250  self.weight = weight
251  self.rs.set_weight(weight)
252 
253  def get_excluded_pairs(self):
254  return self.pairslist
255 
256  def get_output(self):
257  self.m.update()
258  output = {}
259  score = self.weight * self.rs.unprotected_evaluate(None)
260  output["_TotalScore"] = str(score)
261  output["ResidueAngleRestraint_" + self.label] = str(score)
262  return output
263 
264 
266 
267  '''
268  Add dihedral restraints between quadruplet of consecutive
269  residues/beads to enforce the stereochemistry.
270  Give as input a string of "C" and "T", meaning cys (0+-40) or trans (180+-40)
271  dihedral. The length of the string must be \#residue-3.
272  Without the string, the dihedral will be assumed trans.
273  '''
274  import IMP.pmi.tools
275  from math import pi as pi
276 
277  def __init__(
278  self,
279  representation,
280  selection_tuple,
281  stringsequence=None,
282  strength=10.0):
283  self.m = representation.prot.get_model()
284  self.rs = IMP.RestraintSet(self.m, "Angles")
285  self.weight = 1
286  self.label = "None"
287  self.pairslist = []
288 
289  particles = IMP.pmi.tools.select_by_tuple(
290  representation,
291  selection_tuple,
292  resolution=1)
293 
294  if stringsequence is None:
295  stringsequence = "T" * (len(particles) - 3)
296 
297  for n, ps in enumerate(IMP.pmi.tools.sublist_iterator(particles, 4, 4)):
298  quadruplet = []
299  if len(ps) != 4:
300  raise ValueError("wrong length of quadruplet")
301  for p in ps:
303  raise TypeError("not a residue")
304  else:
305  quadruplet.append(p)
306  dihedraltype = stringsequence[n]
307  if dihedraltype == "C":
308  anglemin = -20.0
309  anglemax = 20.0
311  (self.pi * anglemin / 180.0,
312  self.pi * anglemax / 180.0),
313  strength)
314  print("ResidueDihedralRestraint: adding a CYS restraint between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(),
315  quadruplet[2].get_name(), quadruplet[3].get_name()))
316  if dihedraltype == "T":
317  anglemin = 180 - 70.0
318  anglemax = 180 + 70.0
320  (self.pi * anglemin / 180.0,
321  self.pi * anglemax / 180.0),
322  strength)
323  print("ResidueDihedralRestraint: adding a TRANS restraint between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(),
324  quadruplet[2].get_name(), quadruplet[3].get_name()))
325  self.rs.add_restraint(
327  quadruplet[0],
328  quadruplet[1],
329  quadruplet[2],
330  quadruplet[3]))
331  self.pairslist.append(
332  IMP.ParticlePair(quadruplet[0], quadruplet[3]))
333  self.pairslist.append(
334  IMP.ParticlePair(quadruplet[3], quadruplet[0]))
335 
336  def set_label(self, label):
337  self.label = label
338  self.rs.set_name(label)
339  for r in self.rs.get_restraints():
340  r.set_name(label)
341 
342  def add_to_model(self):
343  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
344 
345  def get_restraint(self):
346  return self.rs
347 
348  def set_weight(self, weight):
349  self.weight = weight
350  self.rs.set_weight(weight)
351 
352  def get_excluded_pairs(self):
353  return self.pairslist
354 
355  def get_output(self):
356  self.m.update()
357  output = {}
358  score = self.weight * self.rs.unprotected_evaluate(None)
359  output["_TotalScore"] = str(score)
360  output["ResidueDihedralRestraint_" + self.label] = str(score)
361  return output
362 
363 
364 #
365 class SecondaryStructure(object):
366 
367  from math import pi
368  from math import log
369 
370  def __init__(
371  self,
372  representation,
373  selection_tuple,
374  ssstring,
375  mixture=False,
376  nativeness=1.0,
377  kt_caff=0.1):
378 
379  if no_isd_emxl:
380  raise ValueError("IMP.isd_emxl is needed")
381 
382  # check that the secondary structure string
383  # is compatible with the ssstring
384 
385  self.particles = IMP.pmi.tools.select_by_tuple(
386  representation,
387  selection_tuple,
388  resolution=1)
389  self.m = representation.prot.get_model()
390  self.dihe_dict = {}
391  self.ang_dict = {}
392  self.do_mix = {}
393  self.anglfilename = IMP.isd_emxl.get_data_path("CAAngleRestraint.dat")
394  self.dihefilename = IMP.isd_emxl.get_data_path(
395  "CADihedralRestraint.dat")
396  self.nativeness = nativeness
397  self.kt_caff = kt_caff
398  self.anglrs = IMP.RestraintSet(self.m, "Angles")
399  self.dihers = IMP.RestraintSet(self.m, "Dihedrals")
400  self.bondrs = IMP.RestraintSet(self.m, "Bonds")
401  self.label = "None"
402 
403  if len(self.particles) != len(ssstring):
404  print(len(self.particles), len(ssstring))
405  print("SecondaryStructure: residue range and SS string incompatible")
406  self.ssstring = ssstring
407 
408  (bondrslist, anglrslist, diherslist,
409  pairslist) = self.get_CA_force_field()
410  self.pairslist = pairslist
411 
412  # print anglrslist, diherslist, bondrslist, self.particles
413  self.anglrs.add_restraints(anglrslist)
414  self.dihers.add_restraints(diherslist)
415  self.bondrs.add_restraints(bondrslist)
416 
417  def set_label(self, label):
418  self.label = label
419 
420  def add_to_model(self):
421  IMP.pmi.tools.add_restraint_to_model(self.m, self.anglrs)
422  IMP.pmi.tools.add_restraint_to_model(self.m, self.dihers)
423  IMP.pmi.tools.add_restraint_to_model(self.m, self.bondrs)
424 
425  def get_CA_force_field(self):
426  bondrslist = []
427  anglrslist = []
428  diherslist = []
429  pairslist = []
430  # add bonds
431  for res in range(0, len(self.particles) - 1):
432 
433  ps = self.particles[res:res + 2]
434  pairslist.append(IMP.ParticlePair(ps[0], ps[1]))
435  pairslist.append(IMP.ParticlePair(ps[1], ps[0]))
436  br = self.get_distance_restraint(ps[0], ps[1], 3.78, 416.0)
437  br.set_name('Bond_restraint')
438  bondrslist.append(br)
439  # add dihedrals
440  for res in range(0, len(self.particles) - 4):
441 
442  # if res not in dihe_dict: continue
443  # get the appropriate parameters
444  # get the particles
445  ps = self.particles[res:res + 5]
446  [phi0,
447  phi1,
448  score_dih] = self.read_potential_dihedral(
449  self.ssstring[res:res + 4],
450  True)
451  pairslist.append(IMP.ParticlePair(ps[0], ps[3]))
452  pairslist.append(IMP.ParticlePair(ps[3], ps[0]))
453  pairslist.append(IMP.ParticlePair(ps[1], ps[4]))
454  pairslist.append(IMP.ParticlePair(ps[4], ps[1]))
455  dr = IMP.isd_emxl.CADihedralRestraint(
456  ps[0],
457  ps[1],
458  ps[2],
459  ps[3],
460  ps[4],
461  phi0,
462  phi1,
463  score_dih)
464  dr.set_name('Dihedral restraint')
465  diherslist.append(dr)
466  # add angles
467  for res in range(0, len(self.particles) - 2):
468  ps = self.particles[res:res + 3]
469  [psi, score_ang] = self.read_potential_angle(
470  self.ssstring[res:res + 2], True)
471  pairslist.append(IMP.ParticlePair(ps[0], ps[2]))
472  pairslist.append(IMP.ParticlePair(ps[2], ps[0]))
473  dr = IMP.isd_emxl.CAAngleRestraint(
474  ps[0],
475  ps[1],
476  ps[2],
477  psi,
478  score_ang)
479  dr.set_name('Angle restraint')
480  anglrslist.append(dr)
481  return (bondrslist, anglrslist, diherslist, pairslist)
482 
483  def read_potential_dihedral(self, string, mix=False):
484  # read potentials for dihedral
485  score_dih = []
486  phi0 = []
487  phi1 = []
488  for i in range(0, 36):
489  phi0.append(i * 10.0 / 180.0 * self.pi)
490  phi1.append(i * 10.0 / 180.0 * self.pi)
491  for j in range(0, 36):
492  score_dih.append(0.0)
493  # open file
494  if not mix:
495  f = open(self.dihefilename, 'r')
496  for line in f.readlines():
497  riga = (line.strip()).split()
498  if (len(riga) == 4 and riga[0] == string):
499  ii = int(float(riga[1]) / 10.0)
500  jj = int(float(riga[2]) / 10.0)
501  score_dih[ii * len(phi0) + jj] = - \
502  self.kt_caff * self.log(float(riga[3]))
503  f.close()
504  if mix:
505  # mix random coil and native secondary structure
506  counts = []
507  for i in range(0, 36):
508  for j in range(0, 36):
509  counts.append(1.0)
510  f = open(self.dihefilename, 'r')
511  for line in f.readlines():
512  riga = (line.strip()).split()
513  if (len(riga) == 4 and riga[0] == string):
514  ii = int(float(riga[1]) / 10.0)
515  jj = int(float(riga[2]) / 10.0)
516  counts[ii * len(phi0) + jj] += self.nativeness * \
517  float(riga[3])
518  if (len(riga) == 4 and riga[0] == "-----"):
519  ii = int(float(riga[1]) / 10.0)
520  jj = int(float(riga[2]) / 10.0)
521  counts[ii * len(phi0) + jj] += (1.0 - self.nativeness) * \
522  float(riga[3])
523  f.close()
524  for i in range(len(counts)):
525  score_dih[i] = -self.kt_caff * self.log(counts[i])
526  return [phi0, phi1, score_dih]
527 
528  def read_potential_angle(self, string, mix=False):
529  # read potentials for angles
530  score_ang = []
531  psi = []
532  for i in range(0, 180):
533  psi.append(i / 180.0 * self.pi)
534  score_ang.append(0.0)
535  # read file
536  if not mix:
537  f = open(self.anglfilename, 'r')
538  for line in f.readlines():
539  riga = (line.strip()).split()
540  if (len(riga) == 3 and riga[0] == string):
541  ii = int(riga[1])
542  score_ang[ii] = -self.kt_caff * self.log(float(riga[2]))
543  f.close()
544  if mix:
545  # mix random coil and native secondary structure
546  counts = []
547  for i in range(0, 180):
548  counts.append(1.0)
549 
550  f = open(self.anglfilename, 'r')
551  for line in f.readlines():
552  riga = (line.strip()).split()
553  if (len(riga) == 3 and riga[0] == string):
554  ii = int(riga[1])
555  counts[ii] += self.nativeness * float(riga[2])
556  if (len(riga) == 3 and riga[0] == "---"):
557  ii = int(riga[1])
558  counts[ii] += (1.0 - self.nativeness) * float(riga[2])
559  f.close()
560  for i in range(0, 180):
561  score_ang[i] = -self.kt_caff * self.log(counts[i])
562  return [psi, score_ang]
563 
564  def get_excluded_pairs(self):
565  return self.pairslist
566 
567  def get_restraint(self):
568  tmprs = IMP.RestraintSet(self.m, 'tmp')
569  tmprs.add_restraint(self.anglrs)
570  tmprs.add_restraint(self.dihers)
571  tmprs.add_restraint(self.bondrs)
572  return tmprs
573 
574  def get_distance_restraint(self, p0, p1, d0, kappa):
575  h = IMP.core.Harmonic(d0, kappa)
577  pr = IMP.core.PairRestraint(self.m, dps, IMP.ParticlePair(p0, p1))
578  return pr
579 
580  def get_output(self):
581  output = {}
582  self.m.update()
583  score_angle = self.anglrs.unprotected_evaluate(None)
584  score_dihers = self.dihers.unprotected_evaluate(None)
585  score_bondrs = self.bondrs.unprotected_evaluate(None)
586  output["_TotalScore"] = str(score_angle + score_dihers + score_bondrs)
587 
588  output["SecondaryStructure_Angles_" + self.label] = str(score_angle)
589  output["SecondaryStructure_Dihedrals_" +
590  self.label] = str(score_dihers)
591  output["SecondaryStructure_Bonds_" + self.label] = str(score_bondrs)
592  return output
593 
594 
596 
597  '''
598  add harmonic restraints between all pairs
599  '''
600  import IMP.pmi.tools
601  from math import pi as pi
602 
603  def __init__(self,representation,
604  selection_tuples,
605  resolution=1,
606  strength=0.01,
607  dist_cutoff=10.0,
608  ca_only=True):
609  '''
610  ca_only: only applies for resolution 0
611  '''
612  self.m = representation.prot.get_model()
613  self.rs = IMP.RestraintSet(self.m, "ElasticNetwork")
614  self.weight = 1
615  self.label = "None"
616  self.pairslist = []
617 
618  particles = []
619  for st in selection_tuples:
620  print('selecting with',st)
621  for p in IMP.pmi.tools.select_by_tuple(representation,st,resolution=resolution):
622  if (resolution==0 and ca_only and IMP.atom.Atom(p).get_atom_type()!=IMP.atom.AtomType("CA")):
623  continue
624  else:
625  particles.append(p.get_particle())
626 
627 
629  gcpf.set_distance(dist_cutoff)
630  particleindexes=IMP.get_indexes(particles)
631  pairs=gcpf.get_close_pairs( self.m,
632  particleindexes,
633  particleindexes)
634 
635  for pair in pairs:
636  p1=self.m.get_particle(pair[0])
637  p2=self.m.get_particle(pair[1])
638  if p1==p2:
639  print("%s and %s are the same particle" % (p1.get_name(),p2.get_name()))
640  continue
643  IMP.core.RigidMember(p1).get_rigid_body() ==
644  IMP.core.RigidMember(p2).get_rigid_body()):
645  print("%s and %s are in the same rigid body" % (p1.get_name(),p2.get_name()))
646  continue
647 
648  distance=IMP.algebra.get_distance(IMP.core.XYZ(p1).get_coordinates(),
649  IMP.core.XYZ(p2).get_coordinates())
650 
651  ts=IMP.core.HarmonicDistancePairScore(distance,strength)
652  print("ElasticNetworkConstraint: adding a restraint between %s and %s with distance %.3f" % (p1.get_name(),p2.get_name(),distance))
653  self.rs.add_restraint(IMP.core.PairRestraint(self.m, ts, (p1, p2)))
654  self.pairslist.append(IMP.ParticlePair(p1, p2))
655  self.pairslist.append(IMP.ParticlePair(p1, p2))
656  print('created',self.rs.get_number_of_restraints(),'restraints')
657 
658  def set_label(self, label):
659  self.label = label
660  self.rs.set_name(label)
661  for r in self.rs.get_restraints():
662  r.set_name(label)
663 
664  def add_to_model(self):
665  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
666 
667  def get_restraint(self):
668  return self.rs
669 
670  def set_weight(self, weight):
671  self.weight = weight
672  self.rs.set_weight(weight)
673 
674  def get_excluded_pairs(self):
675  return self.pairslist
676 
677  def get_output(self):
678  self.m.update()
679  output = {}
680  score = self.weight * self.rs.unprotected_evaluate(None)
681  output["_TotalScore"] = str(score)
682  output["ElasticNetworkRestraint_" + self.label] = str(score)
683  return output
684 
685 
687 
688  '''
689  add charmm force field
690  '''
691  import IMP.pmi.tools
692  from math import pi as pi
693  import IMP.isd
694 
695  def __init__(self,representation,ff_temp=300.0):
696 
697  kB = (1.381 * 6.02214) / 4184.0
698 
699  self.m=representation.prot.get_model()
700  self.bonds_rs = IMP.RestraintSet(self.m, 1.0 / (kB * ff_temp), 'bonds')
701  self.nonbonded_rs = IMP.RestraintSet(self.m, 1.0 / (kB * ff_temp), 'NONBONDED')
702  self.weight=1
703  self.label="None"
704 
705 
706  #root=representation.prot.get_children()[0].get_children()[0].get_children()[0]
707  root=representation.prot
708 
709  ### charmm setup
711  topology = ff.create_topology(root)
712  topology.apply_default_patches()
713  topology.setup_hierarchy(root)
714  r = IMP.atom.CHARMMStereochemistryRestraint(root, topology)
715  self.bonds_rs.add_restraint(r)
716  ff.add_radii(root)
717  ff.add_well_depths(root)
718  atoms=IMP.atom.get_leaves(root)
719 
720  ### non-bonded forces
722  self.nbl = IMP.container.ClosePairContainer(cont, 4.0)
723  self.nbl.add_pair_filter(r.get_pair_filter())
724  #sf = IMP.atom.ForceSwitch(6.0, 7.0)
725  #pairscore = IMP.atom.LennardJonesPairScore(sf)
726  pairscore = IMP.isd.RepulsiveDistancePairScore(0,1)
727  pr=IMP.container.PairsRestraint(pairscore, self.nbl)
728  self.nonbonded_rs.add_restraint(pr)
729 
730  #self.scoring_function = IMP.core.RestraintsScoringFunction([r,pr])
731 
732  print('CHARMM is set up')
733 
734  def set_label(self, label):
735  self.label = label
736  self.rs.set_name(label)
737  for r in self.rs.get_restraints():
738  r.set_name(label)
739 
740  def add_to_model(self):
741  IMP.pmi.tools.add_restraint_to_model(self.m, self.bonds_rs)
742  IMP.pmi.tools.add_restraint_to_model(self.m, self.nonbonded_rs)
743 
744  def get_restraint(self):
745  return self.rs
746 
747  def get_close_pair_container(self):
748  return self.nbl
749 
750  def set_weight(self, weight):
751  self.weight = weight
752  self.rs.set_weight(weight)
753 
754  def get_output(self):
755  self.m.update()
756  output = {}
757  bonds_score = self.weight * self.bonds_rs.unprotected_evaluate(None)
758  nonbonded_score = self.weight * self.nonbonded_rs.unprotected_evaluate(None)
759  score=bonds_score+nonbonded_score
760  output["_TotalScore"] = str(score)
761  output["CHARMM_BONDS"] = str(bonds_score)
762  output["CHARMM_NONBONDED"] = str(nonbonded_score)
763  return output
764 
765 
766 class PseudoAtomicRestraint(object):
767 
768  '''
769  add bonds and improper dihedral restraints for the CBs
770  '''
771  import IMP.pmi.tools
772  from math import pi as pi
773 
774  def __init__(
775  self, rnums, representation, selection_tuple, strength=10.0, kappa=1.0,
776  jitter_angle=0.0, jitter_improper=0.0):
777  '''
778  need to add:
779  ca-ca bond
780  ca-cb is a constraint, no restraint needed
781  ca-ca-ca
782  cb-ca-ca-cb
783  '''
784 
785  self.m = representation.prot.get_model()
786  self.rs = IMP.RestraintSet(self.m, "PseudoAtomic")
787  self.rset_angles = IMP.RestraintSet(self.m, "PseudoAtomic_Angles")
788  self.rset_bonds = IMP.RestraintSet(self.m, "PseudoAtomic_Bonds")
789  self.weight = 1
790  self.label = "None"
791  self.pairslist = []
792 
793  # residues=IMP.pmi.tools.select_by_tuple(representation,selection_tuple,resolution=1)
794  for rnum in rnums:
795  ca, cb = self.get_ca_cb(
796  IMP.pmi.tools.select_by_tuple(representation,
797  (rnum, rnum, 'chainA'), resolution=0))
798  if not cb is None:
799  nter = False
800  cter = False
801  ca_prev, cb_prev = self.get_ca_cb(
802  IMP.pmi.tools.select_by_tuple(representation,
803  (rnum - 1, rnum - 1, 'chainA'), resolution=0))
804  ca_next, cb_next = self.get_ca_cb(
805  IMP.pmi.tools.select_by_tuple(representation,
806  (rnum + 1, rnum + 1, 'chainA'), resolution=0))
807  if ca_prev is None:
808  nter = True
809  else:
810  if ca_next is None:
811  cter = True
812  else:
813  if (nter and cter):
814  continue
815 
816  # adding a bond restraint between CA and CB
817  # h=IMP.core.Harmonic(6.0,kappa)
818  # dps=IMP.core.DistancePairScore(h)
819  # pr=IMP.core.PairRestraint(dps,IMP.ParticlePair(ca,cb))
820  # self.pairslist.append((ca,cb))
821  # self.rset_bonds.add_restraint(pr)
822 
823  # creating improper dihedral restraint
824  # hus=IMP.core.Harmonic(2.09,kappa)
826  2.09 +
827  jitter_angle /
828  0.5,
829  kappa)
831  2.09 -
832  jitter_angle /
833  0.5,
834  kappa)
835  if not nter:
836  # ar13=IMP.core.AngleRestraint(hus,ca_prev,ca,cb)
837  # self.rset_angles.add_restraint(ar13)
838  ar13u = IMP.core.AngleRestraint(hupp, ca_prev, ca, cb)
839  ar13l = IMP.core.AngleRestraint(hlow, ca_prev, ca, cb)
840  self.rset_angles.add_restraint(ar13u)
841  self.rset_angles.add_restraint(ar13l)
842  if not cter:
843  # ar23=IMP.core.AngleRestraint(hus,ca_next,ca,cb)
844  # self.rset_angles.add_restraint(ar23)
845  ar23u = IMP.core.AngleRestraint(hupp, ca_next, ca, cb)
846  ar23l = IMP.core.AngleRestraint(hlow, ca_next, ca, cb)
847  self.rset_angles.add_restraint(ar23u)
848  self.rset_angles.add_restraint(ar23l)
849  if not nter and not cter:
850  # hus2=IMP.core.Harmonic(0,kappa)
851  # idr=IMP.core.DihedralRestraint(hus2,ca,ca_prev,ca_next,cb)
852  # self.rset_angles.add_restraint(idr)
853 
854  hus2upp = IMP.core.HarmonicUpperBound(
855  jitter_improper,
856  kappa)
857  hus2low = IMP.core.HarmonicLowerBound(
858  -
859  jitter_improper,
860  kappa)
862  hus2upp,
863  ca,
864  ca_prev,
865  ca_next,
866  cb)
868  hus2low,
869  ca,
870  ca_prev,
871  ca_next,
872  cb)
873  self.rset_angles.add_restraint(idru)
874  self.rset_angles.add_restraint(idrl)
875  self.rs.add_restraint(self.rset_bonds)
876  self.rs.add_restraint(self.rset_angles)
877 
878  def get_ca_cb(self, atoms):
879  ca = None
880  cb = None
881  for a in atoms:
882  if IMP.atom.Atom(a).get_atom_type() == IMP.atom.AtomType("CA"):
883  ca = a.get_particle()
884  elif IMP.atom.Atom(a).get_atom_type() == IMP.atom.AtomType("CB"):
885  cb = a.get_particle()
886  return ca, cb
887 
888  def set_label(self, label):
889  self.label = label
890  self.rs.set_name(label)
891  for r in self.rs.get_restraints():
892  r.set_name(label)
893 
894  def add_to_model(self):
895  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
896 
897  def get_restraint(self):
898  return self.rs
899 
900  def set_weight(self, weight):
901  self.weight = weight
902  self.rs.set_weight(weight)
903 
904  def get_excluded_pairs(self):
905  return self.pairslist
906 
907  def get_output(self):
908  self.m.update()
909  output = {}
910  score = self.weight * self.rs.unprotected_evaluate(None)
911  output["_TotalScore"] = str(score)
912  output["PseudoAtomicRestraint_" + self.label] = str(score)
913  return output
A filter which returns true if a container containers the Pair.
Add dihedral restraints between quadruplet of consecutive residues/beads to enforce the stereochemist...
CHARMMParameters * get_heavy_atom_CHARMM_parameters()
Lower bound harmonic function (non-zero when feature < mean)
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: Residue.h:155
Enforce CHARMM stereochemistry on the given Hierarchy.
Various classes to hold sets of particles.
Upper bound harmonic function (non-zero when feature > mean)
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Miscellaneous utilities.
Definition: tools.py:1
add harmonic restraints between all pairs
Dihedral restraint between four particles.
The type of an atom.
Return all close unordered pairs of particles taken from the SingletonContainer.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:469
Return all close ordered pairs of particles taken from the two SingletonContainers.
Distance restraint between two particles.
Object used to hold a set of restraints.
Definition: RestraintSet.h:36
def __init__
ca_only: only applies for resolution 0
Store a list of ParticleIndexPairs.
A well with harmonic barriers.
Definition: HarmonicWell.h:25
Angle restraint between three particles.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
add bond restraint between pair of consecutive residues/beads to enforce the stereochemistry.
add bonds and improper dihedral restraints for the CBs
Store a list of ParticleIndexes.
A decorator for a particle representing an atom.
Definition: atom/Atom.h:234
def add_restraint_to_model
Add a PMI restraint to the model.
Definition: tools.py:22
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
add angular restraint between triplets of consecutive residues/beads to enforce the stereochemistry...
Find all nearby pairs by testing all pairs.
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...
all leaves of the input hierarchies will be input in the restraint.
def __init__
need to add: ca-ca bond ca-cb is a constraint, no restraint needed ca-ca-ca cb-ca-ca-cb ...
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the distance between two vectors.
Definition: VectorD.h:209
Applies a PairScore to a Pair.
Definition: PairRestraint.h:29
def select
this function uses representation=SimplifiedModel it returns the corresponding selected particles rep...
Definition: tools.py:662
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
def __init__
jitter: defines the +- added to the optimal distance in the harmonic well restraint used to increase ...
Applies a PairScore to each Pair in a list.
A repulsive potential on the distance between two atoms.
Perform more efficient close pair finding when rigid bodies are involved.
Inferential scoring building on methods developed as part of the Inferential Structure Determination ...
def sublist_iterator
Yield all sublists of length >= lmin and <= lmax.
Definition: tools.py:1055
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:24