IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
restraints/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 IMP.isd
12 import itertools
13 import IMP.pmi.tools
14 from operator import itemgetter
15 from math import pi,log,sqrt
16 import sys
17 
18 
19 
20 class ConnectivityRestraint(object):
21  """ This class creates a restraint between consecutive TempResidue objects OR an entire
22  PMI MOlecule object. """
23 
24  def __init__(self,
25  objects,
26  scale=1.0,
27  disorderedlength=False,
28  upperharmonic=True,
29  resolution=1,
30  label="None"):
31  """
32  @param objects - a list of hierarchies, PMI TempResidues OR a single Molecule
33  @param scale Scale the maximal distance between the beads by this factor when disorderedlength is False.
34  The maximal distance is calculated as ((float(residuegap) + 1.0) * 3.6) * scale.
35  @param disorderedlength - This flag uses either disordered length
36  calculated for random coil peptides (True) or zero
37  surface-to-surface distance between beads (False)
38  as optimal distance for the sequence connectivity
39  restraint.
40  @param upperharmonic - This flag uses either harmonic (False)
41  or upperharmonic (True) in the intra-pair
42  connectivity restraint.
43  @param resolution - The resolution to connect things at - only used if you pass PMI objects
44  @param label - A string to identify this restraint in the output/stat file
45  """
46  self.label = label
47  self.weight = 1.0
48 
49  hiers = IMP.pmi.tools.input_adaptor(objects,resolution)
50  if len(hiers)>1:
51  raise Exception("ConnectivityRestraint: only pass stuff from one Molecule, please")
52  hiers = hiers[0]
53 
54  self.kappa = 10 # spring constant used for the harmonic restraints
55  self.m = list(hiers)[0].get_model()
56  SortedSegments = []
57  self.rs = IMP.RestraintSet(self.m, "connectivity_restraint")
58  for h in hiers:
59  try:
60  start = IMP.atom.Hierarchy(h).get_children()[0]
61  except:
62  start = IMP.atom.Hierarchy(h)
63 
64  try:
65  end = IMP.atom.Hierarchy(h).get_children()[-1]
66  except:
67  end = IMP.atom.Hierarchy(h)
68 
69  startres = IMP.pmi.tools.get_residue_indexes(start)[0]
70  endres = IMP.pmi.tools.get_residue_indexes(end)[-1]
71  SortedSegments.append((start, end, startres))
72  SortedSegments = sorted(SortedSegments, key=itemgetter(2))
73 
74  # connect the particles
75  self.particle_pairs=[]
76  for x in range(len(SortedSegments) - 1):
77 
78  last = SortedSegments[x][1]
79  first = SortedSegments[x + 1][0]
80 
81  apply_restraint = True
82 
83  # Apply connectivity runless ALL of the following are true:
84  # - first and last both have RigidBodyMember decorators
85  # - first and last are both RigidMembers
86  # - first and last are part of the same RigidBody object
87 
88  # Check for both in a rigid body
91 
92  #Check if the rigid body objects for each particle are the same object.
93  # if so, skip connectivity restraint
94  if IMP.core.RigidBodyMember(first).get_rigid_body() == IMP.core.RigidBodyMember(last).get_rigid_body():
95  apply_restraint = False
96 
97  if apply_restraint:
98 
99  nreslast = len(IMP.pmi.tools.get_residue_indexes(last))
100  lastresn = IMP.pmi.tools.get_residue_indexes(last)[-1]
101  nresfirst = len(IMP.pmi.tools.get_residue_indexes(first))
102  firstresn = IMP.pmi.tools.get_residue_indexes(first)[0]
103 
104  residuegap = firstresn - lastresn - 1
105  if disorderedlength and (nreslast / 2 + nresfirst / 2 + residuegap) > 20.0:
106  # calculate the distance between the sphere centers using Kohn
107  # PNAS 2004
108  optdist = sqrt(5 / 3) * 1.93 * \
109  (nreslast / 2 + nresfirst / 2 + residuegap) ** 0.6
110  # optdist2=sqrt(5/3)*1.93*((nreslast)**0.6+(nresfirst)**0.6)/2
111  if upperharmonic:
112  hu = IMP.core.HarmonicUpperBound(optdist, self.kappa)
113  else:
114  hu = IMP.core.Harmonic(optdist, self.kappa)
116  else: # default
117  optdist = (0.0 + (float(residuegap) + 1.0) * 3.6) * scale
118  if upperharmonic: # default
119  hu = IMP.core.HarmonicUpperBound(optdist, self.kappa)
120  else:
121  hu = IMP.core.Harmonic(optdist, self.kappa)
123 
124  pt0 = last.get_particle()
125  pt1 = first.get_particle()
126  self.particle_pairs.append((pt0,pt1))
127  r = IMP.core.PairRestraint(self.m, dps, (pt0.get_index(), pt1.get_index()))
128 
129  print("Adding sequence connectivity restraint between", pt0.get_name(), " and ", pt1.get_name(), 'of distance', optdist)
130  self.rs.add_restraint(r)
131 
132  def set_label(self, label):
133  self.label = label
134 
135  def get_weight(self):
136  return self.weight
137 
138  def add_to_model(self):
139  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
140 
141  def get_restraint(self):
142  return self.rs
143 
144  def set_weight(self, weight):
145  self.weight = weight
146  self.rs.set_weight(weight)
147 
148  def get_output(self):
149  output = {}
150  score = self.weight * self.rs.unprotected_evaluate(None)
151  output["_TotalScore"] = str(score)
152  output["ConnectivityRestraint_" + self.label] = str(score)
153  return output
154 
156  """ Returns number of connectivity restraints """
157  return len(self.rs.get_restraints())
158 
160  """ Returns the list of connected particles pairs """
161  return self.particle_pairs
162 
163  def evaluate(self):
164  return self.weight * self.rs.unprotected_evaluate(None)
165 
166 class ExcludedVolumeSphere(object):
167  """A class to create an excluded volume restraint for a set of particles at a given resolution.
168  Can be initialized as a bipartite restraint between two sets of particles.
169  # Potential additional function: Variable resolution for each PMI object. Perhaps passing selection_tuples
170  with (PMI_object, resolution)
171  """
172 
173  def __init__(self,
174  representation=None,
175  included_objects=None,
176  other_objects=None,
177  resolution=1000,
178  kappa=1.0):
179  """Constructor.
180  @param representation DEPRECATED - just pass objects
181  @param included_objects Can be one of the following inputs:
182  IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set of them
183  @param other_objects Initializes a bipartite restraint between included_objects and other_objects
184  Same format as included_objects
185  @param resolution The resolution particles at which to impose the restraint.
186  By default, the coarsest particles will be chosen.
187  If a number is chosen, for each particle, the closest
188  resolution will be used (see IMP.atom.Selection).
189  @param kappa Restraint strength
190  """
191 
192  self.weight = 1.0
193  self.kappa = kappa
194  self.label = "None"
195  self.cpc = None
196  bipartite = False
197 
198  # gather IMP hierarchies from input objects
199  hierarchies = IMP.pmi.tools.input_adaptor(included_objects,
200  resolution,
201  flatten=True)
202  included_ps = []
203  if other_objects is not None:
204  bipartite = True
205  other_hierarchies = IMP.pmi.tools.input_adaptor(other_objects,
206  resolution,
207  flatten=True)
208  other_ps = []
209 
210 
211  # perform selection
212  if representation is None:
213  if hierarchies is None:
214  raise Exception("Must at least pass included objects")
215  self.mdl = hierarchies[0].get_model()
216  included_ps = [h.get_particle() for h in hierarchies]
217  if bipartite:
218  other_ps = [h.get_particle() for h in other_hierarchies]
219  else:
220  raise Exception("Must pass included_objects")
221 
222  # setup score
223  self.rs = IMP.RestraintSet(self.mdl, 'excluded_volume')
224  ssps = IMP.core.SoftSpherePairScore(self.kappa)
226  lsa.add(IMP.get_indexes(included_ps))
227 
228  # setup close pair container
229  if not bipartite:
231  self.cpc = IMP.container.ClosePairContainer(lsa, 0.0, rbcpf, 10.0)
232  evr = IMP.container.PairsRestraint(ssps, self.cpc)
233  else:
234  other_lsa = IMP.container.ListSingletonContainer(self.mdl)
235  other_lsa.add(IMP.get_indexes(other_ps))
237  lsa,
238  other_lsa,
239  0.0,
240  10.0)
241  evr = IMP.container.PairsRestraint(ssps, self.cpc)
242 
243  self.rs.add_restraint(evr)
244 
245  def add_excluded_particle_pairs(self, excluded_particle_pairs):
246  # add pairs to be filtered when calculating the score
247  inverted=[(p1,p0)for p0,p1 in excluded_particle_pairs]
248  lpc = IMP.container.ListPairContainer(self.mdl)
249  lpc.add(IMP.get_indexes(excluded_particle_pairs))
250  lpc.add(IMP.get_indexes(inverted))
252  self.cpc.add_pair_filter(icpf)
253 
254  def set_label(self, label):
255  self.label = label
256 
257  def add_to_model(self):
258  IMP.pmi.tools.add_restraint_to_model(self.mdl, self.rs)
259 
260  def get_restraint(self):
261  return self.rs
262 
263  def set_weight(self, weight):
264  self.weight = weight
265  self.rs.set_weight(weight)
266 
267  def get_output(self):
268  output = {}
269  score = self.weight * self.rs.unprotected_evaluate(None)
270  output["_TotalScore"] = str(score)
271  output["ExcludedVolumeSphere_" + self.label] = str(score)
272  return output
273 
274  def evaluate(self):
275  return self.weight * self.rs.unprotected_evaluate(None)
276 
277 class HelixRestraint(object):
278  """Enforce ideal Helix dihedrals and bonds for a selection at resolution 0"""
279  def __init__(self,
280  hierarchy,
281  selection_tuple,
282  weight=1.0,
283  label=''):
284  """Constructor
285  @param hierarchy the root node
286  @param selection_tuple (start, stop, molname, copynum=0)
287  @param weight
288  """
289  self.mdl = hierarchy.get_model()
290  self.rs = IMP.RestraintSet(self.mdl)
291  self.weight = weight
292  self.label = label
293  start = selection_tuple[0]
294  stop = selection_tuple[1]
295  mol = selection_tuple[2]
296  copy_index = 0
297  if len(selection_tuple)>3:
298  copy_index = selection_tuple[3]
299 
300  sel = IMP.atom.Selection(hierarchy,molecule=mol,copy_index=copy_index,
301  residue_indexes=range(start,stop+1))
302  ps = sel.get_selected_particles(with_representation=False)
303  res = [IMP.atom.Residue(p) for p in ps]
304  self.rs = IMP.RestraintSet(self.mdl,self.weight)
305  self.r = IMP.atom.HelixRestraint(res)
306  self.rs.add_restraint(self.r)
307  print('Created helix %s.%i.%i-%i with %i dihedrals and %i bonds'%(
308  mol,copy_index,start,stop,
309  self.get_number_of_bonds(),self.get_number_of_dihedrals()))
310  def set_label(self, label):
311  self.label = label
312 
313  def get_weight(self):
314  return self.weight
315 
316  def add_to_model(self):
317  IMP.pmi.tools.add_restraint_to_model(self.mdl, self.rs)
318 
319  def get_restraint(self):
320  return self.rs
321 
322  def set_weight(self, weight):
323  self.weight = weight
324  self.rs.set_weight(weight)
325 
326  def get_number_of_bonds(self):
327  return self.r.get_number_of_bonds()
328 
329  def get_number_of_dihedrals(self):
330  return self.r.get_number_of_dihedrals()
331 
332  def evaluate(self):
333  return self.weight * self.rs.unprotected_evaluate(None)
334 
335  def get_output(self):
336  output = {}
337  score = self.evaluate()
338  output["_TotalScore"] = str(score)
339  output["HelixRestraint_" + self.label] = str(score)
340  return output
341 
342 class ResidueBondRestraint(object):
343  """ Add bond restraint between pair of consecutive
344  residues/beads to enforce the stereochemistry.
345  """
346  def __init__(self,
347  representation=None,
348  selection_tuple=None,
349  objects=None,
350  distance=3.78,
351  strength=10.0,
352  jitter=None):
353  """Constructor
354  @param representation (PMI1)
355  @param selection_tuple Requested selection (PMI1)
356  @param objects (PMI2)
357  @param distance Resting distance for restraint
358  @param strength Bond constant
359  @param jitter Defines the +- added to the optimal distance in the harmonic well restraint
360  used to increase the tolerance
361  """
362 
363  if representation is not None and selection_tuple is not None:
364  self.m = representation.prot.get_model()
365  particles = IMP.pmi.tools.select_by_tuple(
366  representation,
367  selection_tuple,
368  resolution=1)
369 
370  elif objects is not None:
371  particles = IMP.pmi.tools.input_adaptor(objects,1,flatten=True)
372  self.m = particles[0].get_model()
373 
374  self.rs = IMP.RestraintSet(self.m, "Bonds")
375  self.weight = 1
376  self.label = "None"
377  self.pairslist = []
378 
379 
380 
381  if not jitter:
382  ts = IMP.core.Harmonic(distance, strength)
383  else:
385  (distance - jitter, distance + jitter), strength)
386 
387  for ps in IMP.pmi.tools.sublist_iterator(particles, 2, 2):
388  pair = []
389  if len(ps) != 2:
390  raise ValueError("wrong length of pair")
391  for p in ps:
393  raise TypeError("%s is not a residue" % p)
394  else:
395  pair.append(p)
396  print("ResidueBondRestraint: adding a restraint between %s %s" % (pair[0].get_name(), pair[1].get_name()))
397  self.rs.add_restraint(
398  IMP.core.DistanceRestraint(self.m, ts, pair[0], pair[1]))
399  self.pairslist.append(IMP.ParticlePair(pair[0], pair[1]))
400  self.pairslist.append(IMP.ParticlePair(pair[1], pair[0]))
401 
402  def set_label(self, label):
403  self.label = label
404  self.rs.set_name(label)
405  for r in self.rs.get_restraints():
406  r.set_name(label)
407 
408  def add_to_model(self):
409  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
410 
411  def get_restraint(self):
412  return self.rs
413 
414  def set_weight(self, weight):
415  self.weight = weight
416  self.rs.set_weight(weight)
417 
418  def get_excluded_pairs(self):
419  return self.pairslist
420 
421  def get_output(self):
422  output = {}
423  score = self.weight * self.rs.unprotected_evaluate(None)
424  output["_TotalScore"] = str(score)
425  output["ResidueBondRestraint_" + self.label] = str(score)
426  return output
427 
428 
429 class ResidueAngleRestraint(object):
430  """Add angular restraint between triplets of consecutive
431  residues/beads to enforce the stereochemistry.
432  """
433  def __init__(self,
434  representation=None,
435  selection_tuple=None,
436  objects=None,
437  anglemin=100.0,
438  anglemax=140.0,
439  strength=10.0):
440 
441  if representation is not None and selection_tuple is not None:
442  self.m = representation.prot.get_model()
443  particles = IMP.pmi.tools.select_by_tuple(
444  representation,
445  selection_tuple,
446  resolution=1)
447 
448  elif objects is not None:
449  particles = IMP.pmi.tools.input_adaptor(objects,1,flatten=True)
450  self.m = particles[0].get_model()
451 
452  self.rs = IMP.RestraintSet(self.m, "Angles")
453  self.weight = 1
454  self.label = "None"
455  self.pairslist = []
456 
458  (pi * anglemin / 180.0,
459  pi * anglemax / 180.0),
460  strength)
461 
462  for ps in IMP.pmi.tools.sublist_iterator(particles, 3, 3):
463  triplet = []
464  if len(ps) != 3:
465  raise ValueError("wrong length of triplet")
466  for p in ps:
468  raise TypeError("%s is not a residue" % p)
469  else:
470  triplet.append(p)
471  print("ResidueAngleRestraint: adding a restraint between %s %s %s" % (triplet[0].get_name(), triplet[1].get_name(), triplet[2].get_name()))
472  self.rs.add_restraint(
473  IMP.core.AngleRestraint(triplet[0].get_model(), ts,
474  triplet[0],
475  triplet[1],
476  triplet[2]))
477  self.pairslist.append(IMP.ParticlePair(triplet[0], triplet[2]))
478  self.pairslist.append(IMP.ParticlePair(triplet[2], triplet[0]))
479 
480  def set_label(self, label):
481  self.label = label
482  self.rs.set_name(label)
483  for r in self.rs.get_restraints():
484  r.set_name(label)
485 
486  def add_to_model(self):
487  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
488 
489  def get_restraint(self):
490  return self.rs
491 
492  def set_weight(self, weight):
493  self.weight = weight
494  self.rs.set_weight(weight)
495 
496  def get_excluded_pairs(self):
497  return self.pairslist
498 
499  def get_output(self):
500  output = {}
501  score = self.weight * self.rs.unprotected_evaluate(None)
502  output["_TotalScore"] = str(score)
503  output["ResidueAngleRestraint_" + self.label] = str(score)
504  return output
505 
506 
508  """Add dihedral restraints between quadruplet of consecutive
509  residues/beads to enforce the stereochemistry.
510  Give as input a string of "C" and "T", meaning cys (0+-40) or trans (180+-40)
511  dihedral. The length of the string must be \#residue-3.
512  Without the string, the dihedral will be assumed trans.
513  """
514  def __init__(
515  self,
516  representation=None,
517  selection_tuple=None,
518  objects=None,
519  stringsequence=None,
520  strength=10.0):
521 
522  if representation is not None and selection_tuple is not None:
523  self.m = representation.prot.get_model()
524  particles = IMP.pmi.tools.select_by_tuple(
525  representation,
526  selection_tuple,
527  resolution=1)
528 
529  elif objects is not None:
530  particles = IMP.pmi.tools.input_adaptor(objects,1,flatten=True)
531  self.m = particles[0].get_model()
532 
533  self.rs = IMP.RestraintSet(self.m, "Angles")
534  self.weight = 1
535  self.label = "None"
536  self.pairslist = []
537 
538  if stringsequence is None:
539  stringsequence = "T" * (len(particles) - 3)
540 
541  for n, ps in enumerate(IMP.pmi.tools.sublist_iterator(particles, 4, 4)):
542  quadruplet = []
543  if len(ps) != 4:
544  raise ValueError("wrong length of quadruplet")
545  for p in ps:
547  raise TypeError("%s is not a residue" % p)
548  else:
549  quadruplet.append(p)
550  dihedraltype = stringsequence[n]
551  if dihedraltype == "C":
552  anglemin = -20.0
553  anglemax = 20.0
555  (pi * anglemin / 180.0,
556  pi * anglemax / 180.0),
557  strength)
558  print("ResidueDihedralRestraint: adding a CYS restraint between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(),
559  quadruplet[2].get_name(), quadruplet[3].get_name()))
560  if dihedraltype == "T":
561  anglemin = 180 - 70.0
562  anglemax = 180 + 70.0
564  (pi * anglemin / 180.0,
565  pi * anglemax / 180.0),
566  strength)
567  print("ResidueDihedralRestraint: adding a TRANS restraint between %s %s %s %s" % (quadruplet[0].get_name(), quadruplet[1].get_name(),
568  quadruplet[2].get_name(), quadruplet[3].get_name()))
569  self.rs.add_restraint(
570  IMP.core.DihedralRestraint(self.m,ts,
571  quadruplet[0],
572  quadruplet[1],
573  quadruplet[2],
574  quadruplet[3]))
575  self.pairslist.append(
576  IMP.ParticlePair(quadruplet[0], quadruplet[3]))
577  self.pairslist.append(
578  IMP.ParticlePair(quadruplet[3], quadruplet[0]))
579 
580  def set_label(self, label):
581  self.label = label
582  self.rs.set_name(label)
583  for r in self.rs.get_restraints():
584  r.set_name(label)
585 
586  def add_to_model(self):
587  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
588 
589  def get_restraint(self):
590  return self.rs
591 
592  def set_weight(self, weight):
593  self.weight = weight
594  self.rs.set_weight(weight)
595 
596  def get_excluded_pairs(self):
597  return self.pairslist
598 
599  def get_output(self):
600  output = {}
601  score = self.weight * self.rs.unprotected_evaluate(None)
602  output["_TotalScore"] = str(score)
603  output["ResidueDihedralRestraint_" + self.label] = str(score)
604  return output
605 
606 class SecondaryStructure(object):
607  """Experimental, requires isd_emxl for now"""
608  def __init__(self,
609  representation,
610  selection_tuple,
611  ssstring,
612  mixture=False,
613  nativeness=1.0,
614  kt_caff=0.1):
615 
616  if no_isd_emxl:
617  raise ValueError("IMP.isd_emxl is needed")
618 
619  # check that the secondary structure string
620  # is compatible with the ssstring
621 
622  self.particles = IMP.pmi.tools.select_by_tuple(
623  representation,
624  selection_tuple,
625  resolution=1)
626  self.m = representation.prot.get_model()
627  self.dihe_dict = {}
628  self.ang_dict = {}
629  self.do_mix = {}
630  self.anglfilename = IMP.isd_emxl.get_data_path("CAAngleRestraint.dat")
631  self.dihefilename = IMP.isd_emxl.get_data_path(
632  "CADihedralRestraint.dat")
633  self.nativeness = nativeness
634  self.kt_caff = kt_caff
635  self.anglrs = IMP.RestraintSet(self.m, "Angles")
636  self.dihers = IMP.RestraintSet(self.m, "Dihedrals")
637  self.bondrs = IMP.RestraintSet(self.m, "Bonds")
638  self.label = "None"
639 
640  if len(self.particles) != len(ssstring):
641  print(len(self.particles), len(ssstring))
642  print("SecondaryStructure: residue range and SS string incompatible")
643  self.ssstring = ssstring
644 
645  (bondrslist, anglrslist, diherslist,
646  pairslist) = self.get_CA_force_field()
647  self.pairslist = pairslist
648 
649  # print anglrslist, diherslist, bondrslist, self.particles
650  self.anglrs.add_restraints(anglrslist)
651  self.dihers.add_restraints(diherslist)
652  self.bondrs.add_restraints(bondrslist)
653 
654  def set_label(self, label):
655  self.label = label
656 
657  def add_to_model(self):
658  IMP.pmi.tools.add_restraint_to_model(self.m, self.anglrs)
659  IMP.pmi.tools.add_restraint_to_model(self.m, self.dihers)
660  IMP.pmi.tools.add_restraint_to_model(self.m, self.bondrs)
661 
662  def get_CA_force_field(self):
663  bondrslist = []
664  anglrslist = []
665  diherslist = []
666  pairslist = []
667  # add bonds
668  for res in range(0, len(self.particles) - 1):
669 
670  ps = self.particles[res:res + 2]
671  pairslist.append(IMP.ParticlePair(ps[0], ps[1]))
672  pairslist.append(IMP.ParticlePair(ps[1], ps[0]))
673  br = self.get_distance_restraint(ps[0], ps[1], 3.78, 416.0)
674  br.set_name('Bond_restraint')
675  bondrslist.append(br)
676  # add dihedrals
677  for res in range(0, len(self.particles) - 4):
678 
679  # if res not in dihe_dict: continue
680  # get the appropriate parameters
681  # get the particles
682  ps = self.particles[res:res + 5]
683  [phi0,
684  phi1,
685  score_dih] = self.read_potential_dihedral(
686  self.ssstring[res:res + 4],
687  True)
688  pairslist.append(IMP.ParticlePair(ps[0], ps[3]))
689  pairslist.append(IMP.ParticlePair(ps[3], ps[0]))
690  pairslist.append(IMP.ParticlePair(ps[1], ps[4]))
691  pairslist.append(IMP.ParticlePair(ps[4], ps[1]))
692  dr = IMP.isd_emxl.CADihedralRestraint(
693  ps[0],
694  ps[1],
695  ps[2],
696  ps[3],
697  ps[4],
698  phi0,
699  phi1,
700  score_dih)
701  dr.set_name('Dihedral restraint')
702  diherslist.append(dr)
703  # add angles
704  for res in range(0, len(self.particles) - 2):
705  ps = self.particles[res:res + 3]
706  [psi, score_ang] = self.read_potential_angle(
707  self.ssstring[res:res + 2], True)
708  pairslist.append(IMP.ParticlePair(ps[0], ps[2]))
709  pairslist.append(IMP.ParticlePair(ps[2], ps[0]))
710  dr = IMP.isd_emxl.CAAngleRestraint(
711  ps[0],
712  ps[1],
713  ps[2],
714  psi,
715  score_ang)
716  dr.set_name('Angle restraint')
717  anglrslist.append(dr)
718  return (bondrslist, anglrslist, diherslist, pairslist)
719 
720  def read_potential_dihedral(self, string, mix=False):
721  # read potentials for dihedral
722  score_dih = []
723  phi0 = []
724  phi1 = []
725  for i in range(0, 36):
726  phi0.append(i * 10.0 / 180.0 * pi)
727  phi1.append(i * 10.0 / 180.0 * pi)
728  for j in range(0, 36):
729  score_dih.append(0.0)
730  # open file
731  if not mix:
732  f = open(self.dihefilename, 'r')
733  for line in f.readlines():
734  riga = (line.strip()).split()
735  if (len(riga) == 4 and riga[0] == string):
736  ii = int(float(riga[1]) / 10.0)
737  jj = int(float(riga[2]) / 10.0)
738  score_dih[ii * len(phi0) + jj] = - \
739  self.kt_caff * self.log(float(riga[3]))
740  f.close()
741  if mix:
742  # mix random coil and native secondary structure
743  counts = []
744  for i in range(0, 36):
745  for j in range(0, 36):
746  counts.append(1.0)
747  f = open(self.dihefilename, 'r')
748  for line in f.readlines():
749  riga = (line.strip()).split()
750  if (len(riga) == 4 and riga[0] == string):
751  ii = int(float(riga[1]) / 10.0)
752  jj = int(float(riga[2]) / 10.0)
753  counts[ii * len(phi0) + jj] += self.nativeness * \
754  float(riga[3])
755  if (len(riga) == 4 and riga[0] == "-----"):
756  ii = int(float(riga[1]) / 10.0)
757  jj = int(float(riga[2]) / 10.0)
758  counts[ii * len(phi0) + jj] += (1.0 - self.nativeness) * \
759  float(riga[3])
760  f.close()
761  for i in range(len(counts)):
762  score_dih[i] = -self.kt_caff * self.log(counts[i])
763  return [phi0, phi1, score_dih]
764 
765  def read_potential_angle(self, string, mix=False):
766  # read potentials for angles
767  score_ang = []
768  psi = []
769  for i in range(0, 180):
770  psi.append(i / 180.0 * pi)
771  score_ang.append(0.0)
772  # read file
773  if not mix:
774  f = open(self.anglfilename, 'r')
775  for line in f.readlines():
776  riga = (line.strip()).split()
777  if (len(riga) == 3 and riga[0] == string):
778  ii = int(riga[1])
779  score_ang[ii] = -self.kt_caff * self.log(float(riga[2]))
780  f.close()
781  if mix:
782  # mix random coil and native secondary structure
783  counts = []
784  for i in range(0, 180):
785  counts.append(1.0)
786 
787  f = open(self.anglfilename, 'r')
788  for line in f.readlines():
789  riga = (line.strip()).split()
790  if (len(riga) == 3 and riga[0] == string):
791  ii = int(riga[1])
792  counts[ii] += self.nativeness * float(riga[2])
793  if (len(riga) == 3 and riga[0] == "---"):
794  ii = int(riga[1])
795  counts[ii] += (1.0 - self.nativeness) * float(riga[2])
796  f.close()
797  for i in range(0, 180):
798  score_ang[i] = -self.kt_caff * self.log(counts[i])
799  return [psi, score_ang]
800 
801  def get_excluded_pairs(self):
802  return self.pairslist
803 
804  def get_restraint(self):
805  tmprs = IMP.RestraintSet(self.m, 'tmp')
806  tmprs.add_restraint(self.anglrs)
807  tmprs.add_restraint(self.dihers)
808  tmprs.add_restraint(self.bondrs)
809  return tmprs
810 
811  def get_distance_restraint(self, p0, p1, d0, kappa):
812  h = IMP.core.Harmonic(d0, kappa)
814  pr = IMP.core.PairRestraint(self.m, dps, IMP.ParticlePair(p0, p1))
815  return pr
816 
817  def get_output(self):
818  output = {}
819  score_angle = self.anglrs.unprotected_evaluate(None)
820  score_dihers = self.dihers.unprotected_evaluate(None)
821  score_bondrs = self.bondrs.unprotected_evaluate(None)
822  output["_TotalScore"] = str(score_angle + score_dihers + score_bondrs)
823 
824  output["SecondaryStructure_Angles_" + self.label] = str(score_angle)
825  output["SecondaryStructure_Dihedrals_" +
826  self.label] = str(score_dihers)
827  output["SecondaryStructure_Bonds_" + self.label] = str(score_bondrs)
828  return output
829 
830 
832  """Add harmonic restraints between all pairs
833  """
834  def __init__(self,representation=None,
835  selection_tuples=None,
836  resolution=1,
837  strength=0.01,
838  dist_cutoff=10.0,
839  ca_only=True,
840  hierarchy=None):
841  """Constructor
842  @param representation Representation object
843  @param selection_tuples Selecting regions for the restraint [[start,stop,molname,copy_index=0],...]
844  @param resolution Resolution for applying restraint
845  @param strength Bond strength
846  @param dist_cutoff Cutoff for making restraints
847  @param ca_only Selects only CAlphas. Only matters if resolution=0.
848  @param hierarchy Root hierarchy to select from, use this instead of representation
849  """
850 
851  particles = []
852  if representation is None and hierarchy is not None:
853  self.m = hierarchy.get_model()
854  for st in selection_tuples:
855  copy_index=0
856  if len(st)>3:
857  copy_index=st[3]
858  if not ca_only:
859  sel = IMP.atom.Selection(hierarchy,molecule=st[2],residue_indexes=range(st[0],st[1]+1),
860  copy_index=copy_index)
861  else:
862  sel = IMP.atom.Selection(hierarchy,molecule=st[2],residue_indexes=range(st[0],st[1]+1),
863  copy_index=copy_index,
864  atom_type=IMP.atom.AtomType("CA"))
865  particles+=sel.get_selected_particles()
866  else:
867  raise Exception("must pass hierarchy")
868 
869  self.weight = 1
870  self.label = "None"
871  self.pairslist = []
872 
873  # create score
874  self.rs = IMP.pmi.create_elastic_network(particles,dist_cutoff,strength)
875  for r in self.rs.get_restraints():
876  a1,a2 = r.get_inputs()
877  self.pairslist.append(IMP.ParticlePair(a1,a2))
878  self.pairslist.append(IMP.ParticlePair(a2,a1))
879  print('ElasticNetwork: created',self.rs.get_number_of_restraints(),'restraints')
880 
881  def set_label(self, label):
882  self.label = label
883  self.rs.set_name(label)
884  for r in self.rs.get_restraints():
885  r.set_name(label)
886 
887  def add_to_model(self):
888  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
889 
890  def get_restraint(self):
891  return self.rs
892 
893  def set_weight(self, weight):
894  self.weight = weight
895  self.rs.set_weight(weight)
896 
897  def get_excluded_pairs(self):
898  return self.pairslist
899 
900  def get_output(self):
901  output = {}
902  score = self.weight * self.rs.unprotected_evaluate(None)
903  output["_TotalScore"] = str(score)
904  output["ElasticNetworkRestraint_" + self.label] = str(score)
905  return output
906 
907 
909  """ Enable CHARMM force field """
910  def __init__(self,
911  root=None,
912  ff_temp=300.0,
913  zone_ps=None,
914  zone_size=10.0,
915  enable_nonbonded=True,
916  enable_bonded=True,
917  zone_nonbonded=False,
918  representation=None):
919  """Setup the CHARMM restraint on a selection. Expecting atoms.
920  @param root The node at which to apply the restraint
921  @param ff_temp The temperature of the force field
922  @param zone_ps Create a zone around this set of particles
923  Automatically includes the entire residue (incl. backbone)
924  @param zone_size The size for looking for neighbor residues
925  @param enable_nonbonded Allow the repulsive restraint
926  @param enable_bonded Allow the bonded restraint
927  @param zone_nonbonded EXPERIMENTAL: exclude from nonbonded all sidechains that aren't in zone!
928  @param representation Legacy representation object
929  """
930 
931  kB = (1.381 * 6.02214) / 4184.0
932  if representation is not None:
933  root = representation.prot
934 
935  self.mdl = root.get_model()
936  self.bonds_rs = IMP.RestraintSet(self.mdl, 1.0 / (kB * ff_temp), 'BONDED')
937  self.nonbonded_rs = IMP.RestraintSet(self.mdl, 1.0 / (kB * ff_temp), 'NONBONDED')
938  self.weight = 1.0
939  self.label = ""
940 
941  ### setup topology and bonds etc
942  if enable_bonded:
944  topology = ff.create_topology(root)
945  topology.apply_default_patches()
946  topology.setup_hierarchy(root)
947  if zone_ps is not None:
948  limit_to_ps=IMP.pmi.topology.get_particles_within_zone(
949  root,
950  zone_ps,
951  zone_size,
952  entire_residues=True,
953  exclude_backbone=False)
955  topology,
956  limit_to_ps)
957  self.ps = limit_to_ps
958  else:
959  r = IMP.atom.CHARMMStereochemistryRestraint(root, topology)
960  self.ps = IMP.core.get_leaves(root)
961  print('init bonds score',r.unprotected_evaluate(None))
962  self.bonds_rs.add_restraint(r)
963  ff.add_radii(root)
964  ff.add_well_depths(root)
965 
966  atoms = IMP.atom.get_by_type(root,IMP.atom.ATOM_TYPE)
967  ### non-bonded forces
968  if enable_nonbonded:
969  if (zone_ps is not None) and zone_nonbonded:
970  print('stereochemistry: zone_nonbonded is True')
971  # atoms list should only include backbone plus zone_ps!
972  backbone_types=['C','N','CB','O']
973  sel = IMP.atom.Selection(root,atom_types=[IMP.atom.AtomType(n)
974  for n in backbone_types])
975  backbone_atoms = sel.get_selected_particles()
976  #x = list(set(backbone_atoms)|set(limit_to_ps))
977  sel_ps=IMP.pmi.topology.get_particles_within_zone(
978  root,
979  zone_ps,
980  zone_size,
981  entire_residues=True,
982  exclude_backbone=True)
983 
985  IMP.container.ListSingletonContainer(backbone_atoms),
987  4.0)
988  else:
989  cont = IMP.container.ListSingletonContainer(self.mdl,atoms)
990  self.nbl = IMP.container.ClosePairContainer(cont, 4.0)
991  if enable_bonded:
992  self.nbl.add_pair_filter(r.get_full_pair_filter())
993  pairscore = IMP.isd.RepulsiveDistancePairScore(0,1)
994  pr=IMP.container.PairsRestraint(pairscore, self.nbl)
995  self.nonbonded_rs.add_restraint(pr)
996  print('CHARMM is set up')
997 
998  def set_label(self, label):
999  self.label = label
1000  self.rs.set_name(label)
1001  for r in self.rs.get_restraints():
1002  r.set_name(label)
1003 
1004  def add_to_model(self):
1005  IMP.pmi.tools.add_restraint_to_model(self.mdl, self.bonds_rs)
1006  IMP.pmi.tools.add_restraint_to_model(self.mdl, self.nonbonded_rs)
1007 
1008  def get_restraint(self):
1009  return self.rs
1010 
1011  def get_close_pair_container(self):
1012  return self.nbl
1013 
1014  def set_weight(self, weight):
1015  self.weight = weight
1016  self.rs.set_weight(weight)
1017 
1018  def get_output(self):
1019  output = {}
1020  bonds_score = self.weight * self.bonds_rs.unprotected_evaluate(None)
1021  nonbonded_score = self.weight * self.nonbonded_rs.unprotected_evaluate(None)
1022  score=bonds_score+nonbonded_score
1023  output["_TotalScore"] = str(score)
1024  output["CHARMM_BONDS"] = str(bonds_score)
1025  output["CHARMM_NONBONDED"] = str(nonbonded_score)
1026  return output
1027 
1028 
1030  """Add bonds and improper dihedral restraints for the CBs
1031  """
1032  def __init__(
1033  self, rnums, representation, selection_tuple, strength=10.0, kappa=1.0,
1034  jitter_angle=0.0, jitter_improper=0.0):
1035  '''
1036  need to add:
1037  ca-ca bond
1038  ca-cb is a constraint, no restraint needed
1039  ca-ca-ca
1040  cb-ca-ca-cb
1041  '''
1042 
1043  self.m = representation.prot.get_model()
1044  self.rs = IMP.RestraintSet(self.m, "PseudoAtomic")
1045  self.rset_angles = IMP.RestraintSet(self.m, "PseudoAtomic_Angles")
1046  self.rset_bonds = IMP.RestraintSet(self.m, "PseudoAtomic_Bonds")
1047  self.weight = 1
1048  self.label = "None"
1049  self.pairslist = []
1050 
1051  # residues=IMP.pmi.tools.select_by_tuple(representation,selection_tuple,resolution=1)
1052  for rnum in rnums:
1053  ca, cb = self.get_ca_cb(
1054  IMP.pmi.tools.select_by_tuple(representation,
1055  (rnum, rnum, 'chainA'), resolution=0))
1056  if not cb is None:
1057  nter = False
1058  cter = False
1059  ca_prev, cb_prev = self.get_ca_cb(
1060  IMP.pmi.tools.select_by_tuple(representation,
1061  (rnum - 1, rnum - 1, 'chainA'), resolution=0))
1062  ca_next, cb_next = self.get_ca_cb(
1063  IMP.pmi.tools.select_by_tuple(representation,
1064  (rnum + 1, rnum + 1, 'chainA'), resolution=0))
1065  if ca_prev is None:
1066  nter = True
1067  else:
1068  if ca_next is None:
1069  cter = True
1070  else:
1071  if (nter and cter):
1072  continue
1073 
1074  # adding a bond restraint between CA and CB
1075  # h=IMP.core.Harmonic(6.0,kappa)
1076  # dps=IMP.core.DistancePairScore(h)
1077  # pr=IMP.core.PairRestraint(dps,IMP.ParticlePair(ca,cb))
1078  # self.pairslist.append((ca,cb))
1079  # self.rset_bonds.add_restraint(pr)
1080 
1081  # creating improper dihedral restraint
1082  # hus=IMP.core.Harmonic(2.09,kappa)
1084  2.09 +
1085  jitter_angle /
1086  0.5,
1087  kappa)
1089  2.09 -
1090  jitter_angle /
1091  0.5,
1092  kappa)
1093  if not nter:
1094  # ar13=IMP.core.AngleRestraint(hus,ca_prev,ca,cb)
1095  # self.rset_angles.add_restraint(ar13)
1096  ar13u = IMP.core.AngleRestraint(hupp, ca_prev, ca, cb)
1097  ar13l = IMP.core.AngleRestraint(hlow, ca_prev, ca, cb)
1098  self.rset_angles.add_restraint(ar13u)
1099  self.rset_angles.add_restraint(ar13l)
1100  if not cter:
1101  # ar23=IMP.core.AngleRestraint(hus,ca_next,ca,cb)
1102  # self.rset_angles.add_restraint(ar23)
1103  ar23u = IMP.core.AngleRestraint(hupp, ca_next, ca, cb)
1104  ar23l = IMP.core.AngleRestraint(hlow, ca_next, ca, cb)
1105  self.rset_angles.add_restraint(ar23u)
1106  self.rset_angles.add_restraint(ar23l)
1107  if not nter and not cter:
1108  # hus2=IMP.core.Harmonic(0,kappa)
1109  # idr=IMP.core.DihedralRestraint(hus2,ca,ca_prev,ca_next,cb)
1110  # self.rset_angles.add_restraint(idr)
1111 
1112  hus2upp = IMP.core.HarmonicUpperBound(
1113  jitter_improper,
1114  kappa)
1115  hus2low = IMP.core.HarmonicLowerBound(
1116  -
1117  jitter_improper,
1118  kappa)
1120  hus2upp,
1121  ca,
1122  ca_prev,
1123  ca_next,
1124  cb)
1126  hus2low,
1127  ca,
1128  ca_prev,
1129  ca_next,
1130  cb)
1131  self.rset_angles.add_restraint(idru)
1132  self.rset_angles.add_restraint(idrl)
1133  self.rs.add_restraint(self.rset_bonds)
1134  self.rs.add_restraint(self.rset_angles)
1135 
1136  def get_ca_cb(self, atoms):
1137  ca = None
1138  cb = None
1139  for a in atoms:
1140  if IMP.atom.Atom(a).get_atom_type() == IMP.atom.AtomType("CA"):
1141  ca = a.get_particle()
1142  elif IMP.atom.Atom(a).get_atom_type() == IMP.atom.AtomType("CB"):
1143  cb = a.get_particle()
1144  return ca, cb
1145 
1146  def set_label(self, label):
1147  self.label = label
1148  self.rs.set_name(label)
1149  for r in self.rs.get_restraints():
1150  r.set_name(label)
1151 
1152  def add_to_model(self):
1153  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
1154 
1155  def get_restraint(self):
1156  return self.rs
1157 
1158  def set_weight(self, weight):
1159  self.weight = weight
1160  self.rs.set_weight(weight)
1161 
1162  def get_excluded_pairs(self):
1163  return self.pairslist
1164 
1165  def get_output(self):
1166  output = {}
1167  score = self.weight * self.rs.unprotected_evaluate(None)
1168  output["_TotalScore"] = str(score)
1169  output["PseudoAtomicRestraint_" + self.label] = str(score)
1170  return output
1171 
1172 class SymmetryRestraint(object):
1173  """Create harmonic restraints between the reference and (transformed) clones.
1174  @note Wraps IMP::core::TransformedDistancePairScore with an IMP::core::Harmonic
1175  """
1176  def __init__(self,
1177  references,
1178  clones_list,
1179  transforms,
1180  label='',
1181  strength=10.0,
1182  ca_only=False):
1183  """Constructor
1184  @param references Can be one of the following inputs:
1185  IMP Hierarchy, PMI System/State/Molecule/TempResidue, or a list/set of them
1186  @param clones_list List of lists of the above
1187  @param transforms Transforms moving each selection to the first selection
1188  @param label Label for output
1189  @param strength The elastic bond strength
1190  @param ca_only Optionally select so only CAlpha particles are used
1191  """
1192 
1193  refs = IMP.pmi.tools.input_adaptor(references,flatten=True)
1194  self.mdl = refs[0].get_model()
1195  self.rs = IMP.RestraintSet(self.mdl, "Symmetry")
1196  self.weight = 1
1197  self.label = label
1198  if len(clones_list)!=len(transforms):
1199  raise Exception('Error: There should be as many clones as transforms')
1200 
1201  harmonic = IMP.core.Harmonic(0.,strength)
1202  for tmp_clones,trans in zip(clones_list,transforms):
1203  clones = IMP.pmi.tools.input_adaptor(tmp_clones,flatten=True)
1204  if len(clones)!=len(refs):
1205  raise Exception("Error: len(references)!=len(clones)")
1206  pair_score = IMP.core.TransformedDistancePairScore(harmonic,trans)
1207  for p0,p1 in zip(refs,clones):
1208  if not ca_only or (IMP.atom.Atom(p0).get_atom_type()==IMP.atom.AtomType("CA")
1209  and IMP.atom.Atom(p1).get_atom_type()==IMP.atom.AtomType("CA")):
1210  r = IMP.core.PairRestraint(self.mdl, pair_score, [p0.get_particle_index(),
1211  p1.get_particle_index()])
1212  self.rs.add_restraint(r)
1213  print('created symmetry network with',self.rs.get_number_of_restraints(),'restraints')
1214 
1215  def set_label(self, label):
1216  self.label = label
1217  self.rs.set_name(label)
1218  for r in self.rs.get_restraints():
1219  r.set_name(label)
1220 
1221  def add_to_model(self):
1222  IMP.pmi.tools.add_restraint_to_model(self.mdl, self.rs)
1223 
1224  def get_restraint(self):
1225  return self.rs
1226 
1227  def set_weight(self, weight):
1228  self.weight = weight
1229  self.rs.set_weight(weight)
1230 
1231  def get_excluded_pairs(self):
1232  return self.pairslist
1233 
1234  def get_output(self):
1235  output = {}
1236  score = self.weight * self.rs.unprotected_evaluate(None)
1237  output["SymmetryRestraint_" + self.label] = str(score)
1238  output["_TotalScore"] = str(score)
1239  return output
1240 
1241 
1242 class FusionRestraint(object):
1243  """ This class creates a restraint between the termini two polypeptides, to simulate the sequence connectivity. """
1244  def __init__(self,
1245  nterminal,
1246  cterminal,
1247  scale=1.0,
1248  disorderedlength=False,
1249  upperharmonic=True,
1250  resolution=1,
1251  label="None"):
1252  """
1253  @param nterminal - single PMI2 Hierarchy/molecule at the nterminal
1254  @param cterminal - single PMI2 Hierarchy/molecule at the cterminal
1255  @param scale Scale the maximal distance between the beads by this factor when disorderedlength is False.
1256  The maximal distance is calculated as ((float(residuegap) + 1.0) * 3.6) * scale.
1257  @param disorderedlength - This flag uses either disordered length
1258  calculated for random coil peptides (True) or zero
1259  surface-to-surface distance between beads (False)
1260  as optimal distance for the sequence connectivity
1261  restraint.
1262  @param upperharmonic - This flag uses either harmonic (False)
1263  or upperharmonic (True) in the intra-pair
1264  connectivity restraint.
1265  @param resolution - The resolution to connect things at - only used if you pass PMI objects
1266  @param label - A string to identify this restraint in the output/stat file
1267  """
1268  self.label = label
1269  self.weight = 1.0
1270  ssn=IMP.pmi.tools.get_sorted_segments(nterminal)
1271  ssc=IMP.pmi.tools.get_sorted_segments(cterminal)
1272  nter_lastres=ssn[-1][1]
1273  cter_firstres=ssc[0][0]
1274  self.m = nter_lastres.get_model()
1275 
1276  self.kappa = 10 # spring constant used for the harmonic restraints
1277 
1278  optdist = (3.6) * scale
1279  if upperharmonic: # default
1280  hu = IMP.core.HarmonicUpperBound(optdist, self.kappa)
1281  else:
1282  hu = IMP.core.Harmonic(optdist, self.kappa)
1284 
1285  pt0 = nter_lastres.get_particle()
1286  pt1 = cter_firstres.get_particle()
1287  r = IMP.core.PairRestraint(self.m, dps, (pt0.get_index(), pt1.get_index()))
1288  self.rs = IMP.RestraintSet(self.m, "fusion_restraint")
1289  print("Adding fusion connectivity restraint between", pt0.get_name(), " and ", pt1.get_name(), 'of distance', optdist)
1290  self.rs.add_restraint(r)
1291 
1292  def set_label(self, label):
1293  self.label = label
1294 
1295  def get_weight(self):
1296  return self.weight
1297 
1298  def add_to_model(self):
1299  IMP.pmi.tools.add_restraint_to_model(self.m, self.rs)
1300 
1301  def get_restraint(self):
1302  return self.rs
1303 
1304  def set_weight(self, weight):
1305  self.weight = weight
1306  self.rs.set_weight(weight)
1307 
1308  def get_output(self):
1309  output = {}
1310  score = self.weight * self.rs.unprotected_evaluate(None)
1311  output["_TotalScore"] = str(score)
1312  output["FusionRestraint_" + self.label] = str(score)
1313  return output
1314 
1315  def evaluate(self):
1316  return self.weight * self.rs.unprotected_evaluate(None)
1317 
1318 
1319 
1320 
1322 
1323  """Restrain the dihedral between planes defined by three particles.
1324 
1325  This restraint is useful for restraining the twist of a string of
1326  more or less identical rigid bodies, so long as the curvature is mild.
1327  """
1328 
1329  def __init__(self, particle_triplets, angle=0., k=1., label=None,
1330  weight=1.):
1331  """Constructor
1332  @param particle_triplets List of lists of 3 particles. Each triplet
1333  defines a plane. Dihedrals of adjacent planes
1334  in list are scored.
1335  @param angle Angle of plane dihedral in degrees
1336  @param k Strength of restraint
1337  @param label Label for output
1338  @param weight Weight of restraint
1339  @note Particles defining planes should be rigid and more or less
1340  parallel for proper behavior
1341  """
1342  model = particle_triplets[0][0].get_model()
1343  super(PlaneDihedralRestraint, self).__init__(model, label=label,
1344  weight=weight)
1345 
1346  angle = pi * angle / 180.
1347  ds = IMP.core.Cosine(.5 * k, 1., -angle)
1348  for i, t1 in enumerate(particle_triplets[:-1]):
1349  t2 = particle_triplets[i + 1]
1350  q1 = [t1[1], t1[0], t2[0], t2[1]]
1351  q2 = [t1[2], t1[0], t2[0], t2[2]]
1352  self.rs.add_restraint(
1353  IMP.core.DihedralRestraint(self.model, ds, *q1))
1354  self.rs.add_restraint(
1355  IMP.core.DihedralRestraint(self.model, ds, *q2))
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:156
Enforce CHARMM stereochemistry on the given Hierarchy.
A member of a rigid body, it has internal (local) coordinates.
Definition: rigid_bodies.h:616
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:617
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
Enforce ideal Helix dihedrals and bonds for a selection at resolution 0.
Miscellaneous utilities.
Definition: tools.py:1
Cosine function.
Definition: Cosine.h:22
This class creates a restraint between the termini two polypeptides, to simulate the sequence connect...
Apply a function to the distance between two particles after transforming the second.
Restrain the dihedral between planes defined by three particles.
Dihedral restraint between four particles.
The type of an atom.
A score on the distance between the surfaces of two spheres.
Return all close unordered pairs of particles taken from the SingletonContainer.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Definition: rigid_bodies.h:731
Return all spatially-proximals pairs of particles (a,b) from the two SingletonContainers A and B...
GenericHierarchies get_leaves(Hierarchy mhd)
Get all the leaves of the bit of hierarchy.
Distance restraint between two particles.
Object used to hold a set of restraints.
Definition: RestraintSet.h:36
def input_adaptor
Adapt things for PMI (degrees of freedom, restraints, ...) Returns list of list of hierarchies...
Definition: tools.py:918
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.
The standard decorator for manipulating molecular structures.
RestraintSet * create_elastic_network(const Particles &ps, Float dist_cutoff, Float strength)
Create an elastic network restraint set.
Definition: pmi/utilities.h:26
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 get_particle_pairs
Returns the list of connected particles pairs.
def add_restraint_to_model
Add a PMI restraint to the model.
Definition: tools.py:89
Create harmonic restraints between the reference and (transformed) clones.
Add angular restraint between triplets of consecutive residues/beads to enforce the stereochemistry...
def get_num_restraints
Returns number of connectivity restraints.
A decorator for a residue.
Definition: Residue.h:135
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...
This class creates a restraint between consecutive TempResidue objects OR an entire PMI MOlecule obje...
A class to create an excluded volume restraint for a set of particles at a given resolution.
The general base class for IMP exceptions.
Definition: exception.h:49
def __init__
need to add: ca-ca bond ca-cb is a constraint, no restraint needed ca-ca-ca cb-ca-ca-cb ...
Applies a PairScore to a Pair.
Definition: PairRestraint.h:29
def get_sorted_segments
Returns sequence-sorted segments array, each containing the first particle the last particle and the ...
Definition: tools.py:1044
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
Definition: Selection.h:66
Applies a PairScore to each Pair in a list.
def get_residue_indexes
Retrieve the residue indexes for the given particle.
Definition: tools.py:554
A repulsive potential on the distance between two atoms.
Perform more efficient close pair finding when rigid bodies are involved.
Base class for PMI restraints, which wrap IMP.Restraint(s).
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:627
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:24
Restraint a set of residues to use ideal helix dihedrals and bonds.