IMP logo
IMP Reference Guide  2.10.1
The Integrative Modeling Platform
atomicDominoUtilities.py
1 from __future__ import print_function
2 import IMP
3 import re
4 import sys
5 import os
6 
7 
8 def readParameters(parameterFileName):
9 
10  parameters = {}
11  parameterFh = open(parameterFileName)
12  blankRe = re.compile('^\s*$')
13  skipRe = re.compile('^\#')
14  for line in parameterFh:
15 
16  blankLine = blankRe.search(line)
17  if blankLine:
18  continue
19  skipLine = skipRe.search(line)
20  if skipLine:
21  continue
22 
23  line = line.rstrip("\n\r")
24  [paramName, paramValue] = line.split('\t')
25  print("parameter %s:\t%s" % (paramName, paramValue))
26  parameters[paramName] = paramValue
27 
28  parameterFh.close()
29  return parameters
30 
31 # Represents an atom particle as a string (contains its chain ID, residue ID, and atom name)
32 # Other methods parse the name so if the name format changes they need to be updated
33 #getPeptideCa(); writeCytoscapeIgInput(); getAtomTypeCounts()
34 
35 
36 def quickParticleName(particle):
37  atomDecorator = IMP.atom.Atom(particle)
38  atomName = atomDecorator.get_atom_type()
39 
40  atomDecorator = IMP.atom.Atom(particle)
41  residue = IMP.atom.get_residue(atomDecorator)
42  residueNumber = residue.get_index()
43 
44  chain = IMP.atom.get_chain(residue)
45  chainId = chain.get_id()
46 
47  name = "%s_%s_%s" % (chainId, residueNumber, atomName)
48  nameFinal = name.replace('"', '')
49 
50  return nameFinal
51 
52 # make dictionary mapping particle name to the object it represents
53 
54 
55 def makeNamesToParticles(protein):
56 
57  leaves = IMP.atom.get_leaves(protein)
58  namesToParticles = {}
59  for leaf in leaves:
60  name = quickParticleName(leaf)
61  namesToParticles[name] = leaf
62  leaf.set_name(name)
63  return namesToParticles
64 
65 
66 # get the chain id, residue id, and atom name from the particle name -- slightly cleaner in that if we change the name
67 # format, we don't have to change all the methods that rely on that format
68 def getAtomInfoFromName(particleName):
69  [chain, residue, atom] = particleName.split("_")
70  return [chain, residue, atom]
71 
72 # quick way to get formatted name
73 
74 
75 def makeParticleName(chain, residueNumber, atomName):
76  return "%s_%s_%s" % (chain, residueNumber, atomName)
77 
78 
79 # Check if this particle is an atom particle or a restraint
80 def isAtomParticle(p):
81  # hack; need to distinguish from non-atom particle
82  if (p.get_name().find('_') == -1):
83  return 0
84  else:
85  return 1
86 
87 
88 # Get particles in model that are contained in model's restraints
89 def getRestrainedParticles(protein, model, namesToParticles):
90  leaves = IMP.atom.get_leaves(protein)
91 
92  particleDict = {}
93  count = 0
94  for r in IMP.get_restraints([model.get_root_restraint_set()]):
95  count += 1
96  ps = r.get_input_particles()
97 
98  for p in ps:
99  if (isAtomParticle(p) == 0):
100  continue
101  name = quickParticleName(p)
102  # use dictionary keyed on names to avoid duplication
103  particleDict[name] = 1
104  score = r.evaluate(0)
105 
106  restrainedParticles = []
107  for name in particleDict.keys():
108  p = namesToParticles[name]
109  restrainedParticles.append(p)
110 
111  return restrainedParticles
112 
113 
114 def getMdIntervalFrames(rh, interval, protein):
115  frames = []
116  if (interval > -1):
117  frameCount = IMP.rmf.get_number_of_frames(rh, protein)
118  for i in range(1, frameCount, interval):
119  frames.append(i)
120  return frames
Chain get_chain(Hierarchy h)
Get the containing chain or Chain() if there is none.
A decorator for a particle representing an atom.
Definition: atom/Atom.h:234
RestraintsTemp get_restraints(It b, It e)
Definition: RestraintSet.h:113
Residue get_residue(Atom d, bool nothrow=false)
Return the Residue containing this atom.
Hierarchies get_leaves(const Selection &h)