IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
atomicDominoUtilities.py
1 from __future__ import print_function
2 import IMP
3 import re
4 
5 
6 def readParameters(parameterFileName):
7 
8  parameters = {}
9  parameterFh = open(parameterFileName)
10  blankRe = re.compile(r'^\s*$')
11  skipRe = re.compile(r'^\#')
12  for line in parameterFh:
13 
14  blankLine = blankRe.search(line)
15  if blankLine:
16  continue
17  skipLine = skipRe.search(line)
18  if skipLine:
19  continue
20 
21  line = line.rstrip("\n\r")
22  [paramName, paramValue] = line.split('\t')
23  print("parameter %s:\t%s" % (paramName, paramValue))
24  parameters[paramName] = paramValue
25 
26  parameterFh.close()
27  return parameters
28 
29 # Represents an atom particle as a string (contains its chain ID, residue ID,
30 # and atom name)
31 # Other methods parse the name so if the name format changes they need to
32 # 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 --
67 # slightly cleaner in that if we change the name
68 # format, we don't have to change all the methods that rely on that format
69 def getAtomInfoFromName(particleName):
70  [chain, residue, atom] = particleName.split("_")
71  return [chain, residue, atom]
72 
73 # quick way to get formatted name
74 
75 
76 def makeParticleName(chain, residueNumber, atomName):
77  return "%s_%s_%s" % (chain, residueNumber, atomName)
78 
79 
80 # Check if this particle is an atom particle or a restraint
81 def isAtomParticle(p):
82  # hack; need to distinguish from non-atom particle
83  if (p.get_name().find('_') == -1):
84  return 0
85  else:
86  return 1
87 
88 
89 # Get particles in model that are contained in model's restraints
90 def getRestrainedParticles(protein, model, namesToParticles):
91  particleDict = {}
92  count = 0
93  for r in IMP.get_restraints([model.get_root_restraint_set()]):
94  count += 1
95  ps = r.get_input_particles()
96 
97  for p in ps:
98  if (isAtomParticle(p) == 0):
99  continue
100  name = quickParticleName(p)
101  # use dictionary keyed on names to avoid duplication
102  particleDict[name] = 1
103  _ = r.evaluate(0)
104 
105  restrainedParticles = []
106  for name in particleDict.keys():
107  p = namesToParticles[name]
108  restrainedParticles.append(p)
109 
110  return restrainedParticles
111 
112 
113 def getMdIntervalFrames(rh, interval, protein):
114  frames = []
115  if (interval > -1):
116  frameCount = IMP.rmf.get_number_of_frames(rh, protein)
117  for i in range(1, frameCount, interval):
118  frames.append(i)
119  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:238
RestraintsTemp get_restraints(It b, It e)
Definition: RestraintSet.h:132
Residue get_residue(Atom d, bool nothrow=false)
Return the Residue containing this atom.
Hierarchies get_leaves(const Selection &h)