IMP  2.3.0
The Integrative Modeling Platform
atomicDominoUtilities.py
1 import IMP
2 import re
3 import sys
4 import os
5 
6 
7 def readParameters(parameterFileName):
8 
9  parameters = {}
10  parameterFh = open(parameterFileName)
11  blankRe = re.compile('^\s*$')
12  skipRe = re.compile('^\#')
13  for line in parameterFh:
14 
15  blankLine = blankRe.search(line)
16  if blankLine:
17  continue
18  skipLine = skipRe.search(line)
19  if skipLine:
20  continue
21 
22  line = line.rstrip("\n\r")
23  [paramName, paramValue] = line.split('\t')
24  print "parameter %s:\t%s" % (paramName, paramValue)
25  parameters[paramName] = paramValue
26 
27  parameterFh.close()
28  return parameters
29 
30 # Represents an atom particle as a string (contains its chain ID, residue ID, and atom name)
31 # Other methods parse the name so if the name format changes they need to be updated
32 #getPeptideCa(); writeCytoscapeIgInput(); getAtomTypeCounts()
33 
34 
35 def quickParticleName(particle):
36  atomDecorator = IMP.atom.Atom(particle)
37  atomName = atomDecorator.get_atom_type()
38 
39  atomDecorator = IMP.atom.Atom(particle)
40  residue = IMP.atom.get_residue(atomDecorator)
41  residueNumber = residue.get_index()
42 
43  chain = IMP.atom.get_chain(residue)
44  chainId = chain.get_id()
45 
46  name = "%s_%s_%s" % (chainId, residueNumber, atomName)
47  nameFinal = name.replace('"', '')
48 
49  return nameFinal
50 
51 # make dictionary mapping particle name to the object it represents
52 
53 
54 def makeNamesToParticles(protein):
55 
56  leaves = IMP.atom.get_leaves(protein)
57  namesToParticles = {}
58  for leaf in leaves:
59  name = quickParticleName(leaf)
60  namesToParticles[name] = leaf
61  leaf.set_name(name)
62  return namesToParticles
63 
64 
65 # get the chain id, residue id, and atom name from the particle name -- slightly cleaner in that if we change the name
66 # format, we don't have to change all the methods that rely on that format
67 def getAtomInfoFromName(particleName):
68  [chain, residue, atom] = particleName.split("_")
69  return [chain, residue, atom]
70 
71 # quick way to get formatted name
72 
73 
74 def makeParticleName(chain, residueNumber, atomName):
75  return "%s_%s_%s" % (chain, residueNumber, atomName)
76 
77 
78 # Check if this particle is an atom particle or a restraint
79 def isAtomParticle(p):
80  # hack; need to distinguish from non-atom particle
81  if (p.get_name().find('_') == -1):
82  return 0
83  else:
84  return 1
85 
86 
87 # Get particles in model that are contained in model's restraints
88 def getRestrainedParticles(protein, model, namesToParticles):
89  leaves = IMP.atom.get_leaves(protein)
90 
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  score = 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)
Hierarchy get_residue(Hierarchy mhd, unsigned int index)
Get the residue with the specified index.
A decorator for a particle representing an atom.
Definition: atom/Atom.h:234
Hierarchies get_leaves(const Selection &h)