IMP  2.1.1
The Integrative Modeling Platform
atomicDominoUtilities.py
1 import IMP
2 import re
3 import sys
4 import os
5 
6 def readParameters(parameterFileName):
7 
8  parameters = {}
9  parameterFh = open(parameterFileName)
10  blankRe = re.compile('^\s*$')
11  skipRe = re.compile('^\#')
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, and atom name)
30 #Other methods parse the name so if the name format changes they need to be updated
31 #getPeptideCa(); writeCytoscapeIgInput(); getAtomTypeCounts()
32 def quickParticleName(particle):
33  atomDecorator = IMP.atom.Atom.decorate_particle(particle)
34  atomName = atomDecorator.get_atom_type()
35 
36  atomDecorator = IMP.atom.Atom.decorate_particle(particle)
37  residue = IMP.atom.get_residue(atomDecorator)
38  residueNumber = residue.get_index()
39 
40  chain = IMP.atom.get_chain(residue)
41  chainId = chain.get_id()
42 
43  name = "%s_%s_%s" % (chainId, residueNumber, atomName)
44  nameFinal = name.replace('"', '')
45 
46  return nameFinal
47 
48 #make dictionary mapping particle name to the object it represents
49 def makeNamesToParticles(protein):
50 
51  leaves = IMP.atom.get_leaves(protein)
52  namesToParticles = {}
53  for leaf in leaves:
54  name = quickParticleName(leaf)
55  namesToParticles[name] = leaf
56  leaf.set_name(name)
57  return namesToParticles
58 
59 
60 #get the chain id, residue id, and atom name from the particle name -- slightly cleaner in that if we change the name
61 #format, we don't have to change all the methods that rely on that format
62 def getAtomInfoFromName(particleName):
63  [chain, residue, atom] = particleName.split("_")
64  return [chain, residue, atom]
65 
66 #quick way to get formatted name
67 def makeParticleName(chain, residueNumber, atomName):
68  return "%s_%s_%s" % (chain, residueNumber, atomName)
69 
70 
71 #Check if this particle is an atom particle or a restraint
72 def isAtomParticle(p):
73  if (p.get_name().find('_') == -1): #hack; need to distinguish from non-atom particle
74  return 0
75  else:
76  return 1
77 
78 
79 #Get particles in model that are contained in model's restraints
80 def getRestrainedParticles(protein, model, namesToParticles):
81  leaves = IMP.atom.get_leaves(protein)
82 
83  particleDict = {}
84  count = 0
85  for r in IMP.get_restraints([model.get_root_restraint_set()]):
86  count += 1
87  ps = r.get_input_particles()
88 
89  for p in ps:
90  if (isAtomParticle(p) == 0):
91  continue
92  name = quickParticleName(p)
93  particleDict[name] = 1 #use dictionary keyed on names to avoid duplication
94  score = r.evaluate(0)
95 
96  restrainedParticles = []
97  for name in particleDict.keys():
98  p = namesToParticles[name]
99  restrainedParticles.append(p)
100 
101  return restrainedParticles
102 
103 def getMdIntervalFrames(rh, interval, protein):
104  frames = []
105  if (interval > -1):
106  frameCount = IMP.rmf.get_number_of_frames(rh, protein)
107  for i in range(1, frameCount, interval):
108  frames.append(i)
109  return frames
Chain get_chain(Hierarchy h)
Hierarchy get_residue(Hierarchy mhd, unsigned int index)
Get the residue with the specified index.
static Atom decorate_particle(::IMP::kernel::Particle *p)
Definition: atom/Atom.h:241
Hierarchies get_leaves(const Selection &h)