IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
atomicDominoUtilities.py
1import IMP
2import re
3
4
5def readParameters(parameterFileName):
6
7 parameters = {}
8 parameterFh = open(parameterFileName)
9 blankRe = re.compile(r'^\s*$')
10 skipRe = re.compile(r'^\#')
11 for line in parameterFh:
12
13 blankLine = blankRe.search(line)
14 if blankLine:
15 continue
16 skipLine = skipRe.search(line)
17 if skipLine:
18 continue
19
20 line = line.rstrip("\n\r")
21 [paramName, paramValue] = line.split('\t')
22 print("parameter %s:\t%s" % (paramName, paramValue))
23 parameters[paramName] = paramValue
24
25 parameterFh.close()
26 return parameters
27
28# Represents an atom particle as a string (contains its chain ID, residue ID,
29# and atom name)
30# Other methods parse the name so if the name format changes they need to
31# be updated
32# getPeptideCa(); writeCytoscapeIgInput(); getAtomTypeCounts()
33
34
35def 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
54def 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 --
66# 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
68def getAtomInfoFromName(particleName):
69 [chain, residue, atom] = particleName.split("_")
70 return [chain, residue, atom]
71
72# quick way to get formatted name
73
74
75def 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
80def 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
89def getRestrainedParticles(protein, model, namesToParticles):
90 particleDict = {}
91 count = 0
92 for r in IMP.get_restraints([model.get_root_restraint_set()]):
93 count += 1
94 ps = r.get_input_particles()
95
96 for p in ps:
97 if (isAtomParticle(p) == 0):
98 continue
99 name = quickParticleName(p)
100 # use dictionary keyed on names to avoid duplication
101 particleDict[name] = 1
102 _ = r.evaluate(0)
103
104 restrainedParticles = []
105 for name in particleDict.keys():
106 p = namesToParticles[name]
107 restrainedParticles.append(p)
108
109 return restrainedParticles
110
111
112def getMdIntervalFrames(rh, interval, protein):
113 frames = []
114 if (interval > -1):
115 frameCount = IMP.rmf.get_number_of_frames(rh, protein)
116 for i in range(1, frameCount, interval):
117 frames.append(i)
118 return frames
A decorator for a particle representing an atom.
Definition Atom.h:238
Chain get_chain(Hierarchy h)
Get the containing chain or Chain() if there is none.
Residue get_residue(Atom d, bool nothrow=false)
Return the Residue containing this atom.
Hierarchies get_leaves(const Selection &h)
RestraintsTemp get_restraints(const RestraintsTemp &rs)