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