Iterate sses: Difference between revisions
Jump to navigation
Jump to search
(New page: A slightly more complex version of ss that allows the user to pass in a function to act on the sse list. Of course, this requires the user to know about the internals of the sse class,...) |
m (same change as for the ss command.) |
||
Line 21: | Line 21: | ||
sses = [SSE(num, currentType, sseNumber)] | sses = [SSE(num, currentType, sseNumber)] | ||
currentSSE = sses[0] | currentSSE = sses[0] | ||
for resi, | for resi, ssType in stored.pairs: | ||
if | if ssType == currentType: | ||
currentSSE.end = resi | currentSSE.end = resi | ||
else: | else: | ||
sseNumber += 1 | sseNumber += 1 | ||
sses.append(SSE(resi, | sses.append(SSE(resi, ssType, sseNumber)) | ||
currentSSE = sses[-1] | currentSSE = sses[-1] | ||
currentType = | currentType = ssType | ||
for sse in sses: | for sse in sses: |
Revision as of 11:57, 9 October 2007
A slightly more complex version of ss that allows the user to pass in a function to act on the sse list. Of course, this requires the user to know about the internals of the sse class, but since this code is all open I doubt that matters..
def iterate_sses(selection, action):
class SSE(object):
def __init__(self, start, typ, sseNumber):
self.start, self.typ = start, typ
self.end = -1
self.sseNumber = sseNumber
def __repr__(self):
return "%s-%s %s" % (self.start, self.end, self.typ)
stored.pairs = []
cmd.iterate(selection, "stored.pairs.append((resi, ss))")
num, currentType = stored.pairs[0]
sseNumber = 1
sses = [SSE(num, currentType, sseNumber)]
currentSSE = sses[0]
for resi, ssType in stored.pairs:
if ssType == currentType:
currentSSE.end = resi
else:
sseNumber += 1
sses.append(SSE(resi, ssType, sseNumber))
currentSSE = sses[-1]
currentType = ssType
for sse in sses:
action(sse)
cmd.extend("iterate_sses", iterate_sses)
As an example, here is a function that makes a series of selections, one for each sse, called "H1", "E2", and so on. Use it like: "iterate_sses('my_protein', doSelect)".
def doSelect(sse):
cmd.select("%s%s" % (sse.typ, sse.sseNumber), "i. %s-%s" % (sse.start, sse.end))