run /dir/to/collapseSel.py
fetch 1cll
select EE, resn GLU
print collapseSel("EE")
#
# and PyMOL should output:
#
# 6-7+11+14+31+45+47+54+67+82-84+87+104+114+119-120+123+127+139-140
#
def collapseIDs(ids):
"""
Helper function to make a smart list of IDs: eg turns 1+2+3+4+5 into 1-5.
"""
rVal = []
if len(ids)==0:
return ""
scanning=False
anchor = 0
start = 0
# 1-5 7-10 12 21-23
for cur in range(0,len(ids)-1):
if ids[cur]+1 == ids[cur+1]:
if scanning:
scanning=True
continue
else:
scanning=True
start = cur
else:
if ..→