Code
function Main()
-- bandsomeSS: interactively place bands between specific cysteines in protein
-- adapted from bandsome code originally by jeff101 8/11/12 and last updated around 10pm 8/11/12
-- bandsomeSS was begun 7/29/15 by jeff101
-- last updated 7/29/15 1022pm
-- below sets default values
rname='bandsomeSS'
rtot=structure.GetCount()
bnum=band.GetCount()
osdate=os.date()
oldscore=math.floor(current.GetScore()*1000)/1000 -- seems Foldit always rounds down at .001 position
print(rname..' begins at '..osdate..' on\n puzzle '..puzzle.GetName()..'\n with puzzle ID '..puzzle.GetPuzzleID()..', '..rtot..' residues, '..bnum..' bands,\n and score '..oldscore..'.')
clist={}
cstr=''
for j=1,rtot do
aa=structure.GetAminoAcid(j)
if aa=='c' then
clist[#clist+1]=j
cstr=(cstr..' '..j)
end -- if aa
end -- for j
ctot=#clist -- ctot is number of cysteines
if ctot==0 then
print('Found 0 cysteines (not enough cys to form s-s bonds).')
elseif ctot==1 then
print('Found 1 cysteine:'..cstr..' (not enough cys to form s-s bonds).')
else -- ctot>1
print('Found '..ctot..' cysteines:'..cstr..' (will call them 1-'..ctot..' below).')
cdone='' -- previous s-s bonds banded
clast='' -- last s-s bond banded
cnum1=1
cnum2=2
if cnum1>ctot then
cnum1=1
end -- if cnum1
if cnum2>ctot then
cnum2=ctot
end -- if cnum2
anum1s={6, 5, 6} -- atom # on residue #1 (rnum1) or cysteine #1 (cnum1)
anum2s={6, 6, 5} -- atom # on residue #2 (rnum2) or cysteine #2 (cnum2)
blens= {2, 3, 3} -- bond lengths in angstroms for 6-6 5-6 6-5 respectively
bstr=5 -- bond strength to use
keeplast=1
qflag=0
-- below gets input values
while qflag==0 do
local ask=dialog.CreateDialog(rname)
ask.Label0=dialog.AddLabel((' \ncnum*=1-'..ctot..' for cys'..cstr..' below:\n '))
ask.Input1=dialog.AddSlider("cnum1: ",cnum1,1,ctot,0)
ask.Label1=dialog.AddLabel(" \ncnum1: index of 1st cysteine in next 3 bands.\n ")
ask.Input2=dialog.AddSlider("cnum2: ",cnum2,1,ctot,0)
ask.Label2=dialog.AddLabel(" \ncnum2: index of 2nd cysteine in next 3 bands.\n ")
ask.Input6=dialog.AddSlider("bstr: ",bstr,0,10,1)
ask.Label6=dialog.AddLabel(" \nbstr: band strength for next 3 bands.\n ")
ask.Input7=dialog.AddSlider("keeplast: ",keeplast,-1,2,0)
ask.Label7a=dialog.AddLabel(" ")
ask.Label7b=dialog.AddLabel("keeplast: -1 remove all previous bands,\n0 replace previous 3 bands, 1 keep previous bands,\n2 quit now without adding new bands.")
ask.Label7c=dialog.AddLabel(" ")
ask.OK = dialog.AddButton("OK", 1)
dialog.Show(ask)
cnum1=ask.Input1.value+0
cnum2=ask.Input2.value+0
bstr=ask.Input6.value+0
keeplast=ask.Input7.value+0
if keeplast== -1 then
bnum=band.GetCount()
print('Deleting all '..bnum..' previous bands.')
band.DeleteAll()
cdone=''
clast=''
elseif keeplast==0 then
for j=1,3 do
bnum=band.GetCount()
if bnum>0 then
print('Deleting band '..bnum..' so end with '..(bnum-1)..' bands.')
band.Delete(bnum)
end -- if bnum
end -- for j
clast=''
elseif keeplast==2 then
qflag=1 -- this will quit
end -- if keeplast
if keeplast~=2 then
rnum1=clist[cnum1]
rnum2=clist[cnum2]
if rnum1==rnum2 then
bnum=band.GetCount()
print('Failed to add new band. Still have '..bnum..' bands.')
else -- rnum1~=rnum2
for j=1,3 do
anum1=anum1s[j]
anum2=anum2s[j]
blen=blens[j]
bnum=band.AddBetweenSegments(rnum1,rnum2,anum1,anum2)
if bnum>0 then
band.SetGoalLength(bnum,blen) -- 3.5 is default band length
band.SetStrength(bnum,bstr) -- 10 is max, 1 is default
dist=round(band.GetLength(bnum)*100)/100 -- round length to nearest 0.01
ss1=structure.GetSecondaryStructure(rnum1)
ss2=structure.GetSecondaryStructure(rnum2)
print('Adding band '..bnum..' between atom '..anum1..' on c'..rnum1..' ('..ss1..')\n and atom '..anum2..' on c'..rnum2..' ('..ss2..') with strength '..bstr..',\n goal length '..blen..', and present length '..dist..'.')
if j==3 then
cdone=cdone..clast
clast=(' '..rnum1..'-'..rnum2)
end
else
j=3 -- redundant with break below?
bnum=band.GetCount()
print('Failed to add new band. Still have '..bnum..' bands.')
break -- redundant with j=3 above?
end -- if bnum
end -- for j
end -- if rnum1==rnum2
end -- if keeplast
end -- while qflag
cdone=cdone..clast
print('Banded for disulfides'..cdone..'.')
-- below does SetNote in lowest #'d blank Note
-- assumes only lowest #'d Notes aren't blank
-- and then once one is blank, all the Notes after it are blank
note_number=rtot
for j=rtot,1,-1 do
if structure.GetNote(j)~="" then break end
note_number=j
end
tstr=string.format("(%s) %.3f + %s%s",user.GetPlayerName(),oldscore,rname,cdone)
print('Setting Note '..note_number..' to the following:\n '..tstr)
structure.SetNote(note_number,tstr)
end -- if ctot>1
bnum=band.GetCount()
osdate=os.date()
print('Ending with '..bnum..' bands for '..rtot..' residues and '..ctot..' cysteines.')
print('All done at '..osdate..'.')
end -- Main()
-- below rounds val to nearest integer and returns it in res
function round(val)
local res=math.floor(val)
if val-res>=0.5 then
res=res+1
end -- if val
return res
end -- round()
Main()