Icon representing a recipe

Recipe: Band Sheets v1.0

created by Serca

Profile


Name
Band Sheets v1.0
ID
103555
Shared with
Public
Parent
None
Children
None
Created on
May 30, 2020 at 09:17 AM UTC
Updated on
May 30, 2020 at 09:17 AM UTC
Description

Bands sheets that are close enough.

Best for


Code


--[[ Band Sheets v1.0 Make bands between sheets that are close enough ]]-- proteinLength=structure.GetCount () bandlistSeg1={} bandlistSeg2={} reportLevel=true bandStrength=0.9 bandLength=2.1 detectRadius=7 ignoreFrozen=false bandCount = 0 --band.GetCount () function OptionsDialog() ask=dialog.CreateDialog("Band Sheets Options") ask.bandStrength = dialog.AddSlider("Set Strength",bandStrength,0,2,1) ask.bandLength = dialog.AddSlider("Set Length",bandLength,0,4,1) ask.reportLevel=dialog.AddCheckbox("Report", reportLevel) ask.ignoreFrozen=dialog.AddCheckbox("Ignore frozen segments", ignoreFrozen) ask.detectRadius = dialog.AddSlider("Search Distance",detectRadius,0,10,1) ask.OK = dialog.AddButton("OK",1) ask.Cancel = dialog.AddButton("Cancel",0) returnVal=dialog.Show(ask) bandStrength = ask.bandStrength.value bandLength=ask.bandLength.value reportLevel=ask.reportLevel.value ignoreFrozen=ask.ignoreFrozen.value detectRadius=ask.detectRadius.value return returnVal end function roundX(x)--cut all afer 3-rd place return x-x%0.1 end function CheckBandExists(seg1, seg2) for k=1, #bandlistSeg1 do if (bandlistSeg1[k]==seg1) and (bandlistSeg2[k]==seg2) then return true end if (bandlistSeg1[k]==seg2) and (bandlistSeg2[k]==seg1) then return true end end return false end if (OptionsDialog()==0) then return end undo.SetUndo(false) for i=2, proteinLength-1 do for j=2, proteinLength-1 do if (j>i) then if ((structure.GetSecondaryStructure(i)=="E") and (structure.GetSecondaryStructure(j)=="E")) then makeBand=true currentDistance=structure.GetDistance(i,j) if (currentDistance < detectRadius) then if (currentDistance>structure.GetDistance(i+1,j)) and ((structure.GetSecondaryStructure(i+1)=="E")) then makeBand=false end if (currentDistance>structure.GetDistance(i-1,j)) and ((structure.GetSecondaryStructure(i-1)=="E")) then makeBand=false end if (currentDistance>structure.GetDistance(i,j+1)) and ((structure.GetSecondaryStructure(j+1)=="E")) then makeBand=false end if (currentDistance>structure.GetDistance(i,j-1)) and ((structure.GetSecondaryStructure(j-1)=="E")) then makeBand=false end if CheckBandExists(i, j) then makeBand=false end if (ignoreFrozen) then if (freeze.IsFrozen(i)) or (freeze.IsFrozen(j)) then makeBand=false end end if makeBand==true then bandCount=bandCount+1 bandID=band.AddBetweenSegments(i, j) bandlistSeg1[bandCount]=i bandlistSeg2[bandCount]=j band.SetStrength(bandID, bandStrength) band.SetGoalLength(bandID, bandLength) if reportLevel then print ("Added band for segments "..i.."-"..j,"distance "..roundX(currentDistance)) end end end end end end end if reportLevel then print ("Total "..bandCount.." bands added. Length="..bandLength..", strength="..bandStrength) end undo.SetUndo(true)

Comments


Bruno Kestemont Lv 1

There was a recipe "polar binding", but it was not perfect. I'll try this one next time I need it (for design or de nove puzzles)