Icon representing a recipe

Recipe: Scaffolding Sheets V1.2

created by SemperRabbit

Profile


Name
Scaffolding Sheets V1.2
ID
107741
Shared with
Public
Parent
None
Children
None
Created on
September 09, 2022 at 23:00 PM UTC
Updated on
September 10, 2022 at 12:02 PM UTC
Description

Scaffolding by Crashguard303
Script request by Mat747
Port to API v2 by SemperRabbit

Included faster band removing, submitted by rav3n_pl

Applies bands between segments,
if their SPATIAL and INDEX distance is inbetween an user-specified range,
resulting a relative position lock of these segments (scaffolding).

Port to API V2 was completed by search/replace of V1 API calls to equivalent V2 API calls. No logic was changed.
-V1.2: added options dialog, tweaked defaults to allow "Band Helices" to work as expected

Best for


Code


-- Scaffolding by Crashguard303 -- Script request by Mat747 -- Included faster band removing, submitted by rav3n_pl -- Applies bands between segments, -- if their SPATIAL and INDEX distance is inbetween an user-specified range, -- resulting a relative position lock of these segments (scaffolding). -- NOTE: -- At the moment, FoldIt doesn't allow us to set band lengths greater than 20. -- We can't apply bands between adjacent segments, so these are skipped recipe_name="Scaffolding Sheets V1.2" function YesNo(Bool) local Bool=Bool local OS if Bool==true then OS="yes" else OS="no" end -- if return OS end -- function function ss_check(SegA,SegB) local SegAss=structure.GetSecondaryStructure(SegA) local SegBss=structure.GetSecondaryStructure(SegB) local ss_flag=false if SegAss~=SegBss then -- if secondary structure is unequal if BandMixed==true then -- And connecting mixed ss is okay ss_flag=true end -- if BandMixeed else -- so if ss is equal if SegAss=="L" then -- loops found if BandLoops==true then ss_flag=true end -- if BandLoops elseif SegAss=="H" then -- helices found if BandHelices==true then ss_flag=true end -- if BandHelices else -- No loops and helices, so it must be sheets if BandSheets==true then ss_flag=true end -- if BandSheets end -- if SegAss is letter end -- if SegAss unequal return ss_flag end -- function function DistanceCheck(k,l) local k=k local l=l local Distance local DistanceFlag=false Distance=structure.GetDistance(k,l) -- get distance if Distance*DistFactor<=20 then -- The game doesn't allow bands longer than 20, so check resulting band length=distance*factor if Distance>=MinSdist then -- above or equal minimum? if Distance<=MaxSdist then -- below or equal maximum? DistanceFlag=true end -- if Distance end -- if Distance if InvertFlag==true then DistanceFlag=not(DistanceFlag) end -- Invert result, if desired end -- if Distance<=20 return Distance,DistanceFlag end -- function function Scaffolding() if MinIdist>MaxIdist then MinIdist,MaxIdist=MaxIdist,MinIdist end -- If Min>Max, swap them because it wouldn't make sense if MinIdist<1 then MinIdist=1 end -- if value is smaller than 1, set it to 1 if MinSdist>MaxSdist then MinSdist,MaxSdist=MaxSdist,MinSdist end -- If Min>Max, swap them because it wouldn't make sense if MinSdist<1 then MinSdist=1 end -- if value is smaller than 1, set it to 1 if DeleteAllBands then local BandsToDelete=band.GetCount() if BandsToDelete>0 then print("Removing ",BandsToDelete," bands...") for k=1,BandsToDelete do print(k) band.Delete(1) end -- k loop end -- if BandsToDelete>0 print() end -- if DeleteAllBands print("Connecting segments with strength: ",Strength) print() local OS if InvertFlag==false then OS="" else OS="out of " end -- if print("Distance range spatial: ",OS,MinSdist," to ",MaxSdist) print("Distance factor: ",DistFactor) print("Distance range index: ",MinIdist," to ",MaxIdist) print() print("Connect:") print("Mixed: ",YesNo(BandMixed)) print("Loops: ",YesNo(BandLoops)) print("Helices: ",YesNo(BandHelices)) print("Sheets: ",YesNo(BandSheets)) print() local kFinish=NumSegs-MinIdist local k for k=1,kFinish do -- k=first segment index to check local lStart=k+MinIdist local lFinish=k+MaxIdist if lFinish>NumSegs then lFinish=NumSegs end local l for l=lStart, lFinish do -- l=second segment index to check Distance,DistanceFlag=DistanceCheck(k,l) -- Get distance and distance flag if DistanceFlag then -- Does distance match? if ss_check(k,l) then -- Do secondary structures match? print("Connected ",k,":",l," distance:",Distance) -- Show band.AddBetweenSegments(k,l) -- Connect local TempBandCount=band.GetCount() -- Get new band amount Distance=Distance*DistFactor -- Change distance value by applying Factor band.SetGoalLength(TempBandCount,Distance) -- Change length of last band band.SetStrength(TempBandCount,Strength) -- Change strength of last band end -- if ss_check end -- if DistanceFlag end -- l loop end -- k loop end -- function -- CHANGE PARAMETERS HERE: NumSegs=structure.GetCount() -- Get amount of segments DeleteAllBands=false -- delete all bands before script start, boolean value -- If true, all existing bands are deleted before script is executed. -- If false, previous bands are kept, however. MinIdist=5 -- Minimum INDEX segment distance to band, INTEGER value -- Minimum value:2, -- because the game doesn't connect bands if the segments are too close MaxIdist=NumSegs-1 -- Maximum INDEX segment distance to band, INTEGER value MinSdist=4 -- Minimum SPATIAL segment distance to band, FLOAT value MaxSdist=6 -- Maximum SPATIAL segment distance to band, FLOAT value DistFactor=1 -- Factor, which changes the band length according to its spatial distance, float value, >=0 -- values<1 pull segments together, -- values keep them in postion, -- values>1 push them apart -- Examples: -- If a segment distance is 4, and factor is 2, the band length will be 8. -- If a segment distance is 4, and factor is .5, the band length will be 2. InvertFlag=false -- Distance inverting, boolean value -- Set this to true if you want to invert spatial distance banding -- Be careful with this option, it can create many bands if MinSdist and MaxSdist are close! Strength=10 -- Band strength of the scaffold, float value BandMixed=false -- Boolean value. If true, banding mixed secondary structures is allowed BandLoops=false -- Boolean value. If true, banding loop to loop is allowed BandHelices=false -- Boolean value. If true, banding helix to helix is allowed BandSheets=true -- Boolean value. If true, banding sheet to sheet is allowed -- Note: If you change BandMixed,BandLoops,BandHelices AND BandSheets to false -- NO band will be applied. You will just waste some of your precious time. -- START SemperRabbit GUI addition (20220910) ------------------ function askDialog() local ask = dialog.CreateDialog(recipe_name) ask.delBands = dialog.AddCheckbox("Delete Existing Bands", false) ask.mixed = dialog.AddCheckbox("Band Mixed", false) ask.sheet = dialog.AddCheckbox("Band sheets", true) ask.helix = dialog.AddCheckbox("Band helices", false) ask.loops = dialog.AddCheckbox("Band loops", false) ask.minSegDist = dialog.AddSlider("Min Seg Dist", 2, 2, 10, 0) ask.minSpatDist = dialog.AddSlider("Min Distance", 3, 2, 10, 1) ask.maxSpatDist = dialog.AddSlider("Max Distance", 6, 2, 10, 1) ask.label1 = dialog.AddLabel("Spacial Distance Factor will adjust the length of") ask.label2 = dialog.AddLabel("the bands. 1 will keep exact lengths, less than") ask.label3 = dialog.AddLabel("1 will pull, and greater than 1 will push.") ask.distFact = dialog.AddSlider("Distance Factor", 1, 0, 2, 2) ask.bandStr = dialog.AddSlider("Band Strength", 1, 0.1, 10, 1) -- Buttons ask.OK = dialog.AddButton("OK", 1) ask.Cancel = dialog.AddButton("Cancel", 0) dialog_show_ask = dialog.Show(ask) DeleteAllBands = ask.delBands.value MinIdist = ask.minSegDist.value MinSdist = ask.minSpatDist.value MaxSdist = ask.maxSpatDist.value DistFactor = ask.distFact.value Strength = ask.bandStr.value BandMixed = ask.mixed.value BandLoops = ask.loops.value BandHelices = ask.helix.value BandSheets = ask.sheet.value return dialog_show_ask==1 end -- function -- END SemperRabbit Addition ----------------------------------- if askDialog () then Scaffolding() -- Call script wi end print("hello")

Comments