Icon representing a recipe

Recipe: CG303 Scaffolding Helices V2.50

created by Crashguard303

Profile


Name
CG303 Scaffolding Helices V2.50
ID
41821
Shared with
Public
Parent
None
Children
Created on
May 21, 2012 at 10:37 AM UTC
Updated on
May 21, 2012 at 10:37 AM UTC
Description

Lua V2 translation, now with input window.
When playing with clash importance, this script can help you preventing atom bonds from breaking apart.
This example tries to maintain atom bonds between helix segments.
It can also be used for sheets, but then you will have to check sheet manipulating and use other distance values (higher index distance).
Feel free to offer some useful parameters (for sheets).
By default, the script does only keep the distances between segments by generating bands having the same length as each distance. Changing the length factor, you can even compress or decompress sections.
Another strategy when playing with clash importance is to choose only bands with big lengths (maintaning only large distances), allowing minor changes in connections.
Have fun!

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 function YesNo(Bool) local OS if Bool then OS="yes" else OS="no" end -- if BOOL 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 Band_ss_mixed then -- And connecting mixed ss is okay ss_flag=true end -- if BandMixeed else -- so if ss is equal if Band_ss_equal[SegAss]then ss_flag=true end -- if Band_ss_equal end -- if SegAss unequal return ss_flag end -- function function DistanceCheck(k,l) local k=k local l=l local Distance=structure.GetDistance(k,l) -- get distance local DistanceFlag=false 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 Band_Invert_Result then DistanceFlag=not(DistanceFlag) end -- Invert result, if desired return Distance,DistanceFlag end -- function function Scaffolding() print("Executing...") if Band_DeleteAll_Before then print("Deleting old bands.") band.DeleteAll() end 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? local OS="Connecting "..k..":"..l.." distance:"..Distance print(OS) -- Show band.AddBetweenSegments(k,l) -- Connect local TempBandCount=band.GetCount() -- Get new band amount Distance=Distance*Band_DistFactor -- Change distance value by applying Factor band.SetGoalLength(TempBandCount,Distance) -- Change length of last band band.SetStrength(TempBandCount,Band_Strength) -- Change strength of last band end -- if ss_check end -- if DistanceFlag end -- l loop end -- k loop print("Finished.") end -- function function InputDialog () local ask = dialog.CreateDialog("Set parameters") ask.Band = dialog.AddLabel("Band which secondary structure:") ask.Helixes = dialog.AddCheckbox("Helix-Helix", Band_ss_equal["H"]) ask.Sheets = dialog.AddCheckbox("Sheet-Sheet", Band_ss_equal["E"]) ask.Loops = dialog.AddCheckbox("Loop-Loop", Band_ss_equal["L"]) ask.Mixed = dialog.AddCheckbox("Mixed", Band_ss_mixed) ask.Distance = dialog.AddLabel("Band which distance:") ask.MinIdist = dialog.AddSlider("Min INDEX:", MinIdist, 2, (NumSegs-1), 0) ask.MaxIdist = dialog.AddSlider("Max INDEX:", MaxIdist, 2, (NumSegs-1), 0) ask.MinSdist = dialog.AddSlider("Min SPATIAL:", MinSdist, 0, ((NumSegs-1)*4), 1) ask.MaxSdist = dialog.AddSlider("Max SPATIAL:", MaxSdist, 0, ((NumSegs-1)*4), 1) ask.Properties = dialog.AddLabel("Band properties:") ask.Band_DistFactor = dialog.AddSlider("Band Factor", Band_DistFactor, 0.0, 10.0, 1) ask.Band_Strength = dialog.AddSlider("Band Strength", Band_Strength, 0.1, 10.0, 1) ask.Band_DeleteAll_Before = dialog.AddCheckbox("Delete all other bands before", Band_DeleteAll_Before) ask.Band_Invert_Result = dialog.AddCheckbox("Invert banding result (careful with this option!)", Band_Invert_Result) ask.OK = dialog.AddButton("OK", 1) ask.Cancel = dialog.AddButton("Cancel", 0) if dialog.Show(ask)>0 then -- If OK was pressed Band_ss_equal["H"]=ask.Helixes.value Band_ss_equal["E"]=ask.Sheets.value Band_ss_equal["L"]=ask.Loops.value Band_ss_mixed=ask.Mixed.value MinIdist=ask.MinIdist.value MaxIdist=ask.MaxIdist.value MinSdist=ask.MinSdist.value MaxSdist=ask.MaxSdist.value if MinIdist>MaxIdist then MinIdist,MaxIdist=MaxIdist,MinIdist end -- If Min>Max, swap them because it wouldn't make sense if MinSdist>MaxSdist then MinSdist,MaxSdist=MaxSdist,MinSdist end -- If Min>Max, swap them because it wouldn't make sense Band_DistFactor=ask.Band_DistFactor.value Band_Strength=ask.Band_Strength.value Band_DeleteAll_Before=ask.Band_DeleteAll_Before.value Band_Invert_Result=ask.Band_Invert_Result.value return true else -- If OK was not pressed print("Canceled.") return false end -- if dialog.Show(ask) end -- function -- Default parameters: NumSegs=structure.GetCount() -- Get amount of segments Band_ss_equal={} -- Initialize table containing information which equal secondary structures are allowed to be banded Band_ss_equal["L"]=false -- Boolean value. If true, banding loop to loop is allowed Band_ss_equal["H"]=true -- Boolean value. If true, banding helix to helix is allowed Band_ss_equal["E"]=false -- Boolean value. If true, banding sheet to sheet is allowed Band_ss_mixed=false -- Boolean value. If true, banding mixed secondary structures is allowed -- Note: If you change Band_ss_mixed,BandLoops,BandHelices AND BandSheets to false, -- NO band will be applied. You will just waste some of your precious time. MinIdist=3 -- 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=4 -- MaxIdist=NumSegs-1 -- Maximum INDEX segment distance to band, INTEGER value MinSdist=4 -- Minimum SPATIAL segment distance to band, FLOAT value MaxSdist=8 -- Maximum SPATIAL segment distance to band, FLOAT value Band_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 Band_Strength=1 -- Band strength of the scaffold, float value -- 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. Band_DeleteAll_Before=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. Band_Invert_Result=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! if InputDialog() then -- Show/change values with input dialog -- If OK was pressed Scaffolding() -- call script with set parameters end

Comments