Advertisement
Crashguard303

CG303 Scaffolding Helices V2.50

May 21st, 2012
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.64 KB | None | 0 0
  1. -- Scaffolding by Crashguard303
  2. -- Script request by Mat747
  3. -- Included faster band removing, submitted by rav3n_pl
  4.  
  5. -- Applies bands between segments,
  6. -- if their SPATIAL and INDEX distance is inbetween an user-specified range,
  7. -- resulting a relative position lock of these segments (scaffolding).
  8.  
  9. -- NOTE:
  10. -- At the moment, FoldIt doesn't allow us to set band lengths greater than 20.
  11. -- We can't apply bands between adjacent segments, so these are skipped
  12.  
  13. function YesNo(Bool)
  14.  local OS
  15.  
  16.  if Bool then
  17.    OS="yes"
  18.   else
  19.    OS="no"
  20.  end -- if BOOL
  21.  
  22.  return OS
  23. end -- function
  24.  
  25. function ss_check(SegA,SegB)
  26.  
  27.  local SegAss=structure.GetSecondaryStructure(SegA)
  28.  local SegBss=structure.GetSecondaryStructure(SegB)
  29.  local ss_flag=false
  30.  
  31.  if SegAss~=SegBss then -- if secondary structure is unequal
  32.    if Band_ss_mixed then -- And connecting mixed ss is okay
  33.     ss_flag=true
  34.    end -- if BandMixeed
  35.   else -- so if ss is equal
  36.    if Band_ss_equal[SegAss]then
  37.      ss_flag=true
  38.    end -- if Band_ss_equal
  39.  end -- if SegAss unequal
  40.  
  41.  return ss_flag
  42. end -- function
  43.  
  44. function DistanceCheck(k,l)
  45.  local k=k
  46.  local l=l
  47.  local Distance=structure.GetDistance(k,l) -- get distance
  48.  local DistanceFlag=false
  49.  
  50.  if Distance>=MinSdist then -- above or equal minimum?
  51.   if Distance<=MaxSdist then -- below or equal maximum?
  52.    DistanceFlag=true
  53.   end -- if Distance
  54.  end -- if Distance
  55.  if Band_Invert_Result then DistanceFlag=not(DistanceFlag) end -- Invert result, if desired
  56.  
  57. return Distance,DistanceFlag
  58. end -- function
  59.  
  60. function Scaffolding()
  61.  print("Executing...")
  62.  
  63.  if Band_DeleteAll_Before then
  64.   print("Deleting old bands.")
  65.   band.DeleteAll()
  66.  end
  67.  
  68.  local kFinish=NumSegs-MinIdist
  69.  
  70.  local k
  71.  for k=1,kFinish do -- k=first segment index to check
  72.   local lStart=k+MinIdist
  73.   local lFinish=k+MaxIdist
  74.   if lFinish>NumSegs then lFinish=NumSegs end
  75.  
  76.   local l
  77.   for l=lStart, lFinish do -- l=second segment index to check
  78.    Distance,DistanceFlag=DistanceCheck(k,l) -- Get distance and distance flag
  79.    if DistanceFlag then -- Does distance match?
  80.    if ss_check(k,l) then -- Do secondary structures match?
  81.    local OS="Connecting "..k..":"..l.." distance:"..Distance
  82.    print(OS) -- Show
  83.    band.AddBetweenSegments(k,l) -- Connect
  84.    local TempBandCount=band.GetCount() -- Get new band amount
  85.    Distance=Distance*Band_DistFactor -- Change distance value by applying Factor
  86.    band.SetGoalLength(TempBandCount,Distance) -- Change length of last band
  87.    band.SetStrength(TempBandCount,Band_Strength) -- Change strength of last band
  88.    end -- if ss_check
  89.    end -- if DistanceFlag
  90.   end -- l loop
  91.  end -- k loop
  92.  
  93.  print("Finished.")
  94. end -- function
  95.  
  96. function InputDialog ()
  97.  local ask = dialog.CreateDialog("Set parameters")
  98.  
  99.  ask.Band = dialog.AddLabel("Band which secondary structure:")
  100.  ask.Helixes = dialog.AddCheckbox("Helix-Helix", Band_ss_equal["H"])
  101.  ask.Sheets = dialog.AddCheckbox("Sheet-Sheet", Band_ss_equal["E"])
  102.  ask.Loops = dialog.AddCheckbox("Loop-Loop", Band_ss_equal["L"])
  103.  ask.Mixed = dialog.AddCheckbox("Mixed", Band_ss_mixed)
  104.  
  105.  ask.Distance = dialog.AddLabel("Band which distance:")
  106.  ask.MinIdist = dialog.AddSlider("Min INDEX:", MinIdist, 2, (NumSegs-1), 0)
  107.  ask.MaxIdist = dialog.AddSlider("Max INDEX:", MaxIdist, 2, (NumSegs-1), 0)
  108.  ask.MinSdist = dialog.AddSlider("Min SPATIAL:", MinSdist, 0, ((NumSegs-1)*4), 1)
  109.  ask.MaxSdist = dialog.AddSlider("Max SPATIAL:", MaxSdist, 0, ((NumSegs-1)*4), 1)
  110.  
  111.  ask.Properties = dialog.AddLabel("Band properties:")
  112.  ask.Band_DistFactor = dialog.AddSlider("Band Factor", Band_DistFactor, 0.0, 10.0, 1)
  113.  ask.Band_Strength = dialog.AddSlider("Band Strength", Band_Strength, 0.1, 10.0, 1)
  114.  ask.Band_DeleteAll_Before = dialog.AddCheckbox("Delete all other bands before", Band_DeleteAll_Before)
  115.  ask.Band_Invert_Result = dialog.AddCheckbox("Invert banding result (careful with this option!)", Band_Invert_Result)
  116.  
  117.  ask.OK = dialog.AddButton("OK", 1)
  118.  ask.Cancel = dialog.AddButton("Cancel", 0)
  119.  
  120.  if dialog.Show(ask)>0 then -- If OK was pressed
  121.    Band_ss_equal["H"]=ask.Helixes.value
  122.    Band_ss_equal["E"]=ask.Sheets.value
  123.    Band_ss_equal["L"]=ask.Loops.value
  124.    Band_ss_mixed=ask.Mixed.value
  125.  
  126.    MinIdist=ask.MinIdist.value
  127.    MaxIdist=ask.MaxIdist.value
  128.    MinSdist=ask.MinSdist.value
  129.    MaxSdist=ask.MaxSdist.value
  130.  
  131.    if MinIdist>MaxIdist then MinIdist,MaxIdist=MaxIdist,MinIdist end
  132.    -- If Min>Max, swap them because it wouldn't make sense
  133.  
  134.    if MinSdist>MaxSdist then MinSdist,MaxSdist=MaxSdist,MinSdist end
  135.    -- If Min>Max, swap them because it wouldn't make sense
  136.  
  137.    Band_DistFactor=ask.Band_DistFactor.value
  138.    Band_Strength=ask.Band_Strength.value
  139.    Band_DeleteAll_Before=ask.Band_DeleteAll_Before.value
  140.    Band_Invert_Result=ask.Band_Invert_Result.value
  141.  
  142.    return true
  143.   else  -- If OK was not pressed
  144.    print("Canceled.")
  145.    return false
  146.  end -- if dialog.Show(ask)
  147. end -- function
  148.  
  149. -- Default parameters:
  150. NumSegs=structure.GetCount()
  151.                                                        -- Get amount of segments
  152. Band_ss_equal={}
  153.                                                        -- Initialize table containing information which equal secondary structures are allowed to be banded
  154. Band_ss_equal["L"]=false
  155.                                                        -- Boolean value. If true, banding loop to loop is allowed
  156. Band_ss_equal["H"]=true
  157.                                                        -- Boolean value. If true, banding helix to helix is allowed
  158. Band_ss_equal["E"]=false
  159.                                                        -- Boolean value. If true, banding sheet to sheet is allowed
  160. Band_ss_mixed=false
  161.                                                        -- Boolean value. If true, banding mixed secondary structures is allowed
  162.  
  163.                                                        -- Note: If you change Band_ss_mixed,BandLoops,BandHelices AND BandSheets to false,
  164.                                                        -- NO band will be applied. You will just waste some of your precious time.
  165.  
  166. MinIdist=3
  167.                                                        -- Minimum INDEX segment distance to band, INTEGER value
  168.                                                        -- Minimum value:2,
  169.                                                        -- because the game doesn't connect bands if the segments are too close
  170. MaxIdist=4
  171. -- MaxIdist=NumSegs-1
  172.                                                        -- Maximum INDEX segment distance to band, INTEGER value
  173. MinSdist=4
  174.                                                        -- Minimum SPATIAL segment distance to band, FLOAT value
  175. MaxSdist=8
  176.                                                        -- Maximum SPATIAL segment distance to band, FLOAT value
  177. Band_DistFactor=1
  178.                                                        -- Factor, which changes the band length according to its spatial distance, float value, >=0
  179.                                                        -- values<1 pull segments together,
  180.                                                        -- values keep them in postion,
  181.                                                        -- values>1 push them apart
  182.  
  183. Band_Strength=1
  184.                                                        -- Band strength of the scaffold, float value
  185.  
  186.                                                        -- Examples:
  187.                                                        -- If a segment distance is 4, and factor is 2, the band length will be 8.
  188.                                                        -- If a segment distance is 4, and factor is .5, the band length will be 2.
  189. Band_DeleteAll_Before=false
  190.                                                        -- delete all bands before script start, boolean value
  191.                                                        -- If true, all existing bands are deleted before script is executed.
  192.                                                        -- If false, previous bands are kept, however.
  193.  
  194. Band_Invert_Result=false
  195.                                                        -- Distance inverting, boolean value
  196.                                                        -- Set this to true if you want to invert spatial distance banding
  197.                                                        -- Be careful with this option, it can create many bands if MinSdist and MaxSdist are close!
  198.  
  199. if InputDialog() then
  200.                                                        -- Show/change values with input dialog
  201.                                                        -- If OK was pressed
  202.   Scaffolding()
  203.                                                        -- call script with set parameters
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement