Profile


Name
Stay Here!
ID
40513
Shared with
Public
Parent
None
Children
Created on
April 15, 2012 at 12:18 PM UTC
Updated on
April 15, 2012 at 12:18 PM UTC
Description

Pins Tool: Select or freeze segments you want pinned in place; they will pivot around their centres, while you work on the protein.

Best for


Code


--Stay Here! (Pins Tool) --Created by Tristan L Bailey; assisted by brow42 --Note: This script creates 6 bands from each selected and/or frozen segment's centre, using the strength that the user has specified, in an attempt to keep the segments pivoting around their initial placement. A recent update allows the script to be used in both interfaces (Selection and Original). Frozen segments MUST be used if user is working in the Original Interface. local dialogbox = dialog.CreateDialog("Stay Here! v0.3") local SelCount = selection.GetCount() local FCount = freeze.GetCount() if SelCount == 0 and FCount == 0 then dialogbox.Label1 = dialog.AddLabel("\nSelect or freeze one or more segments before running\nthis recipe.") dialogbox.OK = dialog.AddButton("OK", 1) dialog.Show(dialogbox) else local SegCount = structure.GetCount() local bandAdd = band.Add local bandSS = band.SetStrength local bandSGL = band.SetGoalLength local PinSel = false local PinF = false local BothTypesAvail = false if SelCount > 0 and FCount > 0 then dialogbox.Checkbox1 = dialog.AddCheckbox("Pin selected segments (" .. SelCount .. ")", true) dialogbox.Checkbox2 = dialog.AddCheckbox("Pin frozen segments (" .. FCount .. ")", true) BothTypesAvail = true elseif SelCount > 0 then dialogbox.Label1 = dialog.AddLabel("Pin selected segments (" .. SelCount .. ")") PinSel = true else dialogbox.Label1 = dialog.AddLabel("Pin frozen segments (" .. FCount .. ")") PinF = true end dialogbox.Label2 = dialog.AddLabel("Choose the strength of the bands:") dialogbox.Slider1 = dialog.AddSlider(" Default: 8", 8, 0, 10, 1) dialogbox.Cancel = dialog.AddButton("Cancel", 0) dialogbox.OK = dialog.AddButton("OK", 1) if dialog.Show(dialogbox) == 1 then local Strength = dialogbox.Slider1.value local i, j, k, L = 0, 0, 0, 0 local x, y local rad90 = math.rad(90) local rad180 = math.rad(180) if BothTypesAvail then --If the user has unchecked both checkboxes, pin selected segments by default if (not dialogbox.Checkbox1.value) and (not dialogbox.Checkbox2.value) then PinSel = true else PinSel = dialogbox.Checkbox1.value PinF = dialogbox.Checkbox2.value end end --Find selected segments for i = 1, SegCount do if (selection.IsSelected(i) and PinSel) or (freeze.IsFrozen(i) and PinF) then --Make x and y indicies different from selected segment if i ~= 1 then x = i - 1 if i ~= SegCount then y = i + 1 else y = SegCount - 2 end else x = 2 y = 3 end --Band to empty space bandAdd(i, x, y, 0.5, 0, 0) bandAdd(i, x, y, 0.5, rad90, 0) bandAdd(i, x, y, 0.5, rad90, rad90) bandAdd(i, x, y, 0.5, rad180, 0) bandAdd(i, x, y, 0.5, rad90, rad180) bandAdd(i, x, y, 0.5, rad90, math.rad(270)) j = j + 1 k = j * 6 for L = k - 5, k do bandSS(L, Strength) bandSGL(L, 0) end end end --Deselect / unfreeze segments, only if used in script if PinSel then selection.DeselectAll() end if PinF then freeze.UnfreezeAll() end end end

Comments


tristanlbailey Lv 1

OK, so after taking a 2 month break from playing Foldit, I couldn't resist plunging myself into the Immunotherapy and CO2 puzzles. While playing the Immunotherapy puzzle, a thought occured to me when I was watching Rav3n's Mutate Combo recipe; would it be any more useful to force the three segments to stay almost exactly where I wanted them, while they were mutated? I was reminded by an idea which I brought up for inclusion in Foldit; the Pins Tool.

The idea can be seen here:

http://fold.it/portal/node/990659

I decided to try my hand at a V2 Lua script/recipe, to attempt to both illustrate my idea, and to maybe provide something useful for Folders to try at the same time.

Initially, I tried to set a band on a particular segment to a length of '0.01', but that caused the band to push the segment away during a wiggle. After some more thinking and testing, I found out that a length of '3.5' appeared to be the right length setting to keep the segment where it was, and modified the script to create 6 bands out from any segments selected by the user (they look like jacks).

I set the default strength to '8' out of '10', which allows for a little movement from centre, but not much. The user can change the strength value with a slider control.

So, you can use it on segments that you want kept in a particular position in space, while allowing the rest of the backbone to freely pivot around those segments. Since the script works on selected segments, you need to be using the "Selection Interface" to make it work (sigh). The script is by no means perfect to the cause, but better than nothing.

To perhaps get a better idea of what I'm getting at, if you are playing Puzzle 539 (Beginner Immunotherapy Design Puzzle), and you pull up or down on segment #121, the end of segment #119 stays exactly where it is (locomotively). Again, if you instead pull on segment #119, the end of segment #121 will stay exactly where it is. They appear to be pinned in space; the end 'atoms' of the segments won't move locomotively while opposite, but will still allow for rotation (or pivoting).

tristanlbailey Lv 1

The recipe has now been modified to work in both Selection and Original Interfaces. If you are using the recipe in the Original Interface, you will need to freeze each segment first. Since the recipe can't detect which interface you are using, it will work on both selected and frozen segments.

Thanks goes to brow42 for this idea.

tristanlbailey Lv 1

I neglected to include the behaviour of the checkboxes before, so I have updated the recipe again, and they should now be working properly. Also, the segments should not be unfrozen or deselected, if the recipe is cancelled on the dialog box.

If a user wishes to use the script in the Selection Interface, the recipe can accept both selected segments, and frozen segments. The checkboxes for these options should only appear in the Selection Interface, when both selected and frozen segments exist. The default is to work with both types, if both are present.