Icon representing a recipe

Recipe: FreezeShakr 1.1.0

created by donuts554

Profile


Name
FreezeShakr 1.1.0
ID
103569
Shared with
Public
Parent
None
Children
None
Created on
June 22, 2020 at 04:44 AM UTC
Updated on
June 22, 2020 at 04:44 AM UTC
Description

This recipe freezes only the backbone on your protein, and makes two Bands to Space at the first segment that is unlocked, whose strength is changed to literally "shake" the protein forward and backward to gain points. This recipe is similar to Wiggle Sidechains, but you get more points than with Wiggle Sidechains. I would suggest you use this recipe with "Auto" Wiggle Power, and "1.00" Clashing Importance if possible. But this time in version 1.1.0, I fixed the bug which happens on locked segments and made the protein go back to its original position. I also made the protein centered in puzzles with no locked segments. Duly credit goes to Formula350, who inspired and helped me make this recipe, and Susume, who also helped me make this recipe. Of course the Foldit Wiki gets credit.

Best for


Code


versionString = "1.1.0" -- Hello! Welcome to the recipe code of FreezeShakr 1.1.0! Feel free to read through the code. Please PM me if you have any questions or comments. -- This recipe freezes the backbone of your protein, and makes two Bands to Space, whose strength is changed to literally "shake" the protein forward and backward to gain points. -- This recipe is similar to Wiggle Sidechains, but you get more points than with Wiggle Sidechains. -- I would suggest you use this recipe in "Auto" Wiggle Power, and with "1.00" Clashing Importance if possible. -- But this time in version 1.1.0, I fixed the bug which happens on locked segments and made the protein go back to its original position. I also made the protein centered in puzzles with no locked segments. -- -- Duly credit goes to Formula350, who inspired and helped me make this recipe, and Susume, who also helped me make this recipe. Of course the Foldit Wiki gets credit. -- -- Thank you for reading through this message! iterations = 0 dialogResult = 0 totalResidues = structure.GetCount() areThereLockedSegments = false function loadData() print("Loading data...") seg = 1 score = math.floor(current.GetEnergyScore()*100000)/100000 previousScore = score gain = 0 totalGain = 0 dialogResult = 0 print("Data loaded!") end function addBands() print("Adding bands...") while(structure.IsLocked(seg)) do seg = seg + 1 end if seg == 1 then print("There are no locked segments in this puzzle.") seg = 2 else print("There are locked segments in this puzzle.") areThereLockedSegments = true end band.Add(seg, seg - 1, seg + 1, 20, 0, 0) activeBand = band.Add(seg, seg + 1, seg - 1, 20, 0, 0) if areThereLockedSegments then startSegment = seg while(not structure.IsLocked(seg)) do if seg == totalResidues then break else seg = seg + 1 end end seg = seg - 1 band.SetStrength(band.Add(seg, seg - 1, seg + 1, 0.01, 0, 0), 10) band.SetGoalLength(band.GetCount(), 0.0) band.SetStrength(band.Add(seg, seg + 1, seg - 1, 0.01, 0, 0), 10) band.SetGoalLength(band.GetCount(), 0.0) middleSegment = math.floor((seg+startSegment)/2) seg = middleSegment band.SetStrength(band.Add(seg, seg - 1, seg + 1, 0.01, 0, 0), 10) band.SetGoalLength(band.GetCount(), 0.0) band.SetStrength(band.Add(seg, seg + 1, seg - 1, 0.01, 0, 0), 10) band.SetGoalLength(band.GetCount(), 0.0) seg = math.floor((startSegment+middleSegment)/2) band.SetStrength(band.Add(seg, seg - 1, seg + 1, 0.01, 0, 0), 10) band.SetGoalLength(band.GetCount(), 0.0) band.SetStrength(band.Add(seg, seg + 1, seg - 1, 0.01, 0, 0), 10) band.SetGoalLength(band.GetCount(), 0.0) end end function prepProtein() print("Prepping up the protein...") freeze.UnfreezeAll() band.DisableAll() print("Prepping completed!") end function freezeBackbone() print("Freezing backbone...") selection.SelectAll() freeze.FreezeSelected(true, false) end function confirmRun() confirmDialog = dialog.CreateDialog("Confirmation") confirmDialog.Text = dialog.AddLabel("Are you sure you want to run FreezeShakr " .. versionString .. "?") confirmDialog.Yes = dialog.AddButton("Yes", 1) confirmDialog.No = dialog.AddButton("No", 0) dialogResult = dialog.Show(confirmDialog) if (dialogResult == 1) then print("Ok, so you're sure you want to run this recipe after all!") confirmed = true end end function getSettings() settingsDialog = dialog.CreateDialog("Settings") settingsDialog.IterationsText = dialog.AddLabel("How many times shall the protein be shaken?") settingsDialog.IterationsSlider = dialog.AddSlider("Times",100,1,100,0) settingsDialog.IterationsSliderButton = dialog.AddButton("OK", 1) settingsDialog.InfiniteIterationsButton = dialog.AddButton("Unlimited!", 2) dialogResult = dialog.Show(settingsDialog) statusGetSettings = xpcall(setSettings, handleError) if confirmed then print("I need to confirm if these settings are the right ones.") statusConfirmSettings = xpcall (confirmSettings, handleError) end end function setSettings () print("I am setting the settings...") if(dialogResult == 1) then iterations = settingsDialog.IterationsSlider.value print("The number of times is " .. iterations) else if(dialogResult == 2) then print("There are an unlimited number of times!") AreIterationsUnlimited = true else print("The settings dialog has been closed!") confirmed = false end end print("The settings are set!") end function confirmSettings() settingsConfirmationDialog = dialog.CreateDialog("Settings Confirmation") settingsConfirmationDialog.Text = dialog.AddLabel("The settings are:") if AreIterationsUnlimited then settingsConfirmationDialog.Text = dialog.AddLabel("The protein will be shaken with unlimited times.") else if(iterations == 1) then settingsConfirmationDialog.Text = dialog.AddLabel("The protein will be shaken once.") else settingsConfirmationDialog.Text = dialog.AddLabel("The protein will be shaken " .. iterations .. " times.") end end settingsConfirmationDialog.Text2 = dialog.AddLabel("Are these settings the right ones?") settingsConfirmationDialog.Yes = dialog.AddButton("Yes", 1) settingsConfirmationDialog.No = dialog.AddButton("No", 2) dialogResult = dialog.Show(settingsConfirmationDialog); print("I am setting the settings...") if(dialogResult == 1) then print("The settings are confirmed!") else if(dialogResult == 2) then print("The settings are not confirmed.") getSettings() else print("The settings confirmation dialog has been closed!") confirmed = false end end print("The settings are set!") end function main() statusConfirmRun = xpcall(confirmRun, handleError) print("Hello " .. user.GetPlayerName() .. "! Welcome to FreezeShakr " .. versionString .. ", by donuts554!") if confirmed then statusGetSettings = xpcall(getSettings, handleError) if confirmed then print("The recipe has begun!") statusPrepProtein = xpcall(prepProtein, handleError) statusLoadData = xpcall(loadData, handleError) print("Your score is " .. score) statusFreezeBackbone = xpcall(freezeBackbone, handleError) statusAddBands = xpcall(addBands, handleError) print("And now for the freeze shaking!") if AreIterationsUnlimited then statusFreezeShake = xpcall(freezeShake, handleError) while(current.GetEnergyScore()>score) do previousScore = score score = math.floor(current.GetEnergyScore()*100000)/100000 statusFreezeShake = xpcall(freezeShake, handleError) end else if(iterations == 1) then print("Your protein will be shaken once.") else print("Now, your protein will be shaken " .. iterations .. " times.") end counter = 0 while(counter<iterations) do previousScore = score score = math.floor(current.GetEnergyScore()*100000)/100000 statusFreezeShake = xpcall(freezeShake, handleError) counter = counter + 1 end end statusConcludeRecipe = xpcall(concludeRecipe, handleError) else print("Ok, you don't want to use the current settings.") end else print("Oh, it was a mistake. Sorry for the inconvenience.") end end function freezeShake() numberOfBands = band.GetCount() if areThereLockedSegments then band.Disable(numberOfBands) band.Disable(numberOfBands-1) band.Disable(numberOfBands-2) band.Disable(numberOfBands-3) band.Disable(numberOfBands-4) band.Disable(numberOfBands-5) end band.SetStrength(activeBand,0) structure.WiggleAll(10,true,true) band.SetStrength(activeBand,10) structure.WiggleAll(10,true,true) if areThereLockedSegments then freeze.FreezeAll() band.Enable(numberOfBands) band.Enable(numberOfBands-1) band.Enable(numberOfBands-2) band.Enable(numberOfBands-3) band.Enable(numberOfBands-4) band.Enable(numberOfBands-5) band.SetStrength(activeBand,1) structure.WiggleAll(25,true,false) else ui.CenterViewport() end freeze.UnfreezeAll() selection.SelectAll() freeze.FreezeSelected(true, false) previousScore = score score = math.floor(current.GetEnergyScore()*100000)/100000 gain = math.floor((score - previousScore)*100000)/100000 totalGain = totalGain + gain print("Gained " .. gain .. " points, your score is " .. score .. " points.") end function handleError(err) if string.find(err,"Cancelled")~=nil then print("The recipe was cancelled.") statusConcludeRecipe = xpcall(concludeRecipe, handleError) else print("Sadly, there is an error.") print(err) end end function concludeRecipe() print("Restoring the original conditions...") if areThereLockedSegments then band.Delete(band.GetCount()) band.Delete(band.GetCount()) band.Delete(band.GetCount()) band.Delete(band.GetCount()) band.Delete(band.GetCount()) band.Delete(band.GetCount()) end band.Delete(band.GetCount()) band.Delete(band.GetCount()) freeze.UnfreezeAll() band.EnableAll() print("The original conditions are restored.") if totalGain<0 then print("The recipe is done! In total, you lost " .. totalGain .. " points.") else print("The recipe is done! In total, you gained " .. totalGain .. " points!") end end status = xpcall(main, handleError)

Comments


donuts554 Lv 1

I will try to answer your questions and respond to your comments as soon as possible! I encourage any questions or comments to be asked as soon as possible, so I can utilize them in future versions of this recipe and of my future recipes. It will also help me be more experienced, as this is my first recipe.

Thank you for reading through this comment, I appreciate it!

From, donuts554 :D

BootsMcGraw Lv 1

Thank you for joining the many folderers who are unselfishly sharing their tips and tricks through recipes they create.

Some constructive criticism:

This recipe might be good to help a player find an appropriate alignment between the designed protein and the target protein. I was mildly entertained watching the carefully placed bands yank and pull and twist and turn my protein all over the screen, like a gang of bullies would do to a nerd on a school bus.

Please don't present a pop-up box asking me if I want to run the recipe. I wouldn't have invoked the recipe if I didn't. Also, don't ask me immediately after I set the one parameter for number of rounds if I set it correctly.

After four "shake" rounds out of the fifty I requested, the recipe dropped my score by almost five hundred points. Ten more rounds failed to improve my score beyond the five hundred point loss. To remedy this, set a "recent best" at the start of the recipe, and restore this recent best score, should a round fail to improve the player's score.

Cancelling the recipe prematurely crashed FoldIt. Should you discover and fix that bug, set the score to the recent best if a player cancels the recipe before it completes.

I ran the recipe a second time. It did not clear the bands I already had in place, and that may skew the action of the recipe. To remedy this, clear all bands at the start of the recipe. Cancelling the recipe prematurely this second time did not crash the game.

donuts554 Lv 1

I will try to include as much of your advice into the next version of my recipe as soon as possible!

Thank you for the constructive criticism!

From, donuts554.