Icon representing a recipe

Recipe: The Hedgehog 1.1

created by isaksson

Profile


Name
The Hedgehog 1.1
ID
101696
Shared with
Public
Parent
None
Children
None
Created on
December 20, 2015 at 22:08 PM UTC
Updated on
December 20, 2015 at 22:08 PM UTC
Description

The Hedgehog 1.1 by isaksson

Best for


Code


--[[ The Hedgehog LUA V2 by Lennart Isaksson Description: Early game usage. Useful to hold large sections of structure in place then wiggle. A hint would be to use "insert cut" on Loop structure between Helix and Sheet structures. This script creates 6 bands perpendicular toward each other on each marked segment. 1a) Mark a segment by freeze it, ctr + point with the mouse. 1b) Each marked segment will get 6 perpendicular bands. 2) Experimental mode. Respective band is now changed in length and by doing that it will stretche the hole structure. If positive score is found it will store that length, and continue with the next band. ]]-- version = "1.1" segCnt = structure.GetCount() rho = 3 pos_theta = {0,math.pi/2,math.pi/2,math.pi/2,math.pi/2,math.pi} pos_phi = {0,0,math.pi/2,math.pi,(math.pi/2)*3,0} math.randomseed(os.time()) math.random() -- Has to be use once, otherwise the random number doesn't produce any correct random number max_value_number_of_runs = 10 flag_debug = false save.Quicksave(100) function showConfigDialog() local ask = dialog.CreateDialog("The Hedgehog ".." "..version) ask.a0 = dialog.AddButton("Ok",0) ask.a1 = dialog.AddButton("Cancel",1) --options ask.dd1 = dialog.AddSlider("Selection {1,2}:",1,1,2,0) ask.t1 = dialog.AddLabel("(1) = Add bands ...") ask.c0 = dialog.AddCheckbox("Bands on freezed segment",true) ask.c1 = dialog.AddCheckbox("Remove frozen segments",true) ask.c2 = dialog.AddSlider("Band Strength:",1.0,0.1,2.0,1) ask.t2 = dialog.AddLabel("(2) = Experimental mode, ... it moves each band ...") ask.c3 = dialog.AddSlider("Delta Goal:",0.5,0.1,2.0,1) local result = dialog.Show(ask) selection_value = ask.dd1.value if result == 1 then cleanup() end flag_checkbox_freezed_segment = ask.c0.value flag_checkbox_remove_frozen_segments = ask.c1.value value_strength = ask.c2.value value_delta_goal = ask.c3.value end function WA(Wiggle_runs,p) runs = 1 PES = current.GetEnergyScore() structure.WiggleAll(Wiggle_runs) while abs(current.GetEnergyScore()-PES) > p and runs < max_value_number_of_runs do if flag_debug == true then print("# of iterations: "..runs..", Limit:"..max_value_number_of_runs) print("diff: "..(current.GetEnergyScore()-PES)..", Limit:"..p) end runs = runs + 1 PES = current.GetEnergyScore() structure.WiggleAll(Wiggle_runs) end if flag_debug == true then print("# of iterations: "..runs..", Limit:"..max_value_number_of_runs) print("diff: "..(current.GetEnergyScore()-PES)..", Limit:"..p) end end function abs(x) if x < 0 then return -x else return x end end function get_time() return os.date("%X",os.time()) end function main () print(get_time()) print("The Hedgehog ".." "..version) main_start = current.GetEnergyScore() print("Start Score:"..main_start) showConfigDialog() behavior.SetClashImportance(1.0) if selection_value == 1 then if flag_checkbox_freezed_segment == true then for i = 1 , segCnt-1 , 1 do if freeze.IsFrozen(i) then setbands(i) else end end else for i = 1 , segCnt-1 , 1 do if freeze.IsFrozen(i) then else setbands(i) end end end print("Number of bands:"..band.GetCount()) if flag_checkbox_remove_frozen_segments == true then freeze.UnfreezeAll() end end if selection_value == 2 then for idx = 1 , band.GetCount() , 1 do print("Band Index: "..idx.."/"..band.GetCount()) before = band.GetGoalLength(idx) band.SetGoalLength(idx,band.GetGoalLength(idx)+value_delta_goal) start_score = current.GetEnergyScore() WA(2,0.1) structure.MutateSidechainsAll(1) WA(2,0.1) end_score = current.GetEnergyScore() diff = end_score-start_score print("Score:"..diff) if diff > 0 then save.Quicksave(100) else save.Quickload(100) end end end main_end = current.GetEnergyScore() print("Final Score:"..main_end) print("Main Diff Score:"..(main_end - main_start)) end function setbands(i) j = math.random(segCnt) k = math.random(segCnt) while (i == j) or (i == k) or (j == k) do j = math.random(segCnt) k = math.random(segCnt) end for idx = 1, #pos_theta, 1 do theta = pos_theta[idx] phi = pos_phi[idx] band.Add(i,j,k,rho, theta, phi) index = band.GetCount() strength = band.GetGoalLength(index) band.SetStrength(index,value_strength) end end function cleanup(err) print("Clean up!") freeze.UnfreezeAll() save.Quickload(100) band.DeleteAll() print(err) end -- main call xpcall ( main, cleanup ) --end of script

Comments


isaksson Lv 1

Early game usage.

Useful to hold large sections of structure in place then wiggle.
A hint would be to use "insert cut" on Loop structure between Helix and Sheet structures.

This script creates 6 bands perpendicular toward each other on each marked segment.