Icon representing a recipe

Recipe: MicroIdealize 1.1

created by StackOverflow

Profile


Name
MicroIdealize 1.1
ID
49016
Shared with
Public
Parent
MicroIdealize 1.0
Children
Created on
May 02, 2014 at 12:36 PM UTC
Updated on
May 02, 2014 at 12:36 PM UTC
Description

See MicroIdealize 1.0

Best for


Code


kOriginalStructureOrNewBest = 1 -- the starting structure, or any subsequent improvement, will be stored in this quicksave slot best_score = 0 idealize_length = 3 min_residue = 1 max_residue = 999 sphere = {} kSphereRadius = 10 function r3 ( i ) -- printing convenience return i - i % 0.001 end function GetScore () score = current.GetEnergyScore () return score end function SphereSelect ( start_idx , end_idx ) for i = 1 , n_residues do sphere [ i ] = false end for i = 1 , n_residues do for j = start_idx , end_idx do if ( structure.GetDistance ( i , j ) < kSphereRadius ) then sphere [ i ] = true end end end selection.DeselectAll () for i = 1 , n_residues do if ( sphere [ i ] == true ) then selection.Select ( i ) end end end function Go ( sz ) for i = min_residue - 1 , max_residue - sz do print ( i + 1 .. "-" .. i + sz ) save.Quickload ( kOriginalStructureOrNewBest ) if ( i > 0 ) then structure.InsertCut ( i ) end if ( i < n_residues ) then structure.InsertCut ( i + sz ) end selection.DeselectAll () selection.SelectRange ( i + 1 , i + sz ) structure.IdealizeSelected () if ( i > 0 ) then structure.DeleteCut ( i ) end if ( i < n_residues ) then structure.DeleteCut ( i + sz ) end SphereSelect ( i + 1 , i + sz ) structure.WiggleSelected ( 12 ) score = GetScore () if ( score > best_score ) then best_score = score print ( "Improvement to ".. r3 ( best_score ) ) save.Quicksave ( kOriginalStructureOrNewBest ) end end end -- in puzzles where segments are locked, do not allow user to start there, find the first unlocked segment function GetPuzzleStart () --StackOverflow if ( structure.IsLocked ( 1 ) ) then for s = 2 , structure.GetCount () do if ( structure.IsLocked ( s ) == false ) then return s -- this is the first unlocked segment, this is where the user puzzle truly begins end end return 1 -- ummm, whole puzzle is locked? else return 1 end end function GetParameters () local dlog = dialog.CreateDialog ( "MicroIdealize" ) local n_min = GetPuzzleStart () dlog.idealize_length = dialog.AddSlider ( "Idealize length" , idealize_length , 1 , 20 , 0 ) dlog.min_residue = dialog.AddSlider ( "Min residue" , n_min , n_min , n_residues , 0 ) dlog.max_residue = dialog.AddSlider ( "Max residue" , n_residues , n_min , n_residues , 0 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then idealize_length = dlog.idealize_length.value min_residue = dlog.min_residue.value max_residue = dlog.max_residue.value return true else return false end end function main () print ( "MicroIdealize" ) band.DisableAll () save.Quicksave ( kOriginalStructureOrNewBest ) best_score = GetScore () print ( "Start score " .. r3 ( best_score ) ) n_residues = structure.GetCount () if ( GetParameters () == false ) then return -- graceful exit end Go ( idealize_length ) save.Quickload ( kOriginalStructureOrNewBest ) end function cleanup () print ( "Cleaning up" ) behavior.SetClashImportance ( 1.0 ) save.Quickload ( kOriginalStructureOrNewBest ) band.EnableAll () end --main () xpcall ( main , cleanup )

Comments


StackOverflow Lv 1

I've added a check for docking puzzles, where most of the puzzle is locked (greyed out).

In those cases, the slidebars do not start at segment 1, but at whatever segment is the start of the user part of the puzzle (unlocked).

Just a convenience thing.

Full credit to spvincent for the original script.