Profile
- Name
- Make 4 Helix
- ID
- 103468
- Shared with
- Public
- Parent
- Local Mutate 3.2
- Children
- Created on
- May 05, 2020 at 16:43 PM UTC
- Updated on
- May 05, 2020 at 16:43 PM UTC
- Description
For starting puzzle, first step in building a four helix "box"
Best for
Code
-- How to use this script to make a four helix block
-- This is meant for a docking type puzzle like 1831 Corona Virus Bind
-- Step 1: Set k_pass to 1 and run the script
-- This will start the puzzle over and try to make 4 evenly spaced
-- helix structures.
--
-- Step 2: Go to each of the helix structures and do "IdealizeSS". This can't
-- be done in the script for whatever reason, so need to do this by hand.
-- If this is a docking puzzle, you might want to move the user_residue_count
-- portion away from docking point for now.
--
-- Step 3: Set k_pass to 2 and run this script again
-- This will setup bands and freeze the helix structures
--
-- Step 4: Run wiggle until a box forms. This will only be approximately box-like.
-- Sometimes a box will not form as the helix structures get in each other's way.
-- You might need to do some manual pulling - or simply try again.
--
-- Step 5: Run whatever else you want to improve your score.
-- At some point unfreeze the helix structures so they can change shape too.
-- Also at some point, move the user structure back into place to dock it.
--
-- Note: You can always run the script with k_pass set to 2 to setup the bonds and freezing again.
k_pass = 1
k_helix_amino = "A" -- Helix loving amino acids are M,A,L,E,K. Set to "" to not change
k_loop_amino = "G" -- G is the most flexible amino acid. Set to "" to not change
start_time = 0
function FindFirstAvailable()
for seg_idx = 1, structure.GetCount() do
if not structure.IsLocked(seg_idx) then
return seg_idx
end
end
return nil
end
function IdealizeAll()
selection.SelectAll()
structure.IdealizeSelected()
selection.DeselectAll()
end
function FreezeRange(from_seg_idx, to_seg_idx)
selection.DeselectAll()
for seg_idx = from_seg_idx, to_seg_idx do
selection.Select(seg_idx)
end
freeze.FreezeSelected(true, true)
selection.DeselectAll()
end
function MakeMultipleHelixTable(helix_count, loop_size)
n_residues = structure.GetCount()
user_residue_start = FindFirstAvailable()
user_residue_count = structure.GetCount() - user_residue_start + 1
print("User Residue Start: " .. user_residue_start)
print("User Residue Count: " .. user_residue_count)
k_non_end_loops = helix_count - 1
length_non_end_loops = k_non_end_loops * loop_size
print("Non-end loops will be " .. length_non_end_loops .. " residues")
helix_size = math.floor((user_residue_count - length_non_end_loops) / helix_count)
print("Make four helix of length " .. helix_size)
helix = {}
loop = {}
last_idx = user_residue_start - 1
for idx = 1, helix_count do
if idx > 1 then
this_loop = {start = last_idx + 1, finish = last_idx + loop_size}
print("Loop start: " .. this_loop.start .. " finish: " .. this_loop.finish)
table.insert(loop, this_loop)
last_idx = last_idx + k_loop_size
end
this_helix = {start = last_idx + 1, finish = last_idx + helix_size}
print("Helix start: " .. this_helix.start .. " finish: " .. this_helix.finish)
table.insert(helix, this_helix)
last_idx = this_helix.finish
end
if (last_idx + 1 < structure.GetCount()) then
this_loop = {start = last_idx + 1, finish = last_idx + loop_size}
print("Loop start: " .. this_loop.start .. " finish: " .. this_loop.finish)
table.insert(loop, this_loop)
end
return helix, loop
end
function MakeMultipleHelix(helix, loop)
print("Start puzzle over")
puzzle.StartOver()
for idx = 1, #helix do
this_helix = helix[idx]
print("Helix start: " .. this_helix.start .. " finish: " .. this_helix.finish)
for seg_idx = this_helix.start, this_helix.finish do
print("Set " .. seg_idx .. " to Helix")
if (k_helix_amino ~= "") then
structure.SetAminoAcid(seg_idx, k_helix_amino)
end
structure.SetSecondaryStructure(seg_idx, "H")
end
end
for idx = 1, #loop do
for seg_idx = loop[idx].start, loop[idx].finish do
print("Set " .. seg_idx .. " to Loop")
if (k_loop_amino ~= "") then
structure.SetAminoAcid(seg_idx, k_loop_amino)
end
structure.SetSecondaryStructure(seg_idx, "L")
end
end
end
function PlaceBands(helix)
band.DeleteAll()
length_helix = structure.GetDistance(helix[1].start, helix[1].finish)
separation = length_helix
for helix_idx = 1, k_helix_count do
first_helix = helix_idx
second_helix = helix_idx + 1
if (second_helix > k_helix_count) then
second_helix = 1
end
print("Add anchor band")
band_idx = band.AddBetweenSegments(helix[first_helix].start, helix[second_helix].finish)
print( "Band: " .. band_idx)
band.SetGoalLength(band_idx, separation)
band.SetStrength(band_idx, 5)
print("Add end band")
band_idx = band.AddBetweenSegments(helix[first_helix].finish, helix[second_helix].start)
print( "Band: " .. band_idx)
band.SetGoalLength(band_idx, separation)
band.SetStrength(band_idx, 5)
end
corner_sep = math.sqrt(2) * separation
print("Add cross bands")
band_idx = band.AddBetweenSegments(helix[1].start, helix[3].start)
print( "Band: " .. band_idx)
band.SetGoalLength(band_idx, corner_sep)
band.SetStrength(band_idx, 5)
band_idx = band.AddBetweenSegments(helix[2].start, helix[4].start)
print( "Band: " .. band_idx)
band.SetGoalLength(band_idx, corner_sep)
band.SetStrength(band_idx, 5)
band_idx = band.AddBetweenSegments(helix[1].finish, helix[3].finish)
print( "Band: " .. band_idx)
band.SetGoalLength(band_idx, corner_sep)
band.SetStrength(band_idx, 5)
band_idx = band.AddBetweenSegments(helix[2].finish, helix[4].finish)
print( "Band: " .. band_idx)
band.SetGoalLength(band_idx, corner_sep)
band.SetStrength(band_idx, 5)
end
function FreezeHelix(helix)
freeze.UnfreezeAll()
for helix_idx = 1, k_helix_count do
FreezeRange(helix[helix_idx].start, helix[helix_idx].finish)
-- for seg_idx = helix[helix_idx].start, helix[helix_idx].finish do
-- freeze.Freeze(seg_idx, true, true)
-- end
end
end
function Main()
start_time = os.time()
n_residues = structure.GetCount()
print("Residue Count: " .. n_residues)
k_helix_count = 4
k_loop_size = 4
helix, loop = MakeMultipleHelixTable(k_helix_count, k_loop_size)
if (k_pass == 1) then
print("First Pass")
MakeMultipleHelix(helix, loop)
IdealizeAll()
save.SaveSecondaryStructure()
print("First Pass done - Do IdealizeSS from the GUI")
else
print("Second Pass")
PlaceBands(helix)
FreezeHelix(helix)
end
print("End")
Cleanup()
end
-- Cleanup for regular run or error
function Cleanup()
print( "Cleaning up" )
end_time = os.time()
print ( "Elapsed time: " .. os.difftime(end_time, start_time) .. " secs" )
end
function ErrorHandler(str)
print( "Error " .. str )
-- Do error handling here
Cleanup()
end
--main ()
xpcall(Main, ErrorHandler)