Icon representing a recipe

Recipe: The Disulfides v1.1.18

created by Jumper2

Profile


Name
The Disulfides v1.1.18
ID
103977
Shared with
Public
Parent
None
Children
None
Created on
September 17, 2020 at 02:17 AM UTC
Updated on
September 17, 2020 at 02:17 AM UTC
Description

Added options for setting band goal length and strength.
Defaults are strength: 9.0 length: 2.0

Best for


Code


--[[ The Disulfides LUA V2 by Lennart Isaksson Description: Finds those disulfides by creating bands between them. Option: Rnd: Random selection of two disulfides and create a band between them. Closest: finds the closest distance between two disulfides and create a band between them. Text Box: Create bands according the text box Options added for band goal length and strength. --JMP ]]-- version = "V2 v1.1.18" math.randomseed(os.time()) math.random() -- Has to be use once, otherwise the random number doesn't produce any correct random number segCnt = structure.GetCount() count_disulfides = 0 disulfides = {} distance = {} disulfides_vector = {} disulfides_pair = "" pair_str = "" bStrength = 9.0 bGoal = 2.0 -- Search for the Disulfides disulfides_tmp = {} for i=1,segCnt,1 do if structure.GetAminoAcid(i) == "c" then disulfides_tmp[#disulfides_tmp+1] = {i} end end --print("total: "..#disulfides_tmp) -- put each Disulfide into a string str = "" for i = 1,#disulfides_tmp,1 do str = str..disulfides_tmp[i][1].." " end disulfides_connection = str --######################################## pair = {} function check_segment(a,b) for i = 1,#pair,1 do --print(pair[i][1]..":"..a..","..pair[i][2]..":"..b..","..pair[i][1]..":"..b..","..pair[i][2]..":"..a) if (((pair[i][1] == a) or (pair[i][2] == b)) or ((pair[i][1] == b) or (pair[i][2] == a))) then return 1 end end return 0 end function get_time() return os.date("%X",os.time()) end function Sort_Ascending(vector,idx) --print("Sorting Ascending ...") for x = 1,#vector-1 do for y = x+1,#vector do if vector[x][idx]>vector[y][idx] then vector[x],vector[y]=vector[y],vector[x] end end end return vector end function get_colon_pairs(v) local d = {} local p1 local p2 for p1 in string.gmatch(v,'([%d]+[:][%d]+)') do --print("p1:"..p1) d = {} for p2 in string.gmatch(p1,'([%d]+)') do --print("p2:"..p2) d[#d+1] = {p2} end band.AddBetweenSegments(d[1][1],d[2][1],6,6) band.SetGoalLength(band.GetCount(),bGoal) band.SetStrength(band.GetCount(),bStrength) end end function showMainConfigDialog() local ask = dialog.CreateDialog("The Disulfides ".." "..version) ask.b0 = dialog.AddButton("Rnd",0) ask.b1 = dialog.AddButton("Closest",1) ask.b2 = dialog.AddButton("Add band",2) ask.b9 = dialog.AddButton("Cancel",9) ask.b3 = dialog.AddButton("Help",3) --options ask.c2 = dialog.AddTextbox("Disulfide(s): ",disulfides_connection) ask.c3 = dialog.AddTextbox("Pair(s): ",disulfides_pair) ask.note = dialog.AddLabel("Band Characteristics:") ask.bGoal = dialog.AddSlider("Goal Length: ", bGoal, 0.0, 5.0, 2) ask.bStrength = dialog.AddSlider("Band Strength: ", bStrength, 0.0, 10.0, 1) selection = dialog.Show(ask) value_connection = ask.c3.value if ((selection >= 0) and (selection <= 3))then bGoal = ask.bGoal.value bStrength = ask.bStrength.value exe_flag = 1 main2() end if (selection == 9) then exe_flag = 0 cleanup() end end function main() print("The Disulfides, version: ".." "..version..", "..get_time()) print("Band Goal: " .. bGoal) print("Band Strength: " .. bStrength) showMainConfigDialog() end function main2() disulfides = {} pair_str = "" pair = {} if exe_flag == 1 then -- Create a list of disulfides with random values for i = 1,segCnt,1 do if structure.GetAminoAcid(i) == "c" then disulfides[#disulfides+1] = {i,math.random(1000)} end end --print("Rnd") if (selection == 0) then disulfides_pair = "" Sorted_Disulfides_vector = Sort_Ascending(disulfides,2) a = disulfides_tmp[math.random(1,#disulfides_tmp)][1] b = disulfides_tmp[math.random(1,#disulfides_tmp)][1] while (b == a) do b = disulfides_tmp[math.random(1,#disulfides_tmp)][1] end pair_str = a..":"..b --print("Segment Index:"..pair_str) band.AddBetweenSegments(a,b,6,6) band.SetGoalLength(band.GetCount(),0.1) band.Delete(band.GetCount()) disulfides_pair = pair_str end --print("Closest") if (selection == 1) then disulfides_pair = "" for i = 1,#disulfides-1,1 do for j = i+1,#disulfides,1 do band.AddBetweenSegments(disulfides[i][1],disulfides[j][1],6,6) --print(band.GetCount()) k = band.GetLength(band.GetCount()) band.Delete(band.GetCount()) distance[#distance+1] = {disulfides[i][1],disulfides[j][1],k} --print(disulfides[i][1]..":"..disulfides[j][1]..", "..k) end end print("") --print("Sorted") Sorted_Distance_vector = Sort_Ascending(distance,3) for i = 1,#Sorted_Distance_vector,1 do --print(Sorted_Distance_vector[i][1].." "..Sorted_Distance_vector[i][2].." "..Sorted_Distance_vector[i][3]) --print("check_segment: "..(check_segment(Sorted_Distance_vector[i][1],Sorted_Distance_vector[i][2]))) if (check_segment(Sorted_Distance_vector[i][1],Sorted_Distance_vector[i][2]) == 0) then pair[#pair+1] = {Sorted_Distance_vector[i][1],Sorted_Distance_vector[i][2]} a = Sorted_Distance_vector[i][1] b = Sorted_Distance_vector[i][2] pair_str = a..":"..b --print("Segment Index:"..pair_str) band.AddBetweenSegments(a,b,6,6) band.Delete(band.GetCount()) --band.SetGoalLength(band.GetCount(),0.1) disulfides_pair = disulfides_pair .. pair_str .. " " end end end --print("Text Box") if (selection == 2) then if string.len(value_connection) > 0 then get_colon_pairs(value_connection) disulfides_pair = value_connection else print("Text Box is Empty!") print("Run Rnd or Closest first.") end end --print("Help") if (selection == 3) then print("Rnd: will select a pair randomly") print("Closest: will select all closest pair(s)") print("Add band: will create band(s) defined in the Pair(s) text box") end end exe_flag = 0 showMainConfigDialog() end function cleanup(err) end -- main call xpcall ( main, cleanup ) --end of script

Comments


bravosk8erboy Lv 1

sometimes bonds to the wrong atom (the carbon before) if the Cysteine is the first or last segment of the protein. not sure if they count atoms differently on that segment for cysteine. this happened to me on puzzle 2528 as an example.