Icon representing a recipe

Recipe: Band Beta Carbons v0.2

created by Susume

Profile


Name
Band Beta Carbons v0.2
ID
102087
Shared with
Public
Parent
Band Beta Carbons v0.1
Children
None
Created on
July 08, 2016 at 13:59 PM UTC
Updated on
July 08, 2016 at 13:59 PM UTC
Description

Adds a band between the beta carbons of two residues. If exactly two residues are selected it bands those two, or if there are not exactly two residues selected, it lets you choose two residues in dialog.

Best for


Code


--Band Beta Carbons --v0.1 adds a band between the beta carbons of the chosen residues --v0.2 if exactly 2 residues are selected, adds band between those without dialog SCRIPT = "Band Beta Carbons" VERSION = "0.2" SegCount = structure.GetCount() SelectedCount = 0 BCount = 0 FromRes = 0 ToRes = 0 function GetTwoSelected() for i = 1, SegCount do if selection.IsSelected(i) then SelectedCount = SelectedCount+1 if SelectedCount==1 then FromRes = i elseif SelectedCount==2 then ToRes = i else FromRes = 0 ToRes = 0 return false end end end if SelectedCount==2 then return true else return false end end function GetParams() dlg = dialog.CreateDialog(SCRIPT.." "..VERSION) dlg.FromRes = dialog.AddSlider("From Residue:",0,0,SegCount,0) dlg.ToRes = dialog.AddSlider("To Residue:",0,0,SegCount,0) dlg.ok = dialog.AddButton("OK", 1) dlg.cancel = dialog.AddButton("Cancel", 0) if dialog.Show(dlg) > 0 then FromRes = dlg.FromRes.value ToRes = dlg.ToRes.value return true else print("Dialog canceled") return false end end function BetaCarbon(i) local LastSeg = structure.GetCount() local BETA_CARBON = 5 local TERMINAL_BETA = 6 local CENTER_CARBON = 2 local GLYCINE = "g" if structure.GetAminoAcid(i)==GLYCINE then return CENTER_CARBON elseif i==LastSeg then return TERMINAL_BETA else return BETA_CARBON end end function AddBetaBand() if FromRes~=0 and ToRes~=0 and FromRes~=ToRes then print("Banding from "..FromRes.." to "..ToRes) local b = band.AddBetweenSegments(FromRes, ToRes, BetaCarbon(FromRes), BetaCarbon(ToRes)) if b~=0 then BCount = BCount+1 end else print("From and To must be different and non-zero") end end function Cleanup() print(BCount.." bands placed") end function Main() if GetTwoSelected() then AddBetaBand() elseif GetParams() then AddBetaBand() end Cleanup() end xpcall(Main, Cleanup)

Comments


actiasluna Lv 1

Hi Susume - thanks for making this great recipe. One comment … the slider is very useful, however it's also "touchy" in that it is at least in my experience impossible to select certain residues. Do you have any tips on this? (I can use it by selecting those individual residues but the slider is SO handy for lazy folders like me.)