Icon representing a recipe

Recipe: Scoremod Alpha

created by man_the_stan

Profile


Name
Scoremod Alpha
ID
108629
Shared with
Public
Parent
Scoremod Pre-Alpha
Children
None
Created on
April 05, 2024 at 18:52 PM UTC
Updated on
April 05, 2024 at 18:53 PM UTC
Description

Easily change/reset subscore importances and enable/disable filters. (Set a keyboard shortcut for it for maximum workflow enhancement!)

Improvements from Pre-Alpha:
- Added more fine-grained reset options (and Auto is not the default reset wiggle power anymore)
- Removed APPLY button (was it useful to anyone?)
- Re-labeled RESET button (removed ellipses)

Best for


Code


-- SCOREMOD v. 0.0.2 (alpha) -- man_the_stan if not (_Scoremod and _Scoremod.version and _Scoremod.version == '0.0.2') then _Scoremod = { version = '0.0.2'; origParams = {}; subscoreNames = { "Packing", "Hiding", "Pairwise", "Density" }; paramNames = { "Clash", "SidechainHBond", "BackboneHBond", "Packing", "Hiding", "Pairwise", "Density", "!WigglePower", "!FiltersDisabled" }; ---@param str string # parameter name (with optional "!" prefix to disable "Importance" suffixing) ---@param prefix string ---|"'Get'" # Get function (takes no arguments) ---|"'Set'" # Set function (takes a single argument) ---@return string paramFcn paramFcn = function(str, prefix) return prefix .. (string.byte(str) == 33 and string.sub(str, 2) or (str .. "Importance")) end; wiggleLetterToNum = function(str) return str == "l" and 1 or str == "m" and 2 or str == "h" and 3 or 0 end; wiggleNumToLetter = function(num) return select(num + 1, "a", "l", "m", "h") end; } for _,str in ipairs(_Scoremod.paramNames) do _Scoremod.origParams[str] = behavior[_Scoremod.paramFcn(str, "Get")]() end ---@param paramNames? string[] ---@param params? table ---@param show boolean ---@overload fun(paramNames?: string[], params?: table, show?: `false`): table ---@overload fun(paramNames?: string[], params?: table, show?: `true`): integer _Scoremod.CreateDialog = function(paramNames, params, show) paramNames = paramNames and paramNames or _Scoremod.paramNames params = params and params or {} local dia = dialog.CreateDialog("Scoremod") -- Width of dialog: approximately 53 characters local setApplyText, importanceText, otherText, resetText = -- " " " -------------------- SET/APPLY --------------------", " Importance Parameters", " Other parameters", " ---------------------- RESET ----------------------" dia.setApplyLabel = dialog.AddLabel(setApplyText) dia.ImportanceLabel = dialog.AddLabel(importanceText) for _,str in ipairs(paramNames) do --[[if str == "!SetFiltersDisabledbled" then dia[str] = dialog.AddCheckbox("Disable filters", params[str] and params[str] or behavior.GetFiltersDisabled()) elseif str == "!WigglePower" then dia[str] = dialog.AddSlider("Wiggle power (0=auto)", 0, behavior.HighPowerAllowed() and 3 or 2, 0, _scoremod_data.wiggleLetterToNum(params[str] and params[str] or behavior.GetWigglePower())) else --]] if string.byte(str) ~= 33 then dia[str] = dialog.AddSlider(str, params[str] and params[str] --[[@as number]] or behavior[_Scoremod.paramFcn(str, "Get")](), 0, str == "Clash" and 1 or 3, 2) end end dia.OtherLabel = dialog.AddLabel(otherText) dia["!FiltersDisabled"] = dialog.AddCheckbox("Disable filters", params["!FiltersDisabled"] and params["!FiltersDisabled"] or behavior.GetFiltersDisabled()) dia["!WigglePower"] = dialog.AddSlider("Wig pwr (0=auto)", _Scoremod.wiggleLetterToNum(params["!WigglePower"] and params["!WigglePower"] or behavior.GetWigglePower()), 0, behavior.HighPowerAllowed() and 3 or 2, 0) dia.spacer1 = dialog.AddLabel("") dia.resetLabel = dialog.AddLabel(resetText) dia.resetClash = dialog.AddCheckbox("CI to 1", true) dia.resetSidechainHBond = dialog.AddCheckbox("SC HBonds to 1", true) dia.resetBackboneHBond = dialog.AddCheckbox("BB HBonds to 1", true) dia.resetSubscores = dialog.AddCheckbox("Subscores to 1", true) dia.resetWiggle = dialog.AddCheckbox("WigPow to Low", true) dia.resetWiggleAuto = dialog.AddCheckbox("* WP to Auto instead of Low", false) dia.resetFilters = dialog.AddCheckbox("(Re-)enable filters", true) dia.resetCutbands = dialog.AddCheckbox("(Re-)enable cut bands", true) dia.spacer2 = dialog.AddLabel("") dia.resetLabel2 = dialog.AddLabel("To reset the settings without further modification") dia.resetAndSet = dialog.AddCheckbox("Reset Immediately", false) dia.spacer3 = dialog.AddLabel("")--"12345678901234567890123456789012345678901234567890123456789012345678901234567890") dia.spacer4 = dialog.AddLabel("") -- dia.Apply = dialog.AddButton("Apply", 3) dia.Set = dialog.AddButton("Set", 2) dia.Reset = dialog.AddButton("Reset", 1) dia.Cancel = dialog.AddButton("Cancel", 0) if show then return dialog.Show(dia) else return dia end end ---@param resp integer _Scoremod.HandleDialogResponse = function(resp, params, dia) for k,v in pairs(params) do print(k, v) end if resp == 1 then -- Reset; TODO for _,str in ipairs(_Scoremod.paramNames) do if string.byte(str) ~= 33 then if params["reset" .. str] then params[str] = 1.00 else params[str] = nil end elseif str == "!WigglePower" then if params.resetWiggle then params[str] = (params.resetWiggleAuto and "a" or "l") else params[str] = nil end else if not params.resetFilters then params[str] = false else params[str] = nil end end end if not params.resetAndSet then return true, params else dia = nil end elseif resp == 0 then -- Cancel return nil, params end if not dia then for _,str in ipairs(_Scoremod.paramNames) do if params[str] then if string.byte(str) ~= 95 then -- print(_scoremod_data.paramFcn(str, "Set")) behavior[_Scoremod.paramFcn(str, "Set")](params[str]) end end end else for _,str in ipairs(_Scoremod.paramNames) do if dia[str] then local val = str == "!WigglePower" and _Scoremod.wiggleNumToLetter(dia[str].value) or dia[str].value behavior[_Scoremod.paramFcn(str, "Set")](val) end end end return (resp == 3), params end _Scoremod.GatherDialogValues = function(dia) local ret = {} local resetSubscores = dia.resetSubscores.value for _,subscore in ipairs(_Scoremod.subscoreNames) do ret["reset" .. subscore] = resetSubscores end for _,param in ipairs({ "resetAndSet", "resetWiggle", "resetWiggleAuto", "resetFilters", "resetCutbands", "resetClash", "resetBackboneHBond", "resetSidechainHBond" }) do ret[param] = dia[param].value end for _,str in ipairs(_Scoremod.paramNames) do if dia[str] then ret[str] = str == "!WigglePower" and _Scoremod.wiggleNumToLetter(dia[str].value) or dia[str].value end -- TODO: else? end return ret end end -- TODO: Presets? do local params, dontExit repeat ---@type table local dia = _Scoremod.CreateDialog(nil, params) --[[@as table]] ---@cast dia -integer local resp = dialog.Show(dia) params = _Scoremod.GatherDialogValues(dia) -- for k,v in pairs(params) do print(k, v) end dontExit, params = _Scoremod.HandleDialogResponse(resp, params) until not dontExit end

Comments