#svl // // pseudorestrain.svl Create pseudoatoms and restraints // // Installation: // Place this svl into $MOE/lib/svl/run replacing with restrain.svl // // Usage for defining pseudoatoms: // 1) Select 'pseudoatom' for Restrain: // 2) Pick as many real atoms as necessary // 3) Pick already picked atoms to unselect, if necessary // 4) Set Weight stronger than that of the normal NOE restraints // 5) Pick 'Create' to locate dummy atom at the average coordinate // of the selected atoms and set restraints to the original distance // from the dummy atom and selected atoms. // // 03-feb-2016 (yk, rsi) replace with MOE2015.10 restrain.svl // 06-aug-2002 (rk, rsi) added pseudoatom definition // // COPYRIGHT (C) 2002-2012 RYOKA SYSTEMS INC. PARTIAL RIGHTS RESERVED. // // based on: // restrain.svl Create restraints // // 23-apr-2012 (al) add UndoSnapshot // 02-jun-2009 (al) add task title to ensure only 1 copy // 13-mar-2002 (ts) restraint upper bound bug fix // 30-oct-2001 (pm) bubbleHelp typos // 25-oct-2001 (pl) added [L,U] to restraints // 16-jul-2001 (pl) add unit conversion for torsion restraints // 21-apr-1999 (jd) Display current value of a dihedral angle // 15-apr-1999 (ms) created // // and: // builder.svl Molecule builder and related tools // // 27-dec-2001 (pm) get the return value from adjust_h // 22-dec-2000 (al) adjust h: just do Add_H (A# atoms handled by Add_H) // 18-dec-2000 (al) New/Add/Strip Hydrogens action buttons; rearrange // 13-dec-2000 (al) clear smiles textfield; save shortcuts to RC (no!) // 23-nov-2000 (al) use aSetDihedralCW instead of CCW // 15-nov-2000 (al) if whole group selected, delete it // 31-aug-2000 (al) make function Builder local; fix auto-renaming // 31-aug-2000 (al) replace multiple singly-connected groups // 28-aug-2000 (al) leave atoms selected; strip H mode/button; shortcuts // 23-feb-2000 (al) atom names are always upper case // 21-feb-2000 (al) fix SO2 // 18-feb-2000 (al) is_chiral: don't filter for tetra centres // 07-feb-2000 (al) fix "More" button; fix set labels on H; fix adjust_ion // 03-feb-2000 (al) use state and sens_status // 28-jan-2000 (al) separate set_panel_sensitivity // 28-jan-2000 (al) bond_atoms: auto-reparent if both chains have 1 res // 18-jan-2000 (al) fix adjust_hintlp; get_subs_atoms; YesNoCancel bonding // 17-jan-2000 (al) make_sp3_chain: return atoms // 05-jan-2000 (al) E/Z across dbl bond only; dihedral: higher CIP 1st // 29-nov-1999 (al) color buttons // 17-nov-1999 (al) report area // 10-nov-1999 (al) multiple substitution; major re-layout // 31-mar-1999 (pm) changed title to Small Molecule Builder // 09-feb-1999 (al) grey out smiles text field if smiles subs forbidden // 08-oct-1998 (al) check atom selection in child task, 'subs' button // 18-jul-1997 (dl) removed help button // 04-jun-1997 (al) Build new molecule using ViewLookAt for origin. // 25-apr-1997 (al) Fix substitute hydrogen bug. // 14-feb-1997 (dl) WindowShow changes // 02-dec-1996 (pl) new function names // 11-oct-1996 (al) separated button labels and SMILES strings // 04-oct-1996 (ms) created version 1.1 // // COPYRIGHT (C) 1999-2001 CHEMICAL COMPUTING GROUP INC. ALL RIGHTS RESERVED. // // PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE IS HEREBY // GRANTED PROVIDED THAT: (1) UNMODIFIED OR FUNCTIONALLY EQUIVALENT CODE // DERIVED FROM THIS SOFTWARE MUST CONTAIN THIS NOTICE; (2) ALL CODE DERIVED // FROM THIS SOFTWARE MUST ACKNOWLEDGE THE AUTHOR(S) AND INSTITUTION(S); (3) // THE NAMES OF THE AUTHOR(S) AND INSTITUTION(S) NOT BE USED IN ADVERTISING // OR PUBLICITY PERTAINING TO THE DISTRIBUTION OF THE SOFTWARE WITHOUT // SPECIFIC, WRITTEN PRIOR PERMISSION; (4) ALL CODE DERIVED FROM THIS SOFTWARE // BE EXECUTED WITH THE MOLECULAR OPERATING ENVIRONMENT (MOE) LICENSED FROM // CHEMICAL COMPUTING GROUP INC. // // CHEMICAL COMPUTING GROUP INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS // SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, // AND IN NO EVENT SHALL CHEMICAL COMPUTING GROUP INC. BE LIABLE FOR ANY // SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER // RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF // CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #set title 'Restraint Create' #set class 'MOE:interactive' #set version '2012.04' #set main 'Restrain' // Return an English string representing integer n. // If full_name is true and 0 "23-rd" local function ordinal_string [n, full_name] const NAME = ["first", "second", "third", "fourth", "fifth", "sixth"]; const NTH = ["th", "st", "nd", "rd"]; if n > 0 and n <= length NAME and orE full_name then return NAME(n); endif local k = mod [abs(n), 10]; return swrite ['{}-{}', n, NTH(inc (k*(k<=3)))]; endfunction const CTYPE = ['distance', 'angle','dihedral', 'pseudoatom']; const ASIZE = [2, 3, 4, 7]; // Interactively creates new restraints of an arbitrary type (one of CTYPE). // Using an atom prompter in the main window, the function asks for a sequence // of atoms involved in the restraints. The function iterates the process // for more restrains. The loop is terminated either by killing the // task or terminating the atom prompter. (Note: currently, however, // the atom prompter can be terminated only by a task-killing ESC.) local function Restrain ctype const TASK_TITLE = 'MOE:Restrain'; if m_join [TASK_TITLE, task_title task_keylist[]] then return; endif if 'child' <> second task_fork [errmsg:'ignore'] then return; endif task_settitle [-1, TASK_TITLE]; if ctype === [] then ctype = 'distance'; endif // Restrain type: #of atoms forming the restraint, restraint name local cidx = max [1, indexof [ctype, CTYPE]]; static st_dum_chain = 0; // for creating dummy atom const PANEL = [ name : 'shell', location: 'MOE', mode: 'pickAtom', resizeH:1, bubbleHelp: 'Pick atoms to append them the list of atoms to be restrained.\n' 'Pick an atom already in the list to remove it from the list.\n' 'When the list is complete, press Create to create the restraint.\n' 'Press Esc to exit at any time.' , Option : [ name: 'ctype', title: 'Restrain:', type: 'int', text: CTYPE, onTrigger: 'return', bubbleHelp: 'Type of restraint to be created.' ], Text : [ name: 'value', title: 'Current:', type: 'real', sensitive: 0, bubbleHelp: 'Current value of the selected restraint\n' '(Angles are measured in degrees.)' ], Text : [ name: 'target', title: 'Target:', type: 'real', allowBlank: 0, bubbleHelp: 'Desired lower bound of the restraint\n' '(Angles are measured in degrees.)' ], Text : [ name: 'target_u', type: 'real', allowBlank: 0, bubbleHelp: 'Desired upper bound of the restraint\n' '(Angles are measured in degrees.)' ], Text : [ name: 'weight', title: 'Weight:', type: 'real', min: 0, bubbleHelp: 'Penalty associated with the selected restraint.' ], Button : [ name: 'create', text: 'Create', onTrigger: 'validate', sensitive: 0, bubbleHelp: 'Create the selected restraint.' ], Label:[ name:'msg' ] ]; local wkey = WindowCreate PANEL; WindowSetData [wkey, [weight: 1, ctype:cidx]]; local prio = task_prio 0; SaveSelection[]; local atoms = []; // atoms to participate in the restraint // The event loop: loop // Drop excess atoms (if the restraint type has changed) if CTYPE(cidx) <> 'pseudoatom' then atoms = keep [atoms, ASIZE(cidx)]; endif local natoms = length atoms; // Update the appearance of the prompter area local value = 0; if (CTYPE(cidx) <> 'pseudoatom') and natoms === ASIZE(cidx) then if CTYPE(cidx) === 'distance' then value = aDist atoms; elseif CTYPE(cidx) === 'angle' then value = 180/PI * aAngle atoms; elseif CTYPE(cidx) === 'dihedral' then value = 180/PI * aDihedralCW atoms; endif WindowSetAttr [wkey, [ target: [sensitive: 1], target_u: [sensitive: 1], weight: [sensitive: 1], create: [sensitive: 1], msg: [text: 'Press Create...'] ]]; WindowSetData [wkey, [ value: value, weight: 1 ]]; elseif CTYPE(cidx) === 'pseudoatom' and natoms > 0 then WindowSetAttr [wkey, [ target: [sensitive: 0], target_u: [sensitive: 0], create: [sensitive: 1], msg: [text: 'Press Create...'] ]]; WindowSetData [wkey, [value: 0, weight: 10, ctype:cidx ]]; else WindowSetAttr [wkey, [ create: [sensitive: 0], msg: [text: token swrite ['Pick {} atom...', token ordinal_string [inc natoms, 1]]] ]]; WindowSetData [wkey, [ value: 0 ]]; endif // Set atom selection to the list of atoms to be restrained aSetSelected [Atoms[], indexof [Atoms[], atoms]]; // Get the next window event local [v, t] = WindowWait wkey; // Picking an atom if t === 'shell' then local atom = v.shell; // atoms = cat [ diff[atoms, atom], atom ]; if length atom == 0 then break; endif if indexof [atom, atoms] then atoms = diff [atoms, atom]; // remove from the list else atoms = append [atoms, atom]; // append to the list endif // Changing the restraing type elseif t === 'ctype' then cidx = v.ctype; // Creating a restraint elseif t === 'create' then if CTYPE(cidx) <> 'pseudoatom' and natoms === ASIZE(cidx) then if CTYPE(cidx) === 'angle' or CTYPE(cidx) === 'dihedral' then v.target = v.target*(PI/180); v.target_u = v.target_u*(PI/180); endif UndoSnapshot []; RestraintCreate [ CTYPE(cidx), [atoms], [[v.target, v.target_u]], v.weight ]; elseif CTYPE(cidx) === 'pseudoatom' then if not length atoms then return; endif local is_dum = aElement atoms=='LP' and aBondCount atoms==0; atoms = atoms | not is_dum; if not length atoms then return; endif // if all selected came from same res, add dummy to res local dum_atom; if length uniq aResidue atoms == 1 then dum_atom = oCreate aResidue first atoms; else if not st_dum_chain then st_dum_chain = oCreate 0; endif cSetHeader [st_dum_chain, 'Dummies']; local dum_res = oCreate st_dum_chain; rSetName [dum_res, 'DUM']; dum_atom = oCreate dum_res; endif aSetName [dum_atom, 'DUM']; aSetElement [dum_atom, 'LP']; aSetInert [dum_atom, 0]; aSetRGB [dum_atom, icolor 'red']; aSetColorBy [dum_atom, 'rgb']; aSetPos [dum_atom, oCentroid atoms]; aSetNucleusLook [dum_atom, 'small-sphere']; v.target = aDist [dum_atom, atoms]; v.target_u = v.target; RestraintCreate ['distance', tr[dum_atom, atoms], tr[v.target, v.target_u], v.weight ]; endif atoms = []; endif endloop if wkey then WindowDestroy wkey; endif RestoreSelection[]; task_prio prio; endfunction