#svl // sssuperpose.svl Substructure Superposition // // 05-aug-2010 (na) modified for MOE 2009.10 // 17-nov-2009 (na) background flexible alignment // 03-apr-2009 (na) added flexible alignment score option // 03-sep-2008 (rk) removed to del/add hydrogens bonded to the superposed // substructure // 03-sep-2008 (rk) corrected to pass opt properly // 19-jun-2007 (rk) added MOE/batch functionality in db_SSSuperpose // 21-sep-2006 (rk) added default options in db_SSSuperpose // 16-jan-2006 (rk) added fix/unfix superposed substructure functionality // 13-jan-2006 (rk) added refine functionality in FlexAlign // 11-jan-2006 (rk) revised to del/add hydrogens bonded to the superposed // substructure // 10-jan-2006 (rk) added panels to set/select option parameters // 18-aug-2004 (rk) adopted to MOE 2004.03, // i.e., removed del/add hydrogens and deleted '@' im SMILES // 17-dec-2003 (rk) modified to save superposed conformations // and to delete and add hydrogens // 03-dec-2003 (rk) modified to save match and use first match in a molecule // 26-nov-2003 (rk) modified to treat the multi-chain molecules // and use the first molecule/entry as the reference // iff MOE is empty // 21-nov-2003 (rk) modified to adopt the same substructure conformation // 01-dec-2002 (jg) created // // 'Substructure Superposition' superposes multiple molecules automatically // to the position where the substructure in all molecules have the same // position, replace the substructure coordinates with that of the reference, // and minimize the rest atoms of the molecule. // If substructure is provided by SMILES, all molecules will be superposed // onto the first chain. // If it is provided as a selected atoms in MOE window, molecules will be // superposed onto the molecule that selected atoms belong to. // 'SSSuperpose' works for all molecules in MOE window. // 'db_SSSuperpose' works for all molecules in the MDB file. // // 'db_SSSuperpose' ignores chiralities for matching to reference atoms // whose chiralities could be changed on R-group addition // // Usage: // in MOE window // 1. load molecules into MOE window // 2. (File | Open | select 'ssuperpose.svl' | Load SVL File) // 3. select substructure atoms in MOE window // 4. (CLI | SSSuperpose []) // 5. set SMILES and parameters. // If SMILES text box is blank, then the selected atoms in MOE, or, if no // atoms are selected, all atoms in MOE are used as the template // substructure. // 6. click OK // // in DBV // 1. load MDB into DBV // 2. (File | Open | select 'SSSuperpose.svl' | Load SVL File) // 3. copy an entry molecule to MOE // 4. select substructure atoms in MOE window // if its part is used for substructure // 5. (DBV | CLI | db_SSSuperpose []) // 6. set SMILES and parameters. // If SMILES text box is blank, then the selected atoms in MOE, or, if no // atoms are selected, all atoms in the first molecule in MOE, or, if no // molecules are in MOE, the molecule in the first entry in MDB are used // as the template substructure. // 7. click OK // // in MOE/batch // db_SSSuperpose [ // mdb_file: '', // SSSuperpose MDB file name // mol_field: '', // source molecule field // // if '' then the first molecule field is used // dst_field: 'Superposed', // // destination molecule field // // if '' then the molecule field is overwritten // // [ // option parameters // tmp_file: 'template.moe', // // template molecule file name // sm: '', // SMILES for superposeing substructure // esel: 0, // if <> 0 then use selected entries only // // no use in MOE/batch // replace: 0, // if <>0 then replace the matched atom // // coordinates // fix_ss: 0, // if <> 0 then fix the superposed substructure // refine: 0, // if <>0 then flexibly refine existing // // superposition // maxit: 200, // maximum # of iterations // nfail: 20, // # failures to terminate // cutoff: 10, // energy cutoff (best + cutoff) // // min: 0, // if <>0 then minimize the remaining atoms // mm_gtest: 0.1 // gradient test // ] // ] // // COPYRIGHT (C) 2002-2010 RYOKA SYSTEMS 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 // RYOKA SYSTEMS INC. // // RYOKA SYSTEMS INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS // SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, // AND IN NO EVENT SHALL RYOKA SYSTEMS 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 'Database Substructure Superposition' #set class 'MOE:database' #set author 'Junichi Goto & Ryoichi Kataoka' #set version 'RSI 2010.08.05' #set main 'db_SSSuperpose'; // db_SSSuperpose minimizes/reconstructs molecules in a database. // The parameters as follows: // // filename the mdb filename/key // src_field the name of the mol field (char=SMILES, mol=molecule) // options optional flags and arguments static settings_tid; // task id static settings_options; // task communication // options: const SSSUPERPOSE_TAGS = [ // options for SSSuperpose 'sm', 'replace', 'fix_ss', // /* 'maxit', 'nfail', 'cutoff', */ 'refine', 'min', 'mm_gtest' ]; const DB_SSSUPERPOSE_TAGS = [ // options for db_SSSuperpose // /* 'mdb_file', 'mol_field', 'dst_field', */ 'esel', 'tmp_file', 'sm', 'replace', 'fix_ss', // /* 'maxit', 'nfail', 'cutoff', */ 'refine', 'min', 'mm_gtest', 'flexscore' ]; const DB_SSSUPERPOSE_PANEL_TAGS = [ // options for db_SSSuperpose panel 'mdb_file', 'mol_field', 'esel', 'dst_field', 'tmp_file', 'sm', 'replace', 'fix_ss', // /* 'maxit', 'nfail', 'cutoff', */ 'refine', 'min', 'mm_gtest', 'flexscore' ]; const SSSUPERPOSE_DEFAULTS = [ mdb_file: '', // SSSuperpose MDB file name esel: 0, // <>0 => use selected entries only mol_field: '', // source molecule field dst_field: '', // destination molecule field sm: '', // SMILES for superposeing substructure replace: 0, // <>0 => replace the matched atom coordinates fix_ss: 0, // fix the superposed substructure refine: 0, // <>0 => flexibly refine existing superposement maxit: 200, // maximum # of iterations nfail: 20, // # failures to terminate cutoff: 10, // energy cutoff (best + cutoff) min: 0, // <>0 => minimize the remaining atoms mm_gtest: 0.01 // gradient test ]; const SSSUPERPOSE_PANEL_DEFAULTS = [ mdb_file: '', // SSSuperpose MDB file name esel: 0, // <>0 => use selected entries only mol_field: '', // source molecule field dst_field: 'Superposed', // destination molecule field sm: '', // SMILES for superposeing substructure replace: 0, // <>0 => replace the matched atom coordinates fix_ss: 1, // fix the superposed substructure refine: 0, // <>0 => flexibly refine existing superposement maxit: 200, // maximum # of iterations nfail: 20, // # failures to terminate cutoff: 10, // energy cutoff (best + cutoff) min: 0, // <>0 => minimize the remaining atoms mm_gtest: 0.01, // gradient test flexscore: 0 // output FlexAlignScore ]; const OLD=0; const FLEX_DEFAULTS = [ mode: 'flexible', // 'flexible', 'rigid' file: '', // output database filename ('' for refine) dview: 0, // open data viewer? dump: 1, // suppress CLI output if 0 initial_mm: 1, // perform MM prior to search csearch: 1, // perform stochastic conformational search cs_invert: 1, // invert unconstrained chiral centers cs_rotbond: 1, // rotate bonds cs_rotpi: 0, // don't rotate double and conjugated single cs_pulse: 0, // real no.: random cartesian perturbation pot_charge: 1, // calculate forcefield charges before min. cchirality: 1, // add chiral constraints mm_maxit: 500, // maximum number of TN MM iterations // gtest: 0.01, // minimization gradient test gtest: 0.001, // minimization gradient test maxit: 200, // maximum # of iterations nfail: 20, // # failures to terminate heavy_rms: 0.5, // rms tolerance tolerance cutoff: 15.0, // energy cutoff (best + cutoff) maxconf: 100, // max conformations to retain #if OLD alpha: 2.5 // rad / alpha is SD of gaussian #else alpha: 1.0 #endif ]; #if OLD const ABTerms = [ ['donor', 1, 1.0, 'H-Bond Donor'], ['logp', 0, 1.0, 'LogP(o/w)'], ['acceptor', 1, 1.0, 'H-Bond Acceptor'], ['mr', 0, 1.0, 'Molar Refractivity'], ['aromatic', 1, 3.0, 'Aromaticity'], ['charge', 0, 1.0, 'Partial Charge'], ['acid_base', 0, 1.0, 'Acid/Base'], ['volume', 1, 3.0, 'Volume' ], ['hydrophobe', 0, 1.0, 'Hydrophobe' ], ['exposure', 0, 1.0, 'Exposure' ], ['polarh', 1, 1.0, 'Polar Hydrogens' ], ['hfoda', 0, -1.0, 'Hydrophobe - Don/Acc'] ]; const PH4Terms = []; #else const SIMSCALE = 4.0; // Similarity terms (both AB & PH4) are scaled by this // before adding to the Forcefield energy. // Column 1: base name of tagged vector element used in MakeAtomBasedCtx // Column 2: default value for the element t_*, if 0 then term is excluded // Column 3: default value for the element w_*, the weight of the term // Column 4: term description used in GUI and log file const ABTerms = [ ['volume', 1, 1.0, 'Volume' ], ['aromatic', 0, 1.0, 'Aromaticity'], ['donor', 1, 3.0, 'H-Bond Donor'], ['logp', 0, 1.0, 'LogP(o/w)'], ['acceptor', 1, 3.0, 'H-Bond Acceptor'], ['mr', 0, 1.0, 'Molar Refractivity'], ['hydrophobe', 1, 1.0, 'Hydrophobe' ], ['exposure', 0, 1.0, 'Exposure' ], ['hfoda', 1, -1.0, 'Hydrophobe - Don/Acc'], ['charge', 0, 1.0, 'Partial Charge'], ['polarh', 0, 1.0, 'Polar Hydrogens' ], ['acid_base', 0, 1.0, 'Acid/Base'] ]; // Column 1: base name of tagged vector element used in MakeProjFeatCtx // Column 2: default value for the element t_*, if 0 then term is excluded // Column 3: default value for the element w_*, the weight of the term // Column 4: term description used in GUI and log file // Column 5: correspond to labels in the Unified ph4 scheme. const PH4Terms = [ ['ph4don2', 1, 1.0, 'H-Bond Don Projection', 'Don2'], ['ph4aro', 0, 1.0, 'Aromatic Center', 'Aro'], ['ph4acc2', 1, 1.0, 'H-Bond Acc Projection', 'Acc2'], ['ph4o2', 1, 1.0, 'CO2-type Centroid', 'O2'] ]; #endif // TermTag and TermDefault operate on one element of ABTerms or PH4Terms. local function TermTag a = apt tok_cat [['t_', 'w_'], first a]; local function TermDefault t = tag [TermTag t, [t(2),t(3)]]; local function GetDefaults [] = cat [ FLEX_DEFAULTS, [ABopt: cat app TermDefault ABTerms], [PH4opt: cat app TermDefault PH4Terms] ]; // MakeTermGUITagVec operates on one element of ABTerms or PH4Terms. // It creates an item for use in the GUI settings panel. local function MakeTermGUITagVec term local [name, tog, wt, desc] = term; return [ Pager: [ Checkbox : [ name: tok_cat ['t_',name], text: desc], Label: [text: 'XXXXXXXXXXXXXXXXX'] // defines width of the item ], Text : [ name: tok_cat ['w_',name], type: 'real', len: 7] ]; endfunction local function SettingsWindow [] = [ name: 'panel', windowName: 'FlexibleAlignmentSettings', title: 'Flexible Alignment Settings', text: ['OK','Cancel'], Mbox : [ columns: 3, Text : [ name: 'maxconf', title: 'Configuration Limit:', len:10, type:'int', min:0.01, shortcut: ['10','50','100','200'], bubbleHelp: 'The limit on the number of alignment configurations\n' 'to retain (within each chiral class). Only the best\n' 'scoring configurations will be retained.' ], Label : [ text: ' ' ], Label : [ text: ' ' ], Text : [ name: 'alpha', title: 'Alpha:', len:10, type:'real', min:0.01, bubbleHelp: 'The width of the Gaussian function\n' 'centered on each atom / PH4 feature\n' 'for the similarity terms.' ], Label : [ text: ' ' ], Text : [ name: 'heavy_rms', title: 'RMSD Tolerance:', len: 10, type:'real', min:0, shortcut: [ '0.10', '0.25', '0.50', '1.00', '2.00' ], bubbleHelp: 'Two configurations are judged equal if the\n' 'optimal heavy atom RMS superposition distance\n' 'is at less than RMSD Tolerance.' ], Text : [ name: 'gtest', title: 'Gradient Test:', len: 10, type:'real', min:0, shortcut: [ '1.0', '0.1','0.01','0.001' ], bubbleHelp: 'Energy minimization will be terminated when the RMS\n' 'gradient falls below the specified value.' ], Label : [ text: ' ' ], Text : [ name : 'mm_maxit', title: 'Maximum Steps:', len: 10, type: 'int', min: 0, shortcut: [ '100', '200', '300', '400', '500', '1000'], bubbleHelp: 'Energy minimization will be terminated after\n' 'the specified number of iterations.' ] ], Checkbox : [ title: 'Conformational Search:', name: 'cs_rotbond', text: 'Randomly Rotate Single Bonds', bubbleHelp: 'If on then all open chain bonds and flexible\n' 'ring bonds will be set to random dihedral angles.' ], Checkbox : [ name: 'cs_rotpi', text: 'Randomly Rotate Double and Conjugated Bonds', bubbleHelp: 'If on then double and conjugated single bonds\n' 'will be rotated during the search.' ], Checkbox : [ name: 'cchirality', text: 'Preserve Chirality of Unconstrained Chiral Centers', bubbleHelp: 'If on then chiral constraints will be added\n' 'to all chiral centers in order to preserve the\n' 'chirality of the input conformation.' ], Checkbox : [ name: 'cs_invert', text: 'Randomly Invert Unconstrained Chiral Centers', bubbleHelp: 'If on then all unconstrained chiral centers will be\n' 'inverted for each conformer generation attempt. This\n' 'does not apply if Preserve Chirality of Unconstrained\n' 'Chiral Centers is enabled.' ], Hbox : [ extendH: 1, flushLeft:1, Separator : [flushLeft:1], Label : [text: 'Atom Based Similarity Terms', font: 'mediumBold'], Separator : [flushLeft:1] ], Mbox: cat [ [ columns: 4, flushLeft: 1, spacingH: 'medium'], cat app MakeTermGUITagVec ABTerms, [ bubbleHelp: 'The checkboxes enable individual terms\n' 'while the text fields contain the\n' 'weights associated with each term.' ]], Hbox : [ extendH: 1, flushLeft:1, Separator : [flushLeft:1], Label : [text: 'Projected Pharmacophore Similarity Terms', font: 'mediumBold' ], Separator : [flushLeft:1] ], Mbox: cat [ [columns: 4, flushLeft: 1, spacingH: 'medium'], cat app MakeTermGUITagVec PH4Terms, [ bubbleHelp: 'The checkboxes enable individual terms\n' 'while the text fields contain the\n' 'weights associated with each term.\n' 'Terms here are defined using the\n' 'Unified pharmacophore scheme.' ]] ]; local function SettingsPanel settings_options if MOE_BATCH then return; endif if WindowShow ['FlexibleAlignmentSettings',1] then return; endif // local [tid,code] = task_fork [statics:'share', master:'parent']; // if not (code === 'child') then settings_tid = tid; return; endif local wkey = WindowCreate SettingsWindow []; WindowSetData [wkey, settings_options | indexof [tags settings_options, tags WindowValues wkey]]; WindowShow wkey; loop local [val,trig] = WindowWait wkey; if trig === 'panel' then if val.(trig) === 'Cancel' then break; endif settings_options = val; if val.(trig) === 'OK' then break; endif endif endloop WindowDestroy wkey; // settings_tid = []; // exit[]; return settings_options; endfunction ////////////////////////////////////////////////////////////////////////////////// // import functions // *** function MM; function Superpose; function FlexAlign,FlexAlignSimilarityScore; // FixMin fixes specified atoms, minimizes, then unfixes all. local function FixMin [atoms, opt] aSetFixed [ atoms, 1 ]; (MM opt); // minimize with option and default parameters aSetFixed [ atoms, 0 ]; endfunction function FlexAlignInAnotherSystem [fa_opt,atomsets] if 2 > length Chains[] then return; endif if isnull atomsets then atomsets=cAtoms Chains[]; endif local fa_defaults = GetDefaults[]; fa_opt = tagcat [fa_opt, fa_defaults]; // not flat vectors fa_opt=fa_opt | indexof [tags fa_opt, tags fa_defaults]; // fa_opt = tagcat [fa_opt, FLEX_DEFAULTS]; local function mol_ExactCreate mol local chain = mol_Create mol; aSetPos[cat cAtoms chain, get[(mol(4)),[10,11,12]]]; return chain; endfunction local i; local mols = app mol_Extract atomsets; local fixes = aFixed atomsets; local sys = SystemOpen []; // create a new system local oldsys = SystemCurrent sys; // make it the current system local newchains = cat app mol_ExactCreate mols; aSetFixed[cAtoms newchains, fixes]; local msg = Message[0,'Flexalign in background system.']; FlexAlign fa_opt; Message[msg,[]]; local alinedpos = app aPos cAtoms newchains; SystemCurrent oldsys; // restore old system SystemClose sys; // destroy the created system apt aSetPos[atomsets, alinedpos]; endfunction function SSSuperpose_Panel; global function SSSuperpose opt // write 'SSSuperpose opt: '; print opt; if isfalse opt then opt = SSSuperpose_Panel []; if isfalse opt then exit[]; endif endif local fa_defaults = GetDefaults[]; local fa_opt = cat [opt, fa_defaults]; // not flat vectors fa_opt=fa_opt | indexof [tags fa_opt, tags fa_defaults]; // settings_options = fa_opt | indexof [tags fa_opt, tags fa_default]; // local fa_opt = cat [opt, FLEX_DEFAULTS]; // settings_options = fa_opt | indexof [tags fa_opt, SETTINGS_TAGS]; // fa_opt = fa_opt | indexof [tags fa_opt, tags FLEX_DEFAULTS]; // fa_opt = cat [fa_opt, settings_options]; // fa_opt = fa_opt | m_uniq tags fa_opt; local sm = opt.sm; local chains = Chains[]; if isfalse sm then local targetAtoms = cat select [ [SelectedAtoms[]], cAtoms chains(1), length SelectedAtoms[] ]; local targetMol = uniq aMoleculeNumber targetAtoms; if length targetMol > 1 then Warning 'Please select the substructure in a single molecule!'; exit[]; endif sm = sm_Extract [targetAtoms, aPrioSMI targetAtoms]; chains = cat [chains(targetMol), chains | not (chains == chains(targetMol)) ]; endif opt.sm = sm; local all_atoms = cat cAtoms chains; local a_mol_num = aMoleculeNumber all_atoms; local mols = uniq a_mol_num; local match_atoms = apt sm_MatchAtoms [sm, cAtoms chains]; // select only matched molecules local i; for i = 1, length match_atoms loop match_atoms(i) = first (match_atoms(i) | app length match_atoms(i) > 1); endloop match_atoms = app cat match_atoms; // drop null match match_atoms = match_atoms | app length match_atoms > 1; local match = length match_atoms; // return if there are no matched substructure in the molecule // to be superposed if match <= 1 then return match; endif local match_mol_num = uniq cat aMoleculeNumber match_atoms; local match_mols = uniq cat match_mol_num; local pos = app aPos match_atoms; local [ms,R,t] = Superpose [ pos ]; for i = 2, length match_atoms loop // select all current ligand atoms!!! local a = Atoms [] | a_mol_num == match_mols(i); aSetPos [a, t(1) + app add (R(i) * [aPos a - t(i)]) ]; if opt.replace then // assign substructure to the reference coordinates aSetPos [match_atoms(i), pos(1)]; // optimize the hydrogen atoms aSetInert [diff [Atoms [], a], 1]; FixMin [(a | aElement a <> 'H'), [gtest: opt.mm_gtest]]; aSetInert [Atoms [], 0]; endif // refine the superposed alignment with Flexible Alignment // with the matched atoms fixed if fix_ss is on if opt.refine then local oatoms = diff [Atoms [], a]; if istrue opt.fix_ss then // fix the matched atoms local fixed_atoms = cat [oatoms, match_atoms(i)]; else fixed_atoms = oatoms; endif aSetFixed [fixed_atoms, 1]; FlexAlignInAnotherSystem[fa_opt,[cat Atoms [] | a_mol_num == match_mols(1),a] ]; // FlexAlign fa_opt; aSetFixed [fixed_atoms, 0]; endif // minimize ligand atoms // except for the matched subfragment if fix_ss is on if opt.min then local inert_atoms = diff [Atoms [], a]; aSetInert [inert_atoms, 1]; if istrue opt.fix_ss then fixed_atoms = match_atoms(i); else fixed_atoms = []; endif FixMin [fixed_atoms, [gtest: opt.mm_gtest]]; aSetInert [inert_atoms, 0]; endif endloop return match; endfunction function db_SSSuperpose_Panel; global function db_SSSuperpose [mdb_file, mol_field, dst_field, opt] write 'db_SSSuperpose '; print [mdb_file, mol_field, dst_field, opt]; // if no auguments, call db_SSSuperpose_Panel if isfalse [mdb_file, mol_field, dst_field, opt] then [mdb_file, mol_field, dst_field, opt] = db_SSSuperpose_Panel []; if isfalse [mdb_file, mol_field, dst_field, opt] then exit[]; endif endif local tstart = cpuclock []; opt = tagcat [opt, SSSUPERPOSE_DEFAULTS]; opt = tagcat [opt, GetDefaults[]]; local sa_mdb = ''; local tmp_file = opt.tmp_file; local sm = opt.sm; // local smiles_field = 'SMILES'; local match_field = 'Match'; local data; if istrue mdb_file > 0 then sa_mdb = db_Open [mdb_file, 'read-write']; else sa_mdb = dbv_DefaultView []; endif; if isfalse mol_field then mol_field = first (first db_Fields sa_mdb | second db_Fields sa_mdb == 'molecule'); endif if istrue dst_field then db_EnsureField [sa_mdb, dst_field, 'molecule']; else dst_field = mol_field; endif local ent = db_Entries sa_mdb; // if tmp_file is defined, then read the template molecule local tmp = 0; if istrue tmp_file then if istrue flist [fpath tmp_file, ftail tmp_file] then tmp = 1; Close [force:1]; Open tmp_file; else write ['The template file, \'{}\', does not exist!\n', tmp_file]; exit []; endif endif // write [' Input Substructure in SMILES: \n {c:}\n', sm]; if sm === [] or sm === '' then if length Atoms[] === 0 then // copy the first molecule in MDB to MOE window write 'Use the first molecule in MDB as a template molecule.\n'; mol_Create cat db_ReadFields [sa_mdb,ent(1), mol_field]; endif local satoms = cat select [ [SelectedAtoms[]], [Atoms[]], [length SelectedAtoms[]] ]; if length uniq aMoleculeNumber satoms >1 then exit 'Error: Please select the bonded substructure in a single' 'molecules in MOE window!'; endif local tatoms = satoms | aElement satoms <> 'H'; // target atoms sm = sm_Extract [tatoms, aPrioSMI tatoms]; endif // ignore chiralities for matching to reference atoms // whose chiralities could be changed on R-group addition // write [' Template Substructure in SMILES: \n {c:}\n', sm]; sm = token (string sm | string sm <> "@"); // write ['Adopted Template Substructure in SMILES: \n {c:}\n', sm]; opt.sm = sm; write 'db_SSSuperpose '; print [db_Filename sa_mdb, mol_field, dst_field, opt]; // db_EnsureField [sa_mdb, smiles_field, 'char']; db_EnsureField [sa_mdb, match_field, 'int']; if opt.flexscore then db_EnsureField [sa_mdb, 'S', 'double']; db_EnsureField [sa_mdb, 'U', 'double']; db_EnsureField [sa_mdb, 'F', 'double']; endif if not MOE_BATCH then local msg_key = Message [0, '']; endif local i; for i = 1, length ent loop if opt.esel then if not dbv_EntrySelect [sa_mdb, ent(i)] then continue; endif endif local key = mol_Create cat db_ReadFields [sa_mdb, ent(i), mol_field]; local mol = mol_Extract key; if not MOE_BATCH then Message [msg_key, token swrite [ 'Substructure superposition of molecule #{n:}.', i ]]; endif local atoms = cat oAtoms key; local smi = sm_Extract [atoms, aPrioSMI atoms]; local match = SSSuperpose opt; mol = mol_Extract atoms; local outent=tag [match_field, match - 1 > 0]; if match > 1 then // Match! write [' {n:6}: {c:}\n', i, mol(MOL_NAME)]; outent.(dst_field)=mol; if opt.flexscore then local [S,U]=FlexAlignSimilarityScore []; outent.S=S; outent.U=U; outent.F = S-U; endif if not MOE_BATCH then dbv_EntrySelect [sa_mdb, ent(i), 1]; endif else // No match! write ['>{n:6}: {c:}\n', i, mol(MOL_NAME)]; endif db_Write [sa_mdb, ent(i), outent]; oDestroy key; endloop if tmp then Close [force:1]; endif if not MOE_BATCH then Message [msg_key, '']; endif write '_____________________________' '____________________________________________\n'; write 'The entry marked with \'>\' ' 'does not contain the template as substructure.\n'; write ['db_SSSuperpose elapsed {} sec.\n', cpuclock [] - tstart]; endfunction // SSSuperpose_Panel puts up the GUI for the wash command and then calls // SSSuperpose global function SSSuperpose_Panel [] if MOE_BATCH then return; endif if WindowShow ['SSSuperpose', 1] then return; endif local fa_defaults = GetDefaults[]; local opt_defaults = cat [SSSUPERPOSE_DEFAULTS, fa_defaults]; local sm = ''; if sm === [] or sm === '' then local satoms = cat select [ [SelectedAtoms[]], [Atoms[]], [length SelectedAtoms[]] ]; if length uniq aMoleculeNumber satoms >1 then exit 'Error: Please select the bonded substructure in a single' 'molecules in MOE window!'; endif local tatoms = satoms | aElement satoms <> 'H'; // target atoms sm = sm_Extract [tatoms, aPrioSMI tatoms]; endif // ignore chiralities for matching to reference atoms // whose chiralities could be changed on R-group addition write [' Template Substructure in SMILES: \n {c:}\n', sm]; sm = token (string sm | string sm <> "@"); opt_defaults.sm = sm; local wkey = WindowCreate [ name: 'panel', windowName: 'SSSuperpose', title: 'Substructure Superposition', text: ['OK','Cancel'], Text : [ name: 'sm', title: 'SMILES:', len:40, extendH:1, bubbleHelp: 'If empty then the selected substructure of the molecule in \n' 'MOE, will be used as the template substructure to be \n' 'superposeed or superposed. If no atoms are selected then \n' 'whole atoms of the molecule in MOE will be used as the target ' 'substructure.' ], Checkbox : [ name: 'replace', text: 'Replace the Matched Atom Coordinates', bubbleHelp: 'Replace the Matched Atom Coordinates with the templates\'.\n', onTrigger: 'return' ], Checkbox : [ name: 'fix_ss', text: 'Fix the superposed Substructure', bubbleHelp: 'If on then double and conjugated single bonds\n' 'will be rotated during the search.' ], Hbox : [ Checkbox : [ name: 'refine', text: 'Align the Rest', onTrigger: 'return', bubbleHelp: 'If on then the rest of the superposed molecule will\n' 'be aligned to the template molecule.' ], Label:[text:'',font:'large'], Button:[name:'fasettings',title:'', text:'Settings...', onTrigger:'return', bubbleHelp: 'Flexible Alignment settings.' ] ], Hbox : [ Checkbox : [ name: 'min', text: 'Minimize the Rest', bubbleHelp: 'If on then the rest of the superposed molecule will\n' 'be optimized with fixing the matched atoms.', onTrigger: 'return' ] ], Text : [ name: 'mm_gtest', title: 'RMS Gradient:', len: 10, type:'real', bubbleHelp: 'If the root mean square gradient falls below the\n' 'specified value then energy minimization will stop.' ] ]; local val, trig; val = opt_defaults | indexof [tags opt_defaults, SSSUPERPOSE_TAGS]; val = val | m_uniq tags val; WindowSetData [wkey, val]; WindowShow wkey; local fa_opt = opt_defaults | indexof [tags opt_defaults, tags fa_defaults]; val = WindowValues wkey; // fall into the main event loop loop WindowSetAttr [wkey, tag[['fasettings'], [[sensitive: val.refine]]]]; WindowSetAttr [wkey, [mm_gtest:[sensitive: val.min]]]; [val, trig] = WindowWait wkey; if trig == 'panel' then if val.panel === 'Cancel' then return; endif break; endif if trig === 'fasettings' then // Send flat vector to SettingsPanel local flat = fa_opt | m_diff [tags fa_opt, ['ABopt','PH4opt']]; flat = cat [flat, fa_opt.ABopt, fa_opt.PH4opt]; // convert to flat vector flat = SettingsPanel flat; // Convert flat vector to FlexAlign option fa_opt = tagcat [flat | indexof [tags flat, tags fa_opt], fa_opt]; local ABTags = cat app TermTag ABTerms; fa_opt.ABopt = tagcat [flat | indexof [tags flat, ABTags], fa_opt.ABopt]; local PH4Tags = cat app TermTag PH4Terms; fa_opt.PH4opt = tagcat [flat | indexof [tags flat, PH4Tags], fa_opt.PH4opt]; continue; endif endloop UndoSnapshot[]; WindowDestroy wkey; local opt = cat [val, fa_opt]; opt = opt | indexof [tags opt, tags opt_defaults]; opt = opt | m_uniq tags opt; return opt; endfunction // db_SSSuperpose_Panel puts up the GUI for the db_SSSuperpose command // and then calls db_SSSuperpose global function db_SSSuperpose_Panel mdb_file if MOE_BATCH then return; endif if WindowShow ['db_SSSuperpose', 1] then return; endif local fa_defaults = GetDefaults[]; local opt_defaults = cat [SSSUPERPOSE_DEFAULTS, fa_defaults]; if isfalse mdb_file then mdb_file = task_getenv 'DB_VIEW'; if isfalse mdb_file then mdb_file = FilePrompt [ 'Superpose Molecules: Select a Database','open','*.mdb' ]; if isfalse mdb_file then return; endif endif endif mdb_file = db_Filename mdb_file; opt_defaults.mdb_file = mdb_file; local [fname,ftype] = db_Fields mdb_file; fname = fname | ftype == 'molecule'; local sm = ''; if length Atoms[] then local satoms = cat select [ [SelectedAtoms[]], [Atoms[]], [length SelectedAtoms[]] ]; if length uniq aMoleculeNumber satoms >1 then exit 'Error: Please select the bonded substructure in a single' 'molecules in MOE window!'; endif local tatoms = satoms | aElement satoms <> 'H'; // target atoms sm = sm_Extract [tatoms, aPrioSMI tatoms]; endif // ignore chiralities for matching to reference atoms // whose chiralities could be changed on R-group addition write [' Template Substructure in SMILES: \n {c:}\n', sm]; sm = token (string sm | string sm <> "@"); opt_defaults.sm = sm; // SMILES for superposeing substructure // // refine the unselected atoms if exist // opt_defaults.refine = length Atoms[] - length SelectedAtoms [] > 0; local wkey = WindowCreate [ name: 'panel', windowName: 'db_SSSuperpose', title: 'Database Substructure Superposition', text: ['OK','Cancel'], Text : [ name: 'mdb_file', title: 'Database:', len:40, sensitive:0, extendH:1, bubbleHelp: 'Database to operate upon.' ], Checkbox : [ name: 'esel', text: 'Selected Entries Only', bubbleHelp: 'Operate only on entries selected in the Database Viewer.', onTrigger: 'return' ], Option : [ name: 'mol_field', title: 'Molecule Field:', type: 'char', text: fname ], Text : [ name: 'dst_field', title: 'Destination Field:', len:40, extendH:1, bubbleHelp: 'If empty then output structures will be written to the\n' 'Molecule Field. Otherwise, Destination Field specifies\n' 'the field to contain the washed molecules.' ], Text : [ name: 'sm', title: 'SMILES:', len:40, extendH:1, bubbleHelp: 'If empty then the selected substructure of the molecule in \n' 'MOE,will be used as the template to be superposeed or \n' 'superposed. If no atoms are selected then whole atoms of \n' 'the molecule in MOE will be used as the target molecules.\n' 'If there are no atoms in MOE, the molecule in the first \n' 'entry in MDB will be used.\n' ], Checkbox : [ name: 'replace', text: 'Replace the Matched Atom Coordinates', bubbleHelp: 'Replace the Matched Atom Coordinates with the templates\'.\n', onTrigger: 'return' ], Checkbox : [ name: 'fix_ss', text: 'Fix the superposed Substructure', bubbleHelp: 'If on then double and conjugated single bonds\n' 'will be rotated during the search.' ], Hbox : [ Checkbox : [ name: 'refine', text: 'Align the Rest', bubbleHelp: 'If on then the rest of the superposed molecule will\n' 'be aligned to the template molecule.', onTrigger: 'return' ], Label:[text:'',font:'large'], Button:[name:'fasettings',title:'', text:'Settings...', onTrigger:'return', bubbleHelp: 'Flexible Alignment settings.' ], Checkbox : [ name: 'flexscore', text: 'FlexAlign score', bubbleHelp: 'If on then the score of the alignment by Flexible Alignment\n' 'will be output to S, U and F field.' ] ], Checkbox : [ name: 'min', text: 'Minimize the Rest', bubbleHelp: 'If on then the rest of the superposed molecule will\n' 'be optimized with fixing the matched atoms.', onTrigger: 'return' ], Text : [ name: 'mm_gtest', title: 'RMS Gradient:', len: 10, type:'real', bubbleHelp: 'If the root mean square gradient falls below the\n' 'specified value then energy minimization will stop.' ] ]; local val, trig; val = opt_defaults | indexof [tags opt_defaults, DB_SSSUPERPOSE_PANEL_TAGS]; val = val | m_uniq tags val; WindowSetData [wkey, val]; WindowShow wkey; local fa_opt = opt_defaults | indexof [tags opt_defaults, tags fa_defaults]; val = WindowValues wkey; // fall into the main event loop local mol_field, dst_field; loop WindowSetAttr [wkey, tag[['fasettings'], [[sensitive: val.refine]]]]; WindowSetAttr [wkey, [mm_gtest: [sensitive: val.min]]]; [val, trig] = WindowWait wkey; if trig == 'panel' then if trig === 'Settings...' then SettingsPanel[]; continue; endif if val.panel === 'Cancel' then return; endif mol_field = val.mol_field; dst_field = val.dst_field; if val.esel and dbv_nSelectedEntries mdb_file == 0 then Warning 'No entries selected in Database Viewer.'; continue; endif if dst_field == '' then dst_field = mol_field; endif if dst_field == mol_field then if not YesNo token swrite [ 'Overwrite {} field?', mol_field ] then continue; endif endif if isnull Atoms[] then if not NoYes 'No molecule in MOE window.\nProceed with using the first entry as template?' then continue; endif endif break; endif if trig === 'fasettings' then // Send flat vector to SettingsPanel local flat = fa_opt | m_diff [tags fa_opt, ['ABopt','PH4opt']]; flat = cat [flat, fa_opt.ABopt, fa_opt.PH4opt]; // convert to flat vector flat = SettingsPanel flat; // Convert flat vector to FlexAlign option fa_opt = tagcat [flat | indexof [tags flat, tags fa_opt], fa_opt]; local ABTags = cat app TermTag ABTerms; fa_opt.ABopt = tagcat [flat | indexof [tags flat, ABTags], fa_opt.ABopt]; local PH4Tags = cat app TermTag PH4Terms; fa_opt.PH4opt = tagcat [flat | indexof [tags flat, PH4Tags], fa_opt.PH4opt]; continue; endif endloop WindowDestroy wkey; local opt = tagcat [val, opt_defaults]; return [mdb_file, mol_field, dst_field, opt]; endfunction