/
visualization.svl
797 lines (662 loc) · 26.2 KB
/
visualization.svl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
#set title 'fmoe:visualization'
function _Atoms;
const HARTREE = 627.509474;
const RESOLUTION = 1000;
const CPF_NUM_ATOMS = 1;
const CPF_NUM_FRAGS = 2;
const CPF_ATOM_INDICES = 3;
const CPF_ATOM_ELEMENTS = 4;
const CPF_ATOM_TYPES = 5;
const CPF_ATOM_RES_NAMES = 6;
const CPF_ATOM_RES_INDICES = 7;
const CPF_ATOM_FRAG_INDICES = 8;
const CPF_ATOM_X = 9;
const CPF_ATOM_Y = 10;
const CPF_ATOM_Z = 11;
const CPF_ATOM_HF_Mulliken = 12;
const CPF_ATOM_MP2_Mulliken = 13;
const CPF_ATOM_HF_NBO = 14;
const CPF_ATOM_MP2_NBO = 15;
const CPF_ATOM_HF_RESP = 16;
const CPF_ATOM_MP2_RESP = 17;
const CPF_ATOM_CHAIN_ID = 18;
const CPF_ATOM_INS_CODE = 19;
const CPF_FRAG_BOND_NUMBERS = 20;
const CPF_FRAG_BOND_SELFS = 21;
const CPF_FRAG_BOND_OTHERS = 22;
const CPF_DIMER_DISTANCES = 23;
const CPF_DIMER_ES = 24;
const CPF_DIMER_DI = 25;
const CPF_DIMER_EX = 26;
const CPF_DIMER_CT = 27;
const CPF_FILE_PATH = 28;
const STANDARD_RESIDUES = [
'ALA', 'ARG', 'ASN', 'ASP', 'CYS',
'GLN', 'GLU', 'GLY', 'HIS', 'ILE',
'LEU', 'LYS', 'MET', 'PHE', 'PRO',
'SER', 'THR', 'TRP', 'TYR', 'VAL',
'ACE', 'NME'
];
local function Cpf2SvlExePath []
local env = modenv [];
local exe = fcat [fpath env.filename, 'bin', tok_cat ['cpf2svl.', MOE_ARCH, '.exe']];
if ftype exe === 'file' then
return exe;
endif
endfunction
global function OpenCheckPointFile path
local msg = Message [0, twrite ['Parsing CPF file {}...', path]];
local exe = Cpf2SvlExePath [];
if exe === [] then
return;
endif
local svl_path = fnametemp '$TMP/fmoe_parsed_cpf*.bin';
local pkey = exe_open_shell [exe, [], [CPF_PATH: ffullname path, SVL_PATH: svl_path]];
while exe_status pkey loop
sleep 0.01;
endloop
if not exe_exitcode pkey then
Message [msg, []];
local cpf = freadb [svl_path, 'SVL', 50];
cpf[CPF_FILE_PATH] = path;
return cpf;
else
local line;
for line in freadb [exe_stderr pkey, 'line', 50] loop
fwrite ['*cli*', '{}\n', line];
endloop
endif
endfunction
local function IsStandardResidue res
return app orE eqE [[STANDARD_RESIDUES], res];
endfunction
global function AbinitMpCheckPointFileToPDBFile [cpf, fnum]
local i, header;
for i = 1, cpf(CPF_NUM_ATOMS) loop
if IsStandardResidue cpf(CPF_ATOM_RES_NAMES)(i) then
header = 'ATOM ';
else
header = 'HETATM';
endif
fwrite [
fnum,
'{t:}{n:5} {t:4} {t:3} {t:1}{n:4}{t:1} {n:8.3f}{n:8.3f}{n:8.3f} 1.00{n:6.2f} {t:2}\n',
header, cpf(CPF_ATOM_INDICES)(i), cpf(CPF_ATOM_TYPES)(i), cpf(CPF_ATOM_RES_NAMES)(i),
cpf(CPF_ATOM_CHAIN_ID)(i), cpf(CPF_ATOM_RES_INDICES)(i), cpf(CPF_ATOM_INS_CODE)(i),
cpf(CPF_ATOM_X)(i), cpf(CPF_ATOM_Y)(i), cpf(CPF_ATOM_Z)(i), cpf(CPF_ATOM_HF_Mulliken)(i),
cpf(CPF_ATOM_ELEMENTS)(i)
];
endloop
endfunction
global function ConvertCpfToPDB [cpf_path, pdb_path]
local cpf = OpenCheckPointFile cpf_path;
local pdb = fopenw pdb_path;
AbinitMpCheckPointFileToPDBFile [cpf, pdb];
fclose pdb;
endfunction
local function WriteTempPDBFile cpf
local pdb_path = fnametemp '$TMP/fmoe_visualization_*.pdb';
local pdb_file = fopenw pdb_path;
AbinitMpCheckPointFileToPDBFile [cpf, pdb_file];
fclose pdb_file;
return pdb_path;
endfunction
global function CreateMoleculeFromCPF cpf
local pdb_file = WriteTempPDBFile cpf;
local chains = ReadPDB [pdb_file, [preserve_order: 1]];
fdelete pdb_file;
local prefixes = apt tok_drop [cName chains, tok_length cTag chains];
local name = ftail fbase cpf(CPF_FILE_PATH);
cSetTag [chains, name];
cSetName [chains, apt tok_cat [name, prefixes]];
return chains;
endfunction
local function RGBToNumber [r, g, b]
return floor [r * 0xff] * 0x10000 + floor [g * 0xff] * 0x100 + floor [b * 0xff];
endfunction
local function NumberToRGB n
return [
floor (n / 0x10000) / 0xff,
bitand [floor (n / 0x100), 0xff] / 0xff,
bitand [n, 0xff] / 0xff
];
endfunction
local function DimerIndex [self, other]
local mins = apt min [self, other];
local maxs = apt max [self, other];
local r = ((maxs - 1) * (maxs - 2)) / 2 + mins;
r | (self == other) = 0;
return r;
endfunction
local function DimerLengthToNumFragments l
return (sqrt [8 * l + 1] + 1) / 2;
endfunction
const COMPONENT_NAMES = [
CT: CPF_DIMER_CT,
DI: CPF_DIMER_DI,
EX: CPF_DIMER_EX,
ES: CPF_DIMER_ES
];
local function GetNeighborFragmentIndices [cpf, frags]
local atom_mask = app orE eqE [cpf(CPF_ATOM_FRAG_INDICES), [frags]];
local atom_indices = cpf(CPF_ATOM_INDICES) | atom_mask;
local neighbor_atoms = cat [
cpf(CPF_FRAG_BOND_OTHERS) | (app orE eqE [cpf(CPF_FRAG_BOND_SELFS), [atom_indices]]),
cpf(CPF_FRAG_BOND_SELFS) | (app orE eqE [cpf(CPF_FRAG_BOND_OTHERS), [atom_indices]])
];
neighbor_atoms = neighbor_atoms | (not app orE eqE [neighbor_atoms, [atom_indices]]);
return cpf(CPF_ATOM_FRAG_INDICES) | (app orE eqE [cpf(CPF_ATOM_INDICES), [neighbor_atoms]]);
endfunction
global function SumIfie [cpf, frags, components]
local indices = apt DimerIndex [[igen cpf(CPF_NUM_FRAGS)], frags];
local self_mask = eqE [0, indices];
indices = apt mput [indices, self_mask, 1];
local neighbors = GetNeighborFragmentIndices [cpf, frags];
local sums = [];
local component;
for component in components loop
local idx = tagget[COMPONENT_NAMES, component];
if not (idx === [[]]) then
local ifie = cpf(idx);
local ifiesum = apt add apt get [[ifie], indices];
ifiesum | orE self_mask = 0;
ifiesum[neighbors] = 0;
sums = tagpoke [sums, component, ifiesum];
endif
endloop
return sums;
endfunction
local function InterpolateRGB [rgb0, rgb1, r]
local [r0, g0, b0] = rgb0;
local [r1, g1, b1] = rgb1;
local dr = r1 - r0;
local dg = g1 - g0;
local db = b1 - b0;
return tr [r0 + dr * r, g0 + dg * r, b0 + db * r];
endfunction
local function RGBColorScale [rgbmin, rgb0, rgbmax, v]
local left_mask = v < 0;
local left = InterpolateRGB [rgbmin, rgb0, 1 + (v | left_mask)];
local right = InterpolateRGB [rgb0, rgbmax, v | not left_mask];
local result = zero v;
result | left_mask = left;
result | not left_mask = right;
return result;
endfunction
local function LinearScale [range, v]
v = v / range;
v | v > 1 = 1;
v | v < -1 = -1;
return v;
endfunction
local function GetRange ifiesum
return max [abs max ifiesum, abs min ifiesum, 1e-10];
endfunction
local function Strip t
local s = app string t;
return app token apt mget [s, s <> " "];
endfunction
local function GetFragAtomMasks cpf
return eqE [[cpf(CPF_ATOM_FRAG_INDICES)], igen cpf(CPF_NUM_FRAGS)];
endfunction
local function GetFragAtomMasksWithoutCO cpf
return andE [
GetFragAtomMasks cpf,
[not app orE eqE [Strip cpf(CPF_ATOM_TYPES), [['C', 'O']]]]
];
endfunction
local function Common t
if t === [] then
return [];
endif
if isflat t then
t = [t];
endif
local cand = app uniq t;
local freq = apt freq [cand, t];
return apt get [cand, app x_max freq];
endfunction
local function GetFragNames cpf
local frag_masks = GetFragAtomMasksWithoutCO cpf;
local names = Common apt mget [[cpf(CPF_ATOM_RES_NAMES)], frag_masks];
local indices = totok Common apt mget [[cpf(CPF_ATOM_RES_INDICES)], frag_masks];
return apt tok_cat [names, indices];
endfunction
local function GetFragAtomKeys [cpf, chains]
return apt mget [[cat cAtoms chains], GetFragAtomMasks cpf];
endfunction
local function GetFragResKeys [cpf, chains]
local frag_masks = GetFragAtomMasksWithoutCO cpf;
return app uniq apt mget [[aResidue cat cAtoms chains], frag_masks];
endfunction
local function _SetRGBByIfie [frag_atoms, frag_residues, ifiesum, options]
local scaled = LinearScale [options.range, ifiesum];
local colors = app RGBToNumber RGBColorScale [options.rgbmin, options.rgb0, options.rgbmax, scaled];
colors[options.ligand_indices] = options.ligandrgb;
apt aSetRGB [frag_atoms, colors];
rSetRibbonRGB [frag_residues, colors];
colors | colors == 0 = 0x010101; // FIXME: avoid bug
rSetRGB [frag_residues, colors];
endfunction
local function SetColorBy [chains, colorall]
local atom_keys = cat cAtoms chains;
rSetRibbonColorBy [cResidues chains, 'rgb'];
if colorall then
aSetColorBy [atom_keys, 'a:rgb'];
else
local color_mask = app orE eqE [aElement atom_keys, [['C', 'H']]];
aSetColorBy [atom_keys | color_mask, 'a:rgb'];
aSetColorBy [atom_keys | not color_mask, 'element'];
endif
endfunction
global function SetRGBByIfie [cpf, chains, ligand_frags, options]
local range = options.range,
rgbmin = options.rgbmin,
rgb0 = options.rgb0,
rgbmax = options.rgbmax,
ligandrgb = options.ligandrgb,
colorall = options.colorall,
components = options.components;
if rgbmin === [] then
rgbmin = 0xff0000;
endif
if rgb0 === [] then
rgb0 = 0xffffff;
endif
if rgbmax === [] then
rgbmax = 0x0000ff;
endif
if ligandrgb === [] then
ligandrgb = 0xffff00;
endif
if colorall === [] then
colorall = 1;
endif
if components === [] then
components = ['ES', 'EX', 'CT', 'DI'];
endif
local sumifies = SumIfie [cpf, ligand_frags, components];
local sumifie = add second untag sumifies * HARTREE;
local neighbors = GetNeighborFragmentIndices [cpf, ligand_frags];
sumifie[neighbors] = 0;
if range === [] then
range = GetRange sumifie;
endif
_SetRGBByIfie [GetFragAtomKeys [cpf, chains], GetFragResKeys [cpf, chains], sumifie, [
rgbmin: NumberToRGB rgbmin,
rgb0: NumberToRGB rgb0,
rgbmax: NumberToRGB rgbmax,
ligandrgb: ligandrgb,
ligand_indices: ligand_frags,
range: range
]];
SetColorBy [chains, colorall];
return sumifies;
endfunction
const MAIN_PANEL = [
name: 'fmoe_visualization',
title: 'FMOE Visualization',
windowName: 'FMOEVisualization',
Vbox: [
extendH: 1,
Hbox: [
extendH: 1,
Label: [text: 'Ligand: ', font: 'mediumFixedBold'],
Label: [name: 'ligand_name'],
Button: [text: 'set', name: 'set_ligand', onTrigger: 'return'],
Color: [name: 'ligandrgb', onTrigger: 'return'],
Label: [extendH: 1],
Button: [text: 'list', name: 'listup_ifie']
],
Hbox: [
extendH: 1,
Label: [text: 'Preset: ', font: 'mediumFixedBold'],
Checkbox: [name: 'preset_MP2', text: 'MP2', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'preset_HF', text: 'HF', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'preset_ES', text: 'ES', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'preset_EX', text: 'EX', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'preset_CT', text: 'CT+mix', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'preset_DI', text: 'DI', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4]
],
Hbox: [
extendH: 1,
Label: [text: 'Component:', font: 'mediumFixedBold'],
Checkbox: [name: 'component_ES', text: 'ES', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'component_EX', text: 'EX', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'component_CT', text: 'CT+mix', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4],
Checkbox: [name: 'component_DI', text: 'DI', onTrigger: 'return', checkboxStyle: 'radioButton', minWidth: 4]
],
Hbox: [
extendH: 1,
Label: [text: 'Color: ', font: 'mediumFixedBold'],
Radio: [name: 'color_atoms', type: 'char', text: ['Carbon', 'All'], onTrigger: 'return', minWidth: 4]
],
Separator: [
extendH: 1
],
Hbox: [
extendH: 1,
Vbox: [Color: [name: 'rgbmin', centerH: 1, onTrigger: 'return'], Text: [type: 'real', name: 'energymin', len: 10, onTrigger: 'return']],
Vbox: [
extendH: 1,
Slider: [extendH: 1, centerV: 1, name: 'leftslider', range: [-RESOLUTION, -1, 1], onTrigger: 'return'],
Wheel: [extendH: 1, centerV: 1, name: 'leftwheel', resetButton: 0, onTrigger: 'return']
],
Vbox: [Color: [name: 'rgb0', centerH: 1, onTrigger: 'return'], Button: [text: '0', name: 'reset_energy', centerH: 1, extendH: 1, onTrigger: 'return']],
Vbox: [
extendH: 1,
Slider: [extendH: 1, centerV: 1, name: 'rightslider', range: [1, RESOLUTION, 1], onTrigger: 'return'],
Wheel: [extendH: 1, centerV: 1, name: 'rightwheel', resetButton: 0, onTrigger: 'return']
],
Vbox: [Color: [name: 'rgbmax', centerH: 1, onTrigger: 'return'], Text: [type: 'real', name: 'energymax', len: 10, onTrigger: 'return']]
]
]
];
const LIGAND_PICKER = [
name: 'atom',
location: 'MOE',
mode: 'pickAtom',
title: 'pick one of ligand atoms...'
];
local function PickLigandTask []
local wkey = WindowCreate LIGAND_PICKER;
local result = (first WindowWait wkey).atom;
WindowDestroy wkey;
return result;
endfunction
local function FormatLigands [names, indices]
indices = keep [indices, 10];
return tok_cat droplast cat tr [names[indices], ','];
endfunction
local function EnergyInspector [cpf, chains, ifies]
local msg_key = Message [0, ''];
local frag_names = GetFragNames cpf;
local before_frags = [];
loop
if not andE app oValid chains then
return;
endif
local selected_indices = indexof [SelectedAtoms [], cat cAtoms chains];
selected_indices = selected_indices | selected_indices <> 0;
if length selected_indices > 0 then
local frags = [];
if length selected_indices == 1 then
frags = cpf(CPF_ATOM_FRAG_INDICES)[selected_indices];
else
local non_co_indices = selected_indices | not app orE eqE [Strip cpf(CPF_ATOM_TYPES)[selected_indices], [['C', 'O']]];
frags = uniq cpf(CPF_ATOM_FRAG_INDICES)[non_co_indices];
endif
if not (before_frags === frags) then
before_frags = frags;
local name = FormatLigands [frag_names, frags];
local es = add *ifies.ES[frags] * HARTREE;
local ex = add *ifies.EX[frags] * HARTREE;
local ct = add *ifies.CT[frags] * HARTREE;
local di = add *ifies.DI[frags] * HARTREE;
local hf = es + ex + ct;
local mp2 = hf + di;
local result = twrite ['========\nname: {}\nES: {}\nEX: {}\nCT+mix: {}\nDI: {}\nHF: {}\nMP2: {}\n', name, es, ex, ct, di, hf, mp2];
write result;
Message [msg_key, result];
endif
else
before_frags = [];
Message [msg_key, ''];
endif
sleep 0.2;
endloop
Message [msg_key, []];
endfunction
const IFIE_LIST = [
name: 'ifie list',
title: 'ifie list',
windowName: 'ifie list',
Vbox: [
extendH: 1,
extendV: 1,
Hbox: [
Label: [text: 'Ligand: '],
Label: [
name: 'ligand',
extendH: 1
]
],
Listbox: [
name: 'list',
extendH: 1,
extendV: 1,
header: '#{+5n}\tname{6t}\tMP2{+12n}\tHF{+12n}\tES{+12n}\tEX{+12n}\tCT{+12n}\tDI{+12n}\tMain comp.{+12n}',
len: 50,
width: 120,
multiSelect: 1,
sortEnable: 1
]
]
];
local function IfieList [cpf, frags]
local wkey = WindowCreate IFIE_LIST;
WindowShow wkey;
local frag_names = GetFragNames cpf;
local ifie = SumIfie [cpf, frags, ['ES', 'EX', 'CT', 'DI']];
local ifies = [];
local i;
for i in igen cpf(CPF_NUM_FRAGS) loop
local es = ifie.ES(i) * HARTREE;
local ex = ifie.EX(i) * HARTREE;
local ct = ifie.CT(i) * HARTREE;
local di = ifie.DI(i) * HARTREE;
local hf = es + ex + ct;
local mp2 = hf + di;
local main_comp = ['ES', 'EX', 'CT', 'DI'] (x_max abs [es, ex, ct, di]);
ifies[i] = twrite ['{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}', i, frag_names(i), mp2, hf, es, ex, ct, di, main_comp];
endloop
WindowSetAttr [wkey, [
ligand: [text: FormatLigands [frag_names, frags]],
list: [text: ifies]
]];
// text: ['1\thoge\t32.1\t321\t1\t1\t3\t1']
loop
local [values, trigger] = WindowWait wkey;
endloop
WindowDestroy wkey;
endfunction
const DEFAULT_LIGAND_RGB = 0xffff00;
const DEFAULT_RGB_MIN = 0xff0000;
const DEFAULT_RGB_0 = 0xffffff;
const DEFAULT_RGB_MAX = 0x0000ff;
local function ShowVisualizationPanel [cpf, chains]
local wkey = WindowCreate MAIN_PANEL;
local ligands = dvar_open[];
local ifies = dvar_open[];
local frag_atoms = GetFragAtomKeys [cpf, chains];
local frag_residues = GetFragResKeys [cpf, chains];
local frag_names = GetFragNames cpf;
local ligand_atom_keys = _Atoms 'ligand';
ligand_atom_keys = ligand_atom_keys | app orE eqE [aChain ligand_atom_keys, [chains]];
*ligands = uniq cpf(CPF_ATOM_FRAG_INDICES)[indexof [ligand_atom_keys, cat cAtoms chains]];
WindowSetAttr [wkey, [fmoe_visualization: [title: twrite ['FMO Visualization - {}', uniq cName chains]]]];
*ifies = SetRGBByIfie [cpf, chains, *ligands, [
rgbmin: DEFAULT_RGB_MIN,
rgb0: DEFAULT_RGB_0,
rgbmax: DEFAULT_RGB_MAX,
ligandrgb: DEFAULT_LIGAND_RGB,
colorall: 1
]];
if second task_fork [master: 'parent'] === 'child' then
EnergyInspector [cpf, chains, ifies];
WindowDestroy wkey;
endif
local ifiesum = add second untag *ifies * HARTREE;
local range = GetRange ifiesum;
local bound = range;
WindowSetAttr [wkey, [ligand_name: [text: FormatLigands [frag_names, *ligands]]]];
WindowSetData [wkey, [
preset_MP2: 1,
component_ES: 1,
component_EX: 1,
component_CT: 1,
component_DI: 1,
color_atoms: 'All',
ligandrgb: DEFAULT_LIGAND_RGB,
rgbmin: DEFAULT_RGB_MIN,
rgb0: DEFAULT_RGB_0,
rgbmax: DEFAULT_RGB_MAX,
leftslider: - RESOLUTION,
rightslider: RESOLUTION,
leftwheel: 0,
rightwheel: 0,
energymin: -range,
energymax: range
]];
WindowShow wkey;
loop
local [values, trigger] = WindowWait wkey;
local new_range = values.energymax;
local update_ifiesum = 0;
local update_range = 0;
local update_colors = 0;
local wdata;
if trigger === 'leftwheel' then
new_range = new_range - values.leftwheel;
update_range = 1;
elseif trigger === 'rightwheel' then
new_range = new_range + values.rightwheel;
update_range = 1;
elseif trigger === 'leftslider' then
new_range = -values.leftslider / RESOLUTION * bound;
update_range = 1;
elseif trigger === 'rightslider' then
new_range = values.rightslider / RESOLUTION * bound;
update_range = 1;
elseif trigger === 'energymin' then
new_range = -values.energymin;
update_range = 1;
elseif trigger === 'energymax' then
new_range = values.energymax;
update_range = 1;
elseif trigger === 'preset_MP2' then
WindowSetData [wkey, [component_ES: 1, component_DI: 1, component_EX: 1, component_CT: 1]];
elseif trigger === 'preset_HF' then
WindowSetData [wkey, [component_ES: 1, component_DI: 0, component_EX: 1, component_CT: 1]];
elseif trigger === 'preset_ES' then
WindowSetData [wkey, [component_ES: 1, component_DI: 0, component_EX: 0, component_CT: 0]];
elseif trigger === 'preset_DI' then
WindowSetData [wkey, [component_ES: 0, component_DI: 1, component_EX: 0, component_CT: 0]];
elseif trigger === 'preset_EX' then
WindowSetData [wkey, [component_ES: 0, component_DI: 0, component_EX: 1, component_CT: 0]];
elseif trigger === 'preset_CT' then
WindowSetData [wkey, [component_ES: 0, component_DI: 0, component_EX: 0, component_CT: 1]];
elseif trigger === 'set_ligand' then
local atom_keys = SelectedAtoms [];
if not (atom_keys === []) then
local atom_key, picked_fragments = [];
for atom_key in atom_keys loop
local atom_frag_idx = indexof [1, app orE eqE [frag_atoms, atom_key]];
if atom_frag_idx <> 0 then
picked_fragments = cat [picked_fragments, atom_frag_idx];
endif
endloop
*ligands = uniq picked_fragments;
*ifies = SumIfie [cpf, *ligands, ['ES', 'EX', 'CT', 'DI']];
WindowSetAttr [wkey, [ligand_name: [text: FormatLigands [frag_names, *ligands]]]];
update_ifiesum = 1;
update_colors = 1;
endif
/*
local [atom_key, return_code] = task_call [#PickLigandTask, [], [master: 'parent']];
if return_code === '' then
local picked_fragment = indexof [1, app orE eqE [frag_atoms, atom_key]];
if trigger === 'set_ligand' then
*ligands = picked_fragment;
else
*ligands = cat [*ligands, picked_fragment];
endif
*ifies = SumIfie [cpf, *ligands, ['ES', 'EX', 'CT', 'DI']];
WindowSetAttr [wkey, [ligand_name: [text: FormatLigands [frag_names, *ligands]]]];
update_ifiesum = 1;
update_colors = 1;
endif
*/
elseif trigger === 'reset_energy' then
new_range = GetRange ifiesum;
update_range = 1;
elseif orE eqE [trigger, ['rgbmin', 'rgb0', 'rgbmax', 'ligandrgb']] then
update_colors = 1;
elseif trigger === 'color_atoms' then
SetColorBy [chains, values.color_atoms === 'All'];
elseif trigger === 'listup_ifie' then
if second task_fork [master: 'parent'] === 'child' then
IfieList [cpf, *ligands];
endif
endif
if orE [tok_keep [trigger, 7] === 'preset_', tok_keep [trigger, 10] === 'component_'] then
wdata = WindowGetData [wkey, ['component_ES', 'component_DI', 'component_EX', 'component_CT']];
local new_component = [wdata.component_ES, wdata.component_DI, wdata.component_EX, wdata.component_CT];
if new_component === [1, 1, 1, 1] then
WindowSetData [wkey, [preset_MP2: 1, preset_HF: 0, preset_ES: 0, preset_DI: 0, preset_EX: 0, preset_CT: 0]];
elseif new_component === [1, 0, 1, 1] then
WindowSetData [wkey, [preset_MP2: 0, preset_HF: 1, preset_ES: 0, preset_DI: 0, preset_EX: 0, preset_CT: 0]];
elseif new_component === [1, 0, 0, 0] then
WindowSetData [wkey, [preset_MP2: 0, preset_HF: 0, preset_ES: 1, preset_DI: 0, preset_EX: 0, preset_CT: 0]];
elseif new_component === [0, 1, 0, 0] then
WindowSetData [wkey, [preset_MP2: 0, preset_HF: 0, preset_ES: 0, preset_DI: 1, preset_EX: 0, preset_CT: 0]];
elseif new_component === [0, 0, 1, 0] then
WindowSetData [wkey, [preset_MP2: 0, preset_HF: 0, preset_ES: 0, preset_DI: 0, preset_EX: 1, preset_CT: 0]];
elseif new_component === [0, 0, 0, 1] then
WindowSetData [wkey, [preset_MP2: 0, preset_HF: 0, preset_ES: 0, preset_DI: 0, preset_EX: 0, preset_CT: 1]];
else
WindowSetData [wkey, [preset_MP2: 0, preset_HF: 0, preset_ES: 0, preset_DI: 0, preset_EX: 0, preset_CT: 0]];
endif
update_ifiesum = 1;
update_colors = 1;
endif
if update_ifiesum then
update_range = 1;
wdata = WindowGetData [wkey, ['component_ES', 'component_DI', 'component_EX', 'component_CT']];
ifiesum = add tagget [*ifies, tok_drop [mget untag wdata, 10]] * HARTREE;
if ifiesum === 0 then
ifiesum = zero frag_names;
endif
bound = GetRange ifiesum;
endif
if update_range then
update_colors = 1;
WindowSetData [wkey, [
leftwheel: 0,
rightwheel: 0,
leftslider: -new_range / bound * RESOLUTION,
rightslider: new_range / bound * RESOLUTION,
energymin: -new_range,
energymax: new_range
]];
endif
if update_colors then
wdata = WindowGetData [wkey, ['energymax', 'rgbmin', 'rgb0', 'rgbmax', 'ligandrgb']];
_SetRGBByIfie [frag_atoms, frag_residues, ifiesum, [
range: wdata.energymax,
rgbmin: NumberToRGB wdata.rgbmin,
rgb0: NumberToRGB wdata.rgb0,
rgbmax: NumberToRGB wdata.rgbmax,
ligandrgb: wdata.ligandrgb,
ligand_indices: *ligands
]];
endif
endloop
WindowDestroy wkey;
endfunction
global function FMOEVisualizationGUI path
if path === [] then
path = FilePrompt [title: 'open cpf file', mode: 'open', filter: ['*.cpf', '*.cpf.gz']];
else
path = fabsname path;
endif
if path === [] then
return;
endif
local cpf = OpenCheckPointFile path;
if cpf === [] then
return [];
endif
local chains = CreateMoleculeFromCPF cpf;
ShowVisualizationPanel [cpf, chains];
endfunction