-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetagui3.tcl
3148 lines (2768 loc) · 85.2 KB
/
metagui3.tcl
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package provide metagui3 3.0
# ------------------------------------------------------------------------------- #
# ------------------------------- M E T A G U I ------------------------------- #
# --- A VMD Interface for Analyzing Long-Scale Molecular Dynamics Simulations --- #
# ------------------------------------------------------------------------------- #
# #
# Copyright 2011-2016 #
# #
# ------------------------------------------------------------------------------- #
# #
# METAGUI is free software: you can redistribute it and/or modify it under the #
# terms of the GNU General Public License as published by the Free Software #
# Foundation, either version 3 of the License, or (at your option) any later #
# version. #
# #
# METAGUI is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR #
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License along with #
# METAGUI. If not, see <http://www.gnu.org/licenses/>. #
# #
# ------------------------------------------------------------------------------- #
package require plumed
namespace eval ::metagui3:: {
namespace export metagui
#
# declaration of plugin-specific variables
#
# path to metagui_util.x (precompiled tasks)
# TG windows will also need auto_execok, to be fixed - see proc bemeta_set_defaults
variable METAGUI_exe
# path to this file (must be done here)
variable METAGUI_path [file normalize [file dirname [info script]]]
# path to current working directory
variable START_FOLDER
# CLUSTERS(*,*,*) matrix containing microstates centers, free energy, basins, ...
variable CLUSTERS
# BASINS(*,*,*) matrix containing basins attractors, free energy, ...
variable BASINS
# FES(*,*) matrix containing Free Energy of each micrstate
variable FES
# total number of microstates
variable NCL
# total number of basins
variable NB
# difusion matrix
variable DD
# boolean to refine free energy during kinetic analysis
variable REFES
# variables for internal use only
variable CLUSTERS_FES_list
variable CLUSTERS_bin
variable CLUSTERS_center
variable CLUSTERS_size
variable clusters_LIST
variable ncLIST
variable current_cluster
variable CLUSTERS_NCL
variable CONNECTED_GROUPS
variable NG
variable FES_MIN
variable FES_MAX
variable reprFES_MAX
variable nREPSinFES
variable pickingON
# variables for smart clustering
variable RHO_CUT
variable DELTA_CUT
# maximum number of structures to represent for each microstate (to avoid memory outage in VMD display)
variable MAX_FRAMES_PER_CLUSTER
# hardcoded!!
set MAX_FRAMES_PER_CLUSTER 100
# VMD mol id containing the trajectory
variable TRAJ_molid
# VMD mol id containing the microstates representation (spheres)
variable FES_molid
# total number of active CV for microstates analysis
variable nCV_ACTIVE
# list of active CV for microstates analysis
variable CV_ACTIVE
# grid size for each CV for microstates analysis
variable CV_INFO_GRID
# COLVAR(*,*,*) matrix containing the values of each CV at each time for each COLVAR file
variable COLVAR
# total number of trajectories loaded
variable nTRAJECTORIES
# time after which to load the trajectories
variable T_CLUSTER 1
# time after wich to perform the WHAM analysis
variable T_FILL 1
# WHAM analysis parameters
variable DELTA 4
variable KT 2.4943
variable GCORR
variable TR_N_EXP
# skip TRAJ_SKIP frames when loading trajectories
variable TRAJ_SKIP
variable TRAJ_SKIP_BAFTI
# structure file for loading trajectory XTC files
variable GRO_FILE
# information on each COLVAR file
variable TRAJ_INFO
# total number of active variables
variable nVARIABLES
variable var_list
# total number of frames loaded from COLVAR files
variable TOTAL_COLVAR_FRAMES
# total number of frames loaded from trajectory XTC files
variable TOTAL_COLVAR_STRUCTURES
# total number of frames in trajectory XTC files
variable TOTAL_TRAJ_FRAMES
# total number of frames in VMD
variable FRAMES
# GRID dimensions for each CV
variable DIMENSIONS
# GRID space for each active CV
variable CLUSTER_SPACE
variable CLUSTER_SPACE_dim
variable CLUSTER_SPACE_vol
# list of active CV
variable myVARS
# list of CVs active in HILLS files
variable CV_ACTIVE_HILLS
# total number of CVs active in HILLS files
variable NCV_ACTIVE_HILLS
# ordered list of microstates
variable CLUSTERS_ORDER
# clustering method type (grid, external, read)
variable CLUSTER_TYPE
variable sievlog
# use all colvar frames for clustering analysis, and not only those biased by active hills in use
variable USE_ALL_WALKERS
# ignore convergence controls in Free Energy calculation
variable IGNORE_CONTROLS
# plotting with Multiplot
variable ploth
variable winf .metagui_plot
#
# read input file and store information in variable variables
proc read_input {{INPUT_file "metagui.in"}} {
variable KT
variable T_CLUSTER
variable T_FILL
variable GCORR
variable TR_N_EXP
variable DELTA
variable nVARIABLES
variable nCV_ACTIVE
variable CV_ACTIVE
variable CV_INFO_GRID
variable nTRAJECTORIES
variable TRAJ_SKIP
variable TRAJ_SKIP_BAFTI
variable GRO_FILE
variable CLUSTER_TYPE
variable sieving
variable sievlog
variable cut_off
variable num_cluster
variable FES_RANGE
variable TRAJ_INFO
variable FES_MIN
variable FES_MAX
variable METAGUI_exe
variable START_FOLDER
set TRAJ_SKIP 10
set TRAJ_SKIP_BAFTI 1
set h 0
set c 0
if {[file exists $INPUT_file]} {
set in [open $INPUT_file r]
while {[gets $in line] != -1} {
if [regexp {^#} $line] {
continue; # skip comments
}
set KEY [lindex $line 0]
switch $KEY {
"METAGUI_EXE" {
set METAGUI_exe [lindex $line 1]
}
"KT" {
set KT [lindex $line 1]
}
"T_CLUSTER" {
set T_CLUSTER [lindex $line 1]
}
"T_FILL" {
set T_FILL [lindex $line 1]
}
"GCORR" {
set GCORR [lindex $line 1]
}
"TR_N_EXP" {
set TR_N_EXP [lindex $line 1]
}
"DELTA" {
set DELTA [lindex $line 1]
}
# There's no need to provide this anymore. nVARIABLES is get from parse_colvars
# "NCV" {
# set nVARIABLES [lindex $line 1]
# }
"ACTIVE" {
set nCV_ACTIVE [lindex $line 1]
for { set i 0} {$i < $nCV_ACTIVE } { incr i } {
set cv [lindex $line [expr "2 + $i"]]
set CV_ACTIVE($i) $cv
set CV_INFO_GRID($cv,use) 1
}
}
"CVGRID" {
set idum [lindex $line 1]
set CV_INFO_GRID($idum,min) [lindex $line 2]
set CV_INFO_GRID($idum,max) [lindex $line 3]
set CV_INFO_GRID($idum,grid) [lindex $line 4]
set tmp [lindex $line 5]
if {$tmp=="PERIODIC"} {
set CV_INFO_GRID($idum,periodic) 1
set CV_INFO_GRID($idum,type) " "
} else {
set CV_INFO_GRID($idum,type) [lindex $line 5]
}
set tmp [lindex $line 6]
set CV_INFO_GRID($idum,periodic) 0
if {$tmp=="PERIODIC"} { set CV_INFO_GRID($idum,periodic) 1 }
set kkk [info exists CV_INFO_GRID($idum,use)]
if {$kkk==0} {set CV_INFO_GRID($idum,use) 0}
}
"HILLS_FILE" {
puts "WARNING: HILLS_FILE is obsolete in input."
}
"COLVAR_FILE" {
set TRAJ_INFO($c,colvar_file) [lindex $line 1]
set TRAJ_INFO($c,traj_file) [lindex $line 2]
set TRAJ_INFO($c,temp) [lindex $line 3]
set TRAJ_INFO($c,bias) [lindex $line 4]
if {$TRAJ_INFO($c,bias)==1} {
set TRAJ_INFO($c,hills_file) [lindex $line 5]
} else {
set TRAJ_INFO($c,hills_file) ""
}
incr c
}
"TRAJ_SKIP" {
set TRAJ_SKIP [lindex $line 1]
}
"TRAJ_SKIP_BAFTI" {
set TRAJ_SKIP_BAFTI [lindex $line 1]
}
"GRO_FILE" {
set GRO_FILE [lindex $line 1]
}
"CLUSTER_TYPE" {
set CLUSTER_TYPE [lindex $line 1]
}
"SIEVING" {
set sievlog [lindex $line 1]
}
"NUMBER_STRUCTURES_SIEVING" {
set sieving [lindex $line 1]
}
"MEDOIDS_CLUSTERS" {
set num_cluster [lindex $line 1]
}
"GROMACS_CUTOFF" {
set cut_off [lindex $line 1]
}
"FES_RANGE" {
set FES_RANGE [lindex $line 1]
}
default {
puts "WARNING! mis understood line:"
puts " $line"
}
}
}
# compute_active_hills
} else {
puts ""
puts "WARNING: input file $INPUT_file not found"
puts ""
return "input file $INPUT_file not found"
}
set nTRAJECTORIES $c
puts ""
puts "INPUT file ($INPUT_file) read succesfully"
puts ""
update_lists
if {$CLUSTER_TYPE == "kmed"} {hideargs .metagui3.hlf.nb.analys.nb.cl.clust.ext 3}
if {$CLUSTER_TYPE == "grmc"} {hideargs .metagui3.hlf.nb.analys.nb.cl.clust.ext 2}
}
#
# write configuration into a file
proc write_input {{NEWINPUT_file "cluster_new.in"}} {
variable KT
variable T_CLUSTER
variable T_FILL
variable GCORR
variable TR_N_EXP
variable DELTA
variable nVARIABLES
variable nCV_ACTIVE
variable CV_ACTIVE
variable CV_INFO_GRID
variable nTRAJECTORIES
variable TRAJ_SKIP
variable TRAJ_SKIP_BAFTI
variable GRO_FILE
variable FES_RANGE
variable CLUSTER_TYPE
variable REPR
variable NR
variable TRAJ_INFO
variable FES_MIN
variable FES_MAX
variable METAGUI_exe
variable START_FOLDER
variable sieving
variable sievlog
variable cut_off
variable num_cluster
set out [open $NEWINPUT_file w]
puts $out "# METAGUI_EXE $METAGUI_exe"
puts $out "KT $KT"
# TONI FIXME
# for { set h 0} {$h < [nHILLS] } { incr h } {
# set kkk [info exists TRAJ_INFO([hills2traj $h],hills_use)]
# if { $kkk == 0 } { set TRAJ_INFO([hills2traj $h],hills_use) 0 }
# puts $out "HILLS_FILE $TRAJ_INFO([hills2traj $h],hills_file) $TRAJ_INFO([hills2traj $h],hills_use) $HILLS_INFO($h,traj)"
# }
puts $out "CLUSTER_TYPE $CLUSTER_TYPE"
puts $out "FES_RANGE $FES_RANGE"
puts $out "GRO_FILE $GRO_FILE"
for { set c 0} {$c < $nTRAJECTORIES } { incr c } {
puts $out [list COLVAR_FILE \
$TRAJ_INFO($c,colvar_file) \
$TRAJ_INFO($c,traj_file) \
$TRAJ_INFO($c,temp) \
$TRAJ_INFO($c,bias) \
$TRAJ_INFO($c,hills_file)]
}
puts $out "TRAJ_SKIP $TRAJ_SKIP"
for {set i 1} {$i < [expr "$nVARIABLES+1"]} {incr i} {
puts -nonewline $out "CVGRID $i $CV_INFO_GRID($i,min) $CV_INFO_GRID($i,max) $CV_INFO_GRID($i,grid) $CV_INFO_GRID($i,type)"
if { $CV_INFO_GRID($i,periodic)==1 } { puts -nonewline $out " PERIODIC" }
puts $out ""
}
puts -nonewline $out "ACTIVE $nCV_ACTIVE "
for { set i 0} {$i < $nCV_ACTIVE } { incr i } {
puts -nonewline $out "$CV_ACTIVE($i) "
}
puts $out ""
puts $out "T_CLUSTER $T_CLUSTER"
puts $out "T_FILL $T_FILL"
puts $out "DELTA $DELTA"
puts $out "GCORR $GCORR"
puts $out "TR_N_EXP $TR_N_EXP"
puts $out "SIEVING $sievlog"
puts $out "NUMBER_STRUCTURES_SIEVING $sieving"
puts $out "MEDOIDS_CLUSTERS $num_cluster"
puts $out "GROMACS_CUTOFF $cut_off"
close $out
}
#
# load trajectories from XTC files
proc load_trajs {} {
variable nTRAJECTORIES
variable COLVAR
variable TRAJ_SKIP
variable GRO_FILE
variable TOTAL_TRAJ_FRAMES
variable TRAJ_molid
variable TOTAL_COLVAR_STRUCTURES
variable START_FOLDER
cd $START_FOLDER
variable TRAJ_INFO
set prev_TOTAL_TRAJ_FRAMES 0
# load structure file first and delete the coordinates
mol new $GRO_FILE first 0 last -1 step 1 filebonds 1 autobonds 1 waitfor all
set TRAJ_molid [molinfo top get id]
animate delete beg 0 end 0 $TRAJ_molid
for { set c 0} {$c < $nTRAJECTORIES } { incr c } {
set colvar_file $TRAJ_INFO($c,colvar_file)
set colvar_traj_file $TRAJ_INFO($c,traj_file)
# check wether COLVAR file has been loaded first
if {! [info exists COLVAR($c,traj_frames)]} {
error "ERROR! trajectories incorrectly loaded because colvar data was not loaded previously. Please, use 'load_data' first."
}
puts ""
puts "loading TRAJECTORY file $colvar_traj_file"
puts "starting from frame $COLVAR($c,first_traj_frame_to_be_loaded) and skiping every $TRAJ_SKIP frames"
mol addfile $colvar_traj_file first $COLVAR($c,first_traj_frame_to_be_loaded) last -1 step $TRAJ_SKIP filebonds 1 autobonds 1 waitfor all
set TOTAL_TRAJ_FRAMES [molinfo $TRAJ_molid get numframes]
set nFRAMES [expr "$TOTAL_TRAJ_FRAMES - $prev_TOTAL_TRAJ_FRAMES"]
set prev_TOTAL_TRAJ_FRAMES $TOTAL_TRAJ_FRAMES
puts ""
puts "TRAJECTORY file ($c) loaded succesfully"
puts " FILE: $colvar_traj_file"
puts " FRAMES: $nFRAMES"
# check wether the number of frames in COLVAR file is synchronized with the number of frames in the trajectory XTC file
if {$COLVAR($c,traj_frames) != $nFRAMES} {
puts "WARNING! the TRAJECTORY file is not synchronized with the corresponding COLVAR file"
puts " (number of loaded FRAMES should be $COLVAR($c,traj_frames)"
puts " it is very risky to continue with the analysis"
}
}
puts ""
puts "TOTAL TRAJECTORY frames: $TOTAL_TRAJ_FRAMES"
# check wether the total number of frames in all COLVAR file is synchronized with the total number of frames in all the trajectory XTC files
if {$TOTAL_TRAJ_FRAMES != $TOTAL_COLVAR_STRUCTURES} {
puts "WARNING! total trajectory FRAMES ($TOTAL_TRAJ_FRAMES) differs from total colvar STRUCTURES ($TOTAL_COLVAR_STRUCTURES)"
puts " are you sure TRAJECTORY files are synchronized with the corresponding COLVAR files?"
puts ""
puts "SOLVE THIS FIRST AND TRY AGAIN LATER!"
}
puts ""
}
#
# compute microstates
proc do_clusters {} {
variable nTRAJECTORIES
variable COLVAR
variable nCV_ACTIVE
variable CV_ACTIVE
variable CV_INFO_GRID
variable START_FOLDER
variable CLUSTER_TYPE
variable input_external
variable cut_off
variable sieving
variable sievlog
variable num_cluster
variable efdim
cd $START_FOLDER
# get ative CVs from the user interface
compute_active
list_clusters
if {$nCV_ACTIVE==0} {
error "At least one CV should be marked as active ('Use' column)"
}
# set clusters dimensions
set CLUST_SPACE ""
for { set i 0} {$i < $nCV_ACTIVE } { incr i } {
set idum $CV_ACTIVE($i)
set_dimensions $idum $CV_INFO_GRID($idum,min) $CV_INFO_GRID($idum,max) $CV_INFO_GRID($idum,grid)
lappend CLUST_SPACE $idum
}
set_cluster_space $CLUST_SPACE
# get active CVs according to the HILLS loaded
array unset HILLS
for { set h 0} {$h < [nHILLS] } { incr h } {
parse_hills $h
}
set_use_hills_default
compute_active_hills
if { $CLUSTER_TYPE == "grid" } {
set input_external GRID
set sievlog "0"
run_micro
write_frames "FRAMES"
}
if { $CLUSTER_TYPE == "read" } {
set sievlog "0"
read_data_from_cluster "MICRO_RUN"
write_frames "FRAMES"
}
if { $CLUSTER_TYPE == "external" } {
run_micro
write_frames "FRAMES"
}
if { $CLUSTER_TYPE == "kmed" } {
set input_external "KMEDOIDS $num_cluster"
run_micro
write_frames "FRAMES"
}
if { $CLUSTER_TYPE == "grmc" } {
set input_external "GROMACS $cut_off"
run_micro
write_frames "FRAMES"
}
if { $CLUSTER_TYPE == "dkmed" } {
set input_external "DENSITY $cut_off $efdim"
run_micro
write_frames "FRAMES"
}
# write microstates in the user interface (MICROSTATES box-list)
clusters_datalist_fill
}
#
# read COLVAR files into memory. See comments to read_colvars. NOT
# called for runtime variables, which are cleared.
proc load_data {} {
variable nTRAJECTORIES
variable nRUNTIME
variable COLVAR
variable TRAJ_INFO
variable TOTAL_COLVAR_FRAMES
set TOTAL_COLVAR_FRAMES 0
variable TOTAL_COLVAR_STRUCTURES
set TOTAL_COLVAR_STRUCTURES 0
variable TRAJ_SKIP
variable CV_INFO_GRID
variable START_FOLDER
cd $START_FOLDER
variable nVARIABLES
array unset COLVAR
variable in1
variable out2
puts "INFO: in load_data"
# get the number of collective variables in COLVAR files
set varlist [parse_colvars_metadata $TRAJ_INFO(0,colvar_file)]
set nVARIABLES [llength $varlist]
set nRUNTIME 0
for {set i 1} {$i <= $nVARIABLES} {incr i} {
set CV_INFO_GRID($i,type) [lindex $varlist [expr {$i-1}]]
set COLVAR($i,min) 9999999
set COLVAR($i,max) -9999999
}
# read and load into memory each colvar file
for { set c 0} {$c < $nTRAJECTORIES } { incr c } {
puts ""
puts "reading COLVAR file $TRAJ_INFO($c,colvar_file)"
puts ""
read_active_colvars_header $c
read_colvars $c
set TOTAL_COLVAR_FRAMES [expr "$TOTAL_COLVAR_FRAMES + $COLVAR($c,nframes)"]
set TOTAL_COLVAR_STRUCTURES [expr "$TOTAL_COLVAR_STRUCTURES + $COLVAR($c,traj_frames)"]
}
puts ""
puts "TOTAL COLVAR frames: $TOTAL_COLVAR_FRAMES"
puts "TOTAL COLVAR structures: $TOTAL_COLVAR_STRUCTURES"
puts ""
# update user interface with information read from colvar files
list_cvs $in1.cv.list
list_cvs_vis $out2.cv.list
#XXX
variable out1
list_hills_conv .metagui3.hlf.nb.analys.nb.wham.conv.list
list_clusters
# automatic build the default difusion matrix
build_DD
}
#
# build a default difusion matrix
proc build_DD {} {
variable nVARIABLES
variable CV_INFO_GRID
variable DD
for { set i 1} {$i <= $nVARIABLES} { incr i } {
set dds [expr "( $CV_INFO_GRID($i,max) - $CV_INFO_GRID($i,min) ) / $CV_INFO_GRID($i,grid)"]
for { set j 1} {$j <= $nVARIABLES} { incr j } {
set DD0 0
if {$i==$j} {
set DD0 [expr "$dds*$dds"]
}
if { ![info exists DD($i,$j)] } {
set DD($i,$j) $DD0
}
}
}
}
#
# analyze the structure of COLVAR files. Sanity check. Return a
# list of their names (possibly spaces), whose length can be used
# as nVARIABLES. Does not change "global" variables.
proc parse_colvars_metadata {colvarfile} {
set ret {}
set nV -1
# get the number of collective variables in the first COLVAR
# file (all colvar files are suposed to have the same
# structure).
set in [open $colvarfile r]
while {[gets $in line] != -1} {
if { [lindex $line 0] == "#!" && [lindex $line 1] == "FIELDS" } {
set nV 0
set cvs [lreplace $line 0 1]; # drop #! and FIELDS
foreach cv $cvs {
if { $cv == "time" || $cv == "vbias" } {
continue
}
incr nV
# If name is "informative", remember it (?)
if { ! [regexp {^cv} $cv] && ! [regexp {^@} $cv] } {
lappend ret $cv
# set CV_INFO_GRID($nV,type) $cv
} else {
lappend ret "unk"
}
}
break
}
}
close $in
if {$nV == -1 } {
error "ERROR: likely missing FIELDS header in COLVAR file"
} else {
puts "INFO: parse_colvar_metadata returning $ret"
}
return $ret
}
#
# analyze the structure of HILLS files
proc parse_hills {HILLS_index} {
variable nCV_ACTIVE
variable CV_ACTIVE
variable START_FOLDER
variable TRAJ_INFO
cd $START_FOLDER
set h $HILLS_index
set in [open $TRAJ_INFO([hills2traj $h],hills_file) r]
gets $in line
# parsing header. get the number and id of active CVs on each HILLS file
if { [lindex $line 0] == "#!" && [lindex $line 1] == "ACTIVE" } {
set dim [lindex $line 2]
set TRAJ_INFO([hills2traj $h],hills_dim) $dim
set TRAJ_INFO([hills2traj $h],hills_cvs) ""
for {set i 0} {$i < $dim} {incr i} {
set ia [lindex $line [expr "3 + $i"]]
set ia [expr "0 + $ia "]; # tg ??
lappend TRAJ_INFO([hills2traj $h],hills_cvs) $ia
}
# get the label of this HILLS file
set TRAJ_INFO([hills2traj $h],hills_label) [lindex $line end]
} else {
puts "WARNING! header line not found in HILLS file $TRAJ_INFO([hills2traj $h],hills_file)"
puts "example of header line: #! ACTIVE 2 1 2 ABC"
puts "are you using a Plumed version older than 1.3 ???"
puts "please fix this problem and try again"
}
close $in
puts ""
puts "HILLS file ($HILLS_index) header read succesfully"
puts " FILE: $TRAJ_INFO([hills2traj $h],hills_file)"
puts " LABEL: $TRAJ_INFO([hills2traj $h],hills_label)"
puts " DIMENSIONS: $TRAJ_INFO([hills2traj $h],hills_dim)"
puts " CVs ID: $TRAJ_INFO([hills2traj $h],hills_cvs)"
puts ""
}
#
# set which HILLS files to use (according to the CVs checked as active in the user interface)
proc set_use_hills_default {} {
variable TRAJ_INFO
variable nCV_ACTIVE
variable CV_ACTIVE
variable START_FOLDER
cd $START_FOLDER
for { set h 0} {$h < [nHILLS] } { incr h } {
set goodall 1
foreach ia $TRAJ_INFO([hills2traj $h],hills_cvs) {
set good 0
for { set i 0} {$i < $nCV_ACTIVE } { incr i } {
if { $ia == $CV_ACTIVE($i) } {
set good 1
}
}
set goodall [ expr " $goodall * $good" ]
}
set TRAJ_INFO([hills2traj $h],hills_use) $goodall
if {$TRAJ_INFO([hills2traj $h],hills_use)} {
puts "HILLS file $TRAJ_INFO([hills2traj $h],hills_file) WILL BE USED FOR WHAM ANALYSIS"
}
}
}
# read the ACTIVE lines, including bias label (currently unused)
# and the list of active CVs to be shown in the GUI. This is only
# done if "biased" is true for that trajectory. Fills
# TRAJ_INFO(*,hills_cvs) and TRAJ_INFO(*,bias_label)
proc read_active_colvars_header {c} {
variable TRAJ_INFO
puts "INFO: in read_active_colvars_header with arg $c"
set biased $TRAJ_INFO($c,bias)
set colvar_file $TRAJ_INFO($c,colvar_file)
set found 0
set in [open $colvar_file r]
while {[gets $in line] != -1} {
if [ regexp {^#! ACTIVE} $line ] {
set found 1
break
}
}
close $in
# ACTIVE mandatory for biased case
if {$biased && ! $found } {
error "ERROR! bias not defined for COLVAR file: $colvar_file
Header line not found.
Example of header line: #! ACTIVE 2 1 2 ABC
Plumed version >= 1.3 is required.
Please fix this problem and try again."
}
# Fallbacks only for the unbiased case
set bias_label "Unlabeled"
set hills_cvs ""
if {$found} {
# Now $line is as follows
# #! ACTIVE <N> <cv1> ... <cvN> <label>
# 0 1 2 3 3+N-1 end
set bias_label [lindex $line end]
set N [lindex $line 2]
set hills_cvs [lrange $line 3 [expr 2+$N]]
}
set TRAJ_INFO($c,bias_label) $bias_label
set TRAJ_INFO($c,hills_cvs) $hills_cvs
}
# Read and load into memory the contents of each COLVAR file. The
# argument $tr is a TRAJECTORY (!) index, 0 < $tr < nTRAJECTORIES
#
# If the "runtime" arg is 1, the runtime colvars (there are
# nRUNTIME of them) are appended to the existing ones
# (1..nVARIABLES). The caller will later adjust nVARIABLES to
# nVARIABLES+nRUNTIME . Even if runtime==1, the time column from
# previously-loaded colvar files is used; this is due to the fact
# that "driver" has no knowledge of real simulation timestamps.
#
# TRAJ_SKIP_BAFTI appears to be a way to stride frames, but it is
# not bound to UI elements.
#
# Reads:
# $TRAJ_INFO($tr,colvar_file)
# $TRAJ_INFO($tr,bias_label)
# possibly $TRAJ_INFO($tr,runtime_colvar)
# Sets:
# $COLVAR($tr,$f,time)
# $COLVAR($tr,$f,$i) 1 <= i <= nVARIABLES
# $COLVAR($i,min) <--- note that the index is not tr!
# $COLVAR($i,max) <--- note that the index is not tr!
# $COLVAR($tr,$f,bias_label)
# $COLVAR($tr,$f,cluster) -999
# $COLVAR($tr,nframes) $f
# $COLVAR($tr,traj_frames) $ff
proc read_colvars {tr {runtime 0}} {
variable COLVAR
variable nVARIABLES
variable nRUNTIME
variable TRAJ_SKIP
variable TRAJ_SKIP_BAFTI
variable TRAJ_INFO
variable T_CLUSTER
variable START_FOLDER
puts "INFO: in read_colvars with arguments $tr $runtime"
cd $START_FOLDER
set colvar_file $TRAJ_INFO($tr,colvar_file)
set current_bias $TRAJ_INFO($tr,bias_label); # copied into COLVAR($tr,$f,bias)
# Counters--
set ii 0; # actual lines in file
set f 0; # frames > T_CLUSTER
set ff 0; # frames > T_CLUSTER not skipped
set in [open $colvar_file r]
if {$runtime==0} {
# Read columns 1..nVARIABLES into CVs 1..nVARIABLES
set colvarOffset 0
set ncols $nVARIABLES
} else {
# Read columns 1..nRUNTIME into CVs nVARIABLES+1 .. nVARIABLES+nRUNTIME
set colvarOffset $nVARIABLES
set ncols $nRUNTIME
# If runtime, open and skip over comments
set in_r [open $TRAJ_INFO($tr,runtime_colvar) r]
while { [gets $in_r line_r] != -1} {
if { ! [ regexp {^#} $line_r ] } {
break
}
}
}
# Scan the rest of the COLVAR file
while {[gets $in line] != -1} {
if [ regexp {^#} $line ] {
# comment or header, do nothing
continue
}
if {$runtime==0} {
set line_data $line
} else {
set line_data $line_r
gets $in_r line_r
}
# Time comes from the "real" COLVAR file in any case
set this_time [lindex $line 0]
# read only COLVAR frames after T_CLUSTER
if {$this_time >= $T_CLUSTER} {
# TONI I don't fully get the logic of first_traj_frame_to_be_loaded
if {[info exists COLVAR($tr,first_traj_frame_to_be_loaded)]} {
# puts "DEBUG: first_traj_frame_to_be_loaded already set on trj. $tr"
} else {
if {[expr "$ii%$TRAJ_SKIP_BAFTI"]==0} {
set COLVAR($tr,first_traj_frame_to_be_loaded) [expr "$ii/$TRAJ_SKIP_BAFTI"]
}
}
if {[info exists COLVAR($tr,first_traj_frame_to_be_loaded)]} {
# These properties are being set again to their old value when runtime==1
set COLVAR($tr,$f,time) $this_time
set COLVAR($tr,$f,cluster) -999
for {set col 1} {$col <= $ncols } {incr col} {
set cval [lindex $line_data $col]
# i is the actual CV number, from 1
set i [expr {$col+$colvarOffset}]
set COLVAR($tr,$f,$i) $cval
if {$cval < $COLVAR($i,min)} { set COLVAR($i,min) $cval }
if {$cval > $COLVAR($i,max)} { set COLVAR($i,max) $cval }
set COLVAR($tr,$f,bias) $current_bias; # TONI - I think this is redundant bc it's constant for each trajectory?
}
incr f
if {[expr "($ii-$COLVAR($tr,first_traj_frame_to_be_loaded))%($TRAJ_SKIP*$TRAJ_SKIP_BAFTI)"] == 0} {
incr ff
}
}
}
incr ii
}
close $in
if {$runtime==1} {
close $in_r
}
set COLVAR($tr,nframes) $f
set COLVAR($tr,traj_frames) $ff
puts ""
puts "COLVAR file ($tr) read succesfully"
puts " FILE: $colvar_file"
puts " VARIABLES: $nVARIABLES"
puts " FRAMES: $COLVAR($tr,nframes)"
puts " STRUCTURES: $COLVAR($tr,traj_frames)"
puts " RUNTIME: $runtime"
if {$runtime==1} {
puts " RUNTIME CVs: $nRUNTIME"
puts " FILE: $TRAJ_INFO($tr,runtime_colvar)"
}
puts ""
}
#
# set space dimensions for each CV for microstates analysis
proc set_dimensions {VARIABLE_number min_LIMIT max_LIMIT GRID_size} {
variable DIMENSIONS
set DIMENSIONS($VARIABLE_number,min) $min_LIMIT
set DIMENSIONS($VARIABLE_number,max) $max_LIMIT
set DIMENSIONS($VARIABLE_number,grid) $GRID_size
set DIMENSIONS($VARIABLE_number,spacer) [expr "(double($max_LIMIT)-double($min_LIMIT))/double($GRID_size)"]
puts ""
puts "GRID DIMENSIONS set for variable number $VARIABLE_number -> $DIMENSIONS($VARIABLE_number,min):$DIMENSIONS($VARIABLE_number,spacer):$DIMENSIONS($VARIABLE_number,max)"
puts ""
}
#
# set microstates space for each active CV
proc set_cluster_space {VARIABLES_list} {
variable CLUSTER_SPACE
variable CLUSTER_SPACE_dim
variable CLUSTER_SPACE_vol
variable DIMENSIONS
variable CV_INFO_GRID
variable myVARS
set CLUSTER_SPACE $VARIABLES_list
set CLUSTER_SPACE_dim [llength $CLUSTER_SPACE]
for {set i 0} {$i < $CLUSTER_SPACE_dim} {incr i} {
set myVARS($i,number) [lindex $CLUSTER_SPACE $i]
set myVARS($i,min) $DIMENSIONS($myVARS($i,number),min)
set myVARS($i,max) $DIMENSIONS($myVARS($i,number),max)
set myVARS($i,grid) $DIMENSIONS($myVARS($i,number),grid)
set myVARS($i,spacer) $DIMENSIONS($myVARS($i,number),spacer)
# define period in myVARS to properly compute distances (ALEX)
set myVARS($i,period) 0
if {$CV_INFO_GRID($myVARS($i,number),periodic) == 1} {
set myVARS($i,period) [expr "double($myVARS($i,max))-double($myVARS($i,min))"]
}
}
set j $CLUSTER_SPACE_dim
set myshift 1
set j [expr "$j-1"]
set myVARS($j,shift) $myshift
while {$j > 0} {
set myshift [expr "$myshift*$myVARS($j,grid)"]
set j [expr "$j-1"]
set myVARS($j,shift) $myshift
}
set l [expr "$CLUSTER_SPACE_dim - 1"]
set CLUSTER_SPACE_vol [expr "$myVARS(0,shift)*$myVARS($l,grid)"]
puts ""
puts "CLUSTER SPACE set to variables numbers: $CLUSTER_SPACE"
puts "CLUSTER SPACE dimensionality = $CLUSTER_SPACE_dim dimensions"
puts "CLUSTER SPACE volume = $CLUSTER_SPACE_vol clusters"
puts ""
}
#
# write input file microstates.in for clusters calculation
# (MICROSTATES) with external program (cluster.x). Called from