-
Notifications
You must be signed in to change notification settings - Fork 6
/
parse_amber.tcl
1886 lines (1637 loc) · 57.5 KB
/
parse_amber.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
#
# Reader for AMBER prmtop and inpcrd files \$Revision: 3097
#
# Current status -
#
# %FLAG TITLE skipped
# %FLAG POINTERS ok
# %FLAG ATOM_NAME loaded but not usd
# %FLAG CHARGE ok
# %FLAG MASS loaded but not usd
# %FLAG ATOM_TYPE_INDEX ok
# %FLAG NUMBER_EXCLUDED_ATOMS ok
# %FLAG NONBONDED_PARM_INDEX ok
# %FLAG RESIDUE_LABEL loaded but not used
# %FLAG RESIDUE_POINTER loaded but not used
# %FLAG BOND_FORCE_CONSTANT ok
# %FLAG BOND_EQUIL_VALUE ok
# %FLAG ANGLE_FORCE_CONSTANT ok
# %FLAG ANGLE_EQUIL_VALUE ok
# %FLAG DIHEDRAL_FORCE_CONSTANT ok - see below
# %FLAG DIHEDRAL_PERIODICITY ok
# %FLAG DIHEDRAL_PHASE ok
# %FLAG SOLTY skipped
# %FLAG LENNARD_JONES_ACOEF ok
# %FLAG LENNARD_JONES_BCOEF ok
# %FLAG BONDS_INC_HYDROGEN ok
# %FLAG BONDS_WITHOUT_HYDROGEN ok
# %FLAG ANGLES_INC_HYDROGEN ok
# %FLAG ANGLES_WITHOUT_HYDROGEN ok
# %FLAG DIHEDRALS_INC_HYDROGEN ok
# %FLAG DIHEDRALS_WITHOUT_HYDROGEN "
# %FLAG EXCLUDED_ATOMS_LIST !! loaded but not checked
# %FLAG HBOND_ACOEF need check -
# %FLAG HBOND_BCOEF need check
# %FLAG HBCUT skipped - believed obsolete
# %FLAG AMBER_ATOM_TYPE used - but mapping to elements only for parm94, see amber_type_to_z
# %FLAG TREE_CHAIN_CLASSIFICATION skipped
# %FLAG JOIN_ARRAY skipped
# %FLAG IROTAT skipped
# %FLAG SOLVENT_POINTERS skipped
# %FLAG ATOMS_PER_MOLECULE skipped
# %FLAG BOX_DIMENSIONS (IFBOX = 1) read in, processed if orthogonal
# %FLAG RADIUS_SET skipped
# %FLAG RADII skipped
# %FLAG SCREEN skipped
# Meaning of pointer section from www
# NATOM : total number of atoms
# NTYPES : total number of distinct atom types
# NBONH : number of bonds containing hydrogen
# MBONA : number of bonds not containing hydrogen
# NTHETH : number of angles containing hydrogen
# MTHETA : number of angles not containing hydrogen
# NPHIH : number of dihedrals containing hydrogen
# MPHIA : number of dihedrals not containing hydrogen
# NHPARM : currently not used
# NPARM : currently not used
# NEXT : number of excluded atoms
# NRES : number of residues
# NBONA : MBONA + number of constraint bonds
# NTHETA : MTHETA + number of constraint angles
# NPHIA : MPHIA + number of constraint dihedrals
# NUMBND : number of unique bond types
# NUMANG : number of unique angle types
# NPTRA : number of unique dihedral types
# NATYP : number of atom types in parameter file, see SOLTY below
# NPHB : number of distinct 10-12 hydrogen bond pair types
# IFPERT : set to 1 if perturbation info is to be read in
# NBPER : number of bonds to be perturbed
# NGPER : number of angles to be perturbed
# NDPER : number of dihedrals to be perturbed
# MBPER : number of bonds with atoms completely in perturbed group
# MGPER : number of angles with atoms completely in perturbed group
# MDPER : number of dihedrals with atoms completely in perturbed groups
# IFBOX : set to 1 if standard periodic box, 2 when truncated octahedral
# NMXRS : number of atoms in the largest residue
# IFCAP : set to 1 if the CAP option from edit was specified
proc prmtop_skip_to { fp field } {
set more 1
while {$more} {
set code [ gets $fp line ]
#puts stdout $line
if { $code < 0 } { chemerror "prmtop field $field not found" }
if { [ string index $line 0 ] == "%" } {
#puts stdout HIT1
if { [ string index $line 2 ] == "L" } {
#puts stdout HIT2
set line "$line "
if { [ string range $line 6 20 ] == "$field" } {
#puts stdout HIT3
set more 0
} else {
#puts stdout "X [ string range $line 6 20 ] X $field"
}
}
}
}
}
proc red3 { val } {
if { $val < 0 } {
set val [ expr abs($val) ]
set fac -1
} else {
set fac 1
}
return [ expr $fac * ($val/3 + 1 ) ]
}
proc parse_prmtop { file } {
upvar amber_prmtop amber_prmtop
#
# In AMBER, the parm + top entries are combined so there is actually no need
# to load in the AMBER parameter files
#
# It is possible to work out the number of types of parameter and also
# the instances of where these parameters are used
#
# Unlike CHARMM, the vdw parameters are already combined in the prmtop
# file and therefor combination rules dont need to be applied here
set inst amber1
set fp [ open $file r ]
# %VERSION VERSION_STAMP = V0001.000 DATE = 08/24/05 04:08:16
gets $fp line
if { [ string index $line 0 ] != "%" } {
puts stdout OLD
parse_old_prmtop $fp
return
}
# %FLAG TITLE %FORMAT(20a4) ======================================================
#
#
# %FLAG POINTERS %FORMAT(10I8) ===================================================
#
prmtop_skip_to $fp "POINTERS "
# skip format
gets $fp line
gets $fp line
set NATOM [ lindex $line 0 ]
set NTYPES [lindex $line 1 ]
set NBONH [lindex $line 2]
set MBONA [lindex $line 3]
set NTHETH [lindex $line 4]
set MTHETA [lindex $line 5]
set NPHIH [lindex $line 6]
set MPHIA [lindex $line 7]
set NHPARM [lindex $line 8]
set NPARM [lindex $line 9]
gets $fp line
set NNB [lindex $line 0]
set NRES [lindex $line 1]
set NBONA [lindex $line 2]
set NTHETA [lindex $line 3]
set NPHIA [lindex $line 4]
set NUMBND [lindex $line 5]
set NUMANG [lindex $line 6]
set NPTRA [lindex $line 7]
set NATYP [lindex $line 8]
set NPHB [lindex $line 9]
gets $fp line
set IFPERT [lindex $line 0]
set NBPER [lindex $line 1]
set NGPER [lindex $line 2]
set NDPER [lindex $line 3]
set MBPER [lindex $line 4]
set MGPER [lindex $line 5]
set MDPER [lindex $line 6]
#puts "RB here. line is $line"
set IFBOX [lindex $line 7]
set NMXRS [lindex $line 8]
set IFCAP [lindex $line 9]
# save as part of the main array for later use to reduce number of global variables
foreach var { NATOM NTYPES NBONH MBONA NTHETH MTHETA NPHIH MPHIA NHPARM NPARM NNB
NRES NBONA NTHETA NPHIA NUMBND NUMANG NPTRA NATYP NPHB IFPERT
NBPER NGPER NDPER MBPER MGPER MDPER IFBOX NMXRS IFCAP } {
set amber_prmtop($inst,$var) [ set $var ]
}
gets $fp line
set NUMEXTRA [lindex $line 0]
#set NCOP [lindex $line 1]
# %FLAG ATOM_NAME %FORMAT(20a4) ===================================================
prmtop_skip_to $fp "ATOM_NAME "
gets $fp line
set count 20
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 19 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 4] [ expr ( $count + 1 ) * 4 - 1 ] ]
set amber_prmtop($inst,ATOM_NAME,$i) $label
incr count
}
# %FLAG CHARGE %FORMAT(5E16.8) ================================================
prmtop_skip_to $fp "CHARGE "
gets $fp line
set count 20
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
#puts stdout $label
set amber_prmtop($inst,CHARGE,$i) [ string trim $label ]
incr count
}
# %FLAG MASS %FORMAT(5E16.8) ==================================================
prmtop_skip_to $fp "MASS "
gets $fp line
set count 20
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,MASS,$i) [ string trim $label]
incr count
}
# %FLAG ATOM_TYPE_INDEX %FORMAT(10I8) ============================================
prmtop_skip_to $fp "ATOM_TYPE_INDEX"
gets $fp line
set count 10
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set amber_prmtop($inst,TYPE_INDEX,$i) [ expr int ($label ) ]
incr count
}
# %FLAG NUMBER_EXCLUDED_ATOMS %FORMAT(10I8) ===============================================
prmtop_skip_to $fp "NUMBER_EXCLUDED"
gets $fp line
set count 10
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set amber_prmtop($inst,N_EXCL_ATOMS,$i) [ expr int ($label ) ]
incr count
}
# %FLAG NONBONDED_PARM_INDEX %FORMAT(10I8) ===================================================
prmtop_skip_to $fp "NONBONDED_PARM_"
gets $fp line
set count 10
for { set i 0 } { $i < $NTYPES } { incr i } {
for { set j 0 } { $j < $NTYPES } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set amber_prmtop($inst,NONB_PARM_INDEX,$i,$j) [ expr int ($label ) ]
incr count
}
}
# %FLAG RESIDUE_LABEL %FORMAT(20a4) ===================================================
prmtop_skip_to $fp "RESIDUE_LABEL "
gets $fp line
set count 20
for { set i 0 } { $i < $NRES } { incr i } {
if { $count > 19 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 4] [ expr ( $count + 1 ) * 4 - 1 ] ]
set amber_prmtop($inst,RESIDUE_LAB,$i) $label
incr count
}
# %FLAG RESIDUE_POINTER %FORMAT(10I8) ===================================================
prmtop_skip_to $fp "RESIDUE_POINTER"
gets $fp line
set count 10
for { set i 0 } { $i < $NRES } { incr i } {
if { $count > 9 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set amber_prmtop($inst,RESIDUE_PTR,$i) [ string trim $label ]
incr count
}
# %FLAG BOND_FORCE_CONSTANT %FORMAT(5E16.8) =============================================
prmtop_skip_to $fp "BOND_FORCE_CONS"
gets $fp line
set count 5
for { set i 0 } { $i < $NUMBND } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,BOND_FC,$i) [ string trim $label ]
incr count
}
# %FLAG BOND_EQUIL_VALUE %FORMAT(5E16.8) ================================================
prmtop_skip_to $fp "BOND_EQUIL_VALU"
gets $fp line
set count 5
for { set i 0 } { $i < $NUMBND } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,BOND_R0,$i) [ string trim $label ]
incr count
}
# %FLAG ANGLE_FORCE_CONSTANT %FORMAT(5E16.8) =============================================
prmtop_skip_to $fp "ANGLE_FORCE_CON"
gets $fp line
set count 5
for { set i 0 } { $i < $NUMANG } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,ANG_FC,$i) [ string trim $label ]
incr count
}
# %FLAG ANGLE_EQUIL_VALUE %FORMAT(5E16.8) ==============================================
prmtop_skip_to $fp "ANGLE_EQUIL_VAL"
gets $fp line
set count 5
for { set i 0 } { $i < $NUMANG } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,ANG_A0,$i) [ string trim $label ]
incr count
}
# %FLAG DIHEDRAL_FORCE_CONSTANT %FORMAT(5E16.8) ========================================
prmtop_skip_to $fp "DIHEDRAL_FORCE_"
gets $fp line
set count 5
for { set i 0 } { $i < $NPTRA } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,DIHEDRAL_FC,$i) [ string trim $label]
incr count
}
# %FLAG DIHEDRAL_PERIODICITY %FORMAT(5E16.8) ==========================================
prmtop_skip_to $fp "DIHEDRAL_PERIOD"
gets $fp line
set count 5
for { set i 0 } { $i < $NPTRA } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,DIHEDRAL_PERIOD,$i) [ string trim $label ]
incr count
}
# %FLAG DIHEDRAL_PHASE %FORMAT(5E16.8) ============================================
prmtop_skip_to $fp "DIHEDRAL_PHASE "
gets $fp line
set count 5
for { set i 0 } { $i < $NPTRA } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,DIHEDRAL_PHASE,$i) [ string trim $label ]
incr count
}
# %FLAG SOLTY %FORMAT(5E16.8) ===================================================
# %FLAG LENNARD_JONES_ACOEF %FORMAT(5E16.8) =======================================
set ntri [ expr $NTYPES*($NTYPES+1)/2 ]
# From http://amber.scripps.edu/formats.html
#
#CN1 : Lennard Jones r**12 terms for all possible atom type
# interactions, indexed by ICO and IAC; for atom i and j
# where i < j, the index into this array is as follows
# (assuming the value of ICO(index) is positive):
# CN1(ICO(NTYPES*(IAC(i)-1)+IAC(j))).
prmtop_skip_to $fp "LENNARD_JONES_A"
gets $fp line
set count 5
set k 0
for { set i 0 } { $i < $NTYPES } { incr i } {
for { set j 0 } { $j <= $i } { incr j } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
#puts stdout $label
set amber_prmtop($inst,LJA,$k) [ string trim $label ]
incr count
incr k
}
}
# %FLAG LENNARD_JONES_BCOEF %FORMAT(5E16.8) ===========================================
prmtop_skip_to $fp "LENNARD_JONES_B"
gets $fp line
set count 5
set k 0
for { set i 0 } { $i < $NTYPES } { incr i } {
for { set j 0 } { $j <= $i } { incr j } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,LJB,$k) [ string trim $label ]
incr count
incr k
}
}
# %FLAG BONDS_INC_HYDROGEN %FORMAT(10I8) ==============================================
prmtop_skip_to $fp "BONDS_INC_HYDRO"
gets $fp line
set count 10
for { set i 0 } { $i < $NBONH } { incr i } {
for { set j 0 } { $j < 3 } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set tmp($j) [ expr int ($label ) ]
incr count
}
# reduce to atom indices
set amber_prmtop($inst,BONDS_H,$i,I) [ expr $tmp(0)/3 + 1 ]
set amber_prmtop($inst,BONDS_H,$i,J) [ expr $tmp(1)/3 + 1 ]
set amber_prmtop($inst,BONDS_H,$i,TYPE) $tmp(2)
}
# %FLAG BONDS_WITHOUT_HYDROGEN %FORMAT(10I8) ===============================================
prmtop_skip_to $fp "BONDS_WITHOUT_H"
gets $fp line
set count 10
for { set i 0 } { $i < $NBONA } { incr i } {
for { set j 0 } { $j < 3 } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set tmp($j) [ expr int ($label ) ]
incr count
}
# reduce to atom indices
set amber_prmtop($inst,BONDS_A,$i,I) [ expr $tmp(0)/3 + 1 ]
set amber_prmtop($inst,BONDS_A,$i,J) [ expr $tmp(1)/3 + 1 ]
set amber_prmtop($inst,BONDS_A,$i,TYPE) $tmp(2)
}
# %FLAG ANGLES_INC_HYDROGEN %FORMAT(10I8) =================================================
prmtop_skip_to $fp "ANGLES_INC_HYDR"
gets $fp line
set count 10
for { set i 0 } { $i < $NTHETH } { incr i } {
for { set j 0 } { $j < 4 } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set tmp($j) [ expr int ($label ) ]
incr count
}
# reduce to atom indices
set amber_prmtop($inst,ANGLES_H,$i,I) [ expr $tmp(0)/3 + 1 ]
set amber_prmtop($inst,ANGLES_H,$i,J) [ expr $tmp(1)/3 + 1 ]
set amber_prmtop($inst,ANGLES_H,$i,K) [ expr $tmp(2)/3 + 1 ]
set amber_prmtop($inst,ANGLES_H,$i,TYPE) $tmp(3)
}
# %FLAG ANGLES_WITHOUT_HYDROGEN %FORMAT(10I8) ==============================================
prmtop_skip_to $fp "ANGLES_WITHOUT_"
gets $fp line
set count 10
for { set i 0 } { $i < $NTHETA } { incr i } {
for { set j 0 } { $j < 4 } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set tmp($j) [ expr int ($label ) ]
incr count
}
# reduce to atom indices
set amber_prmtop($inst,ANGLES_A,$i,I) [ expr $tmp(0)/3 + 1 ]
set amber_prmtop($inst,ANGLES_A,$i,J) [ expr $tmp(1)/3 + 1 ]
set amber_prmtop($inst,ANGLES_A,$i,K) [ expr $tmp(2)/3 + 1 ]
set amber_prmtop($inst,ANGLES_A,$i,TYPE) $tmp(3)
}
# %FLAG DIHEDRALS_INC_HYDROGEN %FORMAT(10I8) ==============================================
prmtop_skip_to $fp "DIHEDRALS_INC_H"
gets $fp line
set count 10
for { set i 0 } { $i < $NPHIH } { incr i } {
for { set j 0 } { $j < 5 } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set tmp($j) [ expr int ($label ) ]
incr count
}
# reduce to atom indices
set amber_prmtop($inst,DIHEDRALS_H,$i,I) [ red3 $tmp(0) ]
set amber_prmtop($inst,DIHEDRALS_H,$i,J) [ red3 $tmp(1) ]
set amber_prmtop($inst,DIHEDRALS_H,$i,K) [ red3 $tmp(2) ]
set amber_prmtop($inst,DIHEDRALS_H,$i,L) [ red3 $tmp(3) ]
set amber_prmtop($inst,DIHEDRALS_H,$i,TYPE) $tmp(4)
}
# %FLAG DIHEDRALS_WITHOUT_HYDROGEN %FORMAT(10I8) =======================================
prmtop_skip_to $fp "DIHEDRALS_WITHO"
gets $fp line
set count 10
for { set i 0 } { $i < $NPHIA } { incr i } {
for { set j 0 } { $j < 5 } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
set tmp($j) [ expr int ($label ) ]
incr count
}
# reduce to atom indices
set amber_prmtop($inst,DIHEDRALS_A,$i,I) [ red3 $tmp(0) ]
set amber_prmtop($inst,DIHEDRALS_A,$i,J) [ red3 $tmp(1) ]
set amber_prmtop($inst,DIHEDRALS_A,$i,K) [ red3 $tmp(2) ]
set amber_prmtop($inst,DIHEDRALS_A,$i,L) [ red3 $tmp(3) ]
set amber_prmtop($inst,DIHEDRALS_A,$i,TYPE) $tmp(4)
}
# %FLAG EXCLUDED_ATOMS_LIST %FORMAT(10I8) =============================================
#
# NATEX : the excluded atom list. To get the excluded list for atom
# "i" you need to traverse the NUMEX list, adding up all
# the previous NUMEX values, since NUMEX(i) holds the number
# of excluded atoms for atom "i", not the index into the
# NATEX list. Let IEXCL = SUM(NUMEX(j), j=1,i-1), then
# excluded atoms are NATEX(IEXCL) to NATEX(IEXCL+NUMEX(i)).
prmtop_skip_to $fp "EXCLUDED_ATOMS_"
gets $fp line
set count 10
for { set i 0 } { $i < $NATOM } { incr i } {
for { set j 0 } { $j < $amber_prmtop($inst,N_EXCL_ATOMS,$i) } { incr j } {
if { $count > 9} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 8] [ expr ( $count + 1 ) * 8 - 1 ] ]
incr count
set amber_prmtop($inst,EXCL,$i,$j) [ expr int ($label ) ]
}
}
# %FLAG HBOND_ACOEF %FORMAT(5E16.8) ================================================
prmtop_skip_to $fp "HBOND_ACOEF "
gets $fp line
set count 5
set k 0
for { set i 0 } { $i < $NPHB } { incr i } {
for { set j 0 } { $j <= $i } { incr j } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,HBA,$k) $label
incr count
incr k
}
}
# %FLAG HBOND_BCOEF %FORMAT(5E16.8) ==============================================
prmtop_skip_to $fp "HBOND_BCOEF "
gets $fp line
set count 5
set k 0
for { set i 0 } { $i < $NPHB } { incr i } {
for { set j 0 } { $j <= $i } { incr j } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,HBB,$k) [ string trim $label]
incr count
incr k
}
}
# %FLAG HBCUT %FORMAT(5E16.8) =================================================
# no longer in use
# %FLAG AMBER_ATOM_TYPE %FORMAT(20a4) ==========================================
prmtop_skip_to $fp "AMBER_ATOM_TYPE"
gets $fp line
set count 20
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 19 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 4] [ expr ( $count + 1 ) * 4 - 1 ] ]
#
#RB
#puts stdout $label
set amber_prmtop($inst,AMBER_ATOM_TYPE,$i) [ string trim $label ]
incr count
}
# %FLAG TREE_CHAIN_CLASSIFICATION %FORMAT(20a4) ================================
# %FLAG JOIN_ARRAY %FORMAT(10I8) ==============================================
# %FLAG IROTAT %FORMAT(10I8) ===================================================
#puts "RB here2. IFBOX is $IFBOX"
if { $IFBOX > 0 } {
# The following are only present if IFBOX .gt. 0
# %FLAG SOLVENT_POINTERS %FORMAT(3I8) ===========================================
# %FLAG ATOMS_PER_MOLECULE %FORMAT(10I8) ========================================
# %FLAG BOX_DIMENSIONS %FORMAT(5E16.8) ==========================================
# BETA, BOX(1), BOX(2), BOX(3)
prmtop_skip_to $fp "BOX_DIMENSIONS "
gets $fp line
gets $fp line
set count 0
for { set i 0 } { $i < 4 } { incr i } {
set tmp($i) [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
incr count
}
set amber_prmtop($inst,BETA) $tmp(0)
set amber_prmtop($inst,BOX,1) $tmp(1)
set amber_prmtop($inst,BOX,2) $tmp(2)
set amber_prmtop($inst,BOX,3) $tmp(3)
}
# %FLAG RADII %FORMAT(5E16.8) ===================================================
# %FLAG SCREEN %FORMAT(5E16.8) ==================================================
#parray amber_prmtop
}
proc load_amber_types { coords } {
#
# This routine loads up the amber types. Note that the integer TYPE_INDEX
# values run over a smaller range than the number of unique AMBER_ATOM_TYPE
# names, a number of types can share common VDW parameters.
#
# as far as I can tell the numerical index is only needed to code for the vdw
# energy. Charges are stored separately and all internal coordinate based
# terms are defined separately.
#
# lsearch needs exact flag as C* is an amber type
#
upvar amber_prmtop amber_prmtop
set inst amber1
set n [ get_number_of_atoms coords=$coords ]
global amber_types
global amber_charges
global amber_code_from_type
global amber_known_types
set amber_types {}
set amber_charges {}
# set amber_code_from_type {}
set amber_known_types {}
push_banner_flag 0
for { set i 0 } { $i < $n} { incr i } {
set symbol $amber_prmtop($inst,AMBER_ATOM_TYPE,$i)
lappend amber_types $symbol
#puts "RB. amber_types is $amber_types"
set chg $amber_prmtop($inst,CHARGE,$i)
lappend amber_charges [ expr $chg / 18.2223 ]
if { [ lsearch -exact $amber_known_types $symbol ] == -1 } {
set z [ get_atom_znum coords=$coords atom_number = [ expr $i + 1] ]
param_add_type $symbol $z
lappend amber_known_types $symbol
set code $amber_prmtop($inst,TYPE_INDEX,$i)
set amber_code_from_type($symbol) $code
}
}
#puts "RBX amber atom types $amber_types"
#puts stdout "DEBUG TYPE"
#parray amber_code_from_type
pop_banner_flag
}
proc list_amber_atom_types {} {
global amber_types
return $amber_types
}
proc list_amber_atom_charges {} {
global amber_charges
return $amber_charges
}
proc parse_old_prmtop { fp } {
upvar amber_prmtop amber_prmtop
#
# In AMBER, the parm + top entries are combined so there is actually no need
# to load in the AMBER parameter files
#
# It is possible to work out the number of types of parameter and also
# the instances of where these parameters are used
#
# Unlike CHARMM, the vdw parameters are already combined in the prmtop
# file and therefor combination rules dont need to be applied here
set inst amber1
#set fp [ open $file r ]
# first line - title?
# already read in...
#gets $fp line
# pointers line, 30 numbers 12i6
set count 12
for { set i 0 } { $i < 31 } { incr i } {
if { $count > 11 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 6] [ expr ( $count + 1 ) * 6 - 1 ] ]
set tmp($i) [ string trim $label ]
incr count
}
set NATOM $tmp(0)
set NTYPES $tmp(1)
set NBONH $tmp(2)
set MBONA $tmp(3)
set NTHETH $tmp(4)
set MTHETA $tmp(5)
set NPHIH $tmp(6)
set MPHIA $tmp(7)
set NHPARM $tmp(8)
set NPARM $tmp(9)
set NNB $tmp(10)
set NRES $tmp(11)
set NBONA $tmp(12)
set NTHETA $tmp(13)
set NPHIA $tmp(14)
set NUMBND $tmp(15)
set NUMANG $tmp(16)
set NPTRA $tmp(17)
set NATYP $tmp(18)
set NPHB $tmp(19)
set IFPERT $tmp(20)
set NBPER $tmp(21)
set NGPER $tmp(22)
set NDPER $tmp(23)
set MBPER $tmp(24)
set MGPER $tmp(25)
set MDPER $tmp(26)
set IFBOX $tmp(27)
set NMXRS $tmp(28)
set IFCAP $tmp(29)
set NEXTRA $tmp(30)
# save as part of the main array for later use to reduce number of global variables
foreach var { NATOM NTYPES NBONH MBONA NTHETH MTHETA NPHIH MPHIA NHPARM NPARM NNB
NRES NBONA NTHETA NPHIA NUMBND NUMANG NPTRA NATYP NPHB IFPERT
NBPER NGPER NDPER MBPER MGPER MDPER IFBOX NMXRS IFCAP NEXTRA } {
set amber_prmtop($inst,$var) [ set $var ]
}
# ATOM_NAME NATOM * 20a4
set count 20
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 19 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 4] [ expr ( $count + 1 ) * 4 - 1 ] ]
set amber_prmtop($inst,ATOM_NAME,$i) $label
incr count
}
# CHARGE NATOM * 5E16.8
set count 5
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
#puts stdout $label
set amber_prmtop($inst,CHARGE,$i) [ string trim $label ]
incr count
}
# MASS NATOM * 5E16.8
set count 5
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,MASS,$i) [ string trim $label]
incr count
}
# ATOM_TYPE_INDEX NATOM * 12I6
set count 12
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 11} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 6] [ expr ( $count + 1 ) * 6 - 1 ] ]
set amber_prmtop($inst,TYPE_INDEX,$i) [ expr int ($label ) ]
incr count
}
# NUMBER_EXCLUDED_ATOMS 12I6
set count 12
for { set i 0 } { $i < $NATOM } { incr i } {
if { $count > 11} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 6] [ expr ( $count + 1 ) * 6 - 1 ] ]
set amber_prmtop($inst,N_EXCL_ATOMS,$i) [ expr int ($label ) ]
incr count
}
# NONBONDED_PARM_INDEX 12I6
set count 12
for { set i 0 } { $i < $NTYPES } { incr i } {
for { set j 0 } { $j < $NTYPES } { incr j } {
if { $count > 11} {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 6] [ expr ( $count + 1 ) * 6 - 1 ] ]
set amber_prmtop($inst,NONB_PARM_INDEX,$i,$j) [ expr int ($label ) ]
incr count
}
}
# RESIDUE_LABEL NRES 20a4
set count 20
for { set i 0 } { $i < $NRES } { incr i } {
if { $count > 19 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 4] [ expr ( $count + 1 ) * 4 - 1 ] ]
set amber_prmtop($inst,RESIDUE_LAB,$i) $label
incr count
}
# RESIDUE_POINTER 12I6
set count 12
for { set i 0 } { $i < $NRES } { incr i } {
if { $count > 11 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 6] [ expr ( $count + 1 ) * 6 - 1 ] ]
set amber_prmtop($inst,RESIDUE_PTR,$i) [ string trim $label ]
incr count
}
# BOND_FORCE_CONSTANT 5E16.8
set count 5
for { set i 0 } { $i < $NUMBND } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,BOND_FC,$i) [ string trim $label ]
incr count
}
# BOND_EQUIL_VALUE 5E16.8
set count 5
for { set i 0 } { $i < $NUMBND } { incr i } {
if { $count > 4 } {
gets $fp line
set count 0
}
set label [ string range $line [ expr $count * 16] [ expr ( $count + 1 ) * 16 - 1 ] ]
set amber_prmtop($inst,BOND_R0,$i) [ string trim $label ]
incr count
}
# ANGLE_FORCE_CONSTANT 5E16.8
set count 5
for { set i 0 } { $i < $NUMANG } { incr i } {
if { $count > 4 } {
gets $fp line