-
Notifications
You must be signed in to change notification settings - Fork 5
/
gmx2mdflex.f
1377 lines (1079 loc) · 62.6 KB
/
gmx2mdflex.f
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
! Convert gmx data to mdflex program :: verify gmx format in IO FORMATS
module gmx2mdflex
use constants_m
use MPI_definitions_m , only : master
use for_force
use type_m , only : dynemolworkdir , warning
use MM_types , only : MM_atomic, MM_molecular, MM_system, DefineBonds, DefineAngles, DefinePairs, debug_MM
use MM_tuning_routines , only : SpecialBonds, SpecialAngs
use NonBondPairs , only : Identify_NonBondPairs
use Babel_routines_m , only : TO_UPPER_CASE
use setup_checklist , only : Checking_Topology
private
public :: top2mdflex, itp2mdflex, SpecialPairs, SpecialPairs14, MorsePairs
! module variables ...
character(3) , allocatable , save :: BondPairsSymbols(:,:), AngleSymbols(:,:), DihedSymbols(:,:)
real*8 , allocatable , save :: BondPairsParameters(:,:), AngleParameters(:,:), DihedParameters(:,:)
type(DefinePairs) , allocatable :: SpecialPairs(:), SpecialPairs14(:), MorsePairs(:)
contains
!
!
!
!================================================
subroutine itp2mdflex( MM , atom , species , FF)
!================================================
implicit none
type(MM_system) , intent(in) :: MM
type(MM_atomic) , intent(inout) :: atom(:)
type(MM_atomic) , intent(inout) :: FF(:)
type(MM_molecular) , intent(inout) :: species(:)
! local variables ...
character(15) , allocatable :: InputChars(:,:)
real*8 , allocatable :: InputReals(:,:)
integer , allocatable :: InputIntegers(:,:)
character(18) :: keyword
character(10) :: string , ForceFlag , word(3)
character(200) :: line
logical :: TorF
integer :: i, j, k, a, ioerr, dummy_int, counter, Nbonds, Nangs, Ndiheds, Ntorsion, N_of_atoms, enforce_execution
allocate( InputChars ( 20000 , 10 ) )
allocate( InputReals ( 20000 , 10 ) , source = D_zero )
allocate( InputIntegers ( 20000 , 10 ) , source = I_zero )
! Reading different '.itp' species files ...
counter = 0
do a = 1 , MM % N_of_species
string = species(a) % residue // '.itp'
If( master ) then
! cloning the itp files into log.trunk ...
call systemQQ("cp "//string//" log.trunk/.")
End If
open(33, file=dynemolworkdir//string, status='old',iostat=ioerr,err=101)
101 if( ioerr > 0 ) then
print*, string,' file not found; terminating execution' ; stop
end if
If( master ) write(*,'(/2a9)',advance='no') "Reading ", string
! start reading the molecular structure of species(a) ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ ATOMS ]" , line ) == 0 ) exit ! <== looking for [ atoms ] in *.itp
end do
allocate( species(a) % atom ( species(a) % N_of_atoms ) )
i = 1
read_loop1: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop1
read(line,*,iostat=ioerr) InputChars(i,1)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop1
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop1
read(line,*,iostat=ioerr) species(a) % atom(i) % my_id , &
species(a) % atom(i) % MMSymbol , &
dummy_int , &
species(a) % atom(i) % residue , &
species(a) % atom(i) % EHSymbol , &
dummy_int , &
species(a) % atom(i) % MM_charge , &
species(a) % atom(i) % mass
species(a) % atom(i) % nr = 1
species(a) % atom(i) % MMSymbol = TO_UPPER_CASE( adjustr(species(a) % atom(i) % MMSymbol) )
species(a) % atom(i) % my_species = a
species(a) % my_species = a
species(a) % atom(i) % flex = species(a) % flex
! this is the standard; atomic flexibity can also be defined @ ad_hoc_MM_tuning ...
where( atom % my_species == a ) atom % flex = species(a) % flex
counter = counter + 1
FF(counter) % my_species = a
FF(counter) % my_id = species(a) % atom(i) % my_id
FF(counter) % nr = species(a) % atom(i) % nr
FF(counter) % residue = species(a) % atom(i) % residue
FF(counter) % EHSymbol = species(a) % atom(i) % EHSymbol
FF(counter) % MMSymbol = species(a) % atom(i) % MMSymbol
FF(counter) % MM_charge = species(a) % atom(i) % MM_charge
i = i + 1
end do read_loop1
backspace(33)
N_of_atoms = species(a) % N_of_atoms
If( N_of_atoms*(n_of_atoms+1) /= 2*sum(species(a)%atom%my_id) ) then
CALL warning("halting: check index column of "//string//"file")
stop
end If
! convert MMSymbol to upper case ...
forall( i=1:N_of_atoms ) species(a)% atom(i)% MMSymbol = TO_UPPER_CASE( species(a)% atom(i)% MMSymbol )
! convert residues to upper case ...
forall( i=1:N_of_atoms ) species(a)% atom(i)% residue = TO_UPPER_CASE( species(a)% atom(i)% residue )
i = 1
do
if( i > size(atom) ) exit
if( trim(atom(i) % residue) == trim(species(a) % atom(1) % residue) ) then
atom(i:i+N_of_atoms-1) % MM_charge = species(a) % atom(:N_of_atoms) % MM_charge
i = i + N_of_atoms
else
i = i + 1
end if
end do
rewind 33
!==============================================================================================
! Bonding parameters :: reading ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ BONDS ]" , line ) == 0 ) exit ! <== looking for [ bonds ] in *.itp
end do
i = 1
read_loop2: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop2
read(line,*,iostat=ioerr) InputChars(i,1)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop2
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop2
read(line,*, iostat=ioerr) ( InputIntegers(i,j) , j=1,2 ) , InputChars(i,1)
i = i + 1
end do read_loop2
backspace(33)
Nbonds = i - 1
species(a) % Nbonds = Nbonds
allocate( species(a) % bonds ( Nbonds , 2 ) )
allocate( species(a) % funct_bond ( Nbonds ) )
allocate( species(a) % bond_type ( Nbonds ) )
forall(i=1:2) species(a) % bonds(:Nbonds,i) = InputIntegers(:Nbonds,i)
species(a) % funct_bond(:Nbonds) = adjustl( (InputChars(:Nbonds,1)) )
do i = 1 , Nbonds
select case ( species(a) % funct_bond(i) )
case( "1" )
species(a) % bond_type(i) = "harm"
case( "3" )
species(a) % bond_type(i) = "Mors"
end select
end do
rewind 33
!==============================================================================================
! Angle parameters :: reading ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ ANGLES ]" , line ) == 0 ) exit ! <== looking for [ angles ] in *.itp
end do
InputIntegers = I_zero
i = 1
read_loop3: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop3
read(line,*,iostat=ioerr) InputChars(i,1)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop3
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop3
read(line,*, iostat=ioerr) ( InputIntegers(i,j) , j=1,3 ) , InputChars(i,1)
i = i + 1
end do read_loop3
backspace(33)
Nangs = i - 1
species(a) % Nangs = Nangs
allocate( species(a) % angs ( Nangs , 3 ) )
allocate( species(a) % funct_angle ( Nangs ) )
allocate( species(a) % angle_type ( Nangs ) )
forall(i=1:3) species(a) % angs(:Nangs,i) = InputIntegers(:Nangs,i)
species(a) % funct_angle(:Nangs) = InputChars(:Nangs,1)
do i = 1 , Nangs
select case ( species(a) % funct_angle(i) )
case( "1" )
species(a) % angle_type(i) = "harm"
case( "5" )
species(a) % angle_type(i) = "urba"
end select
end do
rewind 33
!==============================================================================================
! Dihedral parameters :: reading ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ DIHEDRALS ]" , line ) == 0 .OR. ioerr /= 0 ) exit ! <== looking for [ dihedrals ] in *.itp
end do
if( verify( "[ DIHEDRALS ]" , line ) == 0 ) then
InputIntegers = I_zero
i = 1
read_loop4: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop4
read(line,*,iostat=ioerr) InputChars(i,1)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop4
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop4
read(line,*, iostat=ioerr) ( InputIntegers(i,j) , j=1,5 )
i = i + 1
end do read_loop4
backspace(33)
Ndiheds = i - 1
species(a) % Ndiheds = Ndiheds
allocate( species(a) % diheds ( Ndiheds , 4 ) )
allocate( species(a) % funct_dihed ( Ndiheds ) )
forall(i=1:4) species(a) % diheds(:Ndiheds,i) = InputIntegers(:Ndiheds,i)
species(a) % funct_dihed(:Ndiheds) = InputIntegers(:Ndiheds,5)
! define species(a) % dihedral_type ...
CALL define_DihedralType( species(a) , Ndiheds )
end if
rewind 33
!----------------------------------------------------------------------------------------------
! the IMPROPER dihedrals must be at the END OF THE LIST ...
Ntorsion = count( species(a)%dihedral_type /= "imp" )
species(a)% NTorsions = Ntorsion
species(a)% NImpropers = Ndiheds - Ntorsion
If( master ) then
TorF = Checking_Topology( species(a)%bonds , species(a)%angs , species(a)%diheds(:Ntorsion,:) )
call get_environment_variable("force_flag",ForceFlag)
enforce_execution = verify( "true" , ForceFlag )
If( TorF .AND. enforce_execution /= 0 ) then
CALL warning("error detected in Topology, 1) check log.trunk/Topology.test.log OR 2) use <dynemol -f> ")
stop
End If
End If
!==============================================================================================
! AD_HOC parameters :: reading ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ AD-HOC ]" , line ) == 0 .OR. ioerr /= 0 ) exit ! <== looking for [ ad-hoc ] in *.itp
end do
if( verify( "[ AD-HOC ]" , line ) == 0 ) then
read(33,'(A)',iostat=ioerr) line
read(line,*,iostat=ioerr) keyword
keyword = to_upper_case(keyword)
select case (keyword)
case( ";" )
! Go on now, go, walk out the door ...
case( "FLEX" , "FLEX:")
read_loop: do
read(33, '(A)', iostat=ioerr) line
if( ioerr /= 0 ) exit read_loop
if( len_trim(line) == 0 ) cycle read_loop ! <== empty line
read(line,*,iostat=ioerr) string
if( index(string,";") /= 0 ) cycle read_loop ! <== comment line
if( trim(string) == "[ " ) exit read_loop ! <== end of block
read(line,*, iostat=ioerr) ( word(j) , j=1,3 )
read(word(1),'(i)') k
keyword = to_upper_case(word(3))
TorF = merge( .true. , .false. , any( [".TRUE.","TRUE","T","T_"] == keyword ) )
atom(k) % flex = TorF
end do read_loop
case default
CALL warning("halting: check AD-HOC section of *.itp file")
stop
end select
end if
!==============================================================================================
close(33)
If( master ) write(*,'(a9)') " << done "
end do
FF % residue = adjustl(FF % residue)
FF % Symbol = adjustl(FF % Symbol)
FF % MMSymbol = adjustl(FF % MMSymbol)
! convert MMSymbol to upper case ...
forall( i=1:size(FF) ) FF(i)% MMSymbol = TO_UPPER_CASE( FF(i)% MMSymbol )
deallocate( InputChars , InputIntegers )
end subroutine itp2mdflex
!
!
!
!==========================================
subroutine top2mdflex( MM , species , FF )
!==========================================
implicit none
type(MM_molecular) , intent(inout) :: species(:)
type(MM_system) , intent(inout) :: MM
type(MM_atomic) , allocatable , intent(inout) :: FF(:)
! local variables ...
character(3) , allocatable :: InputChars(:,:) , Input_Chars(:,:)
character(4) , allocatable :: funct_bond(:) , funct_angle(:)
real*8 , allocatable :: InputReals(:,:) , Input_Reals(:,:)
integer , allocatable :: InputIntegers(:,:)
integer , allocatable :: Dihed_Type(:) , Bond_Type(:) , Angle_Type(:)
integer :: a , n , i , j , j1, k , ioerr , dummy_int , N_of_AtomTypes , n_pairs
integer :: NbondsTypes , NangsTypes , NdihedTypes , NBondParms, NPairsParms , NMorseParms
character(3) :: dummy_char
character(200) :: line
logical :: flag1, flag2, flag3, flag4, flag5, flag6, flag7, flag8
allocate( InputChars ( 10000 , 10 ) )
allocate( Input_Chars ( 10000 , 10 ) )
allocate( InputReals ( 10000 , 10 ) , source = D_zero )
allocate( Input_Reals ( 10000 , 10 ) , source = D_zero )
allocate( InputIntegers ( 10000 , 10 ) , source = I_zero )
! FF definitions ...
forcefield = 1 ! <== 1 = Lennard-Jones ; 2 = Buckingham
If( master ) then
! cloning the topol.top file into log.trunk ...
call systemQQ("cp topol.top log.trunk/.")
End If
open(33, file=dynemolworkdir//'topol.top', status='old', iostat=ioerr, err=10)
! file error msg ...
10 if( ioerr > 0 ) stop '"topol.top" file not found; terminating execution'
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ DEFAULTS ]" , line ) == 0 ) exit
end do
i=1
read_loop: do
read(33,*,iostat=ioerr) dummy_char, MM% CombinationRule, dummy_char, MM% fudgeLJ, MM% fudgeQQ
if ( index( dummy_char, ";") /= 0 ) cycle read_loop
if( ioerr /= 0 ) exit
i = i + 1
end do read_loop
rewind(33)
!=====================================================================================
! reading the number of [ atomtypes ] ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ ATOMTYPES ]" , line ) == 0 ) exit
end do
i=1
read_loop1: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop1
read(line,*,iostat=ioerr) InputChars(i,1)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop1
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop1
read(line,*,iostat=ioerr) InputChars(i,1) , (InputReals(i,j) , j=1,2) , InputChars(i,2) , (InputReals(i,j) , j=3,4)
! convert MMSymbol to upper case ...
InputChars(i,1) = TO_UPPER_CASE( InputChars(i,1) )
i = i + 1
end do read_loop1
InputChars = adjustl(InputChars)
backspace(33)
N_of_AtomTypes = i - 1
MM % N_of_AtomTypes = i - 1
do i = 1 , N_of_AtomTypes
where( FF % MMSymbol == InputChars(i,1) )
FF % LJ = .true.
FF % sig = InputReals(i,3)
FF % eps = InputReals(i,4)
end where
end do
! conversion
! factor1 = 1.0d26 <== Factor used to correct units read from Gromacs
! GAFF vs GMX LJ parameters:
! -> epsilon_GAFF = epsilon_GMX / cal_2_J
! -> sigma_GAFF = (sigma_GMX*10/2 ) * 2^(1/6)
FF % eps = sqrt( FF % eps * factor1 * imol )
FF % sig = FF % sig * nano_2_angs
select case( MM % CombinationRule )
case (2)
FF % sig = FF % sig / TWO
case (3)
FF % sig = sqrt( FF % sig )
end select
FF % sig14 = FF % sig
FF % eps14 = FF % eps
do k = 1 , size(FF)
i = FF(k)% my_id
j = FF(k)% my_species
species(j)%atom(i)%lj = FF(k)%lj
species(j)%atom(i)%buck = FF(k)%buck
end do
!=====================================================================================
! NonBonding parameters :: reading ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ NONBOND_PARAMS ]" , line ) == 0 ) exit
end do
i = 1
k = 1
read_loop5: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop5
read(line,*,iostat=ioerr) InputChars(i,1)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop5
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop5
read(line,*,iostat=ioerr) (InputChars(i,j) , j=1,2) , InputIntegers(i,1)
if( InputIntegers(i,1) == 1 ) then
! Lennard-Jones
read(line,*,iostat=ioerr) (InputChars(i,j) , j=1,2) , InputIntegers(i,1) , (InputReals(i,j) , j=1,2)
i = i + 1
elseif( InputIntegers(i,1) == 3 ) then
! Morse
read(line,*) (Input_Chars(k,j) , j=1,2) , dummy_int, (Input_Reals(k,j) , j=1,3)
k = k + 1
end if
end do read_loop5
backspace(33)
NBondParms = i - 1
NMorseParms = k - 1
If( NBondParms /= 0 ) &
Then
allocate( SpecialPairs(NbondParms) )
! Lennard-Jones
do j = 1 , NbondParms
forall(i=1:2) SpecialPairs(j) % MMSymbols(i) = InputChars(j,i)
SpecialPairs(j) % model = "LJ"
SpecialPairs(j) % Parms(1) = InputReals(j,1)
SpecialPairs(j) % Parms(2) = InputReals(j,2)
! conversion
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
SpecialPairs(j) % Parms(1) = SpecialPairs(j) % Parms(1) * nano_2_angs
SpecialPairs(j) % Parms(2) = SpecialPairs(j) % Parms(2) * factor1 * imol
end do
endif
If( NMorseParms /= 0 ) &
Then
allocate( MorsePairs(NMorseParms) )
! Morse Potential
do j = 1 , NMorseParms
forall(i=1:2) MorsePairs(j) % MMSymbols(i) = Input_Chars(j,i)
MorsePairs(j) % model = "Mors"
MorsePairs(j) % Parms(3) = Input_Reals(j,3)
MorsePairs(j) % Parms(2) = Input_Reals(j,1)
MorsePairs(j) % Parms(1) = Input_Reals(j,2)
! conversion
MorsePairs(j) % Parms(1) = MorsePairs(j) % Parms(1) * factor1 * imol
MorsePairs(j) % Parms(2) = MorsePairs(j) % Parms(2) * nano_2_angs
MorsePairs(j) % Parms(3) = MorsePairs(j) % Parms(3) / nano_2_angs
end do
endIf
!=====================================================================================
! reads [ bondtypes ] ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ BONDTYPES ]" , line ) == 0 ) exit
end do
i = 1
read_loop2: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop2
read(line,*,iostat=ioerr) InputChars(i,1), InputChars(i,2)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop2
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop2
read(line,*,iostat=ioerr) (InputChars(i,j) , j=1,2) , InputIntegers(i,1), (InputReals(i,j) , j=1,2)
! convert MMSymbol to upper case ...
forall( k=1:2 ) InputChars(i,k) = TO_UPPER_CASE( InputChars(i,k) )
backspace(33)
select case ( InputIntegers(i,1) )
case( 1 )
read(33,*) (dummy_char, k=1,2) , dummy_int , (InputReals(i,j) , j=1,2)
case( 3 )
read(33,*) (dummy_char, k=1,2) , dummy_int , (InputReals(i,j) , j=1,3)
end select
i = i + 1
end do read_loop2
backspace(33)
NbondsTypes = i - 1
allocate( BondPairsSymbols ( NbondsTypes , 2 ) )
allocate( BondPairsParameters ( NbondsTypes , 3 ) , source = D_zero )
allocate( Bond_Type ( NbondsTypes ) )
allocate( funct_bond ( NbondsTypes ) )
forall(i=1:2) BondPairsSymbols(:NbondsTypes,i) = InputChars(:NbondsTypes,i)
Bond_Type( :NbondsTypes ) = InputIntegers(:NbondsTypes,1)
do i = 1 , NbondsTypes
select case( Bond_Type(i) )
case( 1 ) ! Harmonic potential ...
BondPairsParameters(i,1) = InputReals(i,2) * factor2 * imol
BondPairsParameters(i,2) = InputReals(i,1) * nano_2_angs
funct_bond(i) = "harm"
case( 3 ) ! Morse potential ...
BondPairsParameters(i,1) = InputReals(i,2) * factor1 * imol
BondPairsParameters(i,2) = InputReals(i,1) * nano_2_angs
BondPairsParameters(i,3) = InputReals(i,3) / nano_2_angs
funct_bond(i) = "Mors"
end select
end do
!=====================================================================================
! reads [ angletypes ] ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ ANGLETYPES ]" , line ) == 0 ) exit
end do
i = 1
read_loop3: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop3
read(line,*,iostat=ioerr) InputChars(i,1), InputChars(i,2)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop3
if( trim(InputChars(i,1)) == "[ " ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop3
read(line,*,iostat=ioerr) (InputChars(i,j) , j=1,3) , InputIntegers(i,1), (InputReals(i,j) , j=1,2 )
! convert MMSymbol to upper case ...
forall( k=1:3 ) InputChars(i,k) = TO_UPPER_CASE( InputChars(i,k) )
backspace(33)
select case( InputIntegers(i,1) )
case( 1 ) ! Harmonic potential ...
read(33,*) (dummy_char,k=1,3), dummy_int, (InputReals(i,j), j=1,2)
case( 5 ) ! Urey-Bradley potential ...
read(33,*) (dummy_char,k=1,3), dummy_int, (InputReals(i,j), j=1,4)
end select
i = i + 1
end do read_loop3
backspace(33)
backspace(33)
NangsTypes = i - 1
allocate( AngleSymbols ( NangsTypes , 3 ) )
allocate( AngleParameters ( NangsTypes , 4 ) , source = D_zero )
allocate( Angle_Type ( NangsTypes ) )
allocate( funct_angle ( NangsTypes ) )
forall(i=1:3) AngleSymbols(:NangsTypes,i) = InputChars(:NangsTypes,i)
Angle_Type( :NangsTypes ) = InputIntegers(:NangsTypes,1)
do i = 1 , NangsTypes
select case( Angle_Type(i) )
! conversion
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
case( 1 ) ! Harmonic potential ...
AngleParameters(:NangsTypes,1) = InputReals(:NangsTypes,2) * factor1 * imol
AngleParameters(:NangsTypes,2) = InputReals(:NangsTypes,1) * deg_2_rad
funct_angle(i) = "harm"
case( 5 ) ! Urey-Bradley potential ...
AngleParameters(:NangsTypes,1) = InputReals(:NangsTypes,2) * factor1 * imol
AngleParameters(:NangsTypes,2) = InputReals(:NangsTypes,1) * deg_2_rad
AngleParameters(:NangsTypes,3) = InputReals(:NangsTypes,4) * factor2 * imol
AngleParameters(:NangsTypes,4) = InputReals(:NangsTypes,3) * nano_2_angs
funct_angle(i) = "urba"
end select
end do
!=====================================================================================
! reads [ dihedraltypes ] ...
InputReals = D_zero
InputIntegers = I_zero
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ DIHEDRALTYPES ]" , line ) == 0 ) exit
end do
i = 1
read_loop4: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop4
read(line,*,iostat=ioerr) InputChars(i,1), InputChars(i,2)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop4
if( trim(InputChars(i,1)) == "[ " ) exit
if( trim(InputChars(i,1)) == "#in" ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop4
read(line,*,iostat=ioerr) (InputChars(i,k) , k=1,4) , InputIntegers(i,1)
! convert MMSymbol to upper case ...
forall( k=1:4 ) InputChars(i,k) = TO_UPPER_CASE( InputChars(i,k) )
backspace(33)
select case ( InputIntegers(i,1) )
case( 1 )
read( 33 , * ) (dummy_char, k=1,4) , dummy_int , (InputReals(i,k) , k=1,3)
!============================================================================
! V = k[1 + cos(n.phi - theta)]
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
! kdihed0(:,1) = phi_s ==> angle (deg) * deg_2_rad
! kdihed0(:,2) = K_(phi) ==> force constant (kJ/mol) * factor1 * imol
! kdihed0(:,3) = n ==> multiplicity (it will be)
!============================================================================
InputReals(i,1) = InputReals(i,1) * deg_2_rad
InputReals(i,2) = InputReals(i,2) * factor1 * imol
case( 2 )
read( 33 , * ) (dummy_char, k=1,4) , dummy_int , (InputReals(i,k) , k=1,2)
!============================================================================
! V = 1/2.k[cos(phi) - cos(phi0)]²
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
! kdihed0(:,1) = xi_0 ==> angle (deg) * deg_2_rad
! kdihed0(:,2) = K_(xi) ==> force constant (kJ/(mol.rad^2)) * factor1 * imol
!============================================================================
InputReals(i,1) = InputReals(i,1) * deg_2_rad
InputReals(i,2) = InputReals(i,2) * factor1 * imol
case( 3 )
read( 33 , * ) (dummy_char, k=1,4) , dummy_int , (InputReals(i,k) , k=1,6)
!============================================================================
! V = 1/2.A1[1 + cos(phi)] + 1/2.A2[1 - cos(2.phi)] + 1/2.A3[1 + cos(3.phi)]
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
! kdihed0(:,1) = C0 (kJ/mol) * factor1 * imol
! kdihed0(:,2) = C1 (kJ/mol) * factor1 * imol
! kdihed0(:,3) = C2 (kJ/mol) * factor1 * imol
! kdihed0(:,4) = C3 (kJ/mol) * factor1 * imol
! kdihed0(:,5) = C4 (kJ/mol) * factor1 * imol
! kdihed0(:,6) = C5 (kJ/mol) * factor1 * imol
!============================================================================
InputReals(i,1:6) = InputReals(i,1:6) * factor1 * imol
case( 4 )
read( 33 , * ) (dummy_char, k=1,4) , dummy_int , (InputReals(i,k) , k=1,3)
!============================================================================
! V = k[1 + cos(n.phi - theta)] (improper; same as 1)
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
! kdihed0(:,1) = phi_s ==> angle (deg) * deg_2_rad
! kdihed0(:,2) = K_(phi) ==> force constant (kJ.mol⁻¹) * factor1 * imol
! kdihed0(:,3) = n ==> multiplicity (it will be)
!============================================================================
InputReals(i,1) = InputReals(i,1) * deg_2_rad
InputReals(i,2) = InputReals(i,2) * factor1 * imol
case( 9 )
read( 33 , * ) (dummy_char, k=1,4) , dummy_int , (InputReals(i,k) , k=1,3)
!============================================================================
! V = k[1 + cos(n.phi - theta)] (multiple; same as 1)
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
! kdihed0(:,1) = phi_s ==> angle (deg) * deg_2_rad
! kdihed0(:,2) = K_(phi) ==> force constant (kJ.mol⁻¹) * factor1 * imol
! kdihed0(:,3) = n ==> multiplicity (it will be)
!============================================================================
InputReals(i,1) = InputReals(i,1) * deg_2_rad
InputReals(i,2) = InputReals(i,2) * factor1 * imol
end select
i = i + 1
end do read_loop4
NdihedTypes = i - 1
allocate( Dihed_Type ( NdihedTypes ) )
allocate( DihedSymbols ( NdihedTypes , 4 ) )
allocate( DihedParameters ( NdihedTypes , 6 ) , source = D_zero )
forall(k=1:4) DihedSymbols(:NdihedTypes,k) = InputChars(:NdihedTypes,k)
forall(k=1:6) DihedParameters(:NdihedTypes,k) = InputReals(:NdihedTypes,k)
Dihed_Type(:NdihedTypes) = InputIntegers(:NdihedTypes,1)
!=====================================================================================
! [ pairtypes ] parameters :: reading ...
do
read(33,'(A)',iostat=ioerr) line
line = to_upper_case(line)
if( verify( "[ PAIRTYPES ]" , line ) == 0 .OR. ioerr /= 0 ) exit
end do
if( verify( "[ PAIRTYPES ]" , line ) == 0 ) then
i = 1
k = 1
read_loop6: do
read(33, '(A)', iostat=ioerr) line
if ( ioerr /= 0 ) exit read_loop6
read(line,*,iostat=ioerr) InputChars(i,1), InputChars(i,2)
if( index(InputChars(i,1),";") /= 0 ) cycle read_loop6
if( trim(InputChars(i,1)) == "#in" ) exit
if( ioerr > 0 ) exit
if( ioerr /= 0 ) cycle read_loop6
read(line,*,iostat=ioerr) (InputChars(i,j) , j=1,2) , dummy_int, (InputReals(i,j), j=1,2)
i = i + 1
end do read_loop6
backspace(33)
NPairsParms = i - 1
If( NPairsParms /= 0 ) then
allocate( SpecialPairs14 ( NPairsParms ) )
forall(i=1:2) SpecialPairs14(:NPairsParms) % MMSymbols(i) = InputChars(:NPairsParms,i)
SpecialPairs14(:NPairsParms) % Parms(1) = InputReals(:NPairsParms,1)
SpecialPairs14(:NPairsParms) % Parms(2) = InputReals(:NPairsParms,2)
! conversion
! factor1 = 1.0d26 <== Factor used to correct the units read from Gromacs
SpecialPairs14(:NPairsParms) % Parms(1) = sqrt( SpecialPairs14(:NPairsParms)%Parms(1) * nano_2_angs )
SpecialPairs14(:NPairsParms) % Parms(2) = sqrt( SpecialPairs14(:NPairsParms)%Parms(2) * factor1 * imol )
EndIf
end if
!
close(33)
deallocate( InputChars , InputReals , InputIntegers )
deallocate( Input_Chars , Input_Reals )
!=====================================================================================
do a = 1 , MM % N_of_species
! Assigning to each specie the corresponding parameter ...
! Bond parameters ...
allocate( species(a) % kbond0( species(a) % Nbonds , 3 ) , source = D_zero )
do k = 1 , NbondsTypes
do n = 1 , species(a) % Nbonds
flag1 = ( adjustl(species(a) % atom(species(a) % bonds(n,1)) % MMSymbol) == adjustl(BondPairsSymbols(k,1)) ) .AND. &
( adjustl(species(a) % atom(species(a) % bonds(n,2)) % MMSymbol) == adjustl(BondPairsSymbols(k,2)) )
flag2 = ( adjustl(species(a) % atom(species(a) % bonds(n,1)) % MMSymbol) == adjustl(BondPairsSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % bonds(n,2)) % MMSymbol) == adjustl(BondPairsSymbols(k,1)) )
flag3 = ( adjustl(species(a) % bond_type(n)) == adjustl(funct_bond(k)) )
if ( ( flag1 .OR. flag2 ) .AND. flag3 ) then
species(a) % kbond0(n,1) = BondPairsParameters(k,1)
species(a) % kbond0(n,2) = BondPairsParameters(k,2)
species(a) % kbond0(n,3) = BondPairsParameters(k,3)
end if
end do
end do
if( allocated(SpecialBonds) ) then
do k = 1, size(SpecialBonds)
where( species(a) % funct_bond == SpecialBonds(k) % label ) species(a) % kbond0(:,1) = SpecialBonds(k) % kbond0(1) * factor2 * imol
where( species(a) % funct_bond == SpecialBonds(k) % label ) species(a) % kbond0(:,2) = SpecialBonds(k) % kbond0(2) * nano_2_angs
end do
end if
!=============================================================================
! Angle parameters ...
allocate( species(a) % kang0(species(a) % Nangs , 4 ) , source = D_zero )
do k = 1 , NangsTypes
do n = 1 , species(a) % Nangs
flag1 = ( adjustl(species(a) % atom(species(a) % angs(n,1)) % MMSymbol) == adjustl(AngleSymbols(k,1)) ) .AND. &
( adjustl(species(a) % atom(species(a) % angs(n,2)) % MMSymbol) == adjustl(AngleSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % angs(n,3)) % MMSymbol) == adjustl(AngleSymbols(k,3)) )
flag2 = ( adjustl(species(a) % atom(species(a) % angs(n,1)) % MMSymbol) == adjustl(AngleSymbols(k,3)) ) .AND. &
( adjustl(species(a) % atom(species(a) % angs(n,2)) % MMSymbol) == adjustl(AngleSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % angs(n,3)) % MMSymbol) == adjustl(AngleSymbols(k,1)) )
flag3 = ( adjustl(species(a) % angle_type(n)) == adjustl(funct_angle(k)) )
if ( ( flag1 .OR. flag2 ) .AND. flag3 ) then
species(a) % kang0(n,1) = AngleParameters(k,1)
species(a) % kang0(n,2) = AngleParameters(k,2)
species(a) % kang0(n,3) = AngleParameters(k,3)
species(a) % kang0(n,4) = AngleParameters(k,4)
end if
end do
end do
if( allocated(SpecialAngs) ) then
do k = 1 , size(SpecialAngs)
! conversion
! factor1 = 1.0d26 <== Factor used to correct the units read fom Gromacs
where( species(a) % funct_angle == SpecialAngs(k) % label ) species(a) % kang0(:,1) = SpecialAngs(k) % kang0(1) * factor1 * imol
where( species(a) % funct_angle == SpecialAngs(k) % label ) species(a) % kang0(:,2) = SpecialAngs(k) % kang0(2) * deg_2_rad
end do
end if
!=============================================================================
! Dihedral parameters ...
allocate( species(a) % kdihed0 ( species(a) % Ndiheds , 15 ) , source = D_zero )
read_loop0: do n = 1 , species(a) % Ndiheds
! control variables to multiple dihs ...
j = 0 ; j1 = 0
read_loop7: do k = 1 , NdihedTypes
!============================================
! if funct = 1 (cos)
! V = k_phi * [ 1 + cos( n * phi - phi_s ) ]
! Eq. 4.60 (GMX manual 5.0.5)
!============================================
if( species(a) % funct_dihed(n) == 1 ) then
flag1 = ( adjustl(species(a) % atom(species(a) % diheds(n,1)) % MMSymbol) == adjustl(DihedSymbols(k,1)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,2)) % MMSymbol) == adjustl(DihedSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,3)) % MMSymbol) == adjustl(DihedSymbols(k,3)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,4)) % MMSymbol) == adjustl(DihedSymbols(k,4)) ) .AND. &
( Dihed_Type(k) == 1 )
flag2 = ( adjustl(species(a) % atom(species(a) % diheds(n,4)) % MMSymbol) == adjustl(DihedSymbols(k,1)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,3)) % MMSymbol) == adjustl(DihedSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,2)) % MMSymbol) == adjustl(DihedSymbols(k,3)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,1)) % MMSymbol) == adjustl(DihedSymbols(k,4)) ) .AND. &
( Dihed_Type(k) == 1 )
flag3 = ( adjustl(species(a) % atom(species(a) % diheds(n,2)) % MMSymbol) == adjustl(DihedSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,3)) % MMSymbol) == adjustl(DihedSymbols(k,3)) ) .AND. &
( adjustl(DihedSymbols(k,1)) == 'X' ) .AND. &
( adjustl(DihedSymbols(k,4)) == 'X' ) .AND. &
( Dihed_Type(k) == 1 )
flag4 = ( adjustl(species(a) % atom(species(a) % diheds(n,3)) % MMSymbol) == adjustl(DihedSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,2)) % MMSymbol) == adjustl(DihedSymbols(k,3)) ) .AND. &
( adjustl(DihedSymbols(k,1)) == 'X' ) .AND. &
( adjustl(DihedSymbols(k,4)) == 'X' ) .AND. &
( Dihed_Type(k) == 1 )
flag5 = ( adjustl(DihedSymbols(k,1)) == 'X' ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,2)) % MMSymbol) == adjustl(DihedSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,3)) % MMSymbol) == adjustl(DihedSymbols(k,3)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,4)) % MMSymbol) == adjustl(DihedSymbols(k,4)) ) .AND. &
( Dihed_Type(k) == 1 )
flag6 = ( adjustl(DihedSymbols(k,4)) == 'X' ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,3)) % MMSymbol) == adjustl(DihedSymbols(k,2)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,2)) % MMSymbol) == adjustl(DihedSymbols(k,3)) ) .AND. &
( adjustl(species(a) % atom(species(a) % diheds(n,1)) % MMSymbol) == adjustl(DihedSymbols(k,4)) ) .AND. &
( Dihed_Type(k) == 1 )
if( flag1 .OR. flag2 .OR. flag3 .OR. flag4 .OR. flag5 .OR. flag6 ) then
! kdihed0(:,1) = phi_s (deg)
! kdihed0(:,2) = k_phi (kJ/mol)
! kdihed0(:,3) = n
!===============================
species(a) % kdihed0(n,1:3) = DihedParameters(k,1:3)
cycle read_loop0
end if
end if
!===============================
! if funct = 2 (harm)
! V = 1/2.k ( xi - xi_0 )^2