58005809792a61f9db15225f2a5a7aeea43ab8b5
[unres.git] / source / wham / src-M / initialize_p.F
1       subroutine initialize
2
3 C Define constants and zero out tables.
4 C
5       implicit real*8 (a-h,o-z)
6       include 'DIMENSIONS'
7       include 'DIMENSIONS.ZSCOPT'
8 #ifdef MPI
9       include 'mpif.h'
10 #endif
11       include 'COMMON.IOUNITS'
12       include 'COMMON.CHAIN'
13       include 'COMMON.INTERACT'
14       include 'COMMON.GEO'
15       include 'COMMON.LOCAL'
16       include 'COMMON.TORSION'
17       include 'COMMON.FFIELD'
18       include 'COMMON.SBRIDGE'
19       include 'COMMON.MINIM' 
20       include 'COMMON.DERIV'
21       include "COMMON.WEIGHTS"
22       include "COMMON.NAMES"
23       include "COMMON.TIME1"
24 C
25 C The following is just to define auxiliary variables used in angle conversion
26 C
27       pi=4.0D0*datan(1.0D0)
28       dwapi=2.0D0*pi
29       dwapi3=dwapi/3.0D0
30       pipol=0.5D0*pi
31       deg2rad=pi/180.0D0
32       rad2deg=1.0D0/deg2rad
33       angmin=10.0D0*deg2rad
34 C
35 C Define I/O units.
36 C
37       inp=    1
38       iout=   2
39       ipdbin= 3
40       ipdb=   7
41       imol2=  4
42       igeom=  8
43       intin=  9
44       ithep= 11
45       irotam=12
46       itorp= 13
47       itordp= 23
48       ielep= 14
49       isidep=15 
50       isidep1=22
51       iscpp=25
52       icbase=16
53       ifourier=20
54       istat= 17
55       ientin=18
56       ientout=19
57       ibond=28
58       isccor=29
59 C
60 C WHAM files
61 C
62       ihist=30
63       iweight=31
64       izsc=32
65 C Lipidic input file for parameters range 60-79
66       iliptranpar=60
67 C
68 C Set default weights of the energy terms.
69 C
70       wlong=1.0D0
71       welec=1.0D0
72       wtor =1.0D0
73       wang =1.0D0
74       wscloc=1.0D0
75       wstrain=1.0D0
76 C
77 C Zero out tables.
78 C
79       ndih_constr=0
80       do i=1,maxres2
81         do j=1,3
82           c(j,i)=0.0D0
83           dc(j,i)=0.0D0
84         enddo
85       enddo
86       do i=1,maxres
87         do j=1,3
88           xloc(j,i)=0.0D0
89         enddo
90       enddo
91       do i=1,ntyp
92         do j=1,ntyp
93           aa_lip(i,j)=0.0D0
94           bb_lip(i,j)=0.0D0
95           aa_aq(i,j)=0.0D0
96           bb_aq(i,j)=0.0D0
97           augm(i,j)=0.0D0
98           sigma(i,j)=0.0D0
99           r0(i,j)=0.0D0
100           chi(i,j)=0.0D0
101         enddo
102         do j=1,2
103           bad(i,j)=0.0D0
104         enddo
105         chip(i)=0.0D0
106         alp(i)=0.0D0
107         sigma0(i)=0.0D0
108         sigii(i)=0.0D0
109         rr0(i)=0.0D0
110         a0thet(i)=0.0D0
111         do j=1,2
112          do ichir1=-1,1
113           do ichir2=-1,1
114           athet(j,i,ichir1,ichir2)=0.0D0
115           bthet(j,i,ichir1,ichir2)=0.0D0
116           enddo
117          enddo
118         enddo
119         do j=0,3
120           polthet(j,i)=0.0D0
121         enddo
122         do j=1,3
123           gthet(j,i)=0.0D0
124         enddo
125         theta0(i)=0.0D0
126         sig0(i)=0.0D0
127         sigc0(i)=0.0D0
128         do j=1,maxlob
129           bsc(j,i)=0.0D0
130           do k=1,3
131             censc(k,j,i)=0.0D0
132           enddo
133           do k=1,3
134             do l=1,3
135               gaussc(l,k,j,i)=0.0D0
136             enddo
137           enddo
138           nlob(i)=0
139         enddo
140       enddo
141       nlob(ntyp1)=0
142       dsc(ntyp1)=0.0D0
143       do i=-maxtor,maxtor
144         itortyp(i)=0
145        do iblock=1,2
146         do j=-maxtor,maxtor
147           do k=1,maxterm
148             v1(k,j,i,iblock)=0.0D0
149             v2(k,j,i,iblock)=0.0D0
150           enddo
151         enddo
152         enddo
153       enddo
154       do iblock=1,2
155        do i=-maxtor,maxtor
156         do j=-maxtor,maxtor
157          do k=-maxtor,maxtor
158           do l=1,maxtermd_1
159             v1c(1,l,i,j,k,iblock)=0.0D0
160             v1s(1,l,i,j,k,iblock)=0.0D0
161             v1c(2,l,i,j,k,iblock)=0.0D0
162             v1s(2,l,i,j,k,iblock)=0.0D0
163           enddo !l
164           do l=1,maxtermd_2
165            do m=1,maxtermd_2
166             v2c(m,l,i,j,k,iblock)=0.0D0
167             v2s(m,l,i,j,k,iblock)=0.0D0
168            enddo !m
169           enddo !l
170         enddo !k
171        enddo !j
172       enddo !i
173       enddo !iblock
174       do i=1,maxres
175         itype(i)=0
176         itel(i)=0
177       enddo
178 C Initialize the bridge arrays
179       ns=0
180       nss=0 
181       nhpb=0
182       do i=1,maxss
183         iss(i)=0
184       enddo
185       do i=1,maxdim
186         dhpb(i)=0.0D0
187       enddo
188       do i=1,maxres
189         ihpb(i)=0
190         jhpb(i)=0
191         dyn_ss_mask(i)=.false.
192       enddo
193 C
194 C Initialize timing.
195 C
196       call set_timers
197 C
198 C Initialize variables used in minimization.
199 C   
200 c     maxfun=5000
201 c     maxit=2000
202       maxfun=500
203       maxit=200
204       tolf=1.0D-2
205       rtolf=5.0D-4
206
207 C Initialize the variables responsible for the mode of gradient storage.
208 C
209       nfl=0
210       icg=1
211       do i=1,14
212         do j=1,14
213           if (print_order(i).eq.j) then
214             iw(print_order(i))=j
215             goto 1121
216           endif
217         enddo
218 1121    continue
219       enddo
220       calc_grad=.false.
221 C Set timers and counters for the respective routines
222       t_func = 0.0d0
223       t_grad = 0.0d0
224       t_fhel = 0.0d0
225       t_fbet = 0.0d0
226       t_ghel = 0.0d0
227       t_gbet = 0.0d0
228       t_viol = 0.0d0
229       t_gviol = 0.0d0
230       n_func = 0
231       n_grad = 0
232       n_fhel = 0
233       n_fbet = 0
234       n_ghel = 0
235       n_gbet = 0
236       n_viol = 0
237       n_gviol = 0
238       n_map = 0
239 #ifndef SPLITELE
240       nprint_ene=nprint_ene-1
241 #endif
242       return
243       end
244 c-------------------------------------------------------------------------
245       block data nazwy
246       implicit real*8 (a-h,o-z)
247       include 'DIMENSIONS'
248       include 'DIMENSIONS.ZSCOPT'
249       include 'COMMON.NAMES'
250       include 'COMMON.WEIGHTS'
251       include 'COMMON.FFIELD'
252       include 'COMMON.SHIELD'
253       data restyp /
254      &'DD','DAU','DAI','DDB','DSM','DPR','DLY','DAR','DHI','DAS','DGL',
255      & 'DSG','DGN','DSN','DTH',
256      &'DYY','DAL','DTY','DTR','DVA','DLE','DIL','DPN','MED','DCY','ZER',
257      &'CYS','MET','PHE','ILE','LEU','VAL','TRP','TYR','ALA','GLY','THR',
258      &'SER','GLN','ASN','GLU','ASP','HIS','ARG','LYS','PRO','SME','DBZ',
259      &'AIB','ABU','D'/
260       data onelet /
261      &'z','z','z','z','z','p','k','r','h','d','e','n','q','s','t','g',
262      &'a','y','w','v','l','i','f','m','c','x',
263      &'C','M','F','I','L','V','W','Y','A','G','T',
264      &'S','Q','N','E','D','H','R','K','P','z','z','z','z','X'/
265       data potname /'LJ','LJK','BP','GB','GBV'/
266       data ename / 
267      &   "EVDW SC-SC","EVDW2 SC-p","EES p-p","ECORR4 ","ECORR5 ",
268      &   "ECORR6 ","EELLO ","ETURN3 ","ETURN4 ","ETURN6 ",
269      &   "EBE bend","ESC SCloc","ETORS ","ETORSD ","EHPB","EVDWPP",
270      &   "EVDW2_14","ESTR","ESCCOR","EDIHC","EVDW_T","ELIPTRAN",
271      &   "EAFM","ETHETC","EMPTY"/
272       data wname /
273      &   "WSC","WSCP","WELEC","WCORR","WCORR5","WCORR6","WEL_LOC",
274      &   "WTURN3","WTURN4","WTURN6","WANG","WSCLOC","WTOR","WTORD",
275      &   "WHPB","WVDWPP","WSCP14","WBOND","WSCCOR","WDIHC","WSC",
276      &   "WLIPTRAN","WAFM","WTHETC","WSHIELD"/
277       data ww0 /1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,
278      &    1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,0.4d0,1.0d0,1.0d0,
279      &    0.0d0,0.0,0.0d0,0.0d0,0.0d0,0.0d0/
280       data nprint_ene /22/
281       data print_order /1,2,3,18,11,12,13,14,4,5,6,7,8,9,10,19,
282      &  16,15,17,20,21,24,22,23,1/
283       end 
284 c---------------------------------------------------------------------------
285       subroutine init_int_table
286       implicit real*8 (a-h,o-z)
287       include 'DIMENSIONS'
288       include 'DIMENSIONS.ZSCOPT'
289 #ifdef MPI
290       include 'mpif.h'
291 #endif
292 #ifdef MP
293       include 'COMMON.INFO'
294 #endif
295       include 'COMMON.CHAIN'
296       include 'COMMON.INTERACT'
297       include 'COMMON.LOCAL'
298       include 'COMMON.SBRIDGE'
299       include 'COMMON.IOUNITS'
300       logical scheck,lprint
301 #ifdef MPL
302       integer my_sc_int(0:max_fg_Procs-1),my_sc_intt(0:max_fg_Procs),
303      & my_ele_int(0:max_fg_Procs-1),my_ele_intt(0:max_fg_Procs)
304 C... Determine the numbers of start and end SC-SC interaction 
305 C... to deal with by current processor.
306       lprint=.false.
307       if (lprint)
308      &write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
309       n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
310       MyRank=MyID-(MyGroup-1)*fgProcs
311       call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
312       if (lprint)
313      &  write (iout,*) 'Processor',MyID,' MyRank',MyRank,
314      &  ' n_sc_int_tot',n_sc_int_tot,' my_sc_inds=',my_sc_inds,
315      &  ' my_sc_inde',my_sc_inde
316       ind_sctint=0
317       iatsc_s=0
318       iatsc_e=0
319 #endif
320       lprint=.false.
321       do i=1,maxres
322         nint_gr(i)=0
323         nscp_gr(i)=0
324         do j=1,maxint_gr
325           istart(i,1)=0
326           iend(i,1)=0
327           ielstart(i)=0
328           ielend(i)=0
329           iscpstart(i,1)=0
330           iscpend(i,1)=0    
331         enddo
332       enddo
333       ind_scint=0
334       ind_scint_old=0
335 cd    write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
336 cd   &   (ihpb(i),jhpb(i),i=1,nss)
337       do i=nnt,nct-1
338         scheck=.false.
339         if (dyn_ss) goto 10
340         do ii=1,nss
341           if (ihpb(ii).eq.i+nres) then
342             scheck=.true.
343             jj=jhpb(ii)-nres
344             goto 10
345           endif
346         enddo
347    10   continue
348 cd      write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
349         if (scheck) then
350           if (jj.eq.i+1) then
351 #ifdef MPL
352             write (iout,*) 'jj=i+1'
353             call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
354      & iatsc_s,iatsc_e,i+2,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
355 #else
356             nint_gr(i)=1
357             istart(i,1)=i+2
358             iend(i,1)=nct
359 #endif
360           else if (jj.eq.nct) then
361 #ifdef MPL
362             write (iout,*) 'jj=nct'
363             call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
364      &  iatsc_s,iatsc_e,i+1,nct-1,nint_gr(i),istart(i,1),iend(i,1),*12)
365 #else
366             nint_gr(i)=1
367             istart(i,1)=i+1
368             iend(i,1)=nct-1
369 #endif
370           else
371 #ifdef MPL
372             call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
373      & iatsc_s,iatsc_e,i+1,jj-1,nint_gr(i),istart(i,1),iend(i,1),*12)
374             ii=nint_gr(i)+1
375             call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
376      & iatsc_s,iatsc_e,jj+1,nct,nint_gr(i),istart(i,ii),iend(i,ii),*12)
377 #else
378             nint_gr(i)=2
379             istart(i,1)=i+1
380             iend(i,1)=jj-1
381             istart(i,2)=jj+1
382             iend(i,2)=nct
383 #endif
384           endif
385         else
386 #ifdef MPL
387           call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
388      &    iatsc_s,iatsc_e,i+1,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
389 #else
390           nint_gr(i)=1
391           istart(i,1)=i+1
392           iend(i,1)=nct
393           ind_scint=int_scint+nct-i
394 #endif
395         endif
396 #ifdef MPL
397         ind_scint_old=ind_scint
398 #endif
399       enddo
400    12 continue
401 #ifndef MPL
402       iatsc_s=nnt
403       iatsc_e=nct-1
404 #endif
405 #ifdef MPL
406       if (lprint) then
407         write (iout,*) 'Processor',MyID,' Group',MyGroup
408         write (iout,*) 'iatsc_s=',iatsc_s,' iatsc_e=',iatsc_e
409       endif
410 #endif
411       if (lprint) then
412       write (iout,'(a)') 'Interaction array:'
413       do i=iatsc_s,iatsc_e
414         write (iout,'(i3,2(2x,2i3))') 
415      & i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
416       enddo
417       endif
418       ispp=2
419 #ifdef MPL
420 C Now partition the electrostatic-interaction array
421       npept=nct-nnt
422       nele_int_tot=(npept-ispp)*(npept-ispp+1)/2
423       call int_bounds(nele_int_tot,my_ele_inds,my_ele_inde)
424       if (lprint)
425      & write (iout,*) 'Processor',MyID,' MyRank',MyRank,
426      &  ' nele_int_tot',nele_int_tot,' my_ele_inds=',my_ele_inds,
427      &               ' my_ele_inde',my_ele_inde
428       iatel_s=0
429       iatel_e=0
430       ind_eleint=0
431       ind_eleint_old=0
432       do i=nnt,nct-3
433         ijunk=0
434         call int_partition(ind_eleint,my_ele_inds,my_ele_inde,i,
435      &    iatel_s,iatel_e,i+ispp,nct-1,ijunk,ielstart(i),ielend(i),*13)
436       enddo ! i 
437    13 continue
438 #else
439       iatel_s=nnt
440       iatel_e=nct-3
441       do i=iatel_s,iatel_e
442         ielstart(i)=i+2
443         ielend(i)=nct-1
444       enddo
445 #endif
446       if (lprint) then
447         write (iout,'(a)') 'Electrostatic interaction array:'
448         do i=iatel_s,iatel_e
449           write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
450         enddo
451       endif ! lprint
452 c     iscp=3
453       iscp=2
454 C Partition the SC-p interaction array
455 #ifdef MPL
456       nscp_int_tot=(npept-iscp+1)*(npept-iscp+1)
457       call int_bounds(nscp_int_tot,my_scp_inds,my_scp_inde)
458       if (lprint)
459      & write (iout,*) 'Processor',MyID,' MyRank',MyRank,
460      &  ' nscp_int_tot',nscp_int_tot,' my_scp_inds=',my_scp_inds,
461      &               ' my_scp_inde',my_scp_inde
462       iatscp_s=0
463       iatscp_e=0
464       ind_scpint=0
465       ind_scpint_old=0
466       do i=nnt,nct-1
467         if (i.lt.nnt+iscp) then
468 cd        write (iout,*) 'i.le.nnt+iscp'
469           call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
470      &      iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,1),
471      &      iscpend(i,1),*14)
472         else if (i.gt.nct-iscp) then
473 cd        write (iout,*) 'i.gt.nct-iscp'
474           call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
475      &      iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),
476      &      iscpend(i,1),*14)
477         else
478           call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
479      &      iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),
480      &      iscpend(i,1),*14)
481           ii=nscp_gr(i)+1
482           call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
483      &      iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,ii),
484      &      iscpend(i,ii),*14)
485         endif
486       enddo ! i
487    14 continue
488 #else
489       iatscp_s=nnt
490       iatscp_e=nct-1
491       do i=nnt,nct-1
492         if (i.lt.nnt+iscp) then
493           nscp_gr(i)=1
494           iscpstart(i,1)=i+iscp
495           iscpend(i,1)=nct
496         elseif (i.gt.nct-iscp) then
497           nscp_gr(i)=1
498           iscpstart(i,1)=nnt
499           iscpend(i,1)=i-iscp
500         else
501           nscp_gr(i)=2
502           iscpstart(i,1)=nnt
503           iscpend(i,1)=i-iscp
504           iscpstart(i,2)=i+iscp
505           iscpend(i,2)=nct
506         endif 
507       enddo ! i
508 #endif
509       if (lprint) then
510         write (iout,'(a)') 'SC-p interaction array:'
511         do i=iatscp_s,iatscp_e
512           write (iout,'(i3,2(2x,2i3))') 
513      &         i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
514         enddo
515       endif ! lprint
516 C Partition local interactions
517 #ifdef MPL
518       call int_bounds(nres-2,loc_start,loc_end)
519       loc_start=loc_start+1
520       loc_end=loc_end+1
521       call int_bounds(nres-2,ithet_start,ithet_end)
522       ithet_start=ithet_start+2
523       ithet_end=ithet_end+2
524       call int_bounds(nct-nnt-2,iphi_start,iphi_end) 
525       iphi_start=iphi_start+nnt+2
526       iphi_end=iphi_end+nnt+2
527       call int_bounds(nres-3,itau_start,itau_end)
528       itau_start=itau_start+3
529       itau_end=itau_end+3
530       if (lprint) then 
531         write (iout,*) 'Processor:',MyID,
532      & ' loc_start',loc_start,' loc_end',loc_end,
533      & ' ithet_start',ithet_start,' ithet_end',ithet_end,
534      & ' iphi_start',iphi_start,' iphi_end',iphi_end
535         write (*,*) 'Processor:',MyID,
536      & ' loc_start',loc_start,' loc_end',loc_end,
537      & ' ithet_start',ithet_start,' ithet_end',ithet_end,
538      & ' iphi_start',iphi_start,' iphi_end',iphi_end
539       endif
540       if (fgprocs.gt.1 .and. MyID.eq.BossID) then
541         write(iout,'(i10,a,i10,a,i10,a/a,i3,a)') n_sc_int_tot,' SC-SC ',
542      & nele_int_tot,' electrostatic and ',nscp_int_tot,
543      & ' SC-p interactions','were distributed among',fgprocs,
544      & ' fine-grain processors.'
545       endif
546 #else
547       loc_start=2
548       loc_end=nres-1
549       ithet_start=3
550       ithet_end=nres
551       iphi_start=nnt+3
552       iphi_end=nct
553       itau_start=4
554       itau_end=nres
555 #endif
556       return
557       end 
558 c---------------------------------------------------------------------------
559       subroutine int_partition(int_index,lower_index,upper_index,atom,
560      & at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
561       implicit real*8 (a-h,o-z)
562       include 'DIMENSIONS'
563       include 'COMMON.IOUNITS'
564       integer int_index,lower_index,upper_index,atom,at_start,at_end,
565      & first_atom,last_atom,int_gr,jat_start,jat_end
566       logical lprn
567       lprn=.false.
568       if (lprn) write (iout,*) 'int_index=',int_index
569       int_index_old=int_index
570       int_index=int_index+last_atom-first_atom+1
571       if (lprn) 
572      &   write (iout,*) 'int_index=',int_index,
573      &               ' int_index_old',int_index_old,
574      &               ' lower_index=',lower_index,
575      &               ' upper_index=',upper_index,
576      &               ' atom=',atom,' first_atom=',first_atom,
577      &               ' last_atom=',last_atom
578       if (int_index.ge.lower_index) then
579         int_gr=int_gr+1
580         if (at_start.eq.0) then
581           at_start=atom
582           jat_start=first_atom-1+lower_index-int_index_old
583         else
584           jat_start=first_atom
585         endif
586         if (lprn) write (iout,*) 'jat_start',jat_start
587         if (int_index.ge.upper_index) then
588           at_end=atom
589           jat_end=first_atom-1+upper_index-int_index_old
590           return1
591         else
592           jat_end=last_atom
593         endif
594         if (lprn) write (iout,*) 'jat_end',jat_end
595       endif
596       return
597       end
598 c------------------------------------------------------------------------------
599       subroutine hpb_partition
600       implicit real*8 (a-h,o-z)
601       include 'DIMENSIONS'
602       include 'COMMON.SBRIDGE'
603       include 'COMMON.IOUNITS'
604 #ifdef MPL
605       include 'COMMON.INFO'
606       call int_bounds(nhpb,link_start,link_end)
607 #else
608       link_start=1
609       link_end=nhpb
610 #endif
611 cd    write (iout,*) 'Processor',MyID,' MyRank',MyRank,
612 cd   &  ' nhpb',nhpb,' link_start=',link_start,
613 cd   &  ' link_end',link_end
614       return
615       end