87e4ddeed470c7d02d94d7bcdf9a7fac82e58119
[unres.git] / source / cluster / wham / src-HCD-5D / 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 'sizesclu.dat'
8       include 'COMMON.IOUNITS'
9       include 'COMMON.CHAIN'
10       include 'COMMON.INTERACT'
11       include 'COMMON.GEO'
12       include 'COMMON.LOCAL'
13       include 'COMMON.TORSION'
14       include 'COMMON.FFIELD'
15       include 'COMMON.SBRIDGE'
16       include 'COMMON.MINIM' 
17       include 'COMMON.DERIV'
18       include "COMMON.NAMES"
19       include "COMMON.TIME1"
20 C
21 C The following is just to define auxiliary variables used in angle conversion
22 C
23       pi=4.0D0*datan(1.0D0)
24       dwapi=2.0D0*pi
25       dwapi3=dwapi/3.0D0
26       pipol=0.5D0*pi
27       deg2rad=pi/180.0D0
28       rad2deg=1.0D0/deg2rad
29       angmin=10.0D0*deg2rad
30       Rgas = 1.987D-3
31 C
32 C Define I/O units.
33 C
34       inp=    1
35       iout=   2
36       ipdbin= 3
37       ipdb=   7
38       imol2= 18
39       jplot= 19
40       jstatin=10
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       ibond=28
56       isccor=29
57       jrms=30
58       iliptran=60
59 C
60 C Set default weights of the energy terms.
61 C
62       wlong=1.0D0
63       welec=1.0D0
64       wtor =1.0D0
65       wang =1.0D0
66       wscloc=1.0D0
67       wstrain=1.0D0
68 C
69 C Zero out tables.
70 C
71       ndih_constr=0
72       do i=1,maxres2
73         do j=1,3
74           c(j,i)=0.0D0
75           dc(j,i)=0.0D0
76         enddo
77       enddo
78       do i=1,maxres
79         do j=1,3
80           xloc(j,i)=0.0D0
81         enddo
82       enddo
83       do i=1,ntyp
84         do j=1,ntyp
85           aa_aq(i,j)=0.0D0
86           bb_aq(i,j)=0.0D0
87           aa_lip(i,j)=0.0D0
88           bb_lip(i,j)=0.0D0
89           augm(i,j)=0.0D0
90           sigma(i,j)=0.0D0
91           r0(i,j)=0.0D0
92           chi(i,j)=0.0D0
93         enddo
94         do j=1,2
95           bad(i,j)=0.0D0
96         enddo
97         chip(i)=0.0D0
98         alp(i)=0.0D0
99         sigma0(i)=0.0D0
100         sigii(i)=0.0D0
101         rr0(i)=0.0D0
102         a0thet(i)=0.0D0
103         do j=1,2
104          do ichir1=-1,1
105           do ichir2=-1,1
106           athet(j,i,ichir1,ichir2)=0.0D0
107           bthet(j,i,ichir1,ichir2)=0.0D0
108           enddo
109          enddo
110         enddo
111         do j=0,3
112           polthet(j,i)=0.0D0
113         enddo
114         do j=1,3
115           gthet(j,i)=0.0D0
116         enddo
117         theta0(i)=0.0D0
118         sig0(i)=0.0D0
119         sigc0(i)=0.0D0
120         do j=1,maxlob
121           bsc(j,i)=0.0D0
122           do k=1,3
123             censc(k,j,i)=0.0D0
124           enddo
125           do k=1,3
126             do l=1,3
127               gaussc(l,k,j,i)=0.0D0
128             enddo
129           enddo
130           nlob(i)=0
131         enddo
132       enddo
133       nlob(ntyp1)=0
134       dsc(ntyp1)=0.0D0
135       do i=-maxtor,maxtor
136         itortyp(i)=0
137        do iblock=1,2
138         do j=-maxtor,maxtor
139           do k=1,maxterm
140             v1(k,j,i,iblock)=0.0D0
141             v2(k,j,i,iblock)=0.0D0
142            enddo
143          enddo      
144        enddo
145       enddo
146       do iblock=1,2
147        do i=-maxtor,maxtor
148         do j=-maxtor,maxtor
149          do k=-maxtor,maxtor
150           do l=1,maxtermd_1
151             v1c(1,l,i,j,k,iblock)=0.0D0
152             v1s(1,l,i,j,k,iblock)=0.0D0
153             v1c(2,l,i,j,k,iblock)=0.0D0
154             v1s(2,l,i,j,k,iblock)=0.0D0
155           enddo !l
156           do l=1,maxtermd_2
157            do m=1,maxtermd_2
158             v2c(m,l,i,j,k,iblock)=0.0D0
159             v2s(m,l,i,j,k,iblock)=0.0D0
160            enddo !m
161           enddo !l
162         enddo !k
163        enddo !j
164       enddo !i
165       enddo !iblock
166       do i=1,maxres
167         itype(i)=0
168         itel(i)=0
169       enddo
170 C Initialize the bridge arrays
171       ns=0
172       nss=0 
173       nhpb=0
174       do i=1,maxss
175         iss(i)=0
176       enddo
177       do i=1,maxss
178         dhpb(i)=0.0D0
179       enddo
180       do i=1,maxss
181         ihpb(i)=0
182         jhpb(i)=0
183       enddo
184 C
185 C Initialize timing.
186 C
187       call set_timers
188 C
189 C Initialize variables used in minimization.
190 C   
191 c     maxfun=5000
192 c     maxit=2000
193       maxfun=500
194       maxit=200
195       tolf=1.0D-2
196       rtolf=5.0D-4
197
198 C Initialize the variables responsible for the mode of gradient storage.
199 C
200       nfl=0
201       icg=1
202       do i=1,14
203         do j=1,14
204           if (print_order(i).eq.j) then
205             iw(print_order(i))=j
206             goto 1121
207           endif
208         enddo
209 1121    continue
210       enddo
211       calc_grad=.false.
212 C Set timers and counters for the respective routines
213       t_func = 0.0d0
214       t_grad = 0.0d0
215       t_fhel = 0.0d0
216       t_fbet = 0.0d0
217       t_ghel = 0.0d0
218       t_gbet = 0.0d0
219       t_viol = 0.0d0
220       t_gviol = 0.0d0
221       n_func = 0
222       n_grad = 0
223       n_fhel = 0
224       n_fbet = 0
225       n_ghel = 0
226       n_gbet = 0
227       n_viol = 0
228       n_gviol = 0
229       n_map = 0
230 #ifndef SPLITELE
231       nprint_ene=nprint_ene-1
232 #endif
233       return
234       end
235 c-------------------------------------------------------------------------
236       block data nazwy
237       implicit real*8 (a-h,o-z)
238       include 'DIMENSIONS'
239       include 'sizesclu.dat'
240       include 'COMMON.NAMES'
241       include 'COMMON.FFIELD'
242       data restyp /
243      &'DD','DAU','DAI','DDB','DSM','DPR','DLY','DAR','DHI','DAS','DGL',
244      & 'DSG','DGN','DSN','DTH',
245      &'DYY','DAL','DTY','DTR','DVA','DLE','DIL','DPN','MED','DCY','ZER',
246      &'CYS','MET','PHE','ILE','LEU','VAL','TRP','TYR','ALA','GLY','THR',
247      &'SER','GLN','ASN','GLU','ASP','HIS','ARG','LYS','PRO','SME','DBZ',
248      &'AIB','ABU','D'/
249       data onelet /
250      &'z','z','z','z','z','p','k','r','h','d','e','n','q','s','t','g',
251      &'a','y','w','v','l','i','f','m','c','x',
252      &'C','M','F','I','L','V','W','Y','A','G','T',
253      &'S','Q','N','E','D','H','R','K','P','z','z','z','z','X'/
254       data potname /'LJ','LJK','BP','GB','GBV'/
255       data ename / 
256      1   "ESC-SC",
257      2   "ESC-p",
258      3   "Ep-p(el)",
259      4   "ECORR4 ",
260      5   "ECORR5 ",
261      6   "ECORR6 ",
262      7   "ECORR3 ",
263      8   "ETURN3 ",
264      9   "ETURN4 ",
265      @   "ETURN6 ",
266      1   "Ebend",
267      2   "ESCloc",
268      3   "ETORS ",
269      4   "ETORSD ",
270      5   "Edist",
271      6   "Epp(VDW)",
272      7   "EVDW2_14",
273      8   "Ebond",
274      9   "ESCcor",
275      @   "EDIHC",
276      1   "EVDW_T",
277      2   "ELIPTRAN",
278      3   "EAFM",
279      4   "ETHETC",
280      5   "ESHIELD",
281      6   "ESAXS",
282      7   "EHOMO",
283      8   "EDFADIS",
284      9   "EDFATOR",
285      @   "EDFANEI",
286      1   "EDFABET"/
287       data wname /
288 !            1       2       3       4       5        6        7 
289      &   "WSC   ","WSCP  ","WELEC","WCORR","WCORR5","WCORR6","WEL_LOC",
290 !            8       9      10      11      12       13       14
291      &   "WTURN3","WTURN4","WTURN6","WANG","WSCLOC","WTOR  ","WTORD",
292 !           15      16      17      18      19       20       21
293      &   "WHPB  ","WVDWPP","WSCP14","WBOND","WSCCOR","WDIHC","WSC",
294 !           22      23      24      25      26       27       28
295      &   "WLIPTRAN","WAFM","WTHETC","WSHIELD","WSAXS","WHOMO","WDFAD",
296 !           29      30      31   
297      &   "WDFAT","WDFAN","WDFAB"/
298 #ifdef DFA
299 #if defined(SCP14) && defined(SPLITELE)
300       data nprint_ene /31/
301       data print_order/1,2,18,3,16,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
302      & 24,15,26,27,28,29,30,31,22,23,25,20/
303 #elif defined(SCP14)
304       data nprint_ene /30/
305       data print_order/1,2,18,3,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
306      & 24,15,26,27,28,29,30,31,22,23,25,20,0/
307 #elif defined(SPLITELE)
308       data nprint_ene /30/
309       data print_order/1,2,3,16,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
310      & 24,15,26,27,28,29,30,31,22,23,25,20,0/
311 #else
312       data nprint_ene /29/
313       data print_order/1,2,3,16,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
314      & 24,15,26,27,28,29,30,31,22,23,25,20,2*0/
315 #endif
316 #else
317 #if defined(SCP14) && defined(SPLITELE)
318       data nprint_ene /27/
319       data print_order/1,2,18,3,16,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
320      & 24,15,26,27,22,23,25,20,4*0/
321 #elif defined(SCP14)
322       data nprint_ene /26/
323       data print_order/1,2,18,3,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
324      & 24,15,26,27,22,23,25,20,5*0/
325 #elif defined(SPLITELE)
326       data nprint_ene /26/
327       data print_order/1,2,3,16,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
328      & 24,15,26,27,22,23,25,20,5*0/
329 #else
330       data nprint_ene /25/
331       data print_order/1,2,3,16,17,11,12,13,14,4,5,6,7,8,9,10,21,19,
332      & 24,15,26,27,22,23,25,20,6*0/
333 #endif
334 #endif
335       end 
336 c---------------------------------------------------------------------------
337       subroutine init_int_table
338       implicit real*8 (a-h,o-z)
339       include 'DIMENSIONS'
340       include 'COMMON.CHAIN'
341       include 'COMMON.INTERACT'
342       include 'COMMON.LOCAL'
343       include 'COMMON.SBRIDGE'
344       include 'COMMON.IOUNITS'
345       include "COMMON.TORCNSTR"
346       logical scheck,lprint
347       lprint=.false.
348       do i=1,maxres
349         nint_gr(i)=0
350         nscp_gr(i)=0
351         do j=1,maxint_gr
352           istart(i,1)=0
353           iend(i,1)=0
354           ielstart(i)=0
355           ielend(i)=0
356           iscpstart(i,1)=0
357           iscpend(i,1)=0    
358         enddo
359       enddo
360       ind_scint=0
361       ind_scint_old=0
362 cd    write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
363 cd   &   (ihpb(i),jhpb(i),i=1,nss)
364       do i=nnt,nct-1
365         scheck=.false.
366         if (dyn_ss) goto 10
367         do ii=1,nss
368           if (ihpb(ii).eq.i+nres) then
369             scheck=.true.
370             jj=jhpb(ii)-nres
371             goto 10
372           endif
373         enddo
374    10   continue
375 cd      write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
376         if (scheck) then
377           if (jj.eq.i+1) then
378             nint_gr(i)=1
379             istart(i,1)=i+2
380             iend(i,1)=nct
381           else if (jj.eq.nct) then
382             nint_gr(i)=1
383             istart(i,1)=i+1
384             iend(i,1)=nct-1
385           else
386             nint_gr(i)=2
387             istart(i,1)=i+1
388             iend(i,1)=jj-1
389             istart(i,2)=jj+1
390             iend(i,2)=nct
391           endif
392         else
393           nint_gr(i)=1
394           istart(i,1)=i+1
395           iend(i,1)=nct
396           ind_scint=int_scint+nct-i
397         endif
398       enddo
399    12 continue
400       iatsc_s=nnt
401       iatsc_e=nct-1
402       if (lprint) then
403       write (iout,'(a)') 'Interaction array:'
404       do i=iatsc_s,iatsc_e
405         write (iout,'(i3,2(2x,2i3))') 
406      & i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
407       enddo
408       endif
409       ispp=2
410       iatel_s=nnt
411       iatel_e=nct-3
412       do i=iatel_s,iatel_e
413         ielstart(i)=i+4
414         ielend(i)=nct-1
415       enddo
416       if (lprint) then
417         write (iout,'(a)') 'Electrostatic interaction array:'
418         do i=iatel_s,iatel_e
419           write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
420         enddo
421       endif ! lprint
422 c     iscp=3
423       iscp=2
424 C Partition the SC-p interaction array
425       iatscp_s=nnt
426       iatscp_e=nct-1
427       do i=nnt,nct-1
428         if (i.lt.nnt+iscp) then
429           nscp_gr(i)=1
430           iscpstart(i,1)=i+iscp
431           iscpend(i,1)=nct
432         elseif (i.gt.nct-iscp) then
433           nscp_gr(i)=1
434           iscpstart(i,1)=nnt
435           iscpend(i,1)=i-iscp
436         else
437           nscp_gr(i)=2
438           iscpstart(i,1)=nnt
439           iscpend(i,1)=i-iscp
440           iscpstart(i,2)=i+iscp
441           iscpend(i,2)=nct
442         endif 
443       enddo ! i
444       if (lprint) then
445         write (iout,'(a)') 'SC-p interaction array:'
446         do i=iatscp_s,iatscp_e
447           write (iout,'(i3,2(2x,2i3))') 
448      &         i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
449         enddo
450       endif ! lprint
451 C Partition local interactions
452       loc_start=2
453       loc_end=nres-1
454       ithet_start=3
455       ithet_end=nres
456       iturn3_start=nnt
457       iturn3_end=nct-3
458       iturn4_start=nnt
459       iturn4_end=nct-4
460       iphi_start=nnt+3
461       iphi_end=nct
462       idihconstr_start=1
463       idihconstr_end=ndih_constr
464       ithetaconstr_start=1
465       ithetaconstr_end=ntheta_constr
466       itau_start=4
467       itau_end=nres
468       isaxs_start=1
469       isaxs_end=nsaxs
470       write (iout,*) "OSAXS_START",isaxs_start," ISAXS_END",isaxs_end
471       return
472       end 
473 c---------------------------------------------------------------------------
474       subroutine int_partition(int_index,lower_index,upper_index,atom,
475      & at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
476       implicit real*8 (a-h,o-z)
477       include 'DIMENSIONS'
478       include 'COMMON.IOUNITS'
479       integer int_index,lower_index,upper_index,atom,at_start,at_end,
480      & first_atom,last_atom,int_gr,jat_start,jat_end
481       logical lprn
482       lprn=.false.
483       if (lprn) write (iout,*) 'int_index=',int_index
484       int_index_old=int_index
485       int_index=int_index+last_atom-first_atom+1
486       if (lprn) 
487      &   write (iout,*) 'int_index=',int_index,
488      &               ' int_index_old',int_index_old,
489      &               ' lower_index=',lower_index,
490      &               ' upper_index=',upper_index,
491      &               ' atom=',atom,' first_atom=',first_atom,
492      &               ' last_atom=',last_atom
493       if (int_index.ge.lower_index) then
494         int_gr=int_gr+1
495         if (at_start.eq.0) then
496           at_start=atom
497           jat_start=first_atom-1+lower_index-int_index_old
498         else
499           jat_start=first_atom
500         endif
501         if (lprn) write (iout,*) 'jat_start',jat_start
502         if (int_index.ge.upper_index) then
503           at_end=atom
504           jat_end=first_atom-1+upper_index-int_index_old
505           return1
506         else
507           jat_end=last_atom
508         endif
509         if (lprn) write (iout,*) 'jat_end',jat_end
510       endif
511       return
512       end
513 c------------------------------------------------------------------------------
514       subroutine hpb_partition
515       implicit real*8 (a-h,o-z)
516       include 'DIMENSIONS'
517       include 'COMMON.SBRIDGE'
518       include 'COMMON.IOUNITS'
519       link_start=1
520       link_end=nhpb
521       link_start_peak=1
522       link_end_peak=npeak
523       write (iout,*) 'HPB_PARTITION',
524      &  ' nhpb',nhpb,' link_start=',link_start,
525      &  ' link_end',link_end,' link_start_peak',link_start_peak,
526      &  ' link_end_peak',link_end_peak
527       return
528       end
529 c------------------------------------------------------------------------------
530       subroutine homology_partition
531       implicit real*8 (a-h,o-z)
532       include 'DIMENSIONS'
533       include 'COMMON.SBRIDGE'
534       include 'COMMON.IOUNITS'
535       include 'COMMON.CONTROL'
536       include 'COMMON.HOMOLOGY'
537       include 'COMMON.HOMRESTR'
538       include 'COMMON.INTERACT'
539 cd      write(iout,*)"homology_partition: lim_odl=",lim_odl,
540 cd     &   " lim_dih",lim_dih
541       link_start_homo=1
542       link_end_homo=lim_odl
543       idihconstr_start_homo=nnt+3
544       idihconstr_end_homo=lim_dih+nnt-1+3
545       write (iout,*)
546      &  ' lim_odl',lim_odl,' link_start=',link_start_homo,
547      &  ' link_end',link_end_homo,' lim_dih',lim_dih,
548      &  ' idihconstr_start_homo',idihconstr_start_homo,
549      &  ' idihconstr_end_homo',idihconstr_end_homo
550       return
551       end