make cp src-HCD-5D
[unres.git] / source / unres / src-HCD-5D / energy_split-sep.F
1       subroutine etotal_long(energia)
2       implicit none
3       include 'DIMENSIONS'
4 c
5 c Compute the long-range slow-varying contributions to the energy
6 c
7 #ifndef ISNAN
8       external proc_proc
9 #ifdef WINPGI
10 cMS$ATTRIBUTES C ::  proc_proc
11 #endif
12 #endif
13 #ifdef MPI
14       include "mpif.h"
15       double precision weights_(n_ene)
16       double precision time00,time_Bcast,time_BcastW
17       integer ierror,ierr
18 #endif
19       include 'COMMON.SETUP'
20       include 'COMMON.IOUNITS'
21       double precision energia(0:n_ene)
22       include 'COMMON.FFIELD'
23       include 'COMMON.DERIV'
24       include 'COMMON.INTERACT'
25       include 'COMMON.SBRIDGE'
26       include 'COMMON.CHAIN'
27       include 'COMMON.VAR'
28       include 'COMMON.LOCAL'
29       include 'COMMON.QRESTR'
30       include 'COMMON.MD'
31       include 'COMMON.CONTROL'
32       double precision evdw,evdw1,evdw2,evdw2_14,ees,eel_loc,
33      & eello_turn3,eello_turn4,edfadis,estr,ehpb,ebe,ethetacnstr,
34      & escloc,etors,edihcnstr,etors_d,esccor,ecorr,ecorr5,ecorr6,eturn6,
35      & eliptran,Eafmforce,Etube,
36      & esaxs_constr,ehomology_constr,edfator,edfanei,edfabet
37       integer i,n_corr,n_corr1
38 c      write(iout,'(a,i2)')'Calling etotal_long ipot=',ipot
39       if (modecalc.eq.12.or.modecalc.eq.14) then
40 #ifdef MPI
41 c        if (fg_rank.eq.0) call int_from_cart1(.false.)
42 #else
43         call int_from_cart1(.false.)
44 #endif
45       endif
46 #ifdef MPI      
47 c      write(iout,*) "ETOTAL_LONG Processor",fg_rank,
48 c     & " absolute rank",myrank," nfgtasks",nfgtasks
49 c      call flush(iout)
50       if (nfgtasks.gt.1) then
51         time00=MPI_Wtime()
52 C FG slaves call the following matching MPI_Bcast in ERGASTULUM
53         if (fg_rank.eq.0) then
54           call MPI_Bcast(3,1,MPI_INTEGER,king,FG_COMM,IERROR)
55 c          write (iout,*) "Processor",myrank," BROADCAST iorder"
56 c          call flush(iout)
57 C FG master sets up the WEIGHTS_ array which will be broadcast to the 
58 C FG slaves as WEIGHTS array.
59           weights_(1)=wsc
60           weights_(2)=wscp
61           weights_(3)=welec
62           weights_(4)=wcorr
63           weights_(5)=wcorr5
64           weights_(6)=wcorr6
65           weights_(7)=wel_loc
66           weights_(8)=wturn3
67           weights_(9)=wturn4
68           weights_(10)=wturn6
69           weights_(11)=wang
70           weights_(12)=wscloc
71           weights_(13)=wtor
72           weights_(14)=wtor_d
73           weights_(15)=wstrain
74           weights_(16)=wvdwpp
75           weights_(17)=wbond
76           weights_(18)=scal14
77           weights_(21)=wsccor
78           weights_(22)=wliptran
79           weights_(25)=wtube
80           weights_(26)=wsaxs
81           weights_(28)=wdfa_dist
82           weights_(29)=wdfa_tor
83           weights_(30)=wdfa_nei
84           weights_(31)=wdfa_beta
85 C FG Master broadcasts the WEIGHTS_ array
86           call MPI_Bcast(weights_(1),n_ene,
87      &        MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
88         else
89 C FG slaves receive the WEIGHTS array
90           call MPI_Bcast(weights(1),n_ene,
91      &        MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
92           wsc=weights(1)
93           wscp=weights(2)
94           welec=weights(3)
95           wcorr=weights(4)
96           wcorr5=weights(5)
97           wcorr6=weights(6)
98           wel_loc=weights(7)
99           wturn3=weights(8)
100           wturn4=weights(9)
101           wturn6=weights(10)
102           wang=weights(11)
103           wscloc=weights(12)
104           wtor=weights(13)
105           wtor_d=weights(14)
106           wstrain=weights(15)
107           wvdwpp=weights(16)
108           wbond=weights(17)
109           scal14=weights(18)
110           wsccor=weights(21)
111           wliptran=weights(22)
112           wtube=weights(25)
113           wsaxs=weights(26)
114           wdfa_dist=weights_(28)
115           wdfa_tor=weights_(29)
116           wdfa_nei=weights_(30)
117           wdfa_beta=weights_(31)
118         endif
119         call MPI_Bcast(dc(1,1),6*nres,MPI_DOUBLE_PRECISION,
120      &    king,FG_COMM,IERR)
121          time_Bcast=time_Bcast+MPI_Wtime()-time00
122          time_Bcastw=time_Bcastw+MPI_Wtime()-time00
123 c        call chainbuild_cart
124 c        call int_from_cart1(.false.)
125       endif
126 c      write (iout,*) 'Processor',myrank,
127 c     &  ' calling etotal_short ipot=',ipot
128 c      call flush(iout)
129 c      print *,'Processor',myrank,' nnt=',nnt,' nct=',nct
130 #endif     
131 cd    print *,'nnt=',nnt,' nct=',nct
132 C
133 C Compute the side-chain and electrostatic interaction energy
134 C
135       goto (101,102,103,104,105,106) ipot
136 C Lennard-Jones potential.
137   101 call elj_long(evdw)
138 cd    print '(a)','Exit ELJ'
139       goto 107
140 C Lennard-Jones-Kihara potential (shifted).
141   102 call eljk_long(evdw)
142       goto 107
143 C Berne-Pechukas potential (dilated LJ, angular dependence).
144   103 call ebp_long(evdw)
145       goto 107
146 C Gay-Berne potential (shifted LJ, angular dependence).
147   104 call egb_long(evdw)
148       goto 107
149 C Gay-Berne-Vorobjev potential (shifted LJ, angular dependence).
150   105 call egbv_long(evdw)
151       goto 107
152 C Soft-sphere potential
153   106 call e_softsphere(evdw)
154 C
155 C Calculate electrostatic (H-bonding) energy of the main chain.
156 C
157   107 continue
158       call vec_and_deriv
159 c      write (iout,*) "etotal_long: shield_mode",shield_mode
160       if (shield_mode.eq.1) then
161        call set_shield_fac
162       else if  (shield_mode.eq.2) then
163        call set_shield_fac2
164       endif
165
166       if (ipot.lt.6) then
167 #ifdef SPLITELE
168          if (welec.gt.0d0.or.wvdwpp.gt.0d0.or.wel_loc.gt.0d0.or.
169      &       wturn3.gt.0d0.or.wturn4.gt.0d0 .or. wcorr.gt.0.0d0
170      &       .or. wcorr4.gt.0.0d0 .or. wcorr5.gt.0.d0
171      &       .or. wcorr6.gt.0.0d0 .or. wturn6.gt.0.0d0 ) then
172 #else
173          if (welec.gt.0d0.or.wel_loc.gt.0d0.or.
174      &       wturn3.gt.0d0.or.wturn4.gt.0d0 .or. wcorr.gt.0.0d0
175      &       .or. wcorr4.gt.0.0d0 .or. wcorr5.gt.0.d0
176      &       .or. wcorr6.gt.0.0d0 .or. wturn6.gt.0.0d0 ) then
177 #endif
178            call eelec_scale(ees,evdw1,eel_loc,eello_turn3,eello_turn4)
179          else
180             ees=0
181             evdw1=0
182             eel_loc=0
183             eello_turn3=0
184             eello_turn4=0
185          endif
186       else
187 c        write (iout,*) "Soft-spheer ELEC potential"
188         call eelec_soft_sphere(ees,evdw1,eel_loc,eello_turn3,
189      &   eello_turn4)
190       endif
191 C
192 C Calculate excluded-volume interaction energy between peptide groups
193 C and side chains.
194 C
195       if (ipot.lt.6) then
196        if(wscp.gt.0d0) then
197         call escp_long(evdw2,evdw2_14)
198        else
199         evdw2=0
200         evdw2_14=0
201        endif
202       else
203         call escp_soft_sphere(evdw2,evdw2_14)
204       endif
205 #ifdef FOURBODY
206
207 C 12/1/95 Multi-body terms
208 C
209       n_corr=0
210       n_corr1=0
211       if ((wcorr4.gt.0.0d0 .or. wcorr5.gt.0.0d0 .or. wcorr6.gt.0.0d0 
212      &    .or. wturn6.gt.0.0d0) .and. ipot.lt.6) then
213          call multibody_eello(ecorr,ecorr5,ecorr6,eturn6,n_corr,n_corr1)
214 c         write (2,*) 'n_corr=',n_corr,' n_corr1=',n_corr1,
215 c     &" ecorr",ecorr," ecorr5",ecorr5," ecorr6",ecorr6," eturn6",eturn6
216       else
217          ecorr=0.0d0
218          ecorr5=0.0d0
219          ecorr6=0.0d0
220          eturn6=0.0d0
221       endif
222       if ((wcorr4.eq.0.0d0 .and. wcorr.gt.0.0d0) .and. ipot.lt.6) then
223          call multibody_hb(ecorr,ecorr5,ecorr6,n_corr,n_corr1)
224       endif
225 #endif
226
227 C If performing constraint dynamics, call the constraint energy
228 C  after the equilibration time
229       if(usampl.and.totT.gt.eq_time) then
230          call EconstrQ   
231          if (loc_qlike) then
232            call Econstr_back_qlike
233          else
234            call Econstr_back
235          endif
236       else
237          Uconst=0.0d0
238          Uconst_back=0.0d0
239       endif
240
241 C Sum the energies
242 C
243       do i=1,n_ene
244         energia(i)=0.0d0
245       enddo
246       energia(1)=evdw
247 #ifdef SCP14
248       energia(2)=evdw2-evdw2_14
249       energia(18)=evdw2_14
250 #else
251       energia(2)=evdw2
252       energia(18)=0.0d0
253 #endif
254 #ifdef SPLITELE
255       energia(3)=ees
256       energia(16)=evdw1
257 #else
258       energia(3)=ees+evdw1
259       energia(16)=0.0d0
260 #endif
261       energia(4)=ecorr
262       energia(5)=ecorr5
263       energia(6)=ecorr6
264       energia(7)=eel_loc
265       energia(8)=eello_turn3
266       energia(9)=eello_turn4
267       energia(10)=eturn6
268       energia(20)=Uconst+Uconst_back
269       energia(27)=ehomology_constr
270       energia(28)=edfadis
271       energia(29)=edfator
272       energia(30)=edfanei
273       energia(31)=edfabet
274       call sum_energy(energia,.true.)
275 c      write (iout,*) "Exit ETOTAL_LONG"
276 c      call flush(iout)
277       return
278       end
279 c------------------------------------------------------------------------------
280       subroutine etotal_short(energia)
281       implicit real*8 (a-h,o-z)
282       include 'DIMENSIONS'
283 c
284 c Compute the short-range fast-varying contributions to the energy
285 c
286 #ifndef ISNAN
287       external proc_proc
288 #ifdef WINPGI
289 cMS$ATTRIBUTES C ::  proc_proc
290 #endif
291 #endif
292 #ifdef MPI
293       include "mpif.h"
294       double precision weights_(n_ene)
295       double precision time00
296       integer ierror,ierr
297 #endif
298       include 'COMMON.SETUP'
299       include 'COMMON.IOUNITS'
300       double precision energia(0:n_ene)
301       include 'COMMON.FFIELD'
302       include 'COMMON.DERIV'
303       include 'COMMON.INTERACT'
304       include 'COMMON.SBRIDGE'
305       include 'COMMON.CHAIN'
306       include 'COMMON.VAR'
307       include 'COMMON.LOCAL'
308       include 'COMMON.CONTROL'
309       include 'COMMON.SAXS'
310       include 'COMMON.TORCNSTR'
311       double precision evdw,evdw1,evdw2,evdw2_14,ees,eel_loc,
312      & eello_turn3,eello_turn4,edfadis,estr,ehpb,ebe,ethetacnstr,
313      & escloc,etors,edihcnstr,etors_d,esccor,ecorr,ecorr5,ecorr6,eturn6,
314      & eliptran,Eafmforce,Etube,
315      & esaxs_constr,ehomology_constr,edfator,edfanei,edfabet
316       integer i,n_corr,n_corr1
317 c      write(iout,'(a,i2)')'Calling etotal_short ipot=',ipot
318 c      call flush(iout)
319       if (modecalc.eq.12.or.modecalc.eq.14) then
320 #ifdef MPI
321         if (fg_rank.eq.0) call int_from_cart1(.false.)
322 #else
323         call int_from_cart1(.false.)
324 #endif
325       endif
326 #ifdef MPI      
327 #ifndef DFA
328       edfadis=0.0d0
329       edfator=0.0d0
330       edfanei=0.0d0
331       edfabet=0.0d0
332 #endif
333 c      write(iout,*) "ETOTAL_SHORT Processor",fg_rank,
334 c     & " absolute rank",myrank," nfgtasks",nfgtasks
335 c      call flush(iout)
336       if (nfgtasks.gt.1) then
337         time00=MPI_Wtime()
338 C FG slaves call the following matching MPI_Bcast in ERGASTULUM
339         if (fg_rank.eq.0) then
340           call MPI_Bcast(2,1,MPI_INTEGER,king,FG_COMM,IERROR)
341 c          write (iout,*) "Processor",myrank," BROADCAST iorder"
342 c          call flush(iout)
343 C FG master sets up the WEIGHTS_ array which will be broadcast to the 
344 C FG slaves as WEIGHTS array.
345           weights_(1)=wsc
346           weights_(2)=wscp
347           weights_(3)=welec
348           weights_(4)=wcorr
349           weights_(5)=wcorr5
350           weights_(6)=wcorr6
351           weights_(7)=wel_loc
352           weights_(8)=wturn3
353           weights_(9)=wturn4
354           weights_(10)=wturn6
355           weights_(11)=wang
356           weights_(12)=wscloc
357           weights_(13)=wtor
358           weights_(14)=wtor_d
359           weights_(15)=wstrain
360           weights_(16)=wvdwpp
361           weights_(17)=wbond
362           weights_(18)=scal14
363           weights_(21)=wsccor
364           weights_(26)=wsaxs
365           weights_(29)=wdfa_tor
366           weights_(30)=wdfa_nei
367           weights_(31)=wdfa_beta
368 C FG Master broadcasts the WEIGHTS_ array
369           call MPI_Bcast(weights_(1),n_ene,
370      &        MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
371         else
372 C FG slaves receive the WEIGHTS array
373           call MPI_Bcast(weights(1),n_ene,
374      &        MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
375           wsc=weights(1)
376           wscp=weights(2)
377           welec=weights(3)
378           wcorr=weights(4)
379           wcorr5=weights(5)
380           wcorr6=weights(6)
381           wel_loc=weights(7)
382           wturn3=weights(8)
383           wturn4=weights(9)
384           wturn6=weights(10)
385           wang=weights(11)
386           wscloc=weights(12)
387           wtor=weights(13)
388           wtor_d=weights(14)
389           wstrain=weights(15)
390           wvdwpp=weights(16)
391           wbond=weights(17)
392           scal14=weights(18)
393           wsccor=weights(21)
394           wsaxs=weights(26)
395         endif
396 c        write (iout,*),"Processor",myrank," BROADCAST weights"
397         call MPI_Bcast(c(1,1),maxres6,MPI_DOUBLE_PRECISION,
398      &    king,FG_COMM,IERR)
399 c        write (iout,*) "Processor",myrank," BROADCAST c"
400         call MPI_Bcast(dc(1,1),maxres6,MPI_DOUBLE_PRECISION,
401      &    king,FG_COMM,IERR)
402 c        write (iout,*) "Processor",myrank," BROADCAST dc"
403         call MPI_Bcast(dc_norm(1,1),maxres6,MPI_DOUBLE_PRECISION,
404      &    king,FG_COMM,IERR)
405 c        write (iout,*) "Processor",myrank," BROADCAST dc_norm"
406         call MPI_Bcast(theta(1),nres,MPI_DOUBLE_PRECISION,
407      &    king,FG_COMM,IERR)
408 c        write (iout,*) "Processor",myrank," BROADCAST theta"
409         call MPI_Bcast(phi(1),nres,MPI_DOUBLE_PRECISION,
410      &    king,FG_COMM,IERR)
411 c        write (iout,*) "Processor",myrank," BROADCAST phi"
412         call MPI_Bcast(alph(1),nres,MPI_DOUBLE_PRECISION,
413      &    king,FG_COMM,IERR)
414 c        write (iout,*) "Processor",myrank," BROADCAST alph"
415         call MPI_Bcast(omeg(1),nres,MPI_DOUBLE_PRECISION,
416      &    king,FG_COMM,IERR)
417 c        write (iout,*) "Processor",myrank," BROADCAST omeg"
418         call MPI_Bcast(vbld(1),2*nres,MPI_DOUBLE_PRECISION,
419      &    king,FG_COMM,IERR)
420 c        write (iout,*) "Processor",myrank," BROADCAST vbld"
421         call MPI_Bcast(vbld_inv(1),2*nres,MPI_DOUBLE_PRECISION,
422      &    king,FG_COMM,IERR)
423          time_Bcast=time_Bcast+MPI_Wtime()-time00
424 c        write (iout,*) "Processor",myrank," BROADCAST vbld_inv"
425       endif
426 c      write (iout,*) 'Processor',myrank,
427 c     &  ' calling etotal_short ipot=',ipot
428 c      call flush(iout)
429 c      print *,'Processor',myrank,' nnt=',nnt,' nct=',nct
430 #endif     
431 c      call int_from_cart1(.false.)
432 C
433 C Compute the side-chain and electrostatic interaction energy
434 C
435       goto (101,102,103,104,105,106) ipot
436 C Lennard-Jones potential.
437   101 call elj_short(evdw)
438 cd    print '(a)','Exit ELJ'
439       goto 107
440 C Lennard-Jones-Kihara potential (shifted).
441   102 call eljk_short(evdw)
442       goto 107
443 C Berne-Pechukas potential (dilated LJ, angular dependence).
444   103 call ebp_short(evdw)
445       goto 107
446 C Gay-Berne potential (shifted LJ, angular dependence).
447   104 call egb_short(evdw)
448       goto 107
449 C Gay-Berne-Vorobjev potential (shifted LJ, angular dependence).
450   105 call egbv_short(evdw)
451       goto 107
452 C Soft-sphere potential - already dealt with in the long-range part
453   106 evdw=0.0d0
454 c  106 call e_softsphere_short(evdw)
455 C
456 C Calculate electrostatic (H-bonding) energy of the main chain.
457 C
458   107 continue
459 c
460 c Calculate the short-range part of Evdwpp
461 c
462       call evdwpp_short(evdw1)
463 c
464 c Calculate the short-range part of ESCp
465 c
466       if (ipot.lt.6) then
467         call escp_short(evdw2,evdw2_14)
468       endif
469 c
470 c Calculate the bond-stretching energy
471 c
472       call ebond(estr)
473
474 C Calculate the disulfide-bridge and other energy and the contributions
475 C from other distance constraints.
476       call edis(ehpb)
477 C
478 C Calculate the virtual-bond-angle energy.
479 C
480       if (wang.gt.0d0) then
481        if (tor_mode.eq.0) then
482          call ebend(ebe)
483        else
484 C ebend kcc is Kubo cumulant clustered rigorous attemp to derive the
485 C energy function
486          call ebend_kcc(ebe)
487        endif
488       else
489         ebe=0.0d0
490       endif
491       ethetacnstr=0.0d0
492       if (with_theta_constr) call etheta_constr(ethetacnstr)
493 C
494 C Calculate the SC local energy.
495 C
496       call vec_and_deriv
497       call esc(escloc)
498 C
499 C Calculate the virtual-bond torsional energy.
500 C
501       if (wtor.gt.0.0d0) then
502          if (tor_mode.eq.0) then
503            call etor(etors)
504          else
505 C etor kcc is Kubo cumulant clustered rigorous attemp to derive the
506 C energy function
507            call etor_kcc(etors)
508          endif
509       else
510         etors=0.0d0
511       endif
512       edihcnstr=0.0d0
513 c Lipid transfer
514       if (wliptran.gt.0) then
515         call Eliptransfer(eliptran)
516       else
517         eliptran=0.0d0
518       endif
519
520       if (ndih_constr.gt.0) call etor_constr(edihcnstr)
521 c      print *,"Processor",myrank," computed Utor"
522 C
523 C 6/23/01 Calculate double-torsional energy
524 C
525       if ((wtor_d.gt.0.0d0).and.(tor_mode.eq.0)) then
526         call etor_d(etors_d)
527       else
528         etors_d=0
529       endif
530 c
531 c Homology restraints
532 c
533       if (constr_homology.ge.1) then
534         call e_modeller(ehomology_constr)
535       else
536         ehomology_constr=0.0d0
537       endif
538 #ifdef DFA
539 C     BARTEK for dfa test!
540       if (wdfa_dist.gt.0) then
541          call edfad(edfadis)
542       else
543          edfadis=0.0
544       endif
545 c      print*, 'edfad is finished!', edfadis
546       if (wdfa_tor.gt.0) then
547          call edfat(edfator)
548       else
549          edfator=0.0
550       endif
551 c      print*, 'edfat is finished!', edfator
552       if (wdfa_nei.gt.0) then
553          call edfan(edfanei)
554       else
555          edfanei=0.0
556       endif
557 c      print*, 'edfan is finished!', edfanei
558       if (wdfa_beta.gt.0) then
559          call edfab(edfabet)
560       else
561          edfabet=0.0
562       endif
563 c      print*, 'edfab is finished!', edfabet
564 #endif
565 C
566 C 21/5/07 Calculate local sicdechain correlation energy
567 C
568       if (wsccor.gt.0.0d0) then
569         call eback_sc_corr(esccor)
570       else
571         esccor=0.0d0
572       endif
573 c      write (iout,*) "nsaxs",nsaxs," saxs_mode",saxs_mode
574       if (nsaxs.gt.0 .and. saxs_mode.eq.0) then
575         call e_saxs(Esaxs_constr)
576 c        write (iout,*) "From Esaxs: Esaxs_constr",Esaxs_constr
577       else if (nsaxs.gt.0 .and. saxs_mode.gt.0) then
578         call e_saxsC(Esaxs_constr)
579 c        write (iout,*) "From EsaxsC: Esaxs_constr",Esaxs_constr
580       else
581         Esaxs_constr = 0.0d0
582       endif
583 C
584 C Put energy components into an array
585 C
586       do i=1,n_ene
587         energia(i)=0.0d0
588       enddo
589       energia(1)=evdw
590 #ifdef SCP14
591       energia(2)=evdw2-evdw2_14
592       energia(18)=evdw2_14
593 #else
594       energia(2)=evdw2
595       energia(18)=0.0d0
596 #endif
597 #ifdef SPLITELE
598       energia(3)=ees
599       energia(16)=evdw1
600 #else
601       energia(3)=ees+evdw1
602       energia(16)=0.0d0
603 #endif
604       energia(4)=ecorr
605       energia(5)=ecorr5
606       energia(6)=ecorr6
607       energia(7)=eel_loc
608       energia(8)=eello_turn3
609       energia(9)=eello_turn4
610       energia(10)=eturn6
611       energia(11)=ebe
612       energia(12)=escloc
613       energia(13)=etors
614       energia(14)=etors_d
615       energia(15)=ehpb
616       energia(17)=estr
617       energia(19)=edihcnstr
618       energia(21)=esccor
619       energia(22)=eliptran
620       energia(24)=ethetacnstr
621       energia(25)=Etube
622       energia(26)=Esaxs_constr
623       energia(27)=ehomology_constr
624       energia(28)=edfadis
625       energia(29)=edfator
626       energia(30)=edfanei
627       energia(31)=edfabet
628 c      write (iout,*) "ETOTAL_SHORT before SUM_ENERGY"
629 c      call flush(iout)
630       call sum_energy(energia,.true.)
631 c      write (iout,*) "Exit ETOTAL_SHORT"
632 c      call flush(iout)
633       return
634       end