correction in multichain
[unres.git] / source / unres / src_MD-M / unres.F
1 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
2 C                                                                              C
3 C                                U N R E S                                     C
4 C                                                                              C
5 C Program to carry out conformational search of proteins in an united-residue  C
6 C approximation.                                                               C
7 C                                                                              C
8 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
9       implicit real*8 (a-h,o-z)
10       include 'DIMENSIONS'
11
12
13 #ifdef MPI
14       include 'mpif.h'
15       include 'COMMON.SETUP'
16 #endif
17       include 'COMMON.TIME1'
18       include 'COMMON.INTERACT'
19       include 'COMMON.NAMES'
20       include 'COMMON.GEO'
21       include 'COMMON.HEADER'
22       include 'COMMON.CONTROL'
23       include 'COMMON.CONTACTS'
24       include 'COMMON.CHAIN'
25       include 'COMMON.VAR'
26       include 'COMMON.IOUNITS'
27       include 'COMMON.FFIELD'
28       include 'COMMON.REMD'
29       include 'COMMON.MD'
30       include 'COMMON.SBRIDGE'
31       double precision hrtime,mintime,sectime
32       character*64 text_mode_calc(-2:14) /'test',
33      & 'SC rotamer distribution',
34      & 'Energy evaluation or minimization',
35      & 'Regularization of PDB structure',
36      & 'Threading of a sequence on PDB structures',
37      & 'Monte Carlo (with minimization) ',
38      & 'Energy minimization of multiple conformations',
39      & 'Checking energy gradient',
40      & 'Entropic sampling Monte Carlo (with minimization)',
41      & 'Energy map',
42      & 'CSA calculations',
43      & 'Not used 9',
44      & 'Not used 10',
45      & 'Soft regularization of PDB structure',
46      & 'Mesoscopic molecular dynamics (MD) ',
47      & 'Not used 13',
48      & 'Replica exchange molecular dynamics (REMD)'/
49       external ilen
50
51 c      call memmon_print_usage()
52
53       call init_task
54       if (me.eq.king)
55      & write(iout,*)'### LAST MODIFIED  4/25/08 7:29PM by adam'  
56       if (me.eq.king) call cinfo
57 C Read force field parameters and job setup data
58       call readrtns
59       call flush(iout)
60 C
61       if (me.eq.king .or. .not. out1file) then
62        write (iout,'(2a/)') 
63      & text_mode_calc(modecalc)(:ilen(text_mode_calc(modecalc))),
64      & ' calculation.' 
65        if (minim) write (iout,'(a)') 
66      &  'Conformations will be energy-minimized.'
67        write (iout,'(80(1h*)/)') 
68       endif
69       call flush(iout)
70 C
71       if (modecalc.eq.-2) then
72         call test
73         stop
74       else if (modecalc.eq.-1) then
75         write(iout,*) "call check_sc_map next"
76         call check_bond
77         stop
78       endif
79 #ifdef MPI
80       if (fg_rank.gt.0) then
81 C Fine-grain slaves just do energy and gradient components.
82         call ergastulum ! slave workhouse in Latin
83       else
84 #endif
85       if (modecalc.eq.0) then
86         call exec_eeval_or_minim
87       else if (modecalc.eq.1) then
88         call exec_regularize
89       else if (modecalc.eq.2) then
90         call exec_thread
91       else if (modecalc.eq.3 .or. modecalc .eq.6) then
92         call exec_MC
93       else if (modecalc.eq.4) then
94         call exec_mult_eeval_or_minim
95       else if (modecalc.eq.5) then
96         call exec_checkgrad
97       else if (ModeCalc.eq.7) then
98         call exec_map
99       else if (ModeCalc.eq.8) then
100         call exec_CSA
101       else if (modecalc.eq.11) then
102         call exec_softreg
103       else if (modecalc.eq.12) then
104         call exec_MD
105       else if (modecalc.eq.14) then
106 #ifdef MPI
107         call exec_MREMD
108 #else
109         write (iout,*) "Need a parallel version to run MREMD."
110         stop
111 #endif
112       else
113         write (iout,'(a)') 'This calculation type is not supported',
114      &   ModeCalc
115       endif
116 #ifdef MPI
117       endif
118 C Finish task.
119       if (fg_rank.eq.0) call finish_task
120 c      call memmon_print_usage()
121 #ifdef TIMING
122        call print_detailed_timing
123 #endif
124       call MPI_Finalize(ierr)
125       stop 'Bye Bye...'
126 #else
127       call dajczas(tcpu(),hrtime,mintime,sectime)
128       stop '********** Program terminated normally.'
129 #endif
130       end
131 c--------------------------------------------------------------------------
132       subroutine exec_MD
133       include 'DIMENSIONS'
134 #ifdef MPI
135       include "mpif.h"
136 #endif
137       include 'COMMON.SETUP'
138       include 'COMMON.CONTROL'
139       include 'COMMON.IOUNITS'
140       if (me.eq.king .or. .not. out1file)
141      &   write (iout,*) "Calling chainbuild"
142       call chainbuild
143       call MD
144       return
145       end
146 c---------------------------------------------------------------------------
147 #ifdef MPI
148       subroutine exec_MREMD
149       include 'DIMENSIONS'
150 #ifdef MPI
151       include "mpif.h"
152 #endif
153       include 'COMMON.SETUP'
154       include 'COMMON.CONTROL'
155       include 'COMMON.IOUNITS'
156       include 'COMMON.REMD'
157       if (me.eq.king .or. .not. out1file)
158      &   write (iout,*) "Calling chainbuild"
159       call chainbuild
160       if (me.eq.king .or. .not. out1file)
161      &   write (iout,*) "Calling REMD"
162       if (remd_mlist) then 
163         call MREMD
164       else
165         do i=1,nrep
166           remd_m(i)=1
167         enddo
168         call MREMD
169       endif
170       return
171       end
172 #endif
173 c---------------------------------------------------------------------------
174       subroutine exec_eeval_or_minim
175       implicit real*8 (a-h,o-z)
176       include 'DIMENSIONS'
177 #ifdef MPI
178       include 'mpif.h'
179 #endif
180       include 'COMMON.SETUP'
181       include 'COMMON.TIME1'
182       include 'COMMON.INTERACT'
183       include 'COMMON.NAMES'
184       include 'COMMON.GEO'
185       include 'COMMON.HEADER'
186       include 'COMMON.CONTROL'
187       include 'COMMON.CONTACTS'
188       include 'COMMON.CHAIN'
189       include 'COMMON.VAR'
190       include 'COMMON.IOUNITS'
191       include 'COMMON.FFIELD'
192       include 'COMMON.REMD'
193       include 'COMMON.MD'
194       include 'COMMON.SBRIDGE'
195       common /srutu/ icall
196       double precision energy(0:n_ene)
197       double precision energy_long(0:n_ene),energy_short(0:n_ene)
198       double precision varia(maxvar)
199       if (indpdb.eq.0)     call chainbuild
200       time00=MPI_Wtime()
201       print *,'dc',c(1,1)
202       if (indpdb.ne.0) then
203       dc(1,0)=c(1,1)
204       dc(2,0)=c(2,1)
205       dc(3,0)=c(3,1)
206       endif
207 #ifdef MPI
208       time00=MPI_Wtime()
209 #else
210       time00=tcpu()
211 #endif
212       call chainbuild_cart
213       print *,'dc',dc(1,0),dc(2,0),dc(3,0)
214       if (split_ene) then
215        print *,"Processor",myrank," after chainbuild"
216        icall=1
217        call etotal_long(energy_long(0))
218        write (iout,*) "Printing long range energy"
219        call enerprint(energy_long(0))
220        call etotal_short(energy_short(0))
221        write (iout,*) "Printing short range energy"
222        call enerprint(energy_short(0))
223        do i=0,n_ene
224          energy(i)=energy_long(i)+energy_short(i)
225          write (iout,*) i,energy_long(i),energy_short(i),energy(i)
226        enddo
227        write (iout,*) "Printing long+short range energy"
228        call enerprint(energy(0))
229       endif
230       call etotal(energy(0))
231 #ifdef MPI
232       time_ene=MPI_Wtime()-time00
233 #else 
234       time_ene=tcpu()-time00
235 #endif
236       write (iout,*) "Time for energy evaluation",time_ene
237       print *,"after etotal"
238       etota = energy(0)
239       etot =etota
240       call enerprint(energy(0))
241       call hairpin(.true.,nharp,iharp)
242         print *,'after hairpin'
243       call secondary2(.true.)
244         print *,'after secondary'
245       if (minim) then
246 crc overlap test
247         if (overlapsc) then 
248           print *, 'Calling OVERLAP_SC'
249           call overlap_sc(fail)
250         endif 
251
252         if (searchsc) then 
253           call sc_move(2,nres-1,10,1d10,nft_sc,etot)
254           print *,'SC_move',nft_sc,etot
255           write(iout,*) 'SC_move',nft_sc,etot
256         endif 
257
258         if (dccart) then
259           print *, 'Calling MINIM_DC'
260 #ifdef MPI
261           time1=MPI_WTIME()
262 #else
263           time1=tcpu()
264 #endif
265           call minim_dc(etot,iretcode,nfun)
266         else
267           if (indpdb.ne.0) then 
268             call bond_regular
269             call chainbuild
270           endif
271           call geom_to_var(nvar,varia)
272           print *,'Calling MINIMIZE.'
273 #ifdef MPI
274           time1=MPI_WTIME()
275 #else
276           time1=tcpu()
277 #endif
278           call minimize(etot,varia,iretcode,nfun)
279         endif
280         print *,'SUMSL return code is',iretcode,' eval ',nfun
281 #ifdef MPI
282         evals=nfun/(MPI_WTIME()-time1)
283 #else
284         evals=nfun/(tcpu()-time1)
285 #endif
286         print *,'# eval/s',evals
287         print *,'refstr=',refstr
288         call hairpin(.false.,nharp,iharp)
289         print *,'after hairpin'
290         call secondary2(.true.)
291         print *,'after secondary'
292         call etotal(energy(0))
293         etot = energy(0)
294         call enerprint(energy(0))
295
296         call intout
297         call briefout(0,etot)
298         if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
299           write (iout,'(a,i3)') 'SUMSL return code:',iretcode
300           write (iout,'(a,i20)') '# of energy evaluations:',nfun+1
301           write (iout,'(a,f16.3)')'# of energy evaluations/sec:',evals
302       else
303         print *,'refstr=',refstr
304         if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
305         call briefout(0,etot)
306       endif
307       if (outpdb) call pdbout(etot,titel(:32),ipdb)
308       if (outmol2) call mol2out(etot,titel(:32))
309       return
310       end
311 c---------------------------------------------------------------------------
312       subroutine exec_regularize
313       implicit real*8 (a-h,o-z)
314       include 'DIMENSIONS'
315 #ifdef MPI
316       include 'mpif.h'
317 #endif
318       include 'COMMON.SETUP'
319       include 'COMMON.TIME1'
320       include 'COMMON.INTERACT'
321       include 'COMMON.NAMES'
322       include 'COMMON.GEO'
323       include 'COMMON.HEADER'
324       include 'COMMON.CONTROL'
325       include 'COMMON.CONTACTS'
326       include 'COMMON.CHAIN'
327       include 'COMMON.VAR'
328       include 'COMMON.IOUNITS'
329       include 'COMMON.FFIELD'
330       include 'COMMON.REMD'
331       include 'COMMON.MD'
332       include 'COMMON.SBRIDGE'
333       double precision energy(0:n_ene)
334
335       call gen_dist_constr
336       call sc_conf
337       call intout
338       call regularize(nct-nnt+1,etot,rms,cref(1,nnt,1),iretcode)
339       call etotal(energy(0))
340       energy(0)=energy(0)-energy(14)
341       etot=energy(0)
342       call enerprint(energy(0))
343       call intout
344       call briefout(0,etot)
345       if (outpdb) call pdbout(etot,titel(:32),ipdb)
346       if (outmol2) call mol2out(etot,titel(:32))
347       if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
348       write (iout,'(a,i3)') 'SUMSL return code:',iretcode
349       return
350       end
351 c---------------------------------------------------------------------------
352       subroutine exec_thread
353       include 'DIMENSIONS'
354 #ifdef MP
355       include "mpif.h"
356 #endif
357       include "COMMON.SETUP"
358       call thread_seq
359       return
360       end
361 c---------------------------------------------------------------------------
362       subroutine exec_MC
363       implicit real*8 (a-h,o-z)
364       include 'DIMENSIONS'
365       character*10 nodeinfo
366       double precision varia(maxvar)
367 #ifdef MPI
368       include "mpif.h"
369 #endif
370       include "COMMON.SETUP"
371       include 'COMMON.CONTROL'
372       call mcm_setup
373       if (minim) then
374 #ifdef MPI
375         if (modecalc.eq.3) then
376           call do_mcm(ipar)
377         else
378           call entmcm
379         endif
380 #else
381         if (modecalc.eq.3) then
382           call do_mcm(ipar)
383         else
384           call entmcm
385         endif
386 #endif
387       else
388         call monte_carlo
389       endif
390       return
391       end
392 c---------------------------------------------------------------------------
393       subroutine exec_mult_eeval_or_minim
394       implicit real*8 (a-h,o-z)
395       include 'DIMENSIONS'
396 #ifdef MPI
397       include 'mpif.h'
398       dimension muster(mpi_status_size)
399 #endif
400       include 'COMMON.SETUP'
401       include 'COMMON.TIME1'
402       include 'COMMON.INTERACT'
403       include 'COMMON.NAMES'
404       include 'COMMON.GEO'
405       include 'COMMON.HEADER'
406       include 'COMMON.CONTROL'
407       include 'COMMON.CONTACTS'
408       include 'COMMON.CHAIN'
409       include 'COMMON.VAR'
410       include 'COMMON.IOUNITS'
411       include 'COMMON.FFIELD'
412       include 'COMMON.REMD'
413       include 'COMMON.MD'
414       include 'COMMON.SBRIDGE'
415       double precision varia(maxvar)
416       dimension ind(6)
417       double precision energy(0:max_ene)
418       logical eof
419       eof=.false.
420 #ifdef MPI
421       if(me.ne.king) then
422         call minim_mcmf
423         return
424       endif
425
426       close (intin)
427       open(intin,file=intinname,status='old')
428       write (istat,'(a5,20a12)')"#    ",
429      &  (wname(print_order(i)),i=1,nprint_ene)
430       if (refstr) then
431         write (istat,'(a5,20a12)')"#    ",
432      &   (ename(print_order(i)),i=1,nprint_ene),
433      &   "ETOT total","RMSD","nat.contact","nnt.contact"        
434       else
435         write (istat,'(a5,20a12)')"#    ",
436      &    (ename(print_order(i)),i=1,nprint_ene),"ETOT total"
437       endif
438
439       if (.not.minim) then
440         do while (.not. eof)
441           if (read_cart) then
442             read (intin,'(e15.10,e15.5)',end=1100,err=1100) time,ene
443             call read_x(intin,*11)
444 #ifdef MPI
445 c Broadcast the order to compute internal coordinates to the slaves.
446             if (nfgtasks.gt.1)
447      &        call MPI_Bcast(6,1,MPI_INTEGER,king,FG_COMM,IERROR)
448 #endif
449             call int_from_cart1(.false.)
450           else
451             read (intin,'(i5)',end=1100,err=1100) iconf
452             call read_angles(intin,*11)
453             call geom_to_var(nvar,varia)
454             call chainbuild
455           endif
456           write (iout,'(a,i7)') 'Conformation #',iconf
457           call etotal(energy(0))
458           call briefout(iconf,energy(0))
459           call enerprint(energy(0))
460           etot=energy(0)
461           if (refstr) then 
462             call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
463             write (istat,'(i5,20(f12.3))') iconf,
464      &      (energy(print_order(i)),i=1,nprint_ene),etot,
465      &       rms,frac,frac_nn,co
466 cjlee end
467           else
468             write (istat,'(i5,16(f12.3))') iconf,
469      &     (energy(print_order(i)),i=1,nprint_ene),etot
470           endif
471         enddo
472 1100    continue
473         goto 1101
474       endif
475
476       mm=0
477       imm=0
478       nft=0
479       ene0=0.0d0
480       n=0
481       iconf=0
482 c      do n=1,nzsc
483       do while (.not. eof)
484         mm=mm+1
485         if (mm.lt.nodes) then
486           if (read_cart) then
487             read (intin,'(e15.10,e15.5)',end=11,err=11) time,ene
488             call read_x(intin,*11)
489 #ifdef MPI
490 c Broadcast the order to compute internal coordinates to the slaves.
491             if (nfgtasks.gt.1) 
492      &        call MPI_Bcast(6,1,MPI_INTEGER,king,FG_COMM,IERROR)
493 #endif
494             call int_from_cart1(.false.)
495           else
496             read (intin,'(i5)',end=11,err=11) iconf
497             call read_angles(intin,*11)
498             call geom_to_var(nvar,varia)
499             call chainbuild
500           endif
501           write (iout,'(a,i7)') 'Conformation #',iconf
502           n=n+1
503          imm=imm+1
504          ind(1)=1
505          ind(2)=n
506          ind(3)=0
507          ind(4)=0
508          ind(5)=0
509          ind(6)=0
510          ene0=0.0d0
511          call mpi_send(ind,6,mpi_integer,mm,idint,CG_COMM,
512      *                  ierr)
513          call mpi_send(varia,nvar,mpi_double_precision,mm,
514      *                  idreal,CG_COMM,ierr)
515          call mpi_send(ene0,1,mpi_double_precision,mm,
516      *                  idreal,CG_COMM,ierr)
517 c         print *,'task ',n,' sent to worker ',mm,nvar
518         else
519          call mpi_recv(ind,6,mpi_integer,mpi_any_source,idint,
520      *                 CG_COMM,muster,ierr)
521          man=muster(mpi_source)
522 c         print *,'receiving result from worker ',man,' (',iii1,iii,')'
523          call mpi_recv(varia,nvar,mpi_double_precision, 
524      *               man,idreal,CG_COMM,muster,ierr)
525          call mpi_recv(ene,1,
526      *               mpi_double_precision,man,idreal,
527      *               CG_COMM,muster,ierr)
528          call mpi_recv(ene0,1,
529      *               mpi_double_precision,man,idreal,
530      *               CG_COMM,muster,ierr)
531 c         print *,'result received from worker ',man,' sending now'
532
533           call var_to_geom(nvar,varia)
534           call chainbuild
535           call etotal(energy(0))
536           iconf=ind(2)
537           write (iout,*)
538           write (iout,*)
539           write (iout,'(a,2i7)') 'Conformation #',iconf,ind(5)
540
541           etot=energy(0)
542           call enerprint(energy(0))
543           call briefout(it,etot)
544 c          if (minim) call briefout(it,etot)
545           if (refstr) then 
546             call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
547             write (istat,'(i5,19(f12.3))') iconf,
548      &     (energy(print_order(i)),i=1,nprint_ene),etot,
549      &     rms,frac,frac_nn,co
550           else
551             write (istat,'(i5,15(f12.3))') iconf,
552      &     (energy(print_order(i)),i=1,nprint_ene),etot
553           endif
554
555           imm=imm-1
556           if (read_cart) then
557             read (intin,'(e15.10,e15.5)',end=1101,err=1101) time,ene
558             call read_x(intin,*11)
559 #ifdef MPI
560 c Broadcast the order to compute internal coordinates to the slaves.
561             if (nfgtasks.gt.1)
562      &        call MPI_Bcast(6,1,MPI_INTEGER,king,FG_COMM,IERROR)
563 #endif
564             call int_from_cart1(.false.)
565           else
566             read (intin,'(i5)',end=1101,err=1101) iconf
567             call read_angles(intin,*11)
568             call geom_to_var(nvar,varia)
569             call chainbuild
570           endif
571           n=n+1
572           imm=imm+1
573           ind(1)=1
574           ind(2)=n
575           ind(3)=0
576           ind(4)=0
577           ind(5)=0
578           ind(6)=0
579           call mpi_send(ind,6,mpi_integer,man,idint,CG_COMM,
580      *                  ierr)
581           call mpi_send(varia,nvar,mpi_double_precision,man, 
582      *                  idreal,CG_COMM,ierr)
583           call mpi_send(ene0,1,mpi_double_precision,man,
584      *                  idreal,CG_COMM,ierr)
585           nf_mcmf=nf_mcmf+ind(4)
586           nmin=nmin+1
587         endif
588       enddo
589 11    continue
590       do j=1,imm
591         call mpi_recv(ind,6,mpi_integer,mpi_any_source,idint,
592      *               CG_COMM,muster,ierr)
593         man=muster(mpi_source)
594         call mpi_recv(varia,nvar,mpi_double_precision, 
595      *               man,idreal,CG_COMM,muster,ierr)
596         call mpi_recv(ene,1,
597      *               mpi_double_precision,man,idreal,
598      *               CG_COMM,muster,ierr)
599         call mpi_recv(ene0,1,
600      *               mpi_double_precision,man,idreal,
601      *               CG_COMM,muster,ierr)
602
603         call var_to_geom(nvar,varia)
604         call chainbuild
605         call etotal(energy(0))
606         iconf=ind(2)
607         write (iout,*)
608         write (iout,*)
609         write (iout,'(a,2i7)') 'Conformation #',iconf,ind(5)
610
611         etot=energy(0)
612         call enerprint(energy(0))
613         call briefout(it,etot)
614         if (refstr) then 
615           call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
616           write (istat,'(i5,19(f12.3))') iconf,
617      &   (energy(print_order(i)),i=1,nprint_ene),etot,
618      &   rms,frac,frac_nn,co
619         else
620           write (istat,'(i5,15(f12.3))') iconf,
621      &    (energy(print_order(i)),i=1,nprint_ene),etot
622         endif
623         nmin=nmin+1
624       enddo
625 1101  continue
626       do i=1, nodes-1
627          ind(1)=0
628          ind(2)=0
629          ind(3)=0
630          ind(4)=0
631          ind(5)=0
632          ind(6)=0
633          call mpi_send(ind,6,mpi_integer,i,idint,CG_COMM,
634      *                  ierr)
635       enddo
636 #else
637       close (intin)
638       open(intin,file=intinname,status='old')
639       write (istat,'(a5,20a12)')"#    ",
640      &   (wname(print_order(i)),i=1,nprint_ene)
641       write (istat,'("#    ",20(1pe12.4))')
642      &   (weights(print_order(i)),i=1,nprint_ene)
643       if (refstr) then
644         write (istat,'(a5,20a12)')"#    ",
645      &   (ename(print_order(i)),i=1,nprint_ene),
646      &   "ETOT total","RMSD","nat.contact","nnt.contact"
647       else
648         write (istat,'(a5,14a12)')"#    ",
649      &   (ename(print_order(i)),i=1,nprint_ene),"ETOT total"
650       endif
651       do while (.not. eof)
652           if (read_cart) then
653             read (intin,'(e15.10,e15.5)',end=11,err=11) time,ene
654             call read_x(intin,*11)
655 #ifdef MPI
656 c Broadcast the order to compute internal coordinates to the slaves.
657             if (nfgtasks.gt.1)
658      &        call MPI_Bcast(6,1,MPI_INTEGER,king,FG_COMM,IERROR)
659 #endif
660             call int_from_cart1(.false.)
661           else
662             read (intin,'(i5)',end=11,err=11) iconf
663             call read_angles(intin,*11)
664             call geom_to_var(nvar,varia)
665             call chainbuild
666           endif
667         write (iout,'(a,i7)') 'Conformation #',iconf
668         if (minim) call minimize(etot,varia,iretcode,nfun)
669         call etotal(energy(0))
670
671         etot=energy(0)
672         call enerprint(energy(0))
673         if (minim) call briefout(it,etot) 
674         if (refstr) then 
675           call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
676           write (istat,'(i5,18(f12.3))') iconf,
677      &   (energy(print_order(i)),i=1,nprint_ene),
678      &   etot,rms,frac,frac_nn,co
679 cjlee end
680         else
681           write (istat,'(i5,14(f12.3))') iconf,
682      &   (energy(print_order(i)),i=1,nprint_ene),etot
683         endif
684       enddo
685    11 continue
686 #endif
687       return
688       end
689 c---------------------------------------------------------------------------
690       subroutine exec_checkgrad
691       implicit real*8 (a-h,o-z)
692       include 'DIMENSIONS'
693 #ifdef MPI
694       include 'mpif.h'
695 #endif
696       include 'COMMON.SETUP'
697       include 'COMMON.TIME1'
698       include 'COMMON.INTERACT'
699       include 'COMMON.NAMES'
700       include 'COMMON.GEO'
701       include 'COMMON.HEADER'
702       include 'COMMON.CONTROL'
703       include 'COMMON.CONTACTS'
704       include 'COMMON.CHAIN'
705       include 'COMMON.VAR'
706       include 'COMMON.IOUNITS'
707       include 'COMMON.FFIELD'
708       include 'COMMON.REMD'
709       include 'COMMON.MD'
710       include 'COMMON.SBRIDGE'
711       common /srutu/ icall
712       double precision energy(0:max_ene)
713 c      do i=2,nres
714 c        vbld(i)=vbld(i)+ran_number(-0.1d0,0.1d0)
715 c        if (itype(i).ne.10) 
716 c     &      vbld(i+nres)=vbld(i+nres)+ran_number(-0.001d0,0.001d0)
717 c      enddo
718       if (indpdb.eq.0) call chainbuild
719 c      do i=0,nres
720 c        do j=1,3
721 c          dc(j,i)=dc(j,i)+ran_number(-0.2d0,0.2d0)
722 c        enddo
723 c      enddo
724 c      do i=1,nres-1
725 c        if (itype(i).ne.10) then
726 c          do j=1,3
727 c            dc(j,i+nres)=dc(j,i+nres)+ran_number(-0.2d0,0.2d0)
728 c          enddo
729 c        endif
730 c      enddo
731 c      do j=1,3
732 c        dc(j,0)=ran_number(-0.2d0,0.2d0)
733 c      enddo
734       usampl=.true.
735       totT=1.d0
736       eq_time=0.0d0
737       call read_fragments
738       call chainbuild_cart
739       call cartprint
740       call intout
741       icall=1
742       call etotal(energy(0))
743       etot = energy(0)
744       call enerprint(energy(0))
745       write (iout,*) "Uconst",Uconst," Uconst_back",uconst_back
746       print *,'icheckgrad=',icheckgrad
747       goto (10,20,30) icheckgrad
748   10  call check_ecartint
749       return
750   20  call check_cartgrad
751       return
752   30  call check_eint
753       return
754       end
755 c---------------------------------------------------------------------------
756       subroutine exec_map
757 C Energy maps
758       call map_read
759       call map
760       return
761       end
762 c---------------------------------------------------------------------------
763       subroutine exec_CSA
764 #ifdef MPI
765       include "mpif.h"
766 #endif
767       include 'DIMENSIONS'
768       include 'COMMON.IOUNITS'
769 C Conformational Space Annealling programmed by Jooyoung Lee.
770 C This method works only with parallel machines!
771 #ifdef MPI
772       call together
773 #else
774       write (iout,*) "CSA works on parallel machines only"
775 #endif
776       return
777       end
778 c---------------------------------------------------------------------------
779       subroutine exec_softreg
780       include 'DIMENSIONS'
781       include 'COMMON.IOUNITS'
782       include 'COMMON.CONTROL'
783       double precision energy(0:max_ene)
784       call chainbuild
785       call etotal(energy(0))
786       call enerprint(energy(0))
787       if (.not.lsecondary) then
788         write(iout,*) 'Calling secondary structure recognition'
789         call secondary2(debug)
790       else
791         write(iout,*) 'Using secondary structure supplied in pdb'
792       endif
793
794       call softreg
795
796       call etotal(energy(0))
797       etot=energy(0)
798       call enerprint(energy(0))
799       call intout
800       call briefout(0,etot)
801       call secondary2(.true.)
802       if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
803       return
804       end