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