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