+ else if (preminim) then
+ if (start_from_model) then
+ n_model_try=0
+ fail=.true.
+ list_model_try=0
+ do while (fail .and. n_model_try.lt.nmodel_start)
+ write (iout,*) "n_model_try",n_model_try
+ do
+ i_model=iran_num(1,nmodel_start)
+ do k=1,n_model_try
+ if (i_model.eq.list_model_try(k)) exit
+ enddo
+ if (k.gt.n_model_try) exit
+ enddo
+ n_model_try=n_model_try+1
+ list_model_try(n_model_try)=i_model
+ if (me.eq.king .or. .not. out1file) &
+ write (iout,*) 'Trying to start from model ',&
+ pdbfiles_chomo(i_model)(:ilen(pdbfiles_chomo(i_model)))
+ do i=1,2*nres
+ do j=1,3
+ c(j,i)=chomo(j,i,i_model)
+ enddo
+ enddo
+ call int_from_cart(.true.,.false.)
+ call sc_loc_geom(.false.)
+ dc(:,0)=c(:,1)
+ do i=1,nres-1
+ do j=1,3
+ dc(j,i)=c(j,i+1)-c(j,i)
+ dc_norm(j,i)=dc(j,i)*vbld_inv(i+1)
+ enddo
+ enddo
+ do i=2,nres-1
+ do j=1,3
+ dc(j,i+nres)=c(j,i+nres)-c(j,i)
+ dc_norm(j,i+nres)=dc(j,i+nres)*vbld_inv(i+nres)
+ enddo
+ enddo
+ if (me.eq.king.or..not.out1file) then
+ write (iout,*) "Energies before removing overlaps"
+ call etotal(energia(0))
+ call enerprint(energia(0))
+ endif
+! Remove SC overlaps if requested
+ if (overlapsc) then
+ write (iout,*) 'Calling OVERLAP_SC'
+ call overlap_sc(fail)
+ if (fail) then
+ write (iout,*)&
+ "Failed to remove overlap from model",i_model
+ cycle
+ endif
+ endif
+ if (me.eq.king.or..not.out1file) then
+ write (iout,*) "Energies after removing overlaps"
+ call etotal(energia(0))
+ call enerprint(energia(0))
+ endif
+#ifdef SEARCHSC
+! Search for better SC rotamers if requested
+ if (searchsc) then
+ call sc_move(2,nres-1,10,1d10,nft_sc,etot)
+ print *,'SC_move',nft_sc,etot
+ if (me.eq.king.or..not.out1file)&
+ write(iout,*) 'SC_move',nft_sc,etot
+ endif
+ call etotal(energia(0))
+#endif
+ enddo
+ call MPI_Gather(i_model,1,MPI_INTEGER,i_start_models(0),&
+ 1,MPI_INTEGER,king,CG_COMM,IERROR)
+ if (n_model_try.gt.nmodel_start .and.&
+ (me.eq.king .or. out1file)) then
+ write (iout,*)&
+ "All models have irreparable overlaps. Trying randoms starts."
+ iranconf=1
+ i_model=nmodel_start+1
+ goto 122
+ endif
+ else
+! Remove SC overlaps if requested
+ if (overlapsc) then
+ write (iout,*) 'Calling OVERLAP_SC'
+ call overlap_sc(fail)
+ if (fail) then
+ write (iout,*)&
+ "Failed to remove overlap"
+ endif
+ endif
+ if (me.eq.king.or..not.out1file) then
+ write (iout,*) "Energies after removing overlaps"
+ call etotal(energia(0))
+ call enerprint(energia(0))
+ endif
+ endif
+! 8/22/17 AL Minimize initial structure
+ if (dccart) then
+ if (me.eq.king.or..not.out1file) write(iout,*)&
+ 'Minimizing initial PDB structure: Calling MINIM_DC'
+ call minim_dc(etot,iretcode,nfun)
+ else
+ call geom_to_var(nvar,varia)
+ if(me.eq.king.or..not.out1file) write (iout,*)&
+ 'Minimizing initial PDB structure: Calling MINIMIZE.'
+ call minimize(etot,varia,iretcode,nfun)
+ call var_to_geom(nvar,varia)
+#ifdef LBFGS
+ if (me.eq.king.or..not.out1file)&
+ write(iout,*) 'LBFGS return code is ',status,' eval ',nfun
+ if(me.eq.king.or..not.out1file)&
+ write(iout,*) 'LBFGS return code is ',status,' eval ',nfun
+#else
+ if (me.eq.king.or..not.out1file)&
+ write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
+ if(me.eq.king.or..not.out1file)&
+ write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
+#endif
+ endif
+ endif
+ if (nmodel_start.gt.0 .and. me.eq.king) then
+ write (iout,'(a)') "Task Starting model"
+ do i=0,nodes-1
+ if (i_start_models(i).gt.nmodel_start) then
+ write (iout,'(i4,2x,a)') i,"RANDOM STRUCTURE"
+ else
+ write(iout,'(i4,2x,a)')i,pdbfiles_chomo(i_start_models(i)) &
+ (:ilen(pdbfiles_chomo(i_start_models(i))))
+ endif
+ enddo