1 subroutine optsave (ncycle,f,xx)
36 !c nothing to do if coordinate type is undefined
38 if (coordtype .eq. 'NONE') return
40 !c check scaling factors for optimization parameters
42 if (.not. set_scale) then
44 if (coordtype .eq. 'CARTESIAN') then
45 if (.not. allocated(scale)) allocate (scale(3*n))
49 else if (coordtype .eq. 'INTERNAL') then
50 if (.not. allocated(scale)) allocate (scale(nomega))
57 !c convert optimization parameters to atomic coordinates
59 if (coordtype .eq. 'CARTESIAN') then
64 x(i) = xx(nvar) / scale(nvar)
66 y(i) = xx(nvar) / scale(nvar)
68 z(i) = xx(nvar) / scale(nvar)
71 if (use_bounds) call bounds
72 else if (coordtype .eq. 'INTERNAL') then
74 dihed(i) = xx(i) / scale(i)
75 ztors(zline(i)) = dihed(i) * radian
79 !c get name of archive or intermediate coordinates file
84 optfile = filename(1:leng)
85 call suffix (optfile,'arc','old')
86 inquire (file=optfile,exist=exist)
88 call openend (iopt,optfile)
90 open (unit=iopt,file=optfile,status='new')
94 call numeral (ncycle,ext,lext)
95 optfile = filename(1:leng)//'.'//ext(1:lext)
96 call version (optfile,'new')
97 open (unit=iopt,file=optfile,status='new')
101 call version (optfile,'old')
102 open (unit=iopt,file=optfile,status='old')
106 !c update intermediate file with desired coordinate type
108 if (coordtype .eq. 'CARTESIAN') then
110 else if (coordtype .eq. 'INTERNAL') then
112 else if (coordtype .eq. 'RIGIDBODY') then
117 !c save the force vector components for the current step
119 if (frcsave .and. coordtype.eq.'CARTESIAN') then
122 frcfile = filename(1:leng)
123 call suffix (frcfile,'frc','old')
124 inquire (file=frcfile,exist=exist)
126 call openend (ifrc,frcfile)
128 open (unit=ifrc,file=frcfile,status='new')
131 frcfile = filename(1:leng)//'.'//ext(1:lext)//'f'
132 call version (frcfile,'new')
133 open (unit=ifrc,file=frcfile,status='new')
135 write (ifrc,250) n,title(1:ltitle)
138 write (ifrc,260) i,name(i),(-desum(j,i),j=1,3)
139 260 format (i6,2x,a3,3x,d13.6,3x,d13.6,3x,d13.6)
142 write (iout,270) frcfile(1:trimtext(frcfile))
143 270 format (' Force Vector File',11x,a)
146 !c save the current induced dipole moment at each site
148 if (uindsave .and. use_polar .and. coordtype.eq.'CARTESIAN') then
151 indfile = filename(1:leng)
152 call suffix (indfile,'uind','old')
153 inquire (file=indfile,exist=exist)
155 call openend (iind,indfile)
157 open (unit=iind,file=indfile,status='new')
160 indfile = filename(1:leng)//'.'//ext(1:lext)//'u'
161 call version (indfile,'new')
162 open (unit=iind,file=indfile,status='new')
164 write (iind,280) n,title(1:ltitle)
167 if (polarity(i) .ne. 0.0d0) then
169 write (iind,290) k,name(k),(debye*uind(j,i),j=1,3)
170 290 format (i6,2x,a3,3f12.6)
174 write (iout,300) indfile(1:trimtext(indfile))
175 300 format (' Induced Dipole File',10x,a)
178 !c send data via external socket communication if desired
180 if (.not.sktstart .or. use_socket) then
181 if (coordtype .eq. 'INTERNAL') call makexyz
182 call sktopt (ncycle,f)
185 !c test for requested termination of the optimization
187 endfile = 'tinker.end'
188 inquire (file=endfile,exist=exist)
189 if (.not. exist) then
190 endfile = filename(1:leng)//'.end'
191 inquire (file=endfile,exist=exist)
194 open (unit=iend,file=endfile,status='old')
195 close (unit=iend,status='delete')
200 10 format (/,' OPTSAVE -- Optimization Calculation Ending',&
201 ' due to User Request')