update new files
[unres.git] / source / maxlik / src_MD_T_maxlik-NEWCORR-PMF-5 / rmscalc.f.safe
1       double precision function rmsnat(ib,jcon,iref,iprot)
2       implicit none
3       include 'DIMENSIONS'
4       include 'DIMENSIONS.ZSCOPT'
5       include 'COMMON.IOUNITS'
6       include 'COMMON.COMPAR'
7       include 'COMMON.CHAIN' 
8       include 'COMMON.INTERACT'
9       include 'COMMON.VAR'
10       double precision creff(3,maxres2),cc(3,maxres2)
11       integer jcon,ib,iref,iprot
12       double precision rmscalc
13       rmsnat=rmscalc(c(1,1),cref(1,1,iref,ib,iprot),jcon,iref,iprot)
14       return
15       end
16 c------------------------------------------------------------------------
17       double precision function rmscalc(ccc,cccref,jcon,iref,iprot)
18       implicit none
19       include 'DIMENSIONS'
20       include 'DIMENSIONS.ZSCOPT'
21       include 'COMMON.IOUNITS'
22       include 'COMMON.COMPAR'
23       include 'COMMON.CHAIN' 
24       include 'COMMON.INTERACT'
25       include 'COMMON.VAR'
26       double precision cccref(3,maxres2),creff(3,maxres2),
27      &  ccc(3,maxres2),cc(3,maxres2)
28       double precision przes(3),obrot(3,3)
29       logical non_conv
30       integer ishif,i,ii,j,jcon,ib,iref,iprot
31       double precision rms
32       ii=0
33       if (.not.sconly(iprot)) then
34         do i=nstart_sup(iprot),nend_sup(iprot)
35           if (itype(i).ne.ntyp1) then
36             ii=ii+1
37             do j=1,3
38               cc(j,ii)=ccc(j,i)
39               creff(j,ii)=cccref(j,i)
40             enddo
41           endif
42         enddo
43       endif
44       do i=nstart_sup(iprot),nend_sup(iprot)
45         if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
46           ii=ii+1
47           do j=1,3
48             cc(j,ii)=ccc(j,i+nres)
49             creff(j,ii)=cccref(j,i+nres)
50           enddo
51         endif
52       enddo
53       write (iout,*) "rmscalc: iprot",iprot," nsup",nsup(iprot)," ii",ii
54       call fitsq(rms,cc(1,1),creff(1,1),ii,przes,obrot,non_conv)
55       if (non_conv) then
56         write (iout,*) 'Error: FITSQ non-convergent, iprot',iprot,
57      &   ' jcon',jcon,' iref',iref
58         rmscalc=1.0d2
59       else if (rms.lt.-1.0d-6) then 
60         print *,'Error: rms^2 = ',rms,jcon
61         rmscalc = 1.0d2
62       else if (rms.ge.1.0d-6 .and. rms.lt.0) then
63         rmscalc=0.0d0
64       else 
65         rmscalc = dsqrt(rms)
66       endif
67       return
68       end