update new files
[unres.git] / source / maxlik / src_FPy.org / zscorez.F.old
1       subroutine maxlik_init(nvarr,xrange,comm)
2 c Optimize the UNRES energy function by minimization of a quartic target
3 c function or by the VMC method.
4       implicit none
5 #ifndef ISNAN
6       external proc_proc
7 #endif
8 #ifdef WINPGI
9 cMS$ATTRIBUTES C ::  proc_proc
10 #endif
11       include "DIMENSIONS"
12       include "DIMENSIONS.ZSCOPT"
13 #ifdef MPI
14       include "mpif.h"
15       integer IERROR,ERRCODE,kolor,key,comm
16       include "COMMON.MPI"
17 #endif
18       include "COMMON.IOUNITS"
19       include "COMMON.OPTIM"
20       include "COMMON.XBOUND"
21       integer nvarr,iparm
22       double precision rr,x(max_paropt)
23       integer idumm
24       integer i
25 #ifdef PYTHON
26       double precision xrange(maxvar,2)
27       integer number_of_variables
28       common /patch/ number_of_variables
29 Cf2py intent(in) comm
30 Cf2py intent(out) nvarr
31 Cf2Py intent(out) xrange
32 #endif
33 c      print *,"Starting..."
34 #ifdef MPI
35 #ifndef PYTHON
36 c      print *,"Initializing MPI..."
37       call MPI_Init( IERROR )
38       ALL_COMM = MPI_COMM_WORLD 
39 #else
40       ALL_COMM = comm
41 #endif
42       call MPI_Comm_rank( ALL_COMM, me, IERROR )
43       call MPI_Comm_size( ALL_COMM, nprocs, IERROR )
44 c      print *,"Finished initializing MPI..."
45       Master = 0
46       Master1 = 1
47 c      print *,"Me",me," Master",master," Ierror",ierror
48 #ifndef PYTHON
49       if (ierror.gt.0) then
50         write(iout,*) "SEVERE ERROR - Can't initialize MPI."
51         call mpi_finalize(ierror)
52         stop
53       endif
54 #endif
55 #endif
56 #ifndef ISNAN
57 c NaNQ initialization
58       i=-1
59       rr=dacos(100.0d0)
60 #ifdef WINPGI
61       idumm=proc_proc(rr,i)
62 #else
63       call proc_proc(rr,i)
64 #endif
65 #endif
66       call initialize
67 c      print *,"calling openunits"
68       call openunits
69 c      print *,"openunits called"
70       call read_general_data(*10)
71       write (iout,'(80(1h-)/10x,
72      & "Maximum likelihood optimization of UNRES energy function",
73      & " v. 05/10/16"/80(1h-))')
74       call flush(iout)
75       call cinfo
76 c      call promienie(*10)
77       write (iout,*) "Finished READ_GENERAL_DATA"
78       call flush(iout)
79       do iparm=1,nparmset
80         call parmread(iparm,*10)
81       enddo
82       write (iout,*) "Finished parmread"
83       call flush(iout)
84       call read_optim_parm(*10)
85       call print_general_data(*10)
86       call read_protein_data(*10)
87       write (iout,*) "Finished READ_PROTEIN_DATA"
88       call flush(iout)
89       call read_database(*10)
90       write (iout,*) "Finished READ_DATABASE"
91       call flush(iout)
92 #ifdef MPI 
93 c      write (iout,*) Me,' calling PROC_GROUPS'
94       call proc_groups
95 c      write (iout,*) Me,' calling WORK_PARTITION_MAP'
96 c      call work_partition_map(nvarr)
97 #endif
98       call proc_data(nvarr,x,*10)
99 #ifdef PYTHON
100       number_of_variables=nvarr
101       do i=1,nvarr
102         xrange(i,1)=x_low(i)
103         xrange(i,2)=x_up(i)
104       enddo
105       write (iout,*) "xrange from MAXLIK_INIT"
106       do i=1,nvarr
107         write (iout,*) i,xrange(i,1),xrange(i,2)
108       enddo
109       write (iout,*) "================ maxlik intiialization completed"
110       call flush (iout)
111 #endif
112       call read_thermal
113       return
114    10 write (iout,*) "Error termination of the program"
115       call MPI_Finalize( IERROR )
116       return
117       end
118 c------------------------------------------------------------------------
119       subroutine maxlik_optim(x,xmin,fmin)
120 c Optimize the UNRES energy function by minimization of a quartic target
121 c function or by the VMC method.
122       implicit none
123 #ifndef ISNAN
124       external proc_proc
125 #endif
126 #ifdef WINPGI
127 cMS$ATTRIBUTES C ::  proc_proc
128 #endif
129       include "DIMENSIONS"
130       include "DIMENSIONS.ZSCOPT"
131 #ifdef MPI
132       include "mpif.h"
133       integer IERROR,ERRCODE,kolor,key
134       include "COMMON.MPI"
135 #endif
136       include "COMMON.IOUNITS"
137       include "COMMON.OPTIM"
138       integer nvarr,iparm,i
139       double precision rr,x(max_paropt),xmin(max_paropt),fmin
140 #ifdef PYTHON
141       integer number_of_variables
142       common /patch/ number_of_variables
143 Cf2py intent(in) x
144 Cf2py intent(out) xmin
145 Cf2py intent(out) fmin
146       nvarr=number_of_variables
147       write (*,*) "MAXLIK_OPTIM: Variables from PYTHON:",nvarr
148       write (iout,*) "MAXLIK_OPTIM: Variables from PYTHON:",nvarr
149       do i=1,nvarr
150         write (iout,*) i,x(i)
151       enddo 
152 #endif
153 #ifdef MPI
154       if (me.eq.Master) then
155 #endif
156       call maxlikopt(nvarr,x,xmin,fmin)
157       write (iout,*) "fmin from MAXLIK_OPTIM:",fmin
158 #ifdef MPI
159       call jebadelko(nvarr)
160       else
161         call jebadelko(nvarr)
162       endif
163       call bilans
164 #ifdef PYTHON
165       write (iout,'(30(1h-),"Minimization completed",30(1h-))')
166       call flush(iout)
167 #else
168       call MPI_Finalize( IERROR )
169 #endif
170 #else
171       call bilans
172 #endif
173       return
174       end