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