fetch_input.f90 24.7 KB
Newer Older
1
!
Marco Govoni's avatar
Marco Govoni committed
2
! Copyright (C) 2015-2019 M. Govoni 
3
! This file is distributed under the terms of the
Marco Govoni's avatar
Marco Govoni committed
4
! GNU General Public License. See the file License
5
6
7
8
9
10
11
12
13
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST.
!
! Contributors to this file: 
! Marco Govoni
!
!-----------------------------------------------------------------------
14
SUBROUTINE add_intput_parameters_to_json_file( num_drivers, driver, json )
Marco Govoni's avatar
Marco Govoni committed
15
16
17
18
19
20
21
22
23
24
  !-----------------------------------------------------------------------
  !
  USE json_module,      ONLY : json_file
  USE pwcom
  USE westcom
  USE io_files,         ONLY : tmp_dir, prefix
  USE io_global,        ONLY : stdout
  USE mp,               ONLY : mp_bcast
  USE mp_world,         ONLY : mpime,root,world_comm
  USE mp_global,        ONLY : nimage
25
  USE io_push,          ONLY : io_push_title,io_push_value,io_push_bar,io_push_es0,io_push_c512 
Marco Govoni's avatar
Marco Govoni committed
26
27
28
29
30
  !
  IMPLICIT NONE
  !
  ! I/O
  !
31
32
  INTEGER, INTENT(IN) :: num_drivers
  INTEGER, INTENT(IN) :: driver(num_drivers)
Marco Govoni's avatar
Marco Govoni committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  TYPE(json_file), INTENT(INOUT) :: json 
  !
  IF ( mpime == root ) THEN
     !
     IF ( ANY(driver(:)==1) ) THEN
        !
        CALL json%add('input.input_west.qe_prefix',TRIM(qe_prefix))
        CALL json%add('input.input_west.west_prefix',TRIM(west_prefix))
        CALL json%add('input.input_west.outdir',TRIM(outdir))
        !
     ENDIF
     !
     IF ( ANY(driver(:)==2) ) THEN
        !
        CALL json%add('input.wstat_control.wstat_calculation',TRIM(wstat_calculation))
        CALL json%add('input.wstat_control.n_pdep_eigen',n_pdep_eigen)
        CALL json%add('input.wstat_control.n_pdep_times',n_pdep_times)
        CALL json%add('input.wstat_control.n_pdep_maxiter',n_pdep_maxiter)
        CALL json%add('input.wstat_control.n_dfpt_maxiter',n_dfpt_maxiter)
        CALL json%add('input.wstat_control.n_pdep_read_from_file',n_pdep_read_from_file)
        CALL json%add('input.wstat_control.trev_pdep',trev_pdep)
        CALL json%add('input.wstat_control.trev_pdep_rel',trev_pdep_rel)
        CALL json%add('input.wstat_control.tr2_dfpt',tr2_dfpt)
        CALL json%add('input.wstat_control.l_kinetic_only',l_kinetic_only)
        CALL json%add('input.wstat_control.l_minimize_exx_if_active',l_minimize_exx_if_active)
        CALL json%add('input.wstat_control.l_use_ecutrho',l_use_ecutrho)
Marco Govoni's avatar
Marco Govoni committed
59
        CALL json%add('input.wstat_control.qlist', qlist) 
Marco Govoni's avatar
Marco Govoni committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        !
     ENDIF
     !
     IF ( ANY(driver(:)==3) ) THEN
        !
        CALL json%add('input.wfreq_control.wfreq_calculation',TRIM(wfreq_calculation))
        CALL json%add('input.wfreq_control.n_pdep_eigen_to_use',n_pdep_eigen_to_use)
        CALL json%add('input.wfreq_control.qp_bandrange',qp_bandrange)
        CALL json%add('input.wfreq_control.macropol_calculation',macropol_calculation)
        CALL json%add('input.wfreq_control.n_lanczos',n_lanczos)
        CALL json%add('input.wfreq_control.n_imfreq',n_imfreq)
        CALL json%add('input.wfreq_control.n_refreq',n_refreq)
        CALL json%add('input.wfreq_control.ecut_imfreq',ecut_imfreq)
        CALL json%add('input.wfreq_control.ecut_refreq',ecut_refreq)
        CALL json%add('input.wfreq_control.wfreq_eta',wfreq_eta)
        CALL json%add('input.wfreq_control.n_secant_maxiter',n_secant_maxiter)
        CALL json%add('input.wfreq_control.trev_secant',trev_secant)
        CALL json%add('input.wfreq_control.l_enable_lanczos',l_enable_lanczos)
        CALL json%add('input.wfreq_control.l_enable_gwetot',l_enable_gwetot)
        CALL json%add('input.wfreq_control.o_restart_time',o_restart_time)
        CALL json%add('input.wfreq_control.ecut_spectralf',ecut_spectralf)
        CALL json%add('input.wfreq_control.n_spectralf',n_spectralf)
        !
     ENDIF
     !
     IF ( ANY(driver(:)==4) ) THEN
        !
        CALL json%add('input.westpp_control.westpp_calculation',TRIM(westpp_calculation))
        CALL json%add('input.westpp_control.westpp_range',westpp_range)
        CALL json%add('input.westpp_control.westpp_format',TRIM(westpp_format))
        CALL json%add('input.westpp_control.westpp_sign',westpp_sign)
        CALL json%add('input.westpp_control.westpp_n_pdep_eigen_to_use',westpp_n_pdep_eigen_to_use)
        CALL json%add('input.westpp_control.westpp_r0',westpp_r0)
        CALL json%add('input.westpp_control.westpp_nr',westpp_nr)
        CALL json%add('input.westpp_control.westpp_rmax',westpp_rmax)
        CALL json%add('input.westpp_control.westpp_epsinfty',westpp_epsinfty)
        !
     ENDIF
     !
Marco Govoni's avatar
Marco Govoni committed
99
100
101
102
103
104
     IF ( ANY(driver(:)==5) ) THEN
        !
        CALL json%add('input.server_control.document',TRIM(document))
        !
     ENDIF
     !
Marco Govoni's avatar
Marco Govoni committed
105
106
107
  ENDIF
  !
END SUBROUTINE
Marco Govoni's avatar
Marco Govoni committed
108
109


Marco Govoni's avatar
Marco Govoni committed
110
SUBROUTINE fetch_input_yml( num_drivers, driver, verbose, debug )
Marco Govoni's avatar
Marco Govoni committed
111
112
113
114
115
116
117
118
119
120
121
122
  !
  USE west_version, ONLY : start_forpy, end_forpy
  USE io_push,      ONLY : io_push_title,io_push_value,io_push_bar,io_push_es0,io_push_c512 
  USE forpy_mod,    ONLY: call_py, call_py_noret, import_py, module_py
  USE forpy_mod,    ONLY: tuple, tuple_create 
  USE forpy_mod,    ONLY: dict, dict_create 
  USE forpy_mod,    ONLY: list, list_create 
  USE forpy_mod,    ONLY: object, cast
  USE forpy_mod,    ONLY : exception_matches, KeyError, err_clear, err_print 
  USE westcom
  USE io_files,         ONLY : tmp_dir, prefix
  USE io_global,        ONLY : stdout
Marco Govoni's avatar
Marco Govoni committed
123
  USE mp,               ONLY : mp_bcast, mp_barrier
Marco Govoni's avatar
Marco Govoni committed
124
125
126
127
128
129
  USE mp_world,         ONLY : mpime,root,world_comm
  USE mp_global,        ONLY : nimage
  USE gvect,            ONLY : ecutrho
  USE start_k,          ONLY : nk1, nk2, nk3
  USE control_flags,    ONLY : gamma_only
  USE json_module,      ONLY : json_file
Marco Govoni's avatar
Marco Govoni committed
130
  USE pwcom,            ONLY : nelec
Marco Govoni's avatar
Marco Govoni committed
131
132
133
134
135
136
137
  !
  IMPLICIT NONE 
  !
  ! I/O
  !
  INTEGER, INTENT(IN) :: num_drivers
  INTEGER, INTENT(IN) :: driver(num_drivers)
Marco Govoni's avatar
Marco Govoni committed
138
139
  LOGICAL, INTENT(IN) :: verbose
  LOGICAL, INTENT(IN) :: debug
Marco Govoni's avatar
Marco Govoni committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  !
  INTEGER :: IERR
  TYPE(tuple) :: args
  TYPE(dict) :: kwargs
  TYPE(module_py) :: pymod
  TYPE(object) :: return_obj, tmp_obj
  TYPE(dict) :: return_dict
  TYPE(list) :: tmp_list
  INTEGER :: list_len
  INTEGER :: i
  INTEGER :: nq
  INTEGER :: numsp 
  CHARACTER(LEN=512), EXTERNAL :: trimcheck
  CHARACTER(LEN=:),ALLOCATABLE :: cvalue
  TYPE(json_file) :: json
Marco Govoni's avatar
Marco Govoni committed
155
  INTEGER :: iunit, lenc
Marco Govoni's avatar
Marco Govoni committed
156
  !
Marco Govoni's avatar
Marco Govoni committed
157
158
159
160
  CALL start_clock('fetch_input')
  !
  IF ( mpime==root ) THEN 
     ! 
Marco Govoni's avatar
Marco Govoni committed
161
     IERR = import_py(pymod, "west_fetch_input")
Marco Govoni's avatar
Marco Govoni committed
162
163
164
     !
     IF ( ANY(driver(:)==1) ) THEN 
        !  
Marco Govoni's avatar
Marco Govoni committed
165
        IERR = tuple_create(args, 3)
Marco Govoni's avatar
Marco Govoni committed
166
        IERR = args%setitem(0, TRIM(ADJUSTL(main_input_file)) )
Marco Govoni's avatar
Marco Govoni committed
167
        IERR = args%setitem(1, "input_west" )
Marco Govoni's avatar
Marco Govoni committed
168
        IERR = args%setitem(2, verbose )
Marco Govoni's avatar
Marco Govoni committed
169
170
        IERR = dict_create(kwargs)
        !
Marco Govoni's avatar
Marco Govoni committed
171
        IERR = call_py(return_obj, pymod, "read_keyword_from_file", args, kwargs)
Marco Govoni's avatar
Marco Govoni committed
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
        IERR = cast(return_dict, return_obj)
        !
        CALL args%destroy
        CALL kwargs%destroy
        CALL return_obj%destroy
        !
        IERR = return_dict%getitem(cvalue, "qe_prefix"); qe_prefix = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(cvalue, "west_prefix"); west_prefix = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(cvalue, "outdir"); outdir = TRIM(ADJUSTL(cvalue))
        !
        CALL return_dict%destroy
        !
     ENDIF
     !
     IF ( ANY(driver(:)==2) ) THEN
        !
        IF ( gamma_only ) THEN
           nq = 1 
        ELSE
           nq = nk1*nk2*nk3
        ENDIF
        !  
Marco Govoni's avatar
Marco Govoni committed
194
        IERR = tuple_create(args, 3)
Marco Govoni's avatar
Marco Govoni committed
195
        IERR = args%setitem(0, TRIM(ADJUSTL(main_input_file)) )
Marco Govoni's avatar
Marco Govoni committed
196
        IERR = args%setitem(1, "wstat_control" )
Marco Govoni's avatar
Marco Govoni committed
197
        IERR = args%setitem(2, verbose )
Marco Govoni's avatar
Marco Govoni committed
198
        IERR = dict_create(kwargs)
Marco Govoni's avatar
Marco Govoni committed
199
        IERR = kwargs%setitem("nq",nq)
Marco Govoni's avatar
Marco Govoni committed
200
        IERR = kwargs%setitem("nelec",nelec)
Marco Govoni's avatar
Marco Govoni committed
201
        !
Marco Govoni's avatar
Marco Govoni committed
202
        IERR = call_py(return_obj, pymod, "read_keyword_from_file", args, kwargs)
Marco Govoni's avatar
Marco Govoni committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
        IERR = cast(return_dict, return_obj)
        !
        CALL args%destroy
        CALL kwargs%destroy
        CALL return_obj%destroy
        !
        IERR = return_dict%getitem(cvalue, "wstat_calculation"); wstat_calculation = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(n_pdep_eigen, "n_pdep_eigen")
        IERR = return_dict%getitem(n_pdep_times, "n_pdep_times")
        IERR = return_dict%getitem(n_pdep_maxiter, "n_pdep_maxiter")
        IERR = return_dict%getitem(n_dfpt_maxiter, "n_dfpt_maxiter")
        IERR = return_dict%getitem(n_pdep_read_from_file, "n_pdep_read_from_file")
        IERR = return_dict%getitem(trev_pdep, "trev_pdep")
        IERR = return_dict%getitem(trev_pdep_rel, "trev_pdep_rel")
        IERR = return_dict%getitem(tr2_dfpt, "tr2_dfpt")
        IERR = return_dict%getitem(l_kinetic_only, "l_kinetic_only")
        IERR = return_dict%getitem(l_minimize_exx_if_active, "l_minimize_exx_if_active")
        IERR = return_dict%getitem(l_use_ecutrho, "l_use_ecutrho")
        IERR = return_dict%getitem(tmp_obj, "qlist")
        IERR = cast(tmp_list,tmp_obj)
        IERR = tmp_list%len(list_len)
        IF( ALLOCATED(qlist) ) DEALLOCATE(qlist)
        ALLOCATE(qlist(list_len))
        DO i = 0, list_len-1 ! Python indices start at 0
           IERR = tmp_list%getitem(qlist(i+1), i) ! Fortran indices start at 1 
        ENDDO
Marco Govoni's avatar
Marco Govoni committed
229
230
        CALL tmp_list%destroy
        CALL tmp_obj%destroy
Marco Govoni's avatar
Marco Govoni committed
231
232
        !
        CALL return_dict%destroy
Marco Govoni's avatar
Marco Govoni committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
        !
     ENDIF
     !
     IF ( ANY(driver(:)==3) ) THEN
        !  
        IERR = tuple_create(args, 3)
        IERR = args%setitem(0, TRIM(ADJUSTL(main_input_file)) )
        IERR = args%setitem(1, "wfreq_control" )
        IERR = args%setitem(2, verbose )
        IERR = dict_create(kwargs)
        IERR = kwargs%setitem("nelec",nelec)
        IERR = kwargs%setitem("ecutrho",ecutrho)
        !
        IERR = call_py(return_obj, pymod, "read_keyword_from_file", args, kwargs)
        IERR = cast(return_dict, return_obj)
        !
        CALL args%destroy
        CALL kwargs%destroy
        CALL return_obj%destroy
        !
        IERR = return_dict%getitem(cvalue, "wfreq_calculation"); wfreq_calculation = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(n_pdep_eigen_to_use, "n_pdep_eigen_to_use")
        IERR = return_dict%getitem(tmp_obj, "qp_bandrange")
        IERR = cast(tmp_list,tmp_obj)
        IERR = tmp_list%len(list_len)
        IERR = tmp_list%getitem(qp_bandrange(1), 0) ! Fortran indices start at 1 
        IERR = tmp_list%getitem(qp_bandrange(2), 1) ! Fortran indices start at 1 
        CALL tmp_list%destroy 
Marco Govoni's avatar
Marco Govoni committed
261
        CALL tmp_obj%destroy
Marco Govoni's avatar
Marco Govoni committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
        IERR = return_dict%getitem(cvalue, "macropol_calculation"); macropol_calculation = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(n_lanczos, "n_lanczos")
        IERR = return_dict%getitem(n_imfreq, "n_imfreq")
        IERR = return_dict%getitem(n_refreq, "n_refreq")
        IERR = return_dict%getitem(ecut_imfreq, "ecut_imfreq")
        IERR = return_dict%getitem(ecut_refreq, "ecut_refreq")
        IERR = return_dict%getitem(wfreq_eta, "wfreq_eta")
        IERR = return_dict%getitem(n_secant_maxiter, "n_secant_maxiter")
        IERR = return_dict%getitem(trev_secant, "trev_secant")
        IERR = return_dict%getitem(l_enable_lanczos, "l_enable_lanczos")
        IERR = return_dict%getitem(l_enable_gwetot, "l_enable_gwetot")
        IERR = return_dict%getitem(o_restart_time, "o_restart_time")
        IERR = return_dict%getitem(tmp_obj, "ecut_spectralf")
        IERR = cast(tmp_list,tmp_obj)
        IERR = tmp_list%getitem(ecut_spectralf(1), 0) ! Fortran indices start at 1 
        IERR = tmp_list%getitem(ecut_spectralf(2), 1) ! Fortran indices start at 1 
        CALL tmp_list%destroy 
        CALL tmp_obj%destroy 
        IERR = return_dict%getitem(n_spectralf, "n_spectralf")
        !
        CALL return_dict%destroy
        !
     ENDIF
     !
     IF ( ANY(driver(:)==4) ) THEN
        !  
        IERR = tuple_create(args, 3)
        IERR = args%setitem(0, TRIM(ADJUSTL(main_input_file)) )
        IERR = args%setitem(1, "westpp_control" )
        IERR = args%setitem(2, verbose )
        IERR = dict_create(kwargs)
        !
        IERR = call_py(return_obj, pymod, "read_keyword_from_file", args, kwargs)
        IERR = cast(return_dict, return_obj)
        !
        CALL args%destroy
        CALL kwargs%destroy
        CALL return_obj%destroy
        !
        IERR = return_dict%getitem(cvalue, "westpp_calculation"); westpp_calculation = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(tmp_obj, "westpp_range")
        IERR = cast(tmp_list,tmp_obj)
        IERR = tmp_list%getitem(westpp_range(1), 0) ! Fortran indices start at 1 
        IERR = tmp_list%getitem(westpp_range(2), 1) ! Fortran indices start at 1 
        CALL tmp_list%destroy 
        CALL tmp_obj%destroy 
        IERR = return_dict%getitem(cvalue, "westpp_format"); westpp_format = TRIM(ADJUSTL(cvalue))
        IERR = return_dict%getitem(westpp_sign, "westpp_sign")
        IERR = return_dict%getitem(westpp_n_pdep_eigen_to_use, "westpp_n_pdep_eigen_to_use")
        IERR = return_dict%getitem(tmp_obj, "westpp_r0")
        IERR = cast(tmp_list,tmp_obj)
        IERR = tmp_list%getitem(westpp_r0(1), 0) ! Fortran indices start at 1 
        IERR = tmp_list%getitem(westpp_r0(2), 1) ! Fortran indices start at 1 
        IERR = tmp_list%getitem(westpp_r0(3), 2) ! Fortran indices start at 1 
        CALL tmp_list%destroy 
        CALL tmp_obj%destroy 
        IERR = return_dict%getitem(westpp_nr, "westpp_nr")
        IERR = return_dict%getitem(westpp_rmax, "westpp_rmax")
        IERR = return_dict%getitem(westpp_epsinfty, "westpp_epsinfty")
        !
        CALL return_dict%destroy
Marco Govoni's avatar
Marco Govoni committed
323
324
325
        !
     ENDIF
     !
Marco Govoni's avatar
Marco Govoni committed
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
     IF ( ANY(driver(:)==5) ) THEN
        !  
        IERR = tuple_create(args, 3)
        IERR = args%setitem(0, TRIM(ADJUSTL(main_input_file)) )
        IERR = args%setitem(1, "server_control" )
        IERR = args%setitem(2, verbose )
        IERR = dict_create(kwargs)
        !
        IERR = call_py(return_obj, pymod, "read_keyword_from_file", args, kwargs)
        IERR = cast(return_dict, return_obj)
        !
        CALL args%destroy
        CALL kwargs%destroy
        CALL return_obj%destroy
        !
        IERR = return_dict%getitem(cvalue, "document"); document = TRIM(ADJUSTL(cvalue))
        !
        CALL return_dict%destroy
        !
     ENDIF
     !
Marco Govoni's avatar
Marco Govoni committed
347
348
     CALL pymod%destroy
     !
Marco Govoni's avatar
Marco Govoni committed
349
     !
Marco Govoni's avatar
Marco Govoni committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
  ENDIF
  !
  ! BCAST & CHECKS
  !
  IF ( ANY(driver(:)==1) ) THEN
     !
     CALL mp_bcast(qe_prefix,root,world_comm); prefix=qe_prefix
     CALL mp_bcast(west_prefix,root,world_comm)
     CALL mp_bcast(outdir,root,world_comm); tmp_dir = trimcheck (outdir)
     !
  ENDIF
  !
  IF ( ANY(driver(:)==2) ) THEN
     !
     CALL mp_bcast(wstat_calculation,root,world_comm)
     CALL mp_bcast(n_pdep_eigen,root,world_comm)
     CALL mp_bcast(n_pdep_times,root,world_comm)
     CALL mp_bcast(n_pdep_maxiter,root,world_comm)
     CALL mp_bcast(n_dfpt_maxiter,root,world_comm)
     CALL mp_bcast(n_pdep_read_from_file,root,world_comm)
     CALL mp_bcast(trev_pdep,root,world_comm)
     CALL mp_bcast(trev_pdep_rel,root,world_comm)
     CALL mp_bcast(tr2_dfpt,root,world_comm)
     CALL mp_bcast(l_kinetic_only,root,world_comm)
     CALL mp_bcast(l_minimize_exx_if_active,root,world_comm)
     CALL mp_bcast(l_use_ecutrho,root,world_comm)
     IF(mpime == root) nq = SIZE(qlist)
     CALL mp_bcast(nq,root,world_comm)
     IF(mpime /= root) THEN 
        IF( ALLOCATED(qlist) ) DEALLOCATE(qlist)
        ALLOCATE(qlist(nq))
     ENDIF  
     CALL mp_bcast(qlist,root,world_comm)
     !
     ! CHECKS 
     !
     IF( n_pdep_times < 2 ) CALL errore('fetch_input','Err: n_pdep_times<2',1) 
     IF( n_pdep_eigen < 1 ) CALL errore('fetch_input','Err: n_pdep_eigen<1',1)
     IF( n_pdep_eigen*n_pdep_times < nimage ) CALL errore('fetch_input','Err: n_pdep_eigen*n_pdep_times<nimage',1) 
     IF( n_pdep_maxiter < 1 ) CALL errore('fetch_input','Err: n_pdep_maxiter<1',1) 
     IF( n_dfpt_maxiter < 1 ) CALL errore('fetch_input','Err: n_dfpt_maxiter<1',1) 
     IF( n_pdep_read_from_file < 0 ) CALL errore('fetch_input','Err: n_pdep_read_from_file<0',1) 
     IF( n_pdep_read_from_file > n_pdep_eigen ) CALL errore('fetch_input','Err: n_pdep_read_from_file>n_pdep_eigen',1) 
     IF(tr2_dfpt<=0._DP) CALL errore('fetch_input','Err: tr2_dfpt<0.',1)
     IF(trev_pdep<=0._DP) CALL errore('fetch_input','Err: trev_pdep<0.',1)
     IF(trev_pdep_rel<=0._DP) CALL errore('fetch_input','Err: trev_pdep_rel<0.',1)
     IF(gamma_only) THEN
        IF (SIZE(qlist)/=1) CALL errore('fetch_input','Err: SIZE(qlist)/=1.',1)
     ELSE 
        IF (SIZE(qlist)>nk1*nk2*nk3) CALL errore('fetch_input','Err: SIZE(qlist)>nk1*nk2*nk3.',1)
     ENDIF
     !
  ENDIF
  !
Marco Govoni's avatar
Marco Govoni committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
  IF ( ANY(driver(:)==3) ) THEN
     !
     CALL mp_bcast(wfreq_calculation,root,world_comm)
     CALL mp_bcast(n_pdep_eigen_to_use,root,world_comm)
     CALL mp_bcast(qp_bandrange,root,world_comm)
     CALL mp_bcast(macropol_calculation,root,world_comm)
     CALL mp_bcast(n_lanczos,root,world_comm)
     CALL mp_bcast(n_imfreq,root,world_comm)
     CALL mp_bcast(n_refreq,root,world_comm)
     CALL mp_bcast(ecut_imfreq,root,world_comm)
     CALL mp_bcast(ecut_refreq,root,world_comm)
     CALL mp_bcast(wfreq_eta,root,world_comm)
     CALL mp_bcast(n_secant_maxiter,root,world_comm)
     CALL mp_bcast(trev_secant,root,world_comm)
     CALL mp_bcast(l_enable_lanczos,root,world_comm)
     CALL mp_bcast(l_enable_gwetot,root,world_comm)
     CALL mp_bcast(o_restart_time,root,world_comm)
     CALL mp_bcast(ecut_spectralf,root,world_comm)
     CALL mp_bcast(n_spectralf,root,world_comm)
     !
     ! CHECKS 
     !
     IF( n_lanczos < 2 ) CALL errore('fetch_input','Err: n_lanczos<2',1) 
     IF( n_pdep_eigen_to_use < 1 ) CALL errore('fetch_input','Err: n_pdep_eigen_to_use<1',1) 
     IF( n_pdep_eigen_to_use > n_pdep_eigen ) CALL errore('fetch_input','Err: n_pdep_eigen_to_use>n_pdep_eigen',1) 
     IF( n_imfreq < 1 ) CALL errore('fetch_input','Err: n_imfreq<1',1) 
     IF( n_refreq < 1 ) CALL errore('fetch_input','Err: n_refreq<1',1) 
     IF( n_spectralf < 2 ) CALL errore('fetch_input','Err: n_spectralf<1',1) 
     IF( qp_bandrange(1) < 1 ) CALL errore('fetch_input','Err: qp_bandrange(1)<1',1) 
     IF( qp_bandrange(2) < 1 ) CALL errore('fetch_input','Err: qp_bandrange(2)<1',1) 
     IF( qp_bandrange(2) < qp_bandrange(1) ) CALL errore('fetch_input','Err: qp_bandrange(2)<qp_bandrange(1)',1) 
     IF( ecut_imfreq<=0._DP) CALL errore('fetch_input','Err: ecut_imfreq<0.',1)
     IF( ecut_refreq<=0._DP) CALL errore('fetch_input','Err: ecut_imfreq<0.',1)
     IF( ecut_spectralf(2)<ecut_spectralf(1)) CALL errore('fetch_input','Err: ecut_spectralf(2)<ecut_spectralf(1)',1)
     IF( wfreq_eta<=0._DP) CALL errore('fetch_input','Err: wfreq_eta<0.',1)
     IF( n_secant_maxiter < 0 ) CALL errore('fetch_input','Err: n_secant_maxiter<0',1) 
     IF( trev_secant<=0._DP) CALL errore('fetch_input','Err: trev_secant<0.',1)
     SELECT CASE(macropol_calculation) 
     CASE('N','n','C','c')
     CASE DEFAULT
        CALL errore('fetch_input','Err: macropol_calculation /= (N,C)',1)
     END SELECT
     !
  ENDIF
  !
  IF ( ANY(driver(:)==4) ) THEN
     !
     CALL mp_bcast(westpp_calculation,root,world_comm)
     CALL mp_bcast(westpp_range,root,world_comm)
     CALL mp_bcast(westpp_format,root,world_comm)
     CALL mp_bcast(westpp_sign,root,world_comm)
     CALL mp_bcast(westpp_n_pdep_eigen_to_use,root,world_comm)
     CALL mp_bcast(westpp_r0,root,world_comm)
     CALL mp_bcast(westpp_nr,root,world_comm)
     CALL mp_bcast(westpp_rmax,root,world_comm)
     CALL mp_bcast(westpp_epsinfty,root,world_comm)
     !
     ! CHECKS 
     !
     IF( westpp_range(1) < 1 ) CALL errore('fetch_input','Err: westpp_range(1)<1',1)
     IF( westpp_range(2) < 1 ) CALL errore('fetch_input','Err: westpp_range(2)<1',1)
     IF( westpp_range(2) < westpp_range(1) ) CALL errore('fetch_input','Err: westpp_range(2)<westpp_range(1)',1)
     IF( westpp_nr < 1 ) CALL errore('fetch_input','Err: westpp_nr<1',1)
     IF( westpp_n_pdep_eigen_to_use < 1 ) CALL errore('fetch_input','Err: westpp_n_pdep_eigen_to_use<1',1)
     IF( westpp_rmax < 0.d0 ) CALL errore('fetch_input','Err: westpp_rmax<0',1)
     IF( westpp_epsinfty < 1.d0 ) CALL errore('fetch_input','Err: westpp_epsinfty<1',1)
     !
  ENDIF
  !
Marco Govoni's avatar
Marco Govoni committed
473
474
475
476
477
478
479
480
481
  IF ( ANY(driver(:)==5) ) THEN
     !
     lenc = LEN(document)
     CALL mp_bcast(lenc,root,world_comm)
     IF(mpime/=root) ALLOCATE(CHARACTER(LEN=lenc) :: document)
     CALL mp_bcast(document,root,world_comm)
     !
  ENDIF
  !
Marco Govoni's avatar
Marco Govoni committed
482
483
  CALL mp_barrier(world_comm)
  !
Marco Govoni's avatar
Marco Govoni committed
484
485
  ! REPORT
  !
Marco Govoni's avatar
Marco Govoni committed
486
  IF ( debug .AND. mpime == root ) THEN
Marco Govoni's avatar
Marco Govoni committed
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
     !
     IF ( ANY(driver(:)==1) ) THEN
        !
        ! REPORT
        !
        CALL io_push_title("I/O Summary : input_west")
        !
        numsp = 14
        CALL io_push_c512('qe_prefix',qe_prefix,numsp)
        CALL io_push_c512('west_prefix',west_prefix,numsp)
        CALL io_push_c512('outdir',outdir,numsp)
        !
        CALL io_push_bar()
        !
     ENDIF
     !
     IF ( ANY(driver(:)==2) ) THEN
        !
        ! REPORT
        !
        CALL io_push_title('I/O Summary : wstat_control')
        !
        numsp=30
        CALL io_push_value('wstat_calculation',wstat_calculation,numsp)
        CALL io_push_value('n_pdep_eigen',n_pdep_eigen,numsp)
        CALL io_push_value('n_pdep_times',n_pdep_times,numsp)
        CALL io_push_value('n_pdep_maxiter',n_pdep_maxiter,numsp)
        CALL io_push_value('n_dfpt_maxiter',n_dfpt_maxiter,numsp)
        CALL io_push_value('n_pdep_read_from_file',n_pdep_read_from_file,numsp)
        CALL io_push_es0('trev_pdep',trev_pdep,numsp)
        CALL io_push_es0('trev_pdep_rel',trev_pdep_rel,numsp)
        CALL io_push_es0('tr2_dfpt',tr2_dfpt,numsp)
        CALL io_push_value('l_kinetic_only',l_kinetic_only,numsp)
        CALL io_push_value('l_minimize_exx_if_active',l_minimize_exx_if_active,numsp)
        CALL io_push_value('l_use_ecutrho',l_use_ecutrho,numsp)
        DO i = 1, SIZE(qlist) 
           CALL io_push_value('qlist',qlist(i),numsp)
        ENDDO
        !
        CALL io_push_bar()
        !
     ENDIF
     !
     IF ( ANY(driver(:)==3) ) THEN
        !
        ! REPORT
        !
        CALL io_push_title('I/O Summary : wfreq_control')
        !
        numsp=40
        CALL io_push_value('wfreq_calculation',wfreq_calculation,numsp)
        CALL io_push_value('n_pdep_eigen_to_use',n_pdep_eigen_to_use,numsp)
        CALL io_push_value('qp_bandrange(1)',qp_bandrange(1),numsp)
        CALL io_push_value('qp_bandrange(2)',qp_bandrange(2),numsp)
        CALL io_push_value('macropol_calculation',macropol_calculation,numsp)
        CALL io_push_value('n_lanczos',n_lanczos,numsp)
        CALL io_push_value('n_imfreq',n_imfreq,numsp)
        CALL io_push_value('n_refreq',n_refreq,numsp)
        CALL io_push_value('ecut_imfreq [Ry]',ecut_imfreq,numsp)
        CALL io_push_value('ecut_refreq [Ry]',ecut_refreq,numsp)
        CALL io_push_value('wfreq_eta [Ry]',wfreq_eta,numsp)
        CALL io_push_value('n_secant_maxiter',n_secant_maxiter,numsp)
        CALL io_push_value('trev_secant [Ry]',trev_secant,numsp)
        CALL io_push_value('l_enable_lanczos',l_enable_lanczos,numsp)
        CALL io_push_value('l_enable_gwetot',l_enable_gwetot,numsp)
        CALL io_push_value('o_restart_time [min]',o_restart_time,numsp)
        CALL io_push_value('ecut_spectralf(1) [Ry]',ecut_spectralf(1),numsp)
        CALL io_push_value('ecut_spectralf(2) [Ry]',ecut_spectralf(2),numsp)
        CALL io_push_value('n_spectralf',n_spectralf,numsp)
        !
        CALL io_push_bar()
        !
     ENDIF
     !
     IF ( ANY(driver(:)==4) ) THEN
        !
        ! REPORT
        !
        CALL io_push_title('I/O Summary : westpp_control')
        !
        numsp=40
        CALL io_push_value('westpp_calculation',westpp_calculation,numsp)
        CALL io_push_value('westpp_range(1)',westpp_range(1),numsp)
        CALL io_push_value('westpp_range(2)',westpp_range(2),numsp)
        CALL io_push_value('westpp_format',westpp_format,numsp)
        CALL io_push_value('westpp_sign',westpp_sign,numsp)
        CALL io_push_value('westpp_n_pdep_eigen_to_use',westpp_n_pdep_eigen_to_use,numsp)
        CALL io_push_value('westpp_r0(1)',westpp_r0(1),numsp)
        CALL io_push_value('westpp_r0(2)',westpp_r0(2),numsp)
        CALL io_push_value('westpp_r0(3)',westpp_r0(3),numsp)
        CALL io_push_value('westpp_nr',westpp_nr,numsp)
        CALL io_push_value('westpp_rmax',westpp_rmax,numsp)
        CALL io_push_value('westpp_epsinfty',westpp_epsinfty,numsp)
        !
        CALL io_push_bar()
        !
     ENDIF
     !
Marco Govoni's avatar
Marco Govoni committed
585
586
587
588
589
590
591
592
593
594
595
596
597
     IF ( ANY(driver(:)==5) ) THEN
        !
        ! REPORT
        !
        CALL io_push_title('I/O Summary : server_control')
        !
        numsp=40
        CALL io_push_value('document',document,numsp)
        !
        CALL io_push_bar()
        !
     ENDIF
     !
Marco Govoni's avatar
Marco Govoni committed
598
599
  ENDIF
  !
Marco Govoni's avatar
Marco Govoni committed
600
  IF ( verbose .AND. mpime == root ) THEN
Marco Govoni's avatar
Marco Govoni committed
601
602
603
604
605
606
607
608
609
610
     !
     CALL json%initialize()
     CALL json%load_file(filename=TRIM(logfile))
     !
     CALL add_intput_parameters_to_json_file( num_drivers, driver, json )
     ! 
     OPEN( NEWUNIT=iunit, FILE=TRIM(logfile) )
     CALL json%print_file( iunit )
     CLOSE( iunit )
     CALL json%destroy()
Marco Govoni's avatar
Marco Govoni committed
611
     !
Marco Govoni's avatar
Marco Govoni committed
612
     !
Marco Govoni's avatar
Marco Govoni committed
613
614
615
616
617
  ENDIF
  !
  CALL stop_clock('fetch_input')
  !
END SUBROUTINE