forked from lgcrego/Dynemol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.f
623 lines (467 loc) · 21.8 KB
/
backup.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
59
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
229
230
231
232
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
261
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
module Backup_m
use MPI
use type_m
use blas95
use MPI_definitions_m , only : master , EnvCrew
use parameters_m , only : driver , &
QMMM , &
nuclear_matter , &
EnvField_ , &
DP_Moment , &
Coulomb_ , &
restart , n_part
use Solvated_M , only : Prepare_Solvated_System
use Babel_m , only : Coords_from_Universe , &
trj
use Structure_Builder , only : Generate_Structure , &
Basis_Builder
use tuning_m , only : orbital , &
eh_tag
use QCModel_Huckel , only : EigenSystem
use Dielectric_Potential , only : Environment_SetUp
use TD_Dipole_m , only : wavepacket_DP
use DP_main_m , only : Dipole_Matrix
use MM_dynamics_m , only : preprocess_MM , &
Saving_MM_Backup
use Data_Output , only : Net_Charge
public :: Security_Copy , Restart_State , Restart_Sys
interface Security_Copy
module procedure Security_Copy_Eigen
module procedure Security_Copy_Cheb
module procedure Security_Copy_CSDM
end interface
interface Restart_State
module procedure Restart_State_Eigen
module procedure Restart_State_Cheb
module procedure Restart_State_CSDM
end interface
interface Restart_Sys
module procedure Restart_Sys_Eigen
module procedure Restart_Sys_Cheb
end interface
contains
!
!
!
!======================================================================================================================
subroutine Restart_Sys_Eigen( Extended_Cell , ExCell_basis , Unit_Cell , DUAL_ket , AO_bra , AO_ket , frame , UNI_el )
!======================================================================================================================
implicit none
type(structure) , intent(out) :: Extended_Cell
type(STO_basis) , allocatable , intent(out) :: ExCell_basis(:)
type(structure) , intent(inout) :: Unit_Cell
complex*16 , intent(in) :: DUAL_ket (:,:)
complex*16 , intent(in) :: AO_bra (:,:)
complex*16 , intent(in) :: AO_ket (:,:)
integer , intent(in) :: frame
type(R_eigen) , intent(out) :: UNI_el
! local variables ...
type(universe) :: Solvated_System
select case ( nuclear_matter )
case( "solvated_sys" )
CALL Prepare_Solvated_System( Solvated_System , frame )
CALL Coords_from_Universe( Unit_Cell , Solvated_System )
case( "extended_sys" )
CALL Coords_from_Universe( Unit_Cell , trj(frame) )
case( "MDynamics" )
! MM preprocess ...
CALL preprocess_MM( Net_Charge = Net_Charge )
case default
Print*, " >>> Check your nuclear_matter options <<< :" , nuclear_matter
stop
end select
CALL Generate_Structure( frame )
CALL Basis_Builder( Extended_Cell , ExCell_basis )
if( EnvField_ .AND. (master .OR. EnvCrew) ) then
CALL Dipole_Matrix ( Extended_Cell , ExCell_basis )
! wavepacket component of the dipole vector ...
! decide what to do with this ############
If( .false. ) CALL wavepacket_DP ( Extended_Cell , ExCell_basis , AO_bra , AO_ket , Dual_ket )
CALL Environment_SetUp ( Extended_Cell )
end If
! KernelCrew and ForceCrew: only calculate S_matrix and return;
! EnvCrew: follow to even_more_extended_Huckel ...
CALL EigenSystem( Extended_Cell , ExCell_basis , UNI_el )
end subroutine Restart_Sys_Eigen
!
!
!
!=========================================================================================================
subroutine Security_Copy_Eigen( MO_bra , MO_ket , DUAL_bra , DUAL_ket , AO_bra , AO_ket , t , it , frame )
!=========================================================================================================
implicit none
complex*16 , intent(in) :: MO_bra (:,:)
complex*16 , intent(in) :: MO_ket (:,:)
complex*16 , intent(in) :: DUAL_bra (:,:)
complex*16 , intent(in) :: DUAL_ket (:,:)
complex*16 , intent(in) :: AO_bra (:,:)
complex*16 , intent(in) :: AO_ket (:,:)
real*8 , intent(in) :: t
integer , intent(in) :: it
integer , optional , intent(in) :: frame
! local variables ...
integer :: i , j , basis_size
logical , save :: first_time = .true.
logical :: exist
real :: start_time, end_time
call CPU_TIME(start_time)
write( * , 230 , advance='no' ) it , frame , t
! check whether restart conditions are properly set ...
If( first_time ) then
If( restart ) then
inquire( file=dynemolworkdir//"Security_copy.dat", EXIST=exist )
If( exist ) stop " <Security_copy.dat> exists; check restart parameter or move Security_copy.dat to Restart_copy.dat"
else
inquire( file=dynemolworkdir//"Restart_copy.dat", EXIST=exist )
If( exist ) stop " <Restart_copy.dat> exists; check restart parameter or delete Restart_copy.dat"
end If
! get rid of Restart_copy.dat for new Security_copy.dat ...
inquire( file=dynemolworkdir//"Restart_copy.dat", EXIST=exist )
If( exist ) CALL system( "rm Restart_copy.dat" )
first_time = .false.
end If
if( nuclear_matter == "MDynamics" ) CALL Saving_MM_Backup( frame , instance = "from_QM" )
open(unit=33, file="ancillary.trunk/Security_copy.dat", status="unknown", form="unformatted", action="write")
if( present(frame) ) write(33) frame
write(33) it
write(33) t
write(33) size(MO_bra(:,1))
write(33) size(MO_bra(1,:))
write(33) size(eh_tag)
basis_size = size(MO_bra(:,1))
write(33) ( orbital(i) , eh_tag(i) , i=1,n_part )
do j = 1 , n_part
write(33) ( MO_bra(i,j) , MO_ket (i,j) , i=1,basis_size )
write(33) ( DUAL_bra(i,j) , DUAL_ket (i,j) , i=1,basis_size )
write(33) ( AO_bra(i,j) , AO_ket (i,j) , i=1,basis_size )
end do
write(33) ( Net_Charge , i=1,size(Net_Charge) )
close( 33 )
Print*, 'DONE <<<'
call CPU_TIME(end_time)
print *, 'Total Security_Copy execution time: ', end_time - start_time, ' seconds'
include 'formats.h'
end subroutine Security_Copy_Eigen
!
!
!
!=========================================================================================================
subroutine Restart_State_Eigen( MO_bra , MO_ket , DUAL_bra , DUAL_ket , AO_bra , AO_ket , t , it , frame )
!=========================================================================================================
implicit none
complex*16 , allocatable , intent(out) :: MO_bra (:,:)
complex*16 , allocatable , intent(out) :: MO_ket (:,:)
complex*16 , allocatable , intent(out) :: DUAL_bra (:,:)
complex*16 , allocatable , intent(out) :: DUAL_ket (:,:)
complex*16 , allocatable , intent(out) :: AO_bra (:,:)
complex*16 , allocatable , intent(out) :: AO_ket (:,:)
real*8 , intent(out) :: t
integer , intent(out) :: it
integer , optional , intent(out) :: frame
! local variables ...
integer :: i , j , size_r , size_c , file_err , size_eh_tag
open(unit=33, file="Restart_copy.dat", form="unformatted", status="old", action="read" , iostat=file_err , err=11 )
if( present(frame) ) read(33) frame
read(33) it
read(33) t
read(33) size_r
read(33) size_c
read(33) size_eh_tag
allocate( MO_bra ( size_r , size_c ) )
allocate( MO_ket ( size_r , size_c ) )
allocate( DUAL_bra ( size_r , size_c ) )
allocate( DUAL_ket ( size_r , size_c ) )
allocate( AO_bra ( size_r , size_c ) )
allocate( AO_ket ( size_r , size_c ) )
if( .NOT. allocated( orbital) ) allocate( orbital(size_eh_tag) )
if( .NOT. allocated( eh_tag ) ) allocate( eh_tag(size_eh_tag) )
read(33) ( orbital(i) , eh_tag(i) , i=1,size_eh_tag )
do j = 1 , size_c
read(33) ( MO_bra(i,j) , MO_ket (i,j) , i=1,size_r )
read(33) ( DUAL_bra(i,j) , DUAL_ket (i,j) , i=1,size_r )
read(33) ( AO_bra(i,j) , AO_ket (i,j) , i=1,size_r )
end do
read(33) ( Net_Charge , i=1,size(Net_Charge) )
close( 33 )
11 if( file_err > 0 ) then
CALL warning("<Restart_copy.dat> file not found; terminating execution")
stop
endif
end subroutine Restart_State_Eigen
!
!
!
!================= Chebyshev Routines =====================
!
!
!
!============================================================================================================
subroutine Restart_Sys_Cheb( Extended_Cell , ExCell_basis , Unit_Cell , DUAL_ket , AO_bra , AO_ket , frame )
!============================================================================================================
implicit none
type(structure) , intent(out) :: Extended_Cell
type(STO_basis) , allocatable , intent(out) :: ExCell_basis(:)
type(structure) , intent(inout) :: Unit_Cell
complex*16 , intent(in) :: DUAL_ket (:,:)
complex*16 , intent(in) :: AO_bra (:,:)
complex*16 , intent(in) :: AO_ket (:,:)
integer , intent(in) :: frame
! local variables ...
type(universe) :: Solvated_System
select case ( nuclear_matter )
case( "solvated_sys" )
CALL Prepare_Solvated_System( Solvated_System , frame )
CALL Coords_from_Universe( Unit_Cell , Solvated_System )
case( "extended_sys" )
CALL Coords_from_Universe( Unit_Cell , trj(frame) )
case( "MDynamics" )
! MM preprocess ...
CALL preprocess_MM( Net_Charge = Net_Charge )
case default
Print*, " >>> Check your nuclear_matter options <<< :" , nuclear_matter
stop
end select
CALL Generate_Structure ( frame )
CALL Basis_Builder ( Extended_Cell , ExCell_basis )
if( EnvField_ ) then
CALL Dipole_Matrix ( Extended_Cell , ExCell_basis )
! wavepacket component of the dipole vector ...
! decide what to do with this ############
If( .false. ) CALL wavepacket_DP ( Extended_Cell , ExCell_basis , AO_bra , AO_ket , Dual_ket )
CALL Environment_SetUp ( Extended_Cell )
end If
end subroutine Restart_Sys_Cheb
!
!
!
!=======================================================================================
subroutine Security_Copy_Cheb( Dual_bra , Dual_ket , AO_bra , AO_ket , t , it , frame )
!=======================================================================================
implicit none
complex*16 , intent(in) :: DUAL_bra (:,:)
complex*16 , intent(in) :: DUAL_ket (:,:)
complex*16 , intent(in) :: AO_bra (:,:)
complex*16 , intent(in) :: AO_ket (:,:)
real*8 , intent(in) :: t
integer , intent(in) :: it
integer , optional , intent(in) :: frame
! local variables ...
integer :: i , j , basis_size
logical , save :: first_time = .true.
logical :: exist
real :: start_time, end_time
call CPU_TIME(start_time)
write( * , 230 , advance='no' ) it , frame , t
! check whether restart conditions are properly set ...
If( first_time ) then
If( restart ) then
inquire( file=dynemolworkdir//"Security_copy.dat", EXIST=exist )
If( exist ) stop " <Security_copy.dat> exists; check restart parameter or move Security_copy.dat to Restart_copy.dat"
else
inquire( file=dynemolworkdir//"Restart_copy.dat", EXIST=exist )
If( exist ) stop " <Restart_copy.dat> exists; check restart parameter or delete Restart_copy.dat"
end If
! get rid of Restart_copy.dat for new Security_copy.dat ...
inquire( file=dynemolworkdir//"Restart_copy.dat", EXIST=exist )
If( exist ) CALL system( "rm Restart_copy.dat" )
first_time = .false.
end If
if( nuclear_matter == "MDynamics" ) CALL Saving_MM_Backup( frame , instance = "from_QM" )
open(unit=33, file="ancillary.trunk/Security_copy.dat", status="unknown", form="unformatted", action="write")
if( present(frame) ) write(33) frame
write(33) it
write(33) t
write(33) size(AO_bra(:,1))
write(33) size(AO_bra(1,:))
write(33) size(eh_tag)
basis_size = size(AO_bra(:,1))
write(33) ( eh_tag(i) , i=1,n_part )
do j = 1 , n_part
write(33) ( DUAL_bra(i,j) , DUAL_ket (i,j) , i=1,basis_size )
write(33) ( AO_bra(i,j) , AO_ket (i,j) , i=1,basis_size )
end do
write(33) ( Net_Charge , i=1,size(Net_Charge) )
close( 33 )
Print*, 'DONE <<<'
call CPU_TIME(end_time)
print *, 'Total Security_Copy execution time: ', end_time - start_time, ' seconds'
include 'formats.h'
end subroutine Security_Copy_Cheb
!
!
!
!======================================================================================
subroutine Restart_State_Cheb( DUAL_bra , DUAL_ket , AO_bra , AO_ket , t , it , frame )
!======================================================================================
implicit none
complex*16 , allocatable , intent(out) :: DUAL_bra (:,:)
complex*16 , allocatable , intent(out) :: DUAL_ket (:,:)
complex*16 , allocatable , intent(out) :: AO_bra (:,:)
complex*16 , allocatable , intent(out) :: AO_ket (:,:)
real*8 , intent(out) :: t
integer , intent(out) :: it
integer , optional , intent(out) :: frame
! local variables ...
integer :: i , j , size_r , size_c , file_err , size_eh_tag
open(unit=33, file="Restart_copy.dat", form="unformatted", status="old", action="read" , iostat=file_err , err=11 )
if( present(frame) ) read(33) frame
read(33) it
read(33) t
read(33) size_r
read(33) size_c
read(33) size_eh_tag
allocate( DUAL_bra ( size_r , size_c ) )
allocate( DUAL_ket ( size_r , size_c ) )
allocate( AO_bra ( size_r , size_c ) )
allocate( AO_ket ( size_r , size_c ) )
if( .NOT. allocated( eh_tag ) ) allocate( eh_tag(size_eh_tag) )
read(33) ( eh_tag(i) , i=1,size_eh_tag )
do j = 1 , size_c
read(33) ( DUAL_bra(i,j) , DUAL_ket (i,j) , i=1,size_r )
read(33) ( AO_bra(i,j) , AO_ket (i,j) , i=1,size_r )
end do
read(33) ( Net_Charge , i=1,size(Net_Charge) )
close( 33 )
11 if( file_err > 0 ) then
CALL warning("<Restart_copy.dat> file not found; terminating execution")
stop
endif
end subroutine Restart_State_Cheb
!
!
!
!
!================= CSDM Routines =====================
!
!
!
!
!=============================================================================================================================================
subroutine Security_Copy_CSDM &
( MO_bra , MO_ket , MO_TDSE_bra , MO_TDSE_ket , DUAL_bra , DUAL_ket , DUAL_TDSE_bra , DUAL_TDSE_ket , AO_bra , AO_ket , PST , t , it , frame )
!=============================================================================================================================================
implicit none
complex*16 , intent(in) :: MO_bra (:,:)
complex*16 , intent(in) :: MO_ket (:,:)
complex*16 , intent(in) :: MO_TDSE_bra (:,:)
complex*16 , intent(in) :: MO_TDSE_ket (:,:)
complex*16 , intent(in) :: DUAL_bra (:,:)
complex*16 , intent(in) :: DUAL_ket (:,:)
complex*16 , intent(in) :: DUAL_TDSE_bra (:,:)
complex*16 , intent(in) :: DUAL_TDSE_ket (:,:)
complex*16 , intent(in) :: AO_bra (:,:)
complex*16 , intent(in) :: AO_ket (:,:)
integer , intent(in) :: PST(2)
real*8 , intent(in) :: t
integer , intent(in) :: it
integer , intent(in) :: frame
! local variables ...
integer :: i , j , basis_size
logical , save :: first_time = .true.
logical :: exist
real :: start_time, end_time
call CPU_TIME(start_time)
write( * , 230 , advance='no' ) it , frame , t , end_time - start_time
! check whether restart conditions are properly set ...
If( first_time ) then
If( restart ) then
inquire( file=dynemolworkdir//"Security_copy.dat", EXIST=exist )
If( exist ) stop " <Security_copy.dat> exists; check restart parameter or move Security_copy.dat to Restart_copy.dat"
else
inquire( file=dynemolworkdir//"Restart_copy.dat", EXIST=exist )
If( exist ) stop " <Restart_copy.dat> exists; check restart parameter or delete Restart_copy.dat"
end If
! get rid of Restart_copy.dat for new Security_copy.dat ...
inquire( file=dynemolworkdir//"Restart_copy.dat", EXIST=exist )
If( exist ) CALL system( "rm Restart_copy.dat" )
first_time = .false.
end If
CALL Saving_MM_Backup( frame , instance = "from_QM" )
open(unit=33, file="ancillary.trunk/Security_copy.dat", status="unknown", form="unformatted", action="write")
write(33) frame
write(33) it
write(33) t
write(33) PST
write(33) size(MO_bra(:,1))
write(33) size(MO_bra(1,:))
write(33) size(eh_tag)
basis_size = size(MO_bra(:,1))
write(33) ( orbital(i) , eh_tag(i) , i=1,n_part )
do j = 1 , n_part
write(33) ( MO_bra(i,j) , MO_ket (i,j) , i=1,basis_size )
write(33) ( MO_TDSE_bra(i,j) , MO_TDSE_ket (i,j) , i=1,basis_size )
write(33) ( DUAL_bra(i,j) , DUAL_ket (i,j) , i=1,basis_size )
write(33) ( DUAL_TDSE_bra(i,j) , DUAL_TDSE_ket (i,j) , i=1,basis_size )
write(33) ( AO_bra(i,j) , AO_ket (i,j) , i=1,basis_size )
end do
write(33) ( Net_Charge , i=1,size(Net_Charge) )
close( 33 )
Print*, 'DONE <<<'
call CPU_TIME(end_time)
print *, 'Total Security_Copy execution time: ', end_time - start_time, ' seconds'
include 'formats.h'
end subroutine Security_Copy_CSDM
!
!
!
!=============================================================================================================================================
subroutine Restart_State_CSDM &
( MO_bra , MO_ket , MO_TDSE_bra , MO_TDSE_ket , DUAL_bra , DUAL_ket , DUAL_TDSE_bra , DUAL_TDSE_ket , AO_bra , AO_ket , PST , t , it , frame )
!=============================================================================================================================================
implicit none
complex*16 , allocatable , intent(out) :: MO_bra (:,:)
complex*16 , allocatable , intent(out) :: MO_ket (:,:)
complex*16 , allocatable , intent(out) :: MO_TDSE_bra (:,:)
complex*16 , allocatable , intent(out) :: MO_TDSE_ket (:,:)
complex*16 , allocatable , intent(out) :: DUAL_bra (:,:)
complex*16 , allocatable , intent(out) :: DUAL_ket (:,:)
complex*16 , allocatable , intent(out) :: DUAL_TDSE_bra (:,:)
complex*16 , allocatable , intent(out) :: DUAL_TDSE_ket (:,:)
complex*16 , allocatable , intent(out) :: AO_bra (:,:)
complex*16 , allocatable , intent(out) :: AO_ket (:,:)
integer , intent(out) :: PST(2)
real*8 , intent(out) :: t
integer , intent(out) :: it
integer , intent(out) :: frame
! local variables ...
integer :: i , j , size_r , size_c , file_err , size_eh_tag
open(unit=33, file="Restart_copy.dat", form="unformatted", status="old", action="read" , iostat=file_err , err=11 )
read(33) frame
read(33) it
read(33) t
read(33) PST
read(33) size_r
read(33) size_c
read(33) size_eh_tag
allocate( MO_bra ( size_r , size_c ) )
allocate( MO_ket ( size_r , size_c ) )
allocate( MO_TDSE_bra ( size_r , size_c ) )
allocate( MO_TDSE_ket ( size_r , size_c ) )
allocate( DUAL_bra ( size_r , size_c ) )
allocate( DUAL_ket ( size_r , size_c ) )
allocate( DUAL_TDSE_bra ( size_r , size_c ) )
allocate( DUAL_TDSE_ket ( size_r , size_c ) )
allocate( AO_bra ( size_r , size_c ) )
allocate( AO_ket ( size_r , size_c ) )
if( .NOT. allocated( orbital) ) allocate( orbital(size_eh_tag) )
if( .NOT. allocated( eh_tag ) ) allocate( eh_tag(size_eh_tag) )
read(33) ( orbital(i) , eh_tag(i) , i=1,size_eh_tag )
do j = 1 , size_c
read(33) ( MO_bra(i,j) , MO_ket(i,j) , i=1,size_r )
read(33) ( MO_TDSE_bra(i,j) , MO_TDSE_ket(i,j) , i=1,size_r )
read(33) ( DUAL_bra(i,j) , DUAL_ket(i,j) , i=1,size_r )
read(33) ( DUAL_TDSE_bra(i,j) , DUAL_TDSE_ket(i,j) , i=1,size_r )
read(33) ( AO_bra(i,j) , AO_ket(i,j) , i=1,size_r )
end do
read(33) ( Net_Charge , i=1,size(Net_Charge) )
close( 33 )
11 if( file_err > 0 ) then
CALL warning("<Restart_copy.dat> file not found; terminating execution")
stop
endif
end subroutine Restart_State_CSDM
!
!
!
!
end module Backup_m