-
Notifications
You must be signed in to change notification settings - Fork 18
/
phdos_module.f90
552 lines (481 loc) · 16.6 KB
/
phdos_module.f90
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
!
! Copyright (C) 2010 Quantum ESPRESSO group. Inspired to the fqha.f90
! routine of QE and to the programs in the QHA directory by
! Eyvaz Isaev, Department of Physics, Chemistry, and Biophysics (IFM),
! Linkoping University, Sweden.
! Theoretical Physics Department, Moscow State Institute of Steel and Alloys,
! Russia.
! Materials Theory Group, Institute of Physics and Materials Science,
! Uppsala University, Sweden.
!
!
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
MODULE phdos_module
!
! This module provide methods to read phonon dos files and to calculate
! their contribution to the free energy. It defines a type phdos that
! contains the phonon dos as a function of energy.
!
! USE kinds, ONLY : dp
!
USE kinds, ONLY : DP
USE constants, ONLY : k_boltzmann_ry, ry_to_cmm1
IMPLICIT NONE
SAVE
PRIVATE
REAL(DP), PARAMETER :: kb=k_boltzmann_ry ! Boltzmann constant in Ry/K
REAL(DP), PARAMETER :: kb1=1.0_DP/kb/ry_to_cmm1 ! inverse Boltzmann
! constant in K/cm^{-1}
REAL(DP), PARAMETER :: thr_ph=1.D-3 ! a phonon with frequency smaller than
! this is considered of zero frequency.
REAL(DP), PARAMETER :: thr_taylor=1.D-3 ! When the argument of the functions
! is smaller than this threshold use
! a Taylor expansion expression
! to avoid the numerical error due
! to the calculation of
! 1.0-(1.0-epsilon)
TYPE phdos_type
INTEGER :: number_of_points ! rhe number of points
REAL(DP) :: de ! interval of the mesh of frequencies (cm-1)
REAL(DP), ALLOCATABLE :: nu(:) ! the frequencies (cm-1)
REAL(DP), ALLOCATABLE :: phdos(:) ! the phdos (states/ cm-1)
END TYPE phdos_type
TYPE gen_phdos_type
INTEGER :: number_of_points ! the number of points
INTEGER :: nat ! the number of atoms
REAL(DP) :: de ! interval of the mesh of frequencies (cm-1)
REAL(DP), ALLOCATABLE :: nu(:) ! the frequencies (cm-1)
REAL(DP), ALLOCATABLE :: phdos(:,:,:) ! the generalized phdos (states/ cm-1)
END TYPE gen_phdos_type
PUBLIC :: phdos_type, read_phdos_data, zero_point_energy, free_energy, &
vib_energy, vib_entropy, specific_heat_cv, fecv, &
phdos_debye_factor, integrated_dos, set_phdos, destroy_phdos, &
find_minimum_maximum, gen_phdos_type, set_gen_phdos, &
read_genphdos_data, destroy_gen_phdos
CONTAINS
!--------------------------------------------------------------------
SUBROUTINE set_phdos(phdos,ndiv,deltanu)
!--------------------------------------------------------------------
IMPLICIT NONE
TYPE(phdos_type), INTENT(INOUT) :: phdos
INTEGER, INTENT(IN) :: ndiv
REAL(DP), INTENT(IN) :: deltanu
phdos%number_of_points=ndiv
phdos%de=deltanu
ALLOCATE(phdos%nu(ndiv))
ALLOCATE(phdos%phdos(ndiv))
RETURN
END SUBROUTINE set_phdos
!--------------------------------------------------------------------
SUBROUTINE set_gen_phdos(phdos,ndiv,nat,deltanu)
!--------------------------------------------------------------------
IMPLICIT NONE
TYPE(gen_phdos_type), INTENT(INOUT) :: phdos
INTEGER, INTENT(IN) :: ndiv, nat
REAL(DP), INTENT(IN) :: deltanu
phdos%number_of_points=ndiv
phdos%nat=nat
phdos%de=deltanu
ALLOCATE(phdos%nu(ndiv))
ALLOCATE(phdos%phdos(6,nat,ndiv))
RETURN
END SUBROUTINE set_gen_phdos
!--------------------------------------------------------------------
SUBROUTINE destroy_phdos(phdos)
!--------------------------------------------------------------------
IMPLICIT NONE
TYPE(phdos_type), INTENT(INOUT) :: phdos
IF (ALLOCATED(phdos%nu)) DEALLOCATE(phdos%nu)
IF (ALLOCATED(phdos%phdos)) DEALLOCATE(phdos%phdos)
RETURN
END SUBROUTINE destroy_phdos
!--------------------------------------------------------------------
SUBROUTINE destroy_gen_phdos(phdos)
!--------------------------------------------------------------------
IMPLICIT NONE
TYPE(gen_phdos_type), INTENT(INOUT) :: phdos
IF (ALLOCATED(phdos%nu)) DEALLOCATE(phdos%nu)
IF (ALLOCATED(phdos%phdos)) DEALLOCATE(phdos%phdos)
RETURN
END SUBROUTINE destroy_gen_phdos
!--------------------------------------------------------------------
SUBROUTINE read_phdos_data(phdos, filename)
!--------------------------------------------------------------------
!
! This subroutine reads the phdos from a file. It allocates space,
! opens and closes the phdos file.
!
USE mp_images, ONLY : intra_image_comm
USE io_global, ONLY : ionode_id, ionode, stdout
USE mp, ONLY : mp_bcast
IMPLICIT NONE
TYPE(phdos_type), INTENT(INOUT) :: phdos
CHARACTER(LEN=256), INTENT(IN) :: filename
INTEGER :: iunit, ios
INTEGER, PARAMETER :: ndivx=100000
REAL(DP), ALLOCATABLE :: nu(:), dos(:)
REAL(DP) :: de, de_
INTEGER :: i, ndiv
INTEGER :: find_free_unit
IF (ionode) THEN
iunit=find_free_unit()
OPEN(file=TRIM(filename), unit=iunit, status='old', &
form='formatted', err=100, iostat=ios)
ENDIF
100 CALL mp_bcast(ios, ionode_id, intra_image_comm)
IF (ios /= 0) CALL errore('read_phdos_data', &
'opening file'//TRIM(filename), ABS(ios))
ALLOCATE(nu(ndivx))
ALLOCATE(dos(ndivx))
de = 0d0
IF (ionode) THEN
DO i=1,ndivx
! nu(i) = frequencies (cm^{-1}), dos(i) in states/cm^{-1}
READ(iunit, *, END=20, ERR=10, IOSTAT=ios) nu(i),dos(i)
IF ( nu(i) < -1.d0 ) THEN
WRITE(stdout,*) i, nu(i), dos(i)
CALL errore('read_phdos_data','negative frequencies',1)
ELSE IF ( nu(i) < 0.d0 ) THEN
nu(i) = 0.d0
END IF
IF ( i ==2 ) de_ = nu(2) - nu(1)
IF (i > 2) THEN
de = nu(i) - nu(i-1)
IF ( ABS(de - de_) > 1.0d-4 ) &
CALL errore('read_phdos_data','nonuniform grid',1)
END IF
ndiv=i
ENDDO
10 IF (ios /= 0 ) CALL errore('read_phdos_data', 'problem reading phdos', 1)
20 continue
ENDIF
CALL mp_bcast(ndiv,ionode_id,intra_image_comm)
CALL mp_bcast(de,ionode_id,intra_image_comm)
CALL mp_bcast(nu,ionode_id,intra_image_comm)
CALL mp_bcast(dos,ionode_id,intra_image_comm)
phdos%number_of_points=ndiv
phdos%de=de
ALLOCATE(phdos%nu(ndiv))
ALLOCATE(phdos%phdos(ndiv))
phdos%nu(:) = nu(1:ndiv)
phdos%phdos(:) = dos(1:ndiv)
DEALLOCATE(nu)
DEALLOCATE(dos)
IF (ionode) CLOSE(iunit)
RETURN
END SUBROUTINE read_phdos_data
!--------------------------------------------------------------------
SUBROUTINE read_genphdos_data(phdos, nat, filename)
!--------------------------------------------------------------------
!
! This subroutine reads the phdos from a file. It allocates space,
! opens and closes the phdos file.
!
USE mp_images, ONLY : intra_image_comm
USE io_global, ONLY : ionode_id, ionode, stdout
USE mp, ONLY : mp_bcast
IMPLICIT NONE
INTEGER, INTENT(IN) :: nat
TYPE(gen_phdos_type), INTENT(INOUT) :: phdos
CHARACTER(LEN=256), INTENT(IN) :: filename
INTEGER :: iunit, ios
INTEGER, PARAMETER :: ndivx=100000
REAL(DP), ALLOCATABLE :: nu(:), dos(:,:,:)
REAL(DP) :: de, de_
INTEGER :: i, ijpol, na, ndiv
INTEGER :: find_free_unit
CHARACTER(LEN=256) :: filename_loc
CHARACTER(LEN=6) :: int_to_char
IF (ionode) iunit=find_free_unit()
ALLOCATE(nu(ndivx))
ALLOCATE(dos(6,nat,ndivx))
de = 0d0
DO na=1,nat
filename_loc=TRIM(filename)//'.'//TRIM(int_to_char(na))
IF (ionode) OPEN(FILE=TRIM(filename_loc), UNIT=iunit, STATUS='old', &
FORM='formatted', ERR=100, IOSTAT=ios)
100 CALL mp_bcast(ios, ionode_id, intra_image_comm)
IF (ios /= 0) CALL errore('read_phdos_data', &
'opening file'//TRIM(filename_loc), ABS(ios))
IF (ionode) THEN
DO i=1,ndivx
! nu(i) = frequencies (cm^{-1}), dos(i) in states/cm^{-1}
READ(iunit, *, END=20, ERR=10, IOSTAT=ios) nu(i), &
(dos(ijpol,na,i),ijpol=1,6)
ndiv=i
ENDDO
20 ios=0
ENDIF
10 CALL mp_bcast(ios, ionode_id, intra_image_comm)
IF (ios /= 0 ) CALL errore('read_genphdos_data', 'problem reading phdos', 1)
IF (ionode) CLOSE(iunit)
ENDDO
CALL mp_bcast(ndiv,ionode_id,intra_image_comm)
CALL mp_bcast(nu,ionode_id,intra_image_comm)
CALL mp_bcast(dos,ionode_id,intra_image_comm)
DO i=1,ndiv
IF ( nu(i) < -1.d0 ) THEN
WRITE(stdout,*) i, nu(i), dos(ijpol,1,i)
CALL errore('read_genphdos_data','negative frequencies',1)
ELSE IF ( nu(i) < 0.d0 ) THEN
nu(i) = 0.d0
END IF
IF ( i ==2 ) THEN
de_ = nu(2) - nu(1)
ELSEIF (i > 2) THEN
de = nu(i) - nu(i-1)
IF ( ABS(de - de_) > 1.0d-4 ) &
CALL errore('read_genphdos_data','nonuniform grid',1)
END IF
ENDDO
phdos%number_of_points=ndiv
phdos%de=de
ALLOCATE(phdos%nu(ndiv))
ALLOCATE(phdos%phdos(6,nat,ndiv))
phdos%nu(:) = nu(1:ndiv)
phdos%phdos(1:6,1:nat,1:ndiv) = dos(1:6,1:nat,1:ndiv)
DEALLOCATE(nu)
DEALLOCATE(dos)
RETURN
END SUBROUTINE read_genphdos_data
!--------------------------------------------------------------------
SUBROUTINE zero_point_energy(phdos, ener)
!--------------------------------------------------------------------
!
! This subroutine receives as input a phdos and computes the zero point
! energy that corresponds to that phdos. The output energy is in Ry.
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(OUT) :: ener
INTEGER :: ndiv
ndiv=phdos%number_of_points
ener = 0.5_DP * phdos%de*dot_product(phdos%phdos(1:ndiv),phdos%nu(1:ndiv))
! result is in cm^{-1}, bring it to Ry
ener = ener / ry_to_cmm1
RETURN
END SUBROUTINE zero_point_energy
!--------------------------------------------------------------------
SUBROUTINE free_energy(phdos, temp, ener)
!--------------------------------------------------------------------
!
! This routine receives as input a phdos and a temperature and gives as
! output the vibrational free energy at that temperature. ener contains
! only the vibrational contribution WITHOUT the zero point energy.
!
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(IN) :: temp
REAL(DP), INTENT(OUT) :: ener
INTEGER :: ndiv, i
REAL(DP) :: nu, arg, temp1, earg
ener=0.0_DP
IF (temp <= 1.E-9_DP) RETURN
temp1 = 1.0_DP / temp
ndiv=phdos%number_of_points
DO i=1,ndiv
nu=phdos%nu(i)
arg= kb1 * nu * temp1
earg = EXP( - arg )
IF (nu > 0.0_DP) &
ener = ener + phdos%phdos(i)* kb * temp * LOG( 1.0_DP - earg )
ENDDO
ener = ener*phdos%de
RETURN
END SUBROUTINE free_energy
!--------------------------------------------------------------------
SUBROUTINE vib_energy(phdos, temp, ener)
!--------------------------------------------------------------------
!
! This routine receives as input a phdos and a temperature and gives as
! output the vibrational energy at that temperature. ener contains
! the energy WITHOUT the zero point energy.
!
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(IN) :: temp
REAL(DP), INTENT(OUT) :: ener
INTEGER :: ndiv, i
REAL(DP) :: nu, temp1, arg, earg
ener=0.0_DP
IF (temp <= 1.E-9_DP) RETURN
temp1 = 1.0_DP / temp
ndiv=phdos%number_of_points
DO i=1,ndiv
nu=phdos%nu(i)
arg= kb1 * nu * temp1
earg = EXP( -arg )
IF (nu > 0.d0) ener = ener + phdos%phdos(i)* nu * earg/ &
( 1.0_DP - earg )
ENDDO
ener = ener * phdos%de / ry_to_cmm1
RETURN
END SUBROUTINE vib_energy
!--------------------------------------------------------------------
SUBROUTINE vib_entropy(phdos, temp, entr)
!--------------------------------------------------------------------
!
! This routine receives as input a phdos and a temperature and gives as
! output the vibrational entropy at that temperature.
!
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(IN) :: temp
REAL(DP), INTENT(OUT) :: entr
REAL(DP) :: ener, free_ener
CALL free_energy(phdos, temp, free_ener)
CALL vib_energy(phdos, temp, ener)
IF (temp > 0.0_DP) THEN
entr = ( ener - free_ener ) / temp
ELSE
entr = 0.0_DP
ENDIF
RETURN
END SUBROUTINE vib_entropy
!--------------------------------------------------------------------
SUBROUTINE specific_heat_cv(phdos, temp, cv)
!--------------------------------------------------------------------
!
! This routine receives as input a phdos and a temperature and gives as
! output the constant volume specific heat at that temperature.
! The output cv is in Ry / K.
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(IN) :: temp
REAL(DP), INTENT(OUT) :: cv
INTEGER :: ndiv, i
REAL(DP) :: nu, temp1, arg, earg
cv=0.0_DP
IF (temp <= 1.E-9_DP) RETURN
temp1 = 1.0_DP / temp
ndiv=phdos%number_of_points
DO i=1,ndiv
nu=phdos%nu(i)
arg= kb1 * nu * temp1
earg = EXP( - arg )
IF (nu > 0.d0 ) cv = cv + phdos%phdos(i) * earg * &
( arg / ( 1.0_DP - earg )) ** 2
ENDDO
cv = cv * phdos%de * kb
RETURN
END SUBROUTINE specific_heat_cv
!--------------------------------------------------------------------
SUBROUTINE fecv(phdos, temp, free_ener, ener, cv)
!--------------------------------------------------------------------
!
! This routine receives as input a phdos and a temperature and gives as
! output the vibrational free energy at that temperature. ener contains
! only the vibrational contribution WITHOUT the zero point energy.
!
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(IN) :: temp
REAL(DP), INTENT(OUT) :: free_ener, ener, cv
INTEGER :: ndiv, i
REAL(DP) :: nu, arg, temp1, earg, g
free_ener=0.0_DP
ener=0.0_DP
cv=0.0_DP
IF (temp <= 1.E-9_DP) RETURN
temp1 = 1.0_DP / temp
ndiv=phdos%number_of_points
DO i=1,ndiv
nu=phdos%nu(i)
g=phdos%phdos(i)
arg= kb1 * nu * temp1
earg = EXP( - arg )
IF (nu > 0.0_DP ) THEN
free_ener = free_ener + g * kb * temp * LOG( 1.0_DP - earg )
ener = ener + g * nu * earg / ( 1.0_DP - earg )
cv = cv + g * earg * ( arg / ( 1.0_DP - earg )) ** 2
ENDIF
ENDDO
free_ener = free_ener*phdos%de
ener = ener * phdos%de / ry_to_cmm1
cv = cv * phdos%de * kb
RETURN
END SUBROUTINE fecv
!--------------------------------------------------------------------
SUBROUTINE phdos_debye_factor(phdos, temp, b_fact, &
nat, amass, nsp, ityp)
!--------------------------------------------------------------------
!
USE constants, ONLY : h_planck_si, c_si, amu_si
IMPLICIT NONE
TYPE(gen_phdos_type), INTENT(IN) :: phdos
INTEGER :: nsp, nat, ityp(nat)
REAL(DP), INTENT(IN) :: temp, amass(nsp)
REAL(DP), INTENT(INOUT) :: b_fact(3,3,nat)
INTEGER :: ndiv, i, na, ipol, jpol, ijpol
REAL(DP) :: nu, g, temp1, arg, expt, fact, tfact
b_fact = 0.0_DP
IF (temp <= 1.E-9_DP) RETURN
temp1 = 1.0_DP / temp
ndiv = phdos%number_of_points
fact = 1.D20 * h_planck_si / c_si / 100.0_DP / amu_si
DO na=1,nat
ijpol=0
DO ipol=1,3
DO jpol=ipol,3
ijpol=ijpol+1
DO i=1,ndiv
nu = phdos%nu(i)
g = phdos%phdos(ijpol,na,i)
arg = kb1 * nu * temp1
IF (arg > thr_taylor) THEN
expt = EXP(-arg)
tfact = (1.0_DP+expt)/(1.0_DP-expt)
b_fact(ipol,jpol,na) = b_fact(ipol,jpol,na) + tfact * g / nu
ELSEIF (nu > thr_ph) THEN
b_fact(ipol,jpol,na) = b_fact(ipol,jpol,na) + (2.0_DP/arg &
+ arg/6.0_DP - arg**3/360.0_DP) * g / nu
ENDIF
ENDDO
IF (ipol/=jpol) b_fact(jpol,ipol,na)=b_fact(ipol,jpol,na)
ENDDO
ENDDO
b_fact(:,:,na) = b_fact(:,:,na) * fact * phdos%de / amass(ityp(na))
ENDDO
RETURN
END SUBROUTINE phdos_debye_factor
!--------------------------------------------------------------------
SUBROUTINE integrated_dos(phdos, tot_dos)
!--------------------------------------------------------------------
!
! This routine receives as input a phdos and a temperature and gives as
! output the vibrational energy at that temperature. ener contains
! the energy WITHOUT the zero point energy.
!
!
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(OUT) :: tot_dos
INTEGER :: ndiv, i
REAL(DP) :: nu
tot_dos=0.0_DP
ndiv=phdos%number_of_points
DO i=1,ndiv
nu=phdos%nu(i)
IF (nu > 0.d0) tot_dos = tot_dos + phdos%phdos(i)
ENDDO
tot_dos = tot_dos * phdos%de
RETURN
END SUBROUTINE integrated_dos
!--------------------------------------------------------------------
SUBROUTINE find_minimum_maximum(phdos, freqmin, freqmax)
!--------------------------------------------------------------------
!
! find the range of the phdos frequencies
!
IMPLICIT NONE
TYPE(phdos_type), INTENT(IN) :: phdos
REAL(DP), INTENT(OUT) :: freqmin, freqmax
INTEGER :: ndiv
ndiv=phdos%number_of_points
freqmin=phdos%nu(1)
freqmax=phdos%nu(ndiv)
RETURN
END SUBROUTINE find_minimum_maximum
END MODULE phdos_module