8
8
! Use of this software constitutes agreement with the full conditions
9
9
! given in the SIESTA license, as signed by all legitimate users.
11
subroutine ofc(fa, dx, na)
11
subroutine ofc(fa, dx, na, has_constr, first)
12
12
C *******************************************************************
13
13
C Writes force constants matrix to file
14
14
C Input forces are in Ry/Bohr and input displacements are in Bohr.
17
17
C Dynamic memory and save attribute for fres introduced by J.Gale
19
19
C Re-structured by Alberto Garcia, April 2007
20
C Added constrained by Nick Papior, June 2015
20
21
C ********* INPUT ***************************************************
21
22
C real*8 fa(3,na) : atomic forces (in Ry / Bohr)
22
23
C real*8 dx : atomic displacements (in Bohr)
23
24
C integer na : number of atoms
25
c logical has_constr : whether the forces are constrained or not
26
c logical first : first call (initializes the force)
24
27
C ********** BEHAVIOUR **********************************************
25
28
C On the first call (undisplaced coordinates), the forces should be
26
29
C zero (relaxed structure).
40
integer, intent(in) :: na
41
real(dp), intent(in) :: dx, fa(3,na)
43
integer, intent(in) :: na
44
real(dp), intent(in) :: dx, fa(3,na)
45
logical, intent(in) :: has_constr, first
43
47
external io_assign, io_close
45
49
C Saved variables and arrays
46
character(len=label_length+3), save :: fname
47
logical, save :: frstme = .true.
48
real(dp), dimension(:,:), pointer, save :: fres
50
integer :: i, ix, unit1
55
fname = trim(slabel) // '.FC'
57
call re_alloc( fres, 1, 3, 1, na, name='fres', routine='ofc' )
60
open( unit1, file=fname, status='unknown' )
62
write(unit1,'(a)') 'Force constants matrix'
50
character(len=label_length+4) :: fname
51
real(dp), dimension(:,:,:), pointer, save :: fres => null()
52
real(dp), dimension(:,:), pointer :: fr
57
if ( .not. associated(fres) ) then
58
call re_alloc( fres, 1, 3, 1, na, 1, 2,
59
& name='fres', routine='ofc' )
62
if ( has_constr ) then
63
fname = trim(slabel) // '.FCC'
70
open( unit1, file=fname, status='old',position="append",
73
write(unit1,'(3f15.7)') ((-fa(ix,i)+fres(ix,i))*
74
. Ang**2/eV/dx, ix=1,3)
66
fname = trim(slabel) // '.FC'
73
open( iu, file=fname, status='unknown' )
76
if ( has_constr ) then
77
write(iu,'(a)') 'Force constants matrix (constrained)'
79
write(iu,'(a)') 'Force constants matrix'
84
! Copy over the residual (zero point) forces
87
! We should not save anything now
93
open( iu, file=fname, status='old',position="append",
96
tmp = Ang ** 2 / eV / dx
98
write(iu,'(3f15.7)') ((-fa(ix,i)+fr(ix,i))*tmp,ix=1,3)