pwdft  0.1
PW-DFT code for education
stdin.F90
Go to the documentation of this file.
1 !
2 ! Copyright (c) 2018 Mitsuaki Kawamura
3 !
4 ! Permission is hereby granted, free of charge, to any person obtaining a
5 ! copy of this software and associated documentation files (the
6 ! "Software"), to deal in the Software without restriction, including
7 ! without limitation the rights to use, copy, modify, merge, publish,
8 ! distribute, sublicense, and/or sell copies of the Software, and to
9 ! permit persons to whom the Software is furnished to do so, subject to
10 ! the following conditions:
11 !
12 ! The above copyright notice and this permission notice shall be included
13 ! in all copies or substantial portions of the Software.
14 !
15 ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 ! OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ! CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ! TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ! SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 !
23 module stdin
24  !
25  implicit none
26  !
27 contains
28  !
29  subroutine read_stdin()
30  !
31  use constant, only : bohr2ang, pi, htr2ev
32  use kohn_sham, only : calculation, nbnd
34  use k_point, only : nk, kvec, kgrd
35  use atm_spec, only : atm, spec, avec, nat, ntyp, bvec, vcell
36  use gvec, only : g_rh, g_wf, setup_gvec
37  !
38  integer :: iat, jtyp, ii, jj, lwork = 3, ipiv(3), &
39  & info, i1, i2, i3, nn, ik
40  real(8) :: work(3), ecutrho, ecutwfc
41  character(256) :: key
42  !
43  namelist/control/ calculation
44  namelist/system/ nat, ntyp, ecutwfc, ecutrho, nbnd
45  namelist/electrons/ electron_maxstep, conv_thr, mixing_beta
46  !
47  read(*,control)
48  !
49  write(*,*) " calculation : ", trim(calculation)
50  !
51  nbnd = 0
52  !
53  read(*,system)
54  !
55  write(*,*) " Number of atoms : ", nat
56  write(*,*) " Number of species : ", ntyp
57  write(*,*) " Plane-wave cutoff (wfc) [Ry] : ", ecutwfc
58  write(*,*) " Plane-wave cutoff (rho,V) [Ry] : ", ecutrho
59  !
60  allocate(atm(nat), spec(ntyp))
61  !
62  electron_maxstep = 100
63  conv_thr = 1.0d-10
64  mixing_beta = 0.3d0
65  !
66  read(*,electrons)
67  !
68  write(*,*) " Max iteration : ", electron_maxstep
69  write(*,*) " Convergence threshold : ", conv_thr
70  write(*,*) " Initial mixing : ", mixing_beta
71  !
73  !
74  do jj = 1, 4
75  !
76  read(*,*) key
77  !
78  if(key == "ATOMIC_SPECIES") then
79  !
80  write(*,*) " Atomic species :"
81  !
82  do jtyp = 1, ntyp
83  read(*,*) spec(jtyp)%elem, spec(jtyp)%ps_file
84  write(*,*) jtyp, trim(spec(jtyp)%elem), " ", trim(spec(jtyp)%ps_file)
85  end do
86  !
87  else if(key == "ATOMIC_POSITIONS") then
88  !
89  do iat = 1, nat
90  read(*,*) atm(iat)%elem, atm(iat)%pos(1:3)
91  end do
92  !
93  else if(key == "K_POINTS") then
94  !
95  if(calculation == "bands") then
96  read(*,*) nn
97  nk = 10*(nn-1)+1
98  allocate(kvec(3,nk))
99  read(*,*) kvec(1:3,1)
100  do ii = 1, nn - 1
101  read(*,*) kvec(1:3,10*ii+1)
102  do ik = 2, 10
103  kvec(1:3,10*(ii-1)+ik) &
104  & = kvec(1:3,10*(ii-1)+1) * dble(11-ik)/10.0d0 &
105  & + kvec(1:3,10* ii +1) * dble(ik-1)/10.0d0
106  end do
107  end do
108  else if (calculation == "direct" .or. calculation == "iterative") then
109  read(*,*) nk
110  allocate(kvec(3,nk))
111  read(*,*) kvec(1:3,1:nk)
112  else
113  read(*,*) kgrd(1:3)
114  nk = product(kgrd(1:3))
115  allocate(kvec(3,nk))
116  nk = 0
117  do i3 = 0, kgrd(3) - 1
118  do i2 = 0, kgrd(2) - 1
119  do i1 = 0, kgrd(1) - 1
120  nk = nk + 1
121  kvec(1:3,nk) = dble(modulo((/i1,i2,i3/)+kgrd(1:3)/2,kgrd(1:3)) &
122  & -kgrd(1:3)/2) &
123  & / dble(kgrd(1:3))
124  end do
125  end do
126  end do
127  end if
128  !
129  write(*,*) " Number of k : ", nk
130  !
131  else if(key == "CELL_PARAMETERS") then
132  !
133  read(*,*) avec(1:3,1:3)
134  avec(1:3,1:3) = avec(1:3,1:3) / bohr2ang
135  write(*,*) " Cell parameters [Bohr] :"
136  !
137  do ii = 1, 3
138  write(*,*) " ", avec(1:3,ii)
139  end do
140  vcell = (avec(2,1)*avec(3,2) - avec(3,1)*avec(2,2)) * avec(1,3) &
141  & + (avec(3,1)*avec(1,2) - avec(1,1)*avec(3,2)) * avec(2,3) &
142  & + (avec(1,1)*avec(2,2) - avec(2,1)*avec(1,2)) * avec(3,3)
143  vcell = abs(vcell)
144  write(*,*) " Cell volume [Bohr^3] :", vcell
145  !
146  ! Reciprocal lattice vectors
147  !
148  bvec(1:3,1:3) = transpose(avec(1:3,1:3))
149  call dgetrf(3, 3, bvec, 3, ipiv, info)
150  call dgetri(3, bvec, 3, ipiv, work, lwork, info)
151  if(info /= 0) stop 'read_stdin : inverce of avec.'
152  bvec(1:3,1:3) = 2.0d0 * pi * bvec(1:3,1:3)
153  write(*,*) " Reciplocal lattice vector [Bohr^-1] :"
154  do ii = 1, 3
155  write(*,*) " ", bvec(1:3,ii)
156  end do
157  !
158  end if
159  !
160  end do
161  kvec(1:3,1:nk) = matmul(bvec(1:3,1:3), kvec(1:3,1:nk))
162  !
163  write(*,*) " Atomic position"
164  !
165  do iat = 1, nat
166  !
167  do jtyp = 1, ntyp
168  if(trim(spec(jtyp)%elem) == trim(atm(iat)%elem)) then
169  atm(iat)%ityp = jtyp
170  exit
171  end if
172  end do
173  !
174  write(*,*) iat, trim(atm(iat)%elem), atm(iat)%ityp, atm(iat)%pos(1:3)
175  !
176  end do
177  !
178  write(*,*) " FFT and G-vector for wfc"
179  call setup_gvec(g_wf, ecutwfc)
180  write(*,*) " FFT and G-vector for rho and V"
181  call setup_gvec(g_rh, ecutrho)
182  !
183  end subroutine read_stdin
184  !
185 end module stdin
atm_spec::spec
type(spec_t), dimension(:), allocatable, save spec
(ntyp) Species
Definition: atm_spec.F90:57
atm_spec::vcell
real(8), save vcell
Unit cell volume [Bohr^3].
Definition: atm_spec.F90:50
atm_spec::avec
real(8), dimension(3, 3), save avec
Unit lattice vector [Bohr].
Definition: atm_spec.F90:50
constant
Definition: constant.F90:23
kohn_sham::calculation
character(256), save calculation
Calculation mode.
Definition: kohn_sham.F90:27
gvec::g_wf
type(fft), save g_wf
Definition: gvec.F90:38
atm_spec::ntyp
integer, save ntyp
Number of species (elements)
Definition: atm_spec.F90:47
constant::pi
real(8), parameter pi
Definition: constant.F90:25
k_point
Definition: k_point.F90:23
atm_spec::atm
type(atm_t), dimension(:), allocatable, save atm
(nat) Atom
Definition: atm_spec.F90:55
gvec
Definition: gvec.F90:23
scf::mixing_beta
real(8), save mixing_beta
Mixing for SCF.
Definition: scf.F90:29
kohn_sham::nbnd
integer, save nbnd
Number of bands.
Definition: kohn_sham.F90:29
k_point::nk
integer, save nk
Definition: k_point.F90:27
k_point::kgrd
integer, dimension(3), save kgrd
Definition: k_point.F90:28
gvec::setup_gvec
subroutine setup_gvec(xfft, g2cut)
Definition: gvec.F90:43
stdin::read_stdin
subroutine read_stdin()
Definition: stdin.F90:30
gvec::g_rh
type(fft), save g_rh
Definition: gvec.F90:37
atm_spec::nat
integer, save nat
Number of atoms.
Definition: atm_spec.F90:47
scf
Definition: scf.F90:23
scf::electron_maxstep
integer, save electron_maxstep
Max number of iteration.
Definition: scf.F90:27
constant::htr2ev
real(8), parameter htr2ev
Definition: constant.F90:27
atm_spec::bvec
real(8), dimension(3, 3), save bvec
Unit reciplocal lattice vector [Bohr^-1].
Definition: atm_spec.F90:50
scf::conv_thr
real(8), save conv_thr
Convergence threshold [Htr].
Definition: scf.F90:29
k_point::kvec
real(8), dimension(:,:), allocatable, save kvec
Definition: k_point.F90:30
atm_spec
Definition: atm_spec.F90:23
constant::bohr2ang
real(8), parameter bohr2ang
Definition: constant.F90:26
kohn_sham
Definition: kohn_sham.F90:23
stdin
Definition: stdin.F90:23