The Elk Code
readspecies.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2002-2008 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine readspecies
7 use modmain
8 implicit none
9 ! local variables
10 integer is,ist,ios
11 integer nlx,ilx,lx,ilo
12 integer io,jo,ko,l,i,j
13 e0min=0.d0
14 do is=1,nspecies
15  open(50,file=trim(sppath)//trim(spfname(is)),status='OLD',form='FORMATTED', &
16  action='READ',iostat=ios)
17  if (ios /= 0) then
18  write(*,*)
19  write(*,'("Error(readspecies): error opening species file ",A)') &
20  trim(sppath)//trim(spfname(is))
21  write(*,*)
22  stop
23  end if
24  read(50,*) spsymb(is)
25  read(50,*) spname(is)
26  read(50,*) spzn(is)
27  read(50,*) spmass(is)
28  read(50,*) rminsp(is),rmt(is),rmaxsp(is),nrmt(is)
29  if (rminsp(is) <= 0.d0) then
30  write(*,*)
31  write(*,'("Error(readspecies): rminsp <= 0 : ",G18.10)') rminsp(is)
32  write(*,'(" for species ",I0)') is
33  write(*,*)
34  stop
35  end if
36  if (rmt(is) <= rminsp(is)) then
37  write(*,*)
38  write(*,'("Error(readspecies): rmt <= rminsp : ",2G18.10)') rmt(is), &
39  rminsp(is)
40  write(*,'(" for species ",I0)') is
41  write(*,*)
42  stop
43  end if
44  if (rmaxsp(is) < rmt(is)) then
45  write(*,*)
46  write(*,'("Error(readspecies): rmaxsp < rmt : ",2G18.10)') rmaxsp(is), &
47  rmt(is)
48  write(*,*)
49  stop
50  end if
51  if (nrmt(is) < 20) then
52  write(*,*)
53  write(*,'("Error(readspecies): nrmt too small : ",I0)') nrmt(is)
54  write(*,'(" for species ",I0)') is
55  write(*,*)
56  stop
57  end if
58 ! set the smallest radial mesh point to a single value if required
59  if (rminall > 0.d0) rminsp(is)=rminall
60 ! multiply nrmt by the scale factor
61  nrmt(is)=nint(dble(nrmt(is))*nrmtscf)
62 ! reduce the smallest radial mesh point by the same factor
63  rminsp(is)=rminsp(is)/nrmtscf
64  read(50,*) nstsp(is)
65  if ((nstsp(is) < 1).or.(nstsp(is) > maxstsp)) then
66  write(*,*)
67  write(*,'("Error(readspecies): nstsp out of range : ",I0)') nstsp(is)
68  write(*,'(" for species ",I0)') is
69  write(*,*)
70  stop
71  end if
72  do ist=1,nstsp(is)
73  read(50,*) nsp(ist,is),lsp(ist,is),ksp(ist,is),occsp(ist,is),spcore(ist,is)
74  if (nsp(ist,is) < 1) then
75  write(*,*)
76  write(*,'("Error(readspecies): nsp < 1 : ",I0)') nsp(ist,is)
77  write(*,'(" for species ",I0)') is
78  write(*,'(" and state ",I0)') ist
79  write(*,*)
80  stop
81  end if
82  if (lsp(ist,is) < 0) then
83  write(*,*)
84  write(*,'("Error(readspecies): lsp < 0 : ",I0)') lsp(ist,is)
85  write(*,'(" for species ",I0)') is
86  write(*,'(" and state ",I0)') ist
87  write(*,*)
88  stop
89  end if
90  if (ksp(ist,is) < 1) then
91  write(*,*)
92  write(*,'("Error(readspecies): ksp < 1 : ",I0)') ksp(ist,is)
93  write(*,'(" for species ",I0)') is
94  write(*,'(" and state ",I0)') ist
95  write(*,*)
96  stop
97  end if
98  if (occsp(ist,is) < 0.d0) then
99  write(*,*)
100  write(*,'("Error(readspecies): occsp < 0 : ",G18.10)') occsp(ist,is)
101  write(*,'(" for species ",I0)') is
102  write(*,'(" and state ",I0)') ist
103  write(*,*)
104  stop
105  end if
106  end do
107  read(50,*) apword(0,is)
108  if (apword(0,is) < 1) then
109  write(*,*)
110  write(*,'("Error(readspecies): apword < 1 : ",I0)') apword(0,is)
111  write(*,'(" for species ",I0)') is
112  write(*,*)
113  stop
114  end if
115  if (apword(0,is) > maxapword) then
116  write(*,*)
117  write(*,'("Error(readspecies): apword too large : ",I0)') apword(0,is)
118  write(*,'(" for species ",I0)') is
119  write(*,'("Adjust maxapword in modmain and recompile code")')
120  write(*,*)
121  stop
122  end if
123 ! set the APW orders for l>0
124  apword(1:lmaxapw,is)=apword(0,is)
125  do io=1,apword(0,is)
126  read(50,*) apwe0(io,0,is),apwdm(io,0,is),apwve(io,0,is)
127  if (apwdm(io,0,is) < 0) then
128  write(*,*)
129  write(*,'("Error(readspecies): apwdm < 0 : ",I0)') apwdm(io,0,is)
130  write(*,'(" for species ",I0)') is
131  write(*,'(" and order ",I0)') io
132  write(*,*)
133  stop
134  end if
135 ! set the APW linearisation energies, derivative orders and variability for l>0
136  apwe0(io,1:lmaxapw,is)=apwe0(io,0,is)
137  apwdm(io,1:lmaxapw,is)=apwdm(io,0,is)
138  apwve(io,1:lmaxapw,is)=apwve(io,0,is)
139  e0min=min(e0min,apwe0(io,0,is))
140  end do
141  read(50,*) nlx
142  if (nlx < 0) then
143  write(*,*)
144  write(*,'("Error(readspecies): nlx < 0 : ",I0)') nlx
145  write(*,'(" for species ",I0)') is
146  write(*,*)
147  stop
148  end if
149  do ilx=1,nlx
150  read(50,*) lx,io
151  if (lx < 0) then
152  write(*,*)
153  write(*,'("Error(readspecies): lx < 0 : ",I0)') lx
154  write(*,'(" for species ",I0)') is
155  write(*,'(" and exception number ",I0)') ilx
156  write(*,*)
157  stop
158  end if
159  if (lx > lmaxapw) then
160  write(*,*)
161  write(*,'("Error(readspecies): lx > lmaxapw : ",I0)') lx
162  write(*,'(" for species ",I0)') is
163  write(*,'(" and exception number ",I0)') ilx
164  write(*,*)
165  stop
166  end if
167  apword(lx,is)=io
168  if (apword(lx,is) < 1) then
169  write(*,*)
170  write(*,'("Error(readspecies): apword < 1 : ",I0)') apword(lx,is)
171  write(*,'(" for species ",I0)') is
172  write(*,'(" and exception number ",I0)') ilx
173  write(*,*)
174  stop
175  end if
176  if (apword(lx,is) > maxapword) then
177  write(*,*)
178  write(*,'("Error(readspecies): apword too large : ",I0)') apword(lx,is)
179  write(*,'(" for species ",I0)') is
180  write(*,'(" and exception number ",I0)') ilx
181  write(*,'("Adjust maxapword in modmain and recompile code")')
182  write(*,*)
183  stop
184  end if
185  do io=1,apword(lx,is)
186  read(50,*) apwe0(io,lx,is),apwdm(io,lx,is),apwve(io,lx,is)
187  if (apwdm(io,lx,is) < 0) then
188  write(*,*)
189  write(*,'("Error(readspecies): apwdm < 0 : ",I0)') apwdm(io,lx,is)
190  write(*,'(" for species ",I0)') is
191  write(*,'(" exception number ",I0)') ilx
192  write(*,'(" and order ",I0)') io
193  write(*,*)
194  stop
195  end if
196  e0min=min(e0min,apwe0(io,lx,is))
197  end do
198  end do
199 ! add excess order to APW functions if required
200  if (nxoapwlo > 0) then
201  do l=0,lmaxapw
202  jo=apword(l,is)
203  ko=jo+nxoapwlo
204  if (ko > maxapword) ko=maxapword
205  i=0
206  do io=jo+1,ko
207  i=i+1
208  apwe0(io,l,is)=apwe0(jo,l,is)
209  apwdm(io,l,is)=apwdm(jo,l,is)+i
210  apwve(io,l,is)=apwve(jo,l,is)
211  end do
212  apword(l,is)=ko
213  end do
214  end if
215  read(50,*) nlorb(is)
216  if (nlorb(is) < 0) then
217  write(*,*)
218  write(*,'("Error(readspecies): nlorb < 0 : ",I0)') nlorb(is)
219  write(*,'(" for species ",I0)') is
220  write(*,*)
221  stop
222  end if
223  if (nlorb(is) > maxlorb) then
224  write(*,*)
225  write(*,'("Error(readspecies): nlorb too large : ",I0)') nlorb(is)
226  write(*,'(" for species ",I0)') is
227  write(*,'("Adjust maxlorb in modmain and recompile code")')
228  write(*,*)
229  stop
230  end if
231  do ilo=1,nlorb(is)
232  read(50,*) lorbl(ilo,is),lorbord(ilo,is)
233  if (lorbl(ilo,is) < 0) then
234  write(*,*)
235  write(*,'("Error(readspecies): lorbl < 0 : ",I0)') lorbl(ilo,is)
236  write(*,'(" for species ",I0)') is
237  write(*,'(" and local-orbital ",I0)') ilo
238  write(*,*)
239  stop
240  end if
241  if (lorbl(ilo,is) > lmaxo) then
242  write(*,*)
243  write(*,'("Error(readspecies): lorbl > lmaxo :",2(X,I0))') lorbl(ilo,is),&
244  lmaxo
245  write(*,'(" for species ",I0)') is
246  write(*,'(" and local-orbital ",I0)') ilo
247  write(*,*)
248  stop
249  end if
250  if (lorbord(ilo,is) < 2) then
251  write(*,*)
252  write(*,'("Error(readspecies): lorbord < 2 : ",I0)') lorbord(ilo,is)
253  write(*,'(" for species ",I0)') is
254  write(*,'(" and local-orbital ",I0)') ilo
255  write(*,*)
256  stop
257  end if
258  if (lorbord(ilo,is) > maxlorbord) then
259  write(*,*)
260  write(*,'("Error(readspecies): lorbord too large : ",I0)') lorbord(ilo,is)
261  write(*,'(" for species ",I0)') is
262  write(*,'(" and local-orbital ",I0)') ilo
263  write(*,'("Adjust maxlorbord in modmain and recompile code")')
264  write(*,*)
265  stop
266  end if
267  do io=1,lorbord(ilo,is)
268  read(50,*) lorbe0(io,ilo,is),lorbdm(io,ilo,is),lorbve(io,ilo,is)
269  if (lorbdm(io,ilo,is) < 0) then
270  write(*,*)
271  write(*,'("Error(readspecies): lorbdm < 0 : ",I0)') lorbdm(io,ilo,is)
272  write(*,'(" for species ",I0)') is
273  write(*,'(" local-orbital ",I0)') ilo
274  write(*,'(" and order ",I0)') io
275  write(*,*)
276  stop
277  end if
278  e0min=min(e0min,lorbe0(io,ilo,is))
279  end do
280  end do
281 ! add excess local-orbitals if required
282  if (nxlo > 0) then
283  lx=-1
284  do ilo=1,nlorb(is)
285  do io=1,lorbord(ilo,is)
286  if (lorbe0(io,ilo,is) < 0.d0) goto 10
287  end do
288  if (lorbl(ilo,is) > lx) lx=lorbl(ilo,is)
289 10 continue
290  end do
291  ilo=nlorb(is)
292  do i=1,nxlo
293  if (ilo == maxlorb) exit
294  l=lx+i
295  if (l > lmaxo) exit
296  ilo=ilo+1
297  lorbl(ilo,is)=l
298  lorbord(ilo,is)=apword(l,is)+1
299  do io=1,lorbord(ilo,is)
300  lorbe0(io,ilo,is)=apwe0(1,l,is)
301  lorbdm(io,ilo,is)=io-1
302  lorbve(io,ilo,is)=apwve(1,l,is)
303  end do
304  end do
305  nlorb(is)=ilo
306  end if
307 ! add excess order to local-orbitals if required
308  if (nxoapwlo > 0) then
309  do ilo=1,nlorb(is)
310 ! find the maximum energy derivative
311  jo=1
312  j=lorbdm(jo,ilo,is)
313  do io=1,lorbord(ilo,is)
314  i=lorbdm(io,ilo,is)
315  if (i > j) then
316  jo=io
317  j=i
318  end if
319  end do
320  ko=lorbord(ilo,is)+nxoapwlo
321  if (ko > maxlorbord) ko=maxlorbord
322  i=0
323  do io=lorbord(ilo,is)+1,ko
324  i=i+1
325  lorbe0(io,ilo,is)=lorbe0(jo,ilo,is)
326  lorbdm(io,ilo,is)=lorbdm(jo,ilo,is)+i
327  lorbve(io,ilo,is)=lorbve(jo,ilo,is)
328  end do
329  lorbord(ilo,is)=ko
330  end do
331  end if
332  close(50)
333 end do
334 if (rmtall > 0.d0) then
335 ! set all muffin-tin radii to single value if required
336  rmt(1:nspecies)=rmtall
337 else
338 ! scale the muffin-tin radii if required
339  if (rmtscf /= 1.d0) rmt(1:nspecies)=rmtscf*rmt(1:nspecies)
340 ! apply averaging scheme to the muffin-tin radii
341  if (mrmtav > 0) call rmtavrg
342 end if
343 ! make a copy of the muffin-tin radii
345 ! add conduction state local-orbitals if required
346 if (lorbcnd) call addlorbcnd
347 ! maximum number of local-orbitals over all species
348 nlomax=maxval(nlorb(1:nspecies))
349 ! generate the index which arranges the local-orbitals in ascending energy
350 call genidxelo
351 ! subtract 2 Hartree from the minimum energy
352 e0min=e0min-2.d0
353 end subroutine
354 
real(8) rminall
Definition: modmain.f90:158
real(8), dimension(maxstsp, maxspecies) occsp
Definition: modmain.f90:133
subroutine genidxelo
Definition: genidxelo.f90:7
integer, dimension(maxstsp, maxspecies) ksp
Definition: modmain.f90:125
integer, parameter maxapword
Definition: modmain.f90:757
integer, dimension(maxspecies) nlorb
Definition: modmain.f90:789
integer, dimension(maxstsp, maxspecies) lsp
Definition: modmain.f90:123
real(8), dimension(maxspecies) rmaxsp
Definition: modmain.f90:105
character(256) sppath
Definition: modmain.f90:72
real(8) rmtall
Definition: modmain.f90:160
real(8), dimension(maxlorbord, maxlorb, maxspecies) lorbe0
Definition: modmain.f90:807
logical lorbcnd
Definition: modmain.f90:838
real(8) rmtscf
Definition: modmain.f90:154
character(256), dimension(maxspecies) spfname
Definition: modmain.f90:74
integer lmaxo
Definition: modmain.f90:203
integer, dimension(maxapword, 0:maxlapw, maxspecies) apwdm
Definition: modmain.f90:773
subroutine rmtavrg
Definition: rmtavrg.f90:10
integer nxlo
Definition: modmain.f90:844
integer lmaxapw
Definition: modmain.f90:199
real(8) nrmtscf
Definition: modmain.f90:148
integer nlomax
Definition: modmain.f90:791
real(8) e0min
Definition: modmain.f90:828
logical, dimension(maxstsp, maxspecies) spcore
Definition: modmain.f90:127
integer, parameter maxlorbord
Definition: modmain.f90:785
logical, dimension(maxlorbord, maxlorb, maxspecies) lorbve
Definition: modmain.f90:815
real(8), dimension(maxapword, 0:maxlapw, maxspecies) apwe0
Definition: modmain.f90:769
real(8), dimension(maxspecies) spmass
Definition: modmain.f90:101
integer, dimension(0:maxlapw, maxspecies) apword
Definition: modmain.f90:761
real(8), dimension(maxspecies) rmt
Definition: modmain.f90:164
real(8), dimension(maxspecies) rmt0
Definition: modmain.f90:164
subroutine addlorbcnd
Definition: addlorbcnd.f90:7
integer, dimension(maxstsp, maxspecies) nsp
Definition: modmain.f90:121
logical, dimension(maxapword, 0:maxlapw, maxspecies) apwve
Definition: modmain.f90:775
subroutine readspecies
Definition: readspecies.f90:7
character(64), dimension(maxspecies) spname
Definition: modmain.f90:76
integer, dimension(maxlorb, maxspecies) lorbord
Definition: modmain.f90:795
real(8), dimension(maxspecies) rminsp
Definition: modmain.f90:103
integer nspecies
Definition: modmain.f90:34
integer, dimension(maxspecies) nstsp
Definition: modmain.f90:113
real(8), dimension(maxspecies) spzn
Definition: modmain.f90:80
integer, parameter maxlorb
Definition: modmain.f90:783
integer, dimension(maxlorb, maxspecies) lorbl
Definition: modmain.f90:799
integer, parameter maxstsp
Definition: modmain.f90:111
integer mrmtav
Definition: modmain.f90:156
integer nxoapwlo
Definition: modmain.f90:842
character(64), dimension(maxspecies) spsymb
Definition: modmain.f90:78
integer, dimension(maxlorbord, maxlorb, maxspecies) lorbdm
Definition: modmain.f90:813
integer, dimension(maxspecies) nrmt
Definition: modmain.f90:150