7
subroutine siesta_init()
8
USE Kpoint_grid, only: setup_Kpoint_grid, gamma_scf, maxk
9
USE Band, only: gamma_bands, setup_bands
10
USE m_ksvinit, only: gamma_polarization, estimate_pol_kpoints
11
USE m_struct_init, only: struct_init
15
use atomlist, only: no_u, rmaxkb, amass, lasto, qtot, iza, rmaxo,
16
. zvaltot, superc, initatomlists, no_l
17
use m_fdf_global, only: fdf_global_get
18
use sys, only: die, bye
19
use xcmod, only: setXC
20
use molecularmechanics, only : inittwobody
21
use metaforce, only: initmeta
22
use m_mpi_utils, only : broadcast
23
use alloc, only: re_alloc, alloc_report
24
use phonon, only: phonon_num_disps, phonon_setup
25
use parallelsubs, only: getnodeorbs
26
use m_iostruct, only: write_struct, read_struct
27
use zmatrix, only: lUseZmatrix
28
use zmatrix, only: write_canonical_ucell_and_Zmatrix
29
use m_check_supercell, only: check_sc_factors
30
use files, only : slabel
31
use siesta_cmlsubs, only: siesta_cml_init
32
use m_timestamp, only : timestamp
33
use m_wallclock, only : wallclock
34
use parallel, only: Node, Nodes, IOnode
35
USE densematrix, only: Haux, Saux, Psi
43
use m_ioxv, only: xv_file_read
44
USE writewave, only: gamma_wavefunctions, setup_wf_kpoints
46
use mpi_siesta, only: mpi_comm_world
52
integer :: MPIerror ! Return error code in MPI routines
55
real(dp):: veclen ! Length of a unit-cell vector
58
integer :: i, is, ispin
59
integer :: neigmin ! Min. number of eigenstates (per k point)
60
integer :: ns ! Number of species
62
external :: automatic_cell,
64
. dhscf, diagon, dnaefs, extrapol, initatom,
66
. kinefsm, mulliken, naefs, pulayx,
67
. reinit, shaper, spnvec,
68
. timer, xijorb, memory,
69
. ioeig, iofa, iokp, iomd, prversion, eggbox
72
!------------------------------------------------------------------------- BEGIN
73
! Initialise MPI and set processor number
75
call MPI_Init( MPIerror )
76
call MPI_Comm_Rank( MPI_Comm_World, Node, MPIerror )
77
call MPI_Comm_Size( MPI_Comm_World, Nodes, MPIerror )
80
IOnode = (Node .eq. 0)
82
! Print version information ...........................................
88
. '* Running on ', Nodes, ' nodes in parallel'
91
. '* Running in serial mode with MPI'
95
. '* Running in serial mode'
97
call timestamp('Start of run')
98
call wallclock('Start of run')
102
! Start time counter ..................................................
103
call timer( 'siesta', 0 )
104
call timer( 'siesta', 1 )
105
call timer( 'Setup', 1 )
108
nullify(Haux,Saux,psi)
109
nullify(listhptr,listhptrold)
110
nullify(numh,numhold)
112
! Initialize some variables
126
! Initialise read .....................................................
129
call siesta_cml_init() ! Initialize CML (relies on reinit)
131
! Set allocation report level .........................................
132
call fdf_global_get(level, 'alloc_report_level', 0 )
133
call alloc_report( level=level, file=trim(slabel)//'.alloc' )
136
! Initialise exchange-correlation functional information
139
! Initialise force field component
142
! Initialize pseudopotentials and atomic orbitals
143
if (IOnode) call initatom(ns)
145
call broadcast_basis()
147
call fdf_global_get(atmonly,'Atom-Setup-Only',.false.)
148
if (atmonly) call bye("End of atom setup")
151
call struct_init() ! Sets na_u, isa, ucell
153
! Initialize atom lists
155
call initatomlists() ! Sets iza
157
! early exit if only checking the structure
159
call fdf_global_get(struct_only,'Output-Structure-Only',.false.)
161
call write_struct( ucell, na_u, isa, iza, xa )
162
if (lUseZmatrix) then
163
call write_canonical_ucell_and_Zmatrix()
166
if (struct_only) then
167
call bye("End of structure processing")
170
! -- End of Initial Structure Processing --
173
write(6,'(/,a,20("*"),a,28("*"))')
174
. 'siesta: ', ' Simulation parameters '
175
write(6,'(a)') 'siesta:'
176
write(6,'(a)') 'siesta: The following are some of the '//
177
. 'parameters of the simulation.'
178
write(6,'(a)') 'siesta: A complete list of the parameters '//
179
. 'used, including default values,'
180
write(6,'(a,a)')'siesta: can be found in file out.fdf'
181
write(6,'(a)') 'siesta:'
184
! Allocate other arrays based on read sizes ................
187
call re_alloc(fa,1,3,1,na_u,name="fa",
188
$ routine="siesta_init")
189
call re_alloc(cfa,1,3,1,na_u,name="cfa",
190
$ routine="siesta_init")
194
! Read simulation data ................................................
195
call read_options( na_u, ns, nspin )
198
qtot = qtot - charnet ! qtot set in initatomlists
199
! charnet set in redata
201
write(6,fmt="(a,f12.6)") "Total number of electrons: ", qtot
202
write(6,fmt="(a,f12.6)") "Total ionic charge: ", zvaltot
206
! Calculate spin populations for fixed spin case...
209
$ call die('siesta: ERROR: ' //
210
$ 'You can only fix the spin of the system' //
211
$ ' for collinear spin polarized calculations.')
213
qs(i) = (qtot + (3-2*i)*ts) / 2.0_dp
217
if (nspin .le. 2) then
219
qs(ispin) = qtot/nspin
225
! Find maximum interaction range ......................................
229
rmaxh = 2.0_dp*rmaxo + 2.0_dp*rmaxkb
231
! ......................
233
! Madelung correction for charged systems .............................
234
if (charnet .ne. 0.0_dp) then
235
call madelung(ucell, shape, charnet, Emad)
238
! Parallel initialisation
239
call initparallel(no_u,na_u,lasto,xa,ucell,rmaxh,rcoor,isolve)
240
! if (IOnode) call show_distribution()
242
! Find number of locally stored orbitals and allocated related arrays
243
call GetNodeOrbs(no_u,Node,Nodes,no_l)
246
call re_alloc(listhptr,1,no_l,name='listhptr',routine='siesta',
248
call re_alloc(listhptrold,1,no_l,name='listhptrold',
249
. routine='siesta',copy=.false.)
250
call re_alloc(numh,1,no_l,name='numh',routine='siesta',
252
call re_alloc(numhold,1,no_l,name='numhold',routine='siesta',
259
! Get number of eigenstates that need to be calculated
261
call fdf_global_get(neigwanted,'NumberOfEigenStates',no_u)
264
! Check number of eigenstates - cannot be larger than number of
265
! basis functions or smaller than number of occupied states + 1
266
! so that the Fermi level can be estimated
268
neigmin = nint(qs(is)/real(3 - min(nspin,2), kind=dp)) + 1
269
neigwanted = max(neigwanted,neigmin)
271
neigwanted = min(neigwanted,no_u)
273
! Find k-grid for Brillouin zone integration
274
! NOTE: We need to know whether gamma is .true. or
275
! not early, in order to decide whether to use an
276
! auxiliary supercell for the calculation of matrix elements.
278
call setup_Kpoint_grid( ucell )
282
call re_alloc(eo,1,no_u,1,nspin,1,maxk,name="eo",
283
$ routine="state_init")
284
call re_alloc(qo,1,no_u,1,nspin,1,maxk,name="qo",
285
$ routine="state_init")
288
gamma = gamma .and. gamma_bands
290
call setup_wf_kpoints()
291
gamma = gamma .and. gamma_wavefunctions
293
call estimate_pol_kpoints(ucell)
294
gamma = gamma .and. gamma_polarization
295
!! print *, "gamma, gamma_pol: ", gamma, gamma_polarization
298
! Find required supercell
299
! 2*rmaxh is used to guarantee that two given orbitals in the
300
! supercell can only overlap once
306
veclen = sqrt(ucell(1,i)**2+ucell(2,i)**2+ucell(3,i)**2)
307
nsc(i) = ceiling( 2 * rmaxh / veclen )
309
if (.not. naiveauxcell)
310
$ call check_sc_factors(ucell,nsc,2*rmaxh)
320
! Find auxiliary supercell (required only for k sampling) ............
321
call superc( ucell, scell, nsc)
323
! Initialise metadynamic forces if required
326
if (idyn .eq. 0) then
329
else if (idyn .ge. 1 .and. idyn .le. 5) then
332
else if (idyn .eq. 6) then
334
fincoor = (ia2-ia1+1)*3*2
335
else if (idyn .eq. 7) then
338
fincoor = phonon_num_disps
339
else if (idyn .eq. 8) then
343
call die('siesta: wrong idyn')
346
! Build initial velocities according to Maxwell-Bolzmann distribution....
347
if (idyn .ne. 0 .and. idyn .ne. 6 .and. (.not. xv_file_read))
348
. call vmb(na_u,tempinit,amass,xa,isa,va)
352
call timer( 'Setup', 2 )
354
! Output memory use before main loop
355
call printmemory( 6, 0 )
357
! Initialization now complete. Flush stdout.
358
if (ionode) call pxfflush(6)
359
!--------------------------------------------------------------------------- END
361
END subroutine siesta_init
363
End MODULE m_siesta_init