2
! This file is part of the SIESTA package.
4
! Copyright (c) Fundacion General Universidad Autonoma de Madrid:
5
! E.Artacho, J.Gale, A.Garcia, J.Junquera, P.Ordejon, D.Sanchez-Portal
6
! and J.M.Soler, 1996-2006.
8
! Use of this software constitutes agreement with the full conditions
9
! given in the SIESTA license, as signed by all legitimate users.
14
C SIESTA Density Functional LCAO program package.
15
C Copyright by Fundacion General Universidad Autonoma de Madrid:
16
C E.Artacho, J.Gale, A.Garcia, J.Junquera, P.Ordejon, D.Sanchez-Portal
17
C and J.M.Soler, 1996-2006
19
C Copy or disemination of all or part of this package is not permitted
20
C without prior and explicit authorization by the authors.
21
C Send comments/suggestions/bug-reports to siesta@uam.es
25
use precision, only: dp
26
use parallel, only: Node, Nodes, IOnode, ParallelOverK
27
use m_cell, only: ucell
28
use atmfuncs, only: rcut, uion, izofis
29
use atomlist, only: xa, xalast, indxuo, na_u
30
use atomlist, only: isa, cisa, elem, indxua, iza, lastkb, lasto
31
use atomlist, only: qa, amass, qtot, no_u, rmaxo, rmaxkb
32
use atomlist, only: zvaltot
33
use atomlist, only: rmaxv, na_s, iphorb, iphkb, rco, rckb
34
use atomlist, only: datm, no_s, iaorb
35
use atomlist, only: superx, superc, initatomlists
37
use kpoint_grid, only: maxk, nkpnt, setup_kpoint_grid
38
use kpoint_grid, only: kpoint, kweight, writek
40
use band, only: initbands, bands
41
use fdf, only : fdf_block, fdf_convfac, fdf_boolean
42
use fdf, only : fdf_physical
43
use m_fdf_global, only: fdf_global_get
44
use sys, only: die, bye
46
use periodic_table, only : symbol
47
use xcmod, only: setXC
48
use molecularmechanics, only : inittwobody, twobody
49
use metaforce, only: lMetaForce, initmeta, meta
51
use mpi_siesta, only: mpi_comm_world
52
use m_mpi_utils, only : globalize_sum, globalize_max
54
use m_mpi_utils, only : broadcast
55
use alloc, only: re_alloc, alloc_report
56
use phonon, only: phonon_num_disps, phonon_setup
57
use phonon, only: phonon_write_forces, phonon_restore_coords
58
use phonon, only: phonon_set_coords
62
use m_ordern, only: ordern
63
use m_hsparse, only: hsparse
65
use parallelsubs, only: getnodeorbs
66
use writewave, only: initwave, wwave
67
use iopipes, only: forcestopipe, coordsfrompipe
68
use m_iostruct, only: write_struct, read_struct
69
use m_nlefsm, only: nlefsm
70
use m_overfsm, only: overfsm
71
use m_check_supercell, only: check_sc_factors
77
use files, only : slabel, label_length
79
use m_timestamp, only : timestamp
80
use m_wallclock, only : wallclock
82
use zmatrix, only: lUseZmatrix, iofaZmat
83
use zmatrix, only: CartesianForce_to_ZmatForce
84
use zmatrix, only: write_Zmatrix,
85
$ write_canonical_ucell_and_Zmatrix
86
use m_broyden_optim, only:broyden_optimizer
87
use m_zm_broyden_optim, only: zm_broyden_optimizer
88
use m_cell_broyden_optim, only: cell_broyden_optimizer
89
use m_redata, only: redata
90
use m_ioxv, only: ioxv
92
use m_smearing, only: temp
93
use m_dynamics, only: nose, verlet2, npr, anneal, pr
94
use md_out, only: md_v_format
96
use md_out, only: md_netcdf
98
use basis_enthalpy, only: write_basis_enthalpy
8
USE m_steps, only: inicoor, fincoor
104
. i, ia, ia1, ia2, iadispl, ianneal,
105
. idyn, ifa, ifinal, ihmat, ihuge, iiscf, ik,
106
. ind, inicoor, io, ioptlwf, iord,
107
. iquench, is, isel, iscf,
108
. isolve, ispin, istp, istpsave, istart, istep, istr,
109
. iu, iunit, iv, ix, ixdispl,
110
. j, ja, jamin, jo, jx,
111
. level, maxbk, maxnh,
112
. maxna, maxsav, broyden_maxit, maxwk, mscell(3,3), mullipop,
113
. nkick, nnamax, nauxpul, nbcell, nbk, ncgmax, nh,
114
. nmove, nnia, ns, nsc(3), nscold(3), nscf, nspin,
115
. ntm(3), ntcon, no_l, nxij, nwk, pmax, nkpol, nhist,
116
. neigwanted, neigmin
123
integer, dimension(:), allocatable ::
126
integer, pointer, save ::
127
. listh(:), listhold(:), listhptr(:), listhptrold(:),
128
. numh(:), numhold(:)
131
. bcell(3,3), beta, bulkm,
132
. charnet, cfmax, cftem, const, cstress(3,3),
133
. mstress(3,3), kin_stress(3,3), ps(3,3),
134
. dipol(3), dDmax, dDtol, dEmax, dEtol, DEharr, DEna,
135
. dt, DUext, DUscf, Dxc, dx, dxmax, e1, e2, sigma,
136
. Ecorrec, ef, Eharrs, Eharrs1, Eions, Ekin, Ekinion, Emad, Ena,
137
. Elast, Enaatm, Enascf, Enl, Entrop, Entropy, Emeta,
138
. eta(2), etol, Etot, Etot_output, Exc, E0, Emm,
139
. factor, fmax, fmean, FreeE, fres, ftem, ftol, ftot(3),
140
. g2cut, g2max, getot, kn, kpr,
141
. mn, mpr, occtol, Pint, Pmol, Psol, rmax_bonds, Press
143
. qaux, qspin(4), qsol,
144
. rcoor, rcoorcp, rijmin, rmax, rmaxh, rmin, r2min,
145
. scell(3,3), stot, stress(3,3), strtol, svec(3),
146
. taurelax, tempinit, tempion, tiny, tp, ts, tt,
147
. tstress(3,3), Uatm, Uscf,
148
. vcell(3,3), virial, vn,
149
. volcel, volume, vpr, wmix, wmixkick,
150
. stressl(3,3), veclen
152
real(dp), dimension(:), allocatable ::
155
real(dp), pointer, save ::
156
. H0(:), S(:), wgthpol(:)
158
real(dp), dimension(:,:), allocatable ::
159
. auxpul, cfa, fa, fal,
160
. polR, polxyz, va, xij, xijo, wfk
162
real(dp), pointer, save ::
163
. Dold(:,:), Dscf(:,:), Dscfsave(:,:), Eold(:,:), Escf(:,:),
164
. bk(:,:), H(:,:), kpol(:,:)
168
. buffer1, stresstmp(3,3), qtmp(4)
170
real(dp), dimension(:,:), allocatable ::
174
real(dp), dimension(:,:,:), allocatable :: ebk
175
real(dp), dimension(:,:,:), pointer :: eo, qo
178
. auxchanged, chebef, dminit, default, dumpcharge,
179
. final, first, fixauxcell, fixspin, found, foundxv, foundzm,
180
. gamma, naiveauxcell,
181
. initdmaux, inspn, itest, last, lastst, mix, mmix, negl, noeta,
182
. outlng, overflow, overflowed, pulfile, relaxd,
183
. savehs, savevh, savevt, savdrh, savrho,
184
. savepsch, savetoch,
185
. usesavecg, usesavelwf, usesavedm, usesavedmloc, usesavexv,
186
. usesavezm, writeig,
187
. writbk, writmd, writpx, writb, writec, writef,
188
. writic, varcel, genlogic, do_pdos, writedm, atmonly,
189
. harrisfun, muldeb, eggbox_block, use_struct_file,
190
$ require_energy_convergence, broyden_optim, struct_only,
191
$ bornz, cell_can_change, change_kgrid_in_md,
192
$ RelaxCellOnly, RemoveIntraMolecularPressure
195
. line*150, sname*150, shape*10, message*79
197
character(len=label_length+5) :: fildrh
198
character(len=label_length+5) :: filepsch
199
character(len=label_length+5) :: filetoch
200
character(len=label_length+5) :: filevh
201
character(len=label_length+5) :: filevt
202
character(len=label_length+5) :: filrho
203
character(len=label_length+5) :: paste
205
external :: automatic_cell,
206
. bonds, cgvc, cgvc_zmatrix, fixed,
207
. dhscf, diagon, dnaefs, extrapol, initatom,
209
. kinefsm, mulliken, naefs, neighb,
211
. reinit, shaper, spnvec,
212
. timer, volcel, xijorb, memory,
213
. ioeig, iofa, iokp, iomd, prversion, eggbox
215
type(parsed_line), pointer :: p
218
. e1, e2 / 1._dp, -1._dp /
219
. eggbox_block /.true./
224
! maxnh is (initially) the minimum size of all the sparse arrays.
225
! It must be 1 (not 0) since we frequently use the F77 idiom of
226
! passing the first element of the array instead of all of it.
231
. nauxpul, nbk, ns, nspin, nxij /5*1/
233
. nsc, mscell / 1,1,1, 1,0,0, 0,1,0, 0,0,1 /
234
c---------------------------------------------------------------------
236
C Initialise MPI and set processor number
238
call MPI_Init( MPIerror )
239
call MPI_Comm_Rank( MPI_Comm_World, Node, MPIerror )
240
call MPI_Comm_Size( MPI_Comm_World, Nodes, MPIerror )
243
IOnode = (Node .eq. 0)
245
C Print version information ...........................................
250
write(6,'(/,a,i4,a)')
251
. '* Running on ', Nodes, ' nodes in parallel'
253
write(6,'(/,a,i4,a)')
254
. '* Running in serial mode with MPI'
257
write(6,'(/,a,i4,a)')
258
. '* Running in serial mode'
260
call timestamp('Start of run')
261
call wallclock('Start of run')
265
C Start time counter ..................................................
266
call timer( 'siesta', 0 )
267
call timer( 'siesta', 1 )
268
call timer( 'Setup', 1 )
271
nullify(Haux,Saux,psi)
272
nullify(bk,H,H0,S,kpol,wgthpol)
273
nullify(Dold,Dscf,Dscfsave,Eold,Escf)
274
nullify(listh,listhold,listhptr,listhptrold)
275
nullify(numh,numhold)
277
C Initialize some variables
291
C Initialise read .....................................................
294
call siesta_cml_init() ! Initialize CML (relies on reinit)
296
C Set allocation report level .........................................
297
call fdf_global_get(level, 'alloc_report_level', 0 )
298
call alloc_report( level=level, file=trim(slabel)//'.alloc' )
301
C Initialise exchange-correlation functional information
304
C Initialise force field component
307
C Initialize pseudopotentials and atomic orbitals
308
if (IOnode) call initatom()
309
call broadcast_basis()
311
call fdf_global_get(atmonly,'Atom-Setup-Only',.false.)
312
if (atmonly) call bye("End of atom setup")
315
write(6,'(/,a,20("*"),a,28("*"))')
316
. 'siesta: ', ' Simulation parameters '
317
write(6,'(a)') 'siesta:'
318
write(6,'(a)') 'siesta: The following are some of the '//
319
. 'parameters of the simulation.'
320
write(6,'(a)') 'siesta: A complete list of the parameters '//
321
. 'used, including default values,'
322
write(6,'(a,a)')'siesta: can be found in file out.fdf'
323
write(6,'(a)') 'siesta:'
326
C Read simulation sizes ...............................................
328
!! Read number of atoms and coordinates, and unit cell
330
call fdf_global_get(use_struct_file,"MD.UseStructFile",.false.)
331
if (use_struct_file) then
332
call read_struct( na_u, ucell) ! Sets na_u, xa, and isa
334
call coor(na_u,ucell) ! Sets na_u, xa, and isa
339
C We need the names of the elements on node 0
341
call memory('A','S',2*na_u,'siesta')
343
elem(i) = symbol(izofis(isa(i)))
347
C Allocate arrays based on read sizes ................
349
! Those living in module atomlists
351
nullify(indxua,iza,lastkb,lasto,qa,amass,xalast)
352
call re_alloc(indxua,1,na_u,name='indxua',routine='siesta')
353
call re_alloc(iza,1,na_u,name='iza',routine='siesta')
354
call re_alloc(lastkb,0,na_u,name='lastkb',routine='siesta')
355
call re_alloc(lasto,0,na_u,name='lasto',routine='siesta')
356
call re_alloc(qa,1,na_u,name='qa',routine='siesta')
357
call re_alloc(xalast,1,3,1,na_u,name='xalast',routine='siesta')
358
call re_alloc(amass,1,na_u,name='amass',routine='siesta')
363
allocate(cfa(3,na_u))
364
call memory('A','D',3*na_u,'siesta')
366
call memory('A','D',3*na_u,'siesta')
367
allocate(fal(3,na_u))
368
call memory('A','D',3*na_u,'siesta')
370
call memory('A','D',3*na_u,'siesta')
372
C Initialise those arrays that must be pre-initialised
373
fal(1:3,1:na_u) = 0.0_dp
374
stress(1:3,1:3) = 0.0_dp
376
if (IOnode) call spin_init(nspin)
377
call broadcast(nspin)
380
call memory('A','D',nspin,'siesta')
382
call memory('A','D',nspin,'siesta')
383
allocate(polR(3,nspin))
384
call memory('A','D',3*nspin,'siesta')
385
allocate(polxyz(3,nspin))
386
call memory('A','D',3*nspin,'siesta')
388
C Read simulation data ................................................
389
call redata(na_u, ns, nspin, outlng, g2cut, charnet, negl, nscf,
390
. dDtol, dEtol, mix, wmix, isolve, temp, fixspin, ts,
391
. ncgmax, ftol, strtol, eta, etol, rcoor,
392
. ioptlwf, chebef, noeta, rcoorcp, beta, pmax,
393
. idyn, istart, ifinal, nmove, ianneal, iquench,
394
. dt, ia1, ia2, dx, dxmax, tt, tp, mn, mpr,
396
. usesavelwf, usesavedm, usesavecg,
397
. mullipop, inspn, maxsav, nkick, wmixkick,
398
. pulfile, tempinit, dumpcharge, varcel, harrisfun,
399
. occtol,broyden_maxit,require_energy_convergence,
402
C Find some switches ..................................................
403
call fdf_global_get(writek,'WriteKpoints' , outlng )
404
call fdf_global_get(writef,'WriteForces' , outlng )
405
call fdf_global_get(writedm,'WriteDM' , .true.)
406
call fdf_global_get(writb, 'WriteBands' , outlng )
407
call fdf_global_get(writbk, 'WriteKbands' , outlng )
408
call fdf_global_get(writeig,'WriteEigenvalues', outlng )
409
call fdf_global_get(writec, 'WriteCoorStep' , outlng )
410
call fdf_global_get(writic, 'WriteCoorInitial', .true. )
411
call fdf_global_get(writmd, 'WriteMDhistory' , .false.)
412
call fdf_global_get(writpx, 'WriteMDXmol' , .not. writec)
413
call fdf_global_get(default, 'UseSaveData' , .false.)
414
call fdf_global_get(usesavexv, 'MD.UseSaveXV' , default)
415
call fdf_global_get(usesavezm, 'MD.UseSaveZM' , default)
416
call fdf_global_get(savehs, 'SaveHS' , .false.)
417
call fdf_global_get(fixauxcell, 'FixAuxiliaryCell', .false.)
418
call fdf_global_get(naiveauxcell, 'NaiveAuxiliaryCell', .false.)
419
call fdf_global_get(initdmaux, 'ReInitialiseDM' , .false.)
420
call fdf_global_get(muldeb, 'MullikenInSCF' , .false.)
421
call fdf_global_get(rijmin, 'WarningMinimumAtomicDistance',
423
call fdf_global_get(bornz, 'BornCharge' , .false.)
424
if (idyn.ne.6) bornz = .false.
426
call fdf_global_get(change_kgrid_in_md,
427
$ "ChangeKgridInMD", .false.)
428
call fdf_global_get(ParallelOverK, 'Diag.ParallelOverK', .false.)
429
call fdf_global_get(RelaxCellOnly, 'MD.RelaxCellOnly', .false.)
430
call fdf_global_get(RemoveIntraMolecularPressure,
431
$ 'MD.RemoveIntraMolecularPressure', .false.)
433
C Read Z-matrix coordinates and forces from file
434
if (lUseZmatrix) then
437
call iozm('read',ucell,vcell,xa,foundzm)
439
if (.not.foundzm) then
440
write(6,'(/,a)') 'siesta: WARNING: ZM file not found'
443
. "! Info in XV file prevails over previous structure input"
449
C Read cell shape and atomic positions from a former run ..............
452
call ioxv('read', ucell, vcell, na_u, isa, iza, xa, va, foundxv)
454
if (.not.foundxv) then
455
write(6,'(/,a)') 'siesta: WARNING: XV file not found'
458
$ "! Info in XV file prevails over previous structure input"
464
C Read cell shape and atomic positions from driver program through pipe
466
call coordsFromPipe( na_u, xa, ucell )
468
C .....................
470
C Dump initial coordinates to output ..................................
471
if ( writic.and.(IOnode) ) then
472
write(6,'(/a)') 'siesta: Atomic coordinates (Bohr) and species'
473
write(6,"('siesta: ',2x,3f10.5,i3,3x,i6)")
474
. ( (xa(ix,ia), ix=1,3), isa(ia), ia, ia=1, na_u)
479
C Initialize atom lists
480
call initatomlists() ! Sets iza
481
qtot = qtot - charnet
483
write(6,fmt="(a,f12.6)") "Total number of electrons: ", qtot
484
write(6,fmt="(a,f12.6)") "Total ionic charge: ", zvaltot
488
C Calculate spin populations for fixed spin case...
491
$ call die('siesta: ERROR: ' //
492
$ 'You can only fix the spin of the system' //
493
$ ' for collinear spin polarized calculations.')
495
qs(i) = (qtot + (3-2*i)*ts) / 2.0_dp
499
if (nspin .le. 2) then
501
qs(ispin) = qtot/nspin
507
C Find maximum interaction range ......................................
511
rmaxh = 2.0_dp*rmaxo + 2.0_dp*rmaxkb
513
C ......................
515
C Automatic cell generation ...........................................
516
if (volcel(ucell) .lt. 1.0d-8) then
517
call automatic_cell(ucell,scell,na_u,xa,isa,charnet)
520
C Find system shape ...................................................
521
call shaper( ucell, na_u, isa, xa, shape, nbcell, bcell )
523
write(6,'(/,2a)') 'siesta: System type = ', shape
526
C Find interatomic distances (output in file BONDS)
528
rmax_bonds = fdf_physical("MaxBondDistance", 6.0_dp, "Bohr")
529
call bonds( ucell, na_u, isa, xa,
530
$ rmax_bonds, trim(slabel)// ".BONDS" )
533
C Output of initial system details:
535
call cmlStartModule(xf=mainXML, title='Initial System')
536
call cmlAddMolecule(xf=mainXML, natoms=na_u,
537
. coords=xa/Ang, elements=elem, refs=cisa,
538
. style='x3', fmt='(f12.6)')
539
call cmlAddLattice(xf=mainXML, cell=ucell,
540
. units='siestaUnits:angstrom', dictref='siesta:ucell')
541
call cmlAddProperty(xf=mainXML, property=trim(shape),
542
. dictref='siesta:shape')
543
call cmlEndModule(xf=mainXML)
546
! early exit if only checking the structure
548
call fdf_global_get(struct_only,'Output-Structure-Only',.false.)
550
call write_struct( ucell, na_u, isa, iza, xa )
551
if (lUseZmatrix) then
552
call write_canonical_ucell_and_Zmatrix()
555
if (struct_only) then
556
call bye("End of structure processing")
559
!!! --------------------- End of Structure Generation section
561
C Madelung correction for charged systems .............................
562
if (charnet .ne. 0.0_dp) then
563
call madelung(ucell, shape, charnet, Emad)
566
C Parallel initialisation
567
call initparallel(no_u,na_u,lasto,xa,ucell,rmaxh,rcoor,isolve)
568
if (IOnode) call show_distribution()
570
C Find number of locally stored orbitals and allocated related arrays
571
call GetNodeOrbs(no_u,Node,Nodes,no_l)
574
call re_alloc(listhptr,1,no_l,name='listhptr',routine='siesta',
576
call re_alloc(listhptrold,1,no_l,name='listhptrold',
577
. routine='siesta',copy=.false.)
578
call re_alloc(numh,1,no_l,name='numh',routine='siesta',
580
call re_alloc(numhold,1,no_l,name='numhold',routine='siesta',
587
C Get number of eigenstates that need to be calculated
589
call fdf_global_get(neigwanted,'NumberOfEigenStates',no_u)
592
C Check number of eigenstates - cannot be larger than number of
593
C basis functions or smaller than number of occupied states + 1
594
C so that the Fermi level can be estimated
596
neigmin = nint(qs(is)/real(3 - min(nspin,2), kind=dp)) + 1
597
neigwanted = max(neigwanted,neigmin)
599
neigwanted = min(neigwanted,no_u)
601
! Find k-grid for Brillouin zone integration
602
! Sets kscell, nkpnt, maxk, kpoint, kweight
603
call setup_Kpoint_grid( ucell )
606
call re_alloc(eo,1,no_u,1,nspin,1,maxk,name="eo",
607
$ routine="state_init")
608
call re_alloc(qo,1,no_u,1,nspin,1,maxk,name="qo",
609
$ routine="state_init")
611
C ......................
613
C Find number of band k-points ........................................
616
call re_alloc(bk,1,3,1,maxbk,name='bk',routine='siesta',
619
call initbands( maxbk, nbk, bk )
621
if (nbk .gt. maxbk) then
622
C If there wasn't enough space to store bands on first call correct
623
C the dimensions and repeat the initialisation
625
call re_alloc(bk,1,3,1,maxbk,name='bk',routine='siesta',
628
call initbands( maxbk, nbk, bk )
630
allocate(ebk(no_u,nspin,maxbk))
631
call memory('A','D',no_u*nspin*maxbk,'siesta')
633
C ......................
635
C Find number of k-points for wavefunction printout ....................
638
allocate(wfk(3,maxwk))
639
call memory('A','D',3*maxwk,'siesta')
641
call initwave( maxwk, no_u, nwk, wfk, overflow )
644
if (nwk .gt. maxwk) then
645
C If there wasn't enough space to store bands on first call correct
646
C the dimensions and repeat the initialisation
648
call memory('D','D',size(wfk),'siesta')
650
allocate(wfk(3,maxwk))
651
call memory('A','D',3*maxwk,'siesta')
654
call initwave( maxwk, no_u, nwk, wfk, overflow )
656
$ call die('siesta: ERROR: Unsuccessful initialization of' //
657
$ ' list of wavefunctions to print')
659
C ......................
661
C Find the grid for the calculation of the polarization..............
663
call re_alloc(kpol,1,3,1,nkpol,name='kpol',routine='siesta',
665
call re_alloc(wgthpol,1,nkpol,name='wgthpol',routine='siesta',
668
call KSV_init(ucell, 0, nkpol, kpol, wgthpol)
670
call re_alloc(kpol,1,3,1,nkpol,name='kpol',routine='siesta',
671
. shrink=.false.,copy=.false.)
672
call re_alloc(wgthpol,1,nkpol,name='wgthpol',routine='siesta',
673
. shrink=.false.,copy=.false.)
675
C Find if only gamma point is used ....................................
676
if (nkpnt.eq.1 .and. abs(kpoint(1,1)).lt.tiny .and.
677
. abs(kpoint(2,1)).lt.tiny .and.
678
. abs(kpoint(3,1)).lt.tiny) then
683
if (nbk .gt. 0) gamma = .false.
684
if (nwk .gt. 1) gamma = .false.
686
if (abs(wfk(1,1)).gt.tiny .and.
687
. abs(wfk(2,1)).gt.tiny .and.
688
. abs(wfk(3,1)).gt.tiny) then
692
if (nkpol.gt.0) gamma = .false.
693
C ....................
695
C Find required supercell
696
C 2*rmaxh is used to guarantee that two given orbitals in the
697
C supercell can only overlap once
703
veclen = sqrt(ucell(1,i)**2+ucell(2,i)**2+ucell(3,i)**2)
704
nsc(i) = ceiling( 2 * rmaxh / veclen )
706
if (.not. naiveauxcell)
707
$ call check_sc_factors(ucell,nsc,2*rmaxh)
717
C Find auxiliary supercell (required only for k sampling) ............
718
call superc( ucell, scell, nsc)
720
C Initialise metadynamic forces if required
723
C Initialize atomic velocities to zero ................................
724
if (.not. foundxv) then
725
va(1:3,1:na_u) = 0.0_dp
726
vcell(1:3,1:3) = 0.0_dp
730
C Begin of coordinate relaxation iteration ============================
731
C Notice that this loop is not indented
732
if (idyn .eq. 0) then
735
else if (idyn .ge. 1 .and. idyn .le. 5) then
738
else if (idyn .eq. 6) then
740
fincoor = (ia2-ia1+1)*3*2
741
else if (idyn .eq. 7) then
744
fincoor = phonon_num_disps
745
else if (idyn .eq. 8) then
749
call die('siesta: wrong idyn')
752
C Build initial velocities according to Maxwell-Bolzmann distribution....
753
if (idyn .ne. 0 .and. idyn .ne. 6 .and. (.not. foundxv))
754
. call vmb(na_u,tempinit,amass,xa,isa,va)
758
call timer( 'Setup', 2 )
760
C Output memory use before main loop
761
call printmemory( 6, 0 )
763
C Initialization now complete. Flush stdout.
764
if (ionode) call pxfflush(6)
766
C Start loop over coordinate changes
768
do istep = inicoor,fincoor
769
call timer( 'IterMD', 1 )
772
write(6,'(/2a)') 'siesta: ',
773
. '=============================='
776
write(6,'(28(" "),a,i6)') 'Begin CG move = ',istep
777
if (cml_p) call cmlStartStep(mainXML, type='CG', index=istp)
779
write(6,'(28(" "),a,i6)') 'Begin MD step = ',istep
780
if (cml_p) call cmlStartStep(mainXML, type='MD', index=istep)
782
write(6,'(28(" "),a,i6)') 'Begin FC step = ',istep
783
if (cml_p) call cmlStartStep(mainXML, type='FC', index=istep)
784
if (istep .eq. 0) then
785
write(6,'(28(" "),a)') 'Undisplaced coordinates'
787
iadispl = (istep-mod(istep-1,6))/6+ia1
788
write(6,'(28(" "),a,i6)') 'displace atom ',
790
ix = mod(istep-1,6)+1
791
ixdispl = (ix - mod(ix-1,2) +1)/2
792
write(6,'(28(" "),a,i6)') 'in direction ',
795
write(6,'(28(" "),a,f8.4,a)') 'by ',
797
C Displace atom by dx...
798
xa(ixdispl,iadispl) = xa(ixdispl,iadispl) + dx
801
call phonon_set_coords(istep,xa,ucell)
803
write(6,'(28(" "),a,i6)') 'Begin Server step = ',istep
804
if (cml_p) call cmlStartStep(mainXML, type='FS', index=istep)
808
. '=============================='
811
C We don't need to do anything for 0<idyn<6
813
if (istep .ne. 0) then
814
iadispl = (istep-mod(istep-1,6))/6 + ia1
815
ix = mod(istep-1,6) + 1
816
ixdispl = (ix - mod(ix-1,2) +1)/2
818
C Displace atom by dx...
819
xa(ixdispl,iadispl) = xa(ixdispl,iadispl) + dx
822
call phonon_set_coords(istep,xa,ucell)
826
C Get coordinates from driver program through pipe
827
if (idyn.eq.8 .and. istep.ne.inicoor) then
828
call coordsFromPipe( na_u, xa, ucell )
829
if (volcel(ucell) < 1.0e-8_dp) then
830
call automatic_cell(ucell,scell,na_u,xa,isa,charnet)
835
C Print Z-matrix coordinates
836
if (lUseZmatrix) then
839
C Print atomic coordinates ............................................
840
call outcoor( ucell, xa, na_u, ' ', writec )
841
call siesta_write_positions()
843
C ...................
845
C Actualize things if unit cell might have changed
847
cell_can_change = ( varcel .or.
848
$ (idyn .eq. 8) ! Force/stress evaluation
850
if (change_kgrid_in_md) then
851
cell_can_change = cell_can_change .or.
852
$ (idyn .eq. 3) ! Parrinello-Rahman
853
$ .or. (idyn .eq. 4) ! Nose-Parrinello-Rahman
854
$ .or. (idyn .eq. 5) ! Anneal
858
$ .and. (istep.ne.inicoor) .and. (.not.gamma) ) then
860
call setup_Kpoint_grid( ucell )
862
call re_alloc(eo,1,no_u,1,nspin,1,maxk,name="eo",
863
$ routine="state_init")
864
call re_alloc(qo,1,no_u,1,nspin,1,maxk,name="qo",
865
$ routine="state_init")
867
C Find required supercell
873
else if (fixauxcell) then
877
veclen = sqrt(ucell(1,i)**2+ucell(2,i)**2+ucell(3,i)**2)
878
nsc(i) = ceiling( 2 * rmaxh / veclen )
880
if (.not. naiveauxcell)
881
$ call check_sc_factors(ucell,nsc,2*rmaxh)
887
if (nsc(i).ne.nscold(i)) auxchanged = .true.
891
C Madelung correction for charged systems .............................
892
if (charnet .ne. 0.0_dp) then
893
call madelung(ucell, shape, charnet, Emad)
897
C End variable cell actualization
899
C Auxiliary supercell
900
call superc(ucell, scell, nsc)
902
C Print unit cell and find its volume
903
if (IOnode) call outcell(ucell)
904
volume = volcel( ucell )
905
C ...................
907
C Initialize neighb subroutine ........................................
910
rmax = max( 2._dp*rmaxv, 2._dp*rmaxo, rmaxo+rmaxkb )
912
if (allocated(jna)) then
913
call memory('D','I',size(jna),'siesta')
916
if (allocated(r2ij)) then
917
call memory('D','D',size(r2ij),'siesta')
920
if (allocated(xij)) then
921
call memory('D','D',size(xij),'siesta')
925
call memory('A','I',maxna,'siesta')
926
allocate(r2ij(maxna))
927
call memory('A','D',maxna,'siesta')
928
allocate(xij(3,maxna))
929
call memory('A','D',3*maxna,'siesta')
930
call neighb( scell, rmax, na_s, xa, ia, isel,
931
. nnia, jna, xij, r2ij )
935
call neighb( scell, rmax, na_s, xa, ia, isel,
936
. nnia, jna, xij, r2ij )
937
nnamax = max( nnamax, nnia )
939
if (nnamax .gt. maxna) then
940
C Increase maxna with safety margin when atoms move
941
maxna = nnamax + 0.10 * nnamax + 10
946
if (overflow) goto 144
949
C Check if any two atoms are unreasonably close .......................
954
call neighb( scell, rmax, na_s, xa, ia, isel,
955
. nnia, jna, xij, r2ij )
958
if ( r2ij(j).lt.r2min .and. ja.ge.ia ) then
959
C Check that it is not the same atom
960
if ( ja.ne.ia .or. r2ij(j).gt.1.d-12 ) then
968
if ( rmin .lt. rijmin ) write(6,'(a,2i6,a,f12.6,a)')
969
. 'siesta: WARNING: Atoms', ia, jamin, ' too close: rij =',
975
C List of nonzero Hamiltonian matrix elements .........................
980
call re_alloc(listh,1,maxnh,name='listh',routine='siesta',
982
call hsparse( negl, scell, nsc, na_s, isa, xa, lasto, lastkb,
983
. iphorb, iphKB, nh, numh, listhptr, listh )
984
if (nh .gt. maxnh) then
985
! Increase maxnh with safety margin for when atoms move
986
maxnh = 1.05 * nh + 40
992
! In first step, allocate anyway (to catch corner case
993
! where one node has nh=0, and doesn't overflow)
995
call re_alloc(Dscf,1,maxnh,1,nspin,name='Dscf',
996
. routine='siesta',copy=.false.)
997
call re_alloc(Dscfsave,1,maxnh,1,nspin,name='Dscfsave',
998
. routine='siesta',copy=.false.)
999
call re_alloc(listhold,1,maxnh,name='listhold',
1000
. routine='siesta',copy=.false.)
1001
! Initialise Dscfsave to avoid problems in extrapol
1002
Dscfsave(1:maxnh,1:nspin) = 0.0_dp
1003
listhold(1:maxnh) = 0
1004
elseif (overflowed) then
1005
! We need to preserve the contents of these arrays
1006
! when reallocating.
1007
call re_alloc(Dscf,1,maxnh,1,nspin,name='Dscf',
1008
. routine='siesta',copy=.true.)
1009
call re_alloc(Dscfsave,1,maxnh,1,nspin,name='Dscfsave',
1010
. routine='siesta',copy=.true.)
1011
call re_alloc(listhold,1,maxnh,name='listhold',
1012
. routine='siesta',copy=.true.)
1014
if (istp==1.or.overflowed) then
1015
call re_alloc(Dold,1,maxnh,1,nspin,name='Dold',
1016
. routine='siesta',copy=.false.)
1017
call re_alloc(Eold,1,maxnh,1,nspin,name='Eold',
1018
. routine='siesta',copy=.false.)
1019
call re_alloc(Escf,1,maxnh,1,nspin,name='Escf',
1020
. routine='siesta',copy=.false.)
1023
C Allocate/reallocate storage associated with Hamiltonian/Overlap matrix
1024
call re_alloc(H,1,maxnh,1,nspin,name='H',
1025
. routine='siesta',shrink=.false.,copy=.false.)
1026
call re_alloc(H0,1,maxnh,name='H0',routine='siesta',
1027
. shrink=.false.,copy=.false.)
1028
call re_alloc(S,1,maxnh,name='S',routine='siesta',
1029
. shrink=.false.,copy=.false.)
1031
C ..................
1033
C Some printout for debugging ........................................
1035
* write(6,'(/,a)') 'siesta: connected orbitals'
1037
* call GlobalToLocalOrb(io,Node,Nodes,iio)
1038
* if (iio.gt.0) then
1039
* write(6,'(i6,4x,15i4)')
1040
* . io, (listh(listhptr(iio)+j),j=1,numh(iio))
1043
* call MPI_Barrier(MPI_Comm_World,MPIerror)
1048
C ..................
1050
C Find vectors between orbital centers ................................
1051
if (allocated(xijo)) then
1052
call memory('D','D',size(xijo),'siesta')
1055
if (.not.gamma) then
1057
allocate(xijo(3,nxij))
1058
call memory('A','D',3*nxij,'siesta')
1059
call xijorb( negl, scell, na_u, na_s, xa,
1060
. lasto, lastkb, rco, rckb,
1061
. maxnh, numh, listhptr, listh, xijo )
1065
call memory('A','D',3,'siesta')
1067
C ..................
1069
C Initialize density matrix ...........................................
1070
C set density matrix for first step
1073
if (istp .eq. 1) dminit = .true.
1074
if (istp .ne. 1 .and. harrisfun) dminit = .true.
1075
if (istp .ne. 1 .and. (idyn .eq. 6)
1076
$ .and. usesavedm .and. writedm) dminit = .true.
1077
if (istp .ne. 1 .and. (idyn .eq. 7)
1078
$ .and. usesavedm) dminit = .true.
1080
C If auxiliary cell has changed, optionally reset density matrix
1081
C and set usesavedata to false to avoid reading back saved copy
1082
if (initdmaux.and.auxchanged) then
1084
usesavedmloc = .false.
1086
usesavedmloc = usesavedm
1090
. call initdm(Datm, Dscf, Dold, lasto, na_s,
1091
. maxnh, no_s, no_l, nspin, na_u, no_l, nspin,
1092
. numh, numhold, listhptr, listhptrold,
1093
. listh, listhold, iaorb, found, inspn,
1094
. usesavedmloc, no_u)
1097
C Initialize energy-density matrix to zero for first call to overfsm
1098
Escf(1:maxnh,1:nspin) = 0.0_dp
1100
C Extrapolate density matrix between steps
1104
if (idyn .eq. 0) iord = 0
1105
if (idyn .eq. 6) iord = 0
1106
if (idyn .eq. 7) iord = 0
1107
C If DM has just been read from disk,
1108
C call extrapol with istep = 2 and iord = 0
1109
C to make it update the structure of DM, if needed
1110
if (found .and. ((istp .eq. 1) .or. (idyn .eq. 6)
1111
. .or. (idyn .eq. 7))) then
1118
. call extrapol(istp, iord, nspin, no_s, no_l, maxnh,
1119
. numh, listhptr, listh, numhold, listhptrold,
1120
. listhold, Dscfsave, Dscf)
1121
C If DM have just been read, restore istp
1122
if (itest) istp = istpsave
1124
C ..................
1126
C Check for Pulay auxiliary matrices sizes ...................................
1127
if (pulfile .or. maxsav .le. 0) then
1129
if (.not.allocated(auxpul)) then
1130
allocate(auxpul(nauxpul,2))
1131
call memory('A','D',2*nauxpul,'siesta')
1136
nauxpul = nauxpul + numh(io)
1138
nauxpul = nauxpul * nspin * maxsav
1140
call globalize_max(nauxpul,ntmp)
1143
C Increase nauxpul with safety margin when atoms move
1144
nauxpul = 1.1 * nauxpul + 10
1145
if (allocated(auxpul)) then
1146
if (size(auxpul,1).ne.nauxpul) then
1147
call memory('D','D',size(auxpul),'siesta')
1149
allocate(auxpul(nauxpul,2))
1150
call memory('A','D',2*nauxpul,'siesta')
1153
allocate(auxpul(nauxpul,2))
1154
call memory('A','D',2*nauxpul,'siesta')
1157
C ....................
1159
C Find overlap matrix ...............................................
1160
call overfsm(na_u, na_s, no_s, scell, xa, indxua, rmaxo, no_l,
1161
. maxna, maxnh, maxnh, lasto, iphorb, isa,
1162
. numh, listhptr, listh, numh, listhptr, listh,
1163
. min(nspin,2), Escf, jna, xij, r2ij,
1165
C ..................
1167
C Start of SCF iteration _____________________________________________
1170
if (wmix .le. 0._dp) then
1172
write(6,'(/,a,f15.8)')
1173
. 'siesta: WARNING: Mixing weight for SCF loop =', wmix
1179
if (iscf .eq. nscf) last = .true.
1180
call timer( 'IterSCF', 1 )
1182
if (cml_p) call cmlStartStep(xf=mainXML, type='SCF', index=iscf)
1184
C Normalize density matrix to exact charge ...........................
1186
do ispin = 1,min(nspin,2)
1188
qsol = qsol + Dscf(io,ispin) * s(io)
1192
call globalize_sum(qsol,buffer1)
1196
if (.not.first .and.
1197
. abs(qsol/qtot-1._dp).gt.1.d-2) write(6,'(a,2f15.6)')
1198
. 'siesta: WARNING: Qtot, Tr[D*S] =', qtot, qsol
1202
Dscf(io,ispin) = Dscf(io,ispin) * qtot/qsol
1203
Escf(io,ispin) = Escf(io,ispin) * qtot/qsol
1206
C ..................
1208
C Initialize Hamiltonian ........................................
1211
C Initialize forces and stress ...................
1212
if (first.or.last) then
1213
fa(1:3,1:na_u) = 0.0_dp
1214
fal(1:3,1:na_u) = 0.0_dp
1215
stress(1:3,1:3) = 0.0_dp
1216
stressl(1:3,1:3) = 0.0_dp
1218
C ..................
1220
C Self-energy of isolated ions ........................................
1225
Eions = Eions + uion(is)
1228
C ..................
1230
C Neutral-atom: energy, forces and stress ............................
1231
C First time for energy, last time for forces
1232
if (first.or.last) then
1233
call naefs(na_u, na_s, scell, xa, indxua, rmaxv,
1234
. maxna, isa, jna, xij, r2ij,
1236
call dnaefs(na_u, na_s, scell, xa, indxua, rmaxv,
1237
. maxna, isa, jna, xij, r2ij,
1241
C ..................
1243
C Kinetic: energy, forces, stress and matrix elements .................
1244
if (first.or.last) then
1245
call kinefsm(na_u, na_s, no_s, scell, xa, indxua, rmaxo, no_l,
1246
. maxna, maxnh, maxnh, lasto, iphorb, isa,
1247
. numh, listhptr, listh, numh, listhptr, listh,
1248
. min(nspin,2), Dscf, jna, xij, r2ij,
1249
. Ekin, fal, stressl, H )
1251
C Global reduction of energy terms
1252
call globalize_sum(Ekin,buffer1)
1256
C ..................
1258
C Non-local-pseudop: energy, forces, stress and matrix elements .......
1259
if (first.or.last) then
1260
call nlefsm(scell, na_u, na_s, isa, xa, indxua, maxna,
1261
. maxnh, maxnh, lasto, lastkb, iphorb, iphKB,
1262
. numh, listhptr, listh, numh, listhptr, listh,
1263
. min(nspin,2), Dscf, Enl, fal, stressl, H)
1265
C Check whether maxna has been increased during nlefsm & resize if needed
1266
if (maxna.gt.size(jna)) then
1267
call memory('D','I',size(jna),'siesta')
1269
call memory('D','D',size(r2ij),'siesta')
1271
call memory('D','D',size(xij),'siesta')
1273
allocate(jna(maxna))
1274
call memory('A','I',maxna,'siesta')
1275
allocate(r2ij(maxna))
1276
call memory('A','D',maxna,'siesta')
1277
allocate(xij(3,maxna))
1278
call memory('A','D',3*maxna,'siesta')
1282
C Global reduction of energy terms
1283
call globalize_sum(Enl,buffer1)
1287
C ..................
1289
C Save or get partial Hamiltonian (non-SCF part) ......................
1290
if (first.or.last) then
1296
if (ispin .le. 2) then
1298
H(io,ispin) = H0(io)
1302
H(io,ispin) = 0.0_dp
1307
C ..................
1309
C Non-SCF part of total energy .......................................
1310
if (first.or.last) then
1311
E0 = -Eions + Ena + Ekin + Enl
1314
do ispin = 1,min(nspin,2)
1316
E0 = E0 + H0(io) * Dscf(io,ispin)
1320
C Global reduction of E0
1321
call globalize_sum(E0,buffer1)
1324
E0 = E0 - Eions + Ena
1326
C ..................
1328
C Non-local-pseudop: energy, forces, stress and matrix elements .......
1329
C Add SCF contribution to energy and matrix elements ..................
1332
C Last call to dhscf and grid-cell sampling if requested
1335
call grdsam( nspin, no_s, iaorb, iphorb,
1336
. no_l, no_u, na_u, na_s, isa, xa, indxua,
1337
. ucell, mscell, g2max, ntm, ifa, istr, maxnh,
1338
. maxnh, numh, listhptr, listh, Dscf, Datm, H,
1339
. Enaatm, Enascf, Uatm, Uscf, DUscf, DUext,
1340
. Exc, Dxc, dipol, fa, stress, fal, stressl)
1345
call dhscf( nspin, no_s, iaorb, iphorb, no_l,
1346
. no_u, na_u, na_s, isa, xa, indxua,
1347
. ucell, mscell, g2max, ntm,
1348
. ifa, istr, ihmat, ' ', ' ', ' ', ' ', ' ', ' ',
1349
. maxnh, numh, listhptr, listh, Dscf, Datm,
1350
. maxnh, numh, listhptr, listh, H,
1351
. Enaatm, Enascf, Uatm, Uscf, DUscf, DUext,
1352
. Exc, Dxc, dipol, fa, stress, fal, stressl)
1355
C Output memory use after first call to dhscf
1356
if (istp.eq.1 .and. iscf.eq.1) call printmemory( 6, 0 )
1358
* if (istp.eq.1 .and. iscf.eq.1) write(6,'(/,a,f10.3,a)')
1359
* . 'siesta: dhscf mesh cutoff =', g2max, ' Ry'
1361
C ..................
1363
C Orthonormalization forces ...........................................
1365
call overfsm(na_u, na_s, no_s, scell, xa, indxua,rmaxo,no_l,
1366
. maxna, maxnh, maxnh, lasto, iphorb, isa,
1367
. numh, listhptr, listh, numh, listhptr, listh,
1368
. min(nspin,2), Escf, jna, xij, r2ij,
1371
C ..................
1373
C Metadynamics forces
1374
if (lMetaForce.and.(first.or.last)) then
1375
call meta(xa,na_u,ucell,Emeta,fa,stress,last,last)
1378
C Find entropy ........................................................
1379
C Entropy is returned from the call to diagon. To add to the energy
1380
C the entropy computed from the input charge, here it is assigned to the one
1381
C of the former SCF step
1384
if (isolve .eq. 0) then
1385
if (istp.gt.1 .or. iscf.gt.1) then
1390
C Save present density matrix ........................................
1393
Dold(io,is) = Dscf(io,is)
1394
Eold(io,is) = Escf(io,is)
1398
C Save Hamiltonian and overlap matrices ............................
1400
call iohs( 'write', gamma, no_u, no_s, nspin, indxuo,
1401
$ maxnh, numh, listhptr, listh, H, S, qtot, temp,
1405
C Solve eigenvalue problem .........................................
1407
if (isolve .eq. 0) then
1408
call diagon(no_s, nspin, nspin, no_l, maxnh, maxnh, no_u,
1409
. numh, listhptr, listh, numh, listhptr, listh,
1410
. H, S, qtot, fixspin, qs, temp, e1, e2,
1411
. gamma, xijo, indxuo, nkpnt, kpoint, kweight,
1412
. eo, qo, Dscf, Escf, ef, efs, Entrop, no_u,
1413
. occtol, iscf, neigwanted)
1416
elseif (isolve .eq. 1) then
1417
if (.not. gamma) call die("Cannot do O(N) with k-points.")
1418
call ordern(usesavelwf,ioptlwf,na_s,no_s,no_l,lasto,isa,qa,
1419
. rcoor,rmaxh,ucell,xa,iscf,istp,ncgmax,etol,eta,
1420
. qtot,maxnh,numh,listhptr,listh,H,S,
1421
. chebef,noeta,rcoorcp,beta,pmax,Dscf,Escf,
1425
call die('siesta: ERROR: wrong solution method')
1428
C Harris-functional energy ............................................
1431
C const factor takes into account that there are two nondiagonal
1432
C elements in non-collinear spin density matrix, stored as
1433
C ispin=1 => D11; ispin=2 => D22, ispin=3 => Real(D12);
1434
C ispin=4 => Imag(D12)
1436
if (ispin .gt. 2) const = 2._dp
1438
DEharr = DEharr + H(io,ispin) * const *
1439
. ( Dscf(io,ispin) - Dold(io,ispin) )
1443
C Global reduction of DEharr
1444
call globalize_sum(DEharr,buffer1)
1447
C ..................
1449
C Print populations at each SCF step if requested before mixing ......
1453
. 'siesta: Mulliken populations before mixing'
1454
call mulliken( mullipop, nspin, na_u, no_u, maxnh,
1455
. numh, listhptr, listh, S, Dscf, isa,
1456
. lasto, iaorb, iphorb )
1458
C ..................
1459
C Mix input and output energy-density and density matrices ............
1460
C Following line for using and saving the density matrix without mix ..
1461
if (wmix.ne.0._dp) then
1462
C Pulay or Broyden mixing
1465
if (maxsav .le. 0) then
1467
if (iscf .ne. 1) mmix = .true.
1469
if (broyden_maxit == 0) then
1470
call pulayx( pulfile, iiscf, mmix, no_l, no_s, maxnh,
1471
. numh, listhptr, nspin, maxsav, wmix, nkick,
1472
. wmixkick, auxpul(1,1), auxpul(1,2), nauxpul,
1473
. Dscf, Dold, dDmax)
1475
call broyden_mixing(iscf, mix, no_l, maxnh,
1476
. numh(1:no_l), listhptr(1:no_l), nspin,
1477
$ wmix, nkick, wmixkick, Dscf, Dold, dDmax)
1481
C Ensure that dDmax is the same on all nodes for convergence test/output
1483
call globalize_max(dDmax,buffer1)
1486
C ...................
1488
C Print populations at each SCF step, if requested, after mixing ......
1492
. 'siesta: Mulliken populations after mixing'
1493
call mulliken( mullipop, nspin, na_u, no_u, maxnh,
1494
. numh, listhptr, listh, S, Dscf, isa,
1495
. lasto, iaorb, iphorb )
1497
C ..................
1499
C Save density matrix on disk, after mixing ...........................
1501
if ((idyn .eq. 6) .or. (idyn .eq. 7)) then
1503
. call iodm( 'write', maxnh, no_l, nspin,
1504
. numh, listhptr, listh, Dscf, found )
1506
call iodm( 'write', maxnh, no_l, nspin,
1507
. numh, listhptr, listh, Dscf, found )
1512
C Add on force field contribution if required
1513
if (first.or.last) then
1514
call twobody(na_u,xa,isa,ucell,Emm,ifa,fa,istr,stress)
1517
C Print energies ......................................................
1518
DEna = Enascf - Enaatm
1519
Etot = E0 + DEna + DUscf + DUext + Exc + Ecorrec + Emad + Emm +
1521
Eharrs = Etot + DEharr
1522
FreeE = Etot - Temp * Entropy
1523
C Recalculating the energy in the last iter (for gridcellsampling)
1524
C but preserving the value of Eharrs1
1525
if (.not.last) Eharrs1 = Eharrs
1527
if (IOnode.and..not.last) then
1528
call siesta_write_energies()
1531
write(6,"(/a,f14.6,/)") 'siesta: Eharris(eV) = ', Eharrs/eV
1533
call cmlStartPropertyList(mainXML, title='SCF Cycle')
1534
call cmlAddProperty(xf=mainXML, property=Eharrs/eV,
1535
. units="siestaUnits:eV", dictRef="siesta:Eharrs",
1537
call cmlEndPropertyList(mainXML)
1541
C ...................
1543
! End of one SCF step - flush stdout
1546
call wallclock("-------------- end of scf step")
1549
C If last iteration, exit SCF loop ....................................
1553
Dscf(io,ispin) = Dold(io,ispin)
1554
Escf(io,ispin) = Eold(io,ispin)
1557
if (dumpcharge) then
1558
call plcharge( no_s, na_s, no_u, maxnh, maxna, nspin,
1559
. isa, iphorb, indxuo, lasto,
1560
. scell, nsc, xa, rmaxo, datm )
1562
call timer( 'IterSCF', 2 )
1563
if (cml_p) call cmlEndStep(mainXML)
1566
C ...................
1568
C If converged, make last iteration to find forces ....................
1569
dEmax = abs(Etot - Elast)
1571
if (require_energy_convergence) then
1572
if (dDmax.lt.dDtol.and.dEmax.lt.dEtol) last = .true.
1574
if (dDmax.lt.dDtol) last = .true.
1576
C ...................
1578
call timer( 'IterSCF', 2 )
1579
if (istep.eq.inicoor .and. first) call timer( 'IterSCF', 3 )
1581
if (cml_p) call cmlEndStep(mainXML)
1584
C End of SCF iteration_________________________________________________
1586
C Write final Kohn-Sham Energy ........................................
1587
if (cml_p) call cmlStartPropertyList(mainXML,
1588
. title='Final KS Energy')
1590
if ( .not. harrisfun)
1591
. write(6,"(/a,f14.4)") 'siesta: E_KS(eV) = ', Etot/eV
1592
if (cml_p) call cmlAddProperty(xf=mainXML, property=Etot/eV,
1593
. dictref='siesta:E_KS', units='siestaUnits:eV',
1597
C Substract egg box effect form energy ................................
1598
if (eggbox_block) then
1599
call eggbox('energy',ucell,na_u,isa,ntm,xa,fa,Etot,
1602
. write(6,"(/a,f14.4)") 'siesta: E_KS - E_eggbox = ',Etot/eV
1603
if (cml_p) call cmlAddProperty(xf=mainXML, property=Etot/eV,
1604
. dictref='siesta:E_KS_egg', units='siestaUnits:eV',
1607
if (cml_p) call cmlEndPropertyList(mainXML)
1610
C Global reduction of forces and stresses
1611
allocate(fatmp(3,na_u))
1612
call memory('A','D',3*na_u,'siesta')
1613
call globalize_sum(stressl(1:3,1:3),stresstmp(1:3,1:3))
1614
call globalize_sum(fal(1:3,1:na_u),fatmp(1:3,1:na_u))
1615
stress(1:3,1:3) = stress(1:3,1:3) + stresstmp(1:3,1:3)
1616
fa(1:3,1:na_u) = fa(1:3,1:na_u) + fatmp(1:3,1:na_u)
1617
call memory('D','D',size(fatmp),'siesta')
1620
stress(1:3,1:3) = stress(1:3,1:3) + stressl(1:3,1:3)
1621
fa(1:3,1:na_u) = fa(1:3,1:na_u) + fal(1:3,1:na_u)
1624
C Substract egg box effect from the forces ............................
1625
if (eggbox_block) then
1626
call eggbox('forces',ucell,na_u,isa,ntm,xa,fa,Etot,eggbox_block)
1628
C ...................
1629
! Compute stress without internal molecular pressure
1630
call remove_intramol_pressure(ucell,stress,na_u,xa,fa,mstress)
1632
C Impose constraints to atomic movements by changing forces ...........
1633
if (RemoveIntraMolecularPressure) then
1634
! Consider intramolecular pressure-removal as another
1635
! kind of constraint
1636
call fixed(ucell,mstress,na_u,isa, amass, xa, fa,
1637
$ cstress, cfa, ntcon )
1639
call fixed(ucell,stress,na_u,isa, amass, xa, fa,
1640
$ cstress, cfa, ntcon )
1643
C ...................
1645
C Write atomic forces .................................................
1654
ftot(ix) = ftot(ix) + ftem
1655
fres = fres + ftem*ftem
1656
fmax = max( fmax, dabs(ftem) )
1657
cfmax = max( cfmax, dabs(cftem) )
1660
fres = dsqrt( fres / (3.0_dp*na_u) )
1662
C Calculate and output Zmatrix forces
1663
if (lUseZmatrix) then
1664
call CartesianForce_to_ZmatForce(na_u,xa,fa)
1665
if (IOnode) call iofaZmat
1668
! Compute kinetic contribution to stress
1669
kin_stress(1:3,1:3) = 0.0_dp
1673
kin_stress(ix,jx) = kin_stress(ix,jx) -
1674
. amu * amass(ia) * va(ix,ia) * va(jx,ia) / volume
1678
! Add kinetic term to stress tensor
1679
tstress = stress + kin_stress
1681
C Force output .......................................................
1683
call siesta_write_forces()
1684
call siesta_write_stress_pressure()
1685
call wallclock('--- end of geometry step')
1688
C Mulliken population analysis .......................................
1689
call mulliken( mullipop, nspin, na_u, no_u, maxnh,
1690
. numh, listhptr, listh, S, Dscf, isa,
1691
. lasto, iaorb, iphorb )
1693
! Save structural information in crystallographic format,
1694
! and canonical Zmatrix (if applicable) before moving the atoms
1697
call write_struct( ucell, na_u, isa, iza, xa )
1698
if (lUseZmatrix) then
1699
call write_canonical_ucell_and_Zmatrix()
1703
C Save the last coordinates for which the density matrix has been calculated
1704
C or at every coor step if calculating the BECs (the polarisation uses xalast)
1705
if ( (istep.eq.fincoor) .or. bornz ) then
1706
xalast(1:3,1:na_s)=xa(1:3,1:na_s)
1717
C Move atoms ..........................................................
1720
if (nmove .ne. 0) then
1721
if (RelaxCellOnly) then
1722
call cell_broyden_optimizer( na_u, xa, ucell,
1723
$ cstress, volume, tp, strtol,
1727
if (lUseZmatrix) then
1728
if (broyden_optim) then
1729
call zm_broyden_optimizer( na_u, xa, cfa, ucell,
1730
$ cstress, volume, dxmax, tp, ftol, strtol,
1733
call cgvc_zmatrix( na_u, xa, cfa, ucell, cstress,
1734
$ volume, dxmax, tp, ftol, strtol, varcel,
1735
$ relaxd, usesavecg )
1738
if (broyden_optim) then
1739
call broyden_optimizer( na_u, xa, cfa, ucell,
1740
$ cstress, volume, dxmax, tp, ftol, strtol,
1743
call cgvc( na_u, xa, cfa, ucell, cstress, volume,
1744
$ dxmax, tp, ftol, strtol, varcel,
1745
$ relaxd, usesavecg )
1748
endif ! RelaxCellOnly
1750
! Propagate the new structure to the virtual supercell
1751
call superx( ucell, nsc, na_u, na_s, xa, scell )
1753
! Exit coordinate relaxation loop
1757
call verlet2(istp, iunit, iquench, na_u, cfa, dt,
1758
. amass, ntcon, va, xa, Ekinion, tempion)
1759
! Propagate the new structure to the virtual supercell
1760
call superx( ucell, nsc, na_u, na_s, xa, scell )
1761
! Check convergence for quenching runs (which are
1762
! really relaxations)
1763
if ( iquench .ne. 0 ) then
1767
relaxd = relaxd .and. ( abs(cfa(i,ia)) .lt. ftol )
1773
call nose(istp, iunit, na_u, cfa, tt, dt, amass, mn,
1774
. ntcon, va, xa, Ekinion, kn, vn, tempion)
1775
! Propagate the new structure to the virtual supercell
1776
call superx( ucell, nsc, na_u, na_s, xa, scell )
1779
call pr(istp, iunit, iquench, na_u, cfa, cstress, tp, dt,
1780
. amass, mpr, ntcon, va, xa, vcell, ucell, Ekinion,
1781
. kpr, vpr, tempion, Pint)
1782
! Propagate the new structure to the virtual supercell
1783
call superx( ucell, nsc, na_u, na_s, xa, scell )
1784
if (IOnode) write(6,'(/,a,f12.3,a)')
1785
. 'siesta: E_kin PR =', kpr/Kelvin, ' K'
1788
call npr(istp, iunit, na_u, cfa, cstress, tp, tt, dt,
1789
. amass, mn, mpr, ntcon, va, xa, vcell, ucell,
1790
. Ekinion, kn, kpr, vn, vpr, tempion, Pint)
1791
! Propagate the new structure to the virtual supercell
1792
call superx( ucell, nsc, na_u, na_s, xa, scell )
1795
call anneal(istp, iunit, ianneal, taurelax, bulkm,
1796
. na_u, cfa, cstress, tp, tt, dt, amass, ntcon,
1797
. va, xa, ucell, Ekinion, tempion, Pint)
1798
! Propagate the new structure to the virtual supercell
1799
call superx( ucell, nsc, na_u, na_s, xa, scell )
1802
continue !We can't go until after ioxv - see below
1805
call forcesToPipe( na_u, Etot, cfa, cstress )
1809
if (idyn .gt. 0 .and. idyn .lt. 6) then
1810
write(6,'(/,a,f12.3,a)')
1811
. 'siesta: Temp_ion =', tempion, ' K'
1815
C Save last atomic positions and velocities
1816
C (it should be before moving atoms!)
1817
call ioxv( 'write', ucell, vcell, na_u, isa, iza, xa, va, foundxv)
1819
. call iozm('write',ucell,vcell,xa,foundzm)
1820
call siesta_write_positions
1821
C ...................
1823
C Restore original coordinates after FC displacements
1824
if (idyn .eq. 6 .and. istep .ne. 0) then
1825
xa(ixdispl,iadispl)=xa(ixdispl,iadispl)-dx
1827
if (idyn .eq. 7) then
1828
call phonon_restore_coords(istep,xa,ucell)
1831
C Save atomic positions and velocities accumulatively ................
1832
if (writmd.and.IOnode) then
1833
if ( .not. harrisfun) then
1836
Etot_output = Eharrs1
1838
getot = Etot_output + Ekinion + kn + kpr + vn + vpr
1839
call iomd( na_u, isa, iza,
1840
. xa, va, ucell, vcell, varcel, istep, inicoor,
1841
. fincoor, tempion, Etot_output, getot,
1842
$ volume/Ang**3, Psol/kbar)
1843
call md_v_format(na_u,isa,xa,ucell)
1845
call md_netcdf( na_u, isa, iza,
1846
. xa, va, ucell, vcell, varcel,
1847
. tempion, Etot_output, getot,
1848
$ volume/Ang**3, Psol/kbar)
1853
C Accumulate coor in Xmol file for animation .........................
1854
lastst = fincoor .le. istep
1855
if (writpx.and.IOnode)
1856
. call pixmol(iza, xa, na_u, lastst)
1857
C ...................
1859
C******************Born charge calculation***************************
1861
if (mod(istep,2) .eq. 0 ) then
1862
if (nkpol.lt.1) then
1863
if (IOnode) write(6,'(/,a,f12.6)')
1864
. 'siesta: specify polarization grid for BC calculation'
1865
if (IOnode) write(6,'(a,f12.6)')
1866
. 'siesta: The Born charge matrix will not be calculated'
1869
if (IOnode) write(6,'(/,a,f12.6)')
1870
. 'siesta: Calculating polarization. '
1872
C Find total population of spin up and down
1873
if (nspin .ge. 2) then
1875
qspin(ispin) = 0.0_dp
1878
ind = listhptr(io) + j
1879
qspin(ispin) = qspin(ispin)
1880
. + Dscf(ind,ispin)*S(ind)
1885
C Global reduction of spin components
1886
call globalize_sum(qspin(1:nspin),qtmp(1:nspin))
1887
qspin(1:nspin) = qtmp(1:nspin)
1890
if (nkpol.gt.0) then
1891
call KSV_pol(na_u, na_s, xalast, rmaxo, scell, ucell,
1892
. no_u, no_l, no_s, nspin, qspin, maxna,
1893
. maxnh, nkpol, numh, listhptr, listh,
1894
. H, S, H0, xijo, indxuo, isa, iphorb,
1895
. iaorb, lasto, jna, xij, r2ij,shape,
1896
. nkpol,kpol,wgthpol, polR, polxyz)
1898
if (nkpol.gt.0.and.IOnode) then
1899
call obc( polxyz, polR, ucell, dx, nspin, node )
1904
C*************End born charge calculation******************
1907
C Output memory use at the end of this geometry step
1908
if (cml_p) call cmlEndStep(mainXML)
1909
call printmemory( 6, 0 )
1910
call timer( 'IterMD', 2 )
1912
C End of one MD step - flush stdout
1913
if (ionode) call pxfflush(6)
1918
C End of coordinate-relaxation loop ==================================
1921
! We want xalast to equal xa for coordinate relaxation only.
1922
if (idyn==0) xalast(1:3,1:na_s)=xa(1:3,1:na_s)
1925
call cmlStartModule(xf=mainXML, title='Finalization')
1929
C Print atomic coordinates (and also unit cell for ParrRah.)
1930
if (nmove .ne. 0) then
1932
. call outcoor(ucell, xa, na_u, 'Relaxed', .true. )
1934
. call outcoor(ucell, xa, na_u,
1935
. 'Final (unrelaxed)', .true. )
1937
call siesta_write_positions()
1938
if (lUseZmatrix) call write_Zmatrix
1939
if ( varcel .or. (idyn.eq.8)) call outcell(ucell)
1941
C Print coordinates in xmol format in a separate file
1943
if (fdf_boolean('WriteCoorXmol',.false.))
1944
. call coxmol(iza, xa, na_u )
1946
C Print coordinates in cerius format in a separate file
1948
if (fdf_boolean('WriteCoorCerius',.false.))
1949
. call coceri(iza, xa, ucell, na_u, sname )
1951
C Find interatomic distances (output in file BONDS_FINAL)
1953
call bonds( ucell, na_u, isa, xa,
1954
$ rmax_bonds, trim(slabel) // ".BONDS_FINAL" )
1958
C Find and print wavefunctions at selected k-points
1960
call wwave( no_s, nspin, nspin, no_u, no_l, maxnh, maxwk,
1961
. numh, listhptr, listh, H, S, Ef, xijo, indxuo,
1962
. nwk, wfk, no_u, gamma, occtol )
1965
C Find and print bands
1967
call bands( no_s, nspin, nspin, no_u, no_l, maxnh, maxbk,
1968
. numh, listhptr, listh, H, S, Ef, xijo, indxuo,
1969
. .true., nbk, bk, ebk, no_u, occtol )
1972
write(6,'(/,a,/,a4,a12)')
1973
. 'siesta: Band k vectors (Bohr**-1):', 'ik', 'k'
1975
write(6,'(i4,3f12.6)') ik, (bk(ix,ik),ix=1,3)
1980
write(6,'(/,a,/,a4,a3,a7)')
1981
. 'siesta: Band energies (eV):', 'ik', 'is', 'eps'
1982
do ispin = 1,min(nspin,2)
1984
write(6,'(i4,i3,10f7.2)')
1985
. ik, ispin, (ebk(io,ispin,ik)/eV,io=1,min(10,no_u))
1986
if (no_u.gt.10) write(6,'(7x,10f7.2)')
1987
. (ebk(io,ispin,ik)/eV,io=11,no_u)
1995
if (IOnode .and. writeig) then
1996
if (isolve.eq.0 .and. no_l.lt.1000) then
1997
if (nspin .le. 2) then
1998
write(6,'(/,a,/,a4,a3,a7)')
1999
. 'siesta: Eigenvalues (eV):', 'ik', 'is', 'eps'
2002
write(6,'(i4,i3,10f7.2)')
2003
. ik,ispin,(eo(io,ispin,ik)/eV,io=1,min(10,neigwanted))
2004
if (no_u.gt.10) write(6,'(7x,10f7.2)')
2005
. (eo(io,ispin,ik)/eV,io=11,neigwanted)
2009
write(6,'(/,a)') 'siesta: Eigenvalues (eV):'
2011
write(6,'(a,i6)') 'ik =', ik
2013
. ((eo(io,ispin,ik)/eV,io=1,neigwanted),ispin=1,2)
2016
write(6,'(a,f15.6,a)') 'siesta: Fermi energy =', ef/eV, ' eV'
2020
if (isolve.eq.0.and.IOnode)
2021
. call ioeig(eo,ef,neigwanted,nspin,nkpnt,no_u,nspin,maxk,
2024
C Compute the projected density of states
2026
do_pdos = fdf_block('ProjectedDensityOfStates',iu)
2027
if (isolve.ne.0.and.do_pdos) then
2029
. 'siesta: ERROR: PDOS implemented only with diagon'
2033
call broadcast(do_pdos)
2036
C Find the desired energy range
2040
if (nvalues(p).lt.3 .or. nnames(p).ne.1)
2041
$ call die("Wrong format in PDOS block")
2042
factor = fdf_convfac( names(p,1), 'Ry' )
2043
e1 = values(p,1) * factor
2044
e2 = values(p,2) * factor
2045
sigma = values(p,3) * factor
2046
nhist = integers(p,1)
2047
write(6,'(a)') 'siesta: PDOS info: '
2048
write(6,'(a,3(f8.2,a),2x,i5)')
2049
$ 'siesta: e1, e2, sigma, nhist: ',
2050
$ e1/eV,' eV',e2/eV,' eV',sigma/eV,' eV', nhist
2055
call broadcast(sigma)
2056
call broadcast(nhist)
2058
call pdos( no_s, nspin, nspin, no_l, maxnh,
2059
. no_u, numh, listhptr, listh, H, S,
2060
. e1, e2, sigma, nhist,
2061
. gamma, xijo, indxuo, nkpnt, kpoint, kweight, eo,
2064
endif ! PDOS calc (do_pdos)
2066
C Print program's energy decomposition and final forces
2068
call siesta_write_energies()
2069
call siesta_write_forces()
2070
call siesta_write_stress_pressure()
2071
call write_basis_enthalpy(FreeE)
2074
C Print spin polarization
2075
if (nspin .ge. 2) then
2077
qspin(ispin) = 0.0_dp
2080
ind = listhptr(io)+j
2082
qspin(ispin) = qspin(ispin) + Dscf(ind,ispin) * S(ind)
2088
C Global reduction of spin components
2089
call globalize_sum(qspin(1:nspin),qtmp(1:nspin))
2090
qspin(1:nspin) = qtmp(1:nspin)
2092
if (nspin .eq. 2) then
2094
write(6,'(/,a,f12.6)')
2095
. 'siesta: Total spin polarization (Qup-Qdown) =',
2096
. qspin(1) - qspin(2)
2098
if (cml_p) call cmlAddProperty(xf=mainXML,
2099
. property=qspin(1)-qspin(2), dictref='siesta:qspin')
2100
elseif (nspin .eq. 4) then
2101
call spnvec( nspin, qspin, qaux, stot, svec )
2103
write(6,'(/,a,f12.6)')
2104
. 'siesta: Total spin polarization (Qup-Qdown) =', stot
2105
write(6,'(a,3f12.6)') 'siesta: Spin vector =', svec
2107
call cmlAddProperty(xf=mainXML, property=stot,
2108
. dictref='siesta:stot')
2109
call cmlAddProperty(xf=mainXML, property=svec,
2110
. dictref='siesta:svec')
2116
C Print electric dipole
2117
if (shape .ne. 'bulk') then
2119
write(6,'(/,a,3f12.6)')
2120
. 'siesta: Electric dipole (a.u.) =', dipol
2121
write(6,'(a,3f12.6)')
2122
. 'siesta: Electric dipole (Debye) =',
2123
. (dipol(ix)/Debye,ix=1,3)
2126
call cmlAddProperty(xf=mainXML, property=dipol,
2127
. title='Electric dipole', dictref='siesta:dipol',
2128
. units='siestaUnits:atomic')
2132
C Calculation of the bulk polarization using the Berry phase
2133
C formulas by King-Smith and Vanderbilt
2134
C Attention H0 is used as an auxiliary array
2135
if (nkpol.gt.0 .and. .not.bornz) then
2136
call KSV_pol(na_u, na_s, xalast, rmaxo, scell, ucell,
2137
. no_u, no_l, no_s, nspin, qspin, maxna,
2138
. maxnh, nkpol, numh, listhptr, listh,
2139
. H, S, H0, xijo, indxuo, isa, iphorb,
2140
. iaorb, lasto, jna, xij, r2ij,shape,
2141
. nkpol,kpol,wgthpol, polR, polxyz )
2144
C Calculation of the optical conductivity
2145
C Attention H0, Eold, Dold are used as auxiliary arrays
2146
call optical(na_u, na_s, xa, scell, ucell,
2147
. no_u, no_l, no_s, nspin, qspin,
2148
. maxna, maxnh, numh, listhptr, listh, H, S, H0,
2149
. Eold(1,1), Dold(1,1),
2150
. xijo, indxuo, indxua, ebk, ef, temp,
2151
. isa, iphorb, iphKB, iaorb, lasto, lastkb,
2152
. jna, xij, r2ij, shape )
2154
c...................................
2156
C Save electron density and potential
2157
call fdf_global_get(savrho,'SaveRho',
2158
$ dumpcharge .or. .false.)
2159
call fdf_global_get(savdrh,'SaveDeltaRho', .false.)
2160
call fdf_global_get(savevh,'SaveElectrostaticPotential',
2162
call fdf_global_get(savevt,'SaveTotalPotential', .false.)
2163
call fdf_global_get(savepsch,'SaveIonicCharge', .false.)
2164
call fdf_global_get(savetoch,'SaveTotalCharge', .false.)
2166
if (savrho .or. savdrh .or. savevh .or. savevt .or.
2167
. savepsch .or. savetoch ) then
2174
if (savrho) filrho = paste( slabel, '.RHO' )
2175
if (savdrh) fildrh = paste( slabel, '.DRHO' )
2176
if (savevh) filevh = paste( slabel, '.VH' )
2177
if (savevt) filevt = paste( slabel, '.VT' )
2178
if (savepsch) filepsch = paste( slabel, '.IOCH' )
2179
if (savetoch) filetoch = paste( slabel, '.TOCH' )
2181
call dhscf( nspin, no_s, iaorb, iphorb, no_l,
2182
. no_u, na_u, na_s, isa, xa, indxua,
2183
. ucell, mscell, g2max, ntm,
2184
. 0, 0, 0, filrho, fildrh, filevh, filevt,
2185
. filepsch, filetoch,
2186
. maxnh, numh, listhptr, listh, Dscf, Datm,
2187
. maxnh, numh, listhptr, listh, H,
2188
. Enaatm, Enascf, Uatm, Uscf, DUscf, DUext, Exc, Dxc,
2189
. dipol, fa, stress, fal, stressl )
2192
c Find local density of states
2194
genlogic = fdf_block('LocalDensityOfStates',iu)
2196
call broadcast(genlogic)
2198
if ( genlogic ) then
2200
C Find the desired energy range
2204
if (.not. match(p,"vvn"))
2205
. call die("Wrong format in LocalDensityofStates")
2206
factor = fdf_convfac( names(p,1), 'Ry' )
2207
e1 = values(p,1)*factor
2208
e2 = values(p,2)*factor
2214
! Find the density matrix for states between e1 and e2
2215
if (isolve .eq. 0) then
2216
call diagon(no_s, nspin, nspin, no_l, maxnh, maxnh, no_u,
2217
. numh, listhptr, listh, numh, listhptr, listh,
2218
. H, S, qtot, fixspin, qs, temp, e1, e2,
2219
. gamma, xijo, indxuo, nkpnt, kpoint, kweight,
2220
. eo, qo, Dscf, Escf, ef, efs, Entrop, no_u,
2221
. occtol, iscf, neigwanted)
2223
! Find the LDOS in the real space mesh
2224
filrho = paste( slabel, '.LDOS' )
2226
call dhscf( nspin, no_s, iaorb, iphorb, no_l,
2227
. no_u, na_u, na_s, isa, xa, indxua,
2228
. ucell, mscell, g2max, ntm,
2229
. 0, 0, 0, filrho, ' ', ' ', ' ', ' ', ' ',
2230
. maxnh, numh, listhptr, listh, Dscf, Datm,
2231
. maxnh, numh, listhptr, listh, H,
2232
. Enaatm, Enascf, Uatm, Uscf, DUscf, DUext, Exc, Dxc,
2233
. dipol, fa, stress, fal, stressl )
2235
if (IOnode) write(6,*)
2236
. 'siesta: ERROR: LDOS implemented only with diagon'
2241
C Output memory use up to the end of the program
2242
call printmemory( 6, 1 )
2244
C Print allocation report
2245
call alloc_report( printNow=.true. )
2248
call timer( 'siesta', 2 )
2249
call timer( 'all', 3 )
2251
C Print final date and time
2253
call timestamp('End of run')
2254
call wallclock('End of run')
2259
call MPI_Finalize( MPIerror )
2263
call cmlEndModule(mainXML)
2264
call siesta_cml_exit()
2268
! Internal subroutines follow.
2273
subroutine siesta_write_forces()
2275
! Almost the same forces output whether during simulation
2276
! or at the end. Unfortunately not quite, therefore slightly
2277
! tortuous logic below. If we are content to change format
2278
! of output file slightly, this can be simplified.
2279
if (.not.final) then
2280
! print forces to xml every step.
2281
! output forces to stdout depending on writef
2283
call cmlStartPropertyList(mainXML, title='Forces')
2284
call cmlAddProperty(xf=mainXML, property=fa*Ang/eV,
2285
. dictref='siesta:forces', units='siestaUnits:evpa')
2286
call cmlAddProperty(xf=mainXML, property=ftot,
2287
. dictref='siesta:ftot')
2288
call cmlAddProperty(xf=mainXML, property=fmax,
2289
. dictref='siesta:fmax')
2290
call cmlAddProperty(xf=mainXML, property=fres,
2291
. dictref='siesta:fres')
2292
call cmlAddProperty(xf=mainXML, property=cfmax,
2293
. dictref='siesta:cfmax')
2294
call cmlEndPropertyList(mainXML)
2296
write(6,'(/,a)') 'siesta: Atomic forces (eV/Ang):'
2298
write(6,'(i6,3f12.6)')(ia,(fa(ix,ia)*Ang/eV,ix=1,3),ia=1,na_u)
2300
call iofa( na_u, fa )
2302
write(6,'(40("-"),/,a6,3f12.6)') 'Tot',(ftot(ix)*Ang/eV,ix=1,3)
2303
write(6,'(40("-"),/,a6, f12.6)') 'Max',fmax*Ang/eV
2304
write(6,'(a6,f12.6,a)')'Res',fres*Ang/eV,
2305
. ' sqrt( Sum f_i^2 / 3N )'
2306
write(6,'(40("-"),/,a6, f12.6,a)') 'Max',cfmax*Ang/eV,
2309
C In finalization, only print forces if sufficiently large.
2310
fmax = maxval(abs(fa))
2311
ftot = sum(fa, dim=2)
2312
if (fmax .gt. ftol) then
2313
write(6,'(/,a)') 'siesta: Atomic forces (eV/Ang):'
2314
write(6,'(a,i6,3f12.6)')
2315
. ('siesta: ', ia,(fa(ix,ia)*Ang/eV,ix=1,3),ia=1,na_u)
2316
write(6,'(a,40("-"),/,a,a6,3f12.6)')
2317
. 'siesta: ','siesta: ','Tot',(ftot(ix)*Ang/eV,ix=1,3)
2319
call cmlStartPropertyList(mainXML, title='Force Summary')
2320
call cmlAddProperty(xf=mainXML, property=fa*Ang/eV,
2321
. dictref='siesta:forces', units='siestaUnits:evpa')
2322
call cmlAddProperty(xf=mainXML, property=ftot*Ang/eV,
2323
. dictref='siesta:ftot', units='siestaUnits:evpa')
2324
call cmlEndPropertyList(mainXML)
2327
if (Any(cfa /= fa)) then
2328
fmax = maxval(abs(cfa))
2329
ftot = sum(cfa, dim=2)
2330
if (fmax .gt. ftol) then
2331
write(6,'(/,a)') 'siesta: Constrained forces (eV/Ang):'
2332
write(6,'(a,i6,3f12.6)')
2333
. ('siesta: ',ia,(cfa(ix,ia)*Ang/eV,ix=1,3),ia=1,na_u)
2334
write(6,'(a,40("-"),/,a,a4,3f12.6)')
2335
. 'siesta: ','siesta: ','Tot',(ftot(ix)*Ang/eV,ix=1,3)
2337
call cmlStartPropertyList(mainXML,
2338
. title='Constrained Force Summary')
2339
call cmlAddProperty(xf=mainXML, property=cfa*Ang/eV,
2340
. dictref='siesta:cforces', units='siestaUnits:evpa')
2341
call cmlAddProperty(xf=mainXML, property=ftot*Ang/eV,
2342
. dictref='siesta:cftot', units='siestaUnits:evpa')
2343
call cmlEndPropertyList(mainXML)
2347
endif !final for forces
2349
end subroutine siesta_write_forces
2352
subroutine siesta_write_stress_pressure()
2353
use zmatrix, only: nZmol, nZmolStartAtom
2354
use zmatrix, only: nZmolAtoms
2356
integer :: ifirst, ilast, natoms_mol, imol
2357
! Stress tensor and pressure:
2360
if (.not.final) then
2362
! Write Voigt components of total stress tensor
2364
ps = stress + kin_stress
2365
write(6,'(/,a,6f12.2))')
2366
. 'Stress-tensor-Voigt (kbar):',
2367
. (ps(jx,jx)/kbar,jx=1,3),
2371
Press = - ((ps(1,1) + ps(2,2) + ps(3,3))/3.0_dp)
2372
write(6,"(a,f14.4)") "Enthalpy (eV/cell)",
2373
$ (FreeE + Press*volume)/eV
2375
if (RemoveIntraMolecularPressure) then
2376
ps = mstress + kin_stress
2377
write(6,'(/,a,6f12.2))')
2378
. 'Non-Molecular-Stress-Voigt (kbar):',
2379
. (ps(jx,jx)/kbar,jx=1,3),
2383
Press = - ((ps(1,1) + ps(2,2) + ps(3,3))/3.0_dp)
2384
write(6,"(a,f14.4)") "Non-Molecular Enthalpy (eV/cell)",
2385
$ (FreeE + Press*volume)/eV
2388
! Write "target enthalpy" (E + pV, where p is the *target* pressure)
2389
write(6,"(a,f14.4)") "Target enthalpy (eV/cell)",
2390
$ (FreeE + tp*volume)/eV
2392
! Output depends on dynamics option
2395
if (idyn==0 .and. (.not.varcel)) then
2398
write(6,'(/,a,3(/,a,3f12.6))')
2399
. 'siesta: Stress tensor (static) (eV/Ang**3):',
2400
. (' ',(stress(jx,ix)*Ang**3/eV,jx=1,3),ix=1,3)
2401
Psol = - ((stress(1,1) + stress(2,2) + stress(3,3))/3.0_dp)
2402
write(6,'(/,a,f20.8,a)')
2403
. 'siesta: Pressure (static):', Psol/kBar, ' kBar'
2405
call cmlAddProperty(xf=mainXML, property=stress*Ang**3,
2406
. dictref='siesta:stress')
2407
call cmlAddProperty(xf=mainXML, property=Psol,
2408
. dictref='siesta:psol', title='Pressure (Static)')
2411
write(6,'(/,a,3(/,a,3f12.6))')
2412
. 'siesta: Stress tensor (total) (eV/Ang**3):',
2413
. (' ',(tstress(jx,ix)*Ang**3/eV,jx=1,3),ix=1,3)
2414
Psol = - ((tstress(1,1)+tstress(2,2) +tstress(3,3))/3.0_dp)
2415
write(6,'(/,a,f20.8,a)')
2416
. 'siesta: Pressure (total):', Psol/kBar, ' kBar'
2418
call cmlAddProperty(xf=mainXML, property=tstress*Ang**3,
2419
. dictref='siesta:tstress')
2420
call cmlAddProperty(xf=mainXML, property=Psol,
2421
. dictref='siesta:tpsol', title='Pressure (Total)')
2424
if (RemoveIntraMolecularPressure) then
2426
write(6,'(/,a,3(/,a,3f12.6))')
2427
. 'siesta: Stress tensor (nonmol) (eV/Ang**3):',
2428
. (' ',(ps(jx,ix)*Ang**3/eV,jx=1,3),ix=1,3)
2429
Psol = - ((ps(1,1) + ps(2,2) + ps(3,3))/3.0_dp)
2430
write(6,'(/,a,f20.8,a)')
2431
. 'siesta: Pressure (nonmol):', Psol/kBar, ' kBar'
2433
call cmlAddProperty(xf=mainXML, property=ps*Ang**3,
2434
. dictref='siesta:mstress')
2435
call cmlAddProperty(xf=mainXML, property=Psol,
2436
. dictref='siesta:pmol', title='Pressure (Nonmol)')
2439
ps = mstress + kin_stress
2440
write(6,'(/,a,3(/,a,3f12.6))')
2441
. 'siesta: Stress tensor (nonmol+kin) (eV/Ang**3):',
2442
. (' ',(ps(jx,ix)*Ang**3/eV,jx=1,3),ix=1,3)
2443
Psol = - ((ps(1,1)+ps(2,2) +ps(3,3))/3.0_dp)
2444
write(6,'(/,a,f20.8,a)')
2445
. 'siesta: Pressure (nonmol+kin):', Psol/kBar, ' kBar'
2447
call cmlAddProperty(xf=mainXML, property=ps*Ang**3,
2448
. dictref='siesta:tmstress')
2449
call cmlAddProperty(xf=mainXML, property=Psol,
2450
. dictref='siesta:tpmol', title='Pressure (Nonmol+Kin)')
2452
endif ! Remove intramolecular pressure
2456
! Write Force Constant matrix if FC calculation ...
2458
call ofc(fa,dx,na_u)
2460
call phonon_write_forces(fa,na_u,ns,ucell,istep)
2465
C Print stress tensor unconditionally
2466
write(6,'(/,a,3(/,a,3f12.6))')
2467
. 'siesta: Stress tensor (static) (eV/Ang**3):',
2468
. ('siesta: ',(stress(jx,ix)*Ang**3/eV,jx=1,3),ix=1,3)
2470
call cmlAddProperty(xf=mainXML, property=stress*Ang**3/eV,
2471
. dictref='siesta:stress', units='siestaUnits:eV_Ang__3')
2474
C Print constrained stress tensor if different from unconstrained
2475
if (Any(cstress /= stress )) then
2476
write(6,'(/,a,3(/,a,3f12.6))')
2477
. 'siesta: Constrained stress tensor (static) (eV/Ang**3):',
2478
. ('siesta: ',(cstress(jx,ix)*Ang**3/eV,jx=1,3),ix=1,3)
2480
call cmlAddProperty(xf=mainXML, property=cstress*Ang**3/eV,
2481
. dictref='siesta:cstress',
2482
. units='siestaUnits:eV_Ang__3')
2487
Psol = - (( stress(1,1) + stress(2,2) + stress(3,3) )/3.0_dp)
2488
Pmol = - (( mstress(1,1) + mstress(2,2) + mstress(3,3) )/3.0_dp)
2490
write(6,'(/,a,f18.6,a)')
2491
. 'siesta: Cell volume =', volume/Ang**3, ' Ang**3'
2492
write(6,'(/,a,/,a,2a20,a,3(/,a,2f20.8,a))')
2493
. 'siesta: Pressure (static):',
2494
. 'siesta: ','Solid', 'Molecule', ' Units',
2495
. 'siesta: ', Psol, Pmol, ' Ry/Bohr**3',
2496
. 'siesta: ', Psol*Ang**3/eV, Pmol*Ang**3/eV, ' eV/Ang**3',
2497
. 'siesta: ', Psol/kBar, Pmol/kBar, ' kBar'
2499
call cmlStartPropertyList(mainXML, title='Final Pressure')
2500
call cmlAddProperty(xf=mainXML, property=volume/Ang**3,
2501
. title='cell volume', dictref='siesta:cellvol',
2502
. units='siestaUnits:Ang__3')
2503
call cmlAddProperty(xf=mainXML, property=Psol/kBar,
2504
. title='Pressure of Solid', dictref='siesta:pressSol',
2505
. units='siestaUnits:kbar')
2506
call cmlAddProperty(xf=mainXML, property=Pmol/kBar,
2507
. title='Pressure of Molecule', dictref='siesta:pressMol',
2508
. units='siestaUnits:kbar')
2509
call cmlEndPropertyList(mainXML)
2512
endif !final for stress & pressure
2514
end subroutine siesta_write_stress_pressure
2517
subroutine siesta_write_energies()
2518
! Only print out full decomposition at very beginning and end.
2519
if ((istp==1.and.first).or.final) then
2520
write(6,'(/,a,/,(a,f17.6))')
2521
. 'siesta: Program''s energy decomposition (eV):',
2522
. 'siesta: Eions =', Eions/eV,
2523
. 'siesta: Ena =', Ena/eV,
2524
. 'siesta: Ekin =', Ekin/eV,
2525
. 'siesta: Enl =', Enl/eV,
2526
. 'siesta: DEna =', DEna/eV,
2527
. 'siesta: DUscf =', DUscf/eV,
2528
. 'siesta: DUext =', DUext/eV,
2529
. 'siesta: Exc =', Exc/eV,
2530
. 'siesta: eta*DQ =', Ecorrec/eV,
2531
. 'siesta: Emadel =', Emad/eV,
2532
. 'siesta: Emeta =', Emeta/eV,
2533
. 'siesta: Emolmec =', Emm/eV,
2534
. 'siesta: Ekinion =', Ekinion/eV,
2535
. 'siesta: Eharris =', (Eharrs1+Ekinion)/eV,
2536
. 'siesta: Etot =', (Etot+Ekinion)/eV,
2537
. 'siesta: FreeEng =', (FreeE+Ekinion)/eV
2539
call cmlStartPropertyList(mainXML,
2540
. title='Energy Decomposition')
2541
call cmlAddProperty(xf=mainXML, property=Eions/eV,
2542
. units='siestaUnits:eV',
2543
. dictref='siesta:Eions', fmt='(f17.6)')
2544
call cmlAddProperty(xf=mainXML, property=Ena/eV,
2545
. units='siestaUnits:eV',
2546
. dictref='siesta:Ena', fmt='(f17.6)')
2547
call cmlAddProperty(xf=mainXML, property=Ekin/eV,
2548
. units='siestaUnits:eV',
2549
. dictref='siesta:Ekin', fmt='(f17.6)')
2550
call cmlAddProperty(xf=mainXML, property=Enl/eV,
2551
. units='siestaUnits:eV',
2552
. dictref='siesta:Enl', fmt='(f17.6)')
2553
call cmlAddProperty(xf=mainXML, property=DEna/eV,
2554
. units='siestaUnits:eV',
2555
. dictref='siesta:DEna', fmt='(f17.6)')
2556
call cmlAddProperty(xf=mainXML, property=DUscf/eV,
2557
. units='siestaUnits:eV',
2558
. dictref='siesta:DUscf', fmt='(f17.6)')
2559
call cmlAddProperty(xf=mainXML, property=DUext/eV,
2560
. units='siestaUnits:eV',
2561
. dictref='siesta:DUext', fmt='(f17.6)')
2562
call cmlAddProperty(xf=mainXML, property=Exc/eV,
2563
. units='siestaUnits:eV',
2564
. dictref='siesta:Exc', fmt='(f17.6)')
2565
call cmlAddProperty(xf=mainXML,property=Ecorrec/eV,
2566
. units='siestaUnits:eV',
2567
. dictref='siesta:Ecorrec', fmt='(f17.6)')
2568
call cmlAddProperty(xf=mainXML, property=Emad/eV,
2569
. units='siestaUnits:eV',
2570
. dictref='siesta:Emad', fmt='(f17.6)')
2571
call cmlAddProperty(xf=mainXML, property=Emeta/eV,
2572
. units='siestaUnits:eV',
2573
. dictref='siesta:Emeta', fmt='(f17.6)')
2574
call cmlAddProperty(xf=mainXML, property=Emm/eV,
2575
. units='siestaUnits:eV',
2576
. dictref='siesta:Emm', fmt='(f17.6)')
2577
call cmlAddProperty(xf=mainXML,property=Ekinion/eV,
2578
. units='siestaUnits:eV',
2579
. dictref='siesta:Ekinion', fmt='(f17.6)')
2580
call cmlAddProperty(xf=mainXML, property=(Eharrs1+Ekinion)/eV,
2581
. units='siestaUnits:eV',
2582
. dictref='siesta:EharrsK', fmt='(f17.6)')
2583
call cmlAddProperty(xf=mainXML, property=(Etot+Ekinion)/eV,
2584
. units='siestaUnits:eV',
2585
. dictref='siesta:EtotK', fmt='(f17.6)')
2586
call cmlAddProperty(xf=mainXML, property=(FreeE+Ekinion)/eV,
2587
. units='siestaUnits:eV',
2588
. dictref='siesta:FreeEK', fmt='(f17.6)')
2589
call cmlEndPropertyList(mainXML)
2592
! On all SCF steps, print out the current energy (format depending on type of run)
2593
if (.not.final) then
2594
! Print total energy and density matrix error .........................
2596
call cmlStartPropertyList(mainXML, title='SCF Cycle')
2597
! Eharrs is always output
2598
call cmlAddProperty(xf=mainXML, property=Eharrs/eV,
2599
. units="siestaUnits:eV",
2600
. dictRef="siesta:Eharrs", fmt="(f14.7)")
2602
! This chain of if statements determines which properties are output.
2604
write(6,"(/a,f14.6,/)") 'siesta: Eharris(eV) = ', Eharrs/eV
2605
! No need for further cml output
2606
elseif (isolve==0) then
2608
. call cmlAddProperty(xf=mainXML, property=FreeE/eV,
2609
. units="siestaUnits:eV",
2610
. dictRef="siesta:FreeE", fmt="(f14.7)")
2613
call cmlAddProperty(xf=mainXML, property=Etot/eV,
2614
. units="siestaUnits:eV",
2615
. dictRef="siesta:Etot", fmt="(f14.7)")
2616
call cmlAddProperty(xf=mainXML, property=FreeE/eV,
2617
. units="siestaUnits:eV",
2618
. dictRef="siesta:FreeE", fmt="(f14.7)")
2619
call cmlAddProperty(xf=mainXML, property=dDmax/eV,
2620
. units="siestaUnits:eV",
2621
. dictRef="siesta:dDmax", fmt="(f14.7)")
2623
if ((iscf .eq. 1).or.muldeb)
2624
. write(6,'(/,a12,3a14,a8,a7,a11)')
2625
. 'siesta: iscf', ' Eharris(eV)',
2626
. ' E_KS(eV)', ' FreeEng(eV)',
2627
. ' dDmax', ' Ef_up', ' Ef_dn(eV)'
2628
write(6,'(a8,i4,3f14.4,f8.4,2f9.4)')
2629
. 'siesta: ',iscf, Eharrs/eV, Etot/eV, FreeE/eV, dDmax,
2632
call cmlAddProperty(xf=mainXML, property=Efs(1)/eV,
2633
. units="siestaUnits:eV",
2634
. dictRef="siesta:Efs", fmt="(f14.7)")
2635
call cmlAddProperty(xf=mainXML, property=Efs(2)/eV,
2636
. units="siestaUnits:eV",
2637
. dictRef="siesta:Efs", fmt="(f14.7)")
2640
if ((iscf .eq. 1).or.muldeb)
2641
. write(6,'(/,a12,3a14,2a8)')
2642
. 'siesta: iscf', ' Eharris(eV)',
2643
. ' E_KS(eV)', ' FreeEng(eV)',
2644
. ' dDmax', ' Ef(eV)'
2645
write(6,'(a8,i4,3f14.4,2f8.4)')
2646
. 'siesta: ',iscf, Eharrs/eV, Etot/eV, FreeE/eV,
2649
call cmlAddProperty(xf=mainXML,property=Ef/eV,
2650
. units="siestaUnits:eV",
2651
. dictRef="siesta:Ef", fmt="(f14.7)")
2654
elseif (isolve==1) then
2655
write(6,'(/,a15,i4)') 'siesta: iscf = ',iscf
2656
write(6,'(a14,f15.4,a13,f15.4,a10,f7.4/)')
2657
. 'Eharris(eV) = ',Eharrs/eV,
2658
. ' E_KS(eV) = ',Etot/eV,' dDmax = ',dDmax
2660
call cmlAddProperty(xf=mainXML, property=Etot/eV,
2661
. units="siestaUnits:eV",
2662
. dictRef="siesta:Etot", fmt="(f14.7)")
2663
call cmlAddProperty(xf=mainXML, property=dDmax/eV,
2664
. units="siestaUnits:eV",
2665
. dictRef="siesta:dDmax", fmt="(f14.7)")
2667
endif !harrisfun/isolve
2670
call cmlEndPropertyList(mainXML)
2674
! Print out additional information in finalization.
2676
write(6,'(/,a)') 'siesta: Final energy (eV):'
2677
write(6,'(a,a15,f15.6)')
2678
. 'siesta: ', 'Kinetic =', Ekin/eV,
2679
. 'siesta: ', 'Hartree =', Uscf/eV,
2680
. 'siesta: ', 'Ext. field =', DUext/eV,
2681
. 'siesta: ', 'Exch.-corr. =', Exc/eV,
2682
. 'siesta: ', 'Ion-electron =', (Enascf+Enl+DUscf-Uscf-Uatm)/eV,
2683
. 'siesta: ', 'Ion-ion =', (Ena+Uatm-Enaatm-Eions)/eV,
2684
. 'siesta: ', 'Ekinion =', Ekinion/eV,
2685
. 'siesta: ', 'Total =', (Etot+Ekinion)/eV
2687
call cmlStartPropertyList(xf=mainXML, title='Final Energy')
2688
call cmlAddProperty(xf=mainXML, property=Ekin/eV,
2689
. units='siestaUnits:eV',
2690
. dictref='siesta:Ekin', fmt='(f17.6)')
2691
call cmlAddProperty(xf=mainXML, property=Uscf/eV,
2692
. units='siestaUnits:eV',
2693
. dictref='siesta:Uscf', fmt='(f17.6)')
2694
call cmlAddProperty(xf=mainXML, property=DUext/eV,
2695
. units='siestaUnits:eV',
2696
. dictref='siesta:DUext', fmt='(f17.6)')
2697
call cmlAddProperty(xf=mainXML, property=Exc/eV,
2698
. units='siestaUnits:eV',
2699
. dictref='siesta:Exc', fmt='(f17.6)')
2700
call cmlAddProperty(xf=mainXML,
2701
. property=(Enascf+Enl+DUscf-Uscf-Uatm)/eV,
2702
. units='siestaUnits:eV',
2703
. dictref='siesta:I-e', fmt='(f17.6)')
2704
call cmlAddProperty(xf=mainXML,
2705
. property=(Ena+Uatm-Enaatm-Eions)/eV,
2706
. units='siestaUnits:eV',
2707
. dictref='siesta:I-I', fmt='(f17.6)')
2708
call cmlAddProperty(xf=mainXML, property=Ekinion/eV,
2709
. units='siestaUnits:eV',
2710
. dictref='siesta:Ekinion', fmt='(f17.6)')
2711
call cmlAddProperty(xf=mainXML, property=(Etot+Ekinion)/eV,
2712
. units='siestaUnits:eV',
2713
. dictref='siesta:Etot', fmt='(f17.6)')
2714
call cmlEndPropertyList(mainXML)
2718
end subroutine siesta_write_energies
2720
subroutine siesta_write_positions
2722
! Write out structural information in "crystallography" format,
2723
! and in "canonical" (see Zmatrix module) zmatrix format.
2724
! By now the structure might have changed in response to forces
2727
call write_struct( ucell, na_u, isa, iza, xa, moved=.true.)
2728
if (lUseZmatrix) then
2729
call write_canonical_ucell_and_Zmatrix
2730
$ (filename="NEXT_ITER.UCELL.ZMATRIX")
2734
call cmlAddMolecule(xf=mainXML, natoms=na_u, elements=elem,
2735
. refs=cisa, coords=xa/Ang, style='x3', fmt='(f12.6)')
2736
call cmlAddLattice(xf=mainXML, cell=ucell/Ang,
2737
. units='siestaUnits:Ang', dictref='siesta:ucell')
2739
end subroutine siesta_write_positions
15
!------------------------------------------------------------------------- BEGIN
18
! Begin of coordinate relaxation iteration
21
DO WHILE ((istep.le.fincoor) .AND. (.not. relaxd))
23
call siesta_forces( istep )
25
call siesta_move( istep, relaxd )
26
if (.not. relaxd) then
31
! End of coordinate-relaxation loop
33
call siesta_analysis( relaxd )
36
!--------------------------------------------------------------------------- END