TABLE OF CONTENTS


ABINIT/mrgdv [ Programs ]

[ Top ] [ Programs ]

NAME

 mrgdv

FUNCTION

 This program merges DFPT potentials for different q-vectors and perturbations.

COPYRIGHT

 Copyright (C) 2004-2024 ABINIT group (MG)
 This file is distributed under the terms of the
 GNU General Public Licence, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .
 For the initials of contributors, see ~abinit/doc/developers/contributors.txt .

NOTES

 DVDB file format:
   version (integer)
   number of potentials (integer)
   for each potential:
     Abinit header with info on the perturbation and the FFT mesh
     potential on the FFT mesh

SOURCE

 25 #if defined HAVE_CONFIG_H
 26 #include "config.h"
 27 #endif
 28 
 29 #include "abi_common.h"
 30 
 31 program mrgdv
 32 
 33  use defs_basis
 34  use m_xmpi
 35  use m_errors
 36  use m_abicore
 37  use m_dvdb
 38 
 39  use m_build_info,      only : abinit_version
 40  use m_specialmsg,      only : specialmsg_getcount, herald
 41  use m_fstrings,        only : sjoin, itoa, ltoa
 42  use m_numeric_tools,   only : vdiff_eval, vdiff_print
 43  use m_io_tools,        only : file_exists, prompt
 44  use m_argparse,        only : get_arg, get_arg_list
 45  use m_fftcore,         only : ngfft_seq
 46 
 47  implicit none
 48 
 49 !Local variables-------------------------------
 50 !scalars
 51  integer :: ii, nargs, nfiles, comm, prtvol, my_rank, lenr, dvdb_add_lr, rspace_cell, symv1scf, npert_miss, abimem_level
 52  real(dp) :: dvdb_qdamp, abimem_limit_mb
 53  character(len=24) :: codename
 54  character(len=500) :: command, arg, msg
 55  character(len=fnlen) :: dvdb_filepath, dump_file, ddb_filepath
 56  type(dvdb_t) :: dvdb
 57 !arrays
 58  integer :: ngqpt(3), coarse_ngqpt(3), ngfftf(18), qptopt
 59  character(len=fnlen),allocatable :: v1files(:)
 60 
 61 ! *************************************************************************
 62 
 63  ! Change communicator for I/O (mandatory!)
 64  call abi_io_redirect(new_io_comm=xmpi_world)
 65 
 66  ! Initialize MPI
 67  call xmpi_init()
 68  comm = xmpi_world
 69  my_rank = xmpi_comm_rank(comm)
 70 
 71  ! Initialize memory profiling if it is activated
 72  ! if a full abimem.mocc report is desired, set the argument of abimem_init to "2" instead of "0"
 73  ! note that abimem.mocc files can easily be multiple GB in size so don't use this option normally
 74  ABI_CHECK(get_arg("abimem-level", abimem_level, msg, default=0) == 0, msg)
 75  ABI_CHECK(get_arg("abimem-limit-mb", abimem_limit_mb, msg, default=20.0_dp) == 0, msg)
 76 #ifdef HAVE_MEM_PROFILING
 77  call abimem_init(abimem_level, limit_mb=abimem_limit_mb)
 78 #endif
 79 
 80  ! write greating,read the file names, etc.
 81  codename='MRGDV'//repeat(' ',18)
 82  call herald(codename, abinit_version, std_out)
 83 
 84  ABI_CHECK(xmpi_comm_size(comm) == 1, "Not programmed for parallel execution")
 85  ABI_CHECK(get_arg("prtvol", prtvol, msg, default=0) == 0, msg)
 86 
 87  nargs = command_argument_count()
 88 
 89  if (nargs == 0) then
 90    ! We are reading from stdin
 91    ! Prepend prompt with `-` to bypass bug in intel18-19
 92    call prompt("Enter name of output file:", dvdb_filepath)
 93    call prompt("Enter total number of DFPT POT files:", nfiles)
 94    ABI_MALLOC(v1files, (nfiles))
 95    do ii=1,nfiles
 96      call prompt(sjoin("Enter name of POT file", itoa(ii), ":"), v1files(ii))
 97    end do
 98    call dvdb_merge_files(nfiles, v1files, dvdb_filepath, prtvol)
 99    ABI_FREE(v1files)
100 
101  else
102    ! Command line options.
103    do ii=1,command_argument_count()
104      call get_command_argument(ii, arg)
105      if (arg == "-v" .or. arg == "--version") then
106        write(std_out,"(a)") trim(abinit_version); goto 100
107 
108      else if (arg == "-h" .or. arg == "--help") then
109        ! Document the options.
110        write(std_out,*)"-v, --version              Show version number and exit."
111        write(std_out,*)"merge out_DVDB POT1 POT2   Merge list of POT files, produce out_DVDB file."
112        write(std_out,*)"info out_DVDB              Print information on DVDB file"
113        write(std_out,*)"-h, --help                 Show this help and exit."
114        write(std_out,*)" "
115        write(std_out,*)"=== Options for developers ==="
116        write(std_out,*)" "
117        write(std_out,*)"test_v1complete FILE [--symv1scf 1] [--potfile foo.nc]"
118        write(std_out,*)"                           Test symmetrization of DFPT potentials with symv1scf option"
119        write(std_out,*)"                           Assume DVDB with all 3*natom perturbations for each q (use prep_gkk)."
120        write(std_out,*)"test_v1rsym [--symv1scf]   Test symmetries of DFPT potentials in real space."
121        write(std_out,*)"test_ftinterp in_DVDB --ngqpt 4 4 4 [--ddb-path] [--dvdb-add-lr 0] [--qdamp -1]"
122        write(std_out,*)"                                    [--symv1scf] [--coarse-ngqpt 2 2 2]"
123        write(std_out,*)"                           Test Fourier interpolation of DFPT potentials."
124        write(std_out,*)"downsample in_DVDB out_DVDB [n1, n2, n3] Produce new DVDB with q-subsmesh"
125        !write(std_out,*)"convert in_old_DVDB out_DVDB.nc  Convert old DVDB format to new DVDB in netcdf format"
126        goto 100
127      end if
128    end do
129 
130    call get_command_argument(1, command)
131 
132    select case (command)
133    case ("merge")
134      ! Get name of output database and list of v1 files.
135      ABI_CHECK(nargs > 1, "Additional arguments are missing")
136      call get_command_argument(2, dvdb_filepath)
137      if (file_exists(dvdb_filepath)) then
138        ABI_ERROR(sjoin("Cannot overwrite existing file:", dvdb_filepath))
139      end if
140 
141      nfiles = nargs - 2
142      ABI_MALLOC(v1files, (nfiles))
143      do ii=1,nfiles
144        call get_command_argument(ii+2, v1files(ii))
145      end do
146 
147      ! Merge POT files.
148      call dvdb_merge_files(nfiles, v1files, dvdb_filepath, prtvol)
149      ABI_FREE(v1files)
150 
151    case ("info")
152      ! Get name of output database and list of v1 files.
153      ABI_CHECK(nargs > 1, "Additional arguments are missing")
154      call get_command_argument(2, dvdb_filepath)
155 
156      dvdb = dvdb_new(dvdb_filepath, comm)
157      if (prtvol > 0) call dvdb%print(prtvol=prtvol)
158      call dvdb%list_perts([-1, -1, -1], npert_miss)
159      call dvdb%free()
160 
161    case ("test_v1comp", "test_v1complete")
162      call wrtout(std_out," Testing symmetries (assuming overcomplete DVDB, pass extra argument to dump v1(r)) to file")
163      call get_command_argument(2, dvdb_filepath)
164      ABI_CHECK(get_arg("symv1scf", symv1scf, msg, default=0) == 0, msg)
165      ABI_CHECK(get_arg("potfile", dump_file, msg, default="") == 0, msg)
166      call dvdb_test_v1complete(dvdb_filepath, symv1scf, dump_file, comm)
167 
168    case ("test_v1rsym")
169      call wrtout(std_out," Testing symmetries of V1(r) in real space.")
170      call get_command_argument(2, dvdb_filepath)
171      ABI_CHECK(get_arg("symv1scf", symv1scf, msg, default=0) == 0, msg)
172      call dvdb_test_v1rsym(dvdb_filepath, symv1scf, comm)
173 
174    case ("test_ftinterp")
175      call get_command_argument(2, dvdb_filepath)
176      ABI_CHECK(get_arg_list("ngqpt", ngqpt, lenr, msg, default=2, want_len=3) == 0, msg)
177      ABI_CHECK(get_arg("ddb-path", ddb_filepath, msg, default="") == 0, msg)
178      ABI_CHECK(get_arg("rspace_cell", rspace_cell, msg, default=0) == 0, msg)
179      ABI_CHECK(get_arg("symv1scf", symv1scf, msg, default=0) == 0, msg)
180      ABI_CHECK(get_arg("dvdb-add-lr", dvdb_add_lr, msg, default=1) == 0, msg)
181      ABI_CHECK(get_arg("qdamp", dvdb_qdamp, msg, default=0.1_dp) == 0, msg)
182      ABI_CHECK(get_arg_list("coarse-ngqpt", coarse_ngqpt, lenr, msg, default=0, want_len=3) == 0, msg)
183      call dvdb_test_ftinterp(dvdb_filepath, rspace_cell, symv1scf, ngqpt, dvdb_add_lr, dvdb_qdamp, &
184                              ddb_filepath, prtvol, coarse_ngqpt, comm)
185 
186    case ("downsample")
187      call get_command_argument(2, dvdb_filepath)
188      call get_command_argument(3, dump_file)
189      ABI_CHECK(get_arg_list("ngqpt", ngqpt, lenr, msg, want_len=3) == 0, msg)
190      ABI_CHECK(get_arg("qptopt", qptopt, msg, default=1) == 0, msg)
191      write(std_out,"(a)")sjoin(" Downsampling q-mesh with ngqpt:", ltoa(ngqpt))
192      write(std_out,"(a)")sjoin("                         qptopt:", itoa(qptopt))
193      write(std_out,"(a)")trim(dvdb_filepath), " --> ", trim(dump_file)
194 
195      dvdb = dvdb_new(dvdb_filepath, xmpi_comm_self)
196      call ngfft_seq(ngfftf, dvdb%ngfft3_v1(:, 1))
197      call dvdb%open_read(ngfftf, xmpi_comm_self)
198      if (prtvol > 0) call dvdb%print(prtvol=prtvol)
199      call dvdb%list_perts([-1,-1,-1], npert_miss, unit=std_out)
200      call dvdb%qdownsample(dump_file, qptopt, ngqpt, comm)
201      call dvdb%free()
202 
203    !case ("convert")
204    !  call get_command_argument(2, dvdb_filepath)
205    !  call get_command_argument(3, dump_file)
206    !  call dvdb_convert_fort2nc(dvdb_filepath, dump_file, comm)
207 
208    case default
209      ABI_ERROR(sjoin("Unknown command:", command))
210    end select
211 
212  end if
213 
214  call wrtout(std_out," Done")
215  call abinit_doctor("__mrgdv")
216 
217  100 call xmpi_end()
218 
219  end program mrgdv