4
1
mirror of https://github.com/pfloos/quack synced 2024-12-22 20:35:36 +01:00

absolute PATH in Fortran I/O

This commit is contained in:
Abdallah Ammar 2024-10-31 15:42:22 +01:00
parent a6bc29e958
commit 52894ba30e
9 changed files with 607 additions and 421 deletions

View File

@ -155,5 +155,5 @@ else:
#Execute the QuAcK fortran program
print(QuAcK_dir)
subprocess.call(QuAcK_dir+'/bin/QuAcK')
subprocess.call([QuAcK_dir + '/bin/QuAcK', working_dir])

View File

@ -71,6 +71,16 @@ program QuAcK
logical :: dotest,doRtest,doUtest,doGtest
character(len=256) :: working_dir
! Check if the right number of arguments is provided
if(command_argument_count() < 1) then
print *, "No working directory provided."
stop
else
call get_command_argument(1, working_dir)
endif
!-------------!
! Hello World !
!-------------!
@ -95,7 +105,8 @@ program QuAcK
! Method selection !
!------------------!
call read_methods(doRHF,doUHF,doGHF,doROHF, &
call read_methods(working_dir, &
doRHF,doUHF,doGHF,doROHF, &
doMP2,doMP3, &
doCCD,dopCCD,doDCD,doCCSD,doCCSDT, &
dodrCCD,dorCCD,docrCCD,dolCCD, &
@ -112,7 +123,8 @@ program QuAcK
! Read options for methods !
!--------------------------!
call read_options(maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shift,dostab,dosearch, &
call read_options(working_dir, &
maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shift,dostab,dosearch, &
reg_MP, &
maxSCF_CC,thresh_CC,max_diis_CC, &
TDA,spin_conserved,spin_flip, &
@ -133,18 +145,18 @@ program QuAcK
! nOrb = number of orbitals !
!------------------------------------!
call read_molecule(nNuc,nO,nC,nR)
call read_molecule(working_dir,nNuc,nO,nC,nR)
allocate(ZNuc(nNuc),rNuc(nNuc,ncart))
! Read geometry
call read_geometry(nNuc,ZNuc,rNuc,ENuc)
call read_geometry(working_dir,nNuc,ZNuc,rNuc,ENuc)
!---------------------------------------!
! Read basis set information from PySCF !
!---------------------------------------!
call read_basis_pyscf(nBas,nO,nV)
call read_basis_pyscf(working_dir,nBas,nO,nV)
!--------------------------------------!
! Read one- and two-electron integrals !
@ -163,8 +175,8 @@ program QuAcK
call wall_time(start_int)
call read_integrals(nBas,S,T,V,Hc,ERI_AO)
call read_dipole_integrals(nBas,dipole_int_AO)
call read_integrals(working_dir,nBas,S,T,V,Hc,ERI_AO)
call read_dipole_integrals(working_dir,nBas,dipole_int_AO)
call wall_time(end_int)

View File

@ -1,4 +1,5 @@
subroutine read_methods(doRHF,doUHF,doGHF,doROHF, &
subroutine read_methods(working_dir, &
doRHF,doUHF,doGHF,doROHF, &
doMP2,doMP3, &
doCCD,dopCCD,doDCD,doCCSD,doCCSDT, &
do_drCCD,do_rCCD,do_crCCD,do_lCCD, &
@ -17,6 +18,10 @@ subroutine read_methods(doRHF,doUHF,doGHF,doROHF, &
! Input variables
character(len=256),intent(in) :: working_dir
! Output variables
logical,intent(out) :: doRHF,doUHF,doGHF,doROHF
logical,intent(out) :: doMP2,doMP3
logical,intent(out) :: doCCD,dopCCD,doDCD,doCCSD,doCCSDT
@ -33,10 +38,19 @@ subroutine read_methods(doRHF,doUHF,doGHF,doROHF, &
! Local variables
character(len=1) :: ans1,ans2,ans3,ans4,ans5,ans6
integer :: status
character(len=256) :: file_path
! Open file with method specification
open(unit=1,file='input/methods')
file_path = trim(working_dir) // '/input/methods'
open(unit=1, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
! Read mean-field methods
@ -195,8 +209,9 @@ subroutine read_methods(doRHF,doUHF,doGHF,doROHF, &
if(ans2 == 'T') doUtest = .true.
if(ans3 == 'T') doGtest = .true.
! Close file
endif
! Close file
close(unit=1)
end subroutine

View File

@ -1,4 +1,5 @@
subroutine read_options(maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shift,dostab,dosearch, &
subroutine read_options(working_dir, &
maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shift,dostab,dosearch, &
reg_MP, &
maxSCF_CC,thresh_CC,max_diis_CC, &
TDA,spin_conserved,spin_flip, &
@ -14,6 +15,10 @@ subroutine read_options(maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shi
! Input variables
character(len=256),intent(in) :: working_dir
! Output variables
integer,intent(out) :: maxSCF_HF
double precision,intent(out) :: thresh_HF
integer,intent(out) :: max_diis_HF
@ -70,10 +75,20 @@ subroutine read_options(maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shi
! Local variables
character(len=1) :: ans1,ans2,ans3,ans4,ans5
integer :: status
character(len=256) :: file_path
! Open file with method specification
open(unit=1,file='input/options')
file_path = trim(working_dir) // '/input/options'
open(unit=1, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
! Read HF options
@ -202,8 +217,9 @@ subroutine read_options(maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shi
if(ans4 == 'T') dBSE = .true.
if(ans5 == 'F') dTDA = .false.
! Close file with options
endif
! Close file with options
close(unit=1)
end subroutine

View File

@ -1,4 +1,4 @@
subroutine read_basis_pyscf(nBas,nO,nV)
subroutine read_basis_pyscf(working_dir,nBas,nO,nV)
! Read basis set information from PySCF
@ -8,20 +8,36 @@ subroutine read_basis_pyscf(nBas,nO,nV)
! Input variables
integer,intent(in) :: nO(nspin)
! Local variables
character(len=256),intent(in) :: working_dir
! Output variables
integer,intent(out) :: nV(nspin)
integer,intent(out) :: nBas
! Local variables
integer :: status
character(len=256) :: file_path
!------------------------------------------------------------------------
! Primary basis set information
!------------------------------------------------------------------------
open(unit=3,file='int/nBas.dat')
file_path = trim(working_dir) // '/int/nBas.dat'
open(unit=3, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
read(3, *) nBas
endif
close(unit=3)
! write(*,'(A38)') '--------------------------------------'

View File

@ -1,4 +1,4 @@
subroutine read_dipole_integrals(nBas,R)
subroutine read_dipole_integrals(working_dir,nBas,R)
! Read one-electron integrals related to dipole moment from files
@ -8,6 +8,7 @@ subroutine read_dipole_integrals(nBas,R)
! Input variables
integer,intent(in) :: nBas
character(len=256),intent(in) :: working_dir
! Local variables
@ -19,36 +20,83 @@ subroutine read_dipole_integrals(nBas,R)
double precision,intent(out) :: R(nBas,nBas,ncart)
integer :: status, ios
character(len=256) :: file_path
! Open file with integrals
open(unit=21,file='int/x.dat')
open(unit=22,file='int/y.dat')
open(unit=23,file='int/z.dat')
! Read (x,y,z) integrals
R(:,:,:) = 0d0
file_path = trim(working_dir) // '/int/x.dat'
open(unit=21, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
do
read(21,*,end=21) mu,nu,Dip
read(21,*,iostat=ios) mu,nu,Dip
if(ios /= 0) exit
R(mu,nu,1) = Dip
R(nu,mu,1) = Dip
end do
21 close(unit=21)
endif
close(unit=21)
! ---
file_path = trim(working_dir) // '/int/y.dat'
open(unit=22, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
do
read(22,*,end=22) mu,nu,Dip
read(22,*,iostat=ios) mu,nu,Dip
if(ios /= 0) exit
R(mu,nu,2) = Dip
R(nu,mu,2) = Dip
end do
22 close(unit=22)
endif
close(unit=22)
! ---
file_path = trim(working_dir) // '/int/z.dat'
open(unit=23, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
do
read(23,*,end=23) mu,nu,Dip
read(23,*,iostat=ios) mu,nu,Dip
if(ios /= 0) exit
R(mu,nu,3) = Dip
R(nu,mu,3) = Dip
end do
23 close(unit=23)
endif
close(unit=23)
! ---
! Print results
if(debug) then

View File

@ -1,10 +1,14 @@
subroutine read_geometry(nNuc,ZNuc,rNuc,ENuc)
subroutine read_geometry(working_dir,nNuc,ZNuc,rNuc,ENuc)
! Read molecular geometry
implicit none
include 'parameters.h'
! Input variables
character(len=256),intent(in) :: working_dir
! Ouput variables
integer,intent(in) :: nNuc
@ -20,12 +24,23 @@ subroutine read_geometry(nNuc,ZNuc,rNuc,ENuc)
double precision,intent(out) :: ZNuc(nNuc),rNuc(nNuc,ncart),ENuc
integer :: status
character(len=256) :: file_path
! Open file with geometry specification
open(unit=10,file='input/molecule')
open(unit=11,file='input/molecule.xyz')
file_path = trim(working_dir) // '/input/molecule'
open(unit=10, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
! Read geometry and create xyz file for integrals
open(unit=11,file=trim(working_dir) // '/input/molecule.xyz')
read(10,*)
read(10,*)
@ -40,13 +55,32 @@ subroutine read_geometry(nNuc,ZNuc,rNuc,ENuc)
ZNuc(i) = dble(element_number(El))
end do
! Compute nuclear repulsion energy
close(unit=11)
endif
close(unit=10)
! ---
file_path = trim(working_dir) // '/int/ENuc.dat'
open(unit=3, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
ENuc = 0
open(unit=3,file='int/ENuc.dat')
read(3,*) ENuc
endif
close(unit=3)
! Compute nuclear repulsion energy
!ENuc = 0.d0
!do i=1,nNuc-1
! do j=i+1,nNuc
! RAB = (rNuc(i,1)-rNuc(j,1))**2 + (rNuc(i,2)-rNuc(j,2))**2 + (rNuc(i,3)-rNuc(j,3))**2
@ -54,9 +88,6 @@ subroutine read_geometry(nNuc,ZNuc,rNuc,ENuc)
! end do
!end do
! Close file with geometry specification
close(unit=10)
close(unit=11)
! Print geometry
write(*,'(A28)') '------------------'

View File

@ -1,4 +1,4 @@
subroutine read_integrals(nBas_AOs, S, T, V, Hc, G)
subroutine read_integrals(working_dir,nBas_AOs,S,T,V,Hc,G)
! Read one- and two-electron integrals from files
@ -8,6 +8,7 @@ subroutine read_integrals(nBas_AOs, S, T, V, Hc, G)
! Input variables
integer,intent(in) :: nBas_AOs
character(len=256),intent(in) :: working_dir
! Local variables
@ -24,6 +25,9 @@ subroutine read_integrals(nBas_AOs, S, T, V, Hc, G)
double precision,intent(out) :: Hc(nBas_AOs,nBas_AOs)
double precision,intent(out) :: G(nBas_AOs,nBas_AOs,nBas_AOs,nBas_AOs)
integer :: status, ios
character(len=256) :: file_path
! Open file with integrals
debug = .false.
@ -32,46 +36,67 @@ subroutine read_integrals(nBas_AOs, S, T, V, Hc, G)
print*, 'Scaling integrals by ',lambda
open(unit=8 ,file='int/Ov.dat')
open(unit=9 ,file='int/Kin.dat')
open(unit=10,file='int/Nuc.dat')
open(unit=21,file='int/x.dat')
open(unit=22,file='int/y.dat')
open(unit=23,file='int/z.dat')
! ---
! Read overlap integrals
file_path = trim(working_dir) // '/int/Ov.dat'
open(unit=8, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
S(:,:) = 0d0
do
read(8,*,end=8) mu,nu,Ov
read(8,*,iostat=ios) mu,nu,Ov
if(ios /= 0) exit
S(mu,nu) = Ov
S(nu,mu) = Ov
end do
8 close(unit=8)
endif
close(unit=8)
! ---
! Read kinetic integrals
file_path = trim(working_dir) // '/int/Kin.dat'
open(unit=9, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
T(:,:) = 0d0
do
read(9,*,end=9) mu,nu,Kin
read(9,*,iostat=ios) mu,nu,Kin
if(ios /= 0) exit
T(mu,nu) = Kin
T(nu,mu) = Kin
end do
9 close(unit=9)
endif
close(unit=9)
! ---
! Read nuclear integrals
file_path = trim(working_dir) // '/int/Nuc.dat'
open(unit=10, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
V(:,:) = 0d0
do
read(10,*,end=10) mu,nu,Nuc
read(10,*,iostat=ios) mu,nu,Nuc
if(ios /= 0) exit
V(mu,nu) = Nuc
V(nu,mu) = Nuc
end do
10 close(unit=10)
endif
close(unit=10)
! ---
! Define core Hamiltonian
Hc(:,:) = T(:,:) + V(:,:)
! Read 2e-integrals
@ -94,9 +119,16 @@ subroutine read_integrals(nBas_AOs, S, T, V, Hc, G)
! 11 close(unit=11)
! binary file
open(unit=11, file='int/ERI.bin', form='unformatted', access='stream')
file_path = trim(working_dir) // '/int/ERI.bin'
open(unit=11, file=file_path, status='old', action='read', form='unformatted', access='stream', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
read(11) G
close(11)
endif
close(unit=11)
! Print results

View File

@ -1,4 +1,4 @@
subroutine read_molecule(nNuc,nO,nC,nR)
subroutine read_molecule(working_dir,nNuc,nO,nC,nR)
! Read number of atoms and number of electrons
@ -11,6 +11,10 @@ subroutine read_molecule(nNuc,nO,nC,nR)
integer :: nCore
integer :: nRyd
! Input variables
character(len=256),intent(in) :: working_dir
! Output variables
integer,intent(out) :: nNuc
@ -18,9 +22,20 @@ subroutine read_molecule(nNuc,nO,nC,nR)
integer,intent(out) :: nC(nspin)
integer,intent(out) :: nR(nspin)
integer :: status
character(len=256) :: file_path
! Open file with geometry specification
open(unit=1,file='input/molecule')
file_path = trim(working_dir) // '/input/molecule'
open(unit=1, file=file_path, status='old', action='read', iostat=status)
if(status /= 0) then
print *, "Error opening file: ", file_path
stop
else
! Read number of atoms and number of electrons
@ -55,8 +70,9 @@ subroutine read_molecule(nNuc,nO,nC,nR)
write(*,'(A28)') '----------------------'
write(*,*)
! Close file with geometry specification
endif
! Close file with geometry specification
close(unit=1)
end subroutine