From f2ead7138b2a0ba2e4847297eec38baed4b5c9cd Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Tue, 29 Oct 2024 23:43:33 +0100 Subject: [PATCH 1/9] read mol geom from working dir --- PyDuck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyDuck.py b/PyDuck.py index a8e9033..1154f19 100644 --- a/PyDuck.py +++ b/PyDuck.py @@ -37,7 +37,7 @@ print_2e=args.print_2e working_dir=args.working_dir #Read molecule -f = open(QuAcK_dir + '/mol/' + xyz,'r') +f = open(working_dir+'/mol/'+xyz,'r') lines = f.read().splitlines() nbAt = int(lines.pop(0)) lines.pop(0) From 1f56026c29dbe88864c97ce419587b7656f3b19b Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 31 Oct 2024 10:46:00 +0100 Subject: [PATCH 2/9] separete binary code and I/O when --working_dir is used --- PyDuck.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/PyDuck.py b/PyDuck.py index 1154f19..b47914a 100644 --- a/PyDuck.py +++ b/PyDuck.py @@ -70,6 +70,7 @@ nelec=mol.nelec #Access the number of electrons nalpha=nelec[0] nbeta=nelec[1] +subprocess.call(['mkdir', '-p', 'input']) f = open(working_dir+'/input/molecule','w') f.write('# nAt nEla nElb nCore nRyd\n') f.write(str(mol.natm)+' '+str(nalpha)+' '+str(nbeta)+' '+str(0)+' '+str(0)+'\n') @@ -79,7 +80,8 @@ for i in range(len(list_pos_atom)): f.close() #Compute nuclear energy and put it in a file -subprocess.call(['rm', working_dir + '/int/ENuc.dat']) +subprocess.call(['mkdir', '-p', 'int']) +subprocess.call(['rm', '-f', working_dir + '/int/ENuc.dat']) f = open(working_dir+'/int/ENuc.dat','w') f.write(str(mol.energy_nuc())) f.write(' ') @@ -100,7 +102,7 @@ f.close() def write_matrix_to_file(matrix,size,file,cutoff=1e-15): - f = open(file, 'a') + f = open(file, 'w') for i in range(size): for j in range(i,size): if abs(matrix[i][j]) > cutoff: @@ -110,23 +112,23 @@ def write_matrix_to_file(matrix,size,file,cutoff=1e-15): #Write all 1 electron quantities in files #Ov,Nuc,Kin,x,y,z -subprocess.call(['rm', working_dir + '/int/Ov.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/Ov.dat']) write_matrix_to_file(ovlp,norb,working_dir+'/int/Ov.dat') -subprocess.call(['rm', working_dir + '/int/Nuc.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/Nuc.dat']) write_matrix_to_file(v1e,norb,working_dir+'/int/Nuc.dat') -subprocess.call(['rm', working_dir + '/int/Kin.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/Kin.dat']) write_matrix_to_file(t1e,norb,working_dir+'/int/Kin.dat') -subprocess.call(['rm', working_dir + '/int/x.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/x.dat']) write_matrix_to_file(x,norb,working_dir+'/int/x.dat') -subprocess.call(['rm', working_dir + '/int/y.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/y.dat']) write_matrix_to_file(y,norb,working_dir+'/int/y.dat') -subprocess.call(['rm', working_dir + '/int/z.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/z.dat']) write_matrix_to_file(z,norb,working_dir+'/int/z.dat') eri_ao = mol.intor('int2e') def write_tensor_to_file(tensor,size,file,cutoff=1e-15): - f = open(file, 'a') + f = open(file, 'w') for i in range(size): for j in range(i,size): for k in range(i,size): @@ -140,15 +142,18 @@ def write_tensor_to_file(tensor,size,file,cutoff=1e-15): # Write two-electron integrals if print_2e: # (formatted) - subprocess.call(['rm', working_dir + '/int/ERI.dat']) - write_tensor_to_file(eri_ao,norb,working_dir+'/int/ERI.dat') + subprocess.call(['rm', '-f', working_dir + '/int/ERI.dat']) + write_tensor_to_file(eri_ao, norb, working_dir + '/int/ERI.dat') else: # (binary) - subprocess.call(['rm', working_dir + '/int/ERI.bin']) + subprocess.call(['rm', '-f', working_dir + '/int/ERI.bin']) # chem -> phys notation eri_ao = eri_ao.transpose(0, 2, 1, 3) - eri_ao.tofile('int/ERI.bin') + f = open(working_dir + '/int/ERI.bin', 'w') + eri_ao.tofile(working_dir + '/int/ERI.bin') + f.close() #Execute the QuAcK fortran program +print(QuAcK_dir) subprocess.call(QuAcK_dir+'/bin/QuAcK') From e0cee99d02eb463e15eb4b777b09b96f70c7b22a Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 31 Oct 2024 11:12:18 +0100 Subject: [PATCH 3/9] absolute path for mkdir --- PyDuck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyDuck.py b/PyDuck.py index b47914a..3343c0d 100644 --- a/PyDuck.py +++ b/PyDuck.py @@ -70,7 +70,7 @@ nelec=mol.nelec #Access the number of electrons nalpha=nelec[0] nbeta=nelec[1] -subprocess.call(['mkdir', '-p', 'input']) +subprocess.call(['mkdir', '-p', working_dir+'/input']) f = open(working_dir+'/input/molecule','w') f.write('# nAt nEla nElb nCore nRyd\n') f.write(str(mol.natm)+' '+str(nalpha)+' '+str(nbeta)+' '+str(0)+' '+str(0)+'\n') @@ -80,7 +80,7 @@ for i in range(len(list_pos_atom)): f.close() #Compute nuclear energy and put it in a file -subprocess.call(['mkdir', '-p', 'int']) +subprocess.call(['mkdir', '-p', working_dir+'/int']) subprocess.call(['rm', '-f', working_dir + '/int/ENuc.dat']) f = open(working_dir+'/int/ENuc.dat','w') f.write(str(mol.energy_nuc())) From a6bc29e958fc38975b38e32d36502b45b43bdce0 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 31 Oct 2024 11:16:55 +0100 Subject: [PATCH 4/9] avoid rm error message if file does not exist --- PyDuck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyDuck.py b/PyDuck.py index 3343c0d..fa5922a 100644 --- a/PyDuck.py +++ b/PyDuck.py @@ -95,7 +95,7 @@ dipole = mol.intor('int1e_r') #Matrix elements of the x, y, z operators x,y,z = dipole[0],dipole[1],dipole[2] norb = len(ovlp) # nBAS_AOs -subprocess.call(['rm', working_dir + '/int/nBas.dat']) +subprocess.call(['rm', '-f', working_dir + '/int/nBas.dat']) f = open(working_dir+'/int/nBas.dat','w') f.write(" {} ".format(str(norb))) f.close() From 52894ba30ed1f820760913e996279b2333127334 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Thu, 31 Oct 2024 15:42:22 +0100 Subject: [PATCH 5/9] absolute PATH in Fortran I/O --- PyDuck.py | 4 +- src/QuAcK/QuAcK.f90 | 26 ++- src/QuAcK/read_methods.f90 | 329 +++++++++++++++------------- src/QuAcK/read_options.f90 | 268 +++++++++++----------- src/utils/read_basis_pyscf.f90 | 32 ++- src/utils/read_dipole_integrals.f90 | 98 ++++++--- src/utils/read_geometry.f90 | 87 +++++--- src/utils/read_integrals.f90 | 104 ++++++--- src/utils/read_molecule.f90 | 80 ++++--- 9 files changed, 607 insertions(+), 421 deletions(-) diff --git a/PyDuck.py b/PyDuck.py index fa5922a..7a0e40a 100644 --- a/PyDuck.py +++ b/PyDuck.py @@ -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]) + diff --git a/src/QuAcK/QuAcK.f90 b/src/QuAcK/QuAcK.f90 index 160ee7e..8c31986 100644 --- a/src/QuAcK/QuAcK.f90 +++ b/src/QuAcK/QuAcK.f90 @@ -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) diff --git a/src/QuAcK/read_methods.f90 b/src/QuAcK/read_methods.f90 index 0421852..bef3305 100644 --- a/src/QuAcK/read_methods.f90 +++ b/src/QuAcK/read_methods.f90 @@ -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,170 +38,180 @@ 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) -! Read mean-field methods + if(status /= 0) then - doRHF = .false. - doUHF = .false. - doGHF = .false. - doROHF = .false. + print *, "Error opening file: ", file_path + stop - read(1,*) - read(1,*) ans1,ans2,ans3,ans4 - if(ans1 == 'T') doRHF = .true. - if(ans2 == 'T') doUHF = .true. - if(ans3 == 'T') doGHF = .true. - if(ans4 == 'T') doROHF = .true. + else -! Read MPn methods + ! Read mean-field methods + + doRHF = .false. + doUHF = .false. + doGHF = .false. + doROHF = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4 + if(ans1 == 'T') doRHF = .true. + if(ans2 == 'T') doUHF = .true. + if(ans3 == 'T') doGHF = .true. + if(ans4 == 'T') doROHF = .true. + + ! Read MPn methods + + doMP2 = .false. + doMP3 = .false. + + read(1,*) + read(1,*) ans1,ans2 + if(ans1 == 'T') doMP2 = .true. + if(ans2 == 'T') doMP3 = .true. + + ! Read CC methods + + doCCD = .false. + dopCCD = .false. + doDCD = .false. + doCCSD = .false. + doCCSDT = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4,ans5 + if(ans1 == 'T') doCCD = .true. + if(ans2 == 'T') dopCCD = .true. + if(ans3 == 'T') doDCD = .true. + if(ans4 == 'T') doCCSD = .true. + if(ans5 == 'T') doCCSDT = .true. + + ! Read weird CC methods + + do_drCCD = .false. + do_rCCD = .false. + do_crCCD = .false. + do_lCCD = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4 + if(ans1 == 'T') do_drCCD = .true. + if(ans2 == 'T') do_rCCD = .true. + if(ans3 == 'T') do_crCCD = .true. + if(ans4 == 'T') do_lCCD = .true. + + ! Read CI methods + + doCIS = .false. + doCIS_D = .false. + doCID = .false. + doCISD = .false. + doFCI = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4,ans5 + if(ans1 == 'T') doCIS = .true. + if(ans2 == 'T') doCIS_D = .true. + if(ans3 == 'T') doCID = .true. + if(ans4 == 'T') doCISD = .true. + if(ans5 == 'T') doFCI = .true. + if(doCIS_D) doCIS = .true. + + ! Read RPA methods + + dophRPA = .false. + dophRPAx = .false. + docrRPA = .false. + doppRPA = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4 + if(ans1 == 'T') dophRPA = .true. + if(ans2 == 'T') dophRPAx = .true. + if(ans3 == 'T') docrRPA = .true. + if(ans4 == 'T') doppRPA = .true. + + ! Read Green's function methods + + doG0F2 = .false. + doevGF2 = .false. + doqsGF2 = .false. + doufG0F02 = .false. + doG0F3 = .false. + doevGF3 = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4,ans5,ans6 + if(ans1 == 'T') doG0F2 = .true. + if(ans2 == 'T') doevGF2 = .true. + if(ans3 == 'T') doqsGF2 = .true. + if(ans4 == 'T') doufG0F02 = .true. + if(ans5 == 'T') doG0F3 = .true. + if(ans6 == 'T') doevGF3 = .true. + + ! Read GW methods + + doG0W0 = .false. + doevGW = .false. + doqsGW = .false. + doufG0W0 = .false. + doufGW = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4,ans5 + if(ans1 == 'T') doG0W0 = .true. + if(ans2 == 'T') doevGW = .true. + if(ans3 == 'T') doqsGW = .true. + if(ans4 == 'T') doufG0W0 = .true. + if(ans5 == 'T') doufGW = .true. + + ! Read GTpp methods + + doG0T0pp = .false. + doevGTpp = .false. + doqsGTpp = .false. + doufG0T0pp = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4 + if(ans1 == 'T') doG0T0pp = .true. + if(ans2 == 'T') doevGTpp = .true. + if(ans3 == 'T') doqsGTpp = .true. + if(ans4 == 'T') doufG0T0pp = .true. + + ! Read GTeh methods + + doG0T0eh = .false. + doevGTeh = .false. + doqsGTeh = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3 + if(ans1 == 'T') doG0T0eh = .true. + if(ans2 == 'T') doevGTeh = .true. + if(ans3 == 'T') doqsGTeh = .true. + + ! Read test + + doRtest = .false. + doUtest = .false. + doGtest = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3 + if(ans1 == 'T') doRtest = .true. + if(ans2 == 'T') doUtest = .true. + if(ans3 == 'T') doGtest = .true. - doMP2 = .false. - doMP3 = .false. - - read(1,*) - read(1,*) ans1,ans2 - if(ans1 == 'T') doMP2 = .true. - if(ans2 == 'T') doMP3 = .true. - -! Read CC methods - - doCCD = .false. - dopCCD = .false. - doDCD = .false. - doCCSD = .false. - doCCSDT = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4,ans5 - if(ans1 == 'T') doCCD = .true. - if(ans2 == 'T') dopCCD = .true. - if(ans3 == 'T') doDCD = .true. - if(ans4 == 'T') doCCSD = .true. - if(ans5 == 'T') doCCSDT = .true. - -! Read weird CC methods - - do_drCCD = .false. - do_rCCD = .false. - do_crCCD = .false. - do_lCCD = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4 - if(ans1 == 'T') do_drCCD = .true. - if(ans2 == 'T') do_rCCD = .true. - if(ans3 == 'T') do_crCCD = .true. - if(ans4 == 'T') do_lCCD = .true. - -! Read CI methods - - doCIS = .false. - doCIS_D = .false. - doCID = .false. - doCISD = .false. - doFCI = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4,ans5 - if(ans1 == 'T') doCIS = .true. - if(ans2 == 'T') doCIS_D = .true. - if(ans3 == 'T') doCID = .true. - if(ans4 == 'T') doCISD = .true. - if(ans5 == 'T') doFCI = .true. - if(doCIS_D) doCIS = .true. - -! Read RPA methods - - dophRPA = .false. - dophRPAx = .false. - docrRPA = .false. - doppRPA = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4 - if(ans1 == 'T') dophRPA = .true. - if(ans2 == 'T') dophRPAx = .true. - if(ans3 == 'T') docrRPA = .true. - if(ans4 == 'T') doppRPA = .true. - -! Read Green's function methods - - doG0F2 = .false. - doevGF2 = .false. - doqsGF2 = .false. - doufG0F02 = .false. - doG0F3 = .false. - doevGF3 = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4,ans5,ans6 - if(ans1 == 'T') doG0F2 = .true. - if(ans2 == 'T') doevGF2 = .true. - if(ans3 == 'T') doqsGF2 = .true. - if(ans4 == 'T') doufG0F02 = .true. - if(ans5 == 'T') doG0F3 = .true. - if(ans6 == 'T') doevGF3 = .true. - -! Read GW methods - - doG0W0 = .false. - doevGW = .false. - doqsGW = .false. - doufG0W0 = .false. - doufGW = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4,ans5 - if(ans1 == 'T') doG0W0 = .true. - if(ans2 == 'T') doevGW = .true. - if(ans3 == 'T') doqsGW = .true. - if(ans4 == 'T') doufG0W0 = .true. - if(ans5 == 'T') doufGW = .true. - -! Read GTpp methods - - doG0T0pp = .false. - doevGTpp = .false. - doqsGTpp = .false. - doufG0T0pp = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4 - if(ans1 == 'T') doG0T0pp = .true. - if(ans2 == 'T') doevGTpp = .true. - if(ans3 == 'T') doqsGTpp = .true. - if(ans4 == 'T') doufG0T0pp = .true. - -! Read GTeh methods - - doG0T0eh = .false. - doevGTeh = .false. - doqsGTeh = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3 - if(ans1 == 'T') doG0T0eh = .true. - if(ans2 == 'T') doevGTeh = .true. - if(ans3 == 'T') doqsGTeh = .true. - -! Read test - - doRtest = .false. - doUtest = .false. - doGtest = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3 - if(ans1 == 'T') doRtest = .true. - if(ans2 == 'T') doUtest = .true. - if(ans3 == 'T') doGtest = .true. - -! Close file + endif + ! Close file close(unit=1) end subroutine diff --git a/src/QuAcK/read_options.f90 b/src/QuAcK/read_options.f90 index b9cdae1..8ba4033 100644 --- a/src/QuAcK/read_options.f90 +++ b/src/QuAcK/read_options.f90 @@ -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,140 +75,151 @@ 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) -! Read HF options + if(status /= 0) then - maxSCF_HF = 64 - thresh_HF = 1d-6 - max_diis_HF = 1 - guess_type = 1 - mix = 0d0 - level_shift = 0d0 - dostab = .false. - dosearch = .false. + print *, "Error opening file: ", file_path + stop - read(1,*) - read(1,*) maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shift,ans1,ans2 + else - if(ans1 == 'T') dostab = .true. - if(ans2 == 'T') dosearch = .true. + ! Read HF options + + maxSCF_HF = 64 + thresh_HF = 1d-6 + max_diis_HF = 1 + guess_type = 1 + mix = 0d0 + level_shift = 0d0 + dostab = .false. + dosearch = .false. + + read(1,*) + read(1,*) maxSCF_HF,thresh_HF,max_diis_HF,guess_type,mix,level_shift,ans1,ans2 + + if(ans1 == 'T') dostab = .true. + if(ans2 == 'T') dosearch = .true. + + ! Read MPn options + + reg_MP = .false. + read(1,*) + read(1,*) ans1 + + if(ans1 == 'T') reg_MP = .true. + + ! Read CC options + + maxSCF_CC = 64 + thresh_CC = 1d-5 + max_diis_CC = 1 + + read(1,*) + read(1,*) maxSCF_CC,thresh_CC,max_diis_CC + + ! Read excited state options + + TDA = .false. + spin_conserved = .false. + spin_flip = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3 + + if(ans1 == 'T') TDA = .true. + if(ans2 == 'T') spin_conserved = .true. + if(ans3 == 'T') spin_flip = .true. + + ! Read GF options + + maxSCF_GF = 64 + thresh_GF = 1d-5 + max_diis_GF = 1 + lin_GF = .false. + eta_GF = 0d0 + renorm_GF = 0 + reg_GF = .false. + + read(1,*) + read(1,*) maxSCF_GF,thresh_GF,max_diis_GF,ans1,eta_GF,renorm_GF,ans2 + + if(ans1 == 'T') lin_GF = .true. + if(ans2 == 'T') reg_GF = .true. + + ! Read GW options + + maxSCF_GW = 64 + thresh_GW = 1d-5 + max_diis_GW = 1 + lin_GW = .false. + eta_GW = 0d0 + reg_GW = .false. + TDA_W = .false. + + read(1,*) + read(1,*) maxSCF_GW,thresh_GW,max_diis_GW,ans1,eta_GW,ans2,ans3 + + if(ans1 == 'T') lin_GW = .true. + if(ans2 == 'T') TDA_W = .true. + if(ans3 == 'T') reg_GW = .true. + + ! Read GT options + + maxSCF_GT = 64 + thresh_GT = 1d-5 + max_diis_GT = 1 + lin_GT = .false. + eta_GT = 0d0 + reg_GT = .false. + TDA_T = .false. + + read(1,*) + read(1,*) maxSCF_GT,thresh_GT,max_diis_GT,ans1,eta_GT,ans2,ans3 + + if(ans1 == 'T') lin_GT = .true. + if(ans2 == 'T') TDA_T = .true. + if(ans3 == 'T') reg_GT = .true. + + ! Options for adiabatic connection + + doACFDT = .false. + exchange_kernel = .false. + doXBS = .false. + + read(1,*) + read(1,*) ans1,ans2,ans3 + + if(ans1 == 'T') doACFDT = .true. + if(ans2 == 'T') exchange_kernel = .true. + if(ans3 == 'T') doXBS = .true. + + ! Options for dynamical BSE calculations + + dophBSE = .false. + dophBSE2 = .false. + doppBSE = .false. + dBSE = .false. + dTDA = .true. + + read(1,*) + read(1,*) ans1,ans2,ans3,ans4,ans5 + + if(ans1 == 'T') dophBSE = .true. + if(ans2 == 'T') dophBSE2 = .true. + if(ans3 == 'T') doppBSE = .true. + if(ans4 == 'T') dBSE = .true. + if(ans5 == 'F') dTDA = .false. -! Read MPn options - - reg_MP = .false. - read(1,*) - read(1,*) ans1 - - if(ans1 == 'T') reg_MP = .true. - -! Read CC options - - maxSCF_CC = 64 - thresh_CC = 1d-5 - max_diis_CC = 1 - - read(1,*) - read(1,*) maxSCF_CC,thresh_CC,max_diis_CC - -! Read excited state options - - TDA = .false. - spin_conserved = .false. - spin_flip = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3 - - if(ans1 == 'T') TDA = .true. - if(ans2 == 'T') spin_conserved = .true. - if(ans3 == 'T') spin_flip = .true. - -! Read GF options - - maxSCF_GF = 64 - thresh_GF = 1d-5 - max_diis_GF = 1 - lin_GF = .false. - eta_GF = 0d0 - renorm_GF = 0 - reg_GF = .false. - - read(1,*) - read(1,*) maxSCF_GF,thresh_GF,max_diis_GF,ans1,eta_GF,renorm_GF,ans2 - - if(ans1 == 'T') lin_GF = .true. - if(ans2 == 'T') reg_GF = .true. - -! Read GW options - - maxSCF_GW = 64 - thresh_GW = 1d-5 - max_diis_GW = 1 - lin_GW = .false. - eta_GW = 0d0 - reg_GW = .false. - TDA_W = .false. - - read(1,*) - read(1,*) maxSCF_GW,thresh_GW,max_diis_GW,ans1,eta_GW,ans2,ans3 - - if(ans1 == 'T') lin_GW = .true. - if(ans2 == 'T') TDA_W = .true. - if(ans3 == 'T') reg_GW = .true. - -! Read GT options - - maxSCF_GT = 64 - thresh_GT = 1d-5 - max_diis_GT = 1 - lin_GT = .false. - eta_GT = 0d0 - reg_GT = .false. - TDA_T = .false. - - read(1,*) - read(1,*) maxSCF_GT,thresh_GT,max_diis_GT,ans1,eta_GT,ans2,ans3 - - if(ans1 == 'T') lin_GT = .true. - if(ans2 == 'T') TDA_T = .true. - if(ans3 == 'T') reg_GT = .true. - -! Options for adiabatic connection - - doACFDT = .false. - exchange_kernel = .false. - doXBS = .false. - - read(1,*) - read(1,*) ans1,ans2,ans3 - - if(ans1 == 'T') doACFDT = .true. - if(ans2 == 'T') exchange_kernel = .true. - if(ans3 == 'T') doXBS = .true. - -! Options for dynamical BSE calculations - - dophBSE = .false. - dophBSE2 = .false. - doppBSE = .false. - dBSE = .false. - dTDA = .true. - - read(1,*) - read(1,*) ans1,ans2,ans3,ans4,ans5 - - if(ans1 == 'T') dophBSE = .true. - if(ans2 == 'T') dophBSE2 = .true. - if(ans3 == 'T') doppBSE = .true. - if(ans4 == 'T') dBSE = .true. - if(ans5 == 'F') dTDA = .false. - -! Close file with options + endif + ! Close file with options close(unit=1) end subroutine diff --git a/src/utils/read_basis_pyscf.f90 b/src/utils/read_basis_pyscf.f90 index f44d33b..790c045 100644 --- a/src/utils/read_basis_pyscf.f90 +++ b/src/utils/read_basis_pyscf.f90 @@ -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 @@ -7,21 +7,37 @@ subroutine read_basis_pyscf(nBas,nO,nV) ! Input variables - integer,intent(in) :: nO(nspin) - -! Local variables + integer,intent(in) :: nO(nspin) + character(len=256),intent(in) :: working_dir ! Output variables - integer,intent(out) :: nV(nspin) - integer,intent(out) :: nBas + 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') - read(3, *) nBas + 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)') '--------------------------------------' diff --git a/src/utils/read_dipole_integrals.f90 b/src/utils/read_dipole_integrals.f90 index 095bb18..15af2cb 100644 --- a/src/utils/read_dipole_integrals.f90 +++ b/src/utils/read_dipole_integrals.f90 @@ -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 - do - read(21,*,end=21) mu,nu,Dip - R(mu,nu,1) = Dip - R(nu,mu,1) = Dip - end do - 21 close(unit=21) + file_path = trim(working_dir) // '/int/x.dat' + open(unit=21, file=file_path, status='old', action='read', iostat=status) - do - read(22,*,end=22) mu,nu,Dip - R(mu,nu,2) = Dip - R(nu,mu,2) = Dip - end do - 22 close(unit=22) + if(status /= 0) then + + print *, "Error opening file: ", file_path + stop + + else + + do + read(21,*,iostat=ios) mu,nu,Dip + if(ios /= 0) exit + R(mu,nu,1) = Dip + R(nu,mu,1) = Dip + end do + + 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,*,iostat=ios) mu,nu,Dip + if(ios /= 0) exit + R(mu,nu,2) = Dip + R(nu,mu,2) = Dip + end do + + 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,*,iostat=ios) mu,nu,Dip + if(ios /= 0) exit + R(mu,nu,3) = Dip + R(nu,mu,3) = Dip + end do + + endif + + close(unit=23) + + ! --- - do - read(23,*,end=23) mu,nu,Dip - R(mu,nu,3) = Dip - R(nu,mu,3) = Dip - end do - 23 close(unit=23) ! Print results if(debug) then diff --git a/src/utils/read_geometry.f90 b/src/utils/read_geometry.f90 index f1803cf..4f9bb88 100644 --- a/src/utils/read_geometry.f90 +++ b/src/utils/read_geometry.f90 @@ -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,43 +24,70 @@ 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) -! Read geometry and create xyz file for integrals + if(status /= 0) then - read(10,*) - read(10,*) - read(10,*) + print *, "Error opening file: ", file_path + stop - write(11,'(I3)') nNuc - write(11,*) + else - do i=1,nNuc - read(10,*) El,rNuc(i,1),rNuc(i,2),rNuc(i,3) - write(11,'(A3,1X,3F16.10)') El,rNuc(i,1)*BoToAn,rNuc(i,2)*BoToAn,rNuc(i,3)*BoToAn - ZNuc(i) = dble(element_number(El)) - end do + ! Read geometry and create xyz file for integrals + open(unit=11,file=trim(working_dir) // '/input/molecule.xyz') + + read(10,*) + read(10,*) + read(10,*) + + write(11,'(I3)') nNuc + write(11,*) + + do i=1,nNuc + read(10,*) El,rNuc(i,1),rNuc(i,2),rNuc(i,3) + write(11,'(A3,1X,3F16.10)') El,rNuc(i,1)*BoToAn,rNuc(i,2)*BoToAn,rNuc(i,3)*BoToAn + ZNuc(i) = dble(element_number(El)) + end do -! Compute nuclear repulsion energy + close(unit=11) - ENuc = 0 - open(unit=3,file='int/ENuc.dat') - read(3,*) ENuc - close(unit=3) + endif - ! 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 - ! ENuc = ENuc + ZNuc(i)*ZNuc(j)/(AntoBo*sqrt(RAB)) - ! end do - ! end do - -! Close file with geometry specification close(unit=10) - close(unit=11) + + ! --- + + 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 + + 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 + ! ENuc = ENuc + ZNuc(i)*ZNuc(j)/(AntoBo*sqrt(RAB)) + ! end do + !end do + ! Print geometry write(*,'(A28)') '------------------' diff --git a/src/utils/read_integrals.f90 b/src/utils/read_integrals.f90 index ef8e1d9..91be5fe 100644 --- a/src/utils/read_integrals.f90 +++ b/src/utils/read_integrals.f90 @@ -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 + ! 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,*,iostat=ios) mu,nu,Ov + if(ios /= 0) exit + S(mu,nu) = Ov + S(nu,mu) = Ov + end do + endif + close(unit=8) - S(:,:) = 0d0 - do - read(8,*,end=8) mu,nu,Ov - S(mu,nu) = Ov - S(nu,mu) = Ov - end do - 8 close(unit=8) + ! --- -! Read kinetic integrals + ! 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,*,iostat=ios) mu,nu,Kin + if(ios /= 0) exit + T(mu,nu) = Kin + T(nu,mu) = Kin + end do + endif + close(unit=9) - T(:,:) = 0d0 - do - read(9,*,end=9) mu,nu,Kin - T(mu,nu) = Kin - T(nu,mu) = Kin - end do - 9 close(unit=9) + ! --- -! Read nuclear integrals + ! 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,*,iostat=ios) mu,nu,Nuc + if(ios /= 0) exit + V(mu,nu) = Nuc + V(nu,mu) = Nuc + end do + endif + close(unit=10) - V(:,:) = 0d0 - do - read(10,*,end=10) mu,nu,Nuc - V(mu,nu) = Nuc - V(nu,mu) = Nuc - end do - 10 close(unit=10) - -! Define core Hamiltonian + ! --- + ! 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') - read(11) G - close(11) + 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 + endif + close(unit=11) + ! Print results diff --git a/src/utils/read_molecule.f90 b/src/utils/read_molecule.f90 index 8bcec0b..c3c89ea 100644 --- a/src/utils/read_molecule.f90 +++ b/src/utils/read_molecule.f90 @@ -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,45 +22,57 @@ 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) -! Read number of atoms and number of electrons + if(status /= 0) then - read(1,*) - read(1,*) nNuc,nO(1),nO(2),nCore,nRyd + print *, "Error opening file: ", file_path + stop - if(mod(nCore,2) /= 0 .or. mod(nRyd,2) /= 0) then + else - print*, 'The number of core and Rydberg electrons must be even!' - stop + ! Read number of atoms and number of electrons + + read(1,*) + read(1,*) nNuc,nO(1),nO(2),nCore,nRyd + + if(mod(nCore,2) /= 0 .or. mod(nRyd,2) /= 0) then + + print*, 'The number of core and Rydberg electrons must be even!' + stop + + end if + + nC(:) = nCore/2 + nR(:) = nRyd/2 + + ! Print results + + write(*,'(A28)') '----------------------' + write(*,'(A28,1X,I16)') 'Number of atoms',nNuc + write(*,'(A28)') '----------------------' + write(*,*) + write(*,'(A28)') '----------------------' + write(*,'(A28,1X,I16)') 'Number of spin-up electrons',nO(1) + write(*,'(A28,1X,I16)') 'Number of spin-down electrons',nO(2) + write(*,'(A28,1X,I16)') ' Total number of electrons',sum(nO(:)) + write(*,'(A28)') '----------------------' + write(*,*) + write(*,'(A28)') '----------------------' + write(*,'(A28,1X,I16)') 'Number of core electrons',sum(nC(:)) + write(*,'(A28,1X,I16)') 'Number of Rydberg electrons',sum(nR(:)) + write(*,'(A28)') '----------------------' + write(*,*) - end if - - nC(:) = nCore/2 - nR(:) = nRyd/2 - -! Print results - - write(*,'(A28)') '----------------------' - write(*,'(A28,1X,I16)') 'Number of atoms',nNuc - write(*,'(A28)') '----------------------' - write(*,*) - write(*,'(A28)') '----------------------' - write(*,'(A28,1X,I16)') 'Number of spin-up electrons',nO(1) - write(*,'(A28,1X,I16)') 'Number of spin-down electrons',nO(2) - write(*,'(A28,1X,I16)') ' Total number of electrons',sum(nO(:)) - write(*,'(A28)') '----------------------' - write(*,*) - write(*,'(A28)') '----------------------' - write(*,'(A28,1X,I16)') 'Number of core electrons',sum(nC(:)) - write(*,'(A28,1X,I16)') 'Number of Rydberg electrons',sum(nR(:)) - write(*,'(A28)') '----------------------' - write(*,*) - -! Close file with geometry specification + endif + ! Close file with geometry specification close(unit=1) end subroutine From 3552975ceeed58aa1c45cec58dec6fcae7557827 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Fri, 1 Nov 2024 10:59:35 +0100 Subject: [PATCH 6/9] ensure QUACK_ROOT is defined --- PyDuck.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PyDuck.py b/PyDuck.py index 7a0e40a..6c39b70 100644 --- a/PyDuck.py +++ b/PyDuck.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os +import os, sys import argparse import pyscf from pyscf import gto @@ -8,6 +8,10 @@ import numpy as np import subprocess #Find the value of the environnement variable QUACK_ROOT. If not present we use the current repository +if "QUACK_ROOT" not in os.environ: + print("Please set the QUACK_ROOT environment variable, for example:\n") + print("$ export QUACK_ROOT={0}".format(os.getcwd())) + sys.exit(1) QuAcK_dir=os.environ.get('QUACK_ROOT','./') #Create the argument parser object and gives a description of the script From df8eedf64e581f88b866e5054f3d23e41f00a662 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Fri, 1 Nov 2024 12:27:51 +0100 Subject: [PATCH 7/9] handle the compilation options --- src/make_ninja.py | 92 +++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/src/make_ninja.py b/src/make_ninja.py index da9c885..eec6d6f 100755 --- a/src/make_ninja.py +++ b/src/make_ninja.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 import os import sys +import subprocess + + DEBUG=False try: @@ -20,8 +23,17 @@ if "QUACK_ROOT" not in os.environ: QUACK_ROOT=os.environ["QUACK_ROOT"] -if not DEBUG: - compile_gfortran_mac = """ + +def check_compiler_exists(compiler): + """Check if a compiler exists on the system.""" + try: + # Try to run the compiler with the --version flag to check its existence + subprocess.run([compiler, '--version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return True + except (subprocess.CalledProcessError, FileNotFoundError): + return False + +compile_gfortran_mac = """ FC = gfortran AR = libtool -static -o FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused-variable -Wno-unused -Wno-unused-dummy-argument -O3 @@ -29,32 +41,10 @@ CC = gcc CXX = g++ LAPACK=-lblas -llapack STDCXX=-lc++ -FIX_ORDER_OF_LIBS= +FIX_ORDER_OF_LIBS=-Wl,--start-group """ - compile_gfortran_linux = """ -FC = gfortran -AR = ar crs -FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused -Wno-unused-dummy-argument -O3 -CC = gcc -CXX = g++ -LAPACK=-lblas -llapack -STDCXX=-lstdc++ -FIX_ORDER_OF_LIBS=-Wl,--start-group -""" - - compile_ifort_linux = """ -FC = ifort -mkl=parallel -qopenmp -AR = ar crs -FFLAGS = -I$IDIR -g -Ofast -traceback -CC = icc -CXX = icpc -LAPACK= -STDCXX=-lstdc++ -FIX_ORDER_OF_LIBS=-Wl,--start-group -""" -else: - compile_gfortran_mac = """ +compile_gfortran_mac_debug = """ FC = gfortran AR = libtool -static -o FFLAGS = -I$IDIR -J$IDIR -fbacktrace -Wall -Wno-unused-variable -g -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant @@ -65,7 +55,7 @@ STDCXX=-lc++ FIX_ORDER_OF_LIBS= """ - compile_gfortran_linux = """ +compile_gfortran_linux_debug = """ FC = gfortran AR = ar crs FFLAGS = -I$IDIR -J$IDIR -fbacktrace -Wall -g -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant @@ -76,26 +66,50 @@ STDCXX=-lstdc++ FIX_ORDER_OF_LIBS=-Wl,--start-group """ -compile_olympe = """ -FC = ifort -mkl=parallel -qopenmp + + +if sys.platform == "Darwin": + + if DEBUG: + compiler = compile_gfortran_mac_debug + else: + compiler = compile_gfortran_mac + +elif sys.platform == "Linux" or os.path.exists('/proc/version'): + + if DEBUG: + compiler = compile_gfortran_linux_debug + + else: + if check_compiler_exists('ifort'): + compiler = """ +FC = ifort -qmkl=parallel -qopenmp AR = ar crs -FFLAGS = -I$IDIR -Ofast -traceback -xCORE-AVX512 +FFLAGS = -I$IDIR -module $IDIR -traceback -g -Ofast -xHost CC = icc CXX = icpc LAPACK= STDCXX=-lstdc++ -FIX_ORDER_OF_LIBS=-Wl,--start-group +FIX_ORDER_OF_LIBS=-Wl,--start-group """ + elif check_compiler_exists('gfortran'): + compiler = """ +FC = gfortran -fopenmp +AR = ar crs +FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused-variable -Wno-unused -Wno-unused-dummy-argument -O3 -march=native +CC = gcc +CXX = g++ +LAPACK=-lblas -llapack +STDCXX=-lstdc++ +FIX_ORDER_OF_LIBS=-Wl,--start-group +""" + else: + raise RuntimeError("Neither ifort nor gfortran compilers were found on this system.") -if sys.platform in ["linux", "linux2"]: -# compiler = compile_gfortran_linux - compiler = compile_ifort_linux -# compiler = compile_olympe -elif sys.platform == "darwin": - compiler = compile_gfortran_mac else: - print("Unknown platform. Only Linux and Darwin are supported.") - sys.exit(-1) + + print("Unknown platform. Only Linux and Darwin are supported.") + sys.exit(-1) header = """# # This file was automatically generated. Do not modify this file. From 664a98e57f7b3b428eef30b40db848fd071102ea Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Mon, 4 Nov 2024 22:32:23 +0100 Subject: [PATCH 8/9] merge with master --- src/make_ninja.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/make_ninja.py b/src/make_ninja.py index eec6d6f..78e2aec 100755 --- a/src/make_ninja.py +++ b/src/make_ninja.py @@ -36,7 +36,7 @@ def check_compiler_exists(compiler): compile_gfortran_mac = """ FC = gfortran AR = libtool -static -o -FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused-variable -Wno-unused -Wno-unused-dummy-argument -O3 +FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused-variable -Wno-unused -Wno-unused-dummy-argument -Wuninitialized -Wmaybe-uninitialized -O3 -march=native CC = gcc CXX = g++ LAPACK=-lblas -llapack @@ -81,7 +81,7 @@ elif sys.platform == "Linux" or os.path.exists('/proc/version'): compiler = compile_gfortran_linux_debug else: - if check_compiler_exists('ifort'): + if check_compiler_exists('ifortt'): compiler = """ FC = ifort -qmkl=parallel -qopenmp AR = ar crs @@ -96,7 +96,7 @@ FIX_ORDER_OF_LIBS=-Wl,--start-group compiler = """ FC = gfortran -fopenmp AR = ar crs -FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused-variable -Wno-unused -Wno-unused-dummy-argument -O3 -march=native +FFLAGS = -I$IDIR -J$IDIR -fbacktrace -g -Wall -Wno-unused-variable -Wno-unused -Wno-unused-dummy-argument -Wuninitialized -Wmaybe-uninitialized -O3 -march=native CC = gcc CXX = g++ LAPACK=-lblas -llapack From 344c2bd4fac6c07e3e11e9e04c73f775a067782a Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Tue, 5 Nov 2024 07:45:50 +0100 Subject: [PATCH 9/9] add ifort again --- src/make_ninja.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/make_ninja.py b/src/make_ninja.py index 78e2aec..edeb379 100755 --- a/src/make_ninja.py +++ b/src/make_ninja.py @@ -81,7 +81,7 @@ elif sys.platform == "Linux" or os.path.exists('/proc/version'): compiler = compile_gfortran_linux_debug else: - if check_compiler_exists('ifortt'): + if check_compiler_exists('ifort'): compiler = """ FC = ifort -qmkl=parallel -qopenmp AR = ar crs