Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pfloos/QuAcK
Browse files Browse the repository at this point in the history
  • Loading branch information
pfloos committed Dec 16, 2024
2 parents 6653cea + 26d09cc commit a9ee0cf
Show file tree
Hide file tree
Showing 51 changed files with 3,673 additions and 267 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.slurm
*.mod
*.so
*.o
*.
__pycache__
Expand Down
69 changes: 51 additions & 18 deletions PyDuck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from pyscf import gto
import numpy as np
import subprocess
import time


#Find the value of the environnement variable QUACK_ROOT. If not present we use the current repository
if "QUACK_ROOT" not in os.environ:
Expand All @@ -22,7 +24,10 @@
parser.add_argument('--bohr', default='Angstrom', action='store_const', const='Bohr', help='By default QuAcK assumes that the xyz files are in Angstrom. Add this argument if your xyz file is in Bohr.')
parser.add_argument('-c', '--charge', type=int, default=0, help='Total charge of the molecule. Specify negative charges with "m" instead of the minus sign, for example m1 instead of -1. Default is 0')
parser.add_argument('--cartesian', default=False, action='store_true', help='Add this option if you want to use cartesian basis functions.')
parser.add_argument('--print_2e', default=False, action='store_true', help='Add this option if you want to print 2e-integrals.')
parser.add_argument('--print_2e', default=True, action='store_true', help='If True, print 2e-integrals to disk.')
parser.add_argument('--formatted_2e', default=False, action='store_true', help='Add this option if you want to print formatted 2e-integrals.')
parser.add_argument('--mmap_2e', default=False, action='store_true', help='If True, avoid using DRAM when generating 2e-integrals.')
parser.add_argument('--aosym_2e', default=False, action='store_true', help='If True, use 8-fold symmetry 2e-integrals.')
parser.add_argument('-fc', '--frozen_core', type=bool, default=False, help='Freeze core MOs. Default is false')
parser.add_argument('-m', '--multiplicity', type=int, default=1, help='Spin multiplicity. Default is 1 therefore singlet')
parser.add_argument('--working_dir', type=str, default=QuAcK_dir, help='Set a working directory to run the calculation.')
Expand All @@ -38,6 +43,9 @@
xyz=args.xyz + '.xyz'
cartesian=args.cartesian
print_2e=args.print_2e
formatted_2e=args.formatted_2e
mmap_2e=args.mmap_2e
aosym_2e=args.aosym_2e
working_dir=args.working_dir

#Read molecule
Expand All @@ -59,6 +67,7 @@
basis = input_basis,
charge = charge,
spin = multiplicity - 1
# symmetry = True # Enable symmetry
)

#Fix the unit for the lengths
Expand Down Expand Up @@ -129,33 +138,57 @@ def write_matrix_to_file(matrix,size,file,cutoff=1e-15):
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, 'w')
def write_tensor_to_file(tensor,size,file_name,cutoff=1e-15):
f = open(file_name, 'w')
for i in range(size):
for j in range(i,size):
for k in range(i,size):
for l in range(j,size):
if abs(tensor[i][k][j][l]) > cutoff:
#f.write(str(i+1)+' '+str(j+1)+' '+str(k+1)+' '+str(l+1)+' '+"{:.16E}".format(tensor[i][k][j][l]))
f.write(str(i+1)+' '+str(j+1)+' '+str(k+1)+' '+str(l+1)+' '+"{:.16E}".format(tensor[i][k][j][l]))
f.write('\n')
f.close()

# Write two-electron integrals
if print_2e:
# (formatted)
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', '-f', working_dir + '/int/ERI.bin'])
# chem -> phys notation
eri_ao = eri_ao.transpose(0, 2, 1, 3)
f = open(working_dir + '/int/ERI.bin', 'w')
eri_ao.tofile(working_dir + '/int/ERI.bin')
f.close()
# Write two-electron integrals to HD
ti_2e = time.time()

if formatted_2e:
output_file_path = working_dir + '/int/ERI.dat'
subprocess.call(['rm', '-f', output_file_path])
eri_ao = mol.intor('int2e')
write_tensor_to_file(eri_ao, norb, output_file_path)

if aosym_2e:
output_file_path = working_dir + '/int/ERI_chem.bin'
subprocess.call(['rm', '-f', output_file_path])
eri_ao = mol.intor('int2e', aosym='s8')
f = open(output_file_path, 'w')
eri_ao.tofile(output_file_path)
f.close()
else:
output_file_path = working_dir + '/int/ERI.bin'
subprocess.call(['rm', '-f', output_file_path])
if(mmap_2e):
# avoid using DRAM
eri_shape = (norb, norb, norb, norb)
eri_mmap = np.memmap(output_file_path, dtype='float64', mode='w+', shape=eri_shape)
mol.intor('int2e', out=eri_mmap)
for i in range(norb):
eri_mmap[i, :, :, :] = eri_mmap[i, :, :, :].transpose(1, 0, 2)
eri_mmap.flush()
del eri_mmap
else:
eri_ao = mol.intor('int2e').transpose(0, 2, 1, 3) # chem -> phys
f = open(output_file_path, 'w')
eri_ao.tofile(output_file_path)
f.close()

te_2e = time.time()
print("Wall time for writing 2e-integrals to disk: {:.3f} seconds".format(te_2e - ti_2e))
sys.stdout.flush()




#Execute the QuAcK fortran program
Expand Down
4 changes: 4 additions & 0 deletions input/hpc_flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# if True (T), switch to HPC mode
F
# if True (T), use GPU
F
2 changes: 2 additions & 0 deletions quack.rc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ esac
export QUACK_ROOT="$( cd $QUACK_ROOT; pwd -P )"

export PATH="${QUACK_ROOT}/bin:$PATH"
export LD_LIBRARY_PATH="${QUACK_ROOT}/src/cuda/build:$LD_LIBRARY_PATH"

144 changes: 144 additions & 0 deletions src/AOtoMO/Hartree_matrix_AO_basis.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,147 @@ subroutine Hartree_matrix_AO_basis(nBas,P,G,H)
end do

end subroutine

! ---

subroutine Hartree_matrix_AO_basis_hpc(nBas, ERI_size, P, ERI_chem, H)

implicit none

integer, intent(in) :: nBas
integer*8, intent(in) :: ERI_size
double precision, intent(in) :: P(nBas,nBas)
double precision, intent(in) :: ERI_chem(ERI_size)
double precision, intent(out) :: H(nBas,nBas)

integer*8 :: mu, nu, la, si, nBas8
integer*8 :: nunu, lala, nula, lasi, numu
integer*8 :: nunu0, lala0
integer*8 :: nunununu, nunulala, nununula, nunulasi
integer*8 :: lalanunu, lasinunu, numulala, lalanumu
integer*8 :: numunula, numulasi, lasinumu, nununumu
integer*8 :: nunununu0, numunumu0



nBas8 = int(nBas, kind=8)

!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE (nu, la, si, mu, &
!$OMP nunu0, nunu, nula, lala0, lala, lasi, numu, &
!$OMP nunununu0, nunununu, nununula, numulala, numunula, &
!$OMP nunulala, lalanunu, lalanumu, nunulasi, lasinunu, &
!$OMP numunumu0, nununumu, numulasi, lasinumu) &
!$OMP SHARED (nBas8, H, P, ERI_chem)
!$OMP DO
do nu = 1, nBas8

nunu0 = shiftr(nu * (nu - 1), 1)
nunu = nunu0 + nu
nunununu0 = shiftr(nunu * (nunu - 1), 1)

nunununu = nunununu0 + nunu
H(nu,nu) = P(nu,nu) * ERI_chem(nunununu)

do la = 1, nu - 1

lala0 = shiftr(la * (la - 1), 1)

lala = lala0 + la
nunulala = nunununu0 + lala
H(nu,nu) = H(nu,nu) + P(la,la) * ERI_chem(nunulala)

nula = nunu0 + la
nununula = nunununu0 + nula
H(nu,nu) = H(nu,nu) + 2.d0 * P(la,nu) * ERI_chem(nununula)

do si = 1, la - 1
lasi = lala0 + si
nunulasi = nunununu0 + lasi
H(nu,nu) = H(nu,nu) + 2.d0 * P(si,la) * ERI_chem(nunulasi)
enddo
enddo

do la = nu + 1, nBas8

lala0 = shiftr(la * (la - 1), 1)

lala = lala0 + la
lalanunu = shiftr(lala * (lala - 1), 1) + nunu
H(nu,nu) = H(nu,nu) + P(la,la) * ERI_chem(lalanunu)

do si = 1, la - 1
lasi = lala0 + si
lasinunu = shiftr(lasi * (lasi - 1), 1) + nunu
H(nu,nu) = H(nu,nu) + 2.d0 * P(si,la) * ERI_chem(lasinunu)
enddo
enddo

do mu = 1, nu - 1

numu = nunu0 + mu

numunumu0 = shiftr(numu * (numu - 1), 1)

nununumu = nunununu0 + numu
H(mu,nu) = p(nu,nu) * ERI_chem(nununumu)

do la = 1, nu - 1
lala = shiftr(la * (la - 1), 1) + la
numulala = numunumu0 + lala
H(mu,nu) = H(mu,nu) + p(la,la) * ERI_chem(numulala)
enddo

do la = nu + 1, nBas8
lala = shiftr(la * (la - 1), 1) + la
lalanumu = shiftr(lala * (lala - 1), 1) + numu
H(mu,nu) = H(mu,nu) + p(la,la) * ERI_chem(lalanumu)
enddo

do la = 1, mu
nula = nunu0 + la
numunula = numunumu0 + nula
H(mu,nu) = H(mu,nu) + 2.d0 * P(la,nu) * ERI_chem(numunula)
enddo

do la = mu + 1, nu - 1
nula = nunu0 + la
numunula = shiftr(nula * (nula - 1), 1) + numu
H(mu,nu) = H(mu,nu) + 2.d0 * P(la,nu) * ERI_chem(numunula)
enddo

do la = 2, nu - 1
lala0 = shiftr(la * (la - 1), 1)
do si = 1, la - 1
lasi = lala0 + si
numulasi = numunumu0 + lasi
H(mu,nu) = H(mu,nu) + 2.d0 * P(si,la) * ERI_chem(numulasi)
enddo
enddo

do la = nu + 1, nBas8
lala0 = shiftr(la * (la - 1), 1)
do si = 1, la - 1
lasi = lala0 + si
lasinumu = shiftr(lasi * (lasi - 1), 1) + numu
H(mu,nu) = H(mu,nu) + 2.d0 * P(si,la) * ERI_chem(lasinumu)
enddo
enddo

enddo ! mu
enddo ! nu
!$OMP END DO
!$OMP END PARALLEL

do nu = 1, nBas8
do mu = nu+1, nBas8
H(mu,nu) = H(nu,mu)
enddo
enddo

return
end subroutine

! ---


Loading

0 comments on commit a9ee0cf

Please sign in to comment.