Skip to content

Commit

Permalink
Merge branch 'pyscf:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
wxj6000 authored Nov 13, 2023
2 parents 09010c1 + 5811d24 commit 1694ad5
Show file tree
Hide file tree
Showing 29 changed files with 658 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
**/__pycache__
*.so
*.npz
*.out
*current_revision
**/build
**/launch_logs
Expand All @@ -13,6 +15,7 @@ output/
*.swo
*.swp
*~
**/qchem_input.in
#*
dockerfiles/manylinux/wheelhouse
gpu4pyscf/lib/bin
Expand Down
41 changes: 23 additions & 18 deletions benchmarks/df/dft_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pyscf
import time
import argparse
import numpy as np
from pyscf import lib
from pyscf.dft import rks

Expand Down Expand Up @@ -41,18 +42,19 @@
output_file = 'PySCF-16-cores-CPU.csv'
output_file = args.output_path + output_file

def run_dft(filename):
mol = pyscf.M(atom=filename, basis=bas, max_memory=64000)
def run_dft(path, filename):
mol = pyscf.M(atom=path+filename, basis=bas, max_memory=64000)
start_time = time.time()
# set verbose >= 6 for debugging timer
mol.verbose = 4 #verbose
mol.verbose = 1 #verbose
mol.max_memory = 40000
mf = rks.RKS(mol, xc=xc).density_fit(auxbasis='def2-universal-jkfit')
if args.solvent:
mf = mf.PCM()
mf.lebedev_order = 29
mf.method = 'IEF-PCM'

mf.with_solvent.lebedev_order = 29
mf.with_solvent.method = 'IEF-PCM'
mf.with_solvent.eps = 78.3553
mf.verbose = 6
mf.grids.atom_grid = (99,590)
mf.chkfile = None
prep_time = time.time() - start_time
Expand All @@ -62,7 +64,7 @@ def run_dft(filename):
try:
e_dft = mf.kernel()
scf_time = time.time() - start_time
except:
except Exception:
scf_time = -1
e_dft = 0

Expand All @@ -76,25 +78,28 @@ def run_dft(filename):
g.auxbasis_response = True
f = g.kernel()
grad_time = time.time() - start_time
except:
except Exception:
grad_time = -1
f = -1

# calculate hessian
if args.device == 'GPU':
cupy.get_default_memory_pool().free_all_blocks()

hess_time = -1
if args.with_hessian:
try:
start_time = time.time()
h = mf.Hessian()
h.auxbasis_response = 1
h.max_memory = 40000
hess = h.kernel()
hess_time = time.time() - start_time
except:
hess_time = -1
#try:
start_time = time.time()
h = mf.Hessian()
h.auxbasis_response = 1
h.max_memory = 40000
hess = h.kernel().reshape([3*mol.natm, 3*mol.natm])
hess_time = time.time() - start_time
#except Exception:
# hess_time = -1
# hess = -1

np.savez(args.output_path+filename+'.npz', e_dft=e_dft, grad=f, hess=hess)
return mol.natm, mol.nao, scf_time, grad_time, hess_time, e_dft

fields = ['mol','natm', 'nao', 't_scf', 't_gradient', 't_hessian', 'e_tot']
Expand All @@ -105,7 +110,7 @@ def run_dft(filename):
for filename in sorted(os.listdir(args.input_path)):
if filename.endswith(".xyz"):
print(f'running DFT {filename}')
info = run_dft(args.input_path+filename)
info = run_dft(args.input_path, filename)
row = [filename[:-4]]+list(info)
csvwriter.writerow(row)
csvfile.flush()
Expand Down
26 changes: 13 additions & 13 deletions benchmarks/df/organic/basis/sto-3g/Tesla V100-SXM2-32GB.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mol,natm,nao,t_scf,t_gradient,t_hessian,e_tot
020_Vitamin_C,20,68,7.735399961471558,0.8264245986938477,-1,-675.5191427445513
031_Inosine,31,107,12.40164589881897,1.2864620685577393,-1,-970.3601703535105
033_Bisphenol_A,33,101,9.470605850219727,1.3010294437408447,-1,-722.4575094545307
037_Mg_Porphin,37,141,10.585906982421875,1.7864344120025635,-1,-1173.7927754921361
042_Penicillin_V,42,142,14.566765546798706,1.8530471324920654,-1,-1485.4649683739317
045_Ochratoxin_A,45,157,16.409618377685547,2.151444673538208,-1,-1643.4719863900054
052_Cetirizine,52,164,16.940945386886597,2.433612108230591,-1,-1591.0513291828825
057_Tamoxifen,57,169,17.164642333984375,2.5976877212524414,-1,-1123.9167963056734
066_Raffinose,66,202,19.061853408813477,3.485790491104126,-1,-1882.9880554750498
084_Sphingomyelin,84,220,70.13539099693298,4.33745265007019,-1,-1787.52705174446
095_Azadirachtin,95,299,35.65800380706787,7.805527210235596,-1,-2530.024523612371
113_Taxol,113,361,41.06178140640259,12.37047815322876,-1,-2891.8561844202995
168_Valinomycin,168,480,66.3832175731659,26.61207914352417,-1,-3744.922364373644
020_Vitamin_C,20,68,7.868626832962036,1.0551254749298096,160.80799293518066,-675.538636198446
031_Inosine,31,107,13.161744117736816,1.6693317890167236,409.3673324584961,-970.3940011476416
033_Bisphenol_A,33,101,11.190348148345947,1.703892707824707,454.6797456741333,-722.4680797386372
037_Mg_Porphin,37,141,13.220695495605469,2.3627896308898926,613.8060190677643,-1173.8015084893464
042_Penicillin_V,42,142,16.221434831619263,2.5661509037017822,806.1365261077881,-1485.48745890511
045_Ochratoxin_A,45,157,17.118950366973877,2.869781255722046,942.4001016616821,-1643.4889926123333
052_Cetirizine,52,164,18.82169008255005,3.2975871562957764,1308.8825283050537,-1591.0707662509653
057_Tamoxifen,57,169,20.3020281791687,3.712913751602173,1614.187731742859,-1123.9277518506542
066_Raffinose,66,202,22.84470796585083,4.8171586990356445,2398.439987182617,-1883.0349428068212
084_Sphingomyelin,84,220,35.961305141448975,-1,-1,-1787.6089723002701
095_Azadirachtin,95,299,41.4524290561676,10.98064112663269,-1,-2530.0502561379244
113_Taxol,113,361,56.471648931503296,-1,-1,-2891.887299140597
168_Valinomycin,168,480,-1,-1,-1,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mol,natm,nao,t_scf,t_gradient,t_hessian,e_tot
020_Vitamin_C,20,484,10.453456163406372,2.7370195388793945,363.0008842945099,-685.0347463979249
031_Inosine,31,757,20.68114447593689,6.736889600753784,1316.5888483524323,-983.7176439065447
033_Bisphenol_A,33,751,17.637565851211548,6.877225160598755,1420.3841083049774,-731.960347742662
037_Mg_Porphin,37,944,24.36361074447632,11.089943408966064,2439.1287682056427,-1188.8981396236977
042_Penicillin_V,42,1007,30.862167358398438,11.582371473312378,3181.5790650844574,-1504.6450542609673
045_Ochratoxin_A,45,1100,33.41982841491699,14.166359901428223,4029.220572948456,-1664.4396913351384
052_Cetirizine,52,1198,40.039607763290405,18.70956540107727,6276.552805900574,-1611.0213497063874
057_Tamoxifen,57,1274,44.171112298965454,20.529136180877686,7396.354176044464,-1138.3891845703356
7 changes: 7 additions & 0 deletions benchmarks/df/organic/solvent/sto-3g/Tesla V100-SXM2-32GB.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mol,natm,nao,t_scf,t_gradient,t_hessian,e_tot
020_Vitamin_C,20,68,7.757320165634155,1.040503740310669,174.4666724205017,-675.5386361984456
031_Inosine,31,107,13.179906129837036,1.6433496475219727,417.5237069129944,-970.3940011476411
033_Bisphenol_A,33,101,11.242647647857666,1.7435667514801025,456.6348719596863,-722.4680797386372
037_Mg_Porphin,37,141,13.297797203063965,2.399493455886841,637.2147407531738,-1173.8015084893468
042_Penicillin_V,42,142,17.28551435470581,2.550989866256714,803.3315801620483,-1485.4874589051096
045_Ochratoxin_A,45,157,16.84193205833435,2.799733877182007,933.1838977336884,-1643.4889926123315
12 changes: 0 additions & 12 deletions benchmarks/df/organic/xc/LDA/qchem-32-cores-cpu.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
mol,t_scf,t_gradient,e_tot
020_Vitamin_C,14.0,3.56,-679.7314745086
031_Inosine,49.0,7.96,-975.8114577115
033_Bisphenol_A,46.0,8.89,-725.553763622
037_Mg_Porphin,66.0,14.14,-1179.2748793144
042_Penicillin_V,64.0,13.64,-1494.103579632
045_Ochratoxin_A,94.0,17.73,-1652.8352834053
052_Cetirizine,141.0,23.98,-1599.5921033435
057_Tamoxifen,130.0,28.07,-1128.1503311128
066_Raffinose,159.0,38.63,-1894.4283011989
084_Sphingomyelin,181.0,37.76,-1796.8793820306
095_Azadirachtin,503.0,108.83,-2543.5362671667
113_Taxol,815.0,175.2,-2906.2707301461
5 changes: 3 additions & 2 deletions benchmarks/df/qchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
parser.add_argument('--xc', type=str, default='B3LYP')
parser.add_argument('--input_path', type=str, default='./')
parser.add_argument('--output_path', type=str, default='./')

args = parser.parse_args()
bas = args.basis
xc = args.xc
Expand Down Expand Up @@ -43,9 +44,9 @@ def run_dft(filename):
input.write("THRESH 14\n")
input.write("BASIS_LIN_DEP_THRESH 12\n")
input.write("$end\n")

filename = args.xc + '_' + args.basis
subprocess.run(['qchem', '-np', '32', 'qchem_input.in', filename])
subprocess.run(['qchem', '-save', '-np', '32', 'qchem_input.in', filename, args.output_path+'/qcarchive_'+filename])
with open(filename, 'w') as output_file:
lines = output_file.readlines()
for line in lines:
Expand Down
86 changes: 86 additions & 0 deletions benchmarks/df/qchem_input.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
$molecule
0 1
C -1.42958937 -1.01658249 2.44831265
C -1.54149463 -0.27943595 1.12935913
C -2.95243912 1.47129501 2.22492550
C -2.84134324 0.73400280 3.54388810
C -1.55797242 -0.06742235 3.62210684
H -0.66497820 0.41085733 1.01283439
H -0.44314689 -1.54644194 2.49994231
H -3.93813646 2.00251835 2.17350554
H -3.71865156 0.04459988 3.66018043
H -0.68133448 0.63238265 3.63327796
O -1.92499204 2.46279929 2.14636482
C -1.46076301 4.67520648 3.08258818
C -1.65192906 4.60593616 4.58432062
H -0.74117334 5.43388332 2.85565168
C -3.37658473 6.27667868 2.91318631
C -2.26541279 5.88367074 5.11970508
H -2.31747310 3.73866848 4.83580579
C -3.56636040 6.20921206 4.41472333
H -4.36600055 6.45426127 2.41719619
H -1.54350069 6.73075622 4.97913735
H -4.32958469 5.42429404 4.65913754
O -2.52952388 7.38269576 2.59051909
C -3.31900286 8.44866624 2.05635630
C -3.26458455 9.66301263 2.97202724
C -2.80523815 10.85434814 2.14390783
H -4.26911658 9.86120175 3.42267320
C -2.45049436 10.34868118 0.75291070
H -1.92149828 11.34764146 2.62047963
H -3.01626404 10.91739387 -0.02697788
C -4.76356005 7.92754855 1.94107026
H -4.78266313 7.06714393 1.30527236
H -5.12531018 7.66145994 2.91227245
O -2.82580898 0.52071700 1.05150767
C -0.93849427 3.31732760 2.57761263
H -0.77727115 3.36776157 1.52103158
H -0.01653199 3.08491476 3.06839754
C -1.49224313 -1.28985314 -0.03177454
H -0.58145107 -1.84899344 0.02037852
H -2.32526415 -1.95746693 0.04080516
C -0.95163774 10.56175833 0.47072820
H -0.66603955 9.99216789 -0.38886496
H -0.38034325 10.24135666 1.31681648
O -1.55044662 -0.58860344 -1.27666860
H -1.40118565 -1.20385620 -1.99832308
O -2.45542951 -2.00981905 2.52598600
H -2.07814582 -2.83668451 2.83509848
O -1.53066740 -0.81010098 4.84381994
H -0.61998842 -0.98424670 5.09269150
O -2.88646987 1.67226139 4.62209700
H -3.42291955 1.31644411 5.33428785
O -0.39050984 4.37790095 5.21813565
H -0.43907755 4.65272412 6.13667438
O -2.50206790 5.74947404 6.52358741
H -2.24542728 6.55931660 6.97067871
O -4.06906224 7.46048270 4.89065678
H -4.76357327 7.30283533 5.53439721
O -2.76235824 4.99928466 2.37789525
O -5.59594331 8.94915410 1.38576835
H -6.48998576 8.61436213 1.28476127
O -2.79571817 8.86766013 0.68976834
O -2.35757225 9.42976003 4.05268533
H -2.22828280 10.24429373 4.54402949
O -3.84292711 11.83519815 2.06622328
H -3.45759742 12.71343457 2.10890596
O -0.70503591 11.94904429 0.22675035
H 0.04258943 12.04182451 -0.36826913

$end
$rem
JOBTYPE force
METHOD LDA
BASIS def2-tzvpp
SYMMETRY FALSE
SYM_IGNORE TRUE
XC_GRID 000099000590
NL_GRID 000050000194
MAX_SCF_CYCLES 100
ri_j True
ri_k True
aux_basis RIJK-def2-tzvp
SCF_CONVERGENCE 9
THRESH 14
BASIS_LIN_DEP_THRESH 12
$end
25 changes: 16 additions & 9 deletions benchmarks/df/run_gpu4pyscf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

DIR="./organic/xc"
[ ! -d "$DIR" ] && mkdir -p "$DIR"
for xc in LDA PBE B3LYP M06 wB97m-v
do
python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/xc/$xc/ --xc $xc
done
exit

run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/xc/LDA/ --xc LDA
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/xc/PBE/ --xc PBE
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/xc/B3LYP/ --xc B3LYP
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/xc/M06/ --xc M06
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/xc/wB97m-v/ --xc wB97m-v

DIR="./organic/basis"
[ ! -d "$DIR" ] && mkdir -p "$DIR"

for basis in def2-svp def2-tzvpp def2-tzvpd sto-3g 6-31g
do
python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/basis/$basis/ --basis $basis
done
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/basis/def2-svp/ --basis def2-svp
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/basis/def2-tzvpp/ --basis def2-tzvpp
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/basis/def2-tzvpd/ --basis def2-tzvpd
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/basis/sto-3g/ --basis sto-3g
run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/basis/6-31g/ --basis 6-31g

DIR="./organic/solvent"
[ ! -d "$DIR" ] && mkdir -p "$DIR"

run --cpu 64 --memory 128 --gpu 1 -- python3 dft_driver.py --input_path ../molecules/organic/ --output_path ./organic/solvent/def2-tzvpp/ --basis def2-tzvpp --with_hessian True --solvent C-PCM
6 changes: 4 additions & 2 deletions benchmarks/df/run_qchem.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

export QCSCRATCH=/tmp/

DIR="./organic/xc"
[ ! -d "$DIR" ] && mkdir -p "$DIR"

Expand All @@ -8,9 +10,9 @@ DIR="./organic/basis"

#for xc in LDA PBE B3LYP M06 wB97m-v
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/LDA/ --xc LDA &&
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/PBE/ --xc PBE &&
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/PBE/ --xc PBE &&
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/B3LYP/ --xc B3LYP &&
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/M06/ --xc M06 &&
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/M06/ --xc M06 &&
run --cpu 64 --memory 128 --gpu 0 -- python3 qchem.py --input_path ../molecules/organic/ --output_path ./organic/xc/wB97m-v/ --xc wB97m-v &&

#for basis in def2-svp def2-tzvpp def2-tzvpd sto-3g 6-31g 6-31g*
Expand Down
21 changes: 15 additions & 6 deletions benchmarks/scf/dft_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
parser.add_argument('--device', type=str, default='GPU')
parser.add_argument('--input_path', type=str, default='./')
parser.add_argument('--output_path', type=str, default='./')
parser.add_argument('--with_gradient', type=bool, default=False)
parser.add_argument('--with_hessian', type=bool, default=False)
parser.add_argument("--solvent", type=bool, default=False)

args = parser.parse_args()
bas = args.basis
verbose = args.verbose
Expand All @@ -39,23 +42,29 @@
output_file = 'PySCF-16-cores-CPU.csv'
output_file = args.output_path + output_file

def run_dft(filename):
def run_dft(filename):
mol = pyscf.M(atom=filename, basis=bas, max_memory=64000)
start_time = time.time()
start_time = time.time()
# set verbose >= 6 for debugging timer
mol.verbose = 4 #verbose
mol.max_memory = 40000
mf = rks.RKS(mol, xc=xc)
if args.solvent:
mf = mf.PCM()
mf.with_solvent.lebedev_order = 29
mf.with_solvent.method = 'IEF-PCM'
mf.with_solvent.eps = 78.3553
mf.grids.atom_grid = (99,590)
mf.chkfile = None
prep_time = time.time() - start_time
mf.conv_tol = 1e-9
mf.nlcgrids.atom_grid = (50,194)
mf.max_cycle = 100
print(mf.scf_summary)
try:
e_dft = mf.kernel()
scf_time = time.time() - start_time
except:
except Exception:
scf_time = -1
e_dft = 0

Expand All @@ -68,13 +77,13 @@ def run_dft(filename):
g.max_memory = 40000
f = g.kernel()
grad_time = time.time() - start_time
except:
except Exception:
grad_time = -1

# calculate hessian
if args.device == 'GPU':
cupy.get_default_memory_pool().free_all_blocks()

hess_time = -1
if args.with_hessian:
try:
Expand All @@ -83,7 +92,7 @@ def run_dft(filename):
h.max_memory = 40000
hess = h.kernel()
hess_time = time.time() - start_time
except:
except Exception:
hess_time = -1

return mol.natm, mol.nao, scf_time, grad_time, hess_time, e_dft
Expand Down
Loading

0 comments on commit 1694ad5

Please sign in to comment.