From 4534034bf7089073f5492c727ec955851c182197 Mon Sep 17 00:00:00 2001 From: "xiaojie.wu" Date: Wed, 15 Nov 2023 02:57:00 +0800 Subject: [PATCH] switch ipynb -> py --- benchmarks/df/dft_driver.py | 20 +- benchmarks/df/generate_tables.ipynb | 552 -------------------- benchmarks/df/generate_tables.py | 113 ++++ benchmarks/df/qchem_input.in | 86 --- benchmarks/scf/generate_tables.ipynb | 201 ------- benchmarks/scf/generate_tables.py | 40 ++ gpu4pyscf/solvent/grad/pcm.py | 13 +- gpu4pyscf/solvent/hessian/pcm.py | 2 +- gpu4pyscf/solvent/tests/test_pcm_hessian.py | 40 +- 9 files changed, 193 insertions(+), 874 deletions(-) delete mode 100644 benchmarks/df/generate_tables.ipynb create mode 100644 benchmarks/df/generate_tables.py delete mode 100644 benchmarks/df/qchem_input.in delete mode 100644 benchmarks/scf/generate_tables.ipynb create mode 100644 benchmarks/scf/generate_tables.py diff --git a/benchmarks/df/dft_driver.py b/benchmarks/df/dft_driver.py index 69cc7621..5a629c04 100644 --- a/benchmarks/df/dft_driver.py +++ b/benchmarks/df/dft_driver.py @@ -88,16 +88,16 @@ def run_dft(path, filename): 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().reshape([3*mol.natm, 3*mol.natm]) - hess_time = time.time() - start_time - #except Exception: - # hess_time = -1 - # hess = -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 diff --git a/benchmarks/df/generate_tables.ipynb b/benchmarks/df/generate_tables.ipynb deleted file mode 100644 index 322939e5..00000000 --- a/benchmarks/df/generate_tables.ipynb +++ /dev/null @@ -1,552 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 123, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 122, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Density fitting with difference basis" - ] - }, - { - "cell_type": "code", - "execution_count": 125, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 124, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | sto-3g | 6-31g | def2-svp | def2-tzvpp | def2-tzvpd |\n", - "|:------------------|-------:|---------:|--------:|-----------:|-------------:|-------------:|\n", - "| 020_Vitamin_C | 20 | 0.92 | 1.5 | 2.13 | 5.94 | 8.36 |\n", - "| 031_Inosine | 31 | 4.74 | 7.12 | 10.98 | 17.02 | 21.17 |\n", - "| 033_Bisphenol_A | 33 | 4.53 | 6.24 | 7 | 16.55 | 20.96 |\n", - "| 037_Mg_Porphin | 37 | 7.38 | 9.9 | 13.88 | 16.9 | 23.39 |\n", - "| 042_Penicillin_V | 42 | 5.9 | 8.19 | 11.43 | 16.41 | 20.11 |\n", - "| 045_Ochratoxin_A | 45 | 6.94 | 10.06 | 12.9 | 15.33 | 21.62 |\n", - "| 052_Cetirizine | 52 | 7.15 | 9.86 | 13.85 | 17.34 | 23.24 |\n", - "| 057_Tamoxifen | 57 | 7.48 | 8.95 | 13.19 | 19.26 | 24.22 |\n", - "| 066_Raffinose | 66 | 8.22 | 10.12 | 14.98 | 15.28 | 16.1 |\n", - "| 084_Sphingomyelin | 84 | nan | 9.69 | 14.83 | 17.82 | 20.33 |\n", - "| 095_Azadirachtin | 95 | 16.06 | 17.18 | 24.22 | 23.29 | nan |\n", - "| 113_Taxol | 113 | 20.11 | 18.04 | 23.38 | 24 | nan |\n", - "| 168_Valinomycin | 168 | 23.43 | 19.41 | nan | nan | nan |\n" - ] - } - ], - "source": [ - "A100_file = 'NVIDIA A100-SXM4-80GB.csv'\n", - "V100_file = 'Tesla V100-SXM2-32GB.csv'\n", - "qchem_file = 'qchem-32-cores-cpu.csv'\n", - "\n", - "keys = ['mol', 'natm']\n", - "empty = {'mol':[], 'natm':[]}\n", - "df_A100_scf = pd.DataFrame(empty)\n", - "df_V100_scf = pd.DataFrame(empty)\n", - "df_A100_grad = pd.DataFrame(empty)\n", - "df_V100_grad = pd.DataFrame(empty)\n", - "path = 'organic/basis/'\n", - "\n", - "for basis in ['sto-3g', '6-31g', 'def2-svp', 'def2-tzvpp', 'def2-tzvpd']:\n", - " df_qchem = pd.read_csv(path + basis + '/' + qchem_file)\n", - " df_qchem = df_qchem.rename(columns={'t_scf':'scf_qchem', 't_gradient':'grad_qchem'})\n", - " \n", - " df_A100 = pd.read_csv(path + basis + '/' + A100_file)\n", - " df_A100 = df_A100.rename(columns={'t_scf':'scf_A100', 't_gradient':'grad_A100'})\n", - " df_A100 = df_A100.merge(df_qchem, how='outer', on='mol')\n", - " \n", - " df_A100['scf_'+basis] = df_A100['scf_qchem']/df_A100['scf_A100']\n", - " df_A100['grad_'+basis] = df_A100['grad_qchem']/df_A100['grad_A100']\n", - " df_A100 = df_A100[keys+['scf_'+basis, 'grad_'+basis]]\n", - " \n", - " df_A100_scf = df_A100_scf.merge(df_A100[keys+['scf_'+basis]], how='outer', on=keys)\n", - " df_A100_grad= df_A100_grad.merge(df_A100[keys+['grad_'+basis]], how='outer', on=keys)\n", - " df_A100_scf = df_A100_scf.rename(columns={'scf_'+basis:basis})\n", - " df_A100_grad = df_A100_grad.rename(columns={'grad_'+basis:basis})\n", - " df_A100_scf[basis] = df_A100_scf[basis].apply(lambda x: round(x,2))\n", - " df_A100_grad[basis] = df_A100_grad[basis].apply(lambda x: round(x,2))\n", - "\n", - " df_V100 = pd.read_csv(path + basis + '/' + V100_file)\n", - " df_V100 = df_V100.rename(columns={'t_scf':'scf_V100', 't_gradient':'grad_V100'})\n", - " df_V100 = df_V100.merge(df_qchem, how='outer', on='mol')\n", - " df_V100['scf_'+basis] = df_V100['scf_qchem']/df_V100['scf_V100']\n", - " df_V100['grad_'+basis] = df_V100['grad_qchem']/df_V100['grad_V100']\n", - "\n", - " df_V100_scf = df_V100_scf.merge(df_V100[keys+['scf_'+basis,]], how='outer', on=keys)\n", - " df_V100_grad= df_V100_grad.merge(df_V100[keys+['grad_'+basis]], how='outer', on=keys)\n", - " df_V100_scf = df_V100_scf.rename(columns={'scf_'+basis:basis})\n", - " \n", - " df_V100_grad = df_V100_grad.rename(columns={'grad_'+basis:basis})\n", - " df_V100_scf[basis] = df_V100_scf[basis].apply(lambda x: round(x,2))\n", - " df_V100_grad[basis] = df_V100_grad[basis].apply(lambda x: round(x,2))\n", - " \n", - "print(df_A100_scf.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 127, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 126, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | sto-3g | 6-31g | def2-svp | def2-tzvpp | def2-tzvpd |\n", - "|:------------------|-------:|---------:|--------:|-----------:|-------------:|-------------:|\n", - "| 020_Vitamin_C | 20 | 0.52 | 0.93 | 1.23 | 3.98 | 4.88 |\n", - "| 031_Inosine | 31 | 0.97 | 1.92 | 3.03 | 6.79 | 8.19 |\n", - "| 033_Bisphenol_A | 33 | 1.16 | 1.89 | 2.09 | 6.72 | 8.31 |\n", - "| 037_Mg_Porphin | 37 | 1.79 | 3.55 | 4.49 | 7.64 | 10.55 |\n", - "| 042_Penicillin_V | 42 | 1.37 | 2.62 | 3.63 | 7.69 | 9.24 |\n", - "| 045_Ochratoxin_A | 45 | 1.58 | 3.23 | 4.12 | 7.27 | 9.88 |\n", - "| 052_Cetirizine | 52 | 1.83 | 3.61 | 4.72 | 8.63 | 11.32 |\n", - "| 057_Tamoxifen | 57 | 1.92 | 3.3 | 4.59 | 9.72 | 7.87 |\n", - "| 066_Raffinose | 66 | 2.31 | 4.04 | 5.75 | 6.09 | 5.54 |\n", - "| 084_Sphingomyelin | 84 | nan | 3.29 | 4.92 | 7.32 | 8 |\n", - "| 095_Azadirachtin | 95 | 4.63 | 8.46 | 10.55 | 13.83 | nan |\n", - "| 113_Taxol | 113 | 6.55 | 10.1 | 9.43 | 12.31 | nan |\n", - "| 168_Valinomycin | 168 | 9.23 | 11.66 | nan | nan | nan |\n" - ] - } - ], - "source": [ - "print(df_V100_scf.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 129, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 128, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | sto-3g | 6-31g | def2-svp | def2-tzvpp | def2-tzvpd |\n", - "|:------------------|-------:|---------:|--------:|-----------:|-------------:|-------------:|\n", - "| 020_Vitamin_C | 20 | 3.13 | 4.12 | 5.98 | 9.71 | 10.7 |\n", - "| 031_Inosine | 31 | 11.42 | 9.82 | 13.23 | 16.47 | 16.16 |\n", - "| 033_Bisphenol_A | 33 | 13.28 | 10.3 | 11.94 | 16.08 | 16.02 |\n", - "| 037_Mg_Porphin | 37 | 13.75 | 10.54 | 15.87 | 18.33 | 19.89 |\n", - "| 042_Penicillin_V | 42 | 13.3 | 10.7 | 14.07 | 17.2 | 18.81 |\n", - "| 045_Ochratoxin_A | 45 | 14.68 | 11.33 | 16.28 | 19.79 | 20.94 |\n", - "| 052_Cetirizine | 52 | 21.46 | 14.62 | 19.55 | 20.51 | 21.93 |\n", - "| 057_Tamoxifen | 57 | 20.97 | 16.37 | 18.78 | 20.27 | 21.96 |\n", - "| 066_Raffinose | 66 | 25.4 | 17.78 | 25.71 | 23.88 | 22.38 |\n", - "| 084_Sphingomyelin | 84 | nan | 17.46 | 20.9 | 23.64 | 26.52 |\n", - "| 095_Azadirachtin | 95 | 39.13 | 32.27 | 40.78 | 39.94 | nan |\n", - "| 113_Taxol | 113 | 48.57 | 42.77 | 51.57 | 49.03 | nan |\n", - "| 168_Valinomycin | 168 | 87.81 | 72.58 | nan | nan | nan |\n" - ] - } - ], - "source": [ - "print(df_A100_grad.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 131, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 130, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | sto-3g | 6-31g | def2-svp | def2-tzvpp | def2-tzvpd |\n", - "|:------------------|-------:|---------:|--------:|-----------:|-------------:|-------------:|\n", - "| 020_Vitamin_C | 20 | 1.43 | 2.4 | 3.3 | 5.46 | 5.54 |\n", - "| 031_Inosine | 31 | 3.01 | 4.22 | 5.14 | 7.06 | 6.84 |\n", - "| 033_Bisphenol_A | 33 | 3.31 | 4.18 | 4.38 | 6.75 | 6.89 |\n", - "| 037_Mg_Porphin | 37 | 4.13 | 5.08 | 6.42 | 7.89 | 8.54 |\n", - "| 042_Penicillin_V | 42 | 4.05 | 5.06 | 5.89 | 7.88 | 8.39 |\n", - "| 045_Ochratoxin_A | 45 | 4.59 | 5.42 | 6.8 | 8.6 | 8.93 |\n", - "| 052_Cetirizine | 52 | 6.11 | 7.04 | 7.97 | 9.13 | 9.53 |\n", - "| 057_Tamoxifen | 57 | 6.17 | 8.05 | 7.74 | 9.3 | 9.22 |\n", - "| 066_Raffinose | 66 | 7.9 | 9.49 | 10.82 | 10.51 | 9.58 |\n", - "| 084_Sphingomyelin | 84 | nan | 7.64 | 7.99 | 9.56 | 10.39 |\n", - "| 095_Azadirachtin | 95 | 13.3 | 17.59 | 16.25 | 17.93 | nan |\n", - "| 113_Taxol | 113 | 17.55 | 23.43 | 20.81 | 21.54 | nan |\n", - "| 168_Valinomycin | 168 | 31.21 | 38.79 | nan | nan | nan |\n" - ] - } - ], - "source": [ - "print(df_V100_grad.to_markdown(index=False))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Density fitting with different xc" - ] - }, - { - "cell_type": "code", - "execution_count": 133, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 132, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | LDA | PBE | B3LYP | M06 | wB97m-v |\n", - "|:------------------|-------:|-------:|-------:|--------:|-------:|----------:|\n", - "| 020_Vitamin_C | 20 | 2.86 | 6.09 | 13.11 | 11.58 | 17.46 |\n", - "| 031_Inosine | 31 | 13.14 | 15.87 | 16.57 | 25.89 | 26.14 |\n", - "| 033_Bisphenol_A | 33 | 12.31 | 16.88 | 16.54 | 28.45 | 28.82 |\n", - "| 037_Mg_Porphin | 37 | 13.85 | 19.03 | 20.53 | 28.31 | 30.27 |\n", - "| 042_Penicillin_V | 42 | 10.34 | 13.35 | 15.34 | 22.01 | 24.2 |\n", - "| 045_Ochratoxin_A | 45 | 13.34 | 15.3 | 19.66 | 27.08 | 25.41 |\n", - "| 052_Cetirizine | 52 | 17.79 | 17.44 | 19 | 24.41 | 25.87 |\n", - "| 057_Tamoxifen | 57 | 14.7 | 16.57 | 18.4 | 24.86 | 25.47 |\n", - "| 066_Raffinose | 66 | 13.77 | 14.2 | 20.47 | 22.94 | 25.35 |\n", - "| 084_Sphingomyelin | 84 | 14.24 | 12.82 | 15.96 | 22.11 | 24.46 |\n", - "| 095_Azadirachtin | 95 | 5.58 | 7.72 | 24.18 | 26.84 | 25.21 |\n", - "| 113_Taxol | 113 | 5.44 | 6.81 | 24.58 | 29.14 | nan |\n", - "| 168_Valinomycin | 168 | nan | nan | nan | nan | nan |\n" - ] - } - ], - "source": [ - "keys = ['mol', 'natm']\n", - "empty = {'mol':[], 'natm':[]}\n", - "df_A100_scf = pd.DataFrame(empty)\n", - "df_V100_scf = pd.DataFrame(empty)\n", - "df_A100_grad = pd.DataFrame(empty)\n", - "df_V100_grad = pd.DataFrame(empty)\n", - "path = 'organic/xc/'\n", - "for xc in ['LDA', 'PBE', 'B3LYP', 'M06', 'wB97m-v']:\n", - " df_qchem = pd.read_csv(path + xc + '/' + qchem_file)\n", - " df_qchem = df_qchem.rename(columns={'t_scf':'scf_qchem', 't_gradient':'grad_qchem'})\n", - " \n", - " df_A100 = pd.read_csv(path + xc + '/' + A100_file)\n", - " df_A100 = df_A100.rename(columns={'t_scf':'scf_A100', 't_gradient':'grad_A100'})\n", - " df_A100 = df_A100.merge(df_qchem, how='outer', on='mol')\n", - " \n", - " df_A100['scf_'+xc] = df_A100['scf_qchem']/df_A100['scf_A100']\n", - " df_A100['grad_'+xc] = df_A100['grad_qchem']/df_A100['grad_A100']\n", - " df_A100 = df_A100[keys+['scf_'+xc, 'grad_'+xc]]\n", - " \n", - " df_A100_scf = df_A100_scf.merge(df_A100[keys+['scf_'+xc]], how='outer', on=keys)\n", - " df_A100_grad= df_A100_grad.merge(df_A100[keys+['grad_'+xc]], how='outer', on=keys)\n", - " df_A100_scf = df_A100_scf.rename(columns={'scf_'+xc:xc})\n", - " df_A100_grad = df_A100_grad.rename(columns={'grad_'+xc:xc})\n", - " df_A100_scf[xc] = df_A100_scf[xc].apply(lambda x: round(x,2))\n", - " df_A100_grad[xc] = df_A100_grad[xc].apply(lambda x: round(x,2))\n", - "\n", - " df_V100 = pd.read_csv(path + xc + '/' + V100_file)\n", - " df_V100 = df_V100.rename(columns={'t_scf':'scf_V100', 't_gradient':'grad_V100'})\n", - " df_V100 = df_V100.merge(df_qchem, how='outer', on='mol')\n", - " df_V100['scf_'+xc] = df_V100['scf_qchem']/df_V100['scf_V100']\n", - " df_V100['grad_'+xc] = df_V100['grad_qchem']/df_V100['grad_V100']\n", - "\n", - " df_V100_scf = df_V100_scf.merge(df_V100[keys+['scf_'+xc,]], how='outer', on=keys)\n", - " df_V100_grad= df_V100_grad.merge(df_V100[keys+['grad_'+xc]], how='outer', on=keys)\n", - " df_V100_scf = df_V100_scf.rename(columns={'scf_'+xc:xc})\n", - " \n", - " df_V100_grad = df_V100_grad.rename(columns={'grad_'+xc:xc})\n", - " df_V100_scf[xc] = df_V100_scf[xc].apply(lambda x: round(x,2))\n", - " df_V100_grad[xc] = df_V100_grad[xc].apply(lambda x: round(x,2))\n", - "\n", - "print(df_A100_scf.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 135, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 134, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | LDA | PBE | B3LYP | M06 | wB97m-v |\n", - "|:------------------|-------:|------:|------:|--------:|------:|----------:|\n", - "| 020_Vitamin_C | 20 | 1.89 | 3.3 | 8.18 | 5.95 | 10.58 |\n", - "| 031_Inosine | 31 | 4.64 | 5.95 | 6.41 | 9.48 | 13.15 |\n", - "| 033_Bisphenol_A | 33 | 4.85 | 6.64 | 6.58 | 11.04 | 14.72 |\n", - "| 037_Mg_Porphin | 37 | 5.61 | 8.6 | 9.01 | 12.34 | 16.56 |\n", - "| 042_Penicillin_V | 42 | 4.36 | 6.17 | 7.09 | 10.62 | 14.28 |\n", - "| 045_Ochratoxin_A | 45 | 5.47 | 6.97 | 8.74 | 12.05 | 14.14 |\n", - "| 052_Cetirizine | 52 | 8.43 | 8.51 | 9.16 | 12.44 | 15.37 |\n", - "| 057_Tamoxifen | 57 | 6.79 | 8.41 | 9.98 | 13.44 | 15.67 |\n", - "| 066_Raffinose | 66 | 3.22 | 4.31 | 8.11 | 10.58 | 13.22 |\n", - "| 084_Sphingomyelin | 84 | 3.34 | 3.97 | 6.52 | 8.63 | 12.11 |\n", - "| 095_Azadirachtin | 95 | 3.35 | 4.74 | 14.29 | 16.52 | 15.05 |\n", - "| 113_Taxol | 113 | 3.12 | 4.1 | 12.59 | 15.74 | nan |\n" - ] - } - ], - "source": [ - "print(df_V100_scf.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 137, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 136, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | LDA | PBE | B3LYP | M06 | wB97m-v |\n", - "|:------------------|-------:|-------:|-------:|--------:|-------:|----------:|\n", - "| 020_Vitamin_C | 20 | 5.02 | 7.04 | 10.55 | 9.28 | 11.11 |\n", - "| 031_Inosine | 31 | 7.3 | 10.03 | 15.12 | 12.62 | 13.9 |\n", - "| 033_Bisphenol_A | 33 | 7.58 | 11.1 | 15.55 | 12.64 | 14 |\n", - "| 037_Mg_Porphin | 37 | 7.47 | 11.34 | 18.05 | 15.81 | 14.85 |\n", - "| 042_Penicillin_V | 42 | 6.03 | 8.96 | 17.4 | 14.47 | 13.81 |\n", - "| 045_Ochratoxin_A | 45 | 7.51 | 9.33 | 19.51 | 17.2 | 14.55 |\n", - "| 052_Cetirizine | 52 | 8.32 | 9.7 | 20.8 | 16.46 | 15.7 |\n", - "| 057_Tamoxifen | 57 | 8.91 | 9.61 | 20.61 | 16.2 | 15 |\n", - "| 066_Raffinose | 66 | 8.52 | 9.46 | 24.2 | 18.63 | 17.13 |\n", - "| 084_Sphingomyelin | 84 | 8.51 | 9.49 | 23.62 | 21.63 | 17.66 |\n", - "| 095_Azadirachtin | 95 | 7.69 | 9.48 | 42.24 | 34.01 | 23.93 |\n", - "| 113_Taxol | 113 | 8.08 | 9.05 | 51.03 | 40.13 | nan |\n", - "| 168_Valinomycin | 168 | nan | nan | nan | nan | nan |\n" - ] - } - ], - "source": [ - "print(df_A100_grad.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 139, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 138, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | LDA | PBE | B3LYP | M06 | wB97m-v |\n", - "|:------------------|-------:|------:|------:|--------:|------:|----------:|\n", - "| 020_Vitamin_C | 20 | 3.19 | 4.28 | 5.9 | 4.82 | 5.84 |\n", - "| 031_Inosine | 31 | 3.21 | 4.5 | 6.55 | 5.52 | 6.39 |\n", - "| 033_Bisphenol_A | 33 | 3.55 | 4.87 | 6.61 | 5.51 | 6.48 |\n", - "| 037_Mg_Porphin | 37 | 3.19 | 5.2 | 8.32 | 7.26 | 6.81 |\n", - "| 042_Penicillin_V | 42 | 3.15 | 4.35 | 8.11 | 7.23 | 6.97 |\n", - "| 045_Ochratoxin_A | 45 | 3.32 | 4.29 | 8.99 | 8.04 | 6.92 |\n", - "| 052_Cetirizine | 52 | 3.51 | 4.6 | 9.41 | 8.18 | 7.57 |\n", - "| 057_Tamoxifen | 57 | 3.86 | 4.66 | 9.56 | 8.4 | 7.51 |\n", - "| 066_Raffinose | 66 | 3.4 | 4.32 | 10.94 | 9.4 | 8.29 |\n", - "| 084_Sphingomyelin | 84 | 3.15 | 3.81 | 9.66 | 8.97 | 8.03 |\n", - "| 095_Azadirachtin | 95 | 3.32 | 4.37 | 18.47 | 16.01 | 1.68 |\n", - "| 113_Taxol | 113 | 3.12 | 1.19 | 22.53 | 16.94 | nan |\n" - ] - } - ], - "source": [ - "print(df_V100_grad.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "vscode": { - "languageId": "python" - } - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Merlin (Python3 + MLSQL) [Spark 3.0]", - "language": "python", - "name": "merlin_kernel" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "Python3 with MLSQL", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "0.1" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/benchmarks/df/generate_tables.py b/benchmarks/df/generate_tables.py new file mode 100644 index 00000000..0eef163b --- /dev/null +++ b/benchmarks/df/generate_tables.py @@ -0,0 +1,113 @@ +import pandas as pd +import numpy as np + +# ------------------------------------------- +# | Density fitting with different basis | +# ------------------------------------------- + +A100_file = 'NVIDIA A100-SXM4-80GB.csv' +V100_file = 'Tesla V100-SXM2-32GB.csv' +qchem_file = 'qchem-32-cores-cpu.csv' + +keys = ['mol', 'natm'] +empty = {'mol':[], 'natm':[]} +df_A100_scf = pd.DataFrame(empty) +df_V100_scf = pd.DataFrame(empty) +df_A100_grad = pd.DataFrame(empty) +df_V100_grad = pd.DataFrame(empty) +path = 'organic/basis/' + +for basis in ['sto-3g', '6-31g', 'def2-svp', 'def2-tzvpp', 'def2-tzvpd']: + df_qchem = pd.read_csv(path + basis + '/' + qchem_file) + df_qchem = df_qchem.rename(columns={'t_scf':'scf_qchem', 't_gradient':'grad_qchem'}) + + df_A100 = pd.read_csv(path + basis + '/' + A100_file) + df_A100 = df_A100.rename(columns={'t_scf':'scf_A100', 't_gradient':'grad_A100'}) + df_A100 = df_A100.merge(df_qchem, how='outer', on='mol') + + df_A100['scf_'+basis] = df_A100['scf_qchem']/df_A100['scf_A100'] + df_A100['grad_'+basis] = df_A100['grad_qchem']/df_A100['grad_A100'] + df_A100 = df_A100[keys+['scf_'+basis, 'grad_'+basis]] + + df_A100_scf = df_A100_scf.merge(df_A100[keys+['scf_'+basis]], how='outer', on=keys) + df_A100_grad= df_A100_grad.merge(df_A100[keys+['grad_'+basis]], how='outer', on=keys) + df_A100_scf = df_A100_scf.rename(columns={'scf_'+basis:basis}) + df_A100_grad = df_A100_grad.rename(columns={'grad_'+basis:basis}) + df_A100_scf[basis] = df_A100_scf[basis].apply(lambda x: round(x,2)) + df_A100_grad[basis] = df_A100_grad[basis].apply(lambda x: round(x,2)) + + df_V100 = pd.read_csv(path + basis + '/' + V100_file) + df_V100 = df_V100.rename(columns={'t_scf':'scf_V100', 't_gradient':'grad_V100'}) + df_V100 = df_V100.merge(df_qchem, how='outer', on='mol') + df_V100['scf_'+basis] = df_V100['scf_qchem']/df_V100['scf_V100'] + df_V100['grad_'+basis] = df_V100['grad_qchem']/df_V100['grad_V100'] + + df_V100_scf = df_V100_scf.merge(df_V100[keys+['scf_'+basis,]], how='outer', on=keys) + df_V100_grad= df_V100_grad.merge(df_V100[keys+['grad_'+basis]], how='outer', on=keys) + df_V100_scf = df_V100_scf.rename(columns={'scf_'+basis:basis}) + + df_V100_grad = df_V100_grad.rename(columns={'grad_'+basis:basis}) + df_V100_scf[basis] = df_V100_scf[basis].apply(lambda x: round(x,2)) + df_V100_grad[basis] = df_V100_grad[basis].apply(lambda x: round(x,2)) + +print("\n============SCF speedup with A100-80G============\n") +print(df_A100_scf.to_markdown(index=False)) +print("\n============SCF speedup with V100-32G============\n") +print(df_V100_scf.to_markdown(index=False)) +print("\n============Gradient speedup with A100-80G=======\n") +print(df_A100_grad.to_markdown(index=False)) +print("\n============Gradient speedup with V100-32G=======\n") +print(df_V100_grad.to_markdown(index=False)) + +# ----------------------------------------- +# | Density fitting with different xc | +# ----------------------------------------- + +keys = ['mol', 'natm'] +empty = {'mol':[], 'natm':[]} +df_A100_scf = pd.DataFrame(empty) +df_V100_scf = pd.DataFrame(empty) +df_A100_grad = pd.DataFrame(empty) +df_V100_grad = pd.DataFrame(empty) +path = 'organic/xc/' +for xc in ['LDA', 'PBE', 'B3LYP', 'M06', 'wB97m-v']: + df_qchem = pd.read_csv(path + xc + '/' + qchem_file) + df_qchem = df_qchem.rename(columns={'t_scf':'scf_qchem', 't_gradient':'grad_qchem'}) + + df_A100 = pd.read_csv(path + xc + '/' + A100_file) + df_A100 = df_A100.rename(columns={'t_scf':'scf_A100', 't_gradient':'grad_A100'}) + df_A100 = df_A100.merge(df_qchem, how='outer', on='mol') + + df_A100['scf_'+xc] = df_A100['scf_qchem']/df_A100['scf_A100'] + df_A100['grad_'+xc] = df_A100['grad_qchem']/df_A100['grad_A100'] + df_A100 = df_A100[keys+['scf_'+xc, 'grad_'+xc]] + + df_A100_scf = df_A100_scf.merge(df_A100[keys+['scf_'+xc]], how='outer', on=keys) + df_A100_grad= df_A100_grad.merge(df_A100[keys+['grad_'+xc]], how='outer', on=keys) + df_A100_scf = df_A100_scf.rename(columns={'scf_'+xc:xc}) + df_A100_grad = df_A100_grad.rename(columns={'grad_'+xc:xc}) + df_A100_scf[xc] = df_A100_scf[xc].apply(lambda x: round(x,2)) + df_A100_grad[xc] = df_A100_grad[xc].apply(lambda x: round(x,2)) + + df_V100 = pd.read_csv(path + xc + '/' + V100_file) + df_V100 = df_V100.rename(columns={'t_scf':'scf_V100', 't_gradient':'grad_V100'}) + df_V100 = df_V100.merge(df_qchem, how='outer', on='mol') + df_V100['scf_'+xc] = df_V100['scf_qchem']/df_V100['scf_V100'] + df_V100['grad_'+xc] = df_V100['grad_qchem']/df_V100['grad_V100'] + + df_V100_scf = df_V100_scf.merge(df_V100[keys+['scf_'+xc,]], how='outer', on=keys) + df_V100_grad= df_V100_grad.merge(df_V100[keys+['grad_'+xc]], how='outer', on=keys) + df_V100_scf = df_V100_scf.rename(columns={'scf_'+xc:xc}) + + df_V100_grad = df_V100_grad.rename(columns={'grad_'+xc:xc}) + df_V100_scf[xc] = df_V100_scf[xc].apply(lambda x: round(x,2)) + df_V100_grad[xc] = df_V100_grad[xc].apply(lambda x: round(x,2)) + +print("\n============SCF speedup with A100-80G============\n") +print(df_A100_scf.to_markdown(index=False)) +print("\n============SCF speedup with V100-32G============\n") +print(df_V100_scf.to_markdown(index=False)) +print("\n============Gradient speedup with A100-80G=======\n") +print(df_A100_grad.to_markdown(index=False)) +print("\n============Gradient speedup with V100-32G=======\n") +print(df_V100_grad.to_markdown(index=False)) diff --git a/benchmarks/df/qchem_input.in b/benchmarks/df/qchem_input.in deleted file mode 100644 index 9f357459..00000000 --- a/benchmarks/df/qchem_input.in +++ /dev/null @@ -1,86 +0,0 @@ -$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 diff --git a/benchmarks/scf/generate_tables.ipynb b/benchmarks/scf/generate_tables.ipynb deleted file mode 100644 index c3eb0dd2..00000000 --- a/benchmarks/scf/generate_tables.ipynb +++ /dev/null @@ -1,201 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Direct SCF with different xc" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | LDA | PBE | B3LYP | M06 | wB97m-v |\n", - "|------:|-------:|-------:|-------:|--------:|-------:|----------:|\n", - "| 2 | 3 | 0.22 | 0.32 | 0.27 | 0.25 | 0.69 |\n", - "| 3 | 15 | 0.68 | 0.25 | 1.58 | 2.61 | 4.84 |\n", - "| 4 | 30 | 1.59 | 2.63 | 4.09 | 6.93 | 8.17 |\n", - "| 5 | 60 | 2.86 | 3.64 | 7.15 | 8.44 | 9.44 |\n", - "| 6 | 96 | 4.34 | 4.39 | 7.75 | 10.58 | 9.87 |\n", - "| 7 | 141 | 4.07 | 4.1 | 8.87 | 10.47 | 10.13 |\n", - "| 8 | 228 | 4.34 | 4.58 | 9.39 | 10.48 | 9.36 |\n", - "| 9 | 300 | 5.05 | 5.21 | 9.35 | 11.36 | nan |\n", - "| 10 | 417 | 4.91 | nan | nan | nan | nan |\n", - "| 10 | nan | nan | nan | nan | nan | nan |\n" - ] - } - ], - "source": [ - "A100_file = 'A100-SXM-80GB.csv'\n", - "qchem_file = 'qchem-32-cores-cpu.csv'\n", - "\n", - "keys = ['mol', 'natm']\n", - "empty = {'mol':[], 'natm':[]}\n", - "df_A100_scf = pd.DataFrame(empty)\n", - "df_V100_scf = pd.DataFrame(empty)\n", - "df_A100_grad = pd.DataFrame(empty)\n", - "df_V100_grad = pd.DataFrame(empty)\n", - "path = 'water_clusters/xc/'\n", - "for xc in ['LDA', 'PBE', 'B3LYP', 'M06', 'wB97m-v']:\n", - " df_qchem = pd.read_csv(path + xc + '/' + qchem_file)\n", - " df_qchem = df_qchem.rename(columns={'t_scf':'scf_qchem', 't_gradient':'grad_qchem'})\n", - " \n", - " df_A100 = pd.read_csv(path + xc + '/' + A100_file)\n", - " df_A100 = df_A100.rename(columns={'t_scf':'scf_A100', 't_gradient':'grad_A100'})\n", - " df_A100 = df_A100.merge(df_qchem, how='outer', on='mol')\n", - " \n", - " df_A100['scf_'+xc] = df_A100['scf_qchem']/df_A100['scf_A100']\n", - " df_A100['grad_'+xc] = df_A100['grad_qchem']/df_A100['grad_A100']\n", - " df_A100 = df_A100[keys+['scf_'+xc, 'grad_'+xc]]\n", - " \n", - " df_A100_scf = df_A100_scf.merge(df_A100[keys+['scf_'+xc]], how='outer', on=keys)\n", - " df_A100_grad= df_A100_grad.merge(df_A100[keys+['grad_'+xc]], how='outer', on=keys)\n", - " df_A100_scf = df_A100_scf.rename(columns={'scf_'+xc:xc})\n", - " df_A100_grad = df_A100_grad.rename(columns={'grad_'+xc:xc})\n", - " df_A100_scf[xc] = df_A100_scf[xc].apply(lambda x: round(x,2))\n", - " df_A100_grad[xc] = df_A100_grad[xc].apply(lambda x: round(x,2))\n", - "\n", - "print(df_A100_scf.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "''" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "| mol | natm | LDA | PBE | B3LYP | M06 | wB97m-v |\n", - "|------:|-------:|-------:|-------:|--------:|-------:|----------:|\n", - "| 2 | 3 | 0.82 | 0.89 | 0.75 | 0.82 | 0.6 |\n", - "| 3 | 15 | 0.39 | 0.19 | 1.46 | 1.52 | 1.47 |\n", - "| 4 | 30 | 0.56 | 1.04 | 2.07 | 2.25 | 1.89 |\n", - "| 5 | 60 | 0.54 | 0.87 | 2.42 | 2.4 | 1.77 |\n", - "| 6 | 96 | 0.6 | 0.87 | 2.36 | 2.51 | 1.53 |\n", - "| 7 | 141 | 0.93 | 1.1 | 2.61 | 2.59 | 1.55 |\n", - "| 8 | 228 | 1.92 | 1.9 | 3.37 | 3.39 | 1.83 |\n", - "| 9 | 300 | 2.26 | 2.02 | 3.06 | 3.59 | nan |\n", - "| 10 | 417 | 2.46 | nan | nan | nan | nan |\n", - "| 10 | nan | nan | nan | nan | nan | nan |\n" - ] - } - ], - "source": [ - "print(df_A100_grad.to_markdown(index=False))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Merlin (Python3 + MLSQL) [Spark 3.0]", - "language": "python", - "name": "merlin_kernel" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.2" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/benchmarks/scf/generate_tables.py b/benchmarks/scf/generate_tables.py new file mode 100644 index 00000000..49013b05 --- /dev/null +++ b/benchmarks/scf/generate_tables.py @@ -0,0 +1,40 @@ +import pandas as pd +import numpy as np + +# ------------------------------------------- +# | Density fitting with different xc | +# ------------------------------------------- + +A100_file = 'A100-SXM-80GB.csv' +qchem_file = 'qchem-32-cores-cpu.csv' + +keys = ['mol', 'natm'] +empty = {'mol':[], 'natm':[]} +df_A100_scf = pd.DataFrame(empty) +df_V100_scf = pd.DataFrame(empty) +df_A100_grad = pd.DataFrame(empty) +df_V100_grad = pd.DataFrame(empty) +path = 'water_clusters/xc/' +for xc in ['LDA', 'PBE', 'B3LYP', 'M06', 'wB97m-v']: + df_qchem = pd.read_csv(path + xc + '/' + qchem_file) + df_qchem = df_qchem.rename(columns={'t_scf':'scf_qchem', 't_gradient':'grad_qchem'}) + + df_A100 = pd.read_csv(path + xc + '/' + A100_file) + df_A100 = df_A100.rename(columns={'t_scf':'scf_A100', 't_gradient':'grad_A100'}) + df_A100 = df_A100.merge(df_qchem, how='outer', on='mol') + + df_A100['scf_'+xc] = df_A100['scf_qchem']/df_A100['scf_A100'] + df_A100['grad_'+xc] = df_A100['grad_qchem']/df_A100['grad_A100'] + df_A100 = df_A100[keys+['scf_'+xc, 'grad_'+xc]] + + df_A100_scf = df_A100_scf.merge(df_A100[keys+['scf_'+xc]], how='outer', on=keys) + df_A100_grad= df_A100_grad.merge(df_A100[keys+['grad_'+xc]], how='outer', on=keys) + df_A100_scf = df_A100_scf.rename(columns={'scf_'+xc:xc}) + df_A100_grad = df_A100_grad.rename(columns={'grad_'+xc:xc}) + df_A100_scf[xc] = df_A100_scf[xc].apply(lambda x: round(x,2)) + df_A100_grad[xc] = df_A100_grad[xc].apply(lambda x: round(x,2)) + +print("\n============SCF speedup with A100-80G============\n") +print(df_A100_scf.to_markdown(index=False)) +print("\n============Gradient speedup with A100-80G=======\n") +print(df_A100_grad.to_markdown(index=False)) \ No newline at end of file diff --git a/gpu4pyscf/solvent/grad/pcm.py b/gpu4pyscf/solvent/grad/pcm.py index 88001e35..e3929830 100644 --- a/gpu4pyscf/solvent/grad/pcm.py +++ b/gpu4pyscf/solvent/grad/pcm.py @@ -140,9 +140,10 @@ def get_dD_dS(surface, dF, with_S=True, with_D=False): return dD, dS, dSii -def grad_nuc(pcmobj): - if not pcmobj._intermediates: - pcmobj.build() +def grad_nuc(pcmobj, dm): + if not pcmobj._intermediates or 'q_sym' not in pcmobj._intermediates: + pcmobj._get_vind(dm) + mol = pcmobj.mol q_sym = pcmobj._intermediates['q_sym'].get() gridslice = pcmobj.surface['gslice_by_atom'] @@ -174,8 +175,8 @@ def grad_elec(pcmobj, dm): dE = 0.5*v* d(K^-1 R) *v + q*dv v^T* d(K^-1 R)v = v^T*K^-1(dR - dK K^-1R)v = v^T K^-1(dR - dK q) ''' - if not pcmobj._intermediates: - pcmobj.build() + if not pcmobj._intermediates or 'q_sym' not in pcmobj._intermediates: + pcmobj._get_vind(dm) gridslice = pcmobj.surface['gslice_by_atom'] v_grids = pcmobj._intermediates['v_grids'] @@ -288,7 +289,7 @@ def kernel(self, *args, dm=None, atmlst=None, **kwargs): dm = self.base.make_rdm1(ao_repr=True) self.de_solvent = grad_elec(self.base.with_solvent, dm) - self.de_solvent+= grad_nuc(self.base.with_solvent) + self.de_solvent+= grad_nuc(self.base.with_solvent, dm) self.de_solute = grad_method_class.kernel(self, *args, **kwargs) self.de = self.de_solute + self.de_solvent diff --git a/gpu4pyscf/solvent/hessian/pcm.py b/gpu4pyscf/solvent/hessian/pcm.py index 5d2c4dac..668dff3f 100644 --- a/gpu4pyscf/solvent/hessian/pcm.py +++ b/gpu4pyscf/solvent/hessian/pcm.py @@ -101,7 +101,7 @@ def pcm_grad_scanner(mol): pcmobj.reset(mol) e, v = pcmobj._get_vind(dm) #return grad_elec(pcmobj, dm) - return grad_nuc(pcmobj) + grad_elec(pcmobj, dm) + return grad_nuc(pcmobj, dm) + grad_elec(pcmobj, dm) de = numpy.zeros([mol.natm, mol.natm, 3, 3]) eps = 1e-3 diff --git a/gpu4pyscf/solvent/tests/test_pcm_hessian.py b/gpu4pyscf/solvent/tests/test_pcm_hessian.py index ff6074d4..8a40943b 100644 --- a/gpu4pyscf/solvent/tests/test_pcm_hessian.py +++ b/gpu4pyscf/solvent/tests/test_pcm_hessian.py @@ -28,6 +28,7 @@ def setUpModule(): H -0.7570000000 -0.0000000000 -0.4696000000 H 0.7570000000 0.0000000000 -0.4696000000 ''' + mol.atom = '/mlx_devbox/users/xiaojie.wu/playground/gpu4pyscf/benchmarks/molecules/organic/020_Vitamin_C.xyz' mol.basis = 'def2-tzvpp' mol.output = '/dev/null' mol.build(verbose=0) @@ -42,11 +43,8 @@ def tearDownModule(): mol.stdout.close() del mol -def _check_hessian(method='C-PCM', ix=0, iy=0): - pmol = mol.copy() - pmol.build() - - mf = dft.rks.RKS(pmol, xc=xc).density_fit().PCM() +def _make_mf(method='C-PCM'): + mf = dft.rks.RKS(mol, xc=xc).density_fit().PCM() mf.with_solvent.method = method mf.with_solvent.eps = epsilon mf.with_solvent.lebedev_order = lebedev_order @@ -54,6 +52,11 @@ def _check_hessian(method='C-PCM', ix=0, iy=0): mf.grids.atom_grid = (99,590) mf.verbose = 0 mf.kernel() + return mf + +def _check_hessian(mf, h, ix=0, iy=0): + pmol = mol.copy() + pmol.build() g = mf.nuc_grad_method() g.auxbasis_response = True @@ -75,25 +78,26 @@ def _check_hessian(method='C-PCM', ix=0, iy=0): pmol.set_geom_(coords, unit='Bohr') pmol.build() - hobj = mf.Hessian() - hobj.set(auxbasis_response=2) - h = hobj.kernel() - - print(f"analytical Hessian H({ix},{iy})") - print(h[ix,:,iy,:]) - print(f"finite different Hessian H({ix},{iy})") - print(h_fd) - print('Norm of diff', np.linalg.norm(h[ix,:,iy,:] - h_fd)) + print(f'Norm of H({ix},{iy}) diff, {np.linalg.norm(h[ix,:,iy,:] - h_fd)}') assert(np.linalg.norm(h[ix,:,iy,:] - h_fd) < tol) class KnownValues(unittest.TestCase): + def test_hess_cpcm(self): - _check_hessian(method='C-PCM', ix=0, iy=0) - _check_hessian(method='C-PCM', ix=0, iy=1) + mf = _make_mf(method='C-PCM') + hobj = mf.Hessian() + hobj.set(auxbasis_response=2) + h = hobj.kernel() + _check_hessian(mf, h, ix=0, iy=0) + _check_hessian(mf, h, ix=0, iy=1) def test_hess_iefpcm(self): - _check_hessian(method='IEF-PCM', ix=0, iy=0) - _check_hessian(method='IEF-PCM', ix=0, iy=1) + mf = _make_mf(method='IEF-PCM') + hobj = mf.Hessian() + hobj.set(auxbasis_response=2) + h = hobj.kernel() + _check_hessian(mf, h, ix=0, iy=0) + _check_hessian(mf, h, ix=0, iy=1) if __name__ == "__main__": print("Full Tests for Hessian of PCMs")