{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/gaoxiang/pytorch-dev/pytorchdev/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n",
"WARNING:root:Unable to import NeuroChemAEV, please check your pyNeuroChem installation.\n"
]
}
],
"source": [
"import h5py\n",
"import torch\n",
"from selected_system import mols, mol_file\n",
"from ani_benchmark import ANIBenchmark\n",
"import pandas\n",
"import os\n",
"import tqdm\n",
"from IPython.display import display\n",
"import itertools\n",
"tqdm.monitor_interval = 0"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"torch.set_num_threads(1)\n",
"fm = h5py.File(os.path.join('../',mol_file), \"r\")\n",
"\n",
"benchmarks = {\n",
" 'C': ANIBenchmark(device=torch.device(\"cpu\")),\n",
"}\n",
"\n",
"if torch.cuda.is_available():\n",
" benchmarks.update({\n",
" 'G': ANIBenchmark(device=torch.device(\"cuda\")),\n",
" })"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of atoms: 20\n",
"Running benchmark on molecule COC(=O)c1ccc([N+](=O)[O-])cc1\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9ff5dae10b0e4a85b250095cc1c40f64",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=4), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" C,1 | \n",
" C,B | \n",
" G,1 | \n",
" G,B | \n",
"
\n",
" \n",
" \n",
" \n",
" | aev | \n",
" 0.700781 | \n",
" 0.537888 | \n",
" 1.095591 | \n",
" 0.022238 | \n",
"
\n",
" \n",
" | energy | \n",
" 0.422604 | \n",
" 0.183495 | \n",
" 0.564654 | \n",
" 0.002251 | \n",
"
\n",
" \n",
" | force | \n",
" 1.253797 | \n",
" 0.561175 | \n",
" 1.283622 | \n",
" 0.010574 | \n",
"
\n",
" \n",
" | forward | \n",
" 1.123385 | \n",
" 0.721383 | \n",
" 1.660245 | \n",
" 0.024489 | \n",
"
\n",
" \n",
" | total | \n",
" 2.377182 | \n",
" 1.282558 | \n",
" 2.943866 | \n",
" 0.035064 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" C,1 C,B G,1 G,B\n",
"aev 0.700781 0.537888 1.095591 0.022238\n",
"energy 0.422604 0.183495 0.564654 0.002251\n",
"force 1.253797 0.561175 1.283622 0.010574\n",
"forward 1.123385 0.721383 1.660245 0.024489\n",
"total 2.377182 1.282558 2.943866 0.035064"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of atoms: 50\n",
"Running benchmark on molecule O=[N+]([O-])c1ccc(NN=Cc2ccc(C=NNc3ccc([N+](=O)[O-])cc3[N+](=O)[O-])cc2)c([N+](=O)[O-])c1\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dbb459e25032453e9d6d5a8dc84a08de",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=4), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" C,1 | \n",
" C,B | \n",
" G,1 | \n",
" G,B | \n",
"
\n",
" \n",
" \n",
" \n",
" | aev | \n",
" 1.680758 | \n",
" 2.910254 | \n",
" 1.120638 | \n",
" 0.033106 | \n",
"
\n",
" \n",
" | energy | \n",
" 0.546913 | \n",
" 0.406957 | \n",
" 0.474391 | \n",
" 0.002537 | \n",
"
\n",
" \n",
" | force | \n",
" 3.637797 | \n",
" 2.189924 | \n",
" 1.495740 | \n",
" 0.036373 | \n",
"
\n",
" \n",
" | forward | \n",
" 2.227671 | \n",
" 3.317210 | \n",
" 1.595029 | \n",
" 0.035643 | \n",
"
\n",
" \n",
" | total | \n",
" 5.865469 | \n",
" 5.507135 | \n",
" 3.090769 | \n",
" 0.072016 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" C,1 C,B G,1 G,B\n",
"aev 1.680758 2.910254 1.120638 0.033106\n",
"energy 0.546913 0.406957 0.474391 0.002537\n",
"force 3.637797 2.189924 1.495740 0.036373\n",
"forward 2.227671 3.317210 1.595029 0.035643\n",
"total 5.865469 5.507135 3.090769 0.072016"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of atoms: 10\n",
"Running benchmark on molecule N#CCC(=O)N\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4e04277c06f5497384bed8e910669212",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=4), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" C,1 | \n",
" C,B | \n",
" G,1 | \n",
" G,B | \n",
"
\n",
" \n",
" \n",
" \n",
" | aev | \n",
" 0.420929 | \n",
" 0.149769 | \n",
" 1.081606 | \n",
" 0.006245 | \n",
"
\n",
" \n",
" | energy | \n",
" 0.288124 | \n",
" 0.093577 | \n",
" 0.446744 | \n",
" 0.002521 | \n",
"
\n",
" \n",
" | force | \n",
" 0.755610 | \n",
" 0.216397 | \n",
" 1.218433 | \n",
" 0.007300 | \n",
"
\n",
" \n",
" | forward | \n",
" 0.709054 | \n",
" 0.243346 | \n",
" 1.528349 | \n",
" 0.008766 | \n",
"
\n",
" \n",
" | total | \n",
" 1.464663 | \n",
" 0.459743 | \n",
" 2.746782 | \n",
" 0.016067 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" C,1 C,B G,1 G,B\n",
"aev 0.420929 0.149769 1.081606 0.006245\n",
"energy 0.288124 0.093577 0.446744 0.002521\n",
"force 0.755610 0.216397 1.218433 0.007300\n",
"forward 0.709054 0.243346 1.528349 0.008766\n",
"total 1.464663 0.459743 2.746782 0.016067"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of atoms: 4,5,6\n",
"Running benchmark on molecule C\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "65906ab1bdf1470aaf7515189c163f09",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=4), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" C,1 | \n",
" C,B | \n",
" G,1 | \n",
" G,B | \n",
"
\n",
" \n",
" \n",
" \n",
" | aev | \n",
" 0.207580 | \n",
" 0.017271 | \n",
" 0.775032 | \n",
" 0.004428 | \n",
"
\n",
" \n",
" | energy | \n",
" 0.149350 | \n",
" 0.048953 | \n",
" 0.219576 | \n",
" 0.001350 | \n",
"
\n",
" \n",
" | force | \n",
" 0.390866 | \n",
" 0.121347 | \n",
" 0.768956 | \n",
" 0.005004 | \n",
"
\n",
" \n",
" | forward | \n",
" 0.356931 | \n",
" 0.066225 | \n",
" 0.994608 | \n",
" 0.005778 | \n",
"
\n",
" \n",
" | total | \n",
" 0.747796 | \n",
" 0.187572 | \n",
" 1.763565 | \n",
" 0.010781 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" C,1 C,B G,1 G,B\n",
"aev 0.207580 0.017271 0.775032 0.004428\n",
"energy 0.149350 0.048953 0.219576 0.001350\n",
"force 0.390866 0.121347 0.768956 0.005004\n",
"forward 0.356931 0.066225 0.994608 0.005778\n",
"total 0.747796 0.187572 1.763565 0.010781"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of atoms: 100\n",
"Running benchmark on molecule CC(C)C[C@@H](C(=O)O)NC(=O)C[C@@H]([C@H](CC1CCCCC1)NC(=O)CC[C@@H]([C@H](Cc2ccccc2)NC(=O)OC(C)(C)C)O)O\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bb3a02673cc14b468839c8b3a0e84edc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=4), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" C,1 | \n",
" C,B | \n",
" G,1 | \n",
" G,B | \n",
"
\n",
" \n",
" \n",
" \n",
" | aev | \n",
" 6.933071 | \n",
" 11.386394 | \n",
" 1.226802 | \n",
" 0.118203 | \n",
"
\n",
" \n",
" | energy | \n",
" 1.004400 | \n",
" 0.848959 | \n",
" 0.517654 | \n",
" 0.001794 | \n",
"
\n",
" \n",
" | force | \n",
" 8.206886 | \n",
" 6.606211 | \n",
" 1.827498 | \n",
" 0.108411 | \n",
"
\n",
" \n",
" | forward | \n",
" 7.937472 | \n",
" 12.235354 | \n",
" 1.744456 | \n",
" 0.119997 | \n",
"
\n",
" \n",
" | total | \n",
" 16.144357 | \n",
" 18.841565 | \n",
" 3.571954 | \n",
" 0.228409 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" C,1 C,B G,1 G,B\n",
"aev 6.933071 11.386394 1.226802 0.118203\n",
"energy 1.004400 0.848959 0.517654 0.001794\n",
"force 8.206886 6.606211 1.827498 0.108411\n",
"forward 7.937472 12.235354 1.744456 0.119997\n",
"total 16.144357 18.841565 3.571954 0.228409"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of atoms: 305\n",
"Running benchmark on molecule [H]/N=C(/N)\\NCCC[C@H](C(=O)N[C@H]([C@@H](C)O)C(=O)N[C@H](Cc1ccc(cc1)O)C(=O)NCCCC[C@@H](C(=O)NCCCC[C@@H](C(=O)NCC(=O)O)NC(=O)[C@H](CCCCNC(=O)[C@@H](Cc2ccc(cc2)O)NC(=O)[C@@H]([C@@H](C)O)NC(=O)[C@@H](CCCN/C(=N\\[H])/N)N)NC(=O)[C@@H](Cc3ccc(cc3)O)NC(=O)[C@@H]([C@@H](C)O)NC(=O)[C@@H](CCCN/C(=N\\[H])/N)N)NC(=O)[C@@H](Cc4ccc(cc4)O)NC(=O)[C@@H]([C@@H](C)O)NC(=O)[C@@H](CCCN/C(=N\\[H])/N)N)N\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0a01e82e74094812b0a041a95e42ae38",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, max=4), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cuda runtime error (2) : out of memory at /home/gaoxiang/pytorch/aten/src/THC/generic/THCStorage.cu:58\n",
"\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" C,1 | \n",
" C,B | \n",
" G,1 | \n",
" G,B | \n",
"
\n",
" \n",
" \n",
" \n",
" | aev | \n",
" 22.462832 | \n",
" 38.629616 | \n",
" 1.459434 | \n",
" NaN | \n",
"
\n",
" \n",
" | energy | \n",
" 2.698251 | \n",
" 2.419860 | \n",
" 0.525845 | \n",
" NaN | \n",
"
\n",
" \n",
" | force | \n",
" 21.112948 | \n",
" 20.788418 | \n",
" 3.065523 | \n",
" NaN | \n",
"
\n",
" \n",
" | forward | \n",
" 25.161083 | \n",
" 41.049476 | \n",
" 1.985280 | \n",
" NaN | \n",
"
\n",
" \n",
" | total | \n",
" 46.274031 | \n",
" 61.837895 | \n",
" 5.050802 | \n",
" NaN | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" C,1 C,B G,1 G,B\n",
"aev 22.462832 38.629616 1.459434 NaN\n",
"energy 2.698251 2.419860 0.525845 NaN\n",
"force 21.112948 20.788418 3.065523 NaN\n",
"forward 25.161083 41.049476 1.985280 NaN\n",
"total 46.274031 61.837895 5.050802 NaN"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"for i in mols:\n",
" print('number of atoms:', i)\n",
" smiles = mols[i]\n",
" for s in smiles:\n",
" print('Running benchmark on molecule', s)\n",
" key = s.replace('/', '_')\n",
" coordinates = torch.from_numpy(fm[key][()])\n",
" coordinates = coordinates[:200]\n",
" species = fm[key].attrs['species'].split()\n",
" results = {}\n",
" for b,m in tqdm.tqdm_notebook(list(itertools.product(benchmarks, ['1','B']))):\n",
" bench = benchmarks[b]\n",
" coordinates = coordinates.type(bench.aev_computer.dtype)\n",
" try:\n",
" if m == '1':\n",
" result = bench.oneByOne(coordinates, species)\n",
" elif m == 'B':\n",
" result = bench.inBatch(coordinates, species)\n",
" else:\n",
" raise ValueError('BUG here')\n",
" result['forward'] = result['aev'] + result['energy']\n",
" result['total'] = result['forward'] + result['force']\n",
" except RuntimeError as e:\n",
" print(e)\n",
" result = {'aev': None, 'energy': None, 'force': None, 'total': None }\n",
" results[b + ',' + m] = result\n",
" df = pandas.DataFrame(results)\n",
" display(df)\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}