Created
November 19, 2020 16:01
-
-
Save jthorton/5976cb9599b80d3585d7326a87483cf0 to your computer and use it in GitHub Desktop.
Running QCEngine from OFFTK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "4f22109bec46497e915c15b59d07ca97", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"from openforcefield.topology import Molecule\n", | |
"import qcengine\n", | |
"from qcelemental.models import AtomicInput, OptimizationInput\n", | |
"from qcelemental.models.common_models import Model\n", | |
"from qcelemental.models.procedures import QCInputSpecification\n", | |
"from qcfractal.interface import FractalClient" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "5899acad2f72462791f8542c620bab66", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"NGLWidget()" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# make a off toolkit molecule\n", | |
"molecule = Molecule.from_smiles(\"CCO\")\n", | |
"molecule.generate_conformers()\n", | |
"molecule" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'schema_name': 'qcschema_molecule',\n", | |
" 'schema_version': 2,\n", | |
" 'validated': True,\n", | |
" 'symbols': array(['C', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'], dtype='<U1'),\n", | |
" 'geometry': array([[ 2.00615820e+00, -5.06711540e-01, -1.09933000e-03],\n", | |
" [ 3.60951268e+00, 1.72458306e+00, -7.97534580e-01],\n", | |
" [ 2.86671423e+00, 2.50130220e+00, -3.25568170e+00],\n", | |
" [ 2.53095194e+00, -1.15425288e+00, 1.88985926e+00],\n", | |
" [-8.14200000e-05, -3.21260000e-04, -1.06395000e-03],\n", | |
" [ 2.23006866e+00, -2.07682879e+00, -1.33038667e+00],\n", | |
" [ 5.60946348e+00, 1.20201873e+00, -8.40105250e-01],\n", | |
" [ 3.35055854e+00, 3.30692363e+00, 5.07723010e-01],\n", | |
" [ 3.92823645e+00, 3.92941102e+00, -3.70622143e+00]]),\n", | |
" 'name': 'C2H6O',\n", | |
" 'molecular_charge': 0.0,\n", | |
" 'molecular_multiplicity': 1,\n", | |
" 'connectivity': [(0, 1, 1.0),\n", | |
" (0, 3, 1.0),\n", | |
" (0, 4, 1.0),\n", | |
" (0, 5, 1.0),\n", | |
" (1, 2, 1.0),\n", | |
" (1, 6, 1.0),\n", | |
" (1, 7, 1.0),\n", | |
" (2, 8, 1.0)],\n", | |
" 'fix_com': False,\n", | |
" 'fix_orientation': False,\n", | |
" 'provenance': {'creator': 'QCElemental',\n", | |
" 'version': 'v0.17.0',\n", | |
" 'routine': 'qcelemental.molparse.from_schema'},\n", | |
" 'extras': None}" | |
] | |
}, | |
"execution_count": 23, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# generate the qcelemental molecule\n", | |
"qcel_mol = molecule.to_qcschema()\n", | |
"qcel_mol.dict()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"AtomicInput(driver='energy', model={'method': 'openff-1.0.0', 'basis': 'smirnoff'}, molecule_hash='c6f0b48')" | |
] | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# generate the qcengine input to compute the energy using a range of programs and methods\n", | |
"# openff-1.0.0 program=\"openmm\"\n", | |
"openff_model = Model(method=\"openff-1.0.0\", basis=\"smirnoff\")\n", | |
"# gaff-2.11 program=\"openmm\"\n", | |
"gaff_model = Model(method=\"gaff-2.11\", basis=\"antechamber\")\n", | |
"# DFT with D3 program=\"psi4\"\n", | |
"psi4_model = Model(method=\"B3LYP-D3BJ\", basis=\"DZVP\")\n", | |
"# torchani ani2x program=\"torchani\"\n", | |
"ani_model = Model(method=\"ani2x\", basis=None)\n", | |
"# gfn method program=\"xtb\"\n", | |
"xtb_model = Model(method=\"gfn2-xtb\", basis=None)\n", | |
"\n", | |
"qc_task = AtomicInput(molecule=qcel_mol, driver=\"energy\", model=openff_model)\n", | |
"qc_task" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# compute the energy\n", | |
"result = qcengine.compute(input_data=qc_task, program=\"openmm\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'id': None,\n", | |
" 'schema_name': 'qcschema_output',\n", | |
" 'schema_version': 1,\n", | |
" 'molecule': {'schema_name': 'qcschema_molecule',\n", | |
" 'schema_version': 2,\n", | |
" 'validated': True,\n", | |
" 'symbols': array(['C', 'C', 'O', 'H', 'H', 'H', 'H', 'H', 'H'], dtype='<U1'),\n", | |
" 'geometry': array([[ 2.00615820e+00, -5.06711540e-01, -1.09933000e-03],\n", | |
" [ 3.60951268e+00, 1.72458306e+00, -7.97534580e-01],\n", | |
" [ 2.86671423e+00, 2.50130220e+00, -3.25568170e+00],\n", | |
" [ 2.53095194e+00, -1.15425288e+00, 1.88985926e+00],\n", | |
" [-8.14200000e-05, -3.21260000e-04, -1.06395000e-03],\n", | |
" [ 2.23006866e+00, -2.07682879e+00, -1.33038667e+00],\n", | |
" [ 5.60946348e+00, 1.20201873e+00, -8.40105250e-01],\n", | |
" [ 3.35055854e+00, 3.30692363e+00, 5.07723010e-01],\n", | |
" [ 3.92823645e+00, 3.92941102e+00, -3.70622143e+00]]),\n", | |
" 'name': 'C2H6O',\n", | |
" 'molecular_charge': 0.0,\n", | |
" 'molecular_multiplicity': 1,\n", | |
" 'connectivity': [(0, 1, 1.0),\n", | |
" (0, 3, 1.0),\n", | |
" (0, 4, 1.0),\n", | |
" (0, 5, 1.0),\n", | |
" (1, 2, 1.0),\n", | |
" (1, 6, 1.0),\n", | |
" (1, 7, 1.0),\n", | |
" (2, 8, 1.0)],\n", | |
" 'fix_com': False,\n", | |
" 'fix_orientation': False,\n", | |
" 'provenance': {'creator': 'QCElemental',\n", | |
" 'version': 'v0.17.0',\n", | |
" 'routine': 'qcelemental.molparse.from_schema'},\n", | |
" 'extras': None},\n", | |
" 'driver': <DriverEnum.energy: 'energy'>,\n", | |
" 'model': {'method': 'openff-1.0.0', 'basis': 'smirnoff'},\n", | |
" 'keywords': {},\n", | |
" 'protocols': {},\n", | |
" 'extras': {},\n", | |
" 'provenance': {'creator': 'openmm',\n", | |
" 'version': '7.4.2',\n", | |
" 'routine': None,\n", | |
" 'nthreads': 5,\n", | |
" 'cpu': 'Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz',\n", | |
" 'qcengine_version': 'v0.17.0',\n", | |
" 'hostname': 'Joshuas-iMac',\n", | |
" 'wall_time': 0.2566111087799072,\n", | |
" 'username': 'joshua'},\n", | |
" 'properties': {'return_energy': -0.0070563665201323015},\n", | |
" 'wavefunction': None,\n", | |
" 'return_result': -0.0070563665201323015,\n", | |
" 'stdout': None,\n", | |
" 'stderr': None,\n", | |
" 'success': True,\n", | |
" 'error': None}" | |
] | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"result.dict()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"OptimizationInput(model={'method': 'openff-1.0.0', 'basis': 'smirnoff'}, molecule_hash='c6f0b48')" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# now perform an optimization using geometric\n", | |
"# make sure to change the model and program here\n", | |
"geometric_input = OptimizationInput(initial_molecule=qcel_mol, input_specification=QCInputSpecification(model=openff_model), keywords={\"coordsys\": \"tric\", \"maxiter\": 300, \"program\": \"openmm\"})\n", | |
"geometric_input" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"opt_result = qcengine.compute_procedure(input_data=geometric_input, procedure=\"geometric\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "21e57dbfebd248af9c9525c8ba46e691", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"NGLWidget()" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"initial_mol = opt_result.initial_molecule\n", | |
"initial_mol" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "61da33603f4f48419bc9839d2c314fb5", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"NGLWidget()" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"final_mol = opt_result.final_molecule\n", | |
"final_mol" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2.873823736800184" | |
] | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# measure a bond on the molecule in Bohr\n", | |
"final_mol.measure((0,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2.8607219871857166" | |
] | |
}, | |
"execution_count": 32, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"initial_mol.measure((0,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[AtomicResult(driver='gradient', model={'method': 'openff-1.0.0', 'basis': 'smirnoff'}, molecule_hash='c6f0b48'),\n", | |
" AtomicResult(driver='gradient', model={'method': 'openff-1.0.0', 'basis': 'smirnoff'}, molecule_hash='385d605'),\n", | |
" AtomicResult(driver='gradient', model={'method': 'openff-1.0.0', 'basis': 'smirnoff'}, molecule_hash='eb2dd28'),\n", | |
" AtomicResult(driver='gradient', model={'method': 'openff-1.0.0', 'basis': 'smirnoff'}, molecule_hash='73b4c38')]" | |
] | |
}, | |
"execution_count": 33, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"opt_result.trajectory" | |
] | |
}, | |
{ | |
"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.7.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment