Skip to content

Commit

Permalink
Final edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Nov 9, 2023
1 parent b9b4348 commit d253c91
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions examples/virtual_sites/vsite_showcase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f531ab0129bd48dd9ac2c99b6f99905c",
"model_id": "ba621889dffa475e80a6a6b5f8f476e5",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -314,7 +314,7 @@
"output_type": "stream",
"text": [
"Starting simulation\n",
"Elapsed time 0.89 seconds\n",
"Elapsed time 0.96 seconds\n",
"Done!\n"
]
}
Expand All @@ -335,7 +335,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5b1b2dbed8b04107b9d8ded035dce21b",
"model_id": "c05515b6f75647ed89ebf066d9f99c48",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -377,21 +377,16 @@
"source": [
"Parameterizes a water box with OpenFF/SMIRNOFF and OpenMM implementations of TIP5P.\n",
"\n",
"The code examines the geometry and energy between the two, and examines cases where minimization is performed.\n",
"Specifically, the code compares the four possible combinations:\n",
" - SMIRONFF and OpenMM geometry/energy, minimized separately and then compared\n",
" - SMIRNOFF and OpenMM geometry/energy using no minimization\n",
" - Geometry minimized using OpenFF, then a single point energy calculation is done with OpenMM\n",
" - Geometry minimized using OpenFF, then a single point energy calculation is done with OpenFF\n",
"This code examines the geometry and energy between the two, and examines cases where minimization is performed.\n",
"\n",
"The virtual site definitions give rise to small differences in geometry in due to to how they are defined from their parent atoms.\n",
"OpenMM's force field results in `openmm.OutOfPlaneSite`s being createdwhereas OpenFF's force field results in `openmm.LocalCoordinatesSite`s.\n",
"The virtual site definitions give rise to small differences in geometry in due to to how they are defined relative to their parent atoms.\n",
"OpenMM's force field produces `openmm.OutOfPlaneSite`s whereas OpenFF's force field produces in `openmm.LocalCoordinatesSite`s.\n",
"(In each case, these objects are OpenMM objects to be used in OpenMM simulations; implementations in other engines are not covered here.)\n",
"`OutOfPlaneSite` virtual sites' positions are are determined based on the positions of the orientation atoms.\n",
"(In water models, the \"parent\" atom is oxygen and the \"orientation\" atoms are the oxygen and hydrogens; in other chemistries virtual sites may be definited differently.)\n",
"`LocalCoordinatesSite` virtual sites' positions relative to orientation atoms are fixed to a constant value in order to adhere to the SMIRNOFF specification.\n",
"A consequence of this difference is that tiny fluctuations in the molecular geometry cause slightly different energy evaluations.\n",
"This can arise from marginally different initial positions or dynamics over the course of a simulation, but the description at equilibrium should match.\n",
"A consequence of this difference is that tiny fluctuations in the molecular geometry cause slightly different coordinates and, therefore, energy evaluations.\n",
"This can arise from marginally different initial positions or from the dynamics of a simulation, but the descriptions at equilibrium should match.\n",
"Further nuance is described in the [OpenMM User Guide](http://docs.openmm.org/8.0.0/userguide/theory/05_other_features.html#virtual-sites) and API docs.\n",
"\n",
"This example uses water molecules, but both OpenFF and OpenMM infrastructure support a variety of other virtual site definitions for use in other chemistries.\n",
Expand Down Expand Up @@ -690,8 +685,10 @@
"\n",
" print(\n",
" f\"Results for: {name}\\n\"\n",
" f\"Energy difference ({_energy_difference.units}):\\n\\t{_energy_difference.m}\\n\"\n",
" f\"Coordinates difference ({coordinate_difference.units}), norm):\\n\\t{coordinate_difference.m}\\n\"\n",
" f\"Energy difference ({_energy_difference.units}):\\n\\t\"\n",
" f\"{_energy_difference.m:0.3e}\\n\"\n",
" f\"Coordinates difference ({coordinate_difference.units}), norm):\\n\\t\"\n",
" f\"{coordinate_difference.m:0.3e}\\n\"\n",
" )"
]
},
Expand All @@ -705,10 +702,10 @@
},
"outputs": [],
"source": [
"# The TIP5P force field in SMIRNOFF format\n",
"# The TIP5P force field in SMIRNOFF format, provided by the OpenFF Toolkit\n",
"openff_force_field = ForceField(\"tip5p.offxml\")\n",
"\n",
"# The OpenMM definition of tip5p\n",
"# The OpenMM definition of TIP5P\n",
"openmm_force_field = openmm.app.ForceField(\"tip5p.xml\")"
]
},
Expand All @@ -728,9 +725,9 @@
"text": [
"Results for: OpenFF - OpenMM comparison (per molecule)\n",
"Energy difference (kilojoule / mole):\n",
"\t1.9073486328125e-06\n",
"\t1.907e-06\n",
"Coordinates difference (angstrom), norm):\n",
"\t1.6239076780209112e-07\n",
"\t1.624e-07\n",
"\n"
]
}
Expand All @@ -741,8 +738,6 @@
"num_duplicates = (2, 1, 1) # 2x2x2 = 8 water molecules\n",
"spacing = (3.0, 3.0, 3.0) # water spaced 3A apart in each direction\n",
"\n",
"numpy.set_printoptions(formatter={\"float_kind\": \"{:13.10f}\".format})\n",
"\n",
"waters = build_water_lattice(num_duplicates, spacing)\n",
"\n",
"off_crds, off_ene = evaluate_openff(waters, openff_force_field, minimize=minimize)\n",
Expand All @@ -752,10 +747,10 @@
"omm_crds = numpy.array(omm_crds.value_in_unit(openmm.unit.angstrom))\n",
"\n",
"coordinate_difference = Quantity(\n",
" numpy.linalg.norm(off_crds - omm_crds[reorder(numpy.prod(num_duplicates)), :])\n",
" / numpy.prod(num_duplicates),\n",
" numpy.linalg.norm(off_crds - omm_crds[reorder(numpy.prod(num_duplicates)), :]),\n",
" unit.angstrom,\n",
")\n",
"coordinate_difference /= numpy.prod(num_duplicates)\n",
"energy_difference = abs(off_ene - omm_ene) / numpy.prod(num_duplicates)\n",
"\n",
"print_info(\n",
Expand All @@ -771,6 +766,13 @@
" energy_difference < 1e-4 * openmm.unit.kilojoule_per_mole\n",
"), f\"Energies differ by {energy_difference}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -790,7 +792,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.9.18"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down

0 comments on commit d253c91

Please sign in to comment.