|
21 | 21 | "metadata": { |
22 | 22 | "tags": [] |
23 | 23 | }, |
24 | | - "outputs": [ |
25 | | - { |
26 | | - "data": { |
27 | | - "application/vnd.jupyter.widget-view+json": { |
28 | | - "model_id": "cfce2d5082774a069a379ab1dd3237eb", |
29 | | - "version_major": 2, |
30 | | - "version_minor": 0 |
31 | | - }, |
32 | | - "text/plain": [] |
33 | | - }, |
34 | | - "metadata": {}, |
35 | | - "output_type": "display_data" |
36 | | - } |
37 | | - ], |
| 24 | + "outputs": [], |
38 | 25 | "source": [ |
39 | | - "import openmm\n", |
40 | | - "from openff.interchange import Interchange\n", |
41 | | - "from openff.units.openmm import from_openmm\n", |
| 26 | + "from openff.interchange.drivers.openmm import get_openmm_energies\n", |
42 | 27 | "from rdkit.Chem import rdMolAlign\n", |
43 | 28 | "\n", |
44 | 29 | "from openff.toolkit import ForceField, Molecule\n", |
|
67 | 52 | { |
68 | 53 | "data": { |
69 | 54 | "application/vnd.jupyter.widget-view+json": { |
70 | | - "model_id": "089a1b3c120542d79f178ee6179c8cf4", |
| 55 | + "model_id": "3dd98e55d74b4334adb0f4e207bd0874", |
| 56 | + "version_major": 2, |
| 57 | + "version_minor": 0 |
| 58 | + }, |
| 59 | + "text/plain": [] |
| 60 | + }, |
| 61 | + "metadata": {}, |
| 62 | + "output_type": "display_data" |
| 63 | + }, |
| 64 | + { |
| 65 | + "name": "stderr", |
| 66 | + "output_type": "stream", |
| 67 | + "text": [ |
| 68 | + "/Users/mattthompson/.local/share/mamba/envs/openff-toolkit-test-rdkit/lib/python3.12/site-packages/nglview/__init__.py:12: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", |
| 69 | + " import pkg_resources\n" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "data": { |
| 74 | + "application/vnd.jupyter.widget-view+json": { |
| 75 | + "model_id": "f792d6accb2846c1b4dcee7c9d80a849", |
71 | 76 | "version_major": 2, |
72 | 77 | "version_minor": 0 |
73 | 78 | }, |
|
129 | 134 | }, |
130 | 135 | "outputs": [], |
131 | 136 | "source": [ |
132 | | - "# Load the openff-2.1.0 force field appropriate for vacuum calculations (without constraints)\n", |
133 | | - "forcefield = ForceField(\"openff_unconstrained-2.2.0.offxml\")" |
| 137 | + "# Load the openff-2.2.1 force field appropriate for vacuum calculations (without constraints)\n", |
| 138 | + "forcefield = ForceField(\"openff_unconstrained-2.2.1.offxml\")" |
134 | 139 | ] |
135 | 140 | }, |
136 | 141 | { |
137 | 142 | "cell_type": "markdown", |
138 | 143 | "metadata": {}, |
139 | 144 | "source": [ |
140 | | - "We'll now apply the Sage force field to the molecule to produce an [`Interchange`], and then an OpenMM [`Simulation`] object. Interchange can produce inputs for a whole host of other MD engines though!\n", |
| 145 | + "We'll now apply the Sage force field to the molecule to produce an [`Interchange`], which stores the result of parametrizing with this force field\n", |
141 | 146 | "\n", |
142 | | - "[`Interchange`]: https://docs.openforcefield.org/projects/interchange/en/stable/_autosummary/openff.interchange.Interchange.html#openff.interchange.Interchange\n", |
143 | | - "[`Simulation`]: http://docs.openmm.org/latest/api-python/generated/openmm.app.simulation.Simulation.html#openmm.app.simulation.Simulation" |
| 147 | + "[`Interchange`]: https://docs.openforcefield.org/projects/interchange/en/stable/_autosummary/openff.interchange.Interchange.html#openff.interchange.Interchange" |
144 | 148 | ] |
145 | 149 | }, |
146 | 150 | { |
|
161 | 165 | ], |
162 | 166 | "source": [ |
163 | 167 | "print(f\"Parametrizing {molecule.name} (may take a moment to calculate charges)...\")\n", |
164 | | - "interchange = Interchange.from_smirnoff(forcefield, [molecule])\n", |
165 | | - "print(\"Done.\")\n", |
166 | | - "\n", |
167 | | - "integrator = openmm.VerletIntegrator(1 * openmm.unit.femtoseconds)\n", |
168 | | - "simulation = interchange.to_openmm_simulation(integrator)" |
| 168 | + "interchange = forcefield.create_interchange(molecule.to_topology())\n", |
| 169 | + "print(\"Done.\")" |
169 | 170 | ] |
170 | 171 | }, |
171 | 172 | { |
|
191 | 192 | "minimized_molecule = Molecule(molecule)\n", |
192 | 193 | "minimized_molecule.conformers.clear()\n", |
193 | 194 | "\n", |
| 195 | + "\n", |
194 | 196 | "for conformer in molecule.conformers:\n", |
195 | | - " # Tell the OpenMM Simulation the positions of this conformer\n", |
196 | | - " simulation.context.setPositions(conformer.to_openmm())\n", |
| 197 | + " # Use this conformer to update the positions of the Interchange object\n", |
| 198 | + " interchange.positions = conformer\n", |
197 | 199 | "\n", |
198 | | - " # Keep a record of the initial energy\n", |
199 | | - " initial_energies.append(simulation.context.getState(getEnergy=True).getPotentialEnergy())\n", |
| 200 | + " # Get the (total) initial energy from this conformer and store it\n", |
| 201 | + " initial_energies.append(get_openmm_energies(interchange).total_energy)\n", |
200 | 202 | "\n", |
201 | | - " # Perform the minimization\n", |
202 | | - " simulation.minimizeEnergy()\n", |
| 203 | + " # Minimize using Interchange.minimize, which wraps OpenMM\n", |
| 204 | + " interchange.minimize(engine=\"openmm\")\n", |
203 | 205 | "\n", |
204 | 206 | " # Record minimized energy and positions\n", |
205 | | - " min_state = simulation.context.getState(getEnergy=True, getPositions=True)\n", |
206 | | - "\n", |
207 | | - " minimized_energies.append(min_state.getPotentialEnergy())\n", |
208 | | - " minimized_molecule.add_conformer(from_openmm(min_state.getPositions()))" |
| 207 | + " minimized_energies.append(get_openmm_energies(interchange).total_energy)\n", |
| 208 | + " minimized_molecule.add_conformer(interchange.positions.to(\"angstrom\"))" |
209 | 209 | ] |
210 | 210 | }, |
211 | 211 | { |
|
225 | 225 | { |
226 | 226 | "data": { |
227 | 227 | "application/vnd.jupyter.widget-view+json": { |
228 | | - "model_id": "a4750d0da648475bb17cf557ef89b691", |
| 228 | + "model_id": "c7b7dec6bc7b4c498bab35c31cedb4c3", |
229 | 229 | "version_major": 2, |
230 | 230 | "version_minor": 0 |
231 | 231 | }, |
|
261 | 261 | "text": [ |
262 | 262 | "ruxolitinib: 10 conformers\n", |
263 | 263 | "Conformer Initial PE Minimized PE RMSD\n", |
264 | | - " 1 / 10 : -88.682 kcal/mol -124.600 kcal/mol 0.456 Å\n", |
265 | | - " 2 / 10 : -83.492 kcal/mol -121.554 kcal/mol 0.466 Å\n", |
266 | | - " 3 / 10 : -43.748 kcal/mol -121.709 kcal/mol 0.951 Å\n", |
267 | | - " 4 / 10 : -81.885 kcal/mol -123.365 kcal/mol 0.695 Å\n", |
268 | | - " 5 / 10 : -83.609 kcal/mol -120.864 kcal/mol 0.674 Å\n", |
269 | | - " 6 / 10 : -85.390 kcal/mol -123.760 kcal/mol 0.604 Å\n", |
270 | | - " 7 / 10 : -82.167 kcal/mol -121.679 kcal/mol 0.973 Å\n", |
271 | | - " 8 / 10 : -91.164 kcal/mol -123.829 kcal/mol 0.413 Å\n", |
272 | | - " 9 / 10 : -89.107 kcal/mol -124.535 kcal/mol 0.808 Å\n", |
273 | | - " 10 / 10 : -86.407 kcal/mol -124.416 kcal/mol 0.610 Å\n" |
| 264 | + " 1 / 10 : -88.258 kcal/mol -123.916 kcal/mol 0.452 Å\n", |
| 265 | + " 2 / 10 : -82.884 kcal/mol -120.706 kcal/mol 0.433 Å\n", |
| 266 | + " 3 / 10 : -43.067 kcal/mol -120.913 kcal/mol 0.949 Å\n", |
| 267 | + " 4 / 10 : -81.524 kcal/mol -122.732 kcal/mol 0.693 Å\n", |
| 268 | + " 5 / 10 : -82.897 kcal/mol -120.303 kcal/mol 0.789 Å\n", |
| 269 | + " 6 / 10 : -84.764 kcal/mol -122.897 kcal/mol 0.588 Å\n", |
| 270 | + " 7 / 10 : -81.634 kcal/mol -120.972 kcal/mol 1.004 Å\n", |
| 271 | + " 8 / 10 : -90.702 kcal/mol -123.087 kcal/mol 0.374 Å\n", |
| 272 | + " 9 / 10 : -88.588 kcal/mol -123.813 kcal/mol 0.757 Å\n", |
| 273 | + " 10 / 10 : -85.671 kcal/mol -123.590 kcal/mol 0.634 Å\n" |
274 | 274 | ] |
275 | 275 | } |
276 | 276 | ], |
|
322 | 322 | " output.append(\n", |
323 | 323 | " [\n", |
324 | 324 | " i + 1,\n", |
325 | | - " init_energy.value_in_unit(openmm.unit.kilocalories_per_mole),\n", |
326 | | - " min_energy.value_in_unit(openmm.unit.kilocalories_per_mole),\n", |
| 325 | + " init_energy.m_as(\"kilocalories_per_mole\"),\n", |
| 326 | + " min_energy.m_as(\"kilocalories_per_mole\"),\n", |
327 | 327 | " minimization_rms,\n", |
328 | 328 | " ]\n", |
329 | 329 | " )\n", |
|
361 | 361 | "name": "python", |
362 | 362 | "nbconvert_exporter": "python", |
363 | 363 | "pygments_lexer": "ipython3", |
364 | | - "version": "3.10.10" |
| 364 | + "version": "3.12.11" |
365 | 365 | }, |
366 | 366 | "widgets": { |
367 | 367 | "application/vnd.jupyter.widget-state+json": { |
|
0 commit comments