Skip to content

Commit a93695d

Browse files
IAlibayatravitz
andauthored
Update cookbooks for v1.7 (#237)
* Update cookbooks for v1.7 * not sure why it didn't delete the first time * review comments * bump version * rerun choose_protocol * rerun create_alchemical_network --------- Co-authored-by: Alyssa Travitz <alyssa.travitz@omsf.io> Co-authored-by: Alyssa Travitz <31974495+atravitz@users.noreply.github.com>
1 parent ccbc655 commit a93695d

3 files changed

Lines changed: 209 additions & 112 deletions

File tree

cookbook/bespoke_parameters_showcase.ipynb

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,31 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 2,
52+
"execution_count": null,
5353
"metadata": {},
5454
"outputs": [],
5555
"source": [
5656
"# create the OpenFE RBFE protocol using our bespoke force field\n",
57+
"import copy\n",
58+
"from openff.units import unit\n",
5759
"from openfe.protocols.openmm_rfe import RelativeHybridTopologyProtocol\n",
5860
"import openfe\n",
5961
"\n",
60-
"\n",
6162
"# create the default protocol settings\n",
62-
"settings = RelativeHybridTopologyProtocol.default_settings()\n",
63+
"base_settings = RelativeHybridTopologyProtocol.default_settings()\n",
64+
"\n",
6365
"# add our new force field as a string\n",
6466
"# this avoids the need to move the file around when executing the transformations\n",
65-
"settings.forcefield_settings.small_molecule_forcefield = bespoke_force_field.to_string()\n",
67+
"base_settings.forcefield_settings.small_molecule_forcefield = bespoke_force_field.to_string()\n",
68+
"\n",
69+
"# we create a copy of the settings for the complex leg so that we can reduce the solvation cutoff\n",
70+
"complex_settings = copy.deepcopy(base_settings)\n",
71+
"complex_settings.solvation_settings.solvent_padding = 1 * unit.nanometer\n",
72+
"\n",
73+
"# create the protocols\n",
74+
"solvent_protocol = RelativeHybridTopologyProtocol(base_settings)\n",
75+
"complex_protocol = RelativeHybridTopologyProtocol(complex_settings)\n",
6676
"\n",
67-
"# create the protocol\n",
68-
"protocol = RelativeHybridTopologyProtocol(settings)\n",
6977
"\n",
7078
"# create the solvent and protein components\n",
7179
"solvent = openfe.SolventComponent()\n",
@@ -82,8 +90,11 @@
8290
" 'solvent': solvent}\n",
8391
"\n",
8492
" if leg == 'complex':\n",
93+
" protocol = complex_protocol\n",
8594
" sysA_dict['protein'] = protein\n",
8695
" sysB_dict['protein'] = protein\n",
96+
" else:\n",
97+
" protocol = solvent_protocol\n",
8798
"\n",
8899
" # we don't have to name objects, but it can make things (like filenames) more convenient\n",
89100
" sysA = openfe.ChemicalSystem(sysA_dict, name=f\"{mapping.componentA.name}_{leg}\")\n",
@@ -94,7 +105,7 @@
94105
" transformation = openfe.Transformation(\n",
95106
" stateA=sysA,\n",
96107
" stateB=sysB,\n",
97-
" mapping={'ligand': mapping},\n",
108+
" mapping=mapping,\n",
98109
" protocol=protocol, # use protocol created above\n",
99110
" name=f\"{prefix}{sysA.name}_{sysB.name}\"\n",
100111
" )\n",
@@ -112,7 +123,7 @@
112123
},
113124
{
114125
"cell_type": "code",
115-
"execution_count": 3,
126+
"execution_count": null,
116127
"metadata": {},
117128
"outputs": [],
118129
"source": [
@@ -123,7 +134,7 @@
123134
"\n",
124135
"# then we write out each transformation\n",
125136
"for transformation in network.edges:\n",
126-
" transformation.dump(transformation_dir / f\"{transformation.name}.json\")"
137+
" transformation.to_json(transformation_dir / f\"{transformation.name}.json\")"
127138
]
128139
},
129140
{
@@ -132,7 +143,8 @@
132143
"source": [
133144
"# Recap\n",
134145
"\n",
135-
"So to recap the workflow can be reduced to the following steps:\n\n",
146+
"So to recap the workflow can be reduced to the following steps:\n",
147+
"\n",
136148
"- Plan the RBFE network\n",
137149
"- Create a single SMIRNOFF style force field with all of the bespoke parameters for the network using the BespokeFit `combine` CLI\n",
138150
"- Store the force field as a string in the OpenFE protocol under the `settings.forcefield_settings.small_molecule_forcefield` field\n",
@@ -144,7 +156,7 @@
144156
],
145157
"metadata": {
146158
"kernelspec": {
147-
"display_name": "asapdiscovery",
159+
"display_name": "Python 3 (ipykernel)",
148160
"language": "python",
149161
"name": "python3"
150162
},
@@ -158,9 +170,16 @@
158170
"name": "python",
159171
"nbconvert_exporter": "python",
160172
"pygments_lexer": "ipython3",
161-
"version": "3.11.6"
173+
"version": "3.12.11"
174+
},
175+
"widgets": {
176+
"application/vnd.jupyter.widget-state+json": {
177+
"state": {},
178+
"version_major": 2,
179+
"version_minor": 0
180+
}
162181
}
163182
},
164183
"nbformat": 4,
165-
"nbformat_minor": 2
184+
"nbformat_minor": 4
166185
}

cookbook/choose_protocol.ipynb

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -178,64 +178,82 @@
178178
"text": [
179179
"{'alchemical_settings': {'endstate_dispersion_correction': False,\n",
180180
" 'explicit_charge_correction': False,\n",
181-
" 'explicit_charge_correction_cutoff': <Quantity(0.8, 'nanometer')>,\n",
181+
" 'explicit_charge_correction_cutoff': {'unit': 'nanometer',\n",
182+
" 'val': 0.8},\n",
182183
" 'softcore_LJ': 'gapsys',\n",
183184
" 'softcore_alpha': 0.85,\n",
184185
" 'turn_off_core_unique_exceptions': False,\n",
185186
" 'use_dispersion_correction': False},\n",
186-
" 'engine_settings': {'compute_platform': None, 'gpu_device_index': None},\n",
187+
" 'engine_settings': {'compute_platform': 'cuda', 'gpu_device_index': None},\n",
187188
" 'forcefield_settings': {'constraints': 'hbonds',\n",
188189
" 'forcefields': ['amber/ff14SB.xml',\n",
189190
" 'amber/tip3p_standard.xml',\n",
190191
" 'amber/tip3p_HFE_multivalent.xml',\n",
191192
" 'amber/phosaa10.xml'],\n",
192193
" 'hydrogen_mass': 3.0,\n",
193-
" 'nonbonded_cutoff': <Quantity(1.0, 'nanometer')>,\n",
194+
" 'nonbonded_cutoff': {'unit': 'nanometer', 'val': 0.9},\n",
194195
" 'nonbonded_method': 'PME',\n",
195196
" 'rigid_water': True,\n",
196-
" 'small_molecule_forcefield': 'openff-2.1.1'},\n",
197-
" 'integrator_settings': {'barostat_frequency': <Quantity(25.0, 'timestep')>,\n",
197+
" 'small_molecule_forcefield': 'openff-2.2.1'},\n",
198+
" 'integrator_settings': {'barostat_frequency': {'unit': 'timestep',\n",
199+
" 'val': 25.0},\n",
198200
" 'constraint_tolerance': 1e-06,\n",
199-
" 'langevin_collision_rate': <Quantity(1.0, '1 / picosecond')>,\n",
201+
" 'langevin_collision_rate': {'unit': '1 / picosecond',\n",
202+
" 'val': 1.0},\n",
200203
" 'n_restart_attempts': 20,\n",
201204
" 'reassign_velocities': False,\n",
202205
" 'remove_com': False,\n",
203-
" 'timestep': <Quantity(4.0, 'femtosecond')>},\n",
206+
" 'timestep': {'unit': 'femtosecond', 'val': 4.0}},\n",
204207
" 'lambda_settings': {'lambda_functions': 'default', 'lambda_windows': 11},\n",
205-
" 'output_settings': {'checkpoint_interval': <Quantity(1.0, 'nanosecond')>,\n",
208+
" 'output_settings': {'checkpoint_interval': {'unit': 'nanosecond', 'val': 1.0},\n",
206209
" 'checkpoint_storage_filename': 'checkpoint.chk',\n",
207210
" 'forcefield_cache': 'db.json',\n",
208211
" 'output_filename': 'simulation.nc',\n",
209212
" 'output_indices': 'not water',\n",
210213
" 'output_structure': 'hybrid_system.pdb',\n",
211-
" 'positions_write_frequency': <Quantity(100.0, 'picosecond')>,\n",
214+
" 'positions_write_frequency': {'unit': 'picosecond',\n",
215+
" 'val': 100.0},\n",
212216
" 'velocities_write_frequency': None},\n",
213217
" 'partial_charge_settings': {'nagl_model': None,\n",
214218
" 'number_of_conformers': None,\n",
215219
" 'off_toolkit_backend': 'ambertools',\n",
216220
" 'partial_charge_method': 'am1bcc'},\n",
217221
" 'protocol_repeats': 3,\n",
218-
" 'simulation_settings': {'early_termination_target_error': <Quantity(0.0, 'kilocalorie_per_mole')>,\n",
219-
" 'equilibration_length': <Quantity(1.0, 'nanosecond')>,\n",
222+
" 'simulation_settings': {'early_termination_target_error': {'unit': 'kilocalorie_per_mole',\n",
223+
" 'val': 0.0},\n",
224+
" 'equilibration_length': {'unit': 'nanosecond',\n",
225+
" 'val': 1.0},\n",
220226
" 'minimization_steps': 5000,\n",
221227
" 'n_replicas': 11,\n",
222-
" 'production_length': <Quantity(5.0, 'nanosecond')>,\n",
223-
" 'real_time_analysis_interval': <Quantity(250.0, 'picosecond')>,\n",
224-
" 'real_time_analysis_minimum_time': <Quantity(500.0, 'picosecond')>,\n",
228+
" 'production_length': {'unit': 'nanosecond',\n",
229+
" 'val': 5.0},\n",
230+
" 'real_time_analysis_interval': {'unit': 'picosecond',\n",
231+
" 'val': 250.0},\n",
232+
" 'real_time_analysis_minimum_time': {'unit': 'picosecond',\n",
233+
" 'val': 500.0},\n",
225234
" 'sampler_method': 'repex',\n",
226235
" 'sams_flatness_criteria': 'logZ-flatness',\n",
227236
" 'sams_gamma0': 1.0,\n",
228-
" 'time_per_iteration': <Quantity(1.0, 'picosecond')>},\n",
229-
" 'solvation_settings': {'box_shape': 'cube',\n",
237+
" 'time_per_iteration': {'unit': 'picosecond',\n",
238+
" 'val': 2.5}},\n",
239+
" 'solvation_settings': {'box_shape': 'dodecahedron',\n",
230240
" 'box_size': None,\n",
231241
" 'box_vectors': None,\n",
232242
" 'number_of_solvent_molecules': None,\n",
233243
" 'solvent_model': 'tip3p',\n",
234-
" 'solvent_padding': <Quantity(1.2, 'nanometer')>},\n",
244+
" 'solvent_padding': {'unit': 'nanometer', 'val': 1.5}},\n",
235245
" 'thermo_settings': {'ph': None,\n",
236-
" 'pressure': <Quantity(0.986923267, 'standard_atmosphere')>,\n",
246+
" 'pressure': {'unit': 'bar', 'val': 1},\n",
237247
" 'redox_potential': None,\n",
238-
" 'temperature': <Quantity(298.15, 'kelvin')>}}\n"
248+
" 'temperature': {'unit': 'kelvin', 'val': 298.15}}}\n"
249+
]
250+
},
251+
{
252+
"name": "stderr",
253+
"output_type": "stream",
254+
"text": [
255+
"/Users/atravitz/micromamba/envs/openfe-conda/lib/python3.11/site-packages/gufe/settings/models.py:30: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/\n",
256+
" pprint.pprint(self.dict())\n"
239257
]
240258
}
241259
],
@@ -318,11 +336,11 @@
318336
" ],\n",
319337
" \n",
320338
" # Small molecule force field to use with OpenMM template generator:\n",
321-
" small_molecule_forcefield='openff-2.1.1',\n",
339+
" small_molecule_forcefield='openff-2.2.1',\n",
322340
" \n",
323341
" # Nonbonded settings\n",
324342
" nonbonded_method='PME', # Particle Mesh Ewald for long range electrostatics\n",
325-
" nonbonded_cutoff=1.0 * unit.nm, # Cut off Lennard-Jones interactions beyond 1 nm\n",
343+
" nonbonded_cutoff=0.9 * unit.nm, # Cut off Lennard-Jones interactions beyond 0.9 nm\n",
326344
" ),\n",
327345
" thermo_settings=equil_rfe_settings.ThermoSettings(\n",
328346
" temperature=298.15 * unit.kelvin, # Set thermostat temperature\n",
@@ -332,8 +350,8 @@
332350
" ),\n",
333351
" solvation_settings=equil_rfe_settings.OpenMMSolvationSettings(\n",
334352
" solvent_model='tip3p', # Solvent model to generate starting coords\n",
335-
" solvent_padding=1.2 * unit.nm, # Total distance between periodic image starting coords\n",
336-
" box_shape = 'cube', # Cubic water box\n",
353+
" solvent_padding=1.5 * unit.nm, # Minimum padding distance from the solute\n",
354+
" box_shape = 'dodecahedron', # Dodecahedron water box\n",
337355
" box_size = None, # Size of the water box\n",
338356
" box_vectors = None, # Box vectors\n",
339357
" number_of_solvent_molecules = None, # Number of solvent molecules\n",
@@ -372,7 +390,7 @@
372390
" # Alchemical Space Sampling settings\n",
373391
" n_replicas=11, # Number of replicas sampling alchemical space\n",
374392
" sampler_method='repex', # Sample lambda with Hamiltonian Replica Exchange\n",
375-
" time_per_iteration=1*unit.ps, # Time interval between state sampling (MCMC) attempts\n",
393+
" time_per_iteration=2.5*unit.ps, # Time interval between state sampling (MCMC) attempts\n",
376394
" \n",
377395
" # SAMS sampling settings (used if sampler_method='sams')\n",
378396
" sams_flatness_criteria='logZ-flatness', # Criteria for switch to asymptomatically optimal scheme\n",
@@ -387,7 +405,7 @@
387405
" early_termination_target_error=0.0*unit.kilocalorie_per_mole,\n",
388406
" ),\n",
389407
" engine_settings=equil_rfe_settings.OpenMMEngineSettings(\n",
390-
" compute_platform=None, # Let OpenMM choose the best platform for your hardware\n",
408+
" compute_platform=\"cuda\", # Force the usage of a CUDA device for compute\n",
391409
" ),\n",
392410
" integrator_settings=equil_rfe_settings.IntegratorSettings(\n",
393411
" timestep=4 * unit.femtosecond, # Integration timestep\n",
@@ -466,6 +484,14 @@
466484
"source": [
467485
"Unlike `ProtocolSettings`, a `Protocol` instance is immutable. The only way to safely change the settings of a `Protocol` is to recreate it from the modified `ProtocolSettings` object."
468486
]
487+
},
488+
{
489+
"cell_type": "code",
490+
"execution_count": null,
491+
"id": "91e223bc-5dc7-4533-ba5d-da112809be9a",
492+
"metadata": {},
493+
"outputs": [],
494+
"source": []
469495
}
470496
],
471497
"metadata": {
@@ -484,7 +510,7 @@
484510
"name": "python",
485511
"nbconvert_exporter": "python",
486512
"pygments_lexer": "ipython3",
487-
"version": "3.12.10"
513+
"version": "3.11.14"
488514
},
489515
"widgets": {
490516
"application/vnd.jupyter.widget-state+json": {

0 commit comments

Comments
 (0)