Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions cookbook/bespoke_parameters_showcase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,31 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# create the OpenFE RBFE protocol using our bespoke force field\n",
"import copy\n",
"from openff.units import unit\n",
"from openfe.protocols.openmm_rfe import RelativeHybridTopologyProtocol\n",
"import openfe\n",
"\n",
"\n",
"# create the default protocol settings\n",
"settings = RelativeHybridTopologyProtocol.default_settings()\n",
"base_settings = RelativeHybridTopologyProtocol.default_settings()\n",
"\n",
"# add our new force field as a string\n",
"# this avoids the need to move the file around when executing the transformations\n",
"settings.forcefield_settings.small_molecule_forcefield = bespoke_force_field.to_string()\n",
"base_settings.forcefield_settings.small_molecule_forcefield = bespoke_force_field.to_string()\n",
"\n",
"# we create a copy of the settings for the complex leg so that we can reduce the solvation cutoff\n",
"complex_settings = copy.deepcopy(base_settings)\n",
"complex_settings.solvation_settings.solvent_padding = 1 * unit.nanometer\n",
"\n",
"# create the protocols\n",
"solvent_protocol = RelativeHybridTopologyProtocol(base_settings)\n",
"complex_protocol = RelativeHybridTopologyProtocol(complex_settings)\n",
"\n",
"# create the protocol\n",
"protocol = RelativeHybridTopologyProtocol(settings)\n",
"\n",
"# create the solvent and protein components\n",
"solvent = openfe.SolventComponent()\n",
Expand All @@ -82,8 +90,11 @@
" 'solvent': solvent}\n",
"\n",
" if leg == 'complex':\n",
" protocol = complex_protocol\n",
" sysA_dict['protein'] = protein\n",
" sysB_dict['protein'] = protein\n",
" else:\n",
" protocol = solvent_protocol\n",
"\n",
" # we don't have to name objects, but it can make things (like filenames) more convenient\n",
" sysA = openfe.ChemicalSystem(sysA_dict, name=f\"{mapping.componentA.name}_{leg}\")\n",
Expand All @@ -94,7 +105,7 @@
" transformation = openfe.Transformation(\n",
" stateA=sysA,\n",
" stateB=sysB,\n",
" mapping={'ligand': mapping},\n",
" mapping=mapping,\n",
" protocol=protocol, # use protocol created above\n",
" name=f\"{prefix}{sysA.name}_{sysB.name}\"\n",
" )\n",
Expand All @@ -112,7 +123,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -123,7 +134,7 @@
"\n",
"# then we write out each transformation\n",
"for transformation in network.edges:\n",
" transformation.dump(transformation_dir / f\"{transformation.name}.json\")"
" transformation.to_json(transformation_dir / f\"{transformation.name}.json\")"
]
},
{
Expand All @@ -132,7 +143,8 @@
"source": [
"# Recap\n",
"\n",
"So to recap the workflow can be reduced to the following steps:\n\n",
"So to recap the workflow can be reduced to the following steps:\n",
"\n",
"- Plan the RBFE network\n",
"- Create a single SMIRNOFF style force field with all of the bespoke parameters for the network using the BespokeFit `combine` CLI\n",
"- Store the force field as a string in the OpenFE protocol under the `settings.forcefield_settings.small_molecule_forcefield` field\n",
Expand All @@ -144,7 +156,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "asapdiscovery",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -158,9 +170,16 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.12.11"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
78 changes: 52 additions & 26 deletions cookbook/choose_protocol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -178,64 +178,82 @@
"text": [
"{'alchemical_settings': {'endstate_dispersion_correction': False,\n",
" 'explicit_charge_correction': False,\n",
" 'explicit_charge_correction_cutoff': <Quantity(0.8, 'nanometer')>,\n",
" 'explicit_charge_correction_cutoff': {'unit': 'nanometer',\n",
" 'val': 0.8},\n",
" 'softcore_LJ': 'gapsys',\n",
" 'softcore_alpha': 0.85,\n",
" 'turn_off_core_unique_exceptions': False,\n",
" 'use_dispersion_correction': False},\n",
" 'engine_settings': {'compute_platform': None, 'gpu_device_index': None},\n",
" 'engine_settings': {'compute_platform': 'cuda', 'gpu_device_index': None},\n",
" 'forcefield_settings': {'constraints': 'hbonds',\n",
" 'forcefields': ['amber/ff14SB.xml',\n",
" 'amber/tip3p_standard.xml',\n",
" 'amber/tip3p_HFE_multivalent.xml',\n",
" 'amber/phosaa10.xml'],\n",
" 'hydrogen_mass': 3.0,\n",
" 'nonbonded_cutoff': <Quantity(1.0, 'nanometer')>,\n",
" 'nonbonded_cutoff': {'unit': 'nanometer', 'val': 0.9},\n",
" 'nonbonded_method': 'PME',\n",
" 'rigid_water': True,\n",
" 'small_molecule_forcefield': 'openff-2.1.1'},\n",
" 'integrator_settings': {'barostat_frequency': <Quantity(25.0, 'timestep')>,\n",
" 'small_molecule_forcefield': 'openff-2.2.1'},\n",
" 'integrator_settings': {'barostat_frequency': {'unit': 'timestep',\n",
" 'val': 25.0},\n",
" 'constraint_tolerance': 1e-06,\n",
" 'langevin_collision_rate': <Quantity(1.0, '1 / picosecond')>,\n",
" 'langevin_collision_rate': {'unit': '1 / picosecond',\n",
" 'val': 1.0},\n",
" 'n_restart_attempts': 20,\n",
" 'reassign_velocities': False,\n",
" 'remove_com': False,\n",
" 'timestep': <Quantity(4.0, 'femtosecond')>},\n",
" 'timestep': {'unit': 'femtosecond', 'val': 4.0}},\n",
" 'lambda_settings': {'lambda_functions': 'default', 'lambda_windows': 11},\n",
" 'output_settings': {'checkpoint_interval': <Quantity(1.0, 'nanosecond')>,\n",
" 'output_settings': {'checkpoint_interval': {'unit': 'nanosecond', 'val': 1.0},\n",
" 'checkpoint_storage_filename': 'checkpoint.chk',\n",
" 'forcefield_cache': 'db.json',\n",
" 'output_filename': 'simulation.nc',\n",
" 'output_indices': 'not water',\n",
" 'output_structure': 'hybrid_system.pdb',\n",
" 'positions_write_frequency': <Quantity(100.0, 'picosecond')>,\n",
" 'positions_write_frequency': {'unit': 'picosecond',\n",
" 'val': 100.0},\n",
" 'velocities_write_frequency': None},\n",
" 'partial_charge_settings': {'nagl_model': None,\n",
" 'number_of_conformers': None,\n",
" 'off_toolkit_backend': 'ambertools',\n",
" 'partial_charge_method': 'am1bcc'},\n",
" 'protocol_repeats': 3,\n",
" 'simulation_settings': {'early_termination_target_error': <Quantity(0.0, 'kilocalorie_per_mole')>,\n",
" 'equilibration_length': <Quantity(1.0, 'nanosecond')>,\n",
" 'simulation_settings': {'early_termination_target_error': {'unit': 'kilocalorie_per_mole',\n",
" 'val': 0.0},\n",
" 'equilibration_length': {'unit': 'nanosecond',\n",
" 'val': 1.0},\n",
" 'minimization_steps': 5000,\n",
" 'n_replicas': 11,\n",
" 'production_length': <Quantity(5.0, 'nanosecond')>,\n",
" 'real_time_analysis_interval': <Quantity(250.0, 'picosecond')>,\n",
" 'real_time_analysis_minimum_time': <Quantity(500.0, 'picosecond')>,\n",
" 'production_length': {'unit': 'nanosecond',\n",
" 'val': 5.0},\n",
" 'real_time_analysis_interval': {'unit': 'picosecond',\n",
" 'val': 250.0},\n",
" 'real_time_analysis_minimum_time': {'unit': 'picosecond',\n",
" 'val': 500.0},\n",
" 'sampler_method': 'repex',\n",
" 'sams_flatness_criteria': 'logZ-flatness',\n",
" 'sams_gamma0': 1.0,\n",
" 'time_per_iteration': <Quantity(1.0, 'picosecond')>},\n",
" 'solvation_settings': {'box_shape': 'cube',\n",
" 'time_per_iteration': {'unit': 'picosecond',\n",
" 'val': 2.5}},\n",
" 'solvation_settings': {'box_shape': 'dodecahedron',\n",
" 'box_size': None,\n",
" 'box_vectors': None,\n",
" 'number_of_solvent_molecules': None,\n",
" 'solvent_model': 'tip3p',\n",
" 'solvent_padding': <Quantity(1.2, 'nanometer')>},\n",
" 'solvent_padding': {'unit': 'nanometer', 'val': 1.5}},\n",
" 'thermo_settings': {'ph': None,\n",
" 'pressure': <Quantity(0.986923267, 'standard_atmosphere')>,\n",
" 'pressure': {'unit': 'bar', 'val': 1},\n",
" 'redox_potential': None,\n",
" 'temperature': <Quantity(298.15, 'kelvin')>}}\n"
" 'temperature': {'unit': 'kelvin', 'val': 298.15}}}\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/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",
" pprint.pprint(self.dict())\n"
]
}
],
Expand Down Expand Up @@ -318,11 +336,11 @@
" ],\n",
" \n",
" # Small molecule force field to use with OpenMM template generator:\n",
" small_molecule_forcefield='openff-2.1.1',\n",
" small_molecule_forcefield='openff-2.2.1',\n",
" \n",
" # Nonbonded settings\n",
" nonbonded_method='PME', # Particle Mesh Ewald for long range electrostatics\n",
" nonbonded_cutoff=1.0 * unit.nm, # Cut off Lennard-Jones interactions beyond 1 nm\n",
" nonbonded_cutoff=0.9 * unit.nm, # Cut off Lennard-Jones interactions beyond 0.9 nm\n",
" ),\n",
" thermo_settings=equil_rfe_settings.ThermoSettings(\n",
" temperature=298.15 * unit.kelvin, # Set thermostat temperature\n",
Expand All @@ -332,8 +350,8 @@
" ),\n",
" solvation_settings=equil_rfe_settings.OpenMMSolvationSettings(\n",
" solvent_model='tip3p', # Solvent model to generate starting coords\n",
" solvent_padding=1.2 * unit.nm, # Total distance between periodic image starting coords\n",
" box_shape = 'cube', # Cubic water box\n",
" solvent_padding=1.5 * unit.nm, # Minimum padding distance from the solute\n",
" box_shape = 'dodecahedron', # Dodecahedron water box\n",
" box_size = None, # Size of the water box\n",
" box_vectors = None, # Box vectors\n",
" number_of_solvent_molecules = None, # Number of solvent molecules\n",
Expand Down Expand Up @@ -372,7 +390,7 @@
" # Alchemical Space Sampling settings\n",
" n_replicas=11, # Number of replicas sampling alchemical space\n",
" sampler_method='repex', # Sample lambda with Hamiltonian Replica Exchange\n",
" time_per_iteration=1*unit.ps, # Time interval between state sampling (MCMC) attempts\n",
" time_per_iteration=2.5*unit.ps, # Time interval between state sampling (MCMC) attempts\n",
" \n",
" # SAMS sampling settings (used if sampler_method='sams')\n",
" sams_flatness_criteria='logZ-flatness', # Criteria for switch to asymptomatically optimal scheme\n",
Expand All @@ -387,7 +405,7 @@
" early_termination_target_error=0.0*unit.kilocalorie_per_mole,\n",
" ),\n",
" engine_settings=equil_rfe_settings.OpenMMEngineSettings(\n",
" compute_platform=None, # Let OpenMM choose the best platform for your hardware\n",
" compute_platform=\"cuda\", # Force the usage of a CUDA device for compute\n",
" ),\n",
" integrator_settings=equil_rfe_settings.IntegratorSettings(\n",
" timestep=4 * unit.femtosecond, # Integration timestep\n",
Expand Down Expand Up @@ -466,6 +484,14 @@
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "91e223bc-5dc7-4533-ba5d-da112809be9a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -484,7 +510,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.10"
"version": "3.11.14"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
Loading
Loading