Skip to content

Commit 202a0e3

Browse files
authored
Merge pull request #276 from OpenFreeEnergy/consolidate_preparing_alchemical_networks
consolidate instructions for creating an alchemical network
2 parents f652cc0 + f9bfe01 commit 202a0e3

2 files changed

Lines changed: 50 additions & 645 deletions

File tree

cookbook/create_alchemical_network.ipynb

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
"id": "2b11a786-0fab-4990-a2aa-242067f89287",
1414
"metadata": {},
1515
"source": [
16-
"The final setup step is to compile all the different bits of information into a description of a single simulation campaign. This description takes the form of an [Alchemical Network]. Similarly to `LigandNetwork`, the `AlchemicalNetwork` class is a graph of all the transformations in the campaign; however, in an `AlchemicalNetwork`, these transformations include all the information needed to perform the transformation. By contrast, a `LigandNetwork` includes only the ligands themselves.\n",
16+
"The final setup step is to compile all the different bits of information into a description of a single simulation campaign. This description takes the form of an [Alchemical Network].\n",
17+
"Similar to `LigandNetwork`, the `AlchemicalNetwork` class is a graph of all the transformations in the campaign.\n",
18+
"\n",
19+
"However, in an `AlchemicalNetwork`, these transformations include all the information needed to perform the transformation. By contrast, a `LigandNetwork` includes only the ligands themselves.\n",
20+
"\n",
21+
"See the [User Guide: Alchemical Networks](https://docs.openfree.energy/en/stable/guide/setup/alchemical_network_model.html) for more background information.\n",
1722
"\n",
1823
"[Alchemical Network]: https://docs.openfree.energy/en/stable/reference/api/generated/openfe.AlchemicalNetwork.html"
1924
]
@@ -28,38 +33,33 @@
2833
"tags": []
2934
},
3035
"source": [
31-
"## Setup"
32-
]
33-
},
34-
{
35-
"cell_type": "code",
36-
"execution_count": 1,
37-
"id": "ba6d0d2f-03df-463f-8976-c15a2bdf65e5",
38-
"metadata": {},
39-
"outputs": [],
40-
"source": [
41-
"import openfe, rdkit.Chem\n",
42-
"from openff.units import unit\n",
43-
"from openfe.protocols.openmm_rfe import RelativeHybridTopologyProtocol"
36+
"## Start with a `LigandNetwork`"
4437
]
4538
},
4639
{
4740
"cell_type": "markdown",
4841
"id": "6bfee4c7-0aaf-49a6-b35a-bdbe99444bab",
4942
"metadata": {},
5043
"source": [
51-
"This cookbook assumes you've already loaded a `LigandNetwork`. For more information, see [Generate a Ligand Network Automatically]:\n",
44+
"This cookbook assumes you've already loaded a `LigandNetwork`.\n",
5245
"\n",
53-
"[Generate a Ligand Network Automatically]: https://docs.openfree.energy/en/stable/cookbook/generate_ligand_network.html"
46+
"To learn how to build a `LigandNetwork`, see [Planning a Ligand Network]:\n",
47+
"\n",
48+
"[Planning a Ligand Network]: https://docs.openfree.energy/en/stable/cookbook/generate_ligand_network.html"
5449
]
5550
},
5651
{
5752
"cell_type": "code",
58-
"execution_count": 2,
53+
"execution_count": 1,
5954
"id": "4512c4d6-720f-4008-af53-a0b56b2ee1e9",
6055
"metadata": {},
6156
"outputs": [],
6257
"source": [
58+
"import openfe\n",
59+
"import rdkit.Chem\n",
60+
"from openff.units import unit\n",
61+
"from openfe.protocols.openmm_rfe import RelativeHybridTopologyProtocol\n",
62+
"\n",
6363
"ligand_network = openfe.ligand_network_planning.generate_minimal_spanning_network(\n",
6464
" ligands=[\n",
6565
" openfe.SmallMoleculeComponent(mol) \n",
@@ -85,7 +85,7 @@
8585
},
8686
{
8787
"cell_type": "code",
88-
"execution_count": 3,
88+
"execution_count": 2,
8989
"id": "940e2e19-4e7d-4853-ab5e-54626b3384d8",
9090
"metadata": {},
9191
"outputs": [],
@@ -105,7 +105,7 @@
105105
},
106106
{
107107
"cell_type": "code",
108-
"execution_count": 4,
108+
"execution_count": 3,
109109
"id": "d3054cfc-5040-4882-b3a3-92aba7ab5d1d",
110110
"metadata": {
111111
"slideshow": {
@@ -149,7 +149,7 @@
149149
},
150150
{
151151
"cell_type": "code",
152-
"execution_count": 5,
152+
"execution_count": 4,
153153
"id": "733dee64-d23a-4eb0-87cf-c03065b8d2a6",
154154
"metadata": {},
155155
"outputs": [],
@@ -181,27 +181,34 @@
181181
},
182182
{
183183
"cell_type": "code",
184-
"execution_count": 6,
184+
"execution_count": 5,
185185
"id": "c49f36b1-c3c1-425e-b1de-24da25ed01c3",
186186
"metadata": {},
187187
"outputs": [],
188188
"source": [
189189
"# In an RBFE, each edge includes two \"legs\": \n",
190190
"# one for the ligand complexed to the protein, \n",
191191
"# and the other for the ligand free in solution\n",
192+
"\n",
193+
"\n",
192194
"legs = {\n",
193-
" \"solvent\": {\n",
194-
" # Specify the components common to all systems in this leg\n",
195-
" 'solvent': solvent,\n",
196-
" },\n",
197-
" \"complex\": {\n",
198-
" # Specify the components common to all systems in this leg\n",
199-
" 'solvent': solvent,\n",
200-
" 'protein': protein,\n",
201-
" }\n",
202-
"}\n",
203-
"transformations = []\n",
195+
" # Specify the components common to all systems in this leg\n",
196+
" \"solvent\": {'solvent': solvent},\n",
197+
" # Specify the components common to all systems in this leg\n",
198+
" \"complex\": {'solvent': solvent, 'protein': protein}\n",
199+
"}"
200+
]
201+
},
202+
{
203+
"cell_type": "code",
204+
"execution_count": 6,
205+
"id": "77d71229-5dcc-40cf-a9ae-0724a7327578",
206+
"metadata": {},
207+
"outputs": [],
208+
"source": [
209+
"# create a list of transformations\n",
204210
"\n",
211+
"transformations = []\n",
205212
"for mapping in ligand_network.edges:\n",
206213
" for leg, common_components in legs.items():\n",
207214
" system_a = openfe.ChemicalSystem(\n",
@@ -229,7 +236,7 @@
229236
" name=f\"easy_rbfe_{system_a.name}_{system_b.name}\"\n",
230237
" )\n",
231238
" \n",
232-
" transformations.append(transformation)"
239+
" transformations.append(transformation)\n"
233240
]
234241
},
235242
{
@@ -324,8 +331,16 @@
324331
"\n",
325332
"for n, transformation in enumerate(alchemical_network.edges):\n",
326333
" transformation_name = transformation.name or transformation.key\n",
327-
" transformation.dump(transformations_dir / f\"{n}_{transformation_name}.json\")"
334+
" transformation.to_json(transformations_dir / f\"{n}_{transformation_name}.json\")"
328335
]
336+
},
337+
{
338+
"cell_type": "code",
339+
"execution_count": null,
340+
"id": "28d7af7c-0e8e-4379-91c2-c9d291c3923b",
341+
"metadata": {},
342+
"outputs": [],
343+
"source": []
329344
}
330345
],
331346
"metadata": {
@@ -344,7 +359,7 @@
344359
"name": "python",
345360
"nbconvert_exporter": "python",
346361
"pygments_lexer": "ipython3",
347-
"version": "3.11.6"
362+
"version": "3.13.11"
348363
},
349364
"widgets": {
350365
"application/vnd.jupyter.widget-state+json": {

0 commit comments

Comments
 (0)