{
"cells": [
{
"cell_type": "markdown",
"id": "c78efe73-21eb-4da8-8859-8b500e1dc1b2",
"metadata": {},
"source": [
"# Running MD simulations"
]
},
{
"cell_type": "markdown",
"id": "64f939ac-6f7a-4198-902c-00a655a10634",
"metadata": {},
"source": [
"Running vanilla molecular dynamics (MD) simulations on protein-ligand complexes can provide information about the dynamics of a given ligand inside the binding site and can be used to assess the quality and stability of a proposed binding mode.\n",
"\n",
"Below we will demonstrate an example of running MD simulations on a protein ligand complex, following docking, using the drugforge framework. \n",
"\n",
"We will be running this example on an ASAP target, the SARS-CoV-2 nsp3 Mac1 macrodomain; this removes ADP ribose from viral and host cell proteins. The removal of this post-translational modification reduces the inflammatory and antiviral responses to infection — facilitating replication. For more information on Mac1, follow this [link](https://asapdiscovery.notion.site/Targeting-Opportunity-SARS-CoV-2-nsp3-Mac1-macrodomain-47af24638b994e8ba786303ec743926e).\n",
"\n",
"### Required modules\n",
"To execute this example, the following drugforge modules to be installed: \n",
"- `data`,\n",
"- `docking`,\n",
"- `modeling`\n",
"- `simulation`\n",
" \n",
"To enable the visualization of the docking results, the following modules will also need to be installed:\n",
"- `dataviz`\n",
"- `spectrum`.\n",
"\n",
"**Note** this example requires users have an [OpenEye](https://www.eyesopen.com/) license.\n",
"\n",
"Please refer to the [installation instructions](https://github.com/choderalab/drugforge?tab=readme-ov-file#installation) for more details. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "38041a7e-e18c-42ab-8f64-dbe98ab3efd6",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# import some dependencies\n",
"from drugforge.data.testing.test_resources import fetch_test_file\n",
"from drugforge.docking.docking import DockingInputPair\n",
"from drugforge.docking.openeye import POSITDocker\n",
"from drugforge.data.schema.complex import Complex, PreppedComplex\n",
"from drugforge.data.schema.ligand import Ligand\n",
"from drugforge.simulation.simulate import VanillaMDSimulator"
]
},
{
"cell_type": "markdown",
"id": "7422ecbb-222d-40d6-81b6-6c45f8f05527",
"metadata": {},
"source": [
"## Docking an arbitrary ligand to Mac1\n",
"Let us fetch an example structure of Mac1, hosted in the ASAP testing repository. For convenience, we will utilize the `fetch_test_file` function (part of the `data` module) to download this file and return its location."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "40fd3808-12e8-41f5-9348-a803403b3084",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/hugomacdermott/Library/Caches/asapdiscovery_testing/SARS2_Mac1A-A1013.pdb\n"
]
}
],
"source": [
"# fetch a PDB file from the test suite, in this case a PDB from the COVID MOONSHOT.\n",
"protein_pdb_file = fetch_test_file(\"SARS2_Mac1A-A1013.pdb\") \n",
"\n",
"# print out the location of the pdb file we just downloaded. \n",
"print(protein_pdb_file) "
]
},
{
"cell_type": "markdown",
"id": "a22ca4fe-29a6-4332-b010-65612d755372",
"metadata": {},
"source": [
"Now we will create a `Complex` object from the .pdb file (see the tutorial on base level ASAP abstractions for more info)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a1c841bf-39f0-419b-8f4a-9478bc7b871a",
"metadata": {},
"outputs": [],
"source": [
"# make a complex \n",
"mac1_complex = Complex.from_pdb(protein_pdb_file, ligand_kwargs={\"compound_name\": \"A1013\"}, target_kwargs={\"target_name\": \"SARS2_Mac1A\"})"
]
},
{
"cell_type": "markdown",
"id": "6e53394d-dfa5-4af7-9a95-90df72cec7e8",
"metadata": {},
"source": [
"We will need to create a `Ligand` object to dock into the structure. In this case we will generate the ligand from a SMILES string. Note, in addition to SMILES, the ligands can also be created from InChI strings, SDF files, and OEMol instances. "
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0e145b8c-b548-4b77-9688-2b0bdfcba680",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# make the ligand we want to dock, a simple alkane\n",
"ligand = Ligand.from_smiles(\"CCCCCCC\", compound_name=\"alkane\")"
]
},
{
"cell_type": "markdown",
"id": "0d016862-1743-4ac0-b293-40fb07de6a43",
"metadata": {},
"source": [
"Next, we will run protein preparation."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "26d89a1a-dec0-4cc7-adc5-d4f93ced99d8",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning: No BioAssembly transforms found, using input molecule as biounit: ---_LIG\n",
"DPI: 0.12, RFree: 0.28, Resolution: 1.48\n",
"Processing BU # 1 with title: ---_LIG, chains AB\n"
]
}
],
"source": [
"# prepare our structure\n",
"prepped_mac1_complex_complex = PreppedComplex.from_complex(mac1_complex)\n",
"# pair it up with the ligand we want to dock.\n",
"docking_input_pair = DockingInputPair(complex=prepped_mac1_complex_complex, ligand=ligand)\n"
]
},
{
"cell_type": "markdown",
"id": "2c2d00c3-1cc7-43e0-b368-edda87c96f38",
"metadata": {},
"source": [
"Now, we dock it to our protein. Note, `use_dask` is set to `False`, disabling parallel execution, as it is not required for this example (Note, `dask` is discussed at the end of this tutorial). "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0e56be91-618f-423b-ba4a-9cbf6985b14f",
"metadata": {},
"outputs": [],
"source": [
"# run OpenEye POSIT docking,\n",
"docker = POSITDocker(use_omega=False)\n",
"results = docker.dock([docking_input_pair], use_dask=False)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "26febc9e-2577-4392-941e-172e86c37c6e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'docking-confidence-POSIT': 0.019999999552965164, '_POSIT_method': 'FRED'}\n"
]
}
],
"source": [
"print(results[0].posed_ligand.tags)"
]
},
{
"cell_type": "markdown",
"id": "41c84958-6fa9-4d1d-8b85-972402cd0e12",
"metadata": {},
"source": [
"## Vizualise the docked pose\n",
"Let us now vizualise our results! For more information on vizualisations, see the vizualisation notebook hosted in the [examples directory](https://github.com/choderalab/drugforge/tree/main/examples)."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2205a034-ff8a-489a-a445-c2c35952dbc5",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-05-10 13:03:23,875 [INFO] [plipcmd.py:124] plip.plipcmd: Protein-Ligand Interaction Profiler (PLIP) 2.3.0\n",
"2024-05-10 13:03:23,875 [INFO] [plipcmd.py:125] plip.plipcmd: brought to you by: PharmAI GmbH (2020-2021) - www.pharm.ai - hello@pharm.ai\n",
"2024-05-10 13:03:23,875 [INFO] [plipcmd.py:126] plip.plipcmd: please cite: Adasme,M. et al. PLIP 2021: expanding the scope of the protein-ligand interaction profiler to DNA and RNA. Nucl. Acids Res. (05 May 2021), gkab294. doi: 10.1093/nar/gkab294\n",
"2024-05-10 13:03:23,875 [INFO] [plipcmd.py:49] plip.plipcmd: starting analysis of tmp_complex.pdb\n",
"2024-05-10 13:03:24,022 [INFO] [plipcmd.py:165] plip.plipcmd: finished analysis, find the result files in /var/folders/f5/0zcc5b7570jc40ws28tqdp740000gn/T/tmpsqm6hmwx/\n"
]
}
],
"source": [
"# create a visualization factory. \n",
"from drugforge.dataviz.html_viz import HTMLVisualizer\n",
"\n",
"html_vizualizer = HTMLVisualizer(\n",
" target=\"SARS-CoV-2-Mac1\",\n",
" color_method=\"subpockets\",\n",
" align=True,\n",
" output_dir=\"tutorial_files/running_md_simulations/\",\n",
" write_to_disk=True,\n",
" )\n",
"vizs_from_docked = html_vizualizer.visualize(inputs=results, outpaths=[\"visualise_docked.html\"], use_dask=False)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "e2879742-8d05-4415-bc9f-d0c2b81b1fc7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import IFrame\n",
"IFrame(vizs_from_docked[\"html_path_pose\"][0], 1000, 1000)"
]
},
{
"cell_type": "markdown",
"id": "45e70275-a7e4-44a9-9737-791e621179dc",
"metadata": {},
"source": [
"## Running a single MD simulation\n",
"\n",
"Great, our pose looks good! Lets use the `VanillaMDSimulator` to run simulations of the protein-ligand complex. \n",
"\n",
"The `VanillaMDSimulator` has many options for running simulations in different configurations, however a basic configuration should be sufficient for this example. For the purposes of this tutorial we will keep the simulations very, very short (simulation time <1 minute for a single simulation on a typical GPU-enabled computer). "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "01f2bba2-9de3-429b-9d7e-164ce42268bc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mInit signature:\u001b[0m\n",
"\u001b[0mVanillaMDSimulator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0moutput_dir\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpathlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPath\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'md'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mcollision_rate\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveFloat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mopenmm_logname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'openmm_log.tsv'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mopenmm_platform\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0masapdiscovery\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulation\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mOpenMMPlatform\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m<\u001b[0m\u001b[0mOpenMMPlatform\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFastest\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'Fastest'\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mtemperature\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveFloat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m300\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mpressure\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveFloat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mtimestep\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveFloat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mequilibration_steps\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveInt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m5000\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mreporting_interval\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveInt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1250\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mnum_steps\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveInt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2500000\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mrmsd_restraint\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mrmsd_restraint_atom_indices\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mrmsd_restraint_type\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mrmsd_restraint_force_constant\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mpydantic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPositiveFloat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m50\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mtruncate_steps\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0msmall_molecule_force_field\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'openff-2.2.0'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mextra_data\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m Base class for Simulators.\n",
"\u001b[0;31mInit docstring:\u001b[0m\n",
"Create a new model by parsing and validating input data from keyword arguments.\n",
"\n",
"Raises ValidationError if the input data cannot be parsed to form a valid model.\n",
"\u001b[0;31mFile:\u001b[0m ~/Desktop/asap/asapdiscovery/asapdiscovery-simulation/asapdiscovery/simulation/simulate.py\n",
"\u001b[0;31mType:\u001b[0m ModelMetaclass\n",
"\u001b[0;31mSubclasses:\u001b[0m "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"VanillaMDSimulator?"
]
},
{
"cell_type": "markdown",
"id": "7d147029-3074-4736-b714-ceea1182b70a",
"metadata": {},
"source": [
"Let us set up the simulator:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "7686ae2c-8719-4da2-b052-4afc0d10ecfa",
"metadata": {},
"outputs": [],
"source": [
"md_simulator = VanillaMDSimulator(\n",
" output_dir=\"tutorial_files/running_md_simulations/\",\n",
" equilibration_steps=1,\n",
" num_steps=1,\n",
" reporting_interval=1)\n"
]
},
{
"cell_type": "markdown",
"id": "5f8e23cc-a527-428d-81ea-3473facb37ac",
"metadata": {},
"source": [
"To run the simulation, we will pass the output from the docking performed early (saved as `results`) to the `simulation` function of the `VanillaMDSimulation` instance. This will launch a simulation using the [OpenMM simulation package](https://openmm.org/). "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "3ce50c18-473b-4477-bd15-6235976231a9",
"metadata": {},
"outputs": [],
"source": [
"simulation_results = md_simulator.simulate(\n",
" results,\n",
" use_dask=False)"
]
},
{
"cell_type": "markdown",
"id": "16302373-cf89-4052-8c3d-0344061832ea",
"metadata": {},
"source": [
"This function returns a list, where each entry contains an instance of `SimulationResult` corresponding to each of the simulations executed. In this case, we only ran a single simulation, and to query the output we just need to set the index to be 0. For example, let us check to see if the simulation completed successfully:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "8dcca3c1-e5c4-490d-ba95-4846984dadb2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"simulation_results[0].success"
]
},
{
"cell_type": "markdown",
"id": "0fdb4959-21e1-49d7-92b9-aa3a83babca8",
"metadata": {},
"source": [
"The simulator makes unique paths for the resulting simulations, which can be access via the simulation_results output. The pathes that are returned are relevative to the directory where the simulation was launched. Note, future releases will add additional flexibility with regards to simulation output. "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "88fae402-6b2c-4ef1-bf55-22440696913a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tutorial_files/running_md_simulations/SARS2_Mac1A-b27f22555232d2d68273612ffce5a119d6e22526d95ce3eb0db9012632bcdaf6+FHHVXLFEHODNRQ-XCZWEQHLNA-M_alkane-IMNFDUFMRHMDMM-UHFFFAOYNA-N/traj.xtc\n"
]
}
],
"source": [
"print(simulation_results[0].traj_path)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "57c5b975-e5a7-4032-bb01-d3e43935e3ce",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tutorial_files/running_md_simulations/SARS2_Mac1A-b27f22555232d2d68273612ffce5a119d6e22526d95ce3eb0db9012632bcdaf6+FHHVXLFEHODNRQ-XCZWEQHLNA-M_alkane-IMNFDUFMRHMDMM-UHFFFAOYNA-N/final.pdb\n"
]
}
],
"source": [
"print(simulation_results[0].final_pdb_path)"
]
},
{
"cell_type": "markdown",
"id": "8cd655a1-36ec-40ab-be12-f692451b1bf2",
"metadata": {},
"source": [
"## Running multiple simulations in parallel with dask-cuda\n",
"\n",
"We can pass a series of DockingResults to the VanillaMDSimulator and have `dask-cuda` parallelize work over available GPU resources (see [here](https://docs.rapids.ai/api/dask-cuda/nightly/)). \n",
"\n",
"For this we will need a LocalCUDACluster. You will only see parallelism here if you have more than one GPU, e.g on an HPC cluster, otherwise, the simulations will run sequentially. \n",
"\n",
"**NOTE** dask_cuda is not available for `MacOS` computers."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0b0d7c5-9d50-428f-92c7-f5969fb14c81",
"metadata": {},
"outputs": [],
"source": [
"# create a dask_cuda LocalCUDACluster\n",
"from dask_cuda import LocalCUDACluster\n",
"from dask.distributed import Client\n",
"\n",
"cluster = LocalCUDACluster()\n",
"gpu_client = Client(cluster)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b44d9a17-84c8-411c-8466-de540a8970ee",
"metadata": {},
"outputs": [],
"source": [
"# drugforge provides a convenience function to do this\n",
"from drugforge.data.util.dask_utils import DaskType, make_dask_client_meta\n",
"gpu_client = make_dask_client_meta(DaskType.LOCAL_GPU)"
]
},
{
"cell_type": "markdown",
"id": "3820556f-bac6-4a35-b0ac-cee90f0a143f",
"metadata": {},
"source": [
"We can see by inspecting the signature of the `simulate` method that it can accept a `dask` `Client` "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b3b0b63-33f2-45bf-aaa0-c2858df71aed",
"metadata": {},
"outputs": [],
"source": [
"VanillaMDSimulator.simulate?"
]
},
{
"cell_type": "markdown",
"id": "2c5beff9-5b00-45c1-9427-c1d2fbdeaf99",
"metadata": {},
"source": [
"Lets extend the `results` list of inputs so that these could be run in parallel; this will result in 3 simulation instances."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4de2fb8b-56d9-4fe5-9c12-cc39d9c0204b",
"metadata": {},
"outputs": [],
"source": [
"results_par = results + results + results # duplicate X3 "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1722dc2c-f865-46c0-8738-5ca21672d652",
"metadata": {},
"outputs": [],
"source": [
"md_simulator = VanillaMDSimulator(\n",
" output_dir=\"tutorial_files/running_md_simulations/\",\n",
" equilibration_steps=1,\n",
" num_steps=1,\n",
" reporting_interval=1)\n",
"\n",
"simulation_results_parallel = md_simulator.simulate(\n",
" results_par,\n",
" dask_client=gpu_client,\n",
" failure_mode=\"skip\",\n",
" use_dask=True)"
]
},
{
"cell_type": "markdown",
"id": "2d3f7e5a-efb6-4d85-9030-e6265da11a52",
"metadata": {},
"source": [
"The simulation results are stored in a list, where the outputs for each simulation can be accessed in the same way as demonstrated above:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d88a2c1a-a347-48cc-b7c7-d3cadfbbce33",
"metadata": {},
"outputs": [],
"source": [
"for i, sim_result in enumerate(simulation_results_parallel):\n",
" print(f\"simulation {i}: \", sim_result.traj_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3517791-62a6-4416-b1a8-030a6d323355",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "asapdiscovery_v7",
"language": "python",
"name": "asapdiscovery_v7"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}