Skip to content

Fixes for steered MD tutorial and update to RBFE tutorial #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 13 additions & 26 deletions 03_steered_md/01_setup_sMD.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"outputs": [],
"source": [
"from get_tutorial import download\n",
"\n",
"download(\"01\")"
]
},
Expand Down Expand Up @@ -200,22 +201,7 @@
"metadata": {},
"outputs": [],
"source": [
"reference = BSS.IO.readMolecules(\"data/reference.pdb\").getMolecule(0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9f45911c",
"metadata": {},
"outputs": [],
"source": [
"rmsd_indices = []\n",
"for residue in reference.getResidues():\n",
" if 178 <= residue.index() <= 184:\n",
" for atom in residue.getAtoms():\n",
" if atom.element() != \"Hydrogen (H, 1)\":\n",
" rmsd_indices.append(atom.index())"
"reference = BSS.IO.readMolecules(\"data/reference.pdb\")"
]
},
{
Expand All @@ -225,7 +211,13 @@
"metadata": {},
"outputs": [],
"source": [
"rmsd_cv = BSS.Metadynamics.CollectiveVariable.RMSD(system, reference, rmsd_indices)"
"rmsd_cv = BSS.Metadynamics.CollectiveVariable.RMSD(\n",
" system,\n",
" reference,\n",
" \"molidx 0 and (not residx 178:185) and (not element H)\",\n",
" \"residx 178:185 and not element H\",\n",
" reference_mapping={0: 0},\n",
")"
]
},
{
Expand Down Expand Up @@ -336,9 +328,7 @@
"metadata": {},
"outputs": [],
"source": [
"process = BSS.Process.Gromacs(\n",
" system,\n",
" protocol)"
"process = BSS.Process.Gromacs(system, protocol)"
]
},
{
Expand Down Expand Up @@ -390,8 +380,7 @@
"metadata": {},
"outputs": [],
"source": [
"process = BSS.Process.Amber(\n",
" system, protocol)"
"process = BSS.Process.Amber(system, protocol)"
]
},
{
Expand Down Expand Up @@ -617,8 +606,7 @@
"outputs": [],
"source": [
"# pass exe=f'{os.environ[\"AMBERHOME\"]}/bin/pmemd.cuda to use the faster MD engine pmemd\n",
"process = BSS.Process.Amber(\n",
" system, protocol)"
"process = BSS.Process.Amber(system, protocol)"
]
},
{
Expand Down Expand Up @@ -696,8 +684,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"pygments_lexer": "ipython3"
},
"vscode": {
"interpreter": {
Expand Down
92 changes: 70 additions & 22 deletions 04_fep/02_RBFE/02_analysis_rbfe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"outputs": [],
"source": [
"from get_tutorial import download\n",
"\n",
"download(\"02\")"
]
},
Expand Down Expand Up @@ -221,7 +222,9 @@
" new_file_name = f\"analysis/outputs/results_{results_all_files.index(file)}.csv\"\n",
" with open(new_file_name, \"w\") as result_file:\n",
" writer = csv.writer(result_file, delimiter=\",\")\n",
" writer.writerow([\"lig_1\", \"lig_2\", \"freenrg(kcal/mol)\", \"error(kcal/mol)\", \"engine\"])\n",
" writer.writerow(\n",
" [\"lig_1\", \"lig_2\", \"freenrg(kcal/mol)\", \"error(kcal/mol)\", \"engine\"]\n",
" )\n",
"\n",
" for row, index in pd.read_csv(file).iterrows():\n",
" pert = f\"{index['lig_1']}~{index['lig_2']}\"\n",
Expand Down Expand Up @@ -290,7 +293,9 @@
"# write these to a csv file\n",
"with open(\"analysis/outputs/computed_perturbations_average.csv\", \"w\") as comp_pert_file:\n",
" writer = csv.writer(comp_pert_file, delimiter=\",\")\n",
" writer.writerow([\"lig_1\", \"lig_2\", \"freenrg(kcal/mol)\", \"error(kcal/mol)\", \"engine\"])\n",
" writer.writerow(\n",
" [\"lig_1\", \"lig_2\", \"freenrg(kcal/mol)\", \"error(kcal/mol)\", \"engine\"]\n",
" )\n",
" for pert in perturbations:\n",
" ddGs = comp_dict_list[pert]\n",
" lig_0 = pert.split(\"~\")[0]\n",
Expand Down Expand Up @@ -360,7 +365,9 @@
"# write these to a csv file\n",
"with open(\"analysis/outputs/experimental_perturbations.csv\", \"w\") as exp_pert_file:\n",
" writer = csv.writer(exp_pert_file, delimiter=\",\")\n",
" writer.writerow([\"lig_1\", \"lig_2\", \"freenrg(kcal/mol)\", \"error(kcal/mol)\", \"engine\"])\n",
" writer.writerow(\n",
" [\"lig_1\", \"lig_2\", \"freenrg(kcal/mol)\", \"error(kcal/mol)\", \"engine\"]\n",
" )\n",
"\n",
" for pert in perturbations:\n",
" lig_0 = pert.split(\"~\")[0]\n",
Expand Down Expand Up @@ -527,7 +534,15 @@
"metadata": {},
"outputs": [],
"source": [
"from cinnabar import wrangle, plotting"
"# Import cinnbar, API changes depending on version\n",
"try:\n",
" from cinnabar import wrangle, plotting\n",
"\n",
" cinnabar_is_old = True\n",
"except:\n",
" from cinnabar import FEMap, plotting\n",
"\n",
" cinnabar_is_old = False"
]
},
{
Expand Down Expand Up @@ -644,11 +659,32 @@
"metadata": {},
"outputs": [],
"source": [
"network = wrangle.FEMap(f\"analysis/outputs/cinnabar_data.csv\")\n",
"# plot the perturbations\n",
"plotting.plot_DDGs(network.graph, title=\"DDGs\", filename=f\"analysis/outputs/DDGs.png\", figsize=6)\n",
"# plot the ligands\n",
"plotting.plot_DGs(network.graph, title=\"DGs\", filename=f\"analysis/outputs/DGs.png\", figsize=6)"
"if cinnabar_is_old:\n",
" network = wrangle.FEMap(f\"analysis/outputs/cinnabar_data.csv\")\n",
" # plot the perturbations\n",
" plotting.plot_DDGs(\n",
" network.graph, title=\"DDGs\", filename=f\"analysis/outputs/DDGs.png\", figsize=6\n",
" )\n",
" # plot the ligands\n",
" plotting.plot_DGs(\n",
" network.graph, title=\"DGs\", filename=f\"analysis/outputs/DGs.png\", figsize=6\n",
" )\n",
"else:\n",
" network = FEMap.from_csv(f\"analysis/outputs/cinnabar_data.csv\")\n",
" # plot the perturbations\n",
" plotting.plot_DDGs(\n",
" network.to_legacy_graph(),\n",
" title=\"DDGs\",\n",
" filename=f\"analysis/outputs/DDGs.png\",\n",
" figsize=6,\n",
" )\n",
" # plot the ligands\n",
" plotting.plot_DGs(\n",
" network.to_legacy_graph(),\n",
" title=\"DGs\",\n",
" filename=f\"analysis/outputs/DGs.png\",\n",
" figsize=6,\n",
" )"
]
},
{
Expand Down Expand Up @@ -737,7 +773,7 @@
"<b>Exercise 2.1.1: Excluding intermediates from the Network analysis</b>\n",
"</div>\n",
"\n",
"Try exculding this perturbation and rerunning the above Network analysis. First, we need to remove the perturbation. Then, we need to make sure that our new output image is being saved using a different file path. Adjust these in the cells below where the #FIXME is. \n"
"Try excluding this perturbation and rerunning the above Network analysis. First, we need to remove the perturbation. Then, we need to make sure that our new output image is being saved using a different file path. Adjust these in the cells below where the #FIXME is. \n"
]
},
{
Expand Down Expand Up @@ -876,11 +912,19 @@
" if pert in perturbations:\n",
" writer.writerow([lig_0, lig_1, comp_ddG, comp_err, \"0.0\"])\n",
"\n",
"network = wrangle.FEMap(f\"analysis/outputs/cinnabar_data_outliers_removed.csv\")\n",
"# plot the perturbations\n",
"plotting.plot_DDGs(network.graph, title=\"DDGs\", filename=f\"analysis/outputs/DDGs_outliers_removed.png\", figsize=6)\n",
"# plot the ligands\n",
"plotting.plot_DGs(network.graph, title=\"DGs\", filename=f\"analysis/outputs/DGs_outliers_removed.png\", figsize=6)\n",
"if cinnabar_is_old:\n",
" network = wrangle.FEMap(f\"analysis/outputs/cinnabar_data_outliers_removed.csv\")\n",
" # plot the perturbations\n",
" plotting.plot_DDGs(network.graph, title=\"DDGs\", filename=f\"analysis/outputs/DDGs_outliers_removed.png\", figsize=6)\n",
" # plot the ligands\n",
" plotting.plot_DGs(network.graph, title=\"DGs\", filename=f\"analysis/outputs/DGs_outliers_removed.png\", figsize=6)\n",
"else:\n",
" network = FEMap.from_csv(f\"analysis/outputs/cinnabar_data_outliers_removed.csv\")\n",
" # plot the perturbations\n",
" plotting.plot_DDGs(network.to_legacy_graph(), title=\"DDGs\", filename=f\"analysis/outputs/DDGs_outliers_removed.png\", figsize=6)\n",
" # plot the ligands\n",
" plotting.plot_DGs(network.to_legacy_graph(), title=\"DGs\", filename=f\"analysis/outputs/DGs_outliers_removed.png\", figsize=6)\n",
"\n",
"```\n",
"\n",
"</details>"
Expand Down Expand Up @@ -924,11 +968,16 @@
"<details><summary {style='color:green;font-weight:bold'}> Click here to see solution to Exercise. </summary>\n",
"\n",
"```python\n",
"\n",
"lig_dict = {entry[1]['name']:entry[1]['calc_DG'] for entry in network.graph.nodes.data()}\n",
"lig_df = pd.DataFrame.from_dict(lig_dict, orient=\"index\", columns=[\"calc_DG\"])\n",
"lig_df.to_csv(\"analysis/outputs/ligand_calc_DG.csv\")\n",
"lig_df.sort_values(\"calc_DG\")\n",
"if cinnabar_is_old:\n",
" lig_dict = {entry[1]['name']:entry[1]['calc_DG'] for entry in network.graph.nodes.data()}\n",
" lig_df = pd.DataFrame.from_dict(lig_dict, orient=\"index\", columns=[\"calc_DG\"])\n",
" lig_df.to_csv(\"analysis/outputs/ligand_calc_DG.csv\")\n",
" lig_df.sort_values(\"calc_DG\")\n",
"else:\n",
" lig_dict = {entry[0]:entry[1]['calc_DG'] for entry in network.to_legacy_graph().nodes.data()}\n",
" lig_df = pd.DataFrame.from_dict(lig_dict, orient=\"index\", columns=[\"calc_DG\"])\n",
" lig_df.to_csv(\"analysis/outputs/ligand_calc_DG.csv\")\n",
" lig_df.sort_values(\"calc_DG\")\n",
"\n",
"```\n",
"\n",
Expand Down Expand Up @@ -978,8 +1027,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"pygments_lexer": "ipython3"
},
"varInspector": {
"cols": {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ These tutorials have been tested with BioSimSpace 2023.5.0 on a linux-64 platfor
* Gromacs (tested with 2023.1)
* AmberTools (tested with 23.3)
* PLUMED (tested with 2.9.0)
* cinnabar (tested with 0.3.0)
* cinnabar (tested with 0.4.1)
* alchemlyb (tested with 1.0.1)

# Installation instructions
Expand Down