From d5fd2540744026531d91a8a8b16c84142dbaad44 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 21 Feb 2025 15:11:25 +0000 Subject: [PATCH 1/4] Updates RBFE notebook to support cinnabar 0.4.1 --- 04_fep/02_RBFE/02_analysis_rbfe.ipynb | 92 ++++++++++++++++++++------- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/04_fep/02_RBFE/02_analysis_rbfe.ipynb b/04_fep/02_RBFE/02_analysis_rbfe.ipynb index 783ee13..46442ba 100644 --- a/04_fep/02_RBFE/02_analysis_rbfe.ipynb +++ b/04_fep/02_RBFE/02_analysis_rbfe.ipynb @@ -93,6 +93,7 @@ "outputs": [], "source": [ "from get_tutorial import download\n", + "\n", "download(\"02\")" ] }, @@ -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", @@ -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", @@ -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", @@ -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" ] }, { @@ -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", + " )" ] }, { @@ -737,7 +773,7 @@ "Exercise 2.1.1: Excluding intermediates from the Network analysis\n", "\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" ] }, { @@ -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", "" @@ -924,11 +968,16 @@ "
Click here to see solution to Exercise. \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", @@ -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": { From fdc42f5ab0cd9592ba509ca19a8eb35edce5cb50 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 21 Feb 2025 15:14:49 +0000 Subject: [PATCH 2/4] Update README to new cinnabar version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07c11f7..36a8125 100644 --- a/README.md +++ b/README.md @@ -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 From b142b50b7461be39acb6e77aa3b9601356156af6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 21 Feb 2025 16:03:09 +0000 Subject: [PATCH 3/4] Updates CollectiveVariable.RMSD to new API --- 03_steered_md/01_setup_sMD.ipynb | 39 +++++++++++--------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/03_steered_md/01_setup_sMD.ipynb b/03_steered_md/01_setup_sMD.ipynb index 7c85190..dbd58f1 100644 --- a/03_steered_md/01_setup_sMD.ipynb +++ b/03_steered_md/01_setup_sMD.ipynb @@ -128,6 +128,7 @@ "outputs": [], "source": [ "from get_tutorial import download\n", + "\n", "download(\"01\")" ] }, @@ -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\")" ] }, { @@ -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", + " \"residx 178:185 and not element H\",\n", + " \"residx 178:185 and not element H\",\n", + " reference_mapping={0: 0},\n", + ")" ] }, { @@ -336,9 +328,7 @@ "metadata": {}, "outputs": [], "source": [ - "process = BSS.Process.Gromacs(\n", - " system,\n", - " protocol)" + "process = BSS.Process.Gromacs(system, protocol)" ] }, { @@ -390,8 +380,7 @@ "metadata": {}, "outputs": [], "source": [ - "process = BSS.Process.Amber(\n", - " system, protocol)" + "process = BSS.Process.Amber(system, protocol)" ] }, { @@ -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)" ] }, { @@ -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": { From 9b59d852e4e23788bab38edf2887735056a47c53 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 24 Feb 2025 16:25:25 +0000 Subject: [PATCH 4/4] Updates to be consistent with older versions. --- 03_steered_md/01_setup_sMD.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03_steered_md/01_setup_sMD.ipynb b/03_steered_md/01_setup_sMD.ipynb index dbd58f1..b9d4358 100644 --- a/03_steered_md/01_setup_sMD.ipynb +++ b/03_steered_md/01_setup_sMD.ipynb @@ -214,7 +214,7 @@ "rmsd_cv = BSS.Metadynamics.CollectiveVariable.RMSD(\n", " system,\n", " reference,\n", - " \"residx 178:185 and not element H\",\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", ")"