Skip to content

Commit

Permalink
added raw data analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
simongravelle committed Jan 1, 2024
1 parent 9b38219 commit 23092fe
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 0 deletions.
61 changes: 61 additions & 0 deletions examples/illustrations/lysozyme-in-water.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/simon/.local/lib/python3.11/site-packages/MDAnalysis/topology/TPRParser.py:161: DeprecationWarning: 'xdrlib' is deprecated and slated for removal in Python 3.13\n",
" import xdrlib\n"
]
}
],
"source": [
"import numpy as np\n",
"import MDAnalysis as mda\n",
"import nmrformd as nmrmd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys, os, git\n",
"current_path = os.getcwd()\n",
"git_repo = git.Repo(current_path, search_parent_directories=True)\n",
"git_path = git_repo.git.rev_parse(\"--show-toplevel\")\n",
"sys.path.append(git_path+\"/examples/pyplot-perso/\")\n",
"from color_series1 import colors\n",
"from functions import complete_panel, save_figure, set_boundaries, add_subplotlabels, set_boundaries\n",
"path_figures = \"/docs/source/figures/illustrations/lysozyme-in-water/\""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
146 changes: 146 additions & 0 deletions examples/illustrations/lysozyme-in-water/analysis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import MDAnalysis as mda\n",
"import nmrformd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys, os, git\n",
"current_path = os.getcwd()\n",
"git_repo = git.Repo(current_path, search_parent_directories=True)\n",
"git_path = git_repo.git.rev_parse(\"--show-toplevel\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def save_result(data, name = \"intra_H2O\"):\n",
" \"\"\"Save the correlation functions in dictionary\"\"\"\n",
" if not os.path.exists(\"raw_data/\"):\n",
" os.makedirs(\"raw_data/\")\n",
" saving_file = \"raw_data/\" + name + \".npy\"\n",
" t = data.t\n",
" f = data.f\n",
" C = data.gij[0]\n",
" R1 = data.R1\n",
" R2 = data.R2\n",
" N = data.group_j.atoms.n_atoms\n",
" try:\n",
" previous_dictionary = np.load(saving_file, allow_pickle=True)\n",
" t_prev = np.real(previous_dictionary.item()[\"t\"])\n",
" assert len(t_prev) == len(t)\n",
" C_prev = np.real(previous_dictionary.item()[\"C\"])\n",
" R1_prev = np.real(previous_dictionary.item()[\"R1\"])\n",
" R2_prev = np.real(previous_dictionary.item()[\"R2\"])\n",
" N_prev = np.real(previous_dictionary.item()[\"N\"])\n",
" C = (C*N + C_prev*N_prev) / (N_prev + N)\n",
" R1 = (R1*N + R1_prev*N_prev) / (N_prev + N)\n",
" R2 = (R2*N + R2_prev*N_prev) / (N_prev + N)\n",
" N += N_prev\n",
" except:\n",
" pass\n",
" dictionary = {\n",
" \"t\": t,\n",
" \"f\": f,\n",
" \"C\": C,\n",
" \"N\": N,\n",
" \"R1\": R1,\n",
" \"R2\": R2,\n",
" }\n",
" np.save(saving_file, dictionary)\n",
" return N"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"folder = git_path + \"/nmrformd-data/HEWL-in-water/raw-data/water-to-protein-0.73/\"\n",
"tpr = folder+\"prod.tpr\"\n",
"all_xtc = [folder+\"prod1.xtc\",\n",
" folder+\"prod2.xtc\",\n",
" folder+\"prod3.xtc\",\n",
" folder+\"prod4.xtc\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"u = mda.Universe(tpr, all_xtc)\n",
"# isolate the hydrogen from water and from the protein\n",
"H2O = u.select_atoms(\"name HW1 HW2\")\n",
"HEWL = u.select_atoms(\"\")\n",
"for name in np.unique(u.atoms.names):\n",
" if (name[0] == \"H\") & (name != \"HW1\") & (name != \"HW2\"):\n",
" HEWL += u.select_atoms(\"name \"+name)\n",
"ALL = H2O + HEWL\n",
"while 1 < 2:\n",
" # H2O-H2O\n",
" intra_H2O = nmrformd.NMR(u, atom_group=H2O, neighbor_group=H2O, type_analysis=\"intra_molecular\", number_i=1)\n",
" inter_H2O = nmrformd.NMR(u, atom_group=H2O, neighbor_group=H2O, type_analysis=\"inter_molecular\", number_i=1)\n",
" full_H2O = nmrformd.NMR(u, atom_group=H2O, neighbor_group=H2O, number_i=1)\n",
" # HEWL-HEWL\n",
" intra_HEWL = nmrformd.NMR(u, atom_group=HEWL, neighbor_group=HEWL, type_analysis=\"intra_molecular\", number_i=1)\n",
" inter_HEWL = nmrformd.NMR(u, atom_group=HEWL, neighbor_group=HEWL, type_analysis=\"inter_molecular\", number_i=1)\n",
" full_HEWL = nmrformd.NMR(u, atom_group=HEWL, neighbor_group=HEWL, number_i=1)\n",
" # H2O-HEWL\n",
" inter_H2O_HEWL = nmrformd.NMR(u, atom_group=H2O, neighbor_group=HEWL, number_i=1)\n",
" inter_HEWL_H2O = nmrformd.NMR(u, atom_group=HEWL, neighbor_group=H2O, number_i=1)\n",
" # FULL\n",
" FULL = nmrformd.NMR(u, atom_group=ALL, neighbor_group=ALL, number_i=1)\n",
" # save_results\n",
" N = save_result(intra_H2O, name = \"intra_H2O\")\n",
" print(\"Number of cycle:\", N)\n",
" N = save_result(inter_H2O, name = \"inter_H2O\")\n",
" N = save_result(full_H2O, name = \"full_H2O\")\n",
" N = save_result(intra_HEWL, name = \"intra_HEWL\")\n",
" N = save_result(inter_HEWL, name = \"inter_HEWL\")\n",
" N = save_result(full_HEWL, name = \"full_HEWL\")\n",
" N = save_result(inter_H2O_HEWL, name = \"inter_H2O_HEWL\")\n",
" N = save_result(inter_HEWL_H2O, name = \"inter_HEWL_H2O\")\n",
" N = save_result(FULL, name = \"FULL\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 23092fe

Please sign in to comment.