{ "cells": [ { "cell_type": "markdown", "id": "aaad01f1", "metadata": {}, "source": [ "# Notebook04: Use **buildH** as a module\n", "\n", "**buildH** is intended to be used mainly in the Unix command line but also as a module to a lesser extent. The features available are minimal: you can just call the main function of **buildH** and result files will be written. \n", "\n", "It is not a proper API but more a way to call **buildH** inside larger analysis python scripts." ] }, { "cell_type": "markdown", "id": "bdd9fbac", "metadata": {}, "source": [ "## Checking **buildH** activation\n", "\n", "As explained in [Notebook01](Notebook_01_buildH_calc_OP.ipynb), you should have activated **buildH** before launching this notebook." ] }, { "cell_type": "code", "execution_count": 1, "id": "6bba0a5d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.6.0\n" ] } ], "source": [ "import buildh\n", "print(buildh.__version__)" ] }, { "cell_type": "markdown", "id": "8e916cd3", "metadata": {}, "source": [ "## Download data files\n", "\n", "We will use the same data files as the ones in [Notebook01](Notebook_01_buildH_calc_OP.ipynb) : the Berger POPC test case." ] }, { "cell_type": "code", "execution_count": 2, "id": "d24f4d65", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--2022-01-17 16:11:16-- https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/start_128popc.pdb\n", "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...\n", "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 2253759 (2.1M) [text/plain]\n", "Saving to: ‘start_128popc.pdb’\n", "\n", "start_128popc.pdb 100%[===================>] 2.15M --.-KB/s in 0.05s \n", "\n", "2022-01-17 16:11:17 (44.2 MB/s) - ‘start_128popc.pdb’ saved [2253759/2253759]\n", "\n", "--2022-01-17 16:11:17-- https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/popc0-25ns_dt1000.xtc\n", "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n", "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 2725936 (2.6M) [application/octet-stream]\n", "Saving to: ‘popc0-25ns_dt1000.xtc’\n", "\n", "popc0-25ns_dt1000.x 100%[===================>] 2.60M --.-KB/s in 0.06s \n", "\n", "2022-01-17 16:11:17 (41.9 MB/s) - ‘popc0-25ns_dt1000.xtc’ saved [2725936/2725936]\n", "\n", "--2022-01-17 16:11:18-- https://raw.githubusercontent.com/patrickfuchs/buildH/master/def_files/Berger_POPC.def\n", "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...\n", "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 2135 (2.1K) [text/plain]\n", "Saving to: ‘Berger_POPC.def’\n", "\n", "Berger_POPC.def 100%[===================>] 2.08K --.-KB/s in 0s \n", "\n", "2022-01-17 16:11:18 (4.54 MB/s) - ‘Berger_POPC.def’ saved [2135/2135]\n", "\n" ] } ], "source": [ "# Coordinate file\n", "!wget https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/start_128popc.pdb\n", "# Trajectory file\n", "!wget https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/popc0-25ns_dt1000.xtc\n", "# Def file\n", "!wget https://raw.githubusercontent.com/patrickfuchs/buildH/master/def_files/Berger_POPC.def" ] }, { "cell_type": "markdown", "id": "449e468e", "metadata": {}, "source": [ "## **buildH** as a module\n", "\n", "The only function accessible is the main one of **buildH**: `buildh.launch()`. It has the same arguments than the **buildH** command line (see [Command line options](../command_line_options.md) and [api implementation](../api/UI.rst#buildh.UI.launch)):" ] }, { "cell_type": "code", "execution_count": 3, "id": "fe0ba2a1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function launch in module buildh.UI:\n", "\n", "launch(coord_file, def_file, lipid_type, traj_file=None, out_file='OP_buildH.out', prefix_traj_ouput=None, begin=None, end=None, lipid_jsons=None, ignore_CH3s=False)\n", " Launch BuildH calculations.\n", " \n", " This is the only function which can be called inside a Python script to use BuildH as a module.\n", " It checks the different arguments and call the main function.\n", " \n", " Parameters\n", " ----------\n", " coord_file : str\n", " Coordinate file. Only .pdb and .gro files are currently supported.\n", " def_file : str\n", " Order parameter definition file.\n", " lipid_type : str\n", " Combinaison of ForceField name and residue name for the lipid to calculate the OP on (e.g. Berger_POPC).\n", " It must match with the internal topology files or the one(s) supplied.\n", " traj_file : str, optional\n", " Trajectory file (could be in XTC, TRR or DCD format), by default None.\n", " out_file : str, optional\n", " Output file name for storing order parameters, by default \"OP_buildH.out\".\n", " prefix_traj_ouput : str, optional\n", " Base name for trajectory output with hydrogens.\n", " File extension will be automatically added.\n", " By default None.\n", " begin : int, optional\n", " The first frame (ps) to read from the trajectory, by default None.\n", " end : int, optional\n", " The last frame (ps) to read from the trajectory, by default None.\n", " lipid_jsons : list, optional\n", " User topology lipid json file(s), by default None.\n", " ignore_CH3s: bool, optional\n", " Ignore CH3s groups for the construction of hydrogens and the calculation of the OP.\n", " \n", " Raises\n", " ------\n", " FileNotFoundError\n", " When either coord_file, def_file or the traj_file is missing.\n", " TypeError\n", " When lipid_jsons is not a list.\n", " BuildHError\n", " When something went wront during calculation.\n", "\n" ] } ], "source": [ "help(buildh.launch)" ] }, { "cell_type": "markdown", "id": "5182f163", "metadata": {}, "source": [ "Now, we can call `launch()` with the correct arguments:" ] }, { "cell_type": "code", "execution_count": 4, "id": "7bcf8327", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Constructing the system...\n", "System has 28526 atoms\n", "Dealing with frame 0 at 0.0 ps.\n", "Dealing with frame 1 at 1000.0 ps.\n", "Dealing with frame 2 at 2000.0 ps.\n", "Dealing with frame 3 at 3000.0 ps.\n", "Dealing with frame 4 at 4000.0 ps.\n", "Dealing with frame 5 at 5000.0 ps.\n", "Dealing with frame 6 at 6000.0 ps.\n", "Dealing with frame 7 at 7000.0 ps.\n", "Dealing with frame 8 at 8000.0 ps.\n", "Dealing with frame 9 at 9000.0 ps.\n", "Dealing with frame 10 at 10000.0 ps.\n", "Dealing with frame 11 at 11000.0 ps.\n", "Dealing with frame 12 at 12000.0 ps.\n", "Dealing with frame 13 at 13000.0 ps.\n", "Dealing with frame 14 at 14000.0 ps.\n", "Dealing with frame 15 at 15000.0 ps.\n", "Dealing with frame 16 at 16000.0 ps.\n", "Dealing with frame 17 at 17000.0 ps.\n", "Dealing with frame 18 at 18000.0 ps.\n", "Dealing with frame 19 at 19000.0 ps.\n", "Dealing with frame 20 at 20000.0 ps.\n", "Dealing with frame 21 at 21000.0 ps.\n", "Dealing with frame 22 at 22000.0 ps.\n", "Dealing with frame 23 at 23000.0 ps.\n", "Dealing with frame 24 at 24000.0 ps.\n", "Dealing with frame 25 at 25000.0 ps.\n", "Results written to OP_POPC.dat\n" ] } ], "source": [ "buildh.launch(\"start_128popc.pdb\", \"Berger_POPC.def\", \"Berger_POPC\", traj_file=\"popc0-25ns_dt1000.xtc\", out_file=\"OP_POPC.dat\")" ] }, { "cell_type": "markdown", "id": "73eb869f", "metadata": {}, "source": [ "The order parameters are in `OP_POPC.dat`." ] }, { "cell_type": "code", "execution_count": 5, "id": "2382ae27", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# OP_name resname atom1 atom2 OP_mean OP_stddev OP_stem\n", "#--------------------------------------------------------------------\n", "gamma1_1 POPC C1 H11 0.01304 0.12090 0.01069\n", "gamma1_2 POPC C1 H12 0.00666 0.09279 0.00820\n", "gamma1_3 POPC C1 H13 -0.01531 0.09141 0.00808\n", "gamma2_1 POPC C2 H21 0.01511 0.12080 0.01068\n", "gamma2_2 POPC C2 H22 -0.02050 0.09386 0.00830\n", "gamma2_3 POPC C2 H23 -0.00660 0.09137 0.00808\n", "gamma3_1 POPC C3 H31 0.01430 0.11796 0.01043\n", "gamma3_2 POPC C3 H32 -0.00513 0.08670 0.00766\n" ] } ], "source": [ "!head OP_POPC.dat" ] }, { "cell_type": "code", "execution_count": 6, "id": "7b8ee3bc-bc28-4ccf-b008-04b14c463b6e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "oleoyl_C14b POPC C29 H292 -0.09232 0.08611 0.00761\n", "oleoyl_C15a POPC C30 H301 -0.07331 0.08235 0.00728\n", "oleoyl_C15b POPC C30 H302 -0.07558 0.08218 0.00726\n", "oleoyl_C16a POPC C31 H311 -0.07262 0.08300 0.00734\n", "oleoyl_C16b POPC C31 H312 -0.07200 0.08320 0.00735\n", "oleoyl_C17a POPC CA1 HA11 -0.04622 0.07990 0.00706\n", "oleoyl_C17b POPC CA1 HA12 -0.04141 0.08677 0.00767\n", "oleoyl_C18a POPC CA2 HA21 0.03691 0.08420 0.00744\n", "oleoyl_C18b POPC CA2 HA22 -0.04603 0.07979 0.00705\n", "oleoyl_C18c POPC CA2 HA23 -0.04145 0.08636 0.00763\n" ] } ], "source": [ "!tail OP_POPC.dat" ] }, { "cell_type": "markdown", "id": "f5fef207-cc18-4f62-9c8e-af38e4f0bb16", "metadata": {}, "source": [ "Here is another example where we use the option `ignore_CH3s`, which does not output the order parameters of methyl (CH3) groups even if they are present in the def file." ] }, { "cell_type": "code", "execution_count": 7, "id": "17515a96-5b61-4538-bdaf-ae8a33773f17", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Constructing the system...\n", "System has 28526 atoms\n", "Building hydrogens and computing order parameters will be skipped on CH3 groups (--ignore-CH3s activated).\n", "Dealing with frame 0 at 0.0 ps.\n", "Dealing with frame 1 at 1000.0 ps.\n", "Dealing with frame 2 at 2000.0 ps.\n", "Dealing with frame 3 at 3000.0 ps.\n", "Dealing with frame 4 at 4000.0 ps.\n", "Dealing with frame 5 at 5000.0 ps.\n", "Dealing with frame 6 at 6000.0 ps.\n", "Dealing with frame 7 at 7000.0 ps.\n", "Dealing with frame 8 at 8000.0 ps.\n", "Dealing with frame 9 at 9000.0 ps.\n", "Dealing with frame 10 at 10000.0 ps.\n", "Dealing with frame 11 at 11000.0 ps.\n", "Dealing with frame 12 at 12000.0 ps.\n", "Dealing with frame 13 at 13000.0 ps.\n", "Dealing with frame 14 at 14000.0 ps.\n", "Dealing with frame 15 at 15000.0 ps.\n", "Dealing with frame 16 at 16000.0 ps.\n", "Dealing with frame 17 at 17000.0 ps.\n", "Dealing with frame 18 at 18000.0 ps.\n", "Dealing with frame 19 at 19000.0 ps.\n", "Dealing with frame 20 at 20000.0 ps.\n", "Dealing with frame 21 at 21000.0 ps.\n", "Dealing with frame 22 at 22000.0 ps.\n", "Dealing with frame 23 at 23000.0 ps.\n", "Dealing with frame 24 at 24000.0 ps.\n", "Dealing with frame 25 at 25000.0 ps.\n", "Results written to OP_POPC.dat\n" ] } ], "source": [ "buildh.launch(\"start_128popc.pdb\", \"Berger_POPC.def\", \"Berger_POPC\", traj_file=\"popc0-25ns_dt1000.xtc\", out_file=\"OP_POPC.dat\", ignore_CH3s=True)" ] }, { "cell_type": "code", "execution_count": 8, "id": "6684e5a1-7c7c-442e-8c9a-aa92b8c9694c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# OP_name resname atom1 atom2 OP_mean OP_stddev OP_stem\n", "#--------------------------------------------------------------------\n", "beta1 POPC C5 H51 0.04934 0.11999 0.01061\n", "beta2 POPC C5 H52 0.07162 0.12108 0.01070\n", "alpha1 POPC C6 H61 0.11839 0.15261 0.01349\n", "alpha2 POPC C6 H62 0.13903 0.19003 0.01680\n", "g3_1 POPC C12 H121 -0.28674 0.09135 0.00807\n", "g3_2 POPC C12 H122 -0.16195 0.14832 0.01311\n", "g2_1 POPC C13 H131 -0.15159 0.14511 0.01283\n", "g1_1 POPC C32 H321 0.21133 0.22491 0.01988\n" ] } ], "source": [ "!head OP_POPC.dat" ] }, { "cell_type": "code", "execution_count": 9, "id": "b235cc03-cf75-4f9f-80d8-4619ec0c6c64", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "oleoyl_C13a POPC C28 H281 -0.09307 0.07657 0.00677\n", "oleoyl_C13b POPC C28 H282 -0.08427 0.08647 0.00764\n", "oleoyl_C14a POPC C29 H291 -0.09291 0.07618 0.00673\n", "oleoyl_C14b POPC C29 H292 -0.09232 0.08611 0.00761\n", "oleoyl_C15a POPC C30 H301 -0.07331 0.08235 0.00728\n", "oleoyl_C15b POPC C30 H302 -0.07558 0.08218 0.00726\n", "oleoyl_C16a POPC C31 H311 -0.07262 0.08300 0.00734\n", "oleoyl_C16b POPC C31 H312 -0.07200 0.08320 0.00735\n", "oleoyl_C17a POPC CA1 HA11 -0.04622 0.07990 0.00706\n", "oleoyl_C17b POPC CA1 HA12 -0.04141 0.08677 0.00767\n" ] } ], "source": [ "!tail OP_POPC.dat" ] }, { "cell_type": "markdown", "id": "f4684eac-fe70-4208-a65a-dfcde8772b20", "metadata": {}, "source": [ "We can see that all order parameters belonging to methyl (CH3) groups are not present in the output file `OP_POPC.dat` (such as those from gamma_* or oleoyl_C18 carbon atoms).\n", "\n", "## Conclusion\n", "\n", "We showed you quickly how to launch **buildH** as a Python module which can be convenient in a Jupyter Notebook.\n", "If you want to plot the corresponding order parameters, you can have a look to Notebook01." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.11" } }, "nbformat": 4, "nbformat_minor": 5 }