Notebook04: Use buildH as a module

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.

It is not a proper API but more a way to call buildH inside larger analysis python scripts.

Checking buildH activation

As explained in Notebook01, you should have activated buildH before launching this notebook.

[1]:
import buildh
print(buildh.__version__)
1.6.0

Download data files

We will use the same data files as the ones in Notebook01 : the Berger POPC test case.

[2]:
# Coordinate file
!wget https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/start_128popc.pdb
# Trajectory file
!wget https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/popc0-25ns_dt1000.xtc
# Def file
!wget https://raw.githubusercontent.com/patrickfuchs/buildH/master/def_files/Berger_POPC.def
--2022-01-17 16:11:16--  https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/start_128popc.pdb
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2253759 (2.1M) [text/plain]
Saving to: ‘start_128popc.pdb’

start_128popc.pdb   100%[===================>]   2.15M  --.-KB/s    in 0.05s

2022-01-17 16:11:17 (44.2 MB/s) - ‘start_128popc.pdb’ saved [2253759/2253759]

--2022-01-17 16:11:17--  https://raw.githubusercontent.com/patrickfuchs/buildH/master/docs/Berger_POPC_test_case/popc0-25ns_dt1000.xtc
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2725936 (2.6M) [application/octet-stream]
Saving to: ‘popc0-25ns_dt1000.xtc’

popc0-25ns_dt1000.x 100%[===================>]   2.60M  --.-KB/s    in 0.06s

2022-01-17 16:11:17 (41.9 MB/s) - ‘popc0-25ns_dt1000.xtc’ saved [2725936/2725936]

--2022-01-17 16:11:18--  https://raw.githubusercontent.com/patrickfuchs/buildH/master/def_files/Berger_POPC.def
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2135 (2.1K) [text/plain]
Saving to: ‘Berger_POPC.def’

Berger_POPC.def     100%[===================>]   2.08K  --.-KB/s    in 0s

2022-01-17 16:11:18 (4.54 MB/s) - ‘Berger_POPC.def’ saved [2135/2135]

buildH as a module

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 and api implementation):

[3]:
help(buildh.launch)
Help on function launch in module buildh.UI:

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)
    Launch BuildH calculations.

    This is the only function which can be called inside a Python script to use BuildH as a module.
    It checks the different arguments and call the main function.

    Parameters
    ----------
    coord_file : str
        Coordinate file. Only .pdb and .gro files are currently supported.
    def_file : str
        Order parameter definition file.
    lipid_type : str
        Combinaison of ForceField name and residue name for the lipid to calculate the OP on (e.g. Berger_POPC).
        It must match with the internal topology files or the one(s) supplied.
    traj_file : str, optional
        Trajectory file (could be in XTC, TRR or DCD format), by default None.
    out_file : str, optional
        Output file name for storing order parameters, by default "OP_buildH.out".
    prefix_traj_ouput : str, optional
        Base name for trajectory output with hydrogens.
        File extension will be automatically added.
        By default None.
    begin : int, optional
        The first frame (ps) to read from the trajectory, by default None.
    end : int, optional
        The last frame (ps) to read from the trajectory, by default None.
    lipid_jsons : list, optional
        User topology lipid json file(s), by default None.
    ignore_CH3s: bool, optional
        Ignore CH3s groups for the construction of hydrogens and the calculation of the OP.

    Raises
    ------
    FileNotFoundError
        When either coord_file, def_file or the traj_file is missing.
    TypeError
        When lipid_jsons is not a list.
    BuildHError
        When something went wront during calculation.

Now, we can call launch() with the correct arguments:

[4]:
buildh.launch("start_128popc.pdb", "Berger_POPC.def", "Berger_POPC", traj_file="popc0-25ns_dt1000.xtc", out_file="OP_POPC.dat")
Constructing the system...
System has 28526 atoms
Dealing with frame 0 at 0.0 ps.
Dealing with frame 1 at 1000.0 ps.
Dealing with frame 2 at 2000.0 ps.
Dealing with frame 3 at 3000.0 ps.
Dealing with frame 4 at 4000.0 ps.
Dealing with frame 5 at 5000.0 ps.
Dealing with frame 6 at 6000.0 ps.
Dealing with frame 7 at 7000.0 ps.
Dealing with frame 8 at 8000.0 ps.
Dealing with frame 9 at 9000.0 ps.
Dealing with frame 10 at 10000.0 ps.
Dealing with frame 11 at 11000.0 ps.
Dealing with frame 12 at 12000.0 ps.
Dealing with frame 13 at 13000.0 ps.
Dealing with frame 14 at 14000.0 ps.
Dealing with frame 15 at 15000.0 ps.
Dealing with frame 16 at 16000.0 ps.
Dealing with frame 17 at 17000.0 ps.
Dealing with frame 18 at 18000.0 ps.
Dealing with frame 19 at 19000.0 ps.
Dealing with frame 20 at 20000.0 ps.
Dealing with frame 21 at 21000.0 ps.
Dealing with frame 22 at 22000.0 ps.
Dealing with frame 23 at 23000.0 ps.
Dealing with frame 24 at 24000.0 ps.
Dealing with frame 25 at 25000.0 ps.
Results written to OP_POPC.dat

The order parameters are in OP_POPC.dat.

[5]:
!head OP_POPC.dat
# OP_name            resname atom1 atom2  OP_mean OP_stddev OP_stem
#--------------------------------------------------------------------
gamma1_1             POPC    C1    H11    0.01304  0.12090  0.01069
gamma1_2             POPC    C1    H12    0.00666  0.09279  0.00820
gamma1_3             POPC    C1    H13   -0.01531  0.09141  0.00808
gamma2_1             POPC    C2    H21    0.01511  0.12080  0.01068
gamma2_2             POPC    C2    H22   -0.02050  0.09386  0.00830
gamma2_3             POPC    C2    H23   -0.00660  0.09137  0.00808
gamma3_1             POPC    C3    H31    0.01430  0.11796  0.01043
gamma3_2             POPC    C3    H32   -0.00513  0.08670  0.00766
[6]:
!tail OP_POPC.dat
oleoyl_C14b          POPC    C29   H292  -0.09232  0.08611  0.00761
oleoyl_C15a          POPC    C30   H301  -0.07331  0.08235  0.00728
oleoyl_C15b          POPC    C30   H302  -0.07558  0.08218  0.00726
oleoyl_C16a          POPC    C31   H311  -0.07262  0.08300  0.00734
oleoyl_C16b          POPC    C31   H312  -0.07200  0.08320  0.00735
oleoyl_C17a          POPC    CA1   HA11  -0.04622  0.07990  0.00706
oleoyl_C17b          POPC    CA1   HA12  -0.04141  0.08677  0.00767
oleoyl_C18a          POPC    CA2   HA21   0.03691  0.08420  0.00744
oleoyl_C18b          POPC    CA2   HA22  -0.04603  0.07979  0.00705
oleoyl_C18c          POPC    CA2   HA23  -0.04145  0.08636  0.00763

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.

[7]:
buildh.launch("start_128popc.pdb", "Berger_POPC.def", "Berger_POPC", traj_file="popc0-25ns_dt1000.xtc", out_file="OP_POPC.dat", ignore_CH3s=True)
Constructing the system...
System has 28526 atoms
Building hydrogens and computing order parameters will be skipped on CH3 groups (--ignore-CH3s activated).
Dealing with frame 0 at 0.0 ps.
Dealing with frame 1 at 1000.0 ps.
Dealing with frame 2 at 2000.0 ps.
Dealing with frame 3 at 3000.0 ps.
Dealing with frame 4 at 4000.0 ps.
Dealing with frame 5 at 5000.0 ps.
Dealing with frame 6 at 6000.0 ps.
Dealing with frame 7 at 7000.0 ps.
Dealing with frame 8 at 8000.0 ps.
Dealing with frame 9 at 9000.0 ps.
Dealing with frame 10 at 10000.0 ps.
Dealing with frame 11 at 11000.0 ps.
Dealing with frame 12 at 12000.0 ps.
Dealing with frame 13 at 13000.0 ps.
Dealing with frame 14 at 14000.0 ps.
Dealing with frame 15 at 15000.0 ps.
Dealing with frame 16 at 16000.0 ps.
Dealing with frame 17 at 17000.0 ps.
Dealing with frame 18 at 18000.0 ps.
Dealing with frame 19 at 19000.0 ps.
Dealing with frame 20 at 20000.0 ps.
Dealing with frame 21 at 21000.0 ps.
Dealing with frame 22 at 22000.0 ps.
Dealing with frame 23 at 23000.0 ps.
Dealing with frame 24 at 24000.0 ps.
Dealing with frame 25 at 25000.0 ps.
Results written to OP_POPC.dat
[8]:
!head OP_POPC.dat
# OP_name            resname atom1 atom2  OP_mean OP_stddev OP_stem
#--------------------------------------------------------------------
beta1                POPC    C5    H51    0.04934  0.11999  0.01061
beta2                POPC    C5    H52    0.07162  0.12108  0.01070
alpha1               POPC    C6    H61    0.11839  0.15261  0.01349
alpha2               POPC    C6    H62    0.13903  0.19003  0.01680
g3_1                 POPC    C12   H121  -0.28674  0.09135  0.00807
g3_2                 POPC    C12   H122  -0.16195  0.14832  0.01311
g2_1                 POPC    C13   H131  -0.15159  0.14511  0.01283
g1_1                 POPC    C32   H321   0.21133  0.22491  0.01988
[9]:
!tail OP_POPC.dat
oleoyl_C13a          POPC    C28   H281  -0.09307  0.07657  0.00677
oleoyl_C13b          POPC    C28   H282  -0.08427  0.08647  0.00764
oleoyl_C14a          POPC    C29   H291  -0.09291  0.07618  0.00673
oleoyl_C14b          POPC    C29   H292  -0.09232  0.08611  0.00761
oleoyl_C15a          POPC    C30   H301  -0.07331  0.08235  0.00728
oleoyl_C15b          POPC    C30   H302  -0.07558  0.08218  0.00726
oleoyl_C16a          POPC    C31   H311  -0.07262  0.08300  0.00734
oleoyl_C16b          POPC    C31   H312  -0.07200  0.08320  0.00735
oleoyl_C17a          POPC    CA1   HA11  -0.04622  0.07990  0.00706
oleoyl_C17b          POPC    CA1   HA12  -0.04141  0.08677  0.00767

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).

Conclusion

We showed you quickly how to launch buildH as a Python module which can be convenient in a Jupyter Notebook. If you want to plot the corresponding order parameters, you can have a look to Notebook01.