"Segmentation fault", "std::bad_alloc" and "malloc(): invalid size" when running gmx hbond

GROMACS version: 2023
GROMACS modification: Yes, but hbond has not been touched

Hi, I keep getting ‘low level’ errors when running gmx hbond -life with Gromacs 2023.
When supplying a trajectory generated with a older version I get a note (but no warning or error) and then a segmentation fault, whereas when I supply a trajectory generated with the same version I get either:

-------------------------------------------------------
Program:     gmx hbond, version 2023.1
Memory allocation failed:
std::bad_alloc
For more information and tips for troubleshooting, please check the GROMACS
website at http://www.gromacs.org/Documentation/Errors
-------------------------------------------------------

or simply:

malloc(): invalid size (unsorted)
Aborted (core dumped)

In the last two cases a .xvg file for the h-bond life time distribution is generated, but it’s empty.

I also noticed that in the hbnum.xvg file there are very large negative numbers:

@    title "Hydrogen Bonds"
@    xaxis  label "Time (ps)"
@    yaxis  label "Number"
@TYPE xy
@ view 0.15, 0.15, 0.75, 0.85
@ legend on
@ legend box on
@ legend loctype view
@ legend 0.78, 0.8
@ legend length 2
@ s0 legend "Hydrogen bonds"
@ s1 legend "Pairs within 0.35 nm"
         0  -788421120        1687
      2000       33155        1707
      4000  -788421071        1785
      6000       33160        1829
      8000    25687763        1901
     10000         596        1945
     12000    25687786        1986
     14000         586        1935
     16000         590        2024
     18000         585        1897
     20000         578        1825
     22000         575        1949
     24000         563        1964
     26000         597        1918
     28000         548        1929
     30000         588        1916
     32000         590        1980
     34000         598        2013
     36000         579        2104
     38000         614        2055
     40000         557        2042
     42000         578        2105
     44000         589        2011
     46000         572        1977
     48000         586        1979
     50000         586        1954
     52000         585        2077
     54000         621        2089
     56000         617        2073
     58000         620        2043
     60000         630        2070
     62000         605        2067
     64000         602        2002

Overflow or un-initialized arrays?

Hi Michele,
Thank you for reporting. Maybe a memory allocation problem. I have run some test with the option -num on my local machine. I did not have encounter any error. I did not run any test for -lifetime. Does the option -lifetime work for gmx hbond in GROMACS 2022?

You can report the issue on GitLab or/and test the new implementation of hbond. Note There is working going on to new version of gmx hbond on Gitlab see merge request Merge requests · GROMACS / GROMACS · GitLab
Note that the new tool is called hbond2
It will be great if you could test for your case and give feedback to the authors.
I am not sure that the option -lifetime is implemented, in case it is not I feel that it is important option to have. Please ask if it is possible
Thank you for the help
Alessandra

The arrays for output of gmx hbond were not initialized (!). I fixed this here: Initialize memory in gmx hbond (!3655) · Merge requests · GROMACS / GROMACS · GitLab

But note that gmx hbond prints this note when using the -life option:

Note that the lifetime obtained in this manner is close to useless
Use the -ac option instead and check the Forward lifetime
1 Like

Hi Berk, what do you mean by “it’s close to useless”?

I assume the definition of lifetime that the -life option uses is not very useful. I can’t find any definition in the help text though (which by itself is already an issue).

By the way, -ac was also broken:

Doing autocorrelation according to the theory of Luzar and Chandler.

-------------------------------------------------------
Program:     gmx hbond, version 2023-flow_field-dev
Source file: src/gromacs/correlationfunctions/manyautocorrelation.cpp (line 61)
Function:    int many_auto_correl(std::vector<std::vector<float> >*)

Inconsistency in user input:
Empty vector supplied

For more information and tips for troubleshooting, please check the GROMACS
website at http://www.gromacs.org/Documentation/Errors
-------------------------------------------------------

But I guess this is just because the arrays for output of gmx hbond were not initialized, I’ll try the fixed code.

Indeed, my fix also fixes that.

I also got crazy numbers when I used gmx hbond in 2023.1, like “Average number of hbonds per timeframe -640700.743 out of 2875 possible”. I am running simulations for my study, should I install earlier version to obtain correct results?

Yes, use an older version or if you built from source, overwrite gmx_hbond.cpp in your current source tree with this fixed version and recompile.
https://gitlab.com/gromacs/gromacs/-/raw/f80fcd06bf252a09e9b37b1ef23edc12edd62ea7/src/gromacs/gmxana/gmx_hbond.cpp?inline=false

I seem to still be having this problem. I tried both gmx hbond from Gromacs 2023.3 and gmx hbond-legacy from Gromacs 2025.1 and the output is the same:

Command line:
  gmx hbond-legacy -f md.xtc -s md.tpr -ac

Reading file md.tpr, VERSION 2023.3 (single precision)
Note: file tpx version 129, software tpx version 137
You are going to use a deprecated gmx tool. Please migrate to the new one, gmx hbondSpecify 2 groups to analyze:
Group     0 (         System) has 329231 elements
Group     1 (            RNA) has  4253 elements
Group     2 (             CA) has    10 elements
Group     3 (             CL) has   337 elements
Group     4 (             MG) has     4 elements
Group     5 (             NA) has   441 elements
Group     6 (          Water) has 324186 elements
Group     7 (            SOL) has 324186 elements
Group     8 (      non-Water) has  5045 elements
Group     9 (            Ion) has   792 elements
Group    10 ( Water_and_ions) has 324978 elements
Select a group: 1
Selected 1: 'RNA'
Select a group: 1
Selected 1: 'RNA'
Calculating hydrogen bonds in RNA (4253 atoms)
Found 307 donors and 1431 acceptors
Making hbmap structure...done.
Reading frame       0 time    0.000   
Will do grid-search on 39x39x28 grid, rcut=0.34999999
Segmentation fault (core dumped)

Any advice on if there’s a way to get H-bond lifetimes with recent versions of Gromacs. It looks like the post 2024 hbond doesn’t do lifetime analysis anymore?

It looks like the post 2024 hbond doesn’t do lifetime analysis anymore?

Right now it doesn’t, sadly. I might add that feature later, but right now I’m focused on the nucleic acid analysis tool.