<!-- https://docs.dseams.info/user/tutorials/hydrogen-bonds.md -->

# Hydrogen bonds in water {#hydrogen-bonds-in-water}

Count hydrogen-bonded water pairs in one configuration, then follow
the same pairs through a trajectory to distinguish persistent bonds
from bonds that break and form again.

## Count hydrogen bonds in one configuration {#count-hydrogen-bonds-in-one-configuration}

Install the command-line program using the
[installation instructions](../../getting-started/install.md). The example
uses the supplied TIP4P configuration, with 250 oxygen atoms (type 2)
and 500 hydrogen atoms (type 1). It includes molecule IDs to associate
hydrogens with their parent waters.

From the source directory, run the command below. If you installed only
the executable, first download the reference configuration into the same
relative path:

```bash
mkdir -p input/traj
curl -fsSLo input/traj/exampleTraj.lammpstrj \
  https://raw.githubusercontent.com/d-SEAMS/seams-core/v2.14.3/input/traj/exampleTraj.lammpstrj
```

Count the bonds:

```bash
seams hbonds input/traj/exampleTraj.lammpstrj --type 2 --htype 1
```

```default
nop 250 hbonds 460
```

The command finds 460 distinct hydrogen-bonded oxygen pairs, not 460
waters or 460 directional donor–acceptor assignments. Each pair
contributes to both waters’ neighbour counts, so the mean degree of this
network is 2 × 460 / 250 = 3.68.

With the default criterion, oxygen centres must be within 3.5 Å. A
hydrogen attached to one oxygen must be within 2.42 Å of the other
oxygen, with an acceptor-centred angle of at most 30°. See
[Hydrogen-bond geometry](../../explanation/hydrogen-bonds.md)
for the periodic convention and directional definition.

## Measure persistence across a trajectory {#measure-persistence-across-a-trajectory}

A single count cannot determine whether the same molecules remain
bonded. Save a trajectory with hydrogen coordinates as well as oxygens,
and retain the matching labelled topology. An oxygen-only trajectory
can give geometric neighbours but cannot give the directional
hydrogen-bond criterion.

Follow the
[Python hydrogen-bond tutorial](https://python.dseams.info/tutorials/hydrogen-bonds.md)
to read an example XTC and GRO, count bonded pairs at each frame,
compute continuous and intermittent curves, and plot the results.
It is a separate three-frame dataset from the TIP4P configuration above.

Continuous survival requires a starting pair to remain bonded at every
saved frame up to the chosen lag. Intermittent correlation allows a
pair to break and re-form between the start and end. Neither curve can
detect an event between saved frames. Use the saved-frame interval,
not the molecular dynamics integration timestep, for the lag axis.

For a simulation or analysis program that already supplies bond identities,
the [trajectory and dynamics how-to](../howto/trajectories-and-dynamics.md)
shows how to accumulate the same curves in C++.

## References {#references}

The d-SEAMS software paper uses hydrogen-bond networks for confined
water and ice \[[Goswami *et al.*, 2020](../../explanation/citation.md#id13)\].
