Skip to content

H-Bound Atoms

Provides a utility function to find the hydrogen-bonded atoms in a molecule.

find_hydrogen_bonded_atoms

find_hydrogen_bonded_atoms(mol, n_atoms)

Identify the hydrogen-bonded atoms in a molecule.

This function takes a molecule and the number of atoms in that molecule as input, and it returns a sparse matrix with the indices of the hydrogen-bonded atoms.

Parameters:

Name Type Description Default
mol MolType

The molecule for which the hydrogen-bonded atoms are to be identified.

required
n_atoms int

The number of atoms in the molecule.

required

Returns:

Type Description
csr_matrix

A sparse matrix with the indices of the hydrogen-bonded atoms.

Source code in lahuta/utils/hbonded_atoms.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def find_hydrogen_bonded_atoms(mol: MolType, n_atoms: int) -> csr_matrix:
    """Identify the hydrogen-bonded atoms in a molecule.

    This function takes a molecule and the number of atoms in that molecule as input, and it
    returns a sparse matrix with the indices of the hydrogen-bonded atoms.

    Args:
        mol (MolType): The molecule for which the hydrogen-bonded atoms are to be identified.
        n_atoms (int): The number of atoms in the molecule.

    Returns:
        (csr_matrix): A sparse matrix with the indices of the hydrogen-bonded atoms.
    """
    hbond_array = dok_matrix((n_atoms, 6), dtype=np.int32)

    for atom in ob.OBMolAtomIter(mol):
        if atom.ExplicitHydrogenCount():
            for ix, atom2 in enumerate(ob.OBAtomAtomIter(atom)):
                if atom2.GetAtomicNum() == 1:
                    atom1_id = atom.GetId()
                    atom2_id = atom2.GetId()
                    hbond_array[atom1_id, ix] = atom2_id

    return hbond_array.tocsr()