Utilities

identify_connections

gmso.utils.connectivity.identify_connections(top, index_only=False)[source]

Identify all angle, dihedral and improper connections.

This requires that the bonded connections are fully defined in the gmso.Topology.

Parameters:
  • top (Topology) – The gmso topology for which to identify connections for.

  • index_only (bool) – If True, return integer site indices that would form the connections rather than adding the connections to the topology.

Returns:

Connections are added to top in-place. When index_only is True, a dict of integer-index tuples is returned instead and top is not modified.

Return type:

None

Notes

Connections are detected by direct adjacency enumeration over the topology’s bond graph (built with integer site indices as nodes). This replaces the previous approach of VF2 subgraph isomorphism on the line graph of the bond graph.

The patterns being searched for (bonds, angles, dihedrals, impropers) are simple enough that they can be enumerated by walking the adjacency structure directly, instead of sub-graph matching:

  • Angle (a-b-c):

    for each node b, enumerate pairs of its neighbors.

  • Dihedral (a-b-c-d):

    for each edge (b,c), enumerate (neighbor of b) x (neighbor of c), excluding the b-c bond itself.

  • Improper (central; b1,b2,b3):

    for each node with degree >= 3, enumerate all combinations of 3 neighbors.

Site objects are only touched at two boundaries:
  • Entry: building the site_index_map (site -> int).

  • Exit: _add_connections resolving int indices back to Site objects.

Everything in between operates on plain Python ints.