Breadth First Sorting

Sort your structure according to the breadth-first search algorithm.

Introduction

Breadth First Search (BFS) algorithm traverses a graph in a breadth-ward motion and uses a queue to remember to get the next vertex to start a search, when a dead end occurs in any iteration (depiction below taken from here).

The BFS algorithm employs the following rules.

  1. Visit the adjacent unvisited vertex and mark it as visited. Then display it and insert it in a queue.

  2. If no adjacent vertex is found, remove the first vertex from the queue.

  3. Repeat Rule 1 and Rule 2 until the queue is empty.

Define the Subcommand

Application

Simple example: Ethane

To sort an ethane molecule according to the BFS algorithms, we use the subcommand sort

The depiction below shows the sorting for the ethane molecule. On the left side the initial coordinates are shown, while the right side presents the BFS sorted structure with start = 0. Note that the atom declared by start will always be the first atom in the sorted structure.

More advanced example: Alanine-glycine

Let's increase the difficulty a little bit, we choose the alanine-glycine molecule from our Examples. First we take the unsorted molecule in an xmol format

We want to sort this structure according to the BFS algorithm described above. Here, we choose to sort everything starting from the atom having index 0 .

We obtain the sorted structure as depicted above where the covalent partner of atom 0 are: 1, 2, 3, and 4. Once we have identified all partner we go on with index 1 and identify it's partners: 5 and 6 . After visiting all indices we have a BFS sorted molecule! 🎉

Last updated

Was this helpful?