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.
Visit the adjacent unvisited vertex and mark it as visited. Then display it and insert it in a queue.
If no adjacent vertex is found, remove the first vertex from the queue.
Repeat Rule 1 and Rule 2 until the queue is empty.
Define the Subcommand
> kallisto sort options arguments
# Note that the atom count starts at 0
--start <int>
(optional)
description:
start BFS from given atom
--out <string>
(optional)
description:
write output to file
input file is given as (positional) argument
Application
Simple example: Ethane
To sort an ethane molecule according to the BFS algorithms, we use the subcommand sort
> cat ethane.xyz8ethaneC0.000.00-1.10H2.030.76-1.25H-1.000.27-1.47H0.27-1.00-1.47H1.031.03-2.71C1.031.03-1.61H0.762.03-1.25H0.000.000.00# Save BFS sorted structure to 'ethane_s.xyz'> kallisto sort --start 0 --out ethane_s.xyz ethane.xyz> cat ethane_s.xyz8CreatedwithkallistoC0.00000.0000-1.1000H-1.00000.2700-1.4700H0.2700-1.0000-1.4700C1.03001.0300-1.6100H0.00000.00000.0000H2.03000.7600-1.2500H1.03001.0300-2.7100H0.76002.0300-1.2500
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 .
# Save BFS sorted structure to 'alanine_glycine_s.xyz'> kallisto sort --start 0 --out alanine-glycine_s.xyz alanine-glycine.xyz> cat alanine_glycine_s.xyz20CreatedwithkallistoC2.08140.6151-0.5084C2.74221.8240-1.2008N0.61010.6951-0.5388C2.4888-0.5934-1.1984H2.41650.55740.5321N4.11781.7999-1.1904O2.09562.7249-1.7397H0.30311.42610.1038H0.33841.0507-1.4605H2.0292-1.4570-0.7200H2.1702-0.5424-2.2386H3.5727-0.6884-1.1550C4.94362.8270-1.8221H4.61411.0820-0.6705C6.44012.5694-1.6376H4.69983.7945-1.3737H4.72292.8447-2.8942O7.35163.2523-2.0691O6.70521.4634-0.8975H7.68741.4486-0.8603
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! 🎉