Last active
March 6, 2024 21:16
-
-
Save ghutchis/fd2438d7cbbadeb42772f10f5c155146 to your computer and use it in GitHub Desktop.
Avogadro2 Atom symbols and Neighbors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto graph = m_molecule->graph(); | |
for (Index i = 0; i < m_molecule->atomCount(); ++i) | |
{ | |
// print the symbol for the atom | |
Core::Atom atom = m_molecule->atom(i); | |
std::string atomType = Core::Elements::symbol(atom.atomicNumber()); | |
std::cout << "Atom " << atomType << " (" << i << ")" << std::endl; | |
// check neighbors | |
if (graph.neighbors(i).size() > 0) { | |
std::cout << "Neighbors of " << atomType << " (" << i << "): "; | |
for (const auto neighbor : graph.neighbors(i)) { | |
Core::Atom neighborAtom = m_molecule->atom(neighbor); | |
// check the bond order between the atoms | |
auto bond = m_molecule->bond(i, neighbor); | |
char bondOrder = ' '; | |
switch (bond.order()) { | |
case 1: | |
bondOrder = '-'; | |
break; | |
case 2: | |
bondOrder = '='; | |
break; | |
case 3: | |
bondOrder = '#'; | |
break; | |
default: | |
bondOrder = '?'; | |
break; | |
} | |
std::string neighborType = Core::Elements::symbol(neighborAtom.atomicNumber()); | |
std::cout << bondOrder << neighborType << " (" << neighbor << "), "; | |
} | |
std::cout << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment