Skip to content

Instantly share code, notes, and snippets.

@ghutchis
Last active March 6, 2024 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghutchis/fd2438d7cbbadeb42772f10f5c155146 to your computer and use it in GitHub Desktop.
Save ghutchis/fd2438d7cbbadeb42772f10f5c155146 to your computer and use it in GitHub Desktop.
Avogadro2 Atom symbols and Neighbors
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