| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| 5 |  * 
 | 
|---|
| 6 |  *
 | 
|---|
| 7 |  *   This file is part of MoleCuilder.
 | 
|---|
| 8 |  *
 | 
|---|
| 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
| 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
| 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
| 12 |  *    (at your option) any later version.
 | 
|---|
| 13 |  *
 | 
|---|
| 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
| 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 17 |  *    GNU General Public License for more details.
 | 
|---|
| 18 |  *
 | 
|---|
| 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
| 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 21 |  */
 | 
|---|
| 22 | 
 | 
|---|
| 23 | /*
 | 
|---|
| 24 |  * getGraph6String.cpp
 | 
|---|
| 25 |  *
 | 
|---|
| 26 |  *  Created on: Apr 03, 2021
 | 
|---|
| 27 |  *      Author: heber
 | 
|---|
| 28 |  */
 | 
|---|
| 29 | 
 | 
|---|
| 30 | // include config.h
 | 
|---|
| 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 32 | #include <config.h>
 | 
|---|
| 33 | #endif
 | 
|---|
| 34 | 
 | 
|---|
| 35 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include "modules.hpp"
 | 
|---|
| 38 | 
 | 
|---|
| 39 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 40 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 41 | #include <algorithm>
 | 
|---|
| 42 | #include <string>
 | 
|---|
| 43 | 
 | 
|---|
| 44 | #include "Element/element.hpp"
 | 
|---|
| 45 | #include "Graph/Graph6Writer.hpp"
 | 
|---|
| 46 | #include "World.hpp"
 | 
|---|
| 47 | 
 | 
|---|
| 48 | /** =========== define the function ====================== */
 | 
|---|
| 49 | std::string MoleCuilder::detail::module_getGraph6String()
 | 
|---|
| 50 | {
 | 
|---|
| 51 |   /*
 | 
|---|
| 52 |    * Returns the current molecular graph of the selected set of atoms as
 | 
|---|
| 53 |    * graph6 string representation.
 | 
|---|
| 54 |    */
 | 
|---|
| 55 |   Graph6Writer writer(World::getConstInstance().getSelectedAtoms());
 | 
|---|
| 56 |   std::stringstream output;
 | 
|---|
| 57 |   writer.write_graph6(output);
 | 
|---|
| 58 |   return output.str();
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | std::string MoleCuilder::detail::module_getElementListAsString()
 | 
|---|
| 62 | {
 | 
|---|
| 63 |   /*
 | 
|---|
| 64 |    * Returns the current molecular graph of the selected set of atoms as
 | 
|---|
| 65 |    * graph6 string representation.
 | 
|---|
| 66 |    */
 | 
|---|
| 67 |   Graph6Writer writer(World::getConstInstance().getSelectedAtoms());
 | 
|---|
| 68 |   std::stringstream output;
 | 
|---|
| 69 |   writer.write_elementlist(output);
 | 
|---|
| 70 |   return output.str();
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | MoleCuilder::detail::stringVec MoleCuilder::detail::module_getAllGraph6Strings()
 | 
|---|
| 74 | {
 | 
|---|
| 75 |   /*
 | 
|---|
| 76 |    * Returns all graph6 representation by creating all permutations
 | 
|---|
| 77 |    * of the non-hydrogen atoms.
 | 
|---|
| 78 |    */
 | 
|---|
| 79 |   std::vector<const atom *> selected_atoms = World::getConstInstance().getSelectedAtoms();
 | 
|---|
| 80 |   // split set into hydrogen and non-hydrogen
 | 
|---|
| 81 |   const std::vector<const atom *>::iterator partitioner =
 | 
|---|
| 82 |     std::partition(selected_atoms.begin(), selected_atoms.end(), [](const atom * walker) { return walker->getElement().getAtomicNumber() != (atomicNumber_t)1; });
 | 
|---|
| 83 |   std::sort(selected_atoms.begin(), partitioner);
 | 
|---|
| 84 |   MoleCuilder::detail::stringVec returnlist;
 | 
|---|
| 85 |   do {
 | 
|---|
| 86 |     Graph6Writer writer(selected_atoms);
 | 
|---|
| 87 |     std::stringstream output;
 | 
|---|
| 88 |     writer.write_graph6(output);
 | 
|---|
| 89 |     returnlist.push_back(output.str());
 | 
|---|
| 90 |   } while(std::next_permutation(selected_atoms.begin(), partitioner));
 | 
|---|
| 91 | 
 | 
|---|
| 92 |   return returnlist;
 | 
|---|
| 93 | }
 | 
|---|
| 94 | 
 | 
|---|
| 95 | MoleCuilder::detail::stringVec MoleCuilder::detail::module_getAllElementListAsStrings()
 | 
|---|
| 96 | {
 | 
|---|
| 97 |   /*
 | 
|---|
| 98 |    * Returns non-hydrogen element lists by creating all permutations
 | 
|---|
| 99 |    * of the non-hydrogen atoms.
 | 
|---|
| 100 |    */
 | 
|---|
| 101 |   std::vector<const atom *> selected_atoms = World::getConstInstance().getSelectedAtoms();
 | 
|---|
| 102 |   // split set into non-hydrogen and hydrogen
 | 
|---|
| 103 |   const std::vector<const atom *>::iterator partitioner =
 | 
|---|
| 104 |     std::partition(selected_atoms.begin(), selected_atoms.end(), [](const atom * walker) { return walker->getElement().getAtomicNumber() != (atomicNumber_t)1; });
 | 
|---|
| 105 |   std::sort(selected_atoms.begin(), partitioner);
 | 
|---|
| 106 |   MoleCuilder::detail::stringVec returnlist;
 | 
|---|
| 107 |   do {
 | 
|---|
| 108 |     Graph6Writer writer(selected_atoms);
 | 
|---|
| 109 |     std::stringstream output;
 | 
|---|
| 110 |     writer.write_simple_elementlist(output);
 | 
|---|
| 111 |     returnlist.push_back(output.str());
 | 
|---|
| 112 |   } while(std::next_permutation(selected_atoms.begin(), partitioner));
 | 
|---|
| 113 | 
 | 
|---|
| 114 |   return returnlist;
 | 
|---|
| 115 | }
 | 
|---|