Changeset 5a479d for src/Python


Ignore:
Timestamp:
Jan 24, 2024, 4:53:03 PM (21 months ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
d203d1e
Parents:
d083cc
git-author:
Frederik Heber <frederik.heber@…> (01/22/24 22:21:29)
git-committer:
Frederik Heber <frederik.heber@…> (01/24/24 16:53:03)
Message:

Added python actions to generate all graph6 strings.

  • graph6 strings don't take permutations in the adjacency matrix into account. Hence, we are going through every permutation of non-hydrogens and generate the respective graph6 string.
Location:
src/Python
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Python/PythonScripting_impl.hpp

    rd083cc r5a479d  
    110110      "returns list of elements over the nodes of the graph of the current selected set of atoms."
    111111  );
     112  boost::python::def< MoleCuilder::detail::stringVec() >(
     113      "getAllGraph6Strings",
     114      MoleCuilder::detail::module_getAllGraph6Strings,
     115      "returns chemical graphs of the current selected set of atoms as graph6 representation with all non-hydrogen atom permutations."
     116  );
     117  boost::python::def< MoleCuilder::detail::stringVec() >(
     118      "getAllElementListAsStrings",
     119      MoleCuilder::detail::module_getAllElementListAsStrings,
     120      "returns lists of elements over the nodes of the graph of the current selected set of atoms with all non-hydrogen atom permutations."
     121  );
    112122  boost::python::def< MoleCuilder::detail::doubleVec() >(
    113123      "getBoundingBox",
     
    183193      .def("__iter__", boost::python::iterator< std::vector< std::vector< double > > >())
    184194      .def("__repr__", &MoleCuilder::PythonTypes::vec_item< std::vector< std::vector< double > > >::toStringRepr)
     195  ;
     196  // positions
     197  boost::python::class_< std::vector< std::string > >("PythonType_stringVec")
     198      .def("__len__", &std::vector< std::string >::size)
     199      .def("clear", &std::vector< std::string >::clear)
     200      .def("append", &MoleCuilder::PythonTypes::vec_item< std::vector< std::string > >::add,
     201            boost::python::with_custodian_and_ward<1, 2>()) // let container keep value
     202      .def("__getitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< std::string > >::get,
     203           boost::python::return_value_policy<boost::python::copy_non_const_reference>())
     204      .def("__setitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< std::string > >::set,
     205           boost::python::with_custodian_and_ward<1,2>()) // to let container keep value
     206      .def("__delitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< std::string > >::del)
     207      .def("__iter__", boost::python::iterator< std::vector< std::string > >())
     208      .def("__repr__", &MoleCuilder::PythonTypes::vec_item< std::vector< std::string > >::toStringRepr)
    185209  ;
    186210
  • src/Python/getGraph6String.cpp

    rd083cc r5a479d  
    3939#include "CodePatterns/Assert.hpp"
    4040#include "CodePatterns/Log.hpp"
     41#include <algorithm>
    4142#include <string>
    4243
     44#include "Element/element.hpp"
    4345#include "Graph/Graph6Writer.hpp"
    4446#include "World.hpp"
     
    6870  return output.str();
    6971}
     72
     73MoleCuilder::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
     95MoleCuilder::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}
  • src/Python/modules.hpp

    rd083cc r5a479d  
    3131typedef std::vector<double> doubleVec;
    3232typedef std::vector< std::vector<double> > atomPositionsVec;
     33typedef std::vector< std::string > stringVec;
    3334
    3435doubleVec module_getBoundingBox();
     
    4142std::string module_getGraph6String();
    4243std::string module_getElementListAsString();
     44MoleCuilder::detail::stringVec module_getAllGraph6Strings();
     45MoleCuilder::detail::stringVec module_getAllElementListAsStrings();
    4346
    4447} /* namespace detail */
Note: See TracChangeset for help on using the changeset viewer.