Changeset 5a479d for src/Python
- Timestamp:
- Jan 24, 2024, 4:53:03 PM (21 months ago)
- 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)
- Location:
- src/Python
- Files:
-
- 3 edited
-
PythonScripting_impl.hpp (modified) (2 diffs)
-
getGraph6String.cpp (modified) (2 diffs)
-
modules.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Python/PythonScripting_impl.hpp
rd083cc r5a479d 110 110 "returns list of elements over the nodes of the graph of the current selected set of atoms." 111 111 ); 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 ); 112 122 boost::python::def< MoleCuilder::detail::doubleVec() >( 113 123 "getBoundingBox", … … 183 193 .def("__iter__", boost::python::iterator< std::vector< std::vector< double > > >()) 184 194 .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) 185 209 ; 186 210 -
src/Python/getGraph6String.cpp
rd083cc r5a479d 39 39 #include "CodePatterns/Assert.hpp" 40 40 #include "CodePatterns/Log.hpp" 41 #include <algorithm> 41 42 #include <string> 42 43 44 #include "Element/element.hpp" 43 45 #include "Graph/Graph6Writer.hpp" 44 46 #include "World.hpp" … … 68 70 return output.str(); 69 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 } -
src/Python/modules.hpp
rd083cc r5a479d 31 31 typedef std::vector<double> doubleVec; 32 32 typedef std::vector< std::vector<double> > atomPositionsVec; 33 typedef std::vector< std::string > stringVec; 33 34 34 35 doubleVec module_getBoundingBox(); … … 41 42 std::string module_getGraph6String(); 42 43 std::string module_getElementListAsString(); 44 MoleCuilder::detail::stringVec module_getAllGraph6Strings(); 45 MoleCuilder::detail::stringVec module_getAllElementListAsStrings(); 43 46 44 47 } /* namespace detail */
Note:
See TracChangeset
for help on using the changeset viewer.
