@@ -65,25 +65,53 @@ void addBracketHelper(SubstanceGroup &self, python::object pts) {
6565 self.addBracket (bkt);
6666}
6767
68+ python::tuple getCStatesHelper (const SubstanceGroup &self) {
69+ python::list res;
70+ for (const auto cs : self.getCStates ()) {
71+ res.append (cs);
72+ }
73+ return python::tuple (res);
74+ }
75+
76+ python::tuple getBracketsHelper (const SubstanceGroup &self) {
77+ python::list res;
78+ for (const auto brk : self.getBrackets ()) {
79+ res.append (python::make_tuple (brk[0 ], brk[1 ], brk[2 ]));
80+ }
81+ return python::tuple (res);
82+ }
83+
84+ python::tuple getAttachPointsHelper (const SubstanceGroup &self) {
85+ python::list res;
86+ for (const auto ap : self.getAttachPoints ()) {
87+ res.append (ap);
88+ }
89+ return python::tuple (res);
90+ }
6891} // namespace
6992
7093std::string sGroupClassDoc =
7194 " A collection of atoms and bonds with associated properties\n " ;
7295
7396struct sgroup_wrap {
7497 static void wrap () {
75- // register the vector_indexing_suite for SubstanceGroups
76- // if it hasn't already been done.
77- // logic from https://stackoverflow.com/a/13017303
78- boost::python::type_info info =
79- boost::python::type_id<std::vector<RDKit::SubstanceGroup>>();
80- const boost::python::converter::registration *reg =
81- boost::python::converter::registry::query (info);
82- if (reg == nullptr || (*reg).m_to_python == nullptr ) {
83- python::class_<std::vector<RDKit::SubstanceGroup>>(" SubstanceGroup_VECT" )
84- .def (python::vector_indexing_suite<
85- std::vector<RDKit::SubstanceGroup>>());
86- }
98+ RegisterVectorConverter<SubstanceGroup>(" SubstanceGroup_VECT" );
99+
100+ python::class_<SubstanceGroup::CState,
101+ boost::shared_ptr<SubstanceGroup::CState>>(
102+ " SubstanceGroupCState" , " CSTATE for a SubstanceGroup" , python::init<>())
103+ .def_readonly (" bondIdx" , &SubstanceGroup::CState::bondIdx)
104+ .def_readonly (" vector" , &SubstanceGroup::CState::vector);
105+
106+ python::class_<SubstanceGroup::AttachPoint,
107+ boost::shared_ptr<SubstanceGroup::AttachPoint>>(
108+ " SubstanceGroupAttach" , " AttachPoint for a SubstanceGroup" ,
109+ python::init<>())
110+ .def_readonly (" aIdx" , &SubstanceGroup::AttachPoint::aIdx,
111+ " attachment index" )
112+ .def_readonly (" lvIdx" , &SubstanceGroup::AttachPoint::lvIdx,
113+ " leaving atom or index (0 for implied)" )
114+ .def_readonly (" id" , &SubstanceGroup::AttachPoint::id, " attachment id" );
87115
88116 python::class_<SubstanceGroup, boost::shared_ptr<SubstanceGroup>>(
89117 " SubstanceGroup" , sGroupClassDoc .c_str (), python::no_init)
@@ -93,28 +121,31 @@ struct sgroup_wrap {
93121 .def (" GetIndexInMol" , &SubstanceGroup::getIndexInMol,
94122 " returns the index of this SubstanceGroup in the owning "
95123 " molecule's list." )
96- .def (
97- " GetAtoms " , &SubstanceGroup::getAtoms,
98- " returns a list of the indices of the atoms in this SubstanceGroup" ,
99- python::return_value_policy<python::copy_const_reference>())
124+ .def (" GetAtoms " , &SubstanceGroup::getAtoms,
125+ " returns a list of the indices of the atoms in this "
126+ " SubstanceGroup" ,
127+ python::return_value_policy<python::copy_const_reference>())
100128 .def (" GetParentAtoms" , &SubstanceGroup::getParentAtoms,
101129 " returns a list of the indices of the parent atoms in this "
102130 " SubstanceGroup" ,
103131 python::return_value_policy<python::copy_const_reference>())
104- .def (
105- " GetBonds " , &SubstanceGroup::getBonds,
106- " returns a list of the indices of the bonds in this SubstanceGroup" ,
107- python::return_value_policy<python::copy_const_reference>())
132+ .def (" GetBonds " , &SubstanceGroup::getBonds,
133+ " returns a list of the indices of the bonds in this "
134+ " SubstanceGroup" ,
135+ python::return_value_policy<python::copy_const_reference>())
108136 .def (" AddAtomWithIdx" , &SubstanceGroup::addAtomWithIdx)
109137 .def (" AddBondWithIdx" , &SubstanceGroup::addBondWithIdx)
110138 .def (" AddParentAtomWithIdx" , &SubstanceGroup::addParentAtomWithIdx)
111139 .def (" AddAtomWithBookmark" , &SubstanceGroup::addAtomWithBookmark)
112140 .def (" AddParentAtomWithBookmark" ,
113141 &SubstanceGroup::addParentAtomWithBookmark)
114142 .def (" AddCState" , &SubstanceGroup::addCState)
143+ .def (" GetCStates" , getCStatesHelper)
115144 .def (" AddBondWithBookmark" , &SubstanceGroup::addBondWithBookmark)
116145 .def (" AddAttachPoint" , &SubstanceGroup::addAttachPoint)
146+ .def (" GetAttachPoints" , getAttachPointsHelper)
117147 .def (" AddBracket" , addBracketHelper)
148+ .def (" GetBrackets" , getBracketsHelper)
118149
119150 .def (" SetProp" ,
120151 (void (RDProps::*)(const std::string &, std::string, bool ) const ) &
@@ -183,13 +214,15 @@ struct sgroup_wrap {
183214 .def (" GetPropNames" , &SubstanceGroup::getPropList,
184215 (python::arg (" self" ), python::arg (" includePrivate" ) = false ,
185216 python::arg (" includeComputed" ) = false ),
186- " Returns a list of the properties set on the SubstanceGroup.\n\n " )
217+ " Returns a list of the properties set on the "
218+ " SubstanceGroup.\n\n " )
187219 .def (" GetPropsAsDict" , GetPropsAsDict<SubstanceGroup>,
188220 (python::arg (" self" ), python::arg (" includePrivate" ) = true ,
189221 python::arg (" includeComputed" ) = true ),
190222 " Returns a dictionary of the properties set on the "
191223 " SubstanceGroup.\n "
192224 " n.b. some properties cannot be converted to python types.\n " );
225+
193226 python::def (" GetMolSubstanceGroups" , &getMolSubstanceGroups,
194227 " returns a copy of the molecule's SubstanceGroups (if any)" ,
195228 python::with_custodian_and_ward_postcall<0 , 1 >());
0 commit comments