Files
rdkit/Code/GraphMol/StereoGroup.cpp
Dan N 378a223d66 Python wrap enhanced stereo setters (#2509)
* Allow creation of Enhanced Stereo groups from Python

This wraps creation of Enhanced Stereo groups from Python. It
also allows setting enhanced stereo groups on an RWMol from
Python.

Additionally, this provides a little function to allow C++
vectors to be wrapped for Python, but allow Python list objects
or wrapped C++ vectors to be used as arguments to functions
that take vectors as inputs. I added it only to
Wrap/StereoGroup.cpp, but I _think_ that I should add this
logic to RegisterVectorConverter in RDBoost/Wrap.h. If I
did that, I'd be able to remove a couple of lines in Wrap/Mol.cpp

* enforce atom ownership in SGroups
Some cleanups to make sure you can't add an S group with bogus atoms
to a molecule

* Remove constructor for StereoGroup.

I tried very hard to convince boost Python to allow me to use
with_custodian_and_ward_postcall on an init, and it just never
worked. I've removed the constructor - folks will need to
use the factory function "CreateStereoGroup" if they want
a StereoGroup.
2019-07-03 10:24:26 +02:00

41 lines
1.4 KiB
C++

#include <algorithm>
#include "StereoGroup.h"
namespace RDKit {
StereoGroup::StereoGroup(StereoGroupType grouptype, std::vector<Atom *> &&atoms)
: d_grouptype(grouptype), d_atoms(atoms) {}
StereoGroup::StereoGroup(StereoGroupType grouptype,
const std::vector<Atom *> &atoms)
: d_grouptype(grouptype), d_atoms(atoms) {}
StereoGroupType StereoGroup::getGroupType() const { return d_grouptype; }
const std::vector<Atom *> &StereoGroup::getAtoms() const { return d_atoms; }
void removeGroupsWithAtom(const Atom *atom, std::vector<StereoGroup> &groups) {
auto containsAtom = [atom](const StereoGroup &group) {
return std::find(group.getAtoms().cbegin(), group.getAtoms().cend(),
atom) != group.getAtoms().cend();
};
groups.erase(std::remove_if(groups.begin(), groups.end(), containsAtom),
groups.end());
}
void removeGroupsWithAtoms(const std::vector<Atom *> &atoms,
std::vector<StereoGroup> &groups) {
auto containsAnyAtom = [atoms](const StereoGroup &group) {
for (auto atom : atoms) {
if (std::find(group.getAtoms().cbegin(), group.getAtoms().cend(), atom) !=
group.getAtoms().cend()) {
return true;
}
}
return false;
};
groups.erase(std::remove_if(groups.begin(), groups.end(), containsAnyAtom),
groups.end());
}
} // namespace RDKit