RDKIT库提供了一个分子类提供成员函数 getTopology
返回类型 adjacency_list< vecs,vecs,vecs,diondrecteds,atom *,bond *>
的BGL图。我了解RDKIT类型债券提供了成员函数 getIdx
返回唯一整数以识别债券,因此该图必须具有边缘编号的概念。
使用 biconnected_components
需要一个组件属性映射,该属性映射图形的边缘描述符类型的对象(我知道此类型是 bond> bond
?)来识别整数。由于RDKIT不在双连接组件中交易,因此我得出结论,该属性图必须在图表外部。在这种情况下,BGL文档建议使用 iterator_property_map 适配器类(请参阅“外部属性”部分)。我很难确定 iterator_property_map
获得所需属性映射的正确模板参数。如果这是正确的方法,则缺少模板参数?
不幸的是,在BGL文档中迷失之前,我的代码并没有太远:
void my_function(const RDKit::ROMol& molecule) {
const RDKit::MolGraph& molecule_graph{molecule.getTopology()};
using EdgesSize =
boost::graph_traits<RDKit::MolGraph>::edges_size_type; // map value type
using Edge =
boost::graph_traits<RDKit::MolGraph>::edge_descriptor; // map key type
std::vector<EdgesSize> component_map(boost::num_edges(molecule_graph)
); // range, begin() yields random access iterator
// boost::iterator_property_map<?>;
// boost::biconnected_components(molecule_graph, ?);
}
The rdkit library provides a molecule class ROMol
that provides a member function getTopology
that returns a BGL graph of type adjacency_list<vecS, vecS, undirectedS, Atom *, Bond *>
. I understand that the rdkit type Bond
defines the edge properties of the graph. I know that Bond
provides a member function getIdx
that returns a unique integer identifying the bond, so the graph must have a notion of edge numbering.
To make use of the BGL algorithm for biconnected_components
one requires a component property map that maps objects of the edge descriptor type of the graph (I understand this type is Bond
?) to component identifying integers. As rdkit does not deal in biconnected components, I conclude this property map must be exterior to the graph. In this case, the BGL documentation suggests to use the iterator_property_map
adaptor class (see section "Exterior Properties"). I struggle to determine the correct template arguments for iterator_property_map
to get the required property map. If this is the correct approach what are the missing template arguments?
Unfortunately I did not get very far with my code before getting lost in the BGL documentation:
void my_function(const RDKit::ROMol& molecule) {
const RDKit::MolGraph& molecule_graph{molecule.getTopology()};
using EdgesSize =
boost::graph_traits<RDKit::MolGraph>::edges_size_type; // map value type
using Edge =
boost::graph_traits<RDKit::MolGraph>::edge_descriptor; // map key type
std::vector<EdgesSize> component_map(boost::num_edges(molecule_graph)
); // range, begin() yields random access iterator
// boost::iterator_property_map<?>;
// boost::biconnected_components(molecule_graph, ?);
}
发布评论
评论(1)
边缘描述符是内部描述符,有点像稳定的迭代器。例如
边缘属性是完全独立的概念。您可以从Edge描述符获得边缘属性:
毫不奇怪的是,对于顶点描述符与属性:
并发症
之间的两个描述符类型之间的显着差异是 - 仅是因为Graph类型使用
vecs
作为顶点容器选择器 - 确保顶点描述符是不可或缺的,其中边缘描述符是不透明的(类似于void*
)。因此,边缘脱位不能是基于向量的属性映射的关键类型(因为它需要一个积分索引器)。
取而代之的是建立关联属性map:
样本
live on Coliru >
打印
高级示例
您 can 将向量作为映射存储,但这需要您将边缘( bonds )映射到连续的积分范围[0..num_edges(g g) )。
我不能假设
getIdx()
满足标准,但是如果这样做:让我们将其应用于图形
> https://i.sstatic.net/wpwgf.png“ rel =” nofollow noreferrer“>
live on Coliru 实际上
,如果我们添加a nofollow noreferrer“> bonus wizardry” :
Edge descriptors are internal descriptors, sort of like stable iterators. E.g.
Edge properties are entirely separate notions. You get the edge properties from an edge descriptor like so:
Unsurprisingly the same goes for vertex descriptors vs. properties:
The Complication
A notable difference between the two descriptor types is that - only because the graph type is using
vecS
as the vertex container selector - the vertex descriptor is guaranteed to be integral, where edge descriptor is opaque (similar to avoid*
).Hence, the edge-decriptor cannot be the key type to a vector-based property map (because it would require an integral indexer).
Instead make an associative property-map:
Sample
Live On Coliru
Prints
Advanced Example
You can force a vector as mapping storage, but that requires you to map the edges (bonds) to a contiguous integral range [0..num_edges(g)).
I couldn't assume that
getIdx()
satisfies the criterion, but if it did:Let's apply it to the graph from the documentation:
Live On Coliru
Which prints prints the expected mapping
In fact, if we add a little bit of bonus wizardry, we can render that: