indigoX
MolecularGraph Class Reference

Class containing a graph representation of a molecule. More...

#include <indigox/graph/molecular.hpp>

+ Inheritance diagram for MolecularGraph:
+ Collaboration diagram for MolecularGraph:

Public Types

using AtomMap = eastl::vector_map< Atom, MGVertex >
 Container for mapping atoms to vertices. More...
 
using BondMap = eastl::vector_map< Bond, MGEdge >
 Container for mapping bonds to edges. More...
 
using ComponentContain = std::vector< VertContain >
 Type for storing components. More...
 
using CycleEdgeContain = std::vector< EdgeContain >
 Type for storing edge cycles. More...
 
using CycleVertContain = std::vector< VertContain >
 Type for storing vertex cycles. More...
 
using EdgeContain = std::vector< MGEdge >
 Container for edges. More...
 
using EdgeIter = EdgeContain::const_iterator
 Type of the iterator returned by GetEdges() method. More...
 
using EdgeMap = indigox::utils::SimpleBiMap< MGEdge, EdgeType >
 Type for bidirectional mapping of E to edge descriptor type. More...
 
using EdgeType = MGEdge
 Type used for edges. More...
 
using graph_type = BaseGraph< MGVertex, MGEdge, MolecularGraph >
 Type of the underlying IXGraphBase. More...
 
using NbrsContain = std::map< MGVertex, VertContain >
 Container for neighbours of vertices. More...
 
using NbrsIter = NbrsContain::mapped_type::const_iterator
 Type of the iterator returned by GetNeighbours() method. More...
 
using PredIter = typename graph_type::inv_adjacency_iterator
 Type for iterator over predecessors of a vertex descriptor. More...
 
using SubgraphType = MolecularGraph
 
using VertContain = std::vector< MGVertex >
 Container for vertices. More...
 
using VertexType = MGVertex
 Type used for vertices. More...
 
using VertIter = VertContain::const_iterator
 Type of the iterator returned by GetVertices() method. More...
 
using VertMap = indigox::utils::SimpleBiMap< MGVertex, VertType >
 Type for bidirectional mapping of V to vertex descriptor type. More...
 
using VertType = typename graph_type::vertex_descriptor
 Type of the graph vertex descriptor. More...
 

Public Member Functions

 MolecularGraph ()=default
 Construct with a molecule. More...
 
 MolecularGraph (const MolecularGraph &)=default
 
 MolecularGraph (MolecularGraph &&)=default
 
 MolecularGraph (const Molecule &mol)
 
 ~ MolecularGraph ()=default
 
int64_t Degree (const MGVertex &v) const
 Degree of a vertex. More...
 
const CondensedMolecularGraphGetCondensedGraph ()
 
const ComponentContainGetConnectedComponents ()
 Get the connected components of the graph. More...
 
const CycleEdgeContainGetCycles ()
 Get the cycles of the graph. More...
 
const MGEdgeGetEdge (const Bond &bnd) const
 Get the edge associated with a bond. More...
 
MGEdge GetEdge (const MGVertex &u, const MGVertex &v) const
 Get the edge between two vertices. More...
 
const EdgeContainGetEdges () const
 Get the edges of the graph. More...
 
const MoleculeGetMolecule () const
 
const VertContainGetNeighbours (const MGVertex &v)
 Get the neighbouring vertices of a vertex. More...
 
const VertContainGetPredecessors (const MGVertex &v)
 Get the predecessor vertices of a vertex. More...
 
MGVertex GetSourceVertex (const MGEdge &e) const
 Get the source vertex of an edge. More...
 
const VertContainGetSuccessors (const MGVertex &v)
 
const MolecularGraphGetSuperGraph () const
 
MGVertex GetTargetVertex (const MGEdge &e) const
 Get the target vertex of an edge. More...
 
const MGVertexGetVertex (const Atom &atm) const
 Get the vertex associated with an atom. More...
 
std::pair< MGVertex, MGVertexGetVertices (const MGEdge &e) const
 Get the two vertices that make up an edge. More...
 
const VertContainGetVertices () const
 Get the vertices of the graph. More...
 
bool HasEdge (const MGEdge &e) const
 Is the edge in the graph. More...
 
bool HasEdge (const MGVertex &u, const MGVertex &v) const
 Does an edge exist between two vertices. More...
 
bool HasEdge (const Bond &e) const
 Check if the graph has an edge associated with a bond. More...
 
bool HasVertex (const MGVertex &v) const
 Is the vertex in the graph. More...
 
bool HasVertex (const Atom &v) const
 Check if the graph has a vertex associated with an atom. More...
 
int64_t InDegree (const MGVertex &v) const
 Indegree of a vertex. More...
 
bool IsConnected ()
 Determine if the graph is connected. More...
 
bool IsCyclic (const MGVertex &v)
 Determine if a vertex of this graph is cyclic. More...
 
bool IsCyclic (const MGVertex &v, uint32_t sz)
 
bool IsCyclic (const MGEdge &e)
 Determine if an edge of this graph is cycle. More...
 
bool IsCyclic (const MGEdge &e, uint32_t sz)
 
bool IsSubgraph () const
 
int64_t NumConnectedComponents ()
 Get the number of connected components of the graph. More...
 
int64_t NumCycles ()
 
int64_t NumEdges () const
 Number of edges in the graph. More...
 
int64_t NumVertices () const
 Number of vertices in the graph. More...
 
 operator bool () const
 
bool operator!= (const MolecularGraph &g) const
 
bool operator< (const MolecularGraph &g) const
 
bool operator<= (const MolecularGraph &g) const
 
MolecularGraphoperator= (MolecularGraph &&)=default
 
MolecularGraphoperator= (const MolecularGraph &)=default
 
bool operator== (const MolecularGraph &g) const
 
bool operator> (const MolecularGraph &g) const
 
bool operator>= (const MolecularGraph &g) const
 
MolecularGraph Subgraph (std::vector< MGVertex > &vertices)
 Induce a subgraph from the range of vertices. More...
 
MolecularGraph Subgraph (std::vector< MGVertex > &vertices, std::vector< MGEdge > &edges)
 

Protected Member Functions

void AddEdge (const MGVertex &u, const MGVertex &v, const MGEdge &e)
 Add a new edge to the graph. More...
 
void AddVertex (const MGVertex &v)
 Add a new vertex to the graph. More...
 

Protected Attributes

std::shared_ptr< BaseImpl > m_basedata
 

Friends

class cereal::access
 Friendship allows serialisation. More...
 
class indigox::Molecule
 Friendship allows an Molecule to own a graph. More...
 
std::ostream & operator<< (std::ostream &os, const MolecularGraph &g)
 

Detailed Description

Class containing a graph representation of a molecule.

The IXMolecularGraph is designed to be maintained by the IXMolecule instance owning it. To that end, all the modifying methods assume that the parameters feed to them are valid. However, all the accessing methods do not make this assumption and so perform sanity checks.

Member Typedef Documentation

◆ AtomMap

using AtomMap = eastl::vector_map<Atom, MGVertex>

Container for mapping atoms to vertices.

◆ BondMap

using BondMap = eastl::vector_map<Bond, MGEdge>

Container for mapping bonds to edges.

◆ ComponentContain

using ComponentContain = std::vector<VertContain>
inherited

Type for storing components.

◆ CycleEdgeContain

using CycleEdgeContain = std::vector<EdgeContain>
inherited

Type for storing edge cycles.

◆ CycleVertContain

using CycleVertContain = std::vector<VertContain>
inherited

Type for storing vertex cycles.

◆ EdgeContain

using EdgeContain = std::vector<MGEdge>

Container for edges.

◆ EdgeIter

using EdgeIter = EdgeContain::const_iterator

Type of the iterator returned by GetEdges() method.

◆ EdgeMap

Type for bidirectional mapping of E to edge descriptor type.

◆ EdgeType

using EdgeType = MGEdge

Type used for edges.

◆ graph_type

Type of the underlying IXGraphBase.

◆ NbrsContain

using NbrsContain = std::map<MGVertex, VertContain>

Container for neighbours of vertices.

◆ NbrsIter

using NbrsIter = NbrsContain::mapped_type::const_iterator

Type of the iterator returned by GetNeighbours() method.

◆ PredIter

using PredIter = typename graph_type::inv_adjacency_iterator
inherited

Type for iterator over predecessors of a vertex descriptor.

◆ SubgraphType

using SubgraphType = MolecularGraph
inherited

◆ VertContain

using VertContain = std::vector<MGVertex>

Container for vertices.

◆ VertexType

Type used for vertices.

◆ VertIter

using VertIter = VertContain::const_iterator

Type of the iterator returned by GetVertices() method.

◆ VertMap

Type for bidirectional mapping of V to vertex descriptor type.

◆ VertType

using VertType = typename graph_type::vertex_descriptor
inherited

Type of the graph vertex descriptor.

Constructor & Destructor Documentation

◆ MolecularGraph() [1/4]

MolecularGraph ( )
default

Construct with a molecule.

Parameters
molthe molecule to reference to.

◆ MolecularGraph() [2/4]

MolecularGraph ( const MolecularGraph )
default

◆ MolecularGraph() [3/4]

MolecularGraph ( MolecularGraph &&  )
default

◆ ~ MolecularGraph()

~ MolecularGraph ( )
default

◆ MolecularGraph() [4/4]

MolecularGraph ( const Molecule mol)

Member Function Documentation

◆ AddEdge()

void AddEdge ( const MGVertex u,
const MGVertex v,
const MGEdge e 
)
protectedinherited

Add a new edge to the graph.

Vertex u is used as the source and vertex v as the target. If u and/or v are not already part of the graph, they are added. It is the callers responsibility to ensure that the edge is not part of the graph.

Parameters
u,vvertices the edge is between.
ethe edge.

◆ AddVertex()

void AddVertex ( const MGVertex v)
protectedinherited

Add a new vertex to the graph.

It is the callers responsability to ensure that the vertex added is not already part of the graph. If it is, a mismatch between the vertices in the graph and the what the _verts member thinks are in the graph may arise.

Parameters
vthe vertex to add.

◆ Degree()

int64_t Degree ( const MGVertex v) const
inherited

Degree of a vertex.

In the case of a directed graph, the degree of a vertex is the number of edges leaving the vertex.

Parameters
vthe vertex to get the degree of.
Returns
pair of the degree of the vertex and if it is valid.

◆ GetCondensedGraph()

const CondensedMolecularGraph& GetCondensedGraph ( )

◆ GetConnectedComponents()

const BaseGraph< MGVertex , MGEdge , MolecularGraph , Undirected , GraphLabel , GraphLabel >::ComponentContain & GetConnectedComponents ( )
inherited

Get the connected components of the graph.

Returns
reference to the connected components of the graph.

◆ GetCycles()

Get the cycles of the graph.

Returns
the cycles of the graph.

◆ GetEdge() [1/2]

const MGEdge& GetEdge ( const Bond bnd) const

Get the edge associated with a bond.

If the bond is not associated with an edge on this graph, the returned edge is null.

Parameters
bndthe bond to get the associated edge of.
Returns
the associated edge.

◆ GetEdge() [2/2]

MGEdge GetEdge ( const MGVertex u,
const MGVertex v 
) const
inherited

Get the edge between two vertices.

It is the callers responsibilty to ensure that the vertices are a part of the graph.

Parameters
u,vvertices to get the edge between.
Returns
a pair of the edge between the two vertces and if it is valid.

◆ GetEdges()

const BaseGraph< MGVertex , MGEdge , MolecularGraph , Undirected , GraphLabel , GraphLabel >::EdgeContain & GetEdges ( ) const
inherited

Get the edges of the graph.

Parameters
[out]edgesthe vector where the list of edges will be set. The vector is cleared before any edges are added to it.
Returns
the number of edges added to the vector.

◆ GetMolecule()

const Molecule& GetMolecule ( ) const

◆ GetNeighbours()

const BaseGraph< MGVertex , MGEdge , MolecularGraph , Undirected , GraphLabel , GraphLabel >::VertContain & GetNeighbours ( const MGVertex v)
inherited

Get the neighbouring vertices of a vertex.

The neighbours of a vertex are those for which the edge v -> u exists within the graph. It is the callers responsibilty to ensure that the vertex is a part of the graph.

Parameters
vthe vertex to get the neighbours of.
[out]nbrsthe vector where the list of neighbours will be set. The vector is cleared before any neighbouring vertices are added to it.
Returns
if the vector has been populated or not.

◆ GetPredecessors()

const BaseGraph< MGVertex , MGEdge , MolecularGraph , Undirected , GraphLabel , GraphLabel >::VertContain & GetPredecessors ( const MGVertex v)
inherited

Get the predecessor vertices of a vertex.

The predecessors of a vertex are those for which the edge u -> v exists within the graph. For an undirected graph, this is equivalent to the neighbours. It is the callers responsibilty to ensure that the vertex is a part of the graph.

Parameters
[in]vthe vertex to get the predecessors of.
[out]presthe vector where the list of predecessors will be set. The vector is cleared before any predecessing vertices are added to it.
Returns
if the vector has been populated or not.

◆ GetSourceVertex()

MGVertex GetSourceVertex ( const MGEdge e) const
inherited

Get the source vertex of an edge.

It is the callers responsibilty to ensure that the edge is a part of the graph.

Parameters
ethe edge to get the source of.
Returns
a pair of the source vertex of the edge and if it is valid.

◆ GetSuccessors()

const BaseGraph< MGVertex , MGEdge , MolecularGraph , Undirected , GraphLabel , GraphLabel >::VertContain & GetSuccessors ( const MGVertex v)
inherited

◆ GetSuperGraph()

const MolecularGraph& GetSuperGraph ( ) const

◆ GetTargetVertex()

MGVertex GetTargetVertex ( const MGEdge e) const
inherited

Get the target vertex of an edge.

It is the callers responsibilty to ensure that the edge is a part of the graph.

Parameters
ethe edge to get the target of.
Returns
the target vertex of the edge.

◆ GetVertex()

const MGVertex& GetVertex ( const Atom atm) const

Get the vertex associated with an atom.

If the atom is not associated with a vertex of this graph, the returned vertex is null.

Parameters
atmthe atom to get the assocaited vertex of.
Returns
the associated vertex.

◆ GetVertices() [1/2]

std::pair< MGVertex , MGVertex > GetVertices ( const MGEdge e) const
inherited

Get the two vertices that make up an edge.

It is the callers responsibility to ensure that the edge is a part of the graph.

Parameters
ethe edge to get vertices of.
Returns
a pair of a pair of the two vertices making up the edge and if they are valid.

◆ GetVertices() [2/2]

const BaseGraph< MGVertex , MGEdge , MolecularGraph , Undirected , GraphLabel , GraphLabel >::VertContain & GetVertices ( ) const
inherited

Get the vertices of the graph.

Parameters
[out]vertsthe vector where the list of vertices will be set. The vector is cleared before any vertices are added to it.
Returns
the number of vertices added to the vector.

◆ HasEdge() [1/3]

bool HasEdge ( const MGEdge e) const
inherited

Is the edge in the graph.

Parameters
eedge to search for.
Returns
if the requested edge is contained in the graph or not.

◆ HasEdge() [2/3]

bool HasEdge ( const MGVertex u,
const MGVertex v 
) const
inherited

Does an edge exist between two vertices.

Parameters
u,vvertices to check between.
Returns
if there is an edge between the two vertices.

◆ HasEdge() [3/3]

bool HasEdge ( const Bond e) const

Check if the graph has an edge associated with a bond.

Parameters
ethe bond to check for.
Returns
if the bond is associated with the graph or not.

◆ HasVertex() [1/2]

bool HasVertex ( const MGVertex v) const
inherited

Is the vertex in the graph.

Parameters
vvertex to search for.
Returns
if the requested vertex is contained in the graph or not.

◆ HasVertex() [2/2]

bool HasVertex ( const Atom v) const

Check if the graph has a vertex associated with an atom.

Parameters
vthat atom to check for.
Returns
if the atom is associated with the graph or not.

◆ InDegree()

int64_t InDegree ( const MGVertex v) const
inherited

Indegree of a vertex.

The indegree of a vertex is the number of edges entering the vertex. For an undirected graph, this is equivalent to Degree(V) const. It is the callers responsibilty to ensure that the vertex is a part of the graph.

Parameters
vthe vertex to get indegree of.
Returns
pair of the indegree of the vertex and if it is valid.

◆ IsConnected()

bool IsConnected ( )
inherited

Determine if the graph is connected.

Returns
if the graph is connected or not.

◆ IsCyclic() [1/4]

bool IsCyclic ( const MGVertex v)
inherited

Determine if a vertex of this graph is cyclic.

Parameters
vthe vertex to check if in a cycle
Returns
if the vertex is in a cycle or not.

◆ IsCyclic() [2/4]

bool IsCyclic ( const MGVertex v,
uint32_t  sz 
)
inherited

◆ IsCyclic() [3/4]

bool IsCyclic ( const MGEdge e)
inherited

Determine if an edge of this graph is cycle.

Parameters
ethe edge to check if in a cycle.
Returns
if the edge is in a cycle or not.

◆ IsCyclic() [4/4]

bool IsCyclic ( const MGEdge e,
uint32_t  sz 
)
inherited

◆ IsSubgraph()

bool IsSubgraph ( ) const

◆ NumConnectedComponents()

int64_t NumConnectedComponents ( )
inherited

Get the number of connected components of the graph.

Returns
the number of cnnected components of the graph.

◆ NumCycles()

int64_t NumCycles ( )
inherited

◆ NumEdges()

int64_t NumEdges ( ) const
inherited

Number of edges in the graph.

Returns
the number of edges in the graph.

◆ NumVertices()

int64_t NumVertices ( ) const
inherited

Number of vertices in the graph.

Returns
the number of vertices in the graph.

◆ operator bool()

operator bool ( ) const
inline

◆ operator!=()

bool operator!= ( const MolecularGraph g) const
inline

◆ operator<()

bool operator< ( const MolecularGraph g) const

◆ operator<=()

bool operator<= ( const MolecularGraph g) const
inline

◆ operator=() [1/2]

MolecularGraph& operator= ( MolecularGraph &&  )
default

◆ operator=() [2/2]

MolecularGraph& operator= ( const MolecularGraph )
default

◆ operator==()

bool operator== ( const MolecularGraph g) const

◆ operator>()

bool operator> ( const MolecularGraph g) const

◆ operator>=()

bool operator>= ( const MolecularGraph g) const
inline

◆ Subgraph() [1/2]

MolecularGraph Subgraph ( std::vector< MGVertex > &  vertices)
virtual

Induce a subgraph from the range of vertices.

Induced subgraph has the same vertices and edges as its parent graph. Additionally, its source Molecule is the same. This is a vertex induced subgraph, meaning that all edges where both vertices are in the provided range will be in the induced graph.

Template Parameters
InputIttype of the iterator range provided.
Parameters
begin,endmarking the range of vertices to induce subgraph on.
Returns
a new MolecularGraph.

Implements BaseGraph< MGVertex, MGEdge, MolecularGraph >.

◆ Subgraph() [2/2]

MolecularGraph Subgraph ( std::vector< MGVertex > &  vertices,
std::vector< MGEdge > &  edges 
)
virtual

Friends And Related Function Documentation

◆ cereal::access

friend class cereal::access
friend

Friendship allows serialisation.

◆ indigox::Molecule

friend class indigox::Molecule
friend

Friendship allows an Molecule to own a graph.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const MolecularGraph g 
)
friend

Member Data Documentation

◆ m_basedata

std::shared_ptr<BaseImpl> m_basedata
protectedinherited

The documentation for this class was generated from the following file: