3.1.9. Graph

3.1.9.1. Class Graph

class mod.Graph

This class models an undirected graph with labels on vertices and edges, without loops and without parallel edges. Certain labels are regarded as models of chemical atoms and bonds. See Molecule Encoding for more information on this.

id

(Read-only) A unique instance id among Graph objects.

Type:int
numVertices

(Read-only) The number of vertices in the graph.

Type:int
vertices

(Read-only) An iterable of all vertices in the graph.

Type:GraphVertexRange
numEdges

(Read-only) The number of edges in the graph.

Type:int
edges

(Read-only) An iterable of all edges in the graph.

Type:GraphEdgeRange
print()
print(first, second=None)

Print the graph, using either the default options or the options in first and second. If first and second are the same, only one depiction will be made.

Parameters:
  • first (GraphPrinter) – the printing options used for the first depiction.
  • second (GraphPrinter) – the printing options used for the second depiction. If it is None then it is set to first.
Returns:

the names for the PDF-files that will be compiled in post-processing. If first and second are the same, the two file prefixes are equal.

Return type:

(string, string)

getGMLString(withCoords=False)
Returns:the GML representation of the graph, optionally with generated 2D coordinates.
Return type:string
Raises:LogicError when coordinates are requested, but none can be generated.
printGML(withCoords=False)

Print the GML representation of the graph, optionally with generated 2D coordinates.

Returns:the filename of the printed GML file.
Return type:string
Raises:LogicError when coordinates are requested, but none can be generated.
name

The name of the graph. The default name includes the unique instance id.

Type:string
smiles

(Read-only) If the graph models a molecule, this is the canonical SMILES string for it.

Type:string
Raises:LogicError if the graph is not a molecule.
graphDFS

(Read-only) This is the GraphDFS of the graph.

Type:string
linearEncoding

(Read-only) If the graph models a molecule this is the SMILES string string, otherwise it is the GraphDFS string.

Type:string
isMolecule

(Read-only) Whether or not the graph models a molecule. See Molecule Encoding.

Type:bool
energy

(Read-only) If the graph models a molecule, this is some energy value. The energy is calculated using Open Babel, unless already calculated or cached by Graph.cacheEnergy().

Type:double
cacheEnergy(e)

If the graph models a molecule, sets the energy to a given value.

Parameters:e (double) – the value for the energy to be set.
molarMass

(Read-only) If the graph models a molecule, this is the molar mass of the molecule as calculated by Open Babel.

Type:double
vLabelCount(label)
Parameters:label (string) – some label for querying.
Returns:the number of vertices in the graph with the given label.
Return type:unsigned int
eLabelCount(label)
Parameters:label (string) – some label for querying.
Returns:the number of edges in the graph with the given label.
Return type:unsigned int
isomorphism(other, maxNumMatches=1)
Parameters:
  • other (Graph) – the codomain Graph for finding morphisms.
  • maxNumMatches (std::size_t) – the maximum number of isomorphisms to search for.
Returns:

the number of isomorphisms from this graph to other, but at most maxNumMatches.

Return type:

std::size_t

monomorphism(other, maxNumMatches=1)
Parameters:
  • other – the codomain Graph for finding morphisms.
  • maxNumMatches (std::size_t) – the maximum number of monomorphisms to search for.
Returns:

the number of monomorphisms from this graph to other, though at most maxNumMatches.

Return type:

std::size_t

makePermutation()
Returns:a graph isomorphic to this, but with the vertex indices randomly permuted.
Return type:Graph
image

(Write-only) A custom depiction for the graph. The depiction file used will be the string returned by the given function, with .pdf appended. The function will only be called once.

Type:string()
imageCommad

A command to be run in post-processing if a custom depiction is set. The command is only run once.

Type:string
getVertexFromExternalId(id)

If the graph was not loaded from an external data format, then this function always return a null descriptor. If the graph was loaded from a SMILES string, but any class label was not unique, then the function always return a null descriptor.

Note

In general there is no correlation between external and internal ids.

Parameters:id (int) – the external id to find the vertex descriptor for.
Returns:the vertex descriptor for the given external id. The descriptor is null if the external id was not used.
mod.graphGMLString(s, name=None)

Load a graph in GML format from a given string.

Parameters:
  • d (string) – the string with the GML data to load from.
  • name (string) – the name of the graph. If none is given the default name is used.
Returns:

the loaded graph.

Return type:

Graph

Raises:

InputError on bad input.

mod.graphGML(f, name=None)

Load a graph in GML format from a given file.

Parameters:
  • f (string) – name of the GML file to be loaded.
  • name (string) – the name of the graph. If none is given the default name is used.
Returns:

the loaded graph.

Return type:

Graph

Raises:

InputError on bad input.

mod.graphDFS(s, name=None)

Load a graph from a GraphDFS string.

Parameters:
  • s (string) – the GraphDFS string to parse.
  • name (string) – the name of the graph. If none is given the default name is used.
Returns:

the loaded graph.

Return type:

Graph

Raises:

InputError on bad input.

mod.smiles(s, name=None)

Load a molecule from a SMILES string.

Parameters:
  • s (string) – the SMILES string to parse.
  • name (string) – the name of the graph. If none is given the default name is used.
Returns:

the loaded molecule.

Return type:

Graph

Raises:

InputError on bad input.