AChemKit.utils.simpledot

A library to manage .dot files

There are existing python libraries for this, but they do not always do it correctly (e.g. PyDot does not respect order within a .dot file).

Classes

DictMixin
SimpleDot([name, digraph, strict]) Repsents a graphviz .dot file (also known as .gv).
class AChemKit.utils.simpledot.SimpleDot(name='G', digraph=True, strict=False)

Bases: UserDict.DictMixin

Repsents a graphviz .dot file (also known as .gv).

Uses a dictionary-like interface via the :class:~`UserDict.DictMixin` class.

To produce .dot output, cast to string e.g. str(mysimpledot)

Contains three types of graph objects:

Nodes
Named by strings and are dictionaries of attributes.
Edges
Named by tuples of length 2 of strings and are are dictionaries of attributes. Nodes will be implicitly created by graphviz if they do not exist, and therefore do not need to be explicitly created.
Subgraphs
Named by strings and are instances of this class. Some graphviz layout engines (e.g. neato) will flatten subgraphs.

These can be set and accessed by standard slice notation (e.g. dot[nodename] = {}).

Node names and subgraph names are unique but multiple parallel edges are permitted. However, slice notation (e.g. dot[(from, to)]) cannot cope with this. Therefore, when there are multiple parallel edges, accessing any of them returns a tuple of all their attributes as dictionaries. To create multiple parallel edges you must use the add() method

Names of nodes and subgraphs, attribute keys, and attribute values should all be graphviz compatible. Some attempt to wrap string attribute values in quotes will be made so that the use of plain python strings is accepted by graphviz.

Very little checking and enforcement is performed. This means that you can use them in ways not originally intended; for example, you can se attributes that no graphviz programme will recognize. But, it also means you can break it by doing odd things to them.

add(key, value=None)

Guaranteed to add the passed key/value to self, even if it is a duplicate.

get(key)

Returns a tuple of all things matching that key.

Designed for multiple edges, but will also work with single edges, nodes, or subgraphs. This provides a unified interface.

keys()

Return a tuple of the keys.

plot(output='pdf', prog='dot', args=())

Previous topic

AChemKit.utils.simpledot

Next topic

AChemKit.tools

This Page