utils Package

utils Package

Various utility functions and classes.

bag Module

A collection of classes providing containers. These use the abstract base classes (ABCs) from collections module to satisfy isinstance() criteria for API provision.

class AChemKit.utils.bag.Bag(iterable)

Bases: AChemKit.utils.bag.FrozenBag, _abcoll.MutableSet

A Bag is like a set, but can contain duplicates.

Also, a Bag is like a list, but is always ordered.

add(item)
discard(item)
class AChemKit.utils.bag.FrozenBag(iterable)

Bases: _abcoll.Set

A Bag is like a set, but can contain duplicates.

Also, a Bag is like a list, but is always ordered.

Note: objects must be both hashable and sortable. By default, python objects are sorted by id(), but this is not consistent. As there is no easy way to test this, if you get wierd results this may be the cause.

count(item)
class AChemKit.utils.bag.OrderedBag(iterable)

Bases: AChemKit.utils.bag.OrderedFrozenBag, _abcoll.MutableSet

Like a Bag, but iterating will keep the order things were put in. New items are added to the end of the OrderedBag - if you need anything else you can convert it to a tuple or list and make a new bag.

Comparisons are still as for a Bag so OrderedBag([1,2,1]) == OrderedBag([2,1,1]) will return True.

add(item)
discard(item)
class AChemKit.utils.bag.OrderedFrozenBag(iterable)

Bases: _abcoll.Set

Like a FrozenBag, but iterating will keep the order things were put in.

Comparisons are still as for a FrozenBag so OrderedFrozenBag([1,2,1]) == OrderedFrozenBag([2,1,1]) will return True.

count(item)
index(item)
class AChemKit.utils.bag.OrderedFrozenBagCache

Bases: object

bag_test Module

This is the test harness for AChemKit.utils.bag.

class AChemKit.utils.bag_test.TestBag(methodName='runTest')

Bases: AChemKit.utils.bag_test.TestFrozenBag

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

cls

alias of Bag

setUp()
test_add()
test_discard()
test_hash()
class AChemKit.utils.bag_test.TestFrozenBag(methodName='runTest')

Bases: unittest.TestCase

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

cls

alias of FrozenBag

setUp()
test_eq()
test_hash()
test_iter()
test_len()
test_pickle()
test_repr()
test_str()
class AChemKit.utils.bag_test.TestOrderedBag(methodName='runTest')

Bases: AChemKit.utils.bag_test.TestOrderedFrozenBag, AChemKit.utils.bag_test.TestBag

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

cls

alias of OrderedBag

setUp()
test_hash()
class AChemKit.utils.bag_test.TestOrderedFrozenBag(methodName='runTest')

Bases: AChemKit.utils.bag_test.TestFrozenBag

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

cls

alias of OrderedFrozenBag

setUp()
test_iter()

simpledot Module

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).

class AChemKit.utils.simpledot.SimpleDot(name='G', digraph=True, strict=False, cluster=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=())

Calls the specified drawing program to turn this into an image.

Use args to pass extra arguments, particularly -o to specify an output filename.

Follows the same format as subprocess calls.

utils Module

Various small functions that can get lumped together into this module.

AChemKit.utils.utils.get_sample(distribution, rng=None)

Samples a provided distribution at random.

Distribution can be a single number (int or float), always returns the same value

Distribution can be a sequence (list or tuple) which will be uniformly sampled from Duplicates can be used to adjust frequencies.

Distribution can be a mapping (dict) where the keys are things to be returned and values are the relative weightings.

AChemKit.utils.utils.long_subseq(data)

Given some sequences — strings, tuples, lists, etc — return the longest subsequence common to all sequences.

AChemKit.utils.utils.memory_free()

Returns the amount of memory free, in megabytes

AChemKit.utils.utils.myp(p, f, *args)
AChemKit.utils.utils.unpck(combo)

utils_test Module

This is the test harness for AChemKit.utils.utils.

class AChemKit.utils.utils_test.TestGetSample(methodName='runTest')

Bases: unittest.TestCase

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_dicts()
test_ints()
test_lists()

Table Of Contents

Previous topic

tools Package

Next topic

To-Dos

This Page