CAOS package

Submodules

CAOS.dispatch module

Handles registration and dispatch of reactions and molecule types.

Provides two decorators that are aliases for classes:

decorator alias -> ClassName register_reaction_mechanism -> ReactionDispatcher register_molecule_type -> MoleculeTypeDispatcher

This allows the reaction system to determine which type of reaction and what representation of molecules should be used, all occuring dynamically, at runtime.

Attributes

react: function
Function that attempts to react molecules under given conditions
register_reaction_mechanism: function
Registers a reaction mechanism with the dispatch system.
reaction_is_registered: function
Checks whether or not a reaction has been registered.
class CAOS.dispatch.ReactionDispatcher(mechanism_name, requirements)[source]

Class that dispatches on reaction types.

function

The function to be called when using this reaction.

Returns:

callable

The function that has been registered for this reaction.

Notes

Should not be called directly - let the react function handle that.

name

The name assigned to the mechanism.

Returns:

string

The name the mechanism has been registered as.

Raises:

ExistingReactionError

The name must be unique - if an existing mechanism shares this name it will cause an error.

namespace

Shortcut to this mechanism’s part of the namespace.

Returns:

dict

Contains the requirements that must be met to dispatch this function, as well as the function itself.

Notes

Assumes that the name of this mechanism is already known. If you unset the name, this will behave strangely or error.

requirements

The requirements of this reaction mechanism.

Returns:

dict

Mapping from requirement name to some callable that can be used to determine if the parameters meet the requirement.

Raises:

InvalidReactionError

If any of the requirements aren’t callable then an error is raised.

CAOS.dispatch.register_reaction_mechanism

alias of ReactionDispatcher

CAOS.chem_logging module

Singleton logging for the language.

When verbose mode is enabled, logged messages are written to stdout or stderr, depending on the type of message. Otherwise they are ignored.

class CAOS.chem_logging.DummyLogger[source]

Bases: object

Fake logger I’m going to use for now.

Will return something valid in all cases.

CAOS.chem_logging.logger

Fake logger I’m going to use for now.

Will return something valid in all cases.

CAOS.util module

Utility functions that aren’t core functionality.

CAOS.util.raises(exception_types, function, args=None, kwargs=None)[source]

Return whether or not the given function raises the error.

Parameters:

exception_types: tuple, Exception

Tuple of the types of the exceptions (or a single type of exception) that should be caught.

function: callable

The function to be called

args: collection, optional

List of positional arguments to be used

kwargs: mapping, optional

Dictionary of keyword arguments to be used

Examples

It should return False when given a valid value

>>> raises(ValueError, int, ["3"])
False

It should return True when given an invalid value that results in the expected error

>>> raises(ValueError, int, ["hello"])
True

It should raise an error if it gets an unexpected error

>>> raises(UnboundLocalError, int, ["hello"])
Traceback (most recent call last):
    ...
ValueError: invalid literal for int() with base 10: 'hello'

Module contents

CAOS module.