Detailed documentation for all the components of AChemKit. It is generated directly from the source code, so should be up-to-date.
Library for working with Bucket objects; instances of a simulation of an Artificial Chemistry.
Various tools for going between ReactionNetwork and Bucket objects, as well an analysing the data within Bucket objects.
Bases: object
Event history of a simulation of an Artificial Chemistry.
Alternative constructor that accepts a file() object (or equivalent).
Source must be formatted as a bucket log file, see bucket_file_format.
Wrapper around from_file() that opens the provided filename as a file to read.
Wrapper around from_file() that uses StringIO.
A property that generates and caches a ReactionNetwork object representing the reaction network exhibited by this bucket.
Rates are calculated based on repeats of events in this bucket. This may have a large sampling error depending on how many repeates there were.
Functions for testing properties of particular reaction networks.
These functions expect an object of class AChemKit.reactionnet.ReactionNetwork or subclass or something with an equivalent API. It does not enforce this however, so you may use custom classes with the same API.
Some of these properties have logical prerequisites, but these are not tested for explicitly.
Tests for reactions where some species is both consumed and produced by the same reaction, and is produced more than it is consumed.
For example:
A + C -> A + A
Tests for reactions where some species is both consumed and produced by the same reaction.
For example:
A + C -> B + C
AB + C -> A + B + C
Returns all reactions where reactants combine to produce more products.
For example:
AB -> A + B
AB + C -> A + B + C
Works as an iterator filter.
Tests for divergent reactions.
Divergent reactions are where the same reactants have multiple possible collections of products.
For example:
AB + C -> ABC
AB + C -> A + B + C
Tests for a pair of reactions where the products of one is the reactants of the other and visa vera.
For example:
A + B -> AB
AB -> A + B
Returns all reactions where reactants combine to produce fewer products.
May also be called a combination reaction.
For example:
A + B -> AB
A + B + C -> AB + D
Works as an iterator filter.
Tests if any reactions are direct autocatalysis. See get_autocatalysis_direct() for definition.
Tests if any reactions are direct catalysis. See get_catalysis_direct() for definition.
Tests if any reactions are decomposition. See get_decomposition() for definition.
Tests if any reactions are divergent. See get_divergence() for definition.
Tests if any reactions are reversible. See get_reversible() for definition.
Tests if any reactions are synthesis. See get_synthesis() for definition.
Tests that the reaction network has different rates for different reactions.
To get the range of rates a reaction network spans, use:
span = max(rn.rates.values())-min(rn.rates.values())
Tests for violation of conservation of mass.
Note, we can show that a reaction network breaks conservation of mass, but not prove that it obeys it.
This is done by arranging all the molecules into a partially ordered set - a tree from largest to smallest. If this cannot be done, then conservation of mass must be violated. If this can be done, then conservation of mass may or may not apply - it cannot be said for certain.
This requires that each molecular species can be separated into individual atoms. If this is not possible, then this function will not work.
NEEDS TO BE WRITTEN
(Credit to Adam Nellis for algorithm)
Functions for testing properties of particular reaction networks.
These functions expect an object of class AChemKit.reactionnet.ReactionNetwork or subclass or something with an equivalent API. It does not enforce this however, so you may use custom classes with the same API.
Some of these properties have logical prerequisites, but these are not tested for explicitly.
Unlike AChemKit.reactionnet.properties, the functions here are not boolean, but rather return grops of things
Loops are collections of molecules where a path exists to themselves through linkages of shared products and reactants.
For example:
A -> B
B -> C
C -> A
Various functions that interact with NetworkX (http://networkx.lanl.gov/)
This is used because its a fast graph library with lots of nice algorithms in it.
For each reactant and each product in each reaction, they are linked if they share at minimum subsequence length and if the reactant is a catalsyst.
For each reactant and each product in each reaction, they are linked if they share at minimum subsequence length.
Functions that construct random ReactionNetwork instances by various methods.
This is designed to provide null hypothesis data for various situations and metrics. As with random graphs, there is no single best way to generate a random reaction network.
Generates a random ReactionNetwork from molecules that are strings of atoms and can join together or break apart.
Based on the paper Autocatalytic sets of proteins. 1986. Journal of Theoretical Biology 119:1-24 by Kauffman, Stuart A. but without the explicit catalytic activity.
Arguments:
Note
AChemKit.reactionnet.ReactionNetwork tracks molecules by their reactions, so if a molecule is not part of any reaction it will not appear at all e.g. in seen.
Generates a random ReactionNetwork by assigning reaction randomly between all molecular species.
Arguments:
Note
AChemKit.reactionnet.ReactionNetwork tracks molecules by their reactions, so if a molecule is not part of any reaction it will not appear at all e.g. in seen. This could lead to differences from nmols.
Note
The value of nreactions is the number of times a reaction will be added to the ReactionNetwork. If it is already in the ReactionNetwork, it will be replaced. This can lead to AChemKit.reactionnet.ReactionNetwork with less than nreactions reactions.
Number of reactants for each reaction in the reaction network. Can be a single value or a tuple/list which will be uniformly sampled from (duplicates can be used to give a non-uniform distribution).
Note
If this is a tuple/list it will be sampled for each reaction.
Number of products for each reaction in the reaction network. Can be a single value or a tuple/list which will be uniformly sampled from (duplicates can be used to give a non-uniform distribution).
If this is None, then nreactants must be a list/tuple of tuples of (nreactants, nproducts) pairs that will be uniformly sampled from. Or nreactants must be a dictionary with keys of (nreactants, nproducts) and values of weightings, which will be sampled from.
Note
If this is a tuple/list it will be sampled for each reaction.
Rate of each reaction in the reaction network. Can be a single value or a tuple/list which will be uniformly sampled from (duplicates can be used to give a non-uniform distribution).
Note
If this is a tuple/list it will be sampled for each reaction.
These arguments can be a single value, a tuple/list which will be uniformly sampled from, or a dictionary of value/weighting which will be sampled from
For example:
Uniform(5,3,2,1) will generate 5 molecules with 3 reactions between them where each reaction has two reactants and one product.
Uniform(5,3,(1,2), (1,2)) will generate 5 molecules with 3 reactions between them where each reaction has one or two reactants and one or two products.
Uniform(5,3,((2,1),(1,2)), None) will generate 5 molecules with 3 reactions between them where each reaction has either two reactants and one product or one reactant and two products.
This is the test harness for AChemKit.randomnet.
Tricky to test well because it is non-deterministic.
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.
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.
Core for all ReactionNetwork classes
Of particular note are the alternative constructors of ReactionNetwork, from_file(), from_filename() and from_string().
Bases: object
A dictionary of reactions where each key is a reaction composed of (reactants, products) and each value is the rate.
ReactionNetwork objects are immutable and hashable.
ReactionNetwork objects support __eq__() and __ne__(), but none of the other rich comparison operators (__lt__, __le__, __gt__, __ge__).
Different subclassess could be implemented to generate reaction networks on demand (artificial chemistries, etc) and provide additional functionallity, such as visualization or metrics.
Can be cast to string to get a .chem representation.
Alternative constructor that accepts a file() object (or equivalent).
Source must be formatted as a .chem file, see .chem Format.
Wrapper around AChemKit.reactionnet.ReactionNetwork.from_file() that opens the provided filename as a file to read.
Generates a reaction network using a function that returns all possible products for a given set of reactants and an initial set of molecules.
allreactions is a function that takes two reactants as parameters, (typically via *args) and returns a dictionary of possible outcomes and their weighting.
maxdepth is the number of times all reactions of seen molecules is evaluated. If it is None, then the process repeats until no more novel molecules are created; this may lead to an infinite loop.
Wrapper around AChemKit.reactionnet.ReactionNetwork.from_file() that uses StringIO.
Gets the rate of a particular reaction.
Itterate over all reactions through tuples of the form (reactants, products, rate)
Produces a human-readable string for a particular reaction.
Mainly used to convert entire reaction network to a string representation, but can also be used for individual reactions if desired.
Sorted tuple of all reactions in the network.
Sorted tuple of all molecular species in the network
This is the test harness for AChemKit.reactionnet.
Bases: unittest.TestCase
This is the main class to test ReactionNetwork class.
It relies on setUp to generate a ReactionNetwork instance which is then probed by the other functions
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.
As ReactionNetwork has a custom __eq__ function, it is tested here.
Needs to both pass and fail.
As ReactionNetwork has a custom __hash__ function, it is tested here.
Needs to both pass and fail.
Technically, the fail here could be true and still be a hash but it is supposed to usually be wrong so assume that it will be wrong.
Check that it convert a reaction to a string correctly
Makes sure the reactions that were specified are in reactions. Also checks that they are in sorted order TODO check sorted order between reactions
Makes sure the molecules that were specified are in seen. Also checks that they are in sorted order.
Check that it converts to a string correctly
Bases: AChemKit.reactionnet_test.TestReactionNetwork
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.
Bases: AChemKit.reactionnet.ReactionNetwork
This is a subclass of AChemKit.reactionnet.ReactionNetwork that adds a .dot representation. It is in a subclass so that on machines where dot is not installed, the basic class can still be used.
Return a .dot format string constructed using a AChemKit.utils.simpledot.SimpleDot view of this reaction network.
Molecular species are shown as either full names, identifier numbers, or as blank circles. This is determined by the names parameter, which is a string indicating which to use:
A sub-set of the reaction network can be drawn using the shown and hidden parameters.
Reactions involving only molecular species on the hidden list are not shown. Molecular species on the hidden list are not shown unless they are involved in a reaction with molecular species not on the hidden list, in which case the molecular species on the hidden list is unlabeled and shown as a point.
The shown list in the inverse of the hidden list. If it is used, any molecular species not on the shown list is treated as being on the hidden list. If a molecular species is on both shown and hidden lists, the hidden lists wins.
Catalysts (defined as molecules that are required for but unchanged by a reaction) are indicated with a grey line.
Reversible reactions (defined as a pair of reactions where reactants of one are the products of the other and visa versa) are combined and indicated with double arrows resembling a diamond shape.
This is the test harness for AChemKit.reactionnetdot.
Bases: unittest.TestCase
This is the main class to test ReactionNetwork class.
It relies on setUp to generate a ReactionNetwork instance which is then probed by the other functions
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 for dot conversion by string representation
Assumes that the dot representation itself is valid
Bases: object
Given an Artificial Chemistry, this simulates a series of simple iterative reactions. It returns events as tuples of (time, reactants, products).
This is an implementation of the Gillespie algorithm. It is a simulation of a well-mixed container.
Is an iterator to reduce memory consumption. See simulate_gillespie for this function wrapped in a tuple.
This is the test harness for AChemKit.sims_simple.
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.
Bases: object
This is an abstract base class for an AChem that can be used in a simulation or similar. It defines core attribtues and functions that subclasses must implement in order to follow the API correctly.
It is not required that an AChem inherits this, as Python follows the principle of “duck typing”.
Given some number of reactants, return the products.
The reactant objects should not be changed. Rather, copies should be returned. This is so events and buckets work correctly.
Bases: AChemKit.sims_simple.AChemAbstract
This is an AChem class that uses a Reaction Network as its base.
The main point of this is to be able to compare different simuatlion approaches to see which ones best reconstruct the original Reaction Network.
Given an Artificial Chemistry, this simulates a series of simple iterative reactions. It returns events as tuples of (time, reactants, products).
One reaction occurs each second for a number of seconds up to the maximum time specified.
Works as an iterator to reduce memory consumption. See simulate_itterative for this function wrapped in a tuple.
Given an Artificial Chemistry, this simulates a series of simple iterative reactions. It returns events as tuples of (time, reactants, products).
Each molecule will attempt to react once for each second. If there are any leftover molecules, they will get a free pass to the next second.
Is an iterator to reduce memory consumption. See simulate_stepwise for this function wrapped in a tuple.
Given an Artificial Chemistry, this simulates a series of simple iterative reactions. It returns events as tuples of (time, reactants, products).
Each molecule will attempt to react once for each second. If there are any leftover molecules, they will get a free pass to the next second.
Is an iterator to reduce memory consumption. See simulate_stepwise_multiprocessing for this function wrapped in a tuple.
Uses multiprocessing to parallelize reactions. This does not work that well because the individual reactions are not that complicated.
Will only work where achem is a class, not an instance of a class.
This is the test harness for AChemKit.sims_simple.
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.
Bases: AChemKit.sims_simple_test.TestItterative
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.