Representation of a chemical network

This module provides routines to read, compare, manipulate chemical networks. The new chemical networks can than also be written to files in various formats.

Usage example

This examples reads a network from a ProDiMo Reaction.in renames a species in it and writes the network back to a new file in the same format.

import prodimopy.chemistry.network as pcnet

# Create a new network and load the rates from the Reactions.in (local directory)
reacin=pcnet.ReactionNetworkPin()
reacin.load_reactions("Reactions.in")

# now do the renaming
reacin.renameSpecies("C2H6","CH3CH3")

# write it again in a new file, be careful if you directly want to overwrite your old file.
reacin.write_reactions("Reactions.in.renamed")

Source documentation

Created on 15 Feb 2021

@author: Christian Rab

class prodimopy.chemistry.network.ReactionNetwork(name='ReactionNetwork')[source]

General representation of a chemical reaction network.

Todo

make it an abstract class that requires the child classes to implement the load_reactions routine. Currently this only works for the Reactions.out from ProDiMo.

Create a new Reaction Network.

name

string: A name for the reaction network

reactions

list(Reaction): The list of reactions included in the network.

filename

string: The name/path of the file containing the Reaction network.

non_species

A list of Species names that are considerd as non species (not really a chemical species) but might be included in the network. FIXME: provide a way to change that list

property species

The list of individual species in the network.

duplicates()[source]

Returns possible duplicate reactions in the network.

TODO: is quite slow TODO: properly define what is a duplicate

Returns:

Returns a list of the duplicate Reactions or an empty list if there are no duplicates

Return type:

list(Reaction)

renameSpecies(old, new, variants=['', '+', '#'], log=True)[source]

Renames species with name old with species name new in the whole network.

Parameters:
  • old (str) – The species name of the species that should be renamed.

  • new (str) – The new name of the species.

  • variants (array_like(str)) – extension to the species names that should also be considered for renaming. for example if variants=[“”,”+”,”#”] and the old name is SP and the new name is SPNEW the routine would replace also species `SP,SP+,SP# with SPNEW,SPNEW+,SPNEW# , respectively. Types has to at least contain one element. Default: [“”,”+”,”#”]

  • log (boolean) – log on changes on the screen. Default: True

Returns:

The total number of changed Reactions.

Return type:

int

compareSpecies(reactionNetwork)[source]

Compares the species list of two networks.

Parameters:

reactionNetwork (ReactionNetwork) – Another reaction network

Returns:

  • (tuple)

  • * boolean … equal or not

  • * list … list of species only in old network

  • * list … list of species only in new network

compare(reactionNetwork, printresults=False, eqfunc=None, chgfunc=None, log=True)[source]

Compares the network to the given reaction network. Currently simply prints out the results to stdout.

Parameters:
  • reactionNetwork (ReactionNetwork) – Another reaction network

  • printresults (boolean) – Print the results to stdout

  • eqfunc – Pass a function that decides if two Reactions are equal. The function must take as an argument the outcome of the Reaction compare function.

  • chgfunc – Pass a function that decides if two Reactions are the same Reactoin but some other quantities changes (coefficients, type etc). The function must take as an argument the outcome of the Reaction compare function.

  • log (boolean) – Include log output (print statements) or not.

Returns:

  • (tuple)

  • * boolean … equal or not

  • * list … list of changed reactions

  • * list … list of reactions only in this network

  • * list … list of reactions only in the passed network

abstract load_reactions(filename=None)[source]

In this routine the reading of the Reaction network needs to be implemented.

Fills in the reactions field in this class.

Parameters:

filename (str) – The name/path of the file to read

abstract load_rates(filename=None)[source]

In this routine the reading of rate coeeficients need to be implemented.

Parameters:

filename (str) – The name/path of the file to read

class prodimopy.chemistry.network.Reaction[source]

General representation of one chemical reaction.

id

int: The Reaction Id as is

idU

int: The Umist reaction id … it is unclear what this actually is.

type

string: The Reation type identifier as used in ProDiMo

gasphase

boolean: Gas phase reaction or not.

reactants

array_like: The list of reaction reactants (Species names)

products

array_like: The list of reaction products (Species names)

coeffs

array_like(float,shape=): The [alpha,beta,gamma] coefficients per temperature range. For multipe temperature ranges it will become a 2D array with shape (3,number of t ranges) e.g. [[alpha,beta and gamma],[alpha2,beta2,gamma2]] for two temperature ranges. FIXME: might be hard to handle as it can either be 1D or 2D array. Could be fixed with a @property decorator

temps

array_like The temperature range ([min,max]). Can have more entries if there are several temperature ranges. The shape will than be (2,number of t ranges)). FIXME: might be hard to handle as it can either be 1D or 2D array.

rate

float: The real rate for a given set of physical conditions.

clem

str: Something from UMIST do not know what it is.

accuracy

str: A string describing the quality of the reactions coefficients

comment

str: Any relevant comment for this particular reaction.

compare(reaction)[source]

Compares the Reaction to the passed reaction.

The routines evaluates for a selection of the properties from class:`Reaction individually if it is equal or not. See below for the return value.

Parameters:

reaction (Reaction) –

Returns:

  • dictionary

  • A dictionary with boolean values with the following keys. The keys have the

  • same names as the properties of the Reaction.

  • * type

  • * gasphase

  • * reactants

  • * products

  • * coeffs

  • * temps

  • ..todo

    • deal with comparison of the network if rates only exist in one network

    • the value of the rate coeffs are not compared/checked

    • make the tolerances for comparison of the rate a parameter somehow

class prodimopy.chemistry.network.ReactionNetworkPout(name='ReactionNetworkPout', modeldir=None)[source]

Implementation of ReactionNetwork for the Reaction.out of a ProDiMo model.

Parameters:

modeldir (str) – If set the init routine trys to load the Reactions.out and the rates log file (at the moment). But continues if it does not work

compare(reactionNetwork, printresults=False, eqfunc=None, chgfunc=None, log=True)

Compares the network to the given reaction network. Currently simply prints out the results to stdout.

Parameters:
  • reactionNetwork (ReactionNetwork) – Another reaction network

  • printresults (boolean) – Print the results to stdout

  • eqfunc – Pass a function that decides if two Reactions are equal. The function must take as an argument the outcome of the Reaction compare function.

  • chgfunc – Pass a function that decides if two Reactions are the same Reactoin but some other quantities changes (coefficients, type etc). The function must take as an argument the outcome of the Reaction compare function.

  • log (boolean) – Include log output (print statements) or not.

Returns:

  • (tuple)

  • * boolean … equal or not

  • * list … list of changed reactions

  • * list … list of reactions only in this network

  • * list … list of reactions only in the passed network

compareSpecies(reactionNetwork)

Compares the species list of two networks.

Parameters:

reactionNetwork (ReactionNetwork) – Another reaction network

Returns:

  • (tuple)

  • * boolean … equal or not

  • * list … list of species only in old network

  • * list … list of species only in new network

duplicates()

Returns possible duplicate reactions in the network.

TODO: is quite slow TODO: properly define what is a duplicate

Returns:

Returns a list of the duplicate Reactions or an empty list if there are no duplicates

Return type:

list(Reaction)

renameSpecies(old, new, variants=['', '+', '#'], log=True)

Renames species with name old with species name new in the whole network.

Parameters:
  • old (str) – The species name of the species that should be renamed.

  • new (str) – The new name of the species.

  • variants (array_like(str)) – extension to the species names that should also be considered for renaming. for example if variants=[“”,”+”,”#”] and the old name is SP and the new name is SPNEW the routine would replace also species `SP,SP+,SP# with SPNEW,SPNEW+,SPNEW# , respectively. Types has to at least contain one element. Default: [“”,”+”,”#”]

  • log (boolean) – log on changes on the screen. Default: True

Returns:

The total number of changed Reactions.

Return type:

int

property species

The list of individual species in the network.

reactions

list(Reaction): The list of reactions included in the network.

filename

string: The name/path of the file containing the Reaction network.

non_species

A list of Species names that are considerd as non species (not really a chemical species) but might be included in the network. FIXME: provide a way to change that list

name

string: A name for the reaction network

load_reactions(filename='Reactions.out')[source]

Reads a reaction network in the format of the ProDiMo Reactions.out.

Fills in the reactions field in this class.

Parameters:

filename (str) – The name/path of the file to read

load_rates(filename='rate_coeffs_1NZZ.log')[source]

Load the real rates for a given set of physical conditions. Can be use for comparison.

Has to be run after load_reactions.

Todo

Is not general; just a test at the moment.

class prodimopy.chemistry.network.ReactionNetworkPin(name='ReactionNetworkPin', modeldir=None)[source]

Implementation of ReactionNetwork for the Reactions.in of ProDiMo.

Parameters:
  • name (str) – a name for the network

  • modeldir (str) – If set, the init routine trys to load the Reactions.in from modeldir. But continues if it does not work.

compare(reactionNetwork, printresults=False, eqfunc=None, chgfunc=None, log=True)

Compares the network to the given reaction network. Currently simply prints out the results to stdout.

Parameters:
  • reactionNetwork (ReactionNetwork) – Another reaction network

  • printresults (boolean) – Print the results to stdout

  • eqfunc – Pass a function that decides if two Reactions are equal. The function must take as an argument the outcome of the Reaction compare function.

  • chgfunc – Pass a function that decides if two Reactions are the same Reactoin but some other quantities changes (coefficients, type etc). The function must take as an argument the outcome of the Reaction compare function.

  • log (boolean) – Include log output (print statements) or not.

Returns:

  • (tuple)

  • * boolean … equal or not

  • * list … list of changed reactions

  • * list … list of reactions only in this network

  • * list … list of reactions only in the passed network

compareSpecies(reactionNetwork)

Compares the species list of two networks.

Parameters:

reactionNetwork (ReactionNetwork) – Another reaction network

Returns:

  • (tuple)

  • * boolean … equal or not

  • * list … list of species only in old network

  • * list … list of species only in new network

duplicates()

Returns possible duplicate reactions in the network.

TODO: is quite slow TODO: properly define what is a duplicate

Returns:

Returns a list of the duplicate Reactions or an empty list if there are no duplicates

Return type:

list(Reaction)

renameSpecies(old, new, variants=['', '+', '#'], log=True)

Renames species with name old with species name new in the whole network.

Parameters:
  • old (str) – The species name of the species that should be renamed.

  • new (str) – The new name of the species.

  • variants (array_like(str)) – extension to the species names that should also be considered for renaming. for example if variants=[“”,”+”,”#”] and the old name is SP and the new name is SPNEW the routine would replace also species `SP,SP+,SP# with SPNEW,SPNEW+,SPNEW# , respectively. Types has to at least contain one element. Default: [“”,”+”,”#”]

  • log (boolean) – log on changes on the screen. Default: True

Returns:

The total number of changed Reactions.

Return type:

int

property species

The list of individual species in the network.

reactions

list(Reaction): The list of reactions included in the network.

filename

string: The name/path of the file containing the Reaction network.

non_species

A list of Species names that are considerd as non species (not really a chemical species) but might be included in the network. FIXME: provide a way to change that list

name

string: A name for the reaction network

load_reactions(filename='Reactions.in', fmt=None, threeReactants=True)[source]

Reads a reaction network in the format of the ProDiMo Reactions.in

Fills in the reactions field in this class.

Todo

Include reading of T-dependent rates for the csv format. More sophisticated guessing of the file format.

Parameters:
  • filename (str) – The name/path of the file to read.

  • fmt (str) – Format of the file. Currently either in for old Reactions.in or csv for the UMIST csv format. If None the routine trys to guess the format (primitive at the moment).

write_reactions(filename='Reactions.in.new', fmt=None)[source]

Writes the network to a file. The default format is the one from ProDiMo Reactions.in.

Todo

does not work yet for reactions with multiple temperatures.

Warning

Not well tested … so be carefull.

Parameters:
  • filename (str) – The name/path of the file to read

  • fmt (str) – If None format is the one from ProDiMo. if csv it is written in a csv mode.

load_rates(filename=None)[source]

In this routine the reading of rate coeeficients need to be implemented.

Parameters:

filename (str) – The name/path of the file to read