Package: crnsimulator
crnsimulatorSimulate Chemical Recation Networks (CRNs) using Ordinary Differential Equations (ODEs).ExamplesUsing thecrnsimulatorexecutable:Create a test file with your CRN:File:oscillator.crn# Rock-Paper-Scissors Oscillator

A + B -> B + B [k = 0.2]
B + C -> C + C [k = 0.4]
C + A -> A + A [k = 0.7]And pipe it into the crnsimulator:~$crnsimulator-oozzy<oscillator.crnThis writes the ODE system to an executable python script:ozzy.pyCheck the command line parameters of ozzy.py. You have to set initial species
concentrations, and choose an output-format, e.g.:~$python./ozzy.py--p0A=0.1B=1e-2C=1e-3--t810000--pyplotozzy.pdfThis example plots a simulation on a linear-time scale (0 - 10000) to the fileozzy.pdf.Tips and Tricks:You can pass the command line options for ozzy.py directly tocrnsimulator.
This will automatically simulate your ODE system. Use --force to overwrite an
existingozzy.pyscript.~$crnsimulator--p0A=0.1B=1e-2C=1e-3--t810000-oozzy--pyplotozzy.pdf<oscillator.crnYou can specify the CRN in a single line:~$echo"A+B->2B [k=0.2]; B+C->2C [k=0.4]; C+A->2A"|crnsimulator--p0A=0.1B=1e-2C=1e-3--t810000-oozzy--pyplotozzy.pdfYou can specify default initial concentrations of species:~$echo"A @i 0.1; B @i 1e-2; A+B->2B [k=0.2]; B+C->2C [k=0.4]; C+A->2A"|crnsimulator--p0C=1e-3--t810000-oozzy--pyplotozzy.pdfIf you can set which species appear in the legend using --pyplot-lables. If you
are writing a new executable (you may need --force), then you can also control the order:~$echo"A @i 0.1; B @i 1e-2; A+B->2B [k=0.2]; B+C->2C [k=0.4]; C+A->2A"|crnsimulator--p0C=1e-3--t810000-oozzy--pyplotozzy.pdf--force--pyplot-labelsCBUsing thecrnsimulatorlibrary:The easiest way to get started is by looking at the crnsimulator script itself.
However, here is a small example using the above oscillating CRN.>>>fromcrnsimulatorimportReactionGraph>>>crn=[[['A','B'],['B','B'],0.2],[['B','C'],['C','C'],0.8],[['C','A'],['A','A'],0.9]]>>>RG=ReactionGraph(crn)>>>svars=['B','C','A']# let's enforce the order of species, because we can!>>>filename,odename=RG.write_ODE_lib(filename='ozzy.py',sorted_vars=svars)>>>print('Wrote ODE system file:',filename)WroteODEsystemfile:ozzy.pyThen go ahead and executeozzy.py:~$python./ozzy.py--p01=1e-62=2e-63=5e-6--t81e8--pyplotozzy.pdf--atol1e-10--rtol1e-10... or load its functions by treating it as a python library:# Import>>>importnumpyasnp>>>fromscipy.integrateimportodeint>>>fromcrnsimulatorimportget_integrator>>>odesys=get_integrator(filename,function=odename)>>>odeplt=get_integrator(filename,function='ode_plotter')# Simulate>>>p0=[1e-6,2e-6,5e-6]# order of svars>>>time=np.linspace(0,1e8,num=10_000)>>>ny=odeint(odesys,p0,time,(None,),atol=1e-10,rtol=1e-10).T# Plot>>>odeplt(`ozzy.pdf`,time,ny,svars)... or include the prebuilt integrator in you own script (like the crnsimulator exectuable):>>>fromcrnsimulatorimportget_integrator>>>integrate=get_integrator(filename)>>>integrate(args)# args = <argparse.ArgumentParser()>Installation~$pythonsetup.pyinstallVersionv0.9 -- code cleanupremoved networkx dependencymoved plotting libraries and functions into a separate file to avoid automatic import.v0.8 -- beta statusnow using loggingpython >= 3.7 onlyimproved header documentationusing entry_points for crnsimulator scriptset defaultrate = 1 (new postprocessing strandard)new commandline arguments: labels, labels-strictsupport the constant concentration flag