Because of the complexity of ChemChains sometimes it is hard to modify it without creating unwanted errors in other parts of the code, especially for someone who isn't familiar with the structure of the program. Allowing plugins serves as a way for code written by others to be executed during a simulation, allowing them to have a their plugin issue commands to ChemChains without having to have them worry about correctly modifying the main program. The purpose of this document is to serve as a guide for making a plugin for ChemChains. First the structure of a plugin in relation to ChemChains will be detailed, following that how the Plugin is treated on an operational level by ChemChains will be detailed. There is an exmple plugin in the plugins folder 'Example'.
In the ChemChains directory there is a folder called Plugins, within this folder is a file called config.txt, which contains a list of all plugins to be executed by ChemChains. The source for a plugin called 'Extension' would be in '/ChemChains/Plugins/Extension' and the library that will be loaded will be '/ChemChains/Plugins/Extension/Extension.so'. The abstract class Plugin in Plugin.hpp functions as an API from which plugins inherit. There is an empty
Throughout a simulation ChemChains will be calling different functions on the plugin, here is a breakdown of what will happen:
The initialize() function is called.
2. Pre Simulation Activities, called before each Simulation
ChemChains will populate the variables listed in Plugin with their setters.
The function preSim() is called.
The function bool nSpecs() is called.
If true was returned from bool nSpecs the function string getSpecs() will be called .
The function nLogic() is called.
If true was returned from bool nLogic the function string getLogic() will be called.
3. Mid Simulation Activities, called on every iteration
The variable t will be updated to the current step.
The function string retrieveNodeLevel() will be called.
If a string was returned from retrieveNodeLevel() the current level of the boolean node with that name will be sent to sendNodeLevel(string, int)
The function midSim() will be called.
The function pair<string, int> setInputNodeLevel() will be called until it returns a blank string.
4. Post Simulation Activities, called after each Simulation
The function postSim() will be called.
5. After all of the Simulations are finished
The function close() will be called.
When running multiple simulations the order of these activities would be something like;
1, 2, 3, 3, 3, ..., 4, 2, 3, 3, 3, ..., 4, 5
More information about the expected behaviors and purposes of these functions can be found in the example plugin.