sbml_to_memilio.cpp File Reference
|
CPP API
|
#include "memilio/config_internal.h"#include "memilio/utils/logging.h"#include "memilio/io/io.h"#include <boost/algorithm/string.hpp>#include <boost/filesystem.hpp>#include <sbml/SBMLTypes.h>#include <cmath>#include <fstream>#include <iostream>#include <memory>#include <string>#include <vector>Functions | |
| void | append_brackets (std::string &leading_bracket, std::string &trailing_bracket, std::string &formula) |
| Appends leading and trailing brackets to a formula. More... | |
| mio::IOResult< void > | create_cmake (const std::string &filename, const std::string &path) |
| Create the CMakeLists.txt file for the model folder. More... | |
| mio::IOResult< void > | create_example_cpp (Model &model, const std::string &filename, const std::string &path) |
| Creates the corresponding file to example.cpp. More... | |
| void | create_folder (const std::string &foldername, const std::string &path) |
| Creates a folder with the given name to store the generated model files. More... | |
| mio::IOResult< void > | create_infection_state (Model &model, const std::string &filename, const std::string &path) |
| Creates the infection_states.h file. More... | |
| mio::IOResult< void > | create_model_cpp (const std::string &filename, const std::string &path) |
| Create the model.cpp file. More... | |
| mio::IOResult< void > | create_model_h (Model &model, const std::string &filename, const std::string &path) |
| Create the model.h file. More... | |
| mio::IOResult< void > | create_parameters (Model &model, const std::string &filename, const std::string &path) |
| Creates the parameters.h file. More... | |
| mio::IOResult< std::string > | find_tmax (const ASTNode &trigger, Model &model, const std::string &model_namespace) |
| Returns the maximum time mentioned in a formula or an error. More... | |
| mio::IOResult< std::string > | format_event_formulas (std::string &formula, Model &model, const std::string &model_namespace) |
| Formats the formula for an event for use in the example.cpp file. More... | |
| mio::IOResult< std::string > | format_event_trigger (const std::string &formula, Model &model, const std::string &model_namespace) |
| Formats the trigger formula for an event for use in the example.cpp file. More... | |
| mio::IOResult< std::string > | format_event_variable (const std::string &formula, Model &model, const std::string &model_namespace) |
| Returns the string to change variables inside an event for the example.cpp file. More... | |
| void | format_files (const std::string &filename, const std::string &path) |
| Calls clang-format to format the generated files. More... | |
| std::string | format_main_formula (Model &model, const std::string &math_string, const std::string &model_namespace) |
| Formats a formula for the example.cpp file. More... | |
| std::string | get_filename (const std::string &filepath) |
| Get the filename. More... | |
| std::string | get_initial_assignment (Species &species, Model &model, const std::string &model_namespace) |
| Returns the initial assignment of a species for the example.cpp file. More... | |
| mio::IOResult< std::string > | get_path (std::string folder_name) |
| Get the path to a folder. More... | |
| int | main (int argc, char *argv[]) |
| Runs the program. More... | |
| mio::IOResult< void > | modify_cmakelists (const std::string &filename, const std::string &path) |
| Create the additional lines for the CmakeLists.txt file. More... | |
| void | strip_formula (std::string &leading_bracket, std::string &trailing_bracket, std::string &formula) |
| Strips leading and trailing brackets and minus signs from a formula. More... | |
| mio::IOResult< void > | verify_model_suitability (const Model &model) |
| Checks that a model is suitable, i.e. More... | |
Function Documentation
◆ append_brackets()
| void append_brackets | ( | std::string & | leading_bracket, |
| std::string & | trailing_bracket, | ||
| std::string & | formula | ||
| ) |
Appends leading and trailing brackets to a formula.
- Parameters
-
[in] leading_bracket The string storing leading brackets and minus signs. [in] trailing_bracket The string storing trailing brackets. [in,out] formula The formula to be processed.
This function adds the content of the leading_bracket string to the beginning of the formula and the content of the trailing_bracket string to the end of the formula. This function can be used to reverse the effect of :cpp:func:strip_formula(std::string & leading_bracket, std::string & trailing_bracket, std::string & formula) with respect to the formula string.
◆ create_cmake()
| mio::IOResult<void> create_cmake | ( | const std::string & | filename, |
| const std::string & | path | ||
| ) |
Create the CMakeLists.txt file for the model folder.
- Parameters
-
[in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Success or error code.
Creates the generic CMakeLists.txt file for the model folder, assuming that only the files generated by this program are needed. The file location is generated using filename and path and the file is stored in the generated folder.
◆ create_example_cpp()
| mio::IOResult<void> create_example_cpp | ( | Model & | model, |
| const std::string & | filename, | ||
| const std::string & | path | ||
| ) |
Creates the corresponding file to example.cpp.
- Parameters
-
[in] model The model to be processed. [in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Success or error code.
The filename is based on the given filename and path. The file first contains generic input, then the model, it's parameters and specis are initialized. The model is simulated in steps to add events that are triggered by a specific time. In the end the model is simulated for another 50 days. The results are printed to the console and saved in a file as a table.
◆ create_folder()
| void create_folder | ( | const std::string & | foldername, |
| const std::string & | path | ||
| ) |
Creates a folder with the given name to store the generated model files.
- Parameters
-
[in] foldername The name of the folder to be created. [in] path The path where the folder should be created -this needs to exist.
Extracts the filename using :cpp:func:get_filename(const std::string& filename), converts it to lower case and creates a folder with the resulting name at the location given by path using boost::filesystem.
◆ create_infection_state()
| mio::IOResult<void> create_infection_state | ( | Model & | model, |
| const std::string & | filename, | ||
| const std::string & | path | ||
| ) |
Creates the infection_states.h file.
- Parameters
-
[in] model The model to be processed. [in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Succes or error code.
Extracts the filename using :cpp:func:get_filename(const std::string& filename), converts it to lower case and creates a file with the resulting name using boost::filesystem at the location given by path. Then it writes the species in the model as infection states to the file.
◆ create_model_cpp()
| mio::IOResult<void> create_model_cpp | ( | const std::string & | filename, |
| const std::string & | path | ||
| ) |
Create the model.cpp file.
- Parameters
-
[in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Success or error code.
Creates the generic model.cpp file. The file location is generated using the filename and the path.
◆ create_model_h()
| mio::IOResult<void> create_model_h | ( | Model & | model, |
| const std::string & | filename, | ||
| const std::string & | path | ||
| ) |
Create the model.h file.
- Parameters
-
[in] model The model to be processed. [in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Success or error code.
Creates the model.h file based on the filename and path. First some generic input is written to the file. Then the get_derivatives-function is generated. It
- creates an index variable for every species
- creates a lambda function for every function definition in the model to have it at hand
- goes through every reaction in the model and generates the corresponding code. This is done in local scopes to make sure local parameters don't cause errors.
- checks every rule whether it is a RateRule and generates code for it if it is.
In the end it appends a generic serialization function.
◆ create_parameters()
| mio::IOResult<void> create_parameters | ( | Model & | model, |
| const std::string & | filename, | ||
| const std::string & | path | ||
| ) |
Creates the parameters.h file.
- Parameters
-
[in] model The model to be processed. [in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Succes or error code.
Extracts the filename using :cpp:func:get_filename(const std::string& filename), converts it to lower case and creates a file with the resulting name using boost::filesystem at the location given by path. Then it creates one struct for every parameter in the model. It uses the value as returned by libsbml as default value. (This may be overwritten in the example.cpp file.)
◆ find_tmax()
| mio::IOResult<std::string> find_tmax | ( | const ASTNode & | trigger, |
| Model & | model, | ||
| const std::string & | model_namespace | ||
| ) |
Returns the maximum time mentioned in a formula or an error.
- Parameters
-
[in] trigger The formula to be processed, given as an ASTNode. [in] model The model where the formula stems from. [in] model_namespace The namespace of the model.
- Returns
- mio::IOResult<std::string> The resulting string.
This function assumes a very specific layout of the formula. It needs to be a comparison between exaclty two values. If that is not the case, it prints an error. Then it expects one of the two nodes to be a time node. The other node has the comparison value and is returned. It is always assumed, but never checked, that we have a positive comparison, i.e. the time is indeed the maximum time. This function is used to find the maximum time until which an event runs. It is used for the generation of the
example.cpp file.
◆ format_event_formulas()
| mio::IOResult<std::string> format_event_formulas | ( | std::string & | formula, |
| Model & | model, | ||
| const std::string & | model_namespace | ||
| ) |
Formats the formula for an event for use in the example.cpp file.
- Parameters
-
[in] formula The formula to be processed. [in] model The model where the formula stems from. [in] model_namespace The namespace of the model.
- Returns
- mio::IOResult<std::string> The resulting string.
Goes through the parts of the formula delimited by spaces. It first strips leading/trailing braces and leading minus signs. Then it checks if the part is a parameter, species or compartment. If it is a parameter, it is replaced by the corresponding parameter in the model. If it is a species, it is replaced by the corresponding species in the model. If it is a compartment, it is replaced by the size of the compartment. If it is pi, it is replaced by M_PI. If it is time, it is replaced by t. The leading and trailing braces are then re-added to the part and the parts are joined together.
◆ format_event_trigger()
| mio::IOResult<std::string> format_event_trigger | ( | const std::string & | formula, |
| Model & | model, | ||
| const std::string & | model_namespace | ||
| ) |
Formats the trigger formula for an event for use in the example.cpp file.
- Parameters
-
[in] formula The formula to be processed. [in] model The model where the formula stems from. [in] model_namespace The namespace of the model.
- Returns
- mio::IOResult<std::string> The resulting string.
Goes through the parts of the formula as identified by spaces.
- It first strips leading/trailing braces and leading minus signs.
- Then it checks if the part is a parameter, species or compartment.
- If it is a parameter, it is replaced by the corresponding parameter in the model.
- If it is a species, it prints an error as they are not supported.
- If it is a compartment, it is replaced by the size of the compartment.
- If it is pi, it is replaced by M_PI.
- If it is time, it prints an error. The leading and trailing braces are then re-added to the part and the parts are joined together.
◆ format_event_variable()
| mio::IOResult<std::string> format_event_variable | ( | const std::string & | formula, |
| Model & | model, | ||
| const std::string & | model_namespace | ||
| ) |
Returns the string to change variables inside an event for the example.cpp file.
- Parameters
-
[in] formula The formula to be processed. [in] model The model where the formula stems from. [in] model_namespace The namespace of the model.
- Returns
- mio::IOResult<std::string> The resulting string or an error code.
Checks whether the formula is a parameter, species or compartment. In the first two cases it returns the code to get the corresponding values, in the last case it prints an error message.
◆ format_files()
| void format_files | ( | const std::string & | filename, |
| const std::string & | path | ||
| ) |
Calls clang-format to format the generated files.
- Parameters
-
[in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- bool Whether the writing process was successful.
Calls clang-format using the system command. The command is generated using filename and path. Depending on the return code, an error or info message is printed.
◆ format_main_formula()
| std::string format_main_formula | ( | Model & | model, |
| const std::string & | math_string, | ||
| const std::string & | model_namespace | ||
| ) |
Formats a formula for the example.cpp file.
- Parameters
-
[in] model The model where the formula stems from. [in] math_string A formula from the AST/SBML model in string representation (use e.g. SBML_formulaToL3String). [in] model_namespace The namespace of the model.
- Returns
- std::string The formatted formula.
This function goes through the parts of the formula as identified by spaces. It first strips leading/trailing braces and leading minus sings. Then it checks if the part is a parameter, species or compartment. If it is a parameter, it is replaced by the corresponding parameter in the model. If it is a species, it is replaced by the corresponding species in the model. If it is a compartment, it is replaced by the size of the compartment. If it is pi, it is replaced by M_PI. If it is time, it is replaced by 0.0. The leading and trailing braces are then re-added to the part and the parts are joined together.
◆ get_filename()
| std::string get_filename | ( | const std::string & | filepath | ) |
Get the filename.
- Parameters
-
[in] filepath A path including the filename.
- Returns
- std::string The path without the filename.
Uses boost::filesystem::path to get the path to the input file, then uses stem() to get the name of the input file without file ending.
◆ get_initial_assignment()
| std::string get_initial_assignment | ( | Species & | species, |
| Model & | model, | ||
| const std::string & | model_namespace | ||
| ) |
Returns the initial assignment of a species for the example.cpp file.
- Parameters
-
[in] species The species to be processed. [in] model The model where the species stems from. [in] model_namespace The namespace of the model.
- Returns
- std::string The formatted initial assignement.
First it checks whether an initial amount is given for the species. Then it checks the other possibilites for initial assignements:
- If an initial concentration is given, it is used
- If an initial assignment is given, it is used. This could be
- a values
- a other parameter
- a formula, which would then be parsed using
- See also
- format_main_formula
◆ get_path()
| mio::IOResult<std::string> get_path | ( | std::string | folder_name | ) |
Get the path to a folder.
- Parameters
-
[in] folder_name The name of the folder to be searched for.
- Returns
- IOResult<std::string> The path to the folder or an error code.
This function tries to find the folder called folder_name. It checks whether it is in the current directory or any of the two parent directories. It makes sure that it does not accidently use the folder with the same name in the build directory. This function is thus tailored to find the folder for the sbml generated model files. If the folder is not found, it returns an error code.
◆ main()
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Runs the program.
- Parameters
-
[in] argc The number of command line arguments. [in] argv The command line arguments, here the name of the file that should be processed.
This function expects exaclty one parameter which should be the path to the file that should be processed. If more or less parameters are given, it raises an error. If the correct number of parameters is given, it treats the file as a SBML file and generates the MEmilio code for it.
◆ modify_cmakelists()
| mio::IOResult<void> modify_cmakelists | ( | const std::string & | filename, |
| const std::string & | path | ||
| ) |
Create the additional lines for the CmakeLists.txt file.
- Parameters
-
[in] filename The name of the file to be processed. [in] path The path where the file should be created.
- Returns
- mio::IOResult<void> Success or error code.
Appends the necessary commands for compilation to the CMakeLists.txt file in path using the filename.
◆ strip_formula()
| void strip_formula | ( | std::string & | leading_bracket, |
| std::string & | trailing_bracket, | ||
| std::string & | formula | ||
| ) |
Strips leading and trailing brackets and minus signs from a formula.
- Parameters
-
[in,out] leading_bracket The string to store leading brackets and minus signs. [in,out] trailing_bracket The string to store trailing brackets. [in,out] formula The formula to be processed.
This function goes through the formula and removes leading brackets and minus signs. It also removes trailing brackets and commas. The leading brackets and minus signs are appended to the leading_bracket string, the trailing brackets to the trailing_bracket string. The formula is modified in place. This function can be reversed by calling :cpp:func:append_brackets(std::string & leading_bracket, std::string & trailing_bracket, std::string & formula).
◆ verify_model_suitability()
| mio::IOResult<void> verify_model_suitability | ( | const Model & | model | ) |
Checks that a model is suitable, i.e.
only uses one compartment.
- Parameters
-
[in] model The model to be checked.
- Returns
- mio::IOResult<void> Succes or error code.
This function checks whether the model has exactly one compartment. If it does not, it returns an error code.
Generated by