gMCSpy.Utilities module

add_quotes_inside_brackets(input_string)[source]
createLog(folderLogPath: str = 'logs/log')[source]

Creates a log file with the current date and time, and returns the filename. This functions also creates the folder to save the log file if it does not exist. It is used to save the log of the optimization process depending on the verbosity level.

createToyModel()[source]

Create a toy model for testing purposes. Creates a model with 9 reactions and 5 metabolites, the biomass reaction is r8 based on the model in this paper.

_images/toymodel.jpeg
loadSolutions(path: str | None = None)[source]

Load the solutions generated from the calculation of gMCSs.

Parameters:

path – Path to the folder with the solutions, if no path is given the most recent calculation in the logs folder is used.

Returns:

A dictionary with the solutions.

read_sol_log(logFile)[source]
saveSolutionDict(dict: dict, filename: str, path: str)[source]
saveSolutions(problemDict: dict, solutionDict: dict, modelStruct: Model, filename: str, path: str)[source]

Saves the solutions to a csv file.

Warning

This function has been design to save the solution of our optimization problems, it may not work for other problems.

Parameters:
  • problemDict – Dictionary containing the problem information.

  • solutionDict – Dictionary containing the solution information.

  • modelStruct – The cobra Model used to build the problem dictionary.

  • filename – Name of the file to save the solutions.

  • path – Path to save the file.

setSolver(defaultSolver, useIdicators: bool = True)[source]

Set the solver to be used for the optimization problem. This function is used automatically set the correct interface based on the solver chosen. Current options are ‘cplex’, ‘gurobi’ and ‘scip’.

Parameters:
  • defaultSolver – The solver to be used for the optimization problem. Must be one of the options above.

  • indicator – If True, the solver will be set to use indicators. If False, the solver will be set to not use indicators. The function also checks if the solver has the capability to use indicators. If the solver does not have the capability it returns turns the indicators off and the Big M method is implemented.

Returns:

  • The interface to be used for the optimization problem.

  • A boolean indicating if the solver will use indicators or not.