pyRBM.Core package
Submodules
pyRBM.Core.Cache module
- class ModelPaths(matched_rules_filename: str | None = None, compartments_filename: str | None = None, model_folder_path_to: str | None = None, model_name: str | None = '', classes_filename: str | None = None, metarules_filename: str | None = None)
Bases:
objectProvides paths for created and loaded model files.
All paths follow the format (model_folder_path_to)(model_name)(filename).
Filenames should NOT include the file ending.
A new ModelPaths object should overwrite the old object when a new model is saved/loaded.
- compartment_path
the path to the compartments .json file saved or loaded or created at this object’s creation, if it was saved/loaded, otherwise None.
- Type:
str|None
- classes_path
the path to the classes .json file saved or loaded or created at this object’s creation, if it was saved/loaded, otherwise None.
- Type:
str|None
- matched_rules_path
the path to the matched_rules .json file saved or loaded or created at this object’s creation, if it was saved/loaded, otherwise None.
- Type:
str|None
- metarule_path
the path to the metarule .json file saved or loaded at this object’s creation, if it was saved/loaded, otherwise None.
- Type:
str|None
- property classes_path: str | None
The path to the classes .json file saved or loaded or created at this object’s creation, if it was saved/loaded, otherwise None
- property compartments_path: str | None
The path to the compartments .json file saved or loaded or created at this object’s creation, if it was saved/loaded, otherwise None.
- loadClasses(model_prefix: str = 'model_', classes_filename: str | None = None, classes_dict: dict | None = None) tuple[dict, dict]
Loads classes from either a model class json file (see ModelCreation for details) or from a pyRBM.Build.Classes dictionary, and returns pyRBM.Simulation’s requirements of a class_dict (a dict of all non-model classes) and a built_in_class_dict (a dict of all model classes).
Requires either classes_filename or classes_dict to be passed as an argument.
If both arguments are provided, the function will load from the json at the classes_filename path.
- loadCompartments(compartments_filename: str | None = None, build_compartments_dict: dict[str, dict[str, Any]] | None = None) list[pyRBM.Simulation.Compartment.Compartment]
Loads compartments from either a model compartment json file (see ModelCreation for details) or from a pyRBM.Build.Compartments dictionary.
Requires either compartments_filename or build_compartments_dict to be passed as an argument.
If both arguments are provided, the function will load from the json at the compartments_filename path.
- Parameters:
- Returns:
pyRBM.Simulation compatible Compartments for each compartment in either compartment_file or build_compartments_dict.
- Return type:
- loadMatchedRules(compartments, num_builtin_classes: int, random_state, matched_rules_filename: str | None = None, matched_rule_dict: dict | None = None) tuple[list[pyRBM.Simulation.Rule.Rule], list[list[int]]]
Loads all rules from a model matched rules json (see ModelCreation for details).
- Parameters:
() (compartments) –
num_builtin_classes –
matched_rules_filename – the string of the file compartment containing the rule definitions.
matched_rule_dict –
- Returns: [a list of rules remapped to all possible compartment sets,
a 2d list of lists of satisfying indices for the corresponding rule]
- processFilenameOrDict(filename: str | None, provided_dict: dict[str, Any] | None) dict[str, Any] | None
- readDictFromJSON(filename: str) dict
Read a JSON file found at the filename path and return the dictionary representation of it. :param filename: the string representation of the path to the json file to be loaded (excluding the .json file ending). :type filename: str
- Returns:
dictionary representation of the JSON file found at the path, filename.
- Return type:
- writeDictToJSON(dict_to_write: dict, filename: str, dict_name: str = '') None
Writes dict_to_write to a json file at the filename path. Orders the json keys alphabetically and uses utf-8 encoding.
Creates all folders and then the file if they don’t already exist.
- Parameters:
dict_to_write (dict) – a dictionary to be written to a .json file.
filename (str) – the string representation of the path and filename of the json file that is being written to (excluding the .json file ending).
dict_name (str, optional) – a string to include to provide user friendly output as to which file is being written.
pyRBM.Core.Interfaces module
pyRBM.Core.Model module
pyRBM.Core.Plotting module
pyRBM.Core.StringUtilities module
- replaceVarName(propensity_str, var_name, replacement, ignore_underscore=True)