biosimulators_utils.model_lang.smoldyn package#

Submodules#

biosimulators_utils.model_lang.smoldyn.simularium_converter module#

Using the Biosimulators side of Smoldyn to generate a modelout.txt Smoldyn file for a specified OMEX/COMBINE archive which then is used to generate a .simularium file for the given simulation. That .simularium file is then stored along with the log.yml and report.{FORMAT} relative to the simulation. Remember: each simulation, while not inherently published, has the potential for publication based purely on the simulation’s ability to provide a valid OMEX/COMBINE archive. There exists (or should exist) an additional layer of abstraction to then validate and verify the contents therein.

class biosimulators_utils.model_lang.smoldyn.simularium_converter.BiosimulatorsDataConverter(archive: SmoldynCombineArchive)[source]#

Bases: ABC

static generate_camera_data_object(position: ndarray, look_position: ndarray, up_vector: ndarray) CameraData[source]#
static generate_display_data_object(name: str, radius: float, display_type=DISPLAY_TYPE.SPHERE, obj_color: str | None = None) DisplayData[source]#
generate_display_data_object_dict(agent_names: List[Tuple[str, str, float, str]]) Dict[str, DisplayData][source]#

Generate a display object dict.

Parameters:
  • agent_namesList[Tuple[str, str, float]] -> a list of tuples defining the Display Data configuration parameters.

  • such (The Tuple is expected to be as) – [(agent_name: str, display_name: str, radius: float, color: str)]

Returns:

Dict[str, DisplayData]

generate_input_file_data_object(model_output_file: str | None = None) InputFileData[source]#

Generates a new instance of simulariumio.data_model.InputFileData based on self.archive.model_output_filename (which itself is derived from the model file) if no model_output_file is passed.

Parameters:

model_output_file (str) – Optional: file on which to base the InputFileData instance.

Returns:

simulariumio input file data object based on self.archive.model_output_filename

Return type:

(InputFileData)

static generate_metadata_object(box_size: ndarray[int], camera_data: CameraData) MetaData[source]#
abstract generate_output_data_object(file_data: InputFileData, display_data: Dict[str, DisplayData] | None = None, spatial_units='nm', temporal_units='ns')[source]#

Generate a data object to fit the simulariumio.TrajectoryData interface.

abstract generate_simularium_file(simularium_filename: str, box_size: float, spatial_units='nm', temporal_units='ns', n_dim=3, display_data: Dict[str, DisplayData] | None = None) None[source]#

Create a data_object, optionally translate it, convert to simularium, and save.

prepare_agent_data() AgentData[source]#

Create a new instance of an AgentData object following the specifications of the simulation within the relative combine archive.

static prepare_simularium_fp(**simularium_config) str[source]#

Generate a simularium dir and joined path if not using the init object.

Kwargs:

(obj):**simularium_config: keys are ‘simularium_dirpath’ and ‘simularium_fname’

Returns:

str: complete simularium filepath

Return type:

(obj)

static save_simularium_file(data: SmoldynData | TrajectoryData, simularium_filename) None[source]#

Takes in either a SmoldynData or TrajectoryData instance and saves a simularium file based on it with the name of simularium_filename. If none is passed, the file will be saved in self.archive.rootpath

Parameters:
  • data (Union[SmoldynData, TrajectoryData]) – data object to save.

  • simularium_filename (str) – Optional: name by which to save the new simularium file. If None is passed, will default to self.archive.rootpath/self.archive.simularium_filename

abstract translate_data_object(data_object, box_size, n_dim) TrajectoryData[source]#

Create a mirrored negative image of a distribution and apply it to 3dimensions if AND ONLY IF it contains all non-negative values.

class biosimulators_utils.model_lang.smoldyn.simularium_converter.SmoldynCombineArchive(rootpath: str, outputs_dirpath: str | None = None, model_output_filename: str | None = None, simularium_filename: str | None = None, name='my_combine_archive')[source]#

Bases: object

get_manifest_filepath() List[str] | str[source]#

Read SmoldynCombineArchive manifest files. Return all filepaths containing the word ‘manifest’.

Returns:

path if there is just one manifest file, otherwise List[str] of manifest filepaths.

Return type:

str

set_model_filepath(model_filename: str | None = None) str | None[source]#
verify_smoldyn_in_manifest() bool[source]#

Pass the return value of self.get_manifest_filepath() into a new instance of CombineArchiveReader such that the string manifest object tuples are evaluated for the presence of smoldyn.

Returns:

Whether there exists a smoldyn model in the archive based on the archive’s manifest.

Return type:

bool

class biosimulators_utils.model_lang.smoldyn.simularium_converter.SmoldynDataConverter(archive: SmoldynCombineArchive)[source]#

Bases: BiosimulatorsDataConverter

generate_output_data_object(file_data: InputFileData, display_data: Dict[str, DisplayData] | None = None, meta_data: MetaData | None = None, spatial_units='nm', temporal_units='ns') SmoldynData[source]#
Generate a new instance of SmoldynData. If passing meta_data, please create a new MetaData instance

using the self.generate_metadata_object interface of this same class.

Parameters:
  • file_data – (InputFileData): simulariumio.InputFileData instance based on model output.

  • display_data – (Dict[Dict[str, DisplayData]]): Optional: if passing this parameter, please use the self.generate_display_object_dict interface of this same class.

  • meta_data – (Metadata): new instance of Metadata object. If passing this parameter, please use the self.generate_metadata_object interface method of this same class.

  • spatial_units – (str): spatial units by which to measure this simularium output. Defaults to nm.

  • temporal_units – (str): time units to base this simularium instance on. Defaults to ns.

Returns:

SmoldynData

generate_simularium_file(box_size=1.0, spatial_units='nm', temporal_units='ns', n_dim=3, simularium_filename: str | None = None, display_data: Dict[str, DisplayData] | None = None) None[source]#

Create a data_object, optionally translate it, convert to simularium, and save.

read_model_output_dataframe() DataFrame[source]#
translate_data_object(data_object: SmoldynData, box_size: float, n_dim=3) TrajectoryData[source]#

Create a mirrored negative image of a distribution and apply it to 3dimensions if AND ONLY IF it contains all non-negative values.

write_model_output_dataframe_to_csv(save_fp: str) None[source]#

biosimulators_utils.model_lang.smoldyn.utils module#

Utilities for working with Smoldyn models

Author:

Jonathan Karr <karr@mssm.edu>

Date:

2021-04-05

Copyright:

2021, Center for Reproducible Biomedical Modeling

License:

MIT

biosimulators_utils.model_lang.smoldyn.utils.generate_new_simularium_file(archive_rootpath: str, simularium_filename: str | None = None, save_output_df: bool = False) None[source]#
Generate a new .simularium file based on the model.txt in the passed-archive rootpath using the above

validation method. Raises an Exception if there are errors present.

Parameters:
  • archive_rootpath (str) – Parent dirpath relative to the model.txt file.

  • simularium_filename (str) – Optional: Desired save name for the simularium file to be saved in the archive_rootpath. Defaults to None.

  • save_output_df (bool) – Whether to save the modelout.txt contents as a pandas df in csv form. Defaults to False.

Returns:

None

biosimulators_utils.model_lang.smoldyn.utils.get_parameters_variables_outputs_for_simulation(model_filename, model_language, simulation_type, algorithm_kisao_id=None, change_level=<class 'biosimulators_utils.sedml.data_model.SedDocument'>, native_ids=False, native_data_types=False, config=None)[source]#

Get the possible observables for a simulation of a model

Parameters:
  • model_filename (str) – path to model file

  • model_language (str) – model language (e.g., urn:sedml:language:sbml)

  • simulation_type (types.Type) – subclass of Simulation

  • algorithm_kisao_id (str) – KiSAO id of the algorithm for simulating the model (e.g., KISAO_0000019 for CVODE)

  • change_level (types.Type, optional) – level at which model changes will be made (SedDocument or Task)

  • native_ids (bool, optional) – whether to return the raw id and name of each model component rather than the suggested name for the variable of an associated SED-ML data generator

  • native_data_types (bool, optional) – whether to return new_values in their native data types

  • config (Config, optional) – whether to fail on missing includes

Returns:

possible attributes of a model that can be changed and their default values list of Simulation: simulation of the model list of Variable: possible observables for a simulation of the model

Return type:

list of ModelAttributeChange

biosimulators_utils.model_lang.smoldyn.validation module#

Utilities for validating Smoldyn models

Author:

Jonathan Karr <karr@mssm.edu>

Date:

2021-04-13

Copyright:

2021, Center for Reproducible Biomedical Modeling

License:

MIT

class biosimulators_utils.model_lang.smoldyn.validation.ModelValidation(validation: Tuple[List[str], List[str], Tuple[Simulation, List[str]]])[source]#

Bases: object

biosimulators_utils.model_lang.smoldyn.validation.generate_model_validation_object(archive: SmoldynCombineArchive) ModelValidation[source]#
Generate an instance of ModelValidation based on the output of archive.model_path

with above validate_model method.

Parameters:

archive – (CombineArchive): Instance of CombineArchive to generate model validation on.

Returns:

ModelValidation

biosimulators_utils.model_lang.smoldyn.validation.validate_model(filename, name=None, config=None)[source]#

Check that a model is valid

Parameters:
  • filename (str) – path to model

  • name (str, optional) – name of model for use in error messages

  • config (Config, optional) – whether to fail on missing includes

Returns:

  • nested list of str: nested list of errors (e.g., required ids missing or ids not unique)

  • nested list of str: nested list of errors (e.g., required ids missing or ids not unique)

  • tuple:

    • smoldyn.Simulation: model configuration

    • list of str: model configuration

Return type:

tuple