# lems_loader { #tvbo.parse.lems_loader }

`parse.lems_loader`

This module deals with loading elements from LEMS-generated files.

## Functions

| Name | Description |
| --- | --- |
| [import_lems_model](#tvbo.parse.lems_loader.import_lems_model) | Import a LEMS model file as ontology classes and return the created classes. |
| [lems_model_info](#tvbo.parse.lems_loader.lems_model_info) | Extract model metadata from a parsed LEMS model into a plain dictionary. |
| [load_lems_model](#tvbo.parse.lems_loader.load_lems_model) | Load a LEMS file and return its extracted model information. |

### import_lems_model { #tvbo.parse.lems_loader.import_lems_model }

```python
parse.lems_loader.import_lems_model(lems_file, model_name)
```

Import a LEMS model file as ontology classes and return the created classes.

Parses the LEMS file, creates a `NeuralMassModel` subclass named `model_name`, and registers its state variables, parameters, non-integrated variables, time derivatives, and coupling functions as ontology subclasses. Mathematical relationships are updated on the resulting model class before it is returned.

#### Parameters {.doc-section .doc-section-parameters}

| Name       | Type   | Description                                                              | Default    |
|------------|--------|--------------------------------------------------------------------------|------------|
| lems_file  |        | Path to the LEMS/XML file to import.                                     | _required_ |
| model_name |        | Name and label used for the created model class and its derived acronym. | _required_ |

#### Returns {.doc-section .doc-section-returns}

| Name   | Type   | Description                                                          |
|--------|--------|----------------------------------------------------------------------|
|        |        | A tuple `(model_class, cf_class)` of the created model class and the |
|        |        | last coupling-function class registered for it.                      |

### lems_model_info { #tvbo.parse.lems_loader.lems_model_info }

```python
parse.lems_loader.lems_model_info(model)
```

Extract model metadata from a parsed LEMS model into a plain dictionary.

Reads the `derivatives` component type of a LEMS model and collects its constants (parameters), state variables, non-integrated (derived) variables, time derivatives, exposures, and any coupling-function component types.

#### Parameters {.doc-section .doc-section-parameters}

| Name   | Type   | Description                                                                  | Default    |
|--------|--------|------------------------------------------------------------------------------|------------|
| model  |        | A parsed LEMS `Model` whose `component_types` include a `derivatives` entry. | _required_ |

#### Returns {.doc-section .doc-section-returns}

| Name   | Type   | Description                                                        |
|--------|--------|--------------------------------------------------------------------|
|        |        | A dictionary with keys `state_variables`, `parameters`,            |
|        |        | `non_integrated_variables`, `state_variable_dfuns`, `vois`,        |
|        |        | `model_definition`, and `coupling_functions` describing the model. |

### load_lems_model { #tvbo.parse.lems_loader.load_lems_model }

```python
parse.lems_loader.load_lems_model(lems_file)
```

Load a LEMS file and return its extracted model information.

#### Parameters {.doc-section .doc-section-parameters}

| Name      | Type   | Description                          | Default    |
|-----------|--------|--------------------------------------|------------|
| lems_file |        | Path to the LEMS/XML file to import. | _required_ |

#### Returns {.doc-section .doc-section-returns}

| Name   | Type   | Description                                                        |
|--------|--------|--------------------------------------------------------------------|
|        |        | The dictionary produced by `lems_model_info` for the parsed model. |