Skip to content

Modules

libvcell

VCellExpressionError

Bases: Exception

Raised when a VCell expression cannot be evaluated.

Attributes:

Name Type Description
error_type

the originating Java exception's simple class name (e.g. DivideByZeroException, ExpressionBindingException, ParseException, FunctionDomainException), or None.

message

the error message, or None.

Source code in libvcell/model_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class VCellExpressionError(Exception):
    """Raised when a VCell expression cannot be evaluated.

    Attributes:
        error_type: the originating Java exception's simple class name (e.g. ``DivideByZeroException``,
            ``ExpressionBindingException``, ``ParseException``, ``FunctionDomainException``), or ``None``.
        message: the error message, or ``None``.
    """

    def __init__(self, error_type: str | None, message: str | None) -> None:
        self.error_type = error_type
        self.message = message
        super().__init__(f"{error_type}: {message}")

evaluate_expression(expression_infix, symbol_table)

Evaluate a native-syntax VCell infix expression against a table of symbol values.

Any symbol referenced by the expression must be present in symbol_table; extra (unreferenced) symbols are permitted and ignored.

Parameters:

Name Type Description Default
expression_infix str

native VCell infix expression string (e.g. "a + b/c")

required
symbol_table dict[str, float]

mapping of symbol name to 64-bit float value

required

Returns:

Name Type Description
float float

the evaluated value

Raises:

Type Description
VCellExpressionError

if the expression fails to parse, references an unsupplied symbol, fails to evaluate (e.g. division by zero, math domain error), or evaluates to a non-finite value.

Source code in libvcell/model_utils.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def evaluate_expression(expression_infix: str, symbol_table: dict[str, float]) -> float:
    """
    Evaluate a native-syntax VCell infix expression against a table of symbol values.

    Any symbol referenced by the expression must be present in ``symbol_table``; extra
    (unreferenced) symbols are permitted and ignored.

    Args:
        expression_infix (str): native VCell infix expression string (e.g. ``"a + b/c"``)
        symbol_table (dict[str, float]): mapping of symbol name to 64-bit float value

    Returns:
        float: the evaluated value

    Raises:
        VCellExpressionError: if the expression fails to parse, references an unsupplied symbol,
            fails to evaluate (e.g. division by zero, math domain error), or evaluates to a
            non-finite value.
    """
    native = VCellNativeCalls()
    result: EvalReturnValue = native.evaluate_expression(expression_infix, symbol_table)
    if not result.success or result.value is None:
        raise VCellExpressionError(result.error_type, result.message)
    return result.value

sbml_to_finite_volume_input(sbml_content, output_dir_path)

Convert SBML content to finite volume input files

Parameters:

Name Type Description Default
sbml_content str

SBML content

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def sbml_to_finite_volume_input(sbml_content: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert SBML content to finite volume input files

    Args:
        sbml_content (str): SBML content
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.sbml_to_finite_volume_input(sbml_content, output_dir_path)
    return return_value.success, return_value.message

sbml_to_vcml(sbml_content, vcml_file_path)

Convert SBML content to finite volume input files

Parameters:

Name Type Description Default
sbml_content str

SBML content

required
vcml_file_path Path

path to resulting VCML file

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/model_utils.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def sbml_to_vcml(sbml_content: str, vcml_file_path: Path) -> tuple[bool, str]:
    """
    Convert SBML content to finite volume input files

    Args:
        sbml_content (str): SBML content
        vcml_file_path (Path): path to resulting VCML file

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.sbml_to_vcml(sbml_content=sbml_content, vcml_file_path=vcml_file_path)
    return return_value.success, return_value.message

vcell_infix_to_num_expr_infix(vcell_infix)

Converts an infix string version of a VCell Native Expression, and converts it to a NumExpr compatible version

Parameters:

Name Type Description Default
vcell_infix str

the infix to convert

required

Returns:

Type Description
tuple[bool, str, str]

tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix

Source code in libvcell/model_utils.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def vcell_infix_to_num_expr_infix(vcell_infix: str) -> tuple[bool, str, str]:
    """
    Converts an infix string version of a VCell Native Expression, and converts it to a NumExpr compatible version

    Args:
        vcell_infix (str): the infix to convert

    Returns:
        tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix
    """
    native = VCellNativeCalls()
    target_num_expr_infix = MutableString("")
    return_value: ReturnValue = native.vcell_infix_to_num_expr_infix(vcell_infix, target_num_expr_infix)
    return return_value.success, return_value.message, target_num_expr_infix.value

vcell_infix_to_python_infix(vcell_infix)

Converts an infix string version of a VCell Native Expression, and converts it to a Python compatible version

Parameters:

Name Type Description Default
vcell_infix str

the infix to convert

required

Returns:

Type Description
tuple[bool, str, str]

tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix

Source code in libvcell/model_utils.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def vcell_infix_to_python_infix(vcell_infix: str) -> tuple[bool, str, str]:
    """
    Converts an infix string version of a VCell Native Expression, and converts it to a Python compatible version

    Args:
        vcell_infix (str): the infix to convert

    Returns:
        tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix
    """
    native = VCellNativeCalls()
    target_python_infix = MutableString("")
    return_value: ReturnValue = native.vcell_infix_to_python_infix(vcell_infix, target_python_infix)
    return return_value.success, return_value.message, target_python_infix.value

vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)

Convert VCML content to finite volume input files

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
simulation_name str

simulation name

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def vcml_to_finite_volume_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert VCML content to finite volume input files

    Args:
        vcml_content (str): VCML content
        simulation_name (str): simulation name
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)
    return return_value.success, return_value.message

vcml_to_moving_boundary_input(vcml_content, simulation_name, output_dir_path)

Convert VCML content to Moving Boundary solver input (a MovingBoundarySetup XML file)

The named simulation must be configured for the Moving Boundary solver. The generated MovingBoundarySetup XML can be consumed by the vcell-mbsolver package (MovingBoundarySolver.from_xml).

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
simulation_name str

simulation name (must use the Moving Boundary solver)

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def vcml_to_moving_boundary_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert VCML content to Moving Boundary solver input (a MovingBoundarySetup XML file)

    The named simulation must be configured for the Moving Boundary solver. The generated
    MovingBoundarySetup XML can be consumed by the vcell-mbsolver package (``MovingBoundarySolver.from_xml``).

    Args:
        vcml_content (str): VCML content
        simulation_name (str): simulation name (must use the Moving Boundary solver)
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_moving_boundary_input(vcml_content, simulation_name, output_dir_path)
    return return_value.success, return_value.message

vcml_to_sbml(vcml_content, application_name, sbml_file_path, round_trip_validation)

Convert VCML content to SBML file

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
application_name str

VCell Biomodel application name

required
sbml_file_path Path

path to resulting SBML file

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/model_utils.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def vcml_to_sbml(
    vcml_content: str, application_name: str, sbml_file_path: Path, round_trip_validation: bool
) -> tuple[bool, str]:
    """
    Convert VCML content to SBML file

    Args:
        vcml_content (str): VCML content
        application_name (str): VCell Biomodel application name
        sbml_file_path (Path): path to resulting SBML file

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_sbml(
        vcml_content=vcml_content,
        application_name=application_name,
        sbml_file_path=sbml_file_path,
        round_trip_validation=round_trip_validation,
    )
    return return_value.success, return_value.message

vcml_to_vcml(vcml_content, vcml_file_path)

Process VCML content to regenerated VCML file

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
vcml_file_path Path

path to resulting VCML file

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/model_utils.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def vcml_to_vcml(vcml_content: str, vcml_file_path: Path) -> tuple[bool, str]:
    """
    Process VCML content to regenerated VCML file

    Args:
        vcml_content (str): VCML content
        vcml_file_path (Path): path to resulting VCML file

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_vcml(vcml_content=vcml_content, vcml_file_path=vcml_file_path)
    return return_value.success, return_value.message

Modules

libvcell

VCellExpressionError

Bases: Exception

Raised when a VCell expression cannot be evaluated.

Attributes:

Name Type Description
error_type

the originating Java exception's simple class name (e.g. DivideByZeroException, ExpressionBindingException, ParseException, FunctionDomainException), or None.

message

the error message, or None.

Source code in libvcell/model_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class VCellExpressionError(Exception):
    """Raised when a VCell expression cannot be evaluated.

    Attributes:
        error_type: the originating Java exception's simple class name (e.g. ``DivideByZeroException``,
            ``ExpressionBindingException``, ``ParseException``, ``FunctionDomainException``), or ``None``.
        message: the error message, or ``None``.
    """

    def __init__(self, error_type: str | None, message: str | None) -> None:
        self.error_type = error_type
        self.message = message
        super().__init__(f"{error_type}: {message}")

evaluate_expression(expression_infix, symbol_table)

Evaluate a native-syntax VCell infix expression against a table of symbol values.

Any symbol referenced by the expression must be present in symbol_table; extra (unreferenced) symbols are permitted and ignored.

Parameters:

Name Type Description Default
expression_infix str

native VCell infix expression string (e.g. "a + b/c")

required
symbol_table dict[str, float]

mapping of symbol name to 64-bit float value

required

Returns:

Name Type Description
float float

the evaluated value

Raises:

Type Description
VCellExpressionError

if the expression fails to parse, references an unsupplied symbol, fails to evaluate (e.g. division by zero, math domain error), or evaluates to a non-finite value.

Source code in libvcell/model_utils.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def evaluate_expression(expression_infix: str, symbol_table: dict[str, float]) -> float:
    """
    Evaluate a native-syntax VCell infix expression against a table of symbol values.

    Any symbol referenced by the expression must be present in ``symbol_table``; extra
    (unreferenced) symbols are permitted and ignored.

    Args:
        expression_infix (str): native VCell infix expression string (e.g. ``"a + b/c"``)
        symbol_table (dict[str, float]): mapping of symbol name to 64-bit float value

    Returns:
        float: the evaluated value

    Raises:
        VCellExpressionError: if the expression fails to parse, references an unsupplied symbol,
            fails to evaluate (e.g. division by zero, math domain error), or evaluates to a
            non-finite value.
    """
    native = VCellNativeCalls()
    result: EvalReturnValue = native.evaluate_expression(expression_infix, symbol_table)
    if not result.success or result.value is None:
        raise VCellExpressionError(result.error_type, result.message)
    return result.value

sbml_to_finite_volume_input(sbml_content, output_dir_path)

Convert SBML content to finite volume input files

Parameters:

Name Type Description Default
sbml_content str

SBML content

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def sbml_to_finite_volume_input(sbml_content: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert SBML content to finite volume input files

    Args:
        sbml_content (str): SBML content
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.sbml_to_finite_volume_input(sbml_content, output_dir_path)
    return return_value.success, return_value.message

sbml_to_vcml(sbml_content, vcml_file_path)

Convert SBML content to finite volume input files

Parameters:

Name Type Description Default
sbml_content str

SBML content

required
vcml_file_path Path

path to resulting VCML file

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/model_utils.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def sbml_to_vcml(sbml_content: str, vcml_file_path: Path) -> tuple[bool, str]:
    """
    Convert SBML content to finite volume input files

    Args:
        sbml_content (str): SBML content
        vcml_file_path (Path): path to resulting VCML file

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.sbml_to_vcml(sbml_content=sbml_content, vcml_file_path=vcml_file_path)
    return return_value.success, return_value.message

vcell_infix_to_num_expr_infix(vcell_infix)

Converts an infix string version of a VCell Native Expression, and converts it to a NumExpr compatible version

Parameters:

Name Type Description Default
vcell_infix str

the infix to convert

required

Returns:

Type Description
tuple[bool, str, str]

tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix

Source code in libvcell/model_utils.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def vcell_infix_to_num_expr_infix(vcell_infix: str) -> tuple[bool, str, str]:
    """
    Converts an infix string version of a VCell Native Expression, and converts it to a NumExpr compatible version

    Args:
        vcell_infix (str): the infix to convert

    Returns:
        tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix
    """
    native = VCellNativeCalls()
    target_num_expr_infix = MutableString("")
    return_value: ReturnValue = native.vcell_infix_to_num_expr_infix(vcell_infix, target_num_expr_infix)
    return return_value.success, return_value.message, target_num_expr_infix.value

vcell_infix_to_python_infix(vcell_infix)

Converts an infix string version of a VCell Native Expression, and converts it to a Python compatible version

Parameters:

Name Type Description Default
vcell_infix str

the infix to convert

required

Returns:

Type Description
tuple[bool, str, str]

tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix

Source code in libvcell/model_utils.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def vcell_infix_to_python_infix(vcell_infix: str) -> tuple[bool, str, str]:
    """
    Converts an infix string version of a VCell Native Expression, and converts it to a Python compatible version

    Args:
        vcell_infix (str): the infix to convert

    Returns:
        tuple[bool, str, str]: A tuple containing the success status, a message, and the converted infix
    """
    native = VCellNativeCalls()
    target_python_infix = MutableString("")
    return_value: ReturnValue = native.vcell_infix_to_python_infix(vcell_infix, target_python_infix)
    return return_value.success, return_value.message, target_python_infix.value

vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)

Convert VCML content to finite volume input files

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
simulation_name str

simulation name

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def vcml_to_finite_volume_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert VCML content to finite volume input files

    Args:
        vcml_content (str): VCML content
        simulation_name (str): simulation name
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)
    return return_value.success, return_value.message

vcml_to_moving_boundary_input(vcml_content, simulation_name, output_dir_path)

Convert VCML content to Moving Boundary solver input (a MovingBoundarySetup XML file)

The named simulation must be configured for the Moving Boundary solver. The generated MovingBoundarySetup XML can be consumed by the vcell-mbsolver package (MovingBoundarySolver.from_xml).

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
simulation_name str

simulation name (must use the Moving Boundary solver)

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def vcml_to_moving_boundary_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert VCML content to Moving Boundary solver input (a MovingBoundarySetup XML file)

    The named simulation must be configured for the Moving Boundary solver. The generated
    MovingBoundarySetup XML can be consumed by the vcell-mbsolver package (``MovingBoundarySolver.from_xml``).

    Args:
        vcml_content (str): VCML content
        simulation_name (str): simulation name (must use the Moving Boundary solver)
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_moving_boundary_input(vcml_content, simulation_name, output_dir_path)
    return return_value.success, return_value.message

vcml_to_sbml(vcml_content, application_name, sbml_file_path, round_trip_validation)

Convert VCML content to SBML file

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
application_name str

VCell Biomodel application name

required
sbml_file_path Path

path to resulting SBML file

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/model_utils.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def vcml_to_sbml(
    vcml_content: str, application_name: str, sbml_file_path: Path, round_trip_validation: bool
) -> tuple[bool, str]:
    """
    Convert VCML content to SBML file

    Args:
        vcml_content (str): VCML content
        application_name (str): VCell Biomodel application name
        sbml_file_path (Path): path to resulting SBML file

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_sbml(
        vcml_content=vcml_content,
        application_name=application_name,
        sbml_file_path=sbml_file_path,
        round_trip_validation=round_trip_validation,
    )
    return return_value.success, return_value.message

vcml_to_vcml(vcml_content, vcml_file_path)

Process VCML content to regenerated VCML file

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
vcml_file_path Path

path to resulting VCML file

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/model_utils.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def vcml_to_vcml(vcml_content: str, vcml_file_path: Path) -> tuple[bool, str]:
    """
    Process VCML content to regenerated VCML file

    Args:
        vcml_content (str): VCML content
        vcml_file_path (Path): path to resulting VCML file

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_vcml(vcml_content=vcml_content, vcml_file_path=vcml_file_path)
    return return_value.success, return_value.message

Functions

sbml_to_finite_volume_input

Convert SBML content to finite volume input files

Parameters:

Name Type Description Default
sbml_content str

SBML content

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def sbml_to_finite_volume_input(sbml_content: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert SBML content to finite volume input files

    Args:
        sbml_content (str): SBML content
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.sbml_to_finite_volume_input(sbml_content, output_dir_path)
    return return_value.success, return_value.message

vcml_to_finite_volume_input

Convert VCML content to finite volume input files

Parameters:

Name Type Description Default
vcml_content str

VCML content

required
simulation_name str

simulation name

required
output_dir_path Path

output directory path

required

Returns:

Type Description
tuple[bool, str]

tuple[bool, str]: A tuple containing the success status and a message

Source code in libvcell/solver_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def vcml_to_finite_volume_input(vcml_content: str, simulation_name: str, output_dir_path: Path) -> tuple[bool, str]:
    """
    Convert VCML content to finite volume input files

    Args:
        vcml_content (str): VCML content
        simulation_name (str): simulation name
        output_dir_path (Path): output directory path

    Returns:
        tuple[bool, str]: A tuple containing the success status and a message
    """
    native = VCellNativeCalls()
    return_value: ReturnValue = native.vcml_to_finite_volume_input(vcml_content, simulation_name, output_dir_path)
    return return_value.success, return_value.message

evaluate_expression

Evaluate a native-syntax VCell infix expression against a table of symbol values.

Any symbol referenced by the expression must be present in symbol_table; extra (unreferenced) symbols are permitted and ignored.

Parameters:

Name Type Description Default
expression_infix str

native VCell infix expression string (e.g. "a + b/c")

required
symbol_table dict[str, float]

mapping of symbol name to 64-bit float value

required

Returns:

Name Type Description
float float

the evaluated value

Raises:

Type Description
VCellExpressionError

if the expression fails to parse, references an unsupplied symbol, fails to evaluate (e.g. division by zero, math domain error), or evaluates to a non-finite value.

Source code in libvcell/model_utils.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def evaluate_expression(expression_infix: str, symbol_table: dict[str, float]) -> float:
    """
    Evaluate a native-syntax VCell infix expression against a table of symbol values.

    Any symbol referenced by the expression must be present in ``symbol_table``; extra
    (unreferenced) symbols are permitted and ignored.

    Args:
        expression_infix (str): native VCell infix expression string (e.g. ``"a + b/c"``)
        symbol_table (dict[str, float]): mapping of symbol name to 64-bit float value

    Returns:
        float: the evaluated value

    Raises:
        VCellExpressionError: if the expression fails to parse, references an unsupplied symbol,
            fails to evaluate (e.g. division by zero, math domain error), or evaluates to a
            non-finite value.
    """
    native = VCellNativeCalls()
    result: EvalReturnValue = native.evaluate_expression(expression_infix, symbol_table)
    if not result.success or result.value is None:
        raise VCellExpressionError(result.error_type, result.message)
    return result.value

VCellExpressionError

Bases: Exception

Raised when a VCell expression cannot be evaluated.

Attributes:

Name Type Description
error_type

the originating Java exception's simple class name (e.g. DivideByZeroException, ExpressionBindingException, ParseException, FunctionDomainException), or None.

message

the error message, or None.

Source code in libvcell/model_utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class VCellExpressionError(Exception):
    """Raised when a VCell expression cannot be evaluated.

    Attributes:
        error_type: the originating Java exception's simple class name (e.g. ``DivideByZeroException``,
            ``ExpressionBindingException``, ``ParseException``, ``FunctionDomainException``), or ``None``.
        message: the error message, or ``None``.
    """

    def __init__(self, error_type: str | None, message: str | None) -> None:
        self.error_type = error_type
        self.message = message
        super().__init__(f"{error_type}: {message}")