pyfebiopt.optimize.feb_bindings

Simplified FEBio template helpers.

Classes

BuildContext

Formatting options applied while writing FEBio templates.

ParameterBinding

Map a single theta value onto an XML element's text content.

EvaluationBinding

Bind an XPath to a value derived from multiple θ parameters.

FebTemplate

FEBio template plus bindings applied during rendering.

FebBuilder

Render FEBio input files under a dedicated case subfolder.

Module Contents

class pyfebiopt.optimize.feb_bindings.BuildContext

Formatting options applied while writing FEBio templates.

Parameters:
  • fmtprintf-style format string used for numeric values.

  • namespaces – Optional mapping passed to xml.etree.ElementTree.findall().

fmt: str = '%.20e'
namespaces: dict[str, str]
format_value(value: Number) str

Format a scalar value according to the fmt pattern.

Returns:

String representation suitable for FEBio XML content.

class pyfebiopt.optimize.feb_bindings.ParameterBinding

Map a single theta value onto an XML element’s text content.

The XPath is evaluated with ElementTree.findall(). All matching nodes are updated; set required to False to ignore missing nodes.

theta_name: str
xpath: str
required: bool = True
apply(root: xml.etree.ElementTree.Element, theta: collections.abc.Mapping[str, Number], ctx: BuildContext) None

Insert formatted values into all nodes matched by xpath.

class pyfebiopt.optimize.feb_bindings.EvaluationBinding

Bind an XPath to a value derived from multiple θ parameters.

Parameters:
  • xpath – XPath targeting the XML node(s) to update.

  • value – Expression or callable producing either a numeric value or plain text. String expressions remain numeric-only; callable values may return preformatted text for complex XML nodes such as vectors.

  • required – Same semantics as ParameterBinding.

  • text_template – Optional str.format() template receiving the formatted value via the value placeholder, useful for nodes that contain mixed text such as "2,{value}" in load curves.

xpath: str
value: str | collections.abc.Callable[[collections.abc.Mapping[str, Number]], ScalarOrText]
required: bool = True
text_template: str | None = None
__post_init__() None
apply(root: xml.etree.ElementTree.Element, theta: collections.abc.Mapping[str, Number], ctx: BuildContext) None

Apply the evaluated value to all matching nodes.

class pyfebiopt.optimize.feb_bindings.FebTemplate

FEBio template plus bindings applied during rendering.

template_path: pathlib.Path | str
bindings: list[Binding] = []
__post_init__() None
add_binding(binding: Binding) None

Register an additional binding for this template.

render(theta: collections.abc.Mapping[str, Number], ctx: BuildContext | None = None) xml.etree.ElementTree.ElementTree

Render the template into an XML tree using the supplied parameters.

Returns:

Parsed xml.etree.ElementTree.ElementTree ready for saving.

write(theta: collections.abc.Mapping[str, Number], out_path: pathlib.Path | str, ctx: BuildContext | None = None) pathlib.Path

Render and write the template to out_path.

Returns:

Path to the written FEB file.

class pyfebiopt.optimize.feb_bindings.FebBuilder

Render FEBio input files under a dedicated case subfolder.

template: FebTemplate
subfolder: str
build(theta: collections.abc.Mapping[str, Number], out_root: pathlib.Path | str, out_name: str | None = None, ctx: BuildContext | None = None) pathlib.Path

Render the template into the case subfolder and return the FEB path.

Returns:

Full path to the generated FEB document.