|  | 
| 1 | 1 | """Provide functions for cobrapy objects to generic Python objects and vice-versa.""" | 
| 2 | 2 | import itertools | 
| 3 |  | -import re | 
| 4 | 3 | from collections import OrderedDict, defaultdict | 
| 5 | 4 | from typing import TYPE_CHECKING, Dict, List, Sequence, Set, Tuple, Union | 
| 6 | 5 | 
 | 
| 7 | 6 | import numpy as np | 
| 8 | 7 | 
 | 
| 9 | 8 | from ..core import ( | 
| 10 |  | -    ConstraintComponent, | 
| 11 | 9 |     Gene, | 
| 12 | 10 |     Group, | 
| 13 | 11 |     Metabolite, | 
| 14 | 12 |     Model, | 
| 15 | 13 |     Reaction, | 
| 16 |  | -    UserDefinedConstraint, | 
| 17 | 14 | ) | 
| 18 | 15 | from ..io.sbml import ( | 
| 19 | 16 |     F_GENE, | 
| @@ -520,52 +517,6 @@ def group_from_dict( | 
| 520 | 517 |     new_group.add_members(cobra_members) | 
| 521 | 518 |     return new_group | 
| 522 | 519 | 
 | 
| 523 |  | -def const_comp_to_dict(component: ConstraintComponent) -> Dict: | 
| 524 |  | -    new_const_comp = OrderedDict() | 
| 525 |  | -    for key in _REQUIRED_CONSTRAINT_COMP_ATTRIBUTES: | 
| 526 |  | -        new_const_comp[key] = _fix_type(getattr(component, key)) | 
| 527 |  | -    _update_optional( | 
| 528 |  | -        component, | 
| 529 |  | -        new_const_comp, | 
| 530 |  | -        _OPTIONAL_CONSTRAINT_COMP_ATTRIBUTES, | 
| 531 |  | -        _ORDERED_OPTIONAL_CONSTRAINT_COMP_KEYS, | 
| 532 |  | -    ) | 
| 533 |  | -    return new_const_comp | 
| 534 |  | - | 
| 535 |  | - | 
| 536 |  | -def user_defined_const_to_dict(constraint: UserDefinedConstraint) -> Dict: | 
| 537 |  | -    new_const = OrderedDict() | 
| 538 |  | -    for key in _REQUIRED_CONSTRAINT_ATTRIBUTES: | 
| 539 |  | -        if key != "constraint_comps": | 
| 540 |  | -            new_const[key] = _fix_type(getattr(constraint, key)) | 
| 541 |  | -            continue | 
| 542 |  | -        new_const["constraint_comps"] = list( | 
| 543 |  | -            map(const_comp_to_dict, constraint.constraint_comps) | 
| 544 |  | -        ) | 
| 545 |  | -    _update_optional( | 
| 546 |  | -        constraint, | 
| 547 |  | -        new_const, | 
| 548 |  | -        _OPTIONAL_CONSTRAINT_ATTRIBUTES, | 
| 549 |  | -        _ORDERED_OPTIONAL_CONSTRAINT_KEYS, | 
| 550 |  | -    ) | 
| 551 |  | -    return new_const | 
| 552 |  | - | 
| 553 |  | - | 
| 554 |  | -def user_defined_const_from_dict(constraint: Dict) -> UserDefinedConstraint: | 
| 555 |  | -    new_user_defined_const = UserDefinedConstraint() | 
| 556 |  | -    for k, v in constraint.items(): | 
| 557 |  | -        if k == "constraint_comps": | 
| 558 |  | -            for comp in v: | 
| 559 |  | -                new_comp = ConstraintComponent(**comp) | 
| 560 |  | -                new_user_defined_const.add_constraint_comps([new_comp]) | 
| 561 |  | -        elif k == "annotation": | 
| 562 |  | -            continue | 
| 563 |  | -        elif k == "notes": | 
| 564 |  | -            continue | 
| 565 |  | -        else: | 
| 566 |  | -            setattr(new_user_defined_const, k, v) | 
| 567 |  | -    return new_user_defined_const | 
| 568 |  | - | 
| 569 | 520 | 
 | 
| 570 | 521 | def model_to_dict( | 
| 571 | 522 |     model: Model, sort: bool = False, f_replace: dict = F_REPLACE  # noqa:    W0102 | 
|  | 
0 commit comments