Beispiel #1
0
    def build_product_from_data(self, product_data):
        """ Custom object builder from stored product data.
        """
        product_name = product_data["name"]

        def collect_product_comp(component_name):
            """ Lookup component based on the product name and the component
            name.
            """
            # FIXME: support multiple key filters in get_objects_by_type so
            # that we can have a key containing both the component_name and the
            # target_product
            key = {'target_product': product_name}
            objects = self.get_objects_by_type('product_components',
                                               filter_by=key)
            candidates = [obj for obj in objects if obj.name == component_name]
            if len(candidates) == 0:
                available_obj = [obj.name for obj in objects]
                msg = ("Failed to load one of the product components ({}) from"
                       " all product components of the datasource ({}). Did "
                       "you populate the product component objects before the "
                       "products?".format(component_name, available_obj))
                logger.exception(msg)
                raise KeyError(msg)
            else:
                return candidates[0]

        comp_names = product_data.pop('product_components')
        product_data['product_components'] = [
            collect_product_comp(comp) for comp in comp_names
        ]
        return Product(**product_data)
Beispiel #2
0
    def build_product(self, allow_ui=True):
        """ Create an instance of a Product from the characteristics and
        component descriptions of the builder.
        """
        try:
            if not self.expert_mode:
                self.expand_product_attributes()

            # Collect components
            components = self.lookup_components()

            # Collect component concentration expressions
            concentration_exps = [comp.concentration_exps
                                  for comp in self.component_descs]
            if self.add_strip and not self.expert_mode:
                strip_desc = self.strip_component_descs[0]
                strip_expression = strip_desc.concentration_exps
                concentration_exps.append(strip_expression)

            # Collect assays:
            assay_names = assay_names_from_instances(
                self.component_assay_names
            )
            if self.add_strip and not self.expert_mode:
                assay_names.append(STRIP_COMP_NAME)

            # Build product instance
            prod = Product(
                name=self.name, product_type=self.product_type,
                description=self.description,
                pI=self.pI, product_components=components,
                product_component_concentration_exps=concentration_exps,
                product_component_assays=assay_names
            )

            if self.add_strip and not self.expert_mode:
                self.datasource.set_object_of_type("product_components",
                                                   self.strip_component)
        except Exception as e:
            msg = ("Failed to create new product. Please try again or report "
                   "this issue to the software provider if the problem "
                   "persists, providing the log file of this session.")
            details = "\nError was {}.".format(e)
            logger.exception(msg + details)
            if allow_ui:
                error(None, msg)
            prod = None

        return prod
Beispiel #3
0
        ]
        adapter = build_array_adapter(index_name, column_names, row_names)
        return adapter

    def _param_formula_str_default(self):
        param_formula = """The following parameters get combined into an effective Langmuir model according to:
        ka(pH) = ka0 + ka1 * pH + ka2 * pH^2 + ka3 * pH^3
        kd(pH) = kd0 + kd1 * pH + kd2 * pH^2 + kd3 * pH^3
        qmax(pH) = qmax0 + qmax1 * pH + qmax2 * pH^2 + qmax3 * pH^3
"""  # noqa
        return param_formula


if __name__ == '__main__':

    # Create Product for passing component names
    from kromatography.model.tests.example_model_data import PRODUCT_DATA, \
        Prod001_comp1, Prod001_comp2, Prod001_comp3
    from kromatography.model.product import Product

    product_components = [Prod001_comp1, Prod001_comp2, Prod001_comp3]
    prod = Product(product_components=product_components, **PRODUCT_DATA)

    # Build a model you want to visualize:
    extl = ExternalLangmuir(len(prod.product_component_names),
                            component_names=prod.product_component_names)

    # Build model view, passing the model as a model and make a window for it:
    extl_model_view = ExternalLangmuirView(model=extl)
    extl_model_view.configure_traits()
Beispiel #4
0
""" Test script modifying the user datasource.
"""
import logging
from kromatography.model.product import Product

logger = logging.getLogger(__name__)

# Example of changing the content of the datasource by adding a new product
new_prod = Product(name="PROD", product_type="Mab")
user_datasource.set_object_of_type("products", new_prod)  # noqa

logger.warning("Opening new product {} in central pane...".format(new_prod))
                             show_label=False,
                             editor=self._tabular_editor), ),
                    label="Transport Parameters",
                    show_border=True,
                ),
            ),
            # Relevant when used as standalone view:
            resizable=True,
            buttons=OKCancelButtons,
            default_button=OKButton,
            title="Configure General Rate model")
        return view

    def _vector_attributes_default(self):
        return ['film_mass_transfer', 'pore_diffusion', 'surface_diffusion']


if __name__ == '__main__':
    # Create Product for passing component names
    from kromatography.model.tests.example_model_data import PRODUCT_DATA
    from kromatography.model.product import Product
    prod = Product(**PRODUCT_DATA)

    # Build a model you want to visualize:
    grm = GeneralRateModel(len(prod.product_component_names),
                           component_names=prod.product_component_names)

    # Build model view, passing the model as a model and make a window for it:
    grm_model_view = GeneralRateModelView(model=grm)
    grm_model_view.configure_traits()
}

NATIVE_PRODUCT_COMPONENT_DATA = {
    'target_product': 'Prod001',
    'name': 'Native',
    'molecular_weight': UnitScalar(18.8, units=gram_per_mol),
    'extinction_coefficient': UnitScalar(0.75,
                                         units=extinction_coefficient_unit),
}

Prod001_comp1 = ProductComponent(**ACIDIC_1_PRODUCT_COMPONENT_DATA)
Prod001_comp2 = ProductComponent(**ACIDIC_2_PRODUCT_COMPONENT_DATA)
Prod001_comp3 = ProductComponent(**NATIVE_PRODUCT_COMPONENT_DATA)

Prod001 = Product(
    product_components=[Prod001_comp1, Prod001_comp2, Prod001_comp3],
    **PRODUCT_DATA)

Prod001_with_strip, Prod001_strip = add_strip_to_product(Prod001)

PRODUCT_DATA2 = {
    'name':
    'Mab001',
    'product_type':
    'MAB',
    'product_component_assays':
    ['CEX_Acidic', 'CEX_Main', 'CEX_Basic', 'SEC_Monomer', 'SEC_Dimer'],
    'product_component_concentration_exps': [
        'product_concentration * SEC_Monomer * CEX_Acidic / 10000',
        'product_concentration * SEC_Monomer * CEX_Main / 10000',
        'product_concentration * SEC_Monomer * CEX_Basic / 10000',