Beispiel #1
0
def request_new_component(datasource, kind="livemodal", **traits):
    """ Build a new instance of a chemical component invoking its UI editor.

    Parameters
    -----------
    datasource : Instance(SimpleDataSource)
        User datasource targeted to be contributed to.

    kind : str
        Should be set to None to make it non-blocking (only useful for testing
        purposes).

    traits : dict
        Attributes of the created object. Used to override the defaults.

    Returns
    -------
    Tuple with the object created and the data to create it since it is to be
    contributed to the SimpleDataSource.
    """
    defaults = dict(name="New Component", charge=UnitScalar(0.0, units='1'),
                    pKa=UnitScalar(0.0, units='1'))
    defaults.update(traits)
    model = Component(**defaults)
    view = ComponentView(model=model)
    return _show_view_and_return_model(view, kind)
Beispiel #2
0
 def test_add_strip_to_product_pass_unitscalar(self):
     ds = load_default_user_datasource()[0]
     prod0 = ds.get_object_of_type("products", "Prod000")
     new_prod, new_comp = add_strip_to_product(
         prod0, UnitScalar(18.8e3, units=gram_per_mol),
         UnitScalar(0.75, units=extinction_coefficient_unit))
     self.assert_new_prod_valid(prod0, new_prod, new_comp)
Beispiel #3
0
def request_new_product_component(datasource, kind="livemodal", **traits):
    """ Build a new instance of a ProdutComponent invoking its UI editor.

    Parameters
    -----------
    datasource : Instance(SimpleDataSource)
        User datasource targeted to be contributed to.

    kind : str
        Should be set to None to make it non-blocking (only useful for testing
        purposes).

    traits : dict
        Attributes of the created object. Used to override the defaults.

    Returns
    -------
    Tuple with the object created and the data to create it since it is to be
    contributed to the SimpleDataSource.
    """
    ext_coef_units = chr_units.extinction_coefficient_unit
    defaults = dict(
        name="New_Component", target_product="Unknown",
        molecular_weight=UnitScalar(0.0, units=chr_units.kilo_dalton),
        extinction_coefficient=UnitScalar(0.0, units=ext_coef_units)
    )
    defaults.update(traits)

    model = ProductComponent(**defaults)
    view = ProductComponentView(model=model)
    return _show_view_and_return_model(view, kind)
 def test_calculate_pool_volume_no_time(self):
     start_collect_time = UnitScalar(1, units="minute")
     stop_collect_time = UnitScalar(1, units="minute")
     flow_rate = UnitScalar(3, units="m**3/minute")
     vol = calculate_pool_volume(start_collect_time, stop_collect_time,
                                 flow_rate, self.column)
     assert_unit_scalar_almost_equal(vol, UnitScalar(0.0, units="CV"))
Beispiel #5
0
    def test_update_std_run_sim(self):
        sim = make_sample_simulation(name='Run_1')
        self.assertIsNone(sim.output)
        # Contains data from the CADET run:
        h5file = io_data_path("Sample_Sim_from_Run_1_cadet_simulation_run.h5")
        with self.assertTraitChanges(sim, "perf_param_data_event", 1):
            update_simulation_results(sim, h5file)

        self.assertIsInstance(sim.output, SimulationResults)
        perf_params = sim.output.performance_data
        self.assertIsInstance(perf_params, PerformanceData)
        self.assertIsInstance(perf_params.pool, SolutionWithProduct)
        num_comp = len(sim.product.product_components)
        self.assertEqual(
            len(perf_params.pool.product_component_concentrations),  # noqa
            num_comp)
        assert_unit_scalar_almost_equal(perf_params.pool_volume,
                                        UnitScalar(1.727090, units="CV"),
                                        eps=1.e-6)
        assert_unit_scalar_almost_equal(perf_params.step_yield,
                                        UnitScalar(95.814, units='%'),
                                        eps=1.e-3)
        assert_unit_scalar_almost_equal(perf_params.start_collect_time,
                                        UnitScalar(200.946, units='minute'),
                                        eps=1.e-3)
        assert_unit_scalar_almost_equal(perf_params.stop_collect_time,
                                        UnitScalar(227.9, units='minute'),
                                        eps=1.e-3)
    def compute_loaded_vol(self, tgt_units=column_volumes):
        """ Compute the load step volume that would match the UV data at
        constant load solution concentration.

        Returns
        -------
        UnitScalar
            Load step volume, in CV, that would be needed to match the UV data.
        """
        if tgt_units not in [column_volumes, g_per_liter_resin]:
            msg = "Supported target units are CV and g/Liter of resin but " \
                  "got {}.".format(tgt_units.label)
            logger.debug(msg)
            raise ValueError(msg)

        target_mass = self.mass_from_uv
        col_volume = self.target_experiment.column.volume
        concentration = self.current_concentration
        vol = target_mass / concentration / col_volume
        # Test equality on the labels since CV and g_per_liter_resin are equal
        # from a derivation point of view (dimensionless)
        if tgt_units.label == g_per_liter_resin.label:
            vol = float(vol * concentration)
            vol = UnitScalar(vol, units=g_per_liter_resin)
        else:
            vol = UnitScalar(vol, units=column_volumes)

        return vol
Beispiel #7
0
    def test_bed_height_proxy(self):
        # Make a view. Equivalent to view = ColumnView(model=self.model)
        model_view = self._get_model_view()
        range_units = self.model.bed_height_range.units

        # Check that the view got the initial values from the model:
        self.assertEqual(model_view.column_type_bed_height_min,
                         UnitScalar(10, units=range_units))
        self.assertEqual(model_view.column_type_bed_height_max,
                         UnitScalar(30, units=range_units))

        # Set model min/max values
        # FIXME: This min_val of 20.0 is required to avoid breaking tests in
        # test_simulation_from_experiment_builder. Somehow, this test is
        # setting CP_001's bed_height_actual to min_val, and other code then
        # try to add CP_001 with a bed_height_actual of 20 in the datasource,
        # provoking a DS collision. The connection is unclear at this point.
        min_val = 20.0
        max_val = 21.22
        min_val_unitted = UnitScalar(min_val, units=range_units)
        max_val_unitted = UnitScalar(max_val, units=range_units)

        # Set the view and make sure the model is updated
        model_view.column_type_bed_height_min = min_val_unitted
        model_view.column_type_bed_height_max = max_val_unitted

        # Check that model's range is updated
        self.assertEqual(self.model.bed_height_range,
                         UnitArray([min_val, max_val], units=range_units))
Beispiel #8
0
def request_new_resin(datasource, kind="livemodal", **traits):
    """ Build a new instance of a component invoking its UI editor.

    Parameters
    -----------
    datasource : Instance(SimpleDataSource)
        User datasource targeted to be contributed to.

    kind : str
        Should be set to None to make it non-blocking (only useful for testing
        purposes).

    traits : dict
        Attributes of the created object. Used to override the defaults.

    Returns
    -------
    Tuple with the object created and the data to create it since it is to be
    contributed to the SimpleDataSource.
    """
    defaults = dict(
        name="New Resin", resin_type='CEX', ligand='SO3',
        average_bead_diameter=UnitScalar(0.0, units='um'),
        ligand_density=UnitScalar(0.0, units=chr_units.milli_molar),
        settled_porosity=UnitScalar(0.0, units=chr_units.fraction)
    )
    defaults.update(traits)

    model = Resin(**defaults)
    view = ResinView(model=model)
    return _show_view_and_return_model(view, kind)
Beispiel #9
0
    def test_scalar_convert_units(self):
        scalar_data = UnitScalar(1, units=chr_units.length.m)
        conv_data = convert_units(scalar_data, chr_units.length.cm)
        self.assertEqual(conv_data, UnitScalar(100, units=chr_units.length.cm))

        # convert back to original units and check
        conv_data_2 = convert_units(conv_data, scalar_data.units)
        self.assertEqual(conv_data_2, scalar_data)
Beispiel #10
0
def test_offset_unit_computations():
    """ Executing some basic computations with a basic custom unit with offset.
    """
    my_u = unit(12, m.derivation, 14)
    s1 = UnitScalar(3, units=my_u)
    s2 = UnitScalar(5, units=my_u)
    s3 = s1 + s2
    assert_equal(s3, UnitScalar(8, units=my_u))
    def test_vol_std_units_with_vol_flow(self):
        volume = UnitScalar(1., units="liter")
        time = vol_to_time(volume, self.flow_rate_vol)
        self.assertAlmostEqual(time, 1.)

        volume = UnitScalar(3., units="liter")
        time = vol_to_time(volume, self.flow_rate_vol)
        self.assertAlmostEqual(time, 3.)
 def _bed_height_actual_default(self):
     # return the minimum possible height if column_type is given, else 0.0
     if self.column_type is not None:
         bed_height_min, _ = self.column_type.bed_height_range
         range_units = self.column_type.bed_height_range.units
         bed_height_min = UnitScalar(bed_height_min, units=range_units)
         return bed_height_min
     return UnitScalar(0.0, units='cm')
Beispiel #13
0
 def test_offset_unit_computations(self):
     """ Basic computations with a basic custom unit with offset.
     """
     my_u = unit(12, m.derivation, 14)
     s1 = UnitScalar(3, units=my_u)
     s2 = UnitScalar(5, units=my_u)
     s3 = s1 + s2
     self.assertEqual(s3, UnitScalar(8, units=my_u))
    def test_compute_with_volume_in_CV_units(self):
        time = UnitScalar(1., units="minute")
        volume = time_to_volume(time, self.flow_rate_vol, to_unit="liter")
        assert_unit_scalar_almost_equal(volume, UnitScalar(1., units="liter"))

        time = UnitScalar(3., units="minute")
        volume = time_to_volume(time, self.flow_rate_vol, to_unit="liter")
        assert_unit_scalar_almost_equal(volume, UnitScalar(3., units="liter"))
    def test_time_std_units_with_vol_flow(self):
        time = UnitScalar(1., units="minute")
        volume = time_to_volume(time, self.flow_rate_vol, self.column)
        assert_unit_scalar_almost_equal(volume, UnitScalar(1., units="CV"))

        time = UnitScalar(3., units="minute")
        volume = time_to_volume(time, self.flow_rate_vol, self.column)
        assert_unit_scalar_almost_equal(volume, UnitScalar(3., units="CV"))
 def test_convert_with_unit_change(self):
     expected_lin_flow = UnitScalar(1., units="cm/minute")
     diam = UnitScalar(2 / np.sqrt(0.1 * np.pi), units="0.1*m")
     vol_flow_rate = UnitScalar(1., units="liter/minute")
     lin_flow = volumetric_flow_rate_to_linear(vol_flow_rate,
                                               diam,
                                               to_unit="cm/minute")
     self.assertTrue(unit_scalars_almost_equal(lin_flow, expected_lin_flow))
Beispiel #17
0
 def _strip_component_default(self):
     ext_coef_units = chr_units.extinction_coefficient_unit
     strip_comp = ProductComponent(
         name=STRIP_COMP_NAME, target_product=self.name,
         molecular_weight=UnitScalar(0.0, units=chr_units.kilogram_per_mol),
         extinction_coefficient=UnitScalar(0.0, units=ext_coef_units),
     )
     return strip_comp
Beispiel #18
0
 def test_modified_simple_datasource_via_list(self):
     # FIXME: adding to the datasource currently means adding to the
     # object_catalog, to the data catalog and the corresponding list
     new_comp = Component(name="New Component",
                          charge=UnitScalar(0.0, units='1'),
                          pKa=UnitScalar(0.0, units='1'))
     self.ds.set_object_of_type("components", new_comp)
     self.ds.make_clean()
     assert_file_roundtrip_identical(self.ds)
    def test_set_flow_range(self):
        model_view = self._get_model_view()

        new_flow_range_min = UnitScalar(1, units=ml_per_min)
        new_flow_range_max = UnitScalar(2, units=ml_per_min)
        model_view.system_type_flow_range_max = new_flow_range_max
        model_view.system_type_flow_range_min = new_flow_range_min
        new_flow_range = UnitArray([1, 2], units=ml_per_min)
        self.assertEqual(self.model.flow_range, new_flow_range)
 def setUp(self):
     self.flow_rate_vol = UnitScalar(1., units="liter/minute")
     self.flow_rate_lin = UnitScalar(1., units="cm/minute")
     column_type = ColumnType(**COLUMN_TYPE_DATA)
     self.column = Column(column_type=column_type, **COLUMN_DATA)
     self.column.column_type.diameter = UnitScalar(10, units='cm')
     self.column.column_type.bed_height_range = UnitArray([10., 30.],
                                                          units="cm")
     self.column.volume = UnitScalar(1, units='liter')
 def setUp(self):
     # Make some data to play with.
     self.meter_array = UnitArray([1., 2, 3], units=meters)
     self.second_array = UnitArray([3., 2, 1], units=second)
     self.feet_array = UnitArray([4., 5, 6], units=feet)
     self.meter_scalar = UnitScalar(1., units=meters)
     self.second_scalar = UnitScalar(3., units=second)
     self.feet_scalar = UnitScalar(4., units=feet)
     unittest.TestCase.setUp(self)
    def test_change_strip_fraction_bad_value(self):
        self.experim.strip_mass_fraction = UnitScalar(2, units="%")
        load = self.experim.method.load.solutions[0]
        self.assertAlmostEqual(load.product_component_assay_values[-1], 2.)

        # This will fail by raising an exception, in the
        self.experim.strip_mass_fraction = UnitScalar(3, units="cm")
        self.assertAlmostEqual(load.product_component_assay_values[-1], 2.)
        assert_unit_scalar_almost_equal(self.experim.strip_mass_fraction,
                                        UnitScalar(2, units="%"))
    def test_get_step_start_time_no_offline_steps(self):
        self.experim.method.offline_steps = []
        load_start = self.experim.get_step_start_time(self.experim.method.load)
        expected = UnitScalar(self.load_time, units="min")
        assert_unit_scalar_almost_equal(load_start, expected)

        strip_step = self.experim.method.get_step_of_type(STRIP_STEP_TYPE)
        strip_start = self.experim.get_step_start_time(strip_step)
        expected = UnitScalar(self.strip_time, units="min")
        assert_unit_scalar_almost_equal(strip_start, expected)
Beispiel #24
0
 def get_instance(self, constructor_data):
     # Attribute was renamed: akta_settings -> import_settings
     settings = constructor_data['kwargs'].pop("akta_settings")
     # We used to store the value as a float: convert to UnitScalar
     too = settings["time_of_origin"]
     settings["time_of_origin"] = UnitScalar(too, units="minute")
     settings["holdup_volume"] = UnitScalar(0., units="minute")
     constructor_data['kwargs']["import_settings"] = settings
     return super(experimentResultsDeSerializer,
                  self).get_instance(constructor_data)
    def test_vol_std_units_with_lin_flow(self):
        volume = UnitScalar(1., units="liter")
        time = vol_to_time(volume,
                           flow_rate=self.flow_rate_lin,
                           column=self.column)
        self.assertAlmostEqual(time, 40. / np.pi)

        volume = UnitScalar(3., units="liter")
        time = vol_to_time(volume, self.flow_rate_lin, column=self.column)
        self.assertAlmostEqual(time, 120. / np.pi)
Beispiel #26
0
 def test_g_per_liter_resin_to_cv_conc_units(self):
     """ g/L_resin -> CV, passing concentration in different unit.
     """
     concentration = UnitScalar(8030, units="g/m**3")
     vol = UnitScalar(0.0635, units=chr_units.g_per_liter_resin)
     expected = UnitScalar(0.0635 / 8.03, units="CV")
     new_vol = convert_units(vol,
                             tgt_unit="CV",
                             concentration=concentration)
     assert_unit_scalar_almost_equal(new_vol, expected)
    def test_calculate_step_yield(self):
        pool_concentration = UnitScalar(1, units="g/liter")
        pool_volume = UnitScalar(1, units="CV")
        step_volume = UnitScalar(1, units="CV")
        step_flow_rate = UnitScalar(100, units="liter/minute")
        sols = [
            SolutionWithProduct(product_concentration=pool_concentration,
                                name="Sol")
        ]
        load_step = MethodStep(step_type="Load",
                               name="Load",
                               solutions=sols,
                               flow_rate=step_flow_rate,
                               volume=step_volume)
        step_yield = calculate_step_yield(pool_concentration, pool_volume,
                                          load_step)
        assert_unit_scalar_almost_equal(step_yield, UnitScalar(100, units="%"))

        pool_concentration09 = UnitScalar(0.9, units="g/liter")
        step_yield = calculate_step_yield(pool_concentration09, pool_volume,
                                          load_step)
        assert_unit_scalar_almost_equal(step_yield, UnitScalar(90, units="%"))

        pool_volume = UnitScalar(0.9, units="CV")
        step_yield = calculate_step_yield(pool_concentration, pool_volume,
                                          load_step)
        assert_unit_scalar_almost_equal(step_yield, UnitScalar(90, units="%"))
Beispiel #28
0
    def _get_strip_mass_fraction(self):
        # get the assay value for the Strip assay
        if STRIP_COMP_NAME in self.product.product_component_assays:
            strip_idx = self.product.product_component_assays.index(
                STRIP_COMP_NAME)
        else:
            return UnitScalar(np.nan, units="%")

        assay_values = self.product_component_assay_values
        val = assay_values[strip_idx]
        return UnitScalar(val, units=assay_values.units)
    def test_time_std_units_with_lin_flow(self):
        time = UnitScalar(10., units="minute")
        volume = time_to_volume(time,
                                flow_rate=self.flow_rate_lin,
                                column=self.column)
        self.assertAlmostEqual(volume, UnitScalar(np.pi / 4., units="CV"))

        time = UnitScalar(30., units="minute")
        volume = time_to_volume(time, self.flow_rate_lin, column=self.column)
        assert_unit_scalar_almost_equal(volume,
                                        UnitScalar(3 * np.pi / 4., units="CV"))
    def test_get_step_start_time_default_offline_steps(self):
        self.assertEqual(self.experim.method.offline_steps,
                         ['Pre-Equilibration', 'Equilibration'])
        load_start = self.experim.get_step_start_time(self.experim.method.load)
        expected = UnitScalar(0., units="min")
        assert_unit_scalar_almost_equal(load_start, expected)

        strip_step = self.experim.method.get_step_of_type(STRIP_STEP_TYPE)
        strip_start = self.experim.get_step_start_time(strip_step)
        expected = UnitScalar(self.strip_time - self.load_time, units="min")
        assert_unit_scalar_almost_equal(strip_start, expected)