def setUp(self):
        # Register all views
        BaseModelViewTestCase.setUp(self)

        # Build a model you want to visualize:
        testmethod = Method(**METHOD_DATA)
        self.model = testmethod

        empty_step_method_data = METHOD_DATA.copy()
        empty_step_method_data["method_steps"] = []
        self.empty_step_method = Method(**empty_step_method_data)
        self.initialize_datasource()
    def setUp(self):
        # Manual construction
        column_type = ColumnType(**COLUMN_TYPE_DATA)
        resin = Resin(**RESIN_DATA)
        column = Column(column_type=column_type, resin=resin, **COLUMN_DATA)
        method = Method(**METHOD_DATA)

        self.sim_from_scratch = Simulation(name='Sim1',
                                           column=column,
                                           method=method,
                                           output=None)
        self.sim_from_std_exp = make_sample_simulation()
    def setUp(self):
        # Manual construction
        column_type = ColumnType(**COLUMN_TYPE_DATA.copy())
        resin = Resin(**RESIN_DATA.copy())
        column = Column(column_type=column_type,
                        resin=resin,
                        **COLUMN_DATA.copy())
        method = Method(**deepcopy(METHOD_DATA))

        self.sim_from_scratch = Simulation(name='Sim1',
                                           column=column,
                                           method=method,
                                           output=None)
        self.expected_sec_times = array([0., 540., 1080., 1620., 7668.])
示例#4
0
 def test_construction_duplicate_step_name(self):
     # Make data with redundant step names:
     data = {
         'name':
         'method-1',
         'run_type':
         'Gradient Elution',
         'method_steps': [
             MethodStep(**PRE_EQUIL_STEP),
             MethodStep(**PRE_EQUIL_STEP),
             MethodStep(**LOAD_STEP),
             MethodStep(**GRADIENT_ELUTION_STEP)
         ],
     }
     with self.assertRaises(ValueError):
         Method(**data)
示例#5
0
def make_sample_experiment(name='Run 1'):
    """ Make a sample experiment for testing purposes from example data.
    """
    from kromatography.model.column import Column, ColumnType
    from kromatography.model.resin import Resin
    from kromatography.model.method import Method
    from kromatography.model.system import System, SystemType
    from kromatography.model.experiment import Experiment
    from kromatography.model.tests.example_model_data import COLUMN_TYPE_DATA,\
        COLUMN_DATA, METHOD_DATA, RESIN_DATA, SYSTEM_TYPE_DATA, SYSTEM_DATA

    column_type = ColumnType(**COLUMN_TYPE_DATA)
    resin = Resin(**RESIN_DATA)
    column = Column(column_type=column_type, resin=resin, **COLUMN_DATA)
    system_type = SystemType(**SYSTEM_TYPE_DATA)
    system = System(system_type=system_type, **SYSTEM_DATA)
    method = Method(**METHOD_DATA)

    expr = Experiment(
        name=name, system=system, column=column, method=method,
        output=None
    )
    return expr
示例#6
0
 def setUp(self):
     self.method = Method(**METHOD_DATA)
示例#7
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.method = Method(**METHOD_DATA)

    # -------------------------------------------------------------------------
    # Tests
    # -------------------------------------------------------------------------

    def test_construction(self):
        method = self.method
        # Default data contains a Pre-Equil, an Equil, a Load, and a Gradient
        # Elution
        self.assertEqual(method.num_steps, 4)
        for key, val in METHOD_DATA.iteritems():
            self.assertEqual(getattr(method, key), val)

    def test_construction_duplicate_step_name(self):
        # Make data with redundant step names:
        data = {
            'name':
            'method-1',
            'run_type':
            'Gradient Elution',
            'method_steps': [
                MethodStep(**PRE_EQUIL_STEP),
                MethodStep(**PRE_EQUIL_STEP),
                MethodStep(**LOAD_STEP),
                MethodStep(**GRADIENT_ELUTION_STEP)
            ],
        }
        with self.assertRaises(ValueError):
            Method(**data)

    def test_get_load(self):
        # Remove load from method
        load = self.method.method_steps.pop(2)
        with self.assertRaises(ValueError):
            self.method.load

        # Put load back and look it up
        self.method.method_steps.insert(2, load)
        self.assertIs(self.method.load, load)

    def test_get_step(self):
        with self.assertRaises(ValueError):
            self.method.get_step_of_type("")

        step = self.method.get_step_of_type('Pre-Equilibration')
        assert_has_traits_almost_equal(step, MethodStep(**PRE_EQUIL_STEP))
        step = self.method.get_step_of_type('Gradient Elution')
        assert_has_traits_almost_equal(step,
                                       MethodStep(**GRADIENT_ELUTION_STEP))

        # Collect step number
        step, num = self.method.get_step_of_type('Pre-Equilibration',
                                                 collect_step_num=True)
        assert_has_traits_almost_equal(step, MethodStep(**PRE_EQUIL_STEP))
        self.assertEqual(num, 0)

        # Don't raise on failures
        self.method.get_step_of_type("", handle_not_unique='warn')

    def test_get_step_by_name(self):
        with self.assertRaises(ValueError):
            self.method.get_step_of_name("")

        step = self.method.get_step_of_name('Pre-Equilibration')
        assert_has_traits_almost_equal(step, MethodStep(**PRE_EQUIL_STEP))
        step = self.method.get_step_of_name('whatever name')
        assert_has_traits_almost_equal(step, MethodStep(**LOAD_STEP))

        # Collect step number
        step, num = self.method.get_step_of_name('whatever name',
                                                 collect_step_num=True)
        assert_has_traits_almost_equal(step, MethodStep(**LOAD_STEP))
        self.assertEqual(num, 2)

        # Don't raise on failures
        self.method.get_step_of_name("", handle_not_unique='warn')

    def test_initial_buffer(self):
        from kromatography.model.tests.example_model_data import \
            buffer_equil_wash1

        self.assertEqual(self.method.initial_buffer_name, '')
        self.assertIsNone(self.method.initial_buffer)
        self.method.initial_buffer = buffer_equil_wash1
        self.assertEqual(self.method.initial_buffer_name, 'Equil_Wash_1')
        self.assertEqual(self.method.initial_buffer.name, 'Equil_Wash_1')
def build_sim_method_from_method(source_method,
                                 first_simulated_step,
                                 last_simulated_step,
                                 initial_buffer=None,
                                 **method_traits):
    """ Build a simulation method from a source/experiment method.

    Parameters
    ----------
    source_method : Instance(Method)
        Experiment or source method to build the simulation method from.

    first_simulated_step : str
        Name of the first MethodStep in method to simulate.

    last_simulated_step : str
        Name of the last MethodStep in method to simulate.

    initial_buffer : Buffer [OPTIONAL]
        Name of the buffer to set the method's initial condition. If not
        provided, this function will try to set it from the step before the
        first simulated step.

    Returns
    -------
    Method
        Generated method to build a simulation around.
    """
    expt_col_criteria = source_method.collection_criteria
    if expt_col_criteria is None:
        col_criteria = None
    else:
        col_criteria = expt_col_criteria.clone_traits(copy='deep')

    if "name" not in method_traits:
        method_traits["name"] = "Sim method from {}".format(source_method.name)

    method = Method(run_type=source_method.run_type,
                    collection_criteria=col_criteria,
                    **method_traits)

    source_method_steps = source_method.method_steps
    _, start_step_num = source_method.get_step_of_name(first_simulated_step,
                                                       collect_step_num=True)
    _, stop_step_num = source_method.get_step_of_name(last_simulated_step,
                                                      collect_step_num=True)
    step_indices = {
        first_simulated_step: start_step_num,
        last_simulated_step: stop_step_num
    }

    # Specify what step comes before the first one to set the first
    # simulated step's initial conditions
    if step_indices[first_simulated_step] == 0:
        step_indices[INITIAL_CONDITION] = None
    else:
        step_indices[INITIAL_CONDITION] = \
            step_indices[first_simulated_step] - 1

    # Pooling step, that is, step which creates the pool in the simulation
    # (used for performance parameter computation):
    if source_method.collection_step_number == UNSET:
        step_indices[POOLING_STEP] = UNSET
    else:
        pooling_step_num = source_method.collection_step_number - \
            start_step_num
        step_indices[POOLING_STEP] = pooling_step_num

    valid, check_msg = check_step_index_consistency(step_indices,
                                                    first_simulated_step,
                                                    last_simulated_step,
                                                    initial_buffer)
    if not valid:
        msg = "Failed to build the simulation's method from method {}. Issue" \
              " is {}".format(method.name, check_msg)
        logger.error(msg)
        raise ValueError(msg)

    simulated_step_idx = range(step_indices[first_simulated_step],
                               step_indices[last_simulated_step] + 1)
    method.method_steps = build_sim_steps_from_exp_steps(
        source_method_steps, simulated_step_idx)

    set_method_initial_buffer(method,
                              source_method,
                              step_indices,
                              initial_buffer=initial_buffer)

    method.collection_step_number = step_indices[POOLING_STEP]
    return method