kromatography.model.factories package

Submodules

kromatography.model.factories.api module

API functions and classes for the Reveal Chromatography model factory sub-package.

kromatography.model.factories.binding_model module

kromatography.model.factories.binding_model.create_binding_model(num_components, model_type='STERIC MASS ACTION', **traits)[source]

Create binding model w/ default values inspired from realistic models.

Parameters:
  • num_components (int) – Number of components including the cation/salt component.
  • model_type (str) – Type of binding model to create. Must be one of the values listed in :py:`kromatography.model.binding_model.BINDING_MODEL_TYPES`.
  • traits (dict) – Additional attributes for the binding model to be created with.

kromatography.model.factories.job_manager module

kromatography.model.factories.job_manager.create_start_job_manager(max_workers=0, executor='ProcessPoolExecutor')[source]

Create and start an async job manager.

NOTE: it is critical to avoid saturating the Operating System by calling this function many times. If too many process pools are created, segfaults can be seen in particular on OSX. The right approach is to create one job manager, and to make sure that no matter what happens during execution it gets shutdown before new ones are created.

Parameters:max_workers (int) – Max number of processor workers used by the job manager. If left at 0, all available processors in the machine minus 1 will be used (leaving 1 processor to handle the application’s UI and other tasks).

kromatography.model.factories.method module

Build Methods for simulations from existing (experimental?) methods.

kromatography.model.factories.method.build_sim_method_from_method(source_method, first_simulated_step, last_simulated_step, initial_buffer=None, **method_traits)[source]

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:

Generated method to build a simulation around.

Return type:

Method

kromatography.model.factories.method.set_method_initial_buffer(target_method, source_method, step_indices, initial_buffer=None)[source]

Set initial conditions to provided initial_buffer or from source method

Parameters:
  • target_method (Instance(Method)) – Method being built from source_method.
  • source_method (Instance(Method)) – Experiment or source method to build the simulation method from.
  • step_indices (dict) – Mapping between step descriptions and step number in the source method.
  • initial_buffer (Buffer [OPTIONAL]) – Name of the buffer to set the method’s initial condition. Not needed if it should be set from the step before the first simulated step.
kromatography.model.factories.method.build_sim_steps_from_exp_steps(expt_method_steps, simulated_step_idx)[source]

Build the list of method steps that a simulation must contain.

Make a (deep) copy of the relevant experiment steps, keeping all uses of a solution pointing to the same object, though that object should be copies of the experiment’s solutions.

kromatography.model.factories.method.check_step_index_consistency(step_indices, first_simulated_step, last_simulated_step, initial_buffer)[source]

Check that the step_indices found are consistent with expectations.

Parameters:
  • step_indices (dict) – Mapping between step descriptions and step number in the source method.
  • first_simulated_step (str) – Name of the first step to simulate.
  • last_simulated_step (str) – Name of the last step to simulate.
  • initial_buffer (Buffer or None) – Name of the buffer to set the method’s initial condition if any.
Returns:

  • bool – Whether the step_indices dict is consistent.
  • str – Message about what is inconsistent if anything.

kromatography.model.factories.product module

kromatography.model.factories.product.add_strip_to_product(source_prod, strip_mol_weight=0.0, strip_ext_coef=0.0)[source]

Build a new product to create a version which contains a strip comp.

Parameters:
  • source_prod (Product) – Product to copy and add a strip component to.
  • strip_mol_weight (float or UnitScalar) – Molecular weight of the future strip component to be added.
  • strip_ext_coef (float or UnitScalar) – Extinction coefficient of the future strip component to be added.
Returns:

New Product instance created as the copy of the input product and the newly created strip ProductComponent instance.

Return type:

tuple

kromatography.model.factories.product_component_assay module

kromatography.model.factories.product_component_assay.assay_names_from_instances(component_assay_list)[source]

Convert a list of ProductComponentAssays into a list of assay names.

kromatography.model.factories.product_component_assay.assay_instances_from_names(assay_names)[source]

List of instances of ProductComponentAssays from a list of assay names.

kromatography.model.factories.simulation module

kromatography.model.factories.simulation.generate_sim_name(expt_name)[source]

Generate a simulation name from an experiment name.

kromatography.model.factories.simulation.build_simulation_from_experiment(experiment, binding_model=None, transport_model=None, name='', fstep='Load', lstep='Strip', initial_buffer=None, lazy_loading=False, **traits)[source]

Build a Simulation object given an experiment and some models.

Now only used for testing purposes.

Parameters:
  • experiment (Experiment) – Source experiment to build the simulation from.
  • binding_model (BindingModel [OPTIONAL]) – Binding model to build the simulation from. If not provided, a default model with default value will be generated.
  • transport_model (TransportModel [OPTIONAL]) – Transport model to build the simulation from. If not provided, a default model with default value will be generated.
  • name (str [OPTIONAL]) – Name of the future simulation
  • fstep (str [OPTIONAL, default='Load']) – Name of the first step to simulate. Defaults to ‘Load’.
  • lstep (str [OPTIONAL, default='Strip']) – Name of the last step to simulate. Defaults to ‘Strip’.
  • initial_buffer (Buffer [OPTIONAL]) – Buffer instance to use as initial buffer for the simulation method. If not provided, the buffer in the experimental step before the first simulated step will be used.
  • lazy_loading (bool [OPTIONAL, default=False)) – Should the resulting simulation be of LazyLoadingSimulation type?

kromatography.model.factories.simulation_group module

Classes and utilities to create a SimulationGroup around a center point simulation.

kromatography.model.factories.simulation_group.param_scans_to_sim_group(group_name, parameter_scans, center_sim, lazy_loading=False, max_size=None, group_type='Multi-Param Grid', group_size=-1, auto_delete_run_sims=False)[source]

Returns simulation grid from a list of regular parameter scans.

Parameters:
  • group_name (str) – Target group name.
  • parameter_scans (list(ParameterScanDescription)) – List of parameter scan descriptions.
  • center_sim (Simulation) – Center point simulation from which to create all simulations in the future group.
  • group_type (str [OPTIONAL]) – Type of the future group(s) to be created. Should be one of the values allowed for the simulation_group.SimulationGroup.type attribute. Set to a regular grid by default.
  • lazy_loading (bool (default: False)) – Save memory by making the output group of the lazy loading kind.
  • max_size (None or int [OPTIONAL]) – Max size of the group(s) created. If a non-zero value is specified, a list of simulation group is returned, each with a number of simulation diffs smaller or equal to max_size.
  • group_size (int [OPTIONAL]) – Size of the resulting group, used only if of Monte-Carlo type. Size is computed from parameter scan descriptions for the grid type.
  • auto_delete_run_sims (bool [OPTIONAL, default=False]) – Delete CADET files and in memory simulations once they run?
Returns:

SimulationGroup created from the list of parameter scans the group should explore. If a max_size is provided, returns a list of SimulationGroup instances collectively scanning the entire parameter space described by parameter_scans, each with 0 < size <= max_size.

Return type:

SimulationGroup or list(SimulationGroup)

kromatography.model.factories.simulation_group.build_random_simulation_group(center_sim, param_names, group_size=200, dist_types='uniform', dist_desc=None, lazy_loading=False, max_block_size=None, group_name='New MC group', adtl_params=None)[source]

Build a simulation group around a center point scanning a list of parameters randomly. Useful for scripting tools.

Parameters:
  • center_sim (Simulation) – Simulation around which to build the grid.
  • param_names (List) – List of parameters to scan in the grid.
  • group_size (int [OPTIONAL, default=200]) – Number of simulations to generate to explore the space.
  • dist_types (str or list of str [OPTIONAL, default="uniform"]) – Type(s) of sampling distributions for each parameter scanned. Supported values are “uniform”, “normal”.
  • dist_desc (str or list of str) – Parameters of the sampling distributions for each parameter scanned, in the order of the constructor of the chosen distribution. That is the low (inclusive) and high (EXclusive) if “uniform” is chosen, and mean and standard deviation if “normal” is chosen.
  • lazy_loading (bool) – Whether to force the center simulation to be a lazy loading simulation, to conserve RAM.
  • max_block_size (int) – Maximum group size for the resulting group. If the needed group is larger, a list of groups will be created and returned.
  • group_name (str) – Name of the resulting group.
  • adtl_params (dict) – Map between parameters and adjustment parameters that must be changed at the same time.
Returns:

SimulationGroup created from the list of parameter scans the group should explore. If a max_size is provided, returns a list of SimulationGroup instances collectively scanning the entire parameter space described by parameter_scans, each with 0 < size <= max_size.

Return type:

SimulationGroup or list(SimulationGroup)

kromatography.model.factories.simulation_group.build_simulation_grid(sim, param_names, num_values=20, val_ranges=0.25, lazy_loading=True)[source]

Build a grid around a center point scanning a list of parameters over a range. Useful for scripting tools.

The resulting grid is built with linear spacing.

Parameters:
  • sim (Simulation) – Simulation around which to build the grid.
  • param_names (List) – List of parameters to scan in the grid.
  • num_values (int [OPTIONAL, default=20]) – Number of values to scan, in each dimension.
  • val_ranges (float or list [OPTIONAL, default=0.25]) – If float, the range to scan is relative to the center value. By default, that range is 25%. If a list is specified, it must be the same length as the number of parameters to scan. A list of floats applies potentially different relative ranges for each parameter. A list of tuples must specify, for each parameter scanned, the low and high values to define the range.
  • lazy_loading (bool) – Leave all simulation data/results on disk? Otherwise, the data is brought in memory.
kromatography.model.factories.simulation_group.build_group_or_groups(group_name, center_sim, simulation_diffs, max_size, group_type='Multi-Param Grid', auto_delete_run_sims=False)[source]

Build a group or a list of groups from simulation diffs based on the group size limit.

Parameters:
  • group_name
  • center_sim (Simulation) – Simulation from which to build the group.
  • simulation_diffs (list) – List of simulation differences to build the group’s simulation from.
  • max_size (int) – Max size of the future simulation group. If the resulting group will be bigger, a list of groups is returned rather than 1 group. Then, each group has a size less or equal to max_size.
  • group_type (str [OPTIONAL, default="Multi-Param Grid"]) – Type of simulation group to build. Must be “Multi-Param Grid” or “Monte-Carlo Exploration”.
  • auto_delete_run_sims (bool [OPTIONAL, default=False]) – Delete CADET files and in memory simulations once they run?
Returns:

SimulationGroup created from the list of parameter scans the group should explore. If a max_size is provided, returns a list of SimulationGroup instances collectively scanning the entire parameter space described by parameter_scans, each with 0 < size <= max_size.

Return type:

SimulationGroup or list(SimulationGroup)

kromatography.model.factories.simulation_group.sim_diffs_from_grid_parameter_scans(parameter_scans)[source]

Transform a list of ParameterScanDescription into a list of all possible SimulationDiffs to scan all combinations of parameter values.

Parameters:parameter_scans (list) – List of ParameterScanDescriptions, each defining a different dimension being scanned by the future group. What is returned is all combinations of parameter values.
Returns:List of tuples of SimulationDiff objects to build a SimulationGroup from.
Return type:list

Notes

Instead of 1 ParameterScanDescription per element in parameter_scans, it is possible to have a N-tuple of ParameterScanDescription. In that case, it is treated as the need for N parameters to be changed simultaneously. For example, this can be needed when scanning a proportion of a component, and needing to adjust another one every time to keep the total at 100%.

Examples

>>> parameters = [
    ParameterScanDescription(
        name="method.method_steps[2].flow_rate",
        low=50, high=100, num_values=2
    ),
    ParameterScanDescription(
        name="method.collection_criteria.start_collection_target",
        low=30, high=60, num_values=2
    ),
]
>>> sim_diffs_from_grid_parameter_scans(parameters)
[(SingleParamSimulationDiff(extended_attr='method.method_steps[2].flow_rate', val=50.0),
  SingleParamSimulationDiff(extended_attr='method.collection_criteria.start_collection_target', val=30.0)),
 (SingleParamSimulationDiff(extended_attr='method.method_steps[2].flow_rate', val=50.0),
  SingleParamSimulationDiff(extended_attr='method.collection_criteria.start_collection_target', val=60.0)),
 (SingleParamSimulationDiff(extended_attr='method.method_steps[2].flow_rate', val=100.0),
  SingleParamSimulationDiff(extended_attr='method.collection_criteria.start_collection_target', val=30.0)),
 (SingleParamSimulationDiff(extended_attr='method.method_steps[2].flow_rate', val=100.0),
  SingleParamSimulationDiff(extended_attr='method.collection_criteria.start_collection_target', val=60.0))]
kromatography.model.factories.simulation_group.sim_diffs_from_random_parameter_scans(parameter_scans, group_size, adtl_params=None)[source]

Transform all RandomParameterScanDescription into a list of Simulation diffs.

Parameters:
  • parameter_scans (list) – List of RandomParameterScanDescription describing which parameters to scan and following which random distribution.
  • group_size (int) – Number of random values to generate. Corresponds to the future size of the group.
  • adtl_params (dict) –

    Map between scanned parameter names and a list of additional parameters that must be modified in the same simulation. If that’s the case, the values must be lists of 2-tuples, containing the attribute path for the additional parameter that must change in sync and a callable which receives the random value of the source parameter and returns the value of the additional parameter.

    This advanced feature can be needed when scanning a proportion of a component, and needing to adjust another one every time to keep the total at 100%.

Examples

This will create a 100 size simulation group scanning uniformly the elution flow rate and the start collect:

>>> parameters = [
RandomParameterScanDescription(
name=”method.method_steps[2].flow_rate”, distribution=”uniform”, dist_param1=50, dist_param2=100

), RandomParameterScanDescription(

name=”method.collection_criteria.start_collection_target”, distribution=”uniform”, dist_param1=30, dist_param2=50

),

]

>>> sim_diffs_from_random_parameter_scans(parameters, 100)
[(SingleParamSimulationDiff...]
kromatography.model.factories.simulation_group.build_5_point_groups_from_param_desc(cp_sim, param_list, param_labels=None)[source]

Build 5-point simulation groups from a list of parameters to study their impact on performances. Parameter descriptions specify their operational and characterization ranges.

Parameters:
  • cp_sim (Simulation) – Center point simulation around which to scan and compare to.
  • param_list (dict) – Dictionary mapping parameter paths to scan to a tuple describing how to scan it. That tuple must be of length 4, containing respectively the low operating value, high operating value, low characterization value and high characterization value. All values must be in the unit the center point simulation has that parameter in, if applicable. Note that both keys and values can be replaced with tuples of paths and tuples of 4-value tuples when multiple parameters must be scanned together.
  • param_labels (dict [OPTIONAL]) – Map between a parameter path and a nice string representation for it. It will be used as the grid’s name.
Returns:

Map between the parameter path to explore (the first one in each dimension) and the corresponding simulation group to run.

Return type:

dict

kromatography.model.factories.study module

kromatography.model.factories.study.build_study_from_experimental_study(experimental_study, study_name='', study_purpose='')[source]

Create a new Study from an experimental Study.

kromatography.model.factories.transport_model module

kromatography.model.factories.transport_model.create_transport_model(num_components, transport_model_type='GENERAL_RATE_MODEL', **traits)[source]

Create a new Transport model.

Parameters:
  • num_components (int) – Number of components including the cation component.
  • traits (dict) – Additional attributes for the General rate model. In particular it is expected to contain a target_product value.
  • inspired from realistic values. (Default) –

kromatography.model.factories.user_datasource module

class kromatography.model.factories.user_datasource.DataSourceObjectCatalogBuilder(**traits)[source]

Bases: kromatography.model.data_source.InMemoryDataSource

Build an object catalog for a UserDataSource from one of the default data catalog that ship with kromatography. Used to initialize the user datasource when users start.

Note that

data_catalog = Dict

Dict containing data for known types of objects needed for a study

object_catalog = Dict

Dict containing objects for known types of objects needed for a study

ordered_object_types = List

List of object types to create, in order they need to be built.

get_data_by_type(type_id, key=('name', None))[source]

Returns the data to build an object of type type_id, that match the key value passed as key attr. The lookup on the key is done by ignoring letter case and treating _ and spaces the same (standardize).

TODO: support passing a list of keys.

get_data_of_type(type_id, obj_name)[source]

Returns the data for type type_id, that match the provided name.

This relies on the fact that there can be only 1 object of a given type with a given name.

build_object_catalog()[source]

Convert the catalog (which contains data) into a catalog of objects

build_all_objects_for_type(object_type)[source]
build_object_from_data(object_type, object_data)[source]

General object builder from stored data.

build_chemical_from_data(chemical_data)[source]

Custom object builder from stored chemical data.

build_product_from_data(product_data)[source]

Custom object builder from stored product data.