def __init__(self, abd, layup): dia_o = layup.dia_o dia_i = layup.dia_i omega = layup.omega r_o = 0.5 * layup.dia_o # AXIAL STIFFNESS load_a = Load(1, 0, 0, 0) strain_a = Strain(load_a, abd, layup) self.EA = 1 / strain_a.eps[0, 0] # TORSIONAL STIFFNESS load_t = Load(0, 0, 1, 0) strain_t = Strain(load_t, abd, layup) self.JG = r_o / strain_t.eps[2, 0] # BENDING STIFFNESS z = 0.5 * layup.dia_i * math.cos(omega) def stiffness(omega): return (1 / abd[0, 0]) * z**2 + (1 / abd[3, 3]) * math.cos(omega)**2 # Determine intergral using scipy's integrate.quad function. # The function return value is a tuple, with the first element holding # the estimated value of the integral and the second element holding an # upper bound on the error. [0] index used to return estimated value. self.EI = dia_i * scipy.integrate.quad(lambda omega: stiffness(omega), 0, math.pi)[0]
def test_splice_illegal(): # Try to splice onto a descendant of the source node. strain = Strain( ( ( (), ), ) ) assert_raises( IndexError, lambda: strain.splice([0], [0, 0]) ) # Try to create a node with too many children. strain = Strain( ( (), ( (), ), ) ) assert_raises( ValueError, lambda: strain.splice([1, 0], [0]) )
def main(): # Load bioreactor config file and initialise bioreactor object bioreactor_config_yaml = "./bioreactor_config.yaml" with open(bioreactor_config_yaml, 'r') as yaml_file: bioreactor_config = yaml.load(yaml_file, Loader=yaml.FullLoader) bioreactor = Bioreactor(bioreactor_config) # Load strain config file and initialise strain object strain_config_yaml = "./P_strain_config.yaml" with open(strain_config_yaml, 'r') as yaml_file: strain_config = yaml.load(yaml_file, Loader=yaml.FullLoader) P_strain = Strain(bioreactor, strain_config) # Load strain config file and initialise strain object strain_config_yaml = "./Q_strain_config.yaml" with open(strain_config_yaml, 'r') as yaml_file: strain_config = yaml.load(yaml_file, Loader=yaml.FullLoader) Q_strain = Strain(bioreactor, strain_config) output_dir = "./output/" n_passages = args.n_passages PCN = args.PCN time = args.time # Make time vector (minutes) t = np.arange(0, time, 0.01) # Make list of strains strain_list = [P_strain] # Generate integration inputs and prepare objects species_keys, y0 = generate_integrate_inputs(bioreactor, strain_list) plot_species = ['P_N'] # Run simple growth curve experiment run_growth_curve(y0, t, bioreactor, strain_list, species_keys, plot_species, output_dir) # Make list of strains to be simulated strain_list = [P_strain, Q_strain] # Generate integration inputs and prepare objects species_keys, y0 = generate_integrate_inputs(bioreactor, strain_list) # Run plasmid loss experiment run_plasmid_loss(y0, t, bioreactor, strain_list, species_keys, plasmid_bearing_strain=P_strain, wt_strain=Q_strain, heterologous_species_name='h', PCN=PCN, n_passages=n_passages, output_dir=output_dir)
def __init__(self, h5n, result): self._h5n = h5n self._result = result self.element_force = ElementForce(self._h5n, self) self.energy = Energy(self._h5n, self) self.strain = Strain(self._h5n, self) self.stress = Stress(self._h5n, self)
def test_is_legal(): strain = Strain( ( (), (), ) ) assert_equal(strain.is_legal(), True) strain = Strain( ( (), (), (), ) ) assert_equal(strain.is_legal(), False)
def test_available_spots(): strain = Strain( ( (), ( (), ), ) ) assert_equal( sorted(strain.available_spots()), [ [0, 0], [1, 0], [1, 0, 0], [1, 1], ] )
def test_legal_moves(): strain = Strain( ( (), ( (), ), ) ) assert_equal( sorted(move for move, s in strain.legal_moves()), [ ([0], [1]), ([0], [0, 0]), ([0], [0, 1]), ([0], [0, 0, 0]), ([1], [0]), ([1], [0, 0]), ([1, 0], [0, 0]), ] )
def make_units_from_data_dictionaries(self, filetype, dicts): """Set linked units into state. Takes a list of dictionaries and converts the metadata stored within them into three data units (four if attribution information is included). Each dictionary is created by parsing primary input files and maps field names to metadata, with field names being derived from the spec in the CONFIG dictionary. Todo: * Ensure that this works for JSON input files """ logger.info("Making units from filetype {} & data".format(filetype)) for data_dict in dicts: # Initialize Strain, Sample, and Sequence objects. # Parent/child links are initialized by passing Strain/Sample # ojbects to Sample/Sequence initializers. strain_obj = Strain(self.CONFIG, data_dict) sample_obj = Sample(self.CONFIG, data_dict, strain_obj) sequence_obj = Sequence(self.CONFIG, data_dict, sample_obj) # Add new Strain, Sample, Sequence objects to state self.strains.append(strain_obj) self.samples.append(sample_obj) self.sequences.append(sequence_obj) # Handle Attributions if they exist, or set attribution to None if "authors" not in data_dict.keys(): data_dict["authors"] = None attribution_obj = Attribution(self.CONFIG, data_dict) self.attributions.append(attribution_obj) # Manually link sequences with their attribution attribution_obj.parent = sequence_obj sequence_obj.children.append(attribution_obj) # Validate that parent/child links are of the correct type self.validate_unit_links()
def test_splice(): strain = Strain( ( ( (), ), )) strain.splice([0, 0], [1]) assert_equal( strain.as_tuple(), ( (), (), ) ) strain = Strain( ( (), (), ) ) strain.splice([0], [0, 0]) assert_equal( strain.as_tuple(), ( ( (), ), ) ) strain = Strain( ( (), ( (), (), ), ) ) strain.splice([1], [0, 0]) assert_equal( strain.as_tuple(), ( ( ( (), (), ), ), ) ) strain = Strain( ( ( (), ), (), ) ) strain.splice([0], [1]) assert_equal( strain.as_tuple(), ( (), ( (), ), ) )
def growth_optimize_func(free_params, bioreactor_config, strain_config, target_6hr_ratio=500, target_final_6hr_ratio=1): """ Runs optimises growth parameters Uses target ratios (hard coded) @param free_params vector of params being fit, these should be unpacked @param target_6hr_ratio target cell density ratio for 6hr density / initial density @param target_final_6hr_ratio target cell density ratio for 24hr density / 6hr density """ # Unpack parameters B_s = free_params[0] * float(10**10) n_s = free_params[1] # Initialise bioreactor object bioreactor = Bioreactor(bioreactor_config) # Initialise strain object Q_strain = Strain(bioreactor, strain_config) # Make list of strains strain_list = [Q_strain] species_keys, y0 = utils.generate_integrate_inputs(bioreactor, strain_list) # Set bioreactor initial S B_s_idx = species_keys.index('B_s') y0[B_s_idx] = float(B_s) # Set strain nutrient efficiency Q_strain.params['n_s'] = float(n_s) # Make time vector (minutes) t = np.arange(0, 1440, 0.01) # Simulate growth sol = odeint(growth_curve_diff_eqs, y0, t, args=(bioreactor, strain_list, species_keys), mxstep=10**4) species_str = 'Q_N' Q_N_idx = species_keys.index(species_str) # Get index of six hour time point six_hr_idx = np.argwhere(t == 390)[0][0] # Get cell counts for timepoints of interest cell_count_0_hrs = sol[:, Q_N_idx][0] cell_count_6_hrs = sol[:, Q_N_idx][six_hr_idx] cell_count_24_hrs = sol[:, Q_N_idx][-1] # Get fold changes initial_6hr_ratio = cell_count_6_hrs / cell_count_0_hrs final_six_hr_ratio = cell_count_6_hrs / cell_count_24_hrs objective_1_distance = (initial_6hr_ratio - target_6hr_ratio)**2 objective_2_distance = (final_six_hr_ratio - target_final_6hr_ratio)**2 sum_distance = objective_1_distance + objective_2_distance # print(cell_count_24_hrs) print("free_params: ", free_params) print("6hr / initial density distance: ", objective_1_distance) print("6hr / 24hr density distance: ", objective_2_distance) print("sum distance: ", sum_distance) print("") return sum_distance