def test_transport(sim_time=10): # Kremling 2007 runs sim for 7.5 hours # media for glucose/lactose diauxic growth GLC_LCT_shift = { 'internal': { 'mass': 0.032, 'UHPT': 1e-5, 'PTSG': 0.001, 'G6P': 0.1, 'PEP': 0.05, 'PYR': 0.1, 'XP': 0.01, }, 'external': { 'GLC': 0.22, 'G6P': 0.0, 'LCTS': 1.165, } } # make the timeline timeline = [ # (0, GLC_LCT_shift), (sim_time, {}), ] # get process, initial state, and saved state transport = Transport({}) settings = {'timeline': {'timeline': timeline}} data = simulate_process_in_experiment(transport, settings) return data
def test_toy_metabolism(): regulation_logic = { 'R4': 'if (external, O2) > 0.1 and not (external, F) < 0.1' } toy_config = get_toy_configuration() transport = toy_transport() toy_config['constrained_reaction_ids'] = list(transport.keys()) toy_config['regulation'] = regulation_logic toy_metabolism = Metabolism(toy_config) # TODO -- add molecular weights! # simulate toy model timeline = [(5, { ('external', 'A'): 1 }), (10, { ('external', 'F'): 0 }), (15, {})] settings = { 'environment': { 'volume': 1e-8 * units.L, }, 'timestep': 1.0, 'timeline': { 'timeline': timeline } } return simulate_process_in_experiment(toy_metabolism, settings)
def test_growth_rate(): growth_rate = GrowthRate({}) initial_state = growth_rate.initial_state({}) settings = {'total_time': 1350, 'initial_state': initial_state} output = simulate_process_in_experiment(growth_rate, settings) return output
def run_antibiotic_transport(): process = AntibioticTransport() settings = { 'total_time': 4000, 'environment': { 'volume': 1e-15 * units.L, }, } return simulate_process_in_experiment(process, settings)
def test_receptor(timeline=get_pulse_timeline(), timestep=1): ligand = 'MeAsp' # initialize process initial_ligand = timeline[0][1][('external', ligand)] end_time = timeline[-1][0] process_config = {'initial_ligand': initial_ligand} receptor = ReceptorCluster(process_config) # run experiment experiment_settings = {'timeline': {'timeline': timeline}} return simulate_process_in_experiment(receptor, experiment_settings)
def run_template_process(out_dir='out'): # initialize the process by passing initial_parameters initial_parameters = {} template_process = Template(initial_parameters) # run the simulation sim_settings = {'total_time': 10} output = simulate_process_in_experiment(template_process, sim_settings) # plot the simulation output plot_settings = {} plot_simulation_output(output, plot_settings, out_dir)
def test_convenience_kinetics(end_time=2520): config = get_glc_lct_config() kinetic_process = ConvenienceKinetics(config) settings = { 'environment': { 'volume': 1e-14 * units.L, }, 'timestep': 1, 'total_time': end_time} return simulate_process_in_experiment(kinetic_process, settings)
def test_expression(end_time=10): toy_expression_rates = { 'protein1': 1e-2, 'protein2': 1e-1, 'protein3': 1e0 } expression_config = {'expression_rates': toy_expression_rates} # load process expression = MinimalExpression(expression_config) settings = {'total_time': end_time} return simulate_process_in_experiment(expression, settings)
def run_antibiotic_transport(): process = AntibioticTransport() settings = { 'total_time': 4000, 'environment': { 'volume': 1e-15 * units.L, 'ports': { 'external': ('external', ), 'exchange': ('exchange', ) } } } return simulate_process_in_experiment(process, settings)
def test_complexation(): complexation = Complexation() state = { 'monomers': {monomer: 1000 for monomer in complexation.monomer_ids}, 'complexes': {complex: 0 for complex in complexation.complex_ids} } settings = { 'total_time': 10, 'initial_state': state, } data = simulate_process_in_experiment(complexation, settings) print(data)
def test_mem_potential(): # configure process parameters = {} mp = MembranePotential(parameters) timeline = [(0, { ('external', 'Na'): 1 }), (50, { ('external', 'Na'): 10 }), (100, {})] settings = {'timeline': {'timeline': timeline}} timeseries = simulate_process_in_experiment(mp, settings) PMF_timeseries = timeseries['membrane']['PMF'] assert PMF_timeseries[-1] > PMF_timeseries[2] return timeseries
def test_mem_potential(): initial_parameters = { 'initial_state': DEFAULT_STATE, 'parameters': DEFAULT_PARAMETERS, 'permeability': PERMEABILITY_MAP, 'charge': CHARGE_MAP, } # configure process mp = MembranePotential(initial_parameters) timeline = [(0, { ('external', 'Na'): 1 }), (100, { ('external', 'Na'): 2 }), (500, {})] settings = {'timeline': {'timeline': timeline}} return simulate_process_in_experiment(mp, settings)
def run_spatial_geometry_process(): '''Run a simulation of the process. Returns: The simulation output. ''' # initialize the process by passing in parameters parameters = {} spatial_geometry_process = SpatialGeometry(parameters) # declare the initial state, mirroring the ports structure initial_state = {} # run the simulation sim_settings = {'total_time': 10, 'initial_state': initial_state} output = simulate_process_in_experiment(spatial_geometry_process, sim_settings) return output
def run_inclusion_body(out_dir='out'): # initialize the process by passing initial_parameters initial_parameters = {'growth_rate': 1e-1} inclusion_body_process = InclusionBody(initial_parameters) # get initial state initial_state = inclusion_body_process.initial_state({ 'initial_mass': 1.0, 'molecules': { 'biomass': 1.0 } }) # run the simulation sim_settings = {'initial_state': initial_state, 'total_time': 100} output = simulate_process_in_experiment(inclusion_body_process, sim_settings) # plot the simulation output plot_settings = {} plot_simulation_output(output, plot_settings, out_dir)
def run_sim_save_network( config=get_toy_configuration(), out_dir='out/network'): metabolism = Metabolism(config) # initialize the process stoichiometry = metabolism.fba.stoichiometry reaction_ids = list(stoichiometry.keys()) external_mol_ids = metabolism.fba.external_molecules objective = metabolism.fba.objective settings = { # 'environment_volume': 1e-6, # L # TODO -- bring back environment? 'timestep': 1, 'total_time': 10 } timeseries = simulate_process_in_experiment(metabolism, settings) reactions = timeseries['reactions'] # save fluxes as node size reaction_fluxes = {} for rxn_id in reaction_ids: if rxn_id in reactions: flux = abs(np.mean(reactions[rxn_id][1:])) reaction_fluxes[rxn_id] = np.log(1000 * flux + 1.1) else: reaction_fluxes[rxn_id] = 1 # define node type node_types = {rxn_id: 'reaction' for rxn_id in reaction_ids} node_types.update({mol_id: 'external_mol' for mol_id in external_mol_ids}) node_types.update({rxn_id: 'objective' for rxn_id in objective.keys()}) info = {'node_types': node_types, 'reaction_fluxes': reaction_fluxes} nodes, edges = make_network(stoichiometry, info) save_network(nodes, edges, out_dir)
def test_expression(end_time=10): expression_config = get_toy_expression_config() # load process expression = MinimalExpression(expression_config) settings = {'total_time': end_time} return simulate_process_in_experiment(expression, settings)
if args.bigg: # configure BiGG metabolism config = get_iAF1260b_config() metabolism = Metabolism(config) # simulation settings sim_settings = { 'environment': { 'volume': 1e-5 * units.L, }, 'total_time': 2520, # 2520 sec (42 min) is the expected doubling time in minimal media } # run simulation timeseries = simulate_process_in_experiment(metabolism, sim_settings) save_timeseries(timeseries, out_dir) volume_ts = timeseries['global']['volume'] mass_ts = timeseries['global']['mass'] print('volume growth: {}'.format(volume_ts[-1] / volume_ts[0])) print('mass growth: {}'.format(mass_ts[-1] / mass_ts[0])) # plot settings plot_settings = { 'max_rows': 30, 'remove_zeros': True, 'skip_ports': ['exchange', 'reactions'] } # make plots from simulation output
def test_activity(parameters=default_params, timeline=default_timeline): motor = FlagellaActivity(parameters) settings = {'timeline': {'timeline': timeline}, 'return_raw_data': True} return simulate_process_in_experiment(motor, settings)
transporters_loc = all_reactions[reaction_id]['catalyzed by'] self.all_transport_reactions[reaction_id] = { 'stoichiometry': stoichiometry, 'is reversible': reversible, 'catalyzed by': transporters_loc} # Make map of external molecule_ids with a location tag (as used in reaction stoichiometry) to molecule_ids in the environment self.molecule_to_external_map = {} self.external_to_molecule_map = {} rows = load_tsv(EXTERNAL_MOLECULES_FILE) for row in rows: molecule_id = row['molecule id'] location = row['exchange molecule location'] self.molecule_to_external_map[molecule_id + location] = molecule_id self.external_to_molecule_map[molecule_id] = molecule_id + location if __name__ == '__main__': process = TransportLookup({}) settings = { 'environment': { 'volume': 5e-14, 'states': process.external_molecule_ids, 'environment_port': 'external', 'exchange_port': 'exchange'}, 'timestep': 1, 'total_time': 60} timeseries = simulate_process_in_experiment(process, settings)
def test_expression(config=get_lacy_config(), timeline=[(100, {})]): expression = ODE_expression(config) settings = {'timeline': {'timeline': timeline}} return simulate_process_in_experiment(expression, settings)
def test_diffusion_network(config=get_two_compartment_config(), end_time=10): diffusion = DiffusionNetwork(config) settings = {'timestep': 0.2, 'total_time': end_time} return simulate_process_in_experiment(diffusion, settings)
} def derivers(self): return { self.global_deriver_key: { 'deriver': 'globals_deriver', 'port_mapping': { 'global': 'global' }, 'config': { 'width': 1.0 } } } def next_update(self, timestep, states): mass = states['global']['mass'] new_mass = mass * np.exp(self.parameters['growth_rate'] * timestep) return {'global': {'mass': new_mass}} if __name__ == '__main__': out_dir = os.path.join(PROCESS_OUT_DIR, NAME) if not os.path.exists(out_dir): os.makedirs(out_dir) growth = Growth({}) settings = {'total_time': 10} timeseries = simulate_process_in_experiment(growth, settings) plot_simulation_output(timeseries, {}, out_dir)
def test_diffusion_network_process(out_dir=None): # initialize the process by passing initial_parameters n = int(1E6) molecule_ids = [str(np.round(i, 1)) for i in np.arange(0.1, 19.6, 0.1)] initial_parameters = { 'nodes': ['cytosol_front', 'nucleoid', 'cytosol_rear'], 'edges': { '1': { 'nodes': ['cytosol_front', 'nucleoid'], 'cross_sectional_area': np.pi * 0.3**2, 'mesh': True, }, '2': { 'nodes': ['nucleoid', 'cytosol_rear'], 'cross_sectional_area': np.pi * 0.3**2, 'mesh': True, }, '3': { 'nodes': ['cytosol_front', 'cytosol_rear'], 'cross_sectional_area': np.pi * 0.3**2, }, }, 'mw': { str(np.round(i, 1)): np.round(i, 1) for i in np.arange(0.1, 19.6, 0.1) }, 'mesh_size': 50, 'radii': { str(np.round(i, 1)): np.round(i, 1) for i in np.arange(0.1, 19.6, 0.1) }, } diffusion_network_process = DiffusionNetwork(initial_parameters) # run the simulation sim_settings = { 'total_time': 10, 'initial_state': { 'cytosol_front': { 'length': 0.5, 'volume': 0.25, 'molecules': {mol_id: n for mol_id in molecule_ids} }, 'nucleoid': { 'length': 1.0, 'volume': 0.5, 'molecules': {mol_id: 0 for mol_id in molecule_ids} }, 'cytosol_rear': { 'length': 0.5, 'volume': 0.25, 'molecules': {mol_id: 0 for mol_id in molecule_ids} }, }, } output = simulate_process_in_experiment(diffusion_network_process, sim_settings) rp = diffusion_network_process.rp diffusion_constants = diffusion_network_process.diffusion_constants if out_dir: # plot the simulation output plot_output(output, sim_settings['initial_state'], out_dir)
def test_motor_control(total_time=10): motor = MotorActivity({}) experiment_settings = {'total_time': total_time, 'timestep': 0.01} return simulate_process_in_experiment(motor, experiment_settings)
def run_metabolism(metabolism, settings=None): if not settings: settings = {'total_time': 10} return simulate_process_in_experiment(metabolism, settings)