コード例 #1
0
ファイル: dose.py プロジェクト: colossus-technologies/dose
def revive_simulation(rev_parameters, sim_functions):
    print('\n[' + rev_parameters["simulation_name"].upper() + ' REVIVAL SIMULATION]')
    Populations = {}
    if "sim_folder" in rev_parameters:
        print('Accessing simulation files directory...') 
        print('Excavating World entity: ' + rev_parameters['eco_file'] + '...')
        World = excavate_world(rev_parameters['sim_folder'] + \
                               rev_parameters['eco_file'])
        print('Updating parameters with World dimensions...')
        rev_parameters["world_z"] = len(World.ecosystem[0][0][0])
        rev_parameters["world_y"] = len(World.ecosystem[0][0])
        rev_parameters["world_x"] = len(World.ecosystem[0])
        for i in range(len(rev_parameters["pop_files"])):
            print('\nReviving population file: ' + \
                rev_parameters["pop_files"][i] + '...')
            pop_file = rev_parameters["sim_folder"] + \
                rev_parameters["pop_files"][i]
            Populations[rev_parameters["population_names"][i]] = \
                revive_population(pop_file)
        print('\nUpdating revival generation start in simulation parameters...')
        rev_parameters["rev_start"] = [Populations[pop_name].generation 
                                       for pop_name in Populations]
    elif "database_source" in rev_parameters:
        print('Constructing database directory...')
        dbpath = os.sep.join([os.getcwd(), 
                              'Simulations', 
                              rev_parameters["database_source"]])
        print('Connecting to database file: ' + \
            rev_parameters["database_source"] + '...')
        (con, cur) = connect_database(dbpath, None)
        if rev_parameters["simulation_time"] == 'default':
            print('Acquiring simulation starting time...')
            rev_parameters["simulation_time"] = db_list_simulations(cur)[0][0]
        print('Reconstructing old simulation parameters...')
        temp_parameters = db_reconstruct_simulation_parameters(cur, 
                                    rev_parameters["simulation_time"])
        print('Assimilating old simulation parameters with new simulation parameters...')
        for key in temp_parameters:
            if key not in rev_parameters:
                rev_parameters[key] = temp_parameters[key]
        print('Reconstructing World entity...')
        World = db_reconstruct_world(cur, rev_parameters["simulation_time"], 
                                     rev_parameters["rev_start"][0])
        print('\nUpdating population names parameter...')
        for pop_name in rev_parameters["population_names"]:
            print('Reconstructing population: ' + pop_name + '...')
            Populations[pop_name] = db_reconstruct_population(cur, 
                              rev_parameters["simulation_time"], pop_name, 
            rev_parameters["rev_start"][rev_parameters["population_names"].index(pop_name)])
        print('Terminating database connection...')
        con.close()
    print('Updating last generation revival and population size simulation parameters...')
    rev_parameters["rev_finish"] = [(Populations[pop_name].generation + \
                                     rev_parameters["extend_gen"]) 
                                    for pop_name in Populations]
    rev_parameters["rev_pop_size"] = [len(Populations[pop_name].agents) 
                                      for pop_name in Populations]
    print('\nStarting simulation core...')
    simulation_core(sim_functions, rev_parameters, Populations, World)
コード例 #2
0
ファイル: analytics.py プロジェクト: olehze/dose
 def __init__(self, db_source, population_name, starting_time = 'default'):
     print('\n[INITIALIZING ANALYSIS]')
     self.db_source = db_source
     self.population_name = population_name
     print('Assembling database file directory...')
     dbpath = os.getcwd().split(os.sep)
     dbpath[-1] = 'examples'
     dbpath = os.sep.join(dbpath)
     dbpath = os.sep.join([dbpath, 'Simulations', db_source])
     print('Connecting to database file: ' + db_source + '...')
     (self.con, self.cur) = database_calls.connect_database(dbpath, None)
     print('Acquiring simulation starting time...')
     if starting_time == 'default':
         self.starting_time = database_calls.db_list_simulations(self.cur)[0][0]
     else:
         self.starting_time = starting_time
コード例 #3
0
ファイル: analytics.py プロジェクト: shubhangi0802/dose
 def __init__(self, db_source, population_name, starting_time='default'):
     print('\n[INITIALIZING ANALYSIS]')
     self.db_source = db_source
     self.population_name = population_name
     print('Assembling database file directory...')
     dbpath = os.getcwd().split(os.sep)
     dbpath[-1] = 'examples'
     dbpath = os.sep.join(dbpath)
     dbpath = os.sep.join([dbpath, 'Simulations', db_source])
     print('Connecting to database file: ' + db_source + '...')
     (self.con, self.cur) = \
         database_calls.connect_database(dbpath, None)
     print('Acquiring simulation starting time...')
     if starting_time == 'default':
         self.starting_time = \
             database_calls.db_list_simulations(self.cur)[0][0]
     else:
         self.starting_time = starting_time
コード例 #4
0
ファイル: dose.py プロジェクト: clarencecastillo/dose
def revive_simulation(rev_parameters, sim_functions, eb = event_broker()):

    eb.log("[" + rev_parameters["simulation_name"].upper() + " REVIVAL SIMULATION]")

    populations = {}
    world = None
    eb.log("Accessing simulation files directory")
    if "sim_folder" in rev_parameters:

        eb.log('Excavating World entity: ' + rev_parameters['eco_file'])
        world = excavate_world(rev_parameters['sim_folder'] + rev_parameters['eco_file'])

        eb.log('Updating parameters with World dimensions')
        rev_parameters["world_z"] = len(world.ecosystem[0][0][0])
        rev_parameters["world_y"] = len(world.ecosystem[0][0])
        rev_parameters["world_x"] = len(world.ecosystem[0])

        for i in range(len(rev_parameters["pop_files"])):
            eb.log('Reviving population file: ' + rev_parameters["pop_files"][i])
            pop_file = rev_parameters["sim_folder"] + rev_parameters["pop_files"][i]
            populations[rev_parameters["population_names"][i]] = revive_population(pop_file)

        eb.log('Updating revival generation start in simulation parameters')
        rev_parameters["rev_start"] = [populations[pop_name].generation for pop_name in populations]

    elif "database_source" in rev_parameters:

        eb.log('Constructing database directory')
        dbpath = os.sep.join([os.getcwd(), 'Simulations', rev_parameters["database_source"]])

        eb.log('Connecting to database file: ' + rev_parameters["database_source"])
        (con, cur) = connect_database(dbpath, None)

        if rev_parameters["simulation_time"] == 'default':
            eb.log('Acquiring simulation starting time')
            rev_parameters["simulation_time"] = db_list_simulations(cur)[0][0]

        eb.log('Reconstructing old simulation parameters')
        temp_parameters = db_reconstruct_simulation_parameters(cur, rev_parameters["simulation_time"])

        eb.log('Assimilating old simulation parameters with new simulation parameters')
        for key in temp_parameters:
            if key not in rev_parameters:
                rev_parameters[key] = temp_parameters[key]

        eb.log('Reconstructing World entity')
        world = db_reconstruct_world(cur, rev_parameters["simulation_time"], rev_parameters["rev_start"][0])

        eb.log('Updating population names parameter')
        for pop_name in rev_parameters["population_names"]:
            eb.log('Reconstructing population: ' + pop_name)
            populations[pop_name] = db_reconstruct_population(cur, rev_parameters["simulation_time"], pop_name,
                                                              rev_parameters["rev_start"][rev_parameters
                                                              ["population_names"].index(pop_name)])
        eb.log('Terminating database connection')
        con.close()

    eb.log('Updating last generation revival and population size simulation parameters')
    rev_parameters["rev_finish"] = [(populations[pop_name].generation + rev_parameters["extend_gen"])
                                    for pop_name in populations]
    rev_parameters["rev_pop_size"] = [len(populations[pop_name].agents) for pop_name in populations]

    eb.log('Starting simulation core')
    simulation_core(sim_functions, rev_parameters, populations, world)
コード例 #5
0
import analytics
import database_calls

database_filename = "case_study_00.db"
outputfile = 'sim00_within_cell_analysis.csv'
print('Opening outputfile: ' + outputfile + '...')
outputfile = open(outputfile, 'w')
print('Assembling database file directory...')
dbpath = os.getcwd().split(os.sep)
dbpath[-1] = 'examples'
dbpath = os.sep.join(dbpath)
dbpath = os.sep.join([dbpath, 'Simulations', database_filename])
print('Connecting to database file: ' + database_filename + '...')
(con, cur) = database_calls.connect_database(dbpath, None)
print('Acquiring simulation starting time...')
starting_time = database_calls.db_list_simulations(cur)[0][0]

print('Constructing locations list...')
locations = []
for x in range(5):
    for y in range(5):
        locations.append((x, y, 0))


def get_chromosomes_by_location(starting_time, pop_name, generation):
    organisms = database_calls.db_reconstruct_organisms(
        cur, starting_time, pop_name, generation)
    organism_chromosomes = {}
    for location in locations:
        organism_chromosomes[location] = []
        for organism in organisms:
コード例 #6
0
import analytics
import database_calls

database_filename = "case_study_00.db"
outputfile = 'sim00_within_cell_analysis.csv'
print('Opening outputfile: ' + outputfile + '...')
outputfile = open(outputfile, 'w')
print('Assembling database file directory...')
dbpath = os.getcwd().split(os.sep)
dbpath[-1] = 'examples'
dbpath = os.sep.join(dbpath)
dbpath = os.sep.join([dbpath, 'Simulations', database_filename])
print('Connecting to database file: ' + database_filename + '...')
(con, cur) = database_calls.connect_database(dbpath, None)
print('Acquiring simulation starting time...')
starting_time = database_calls.db_list_simulations(cur)[0][0]

print('Constructing locations list...')
locations = []
for x in range(5):
    for y in range(5):
            locations.append((x,y,0));

def get_chromosomes_by_location(starting_time, pop_name, generation):
    organisms = database_calls.db_reconstruct_organisms(cur, starting_time, pop_name, generation)
    organism_chromosomes = {}
    for location in locations:
        organism_chromosomes[location] = []
        for organism in organisms:
            if organism.status['location'] == location:
                organism_chromosomes[location].append(organism.genome[0].sequence)