[Avida-cvs] [Avida2-svn] r62 - trunk/source/python/AvidaGui2

baerb at myxo.css.msu.edu baerb at myxo.css.msu.edu
Fri Mar 18 12:38:44 PST 2005


Author: baerb
Date: 2005-03-18 15:38:44 -0500 (Fri, 18 Mar 2005)
New Revision: 62

Modified:
   trunk/source/python/AvidaGui2/pyFreezerCtrl.py
   trunk/source/python/AvidaGui2/pyPetriConfigureCtrl.py
   trunk/source/python/AvidaGui2/pyPetriConfigureView.py
   trunk/source/python/AvidaGui2/pyPetriConfigureView.ui
   trunk/source/python/AvidaGui2/pyTemporaryReloads.py
   trunk/source/python/AvidaGui2/pyWriteGenesis.py
   trunk/source/python/AvidaGui2/pyWriteToFreezer.py
Log:
Completed saving and loading populated petri dish.  Pretty crude, but it works.



Modified: trunk/source/python/AvidaGui2/pyFreezerCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyFreezerCtrl.py	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyFreezerCtrl.py	2005-03-18 20:38:44 UTC (rev 62)
@@ -16,7 +16,7 @@
     #   self.clicked_item)
     self.connect(self.m_list_view, 
       SIGNAL("clicked(QListViewItem*, const QPoint &, int )"),
-      self.clicked_item)
+      self.clicked_itemSlot)
 
   def construct(self, session_mdl):
     self.m_session_mdl = session_mdl
@@ -42,7 +42,7 @@
 
   # if freezer item is clicked read file/directory assocatied with item
 
-  def clicked_item(self, item):
+  def clicked_itemSlot(self, item):
    
     # check that the item is not at the top level 
 

Modified: trunk/source/python/AvidaGui2/pyPetriConfigureCtrl.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriConfigureCtrl.py	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyPetriConfigureCtrl.py	2005-03-18 20:38:44 UTC (rev 62)
@@ -1,9 +1,12 @@
 # -*- coding: utf-8 -*-
 
 from qt import *
+import os
+import math
 from pyPetriConfigureView import pyPetriConfigureView
 from pyWriteGenesis import pyWriteGenesis
 from pyFreezeDialogCtrl import pyFreezeDialogCtrl
+from pyWriteToFreezer import pyWriteToFreezer
 
 
 class pyPetriConfigureCtrl(pyPetriConfigureView):
@@ -14,6 +17,7 @@
   def construct(self, session_mdl):
     self.m_session_mdl = session_mdl
     self.m_session_petri_view = pyPetriConfigureView()
+    self.full_petri_dict = {}
     self.connect(self.MutationSlider, SIGNAL("valueChanged(int)"), 
       self.ChangeMutationTextSlot)
     self.connect(self.WorldSizeSlider, SIGNAL("valueChanged(int)"), 
@@ -44,7 +48,18 @@
     self.run_started = False    
 
   def ChangeMutationTextSlot(self):
-    slide_value_txt = str(float(self.MutationSlider.value())/10.0) + "%"
+    slide_value = float(self.MutationSlider.value())/10.0
+    slide_value = pow(10,slide_value)
+    if slide_value < 0.0002:
+      slide_value = 0
+    if slide_value > 1:
+      slide_value_txt = ("%1.1f" % (slide_value)) + "%"
+    elif slide_value > 0.1:
+      slide_value_txt = ("%1.2f" % (slide_value)) + "%"
+    elif slide_value > 0.001:
+      slide_value_txt = ("%1.3f" % (slide_value)) + "%"
+    else:
+      slide_value_txt = ("%1.4f" % (slide_value)) + "%"
     self.MutationPercentTextLabel.setText(slide_value_txt)
 
   def ChangeWorldSizeTextSlot(self):
@@ -74,12 +89,14 @@
     else:
       self.StopAtSpinBox.setEnabled(True)
   
-  def FillDishSlot(self, petri_info):
-    settings_info =  petri_info.dictionary["SETTINGS"]
+  def FillDishSlot(self, petri_dict):
+    self.full_petri_dict = petri_dict.dictionary
+    print "in FillDishSlot keys = " + str(self.full_petri_dict.keys())
+    settings_dict =  petri_dict.dictionary["SETTINGS"]
     self.AncestorComboBox.removeItem (0)
-    start_creature = settings_info["START_CREATURE"]
+    start_creature = settings_dict["START_CREATURE"]
     self.AncestorComboBox.insertItem(start_creature)
-    max_updates = int(settings_info["MAX_UPDATES"])
+    max_updates = int(settings_dict["MAX_UPDATES"])
     self.StopAtSpinBox.setValue(max_updates)
     if max_updates < 0:
        self.StopManuallyRadioButton.setChecked(True)
@@ -87,8 +104,8 @@
     else:
        self.StopManuallyRadioButton.setChecked(False)
        self.StopAtRadioButton.setChecked(True)
-    self.WorldSizeSlider.setValue(int(settings_info["WORLD-X"]))
-    seed = int(settings_info["RANDOM_SEED"])
+    self.WorldSizeSlider.setValue(int(settings_dict["WORLD-X"]))
+    seed = int(settings_dict["RANDOM_SEED"])
     self.RandomSpinBox.setValue(seed)
     if seed == 0:
        self.RadomGeneratedRadioButton.setChecked(True)
@@ -96,16 +113,16 @@
     else:
        self.RadomGeneratedRadioButton.setChecked(False)
        self.RandomFixedRadioButton.setChecked(True)
-    copy_mutation_percent = float(settings_info["COPY_MUT_PROB"]) * 100;
-    self.MutationSlider.setValue(int(copy_mutation_percent * 10))
-    if int(settings_info["BIRTH_METHOD"]) in [0, 1, 2, 3]:
+    copy_mutation_percent = float(settings_dict["COPY_MUT_PROB"]) * 100;
+    self.MutationSlider.setValue(int(math.log10(copy_mutation_percent) * 10))
+    if int(settings_dict["BIRTH_METHOD"]) in [0, 1, 2, 3]:
        self.LocalBirthRadioButton.setChecked(True)
        self.MassActionRadioButton.setChecked(False)
     else:
        self.LocalBirthRadioButton.setChecked(False)
        self.MassActionRadioButton.setChecked(True)
-    self.LifeSpanSpinBox.setValue(int(settings_info["AGE_LIMIT"]))
-    if int(settings_info["DEATH_METHOD"]) == 0:
+    self.LifeSpanSpinBox.setValue(int(settings_dict["AGE_LIMIT"]))
+    if int(settings_dict["DEATH_METHOD"]) == 0:
        self.DieNoButton.setChecked(True)
        self.DieYesButton.setChecked(False)
        self.DeathTextLabel2.setEnabled(False)
@@ -149,48 +166,50 @@
     self.DeathTextLabel3.setEnabled(False)
 
   def CreateFilesFromPetriSlot(self, out_dir = None):
-    tmp_dict = self.Form2Dictionary()
-    write_object = pyWriteGenesis(tmp_dict, "freezer/", "test/")
+    self.full_petri_dict["SETTINGS"] = self.Form2Dictionary()
+    print "in CreateFilesFromPetriSlot keys = " + str(self.full_petri_dict.keys())
+    write_object = pyWriteGenesis(self.full_petri_dict, "freezer/", "test/")
     self.m_session_mdl.m_session_mdtr.emit(
       PYSIGNAL("doInitializeAvidaPhaseIISig"), ("test/genesis.avida",))
       
   def Form2Dictionary(self):
-    tmp_dict = {}
-    settings_info = {}
+    settings_dict = {}
     
-    settings_info["START_CREATURE"] = str(self.AncestorComboBox.text(0))
+    settings_dict["START_CREATURE"] = str(self.AncestorComboBox.text(0))
     if (self.StopAtRadioButton.isChecked() == True):
-      settings_info["MAX_UPDATES"] = self.StopAtSpinBox.value()
+      settings_dict["MAX_UPDATES"] = self.StopAtSpinBox.value()
     else:
-      settings_info["MAX_UPDATES"] = -1
-    settings_info["WORLD-X"] = self.WorldSizeSlider.value()
-    settings_info["WORLD-Y"] = self.WorldSizeSlider.value()
+      settings_dict["MAX_UPDATES"] = -1
+    settings_dict["WORLD-X"] = self.WorldSizeSlider.value()
+    settings_dict["WORLD-Y"] = self.WorldSizeSlider.value()
     if self.RandomFixedRadioButton.isChecked() == True:
-      settings_info["RANDOM_SEED"] = self.RandomSpinBox.value()
+      settings_dict["RANDOM_SEED"] = self.RandomSpinBox.value()
     else:
-      settings_info["RANDOM_SEED"] = 0
-    settings_info["COPY_MUT_PROB"] = float(self.MutationSlider.value())/1000.0
+      settings_dict["RANDOM_SEED"] = 0
+    slide_value = float(self.MutationSlider.value())/10.0
+    slide_value = pow(10,slide_value)
+    if slide_value < 0.0002:
+      slide_value = 0.0
+    settings_dict["COPY_MUT_PROB"] = slide_value/100.0
     if self.LocalBirthRadioButton.isChecked() == True:
-      settings_info["BIRTH_METHOD"] = 0
+      settings_dict["BIRTH_METHOD"] = 0
     else:
-      settings_info["BIRTH_METHOD"] = 0
-    settings_info["AGE_LIMIT"] = self.LifeSpanSpinBox.value()
+      settings_dict["BIRTH_METHOD"] = 0
+    settings_dict["AGE_LIMIT"] = self.LifeSpanSpinBox.value()
     if self.DieNoButton.isChecked() == True:
-      settings_info["DEATH_METHOD"] = 0
+      settings_dict["DEATH_METHOD"] = 0
     else:
-      settings_info["DEATH_METHOD"] = 2
-    tmp_dict["SETTINGS"] = settings_info
-    return tmp_dict
+      settings_dict["DEATH_METHOD"] = 2
+    return settings_dict
     
   def FreezePetriSlot(self, freeze_dir = None, population_dict = None):
+    tmp_dict["SETTINGS"] = self.Form2Dictionary()
     m_pop_up_freezer_file_name = pyFreezeDialogCtrl()
     file_name = m_pop_up_freezer_file_name.showDialog("freezer/")
-    isEmpty = m_pop_up_freezer_file_name.isEmpty()
-    print str(m_pop_up_freezer_file_name.FileNameLineEdit.text())
-#    print "Name = " + str(m_pop_up_freezer_file_name.FileNameLineEdit.text())
-#    print "Empty? = " + str (m_pop_up_freezer_file_name.EmptyRadioButton.isChecked())
-#    print "Result = " + str(m_pop_up_freezer_file_name.result())
-    tmp_dict = self.Form2Dictionary()
-    tmp_dict["POPULATION"] = population_dict
-    print tmp_dict
+    if (m_pop_up_freezer_file_name.isEmpty() == False):
+      os.mkdir(file_name)
+      file_name = file_name + "/petri_dish"
+      tmp_dict["POPULATION"] = population_dict
+    is_empty_dish = m_pop_up_freezer_file_name.EmptyRadioButton.isChecked()
+    freezer_file = pyWriteToFreezer(tmp_dict, is_empty_dish, file_name)
     
\ No newline at end of file

Modified: trunk/source/python/AvidaGui2/pyPetriConfigureView.py
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriConfigureView.py	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyPetriConfigureView.py	2005-03-18 20:38:44 UTC (rev 62)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'pyPetriConfigureView.ui'
 #
-# Created: Mon Mar 14 14:51:31 2005
+# Created: Thu Mar 17 15:21:49 2005
 #      by: The PyQt User Interface Compiler (pyuic) 3.14
 #
 # WARNING! All changes made in this file will be lost!
@@ -41,8 +41,9 @@
         self.MutationSlider = QSlider(self,"MutationSlider")
         MutationSlider_font = QFont(self.MutationSlider.font())
         self.MutationSlider.setFont(MutationSlider_font)
-        self.MutationSlider.setMaxValue(1000)
-        self.MutationSlider.setValue(500)
+        self.MutationSlider.setMinValue(-40)
+        self.MutationSlider.setMaxValue(20)
+        self.MutationSlider.setValue(-20)
         self.MutationSlider.setOrientation(QSlider.Horizontal)
         layout75.addWidget(self.MutationSlider)
 
@@ -275,7 +276,7 @@
 
         self.languageChange()
 
-        self.resize(QSize(309,451).expandedTo(self.minimumSizeHint()))
+        self.resize(QSize(310,451).expandedTo(self.minimumSizeHint()))
         self.clearWState(Qt.WState_Polished)
 
         self.connect(self.RadomGeneratedRadioButton,SIGNAL("clicked()"),self.RandomFixedRadioButton.toggle)
@@ -287,7 +288,7 @@
         self.MutationRateHeadTextLabel.setText(self.__tr("Mutation Rate"))
         QToolTip.add(self.MutationRateHeadTextLabel,self.__tr("Set the rate of mutation from 0 to 1"))
         QToolTip.add(self.MutationSlider,self.__tr("Set Mutation Rate from 0 to 100 %"))
-        self.MutationPercentTextLabel.setText(self.__tr("100 %"))
+        self.MutationPercentTextLabel.setText(self.__tr("0.01 %"))
         self.WorldSizeHeadTextLable.setText(self.__tr("World Size"))
         self.WorldSizeTextLabel.setText(self.__tr("60 x 60 cells"))
         self.DeathLabel.setText(self.__tr("Do organisms die of old age?"))

Modified: trunk/source/python/AvidaGui2/pyPetriConfigureView.ui
===================================================================
--- trunk/source/python/AvidaGui2/pyPetriConfigureView.ui	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyPetriConfigureView.ui	2005-03-18 20:38:44 UTC (rev 62)
@@ -8,7 +8,7 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>309</width>
+            <width>310</width>
             <height>451</height>
         </rect>
     </property>
@@ -84,11 +84,14 @@
                                         <font>
                                         </font>
                                     </property>
+                                    <property name="minValue">
+                                        <number>-40</number>
+                                    </property>
                                     <property name="maxValue">
-                                        <number>1000</number>
+                                        <number>20</number>
                                     </property>
                                     <property name="value">
-                                        <number>500</number>
+                                        <number>-20</number>
                                     </property>
                                     <property name="orientation">
                                         <enum>Horizontal</enum>
@@ -106,7 +109,7 @@
                                         </font>
                                     </property>
                                     <property name="text">
-                                        <string>100 %</string>
+                                        <string>0.01 %</string>
                                     </property>
                                 </widget>
                             </hbox>

Modified: trunk/source/python/AvidaGui2/pyTemporaryReloads.py
===================================================================
--- trunk/source/python/AvidaGui2/pyTemporaryReloads.py	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyTemporaryReloads.py	2005-03-18 20:38:44 UTC (rev 62)
@@ -68,6 +68,7 @@
   "AvidaGui2.pyVivisectionView",
   "AvidaGui2.pyVivisectionCtrl",
   "AvidaGui2.pyWriteGenesis",
+  "AvidaGui2.pyWriteToFreezer",
   
   "AvidaGui2.pyOneAna_GraphView",
   "AvidaGui2.pyOneAna_GraphCtrl",

Modified: trunk/source/python/AvidaGui2/pyWriteGenesis.py
===================================================================
--- trunk/source/python/AvidaGui2/pyWriteGenesis.py	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyWriteGenesis.py	2005-03-18 20:38:44 UTC (rev 62)
@@ -12,6 +12,8 @@
     # incoming dictionary
 
     shutil.copyfile("events.default", out_dir + "events.cfg")
+    if in_dict.has_key("CELLS"):
+      self.createInjects(in_dict, out_dir + "events.cfg")
     shutil.copyfile("environment.default", out_dir + "environment.cfg")
     shutil.copyfile("inst_set.default", out_dir + "inst_set.default")
     shutil.copyfile(freeze_dir + settings_dict["START_CREATURE"],
@@ -47,4 +49,17 @@
           out_genesis_file.write(line)
       else:
          out_genesis_file.write(line)
-    out_genesis_file.close()
\ No newline at end of file
+    out_genesis_file.close()
+    
+  def createInjects(self, in_dict, out_file):
+    cells_dict = in_dict["CELLS"]
+    organisms_dict = in_dict["ORGANISMS"]
+    event_out_file = open(out_file, 'a')
+    for cell in cells_dict.keys():
+      part1 = "u 0 inject_sequence " +  organisms_dict[cells_dict[cell]] + " " 
+      part2 = cell + " " + str(int(cell)+1) + " -1 "
+      part3 = cells_dict[cell] + "\n"
+      event_out_file.write(part1 +  part2 + part3)
+    event_out_file.close()
+    
+    
\ No newline at end of file

Modified: trunk/source/python/AvidaGui2/pyWriteToFreezer.py
===================================================================
--- trunk/source/python/AvidaGui2/pyWriteToFreezer.py	2005-03-17 13:33:33 UTC (rev 61)
+++ trunk/source/python/AvidaGui2/pyWriteToFreezer.py	2005-03-18 20:38:44 UTC (rev 62)
@@ -5,3 +5,47 @@
 
 class pyWriteToFreezer:
 
+  def __init__(self, in_dict = None, empty_dish = True, out_file_name = None):
+  
+    if empty_dish == False:
+      self.simplifyPopulation(in_dict)
+    out_freezer_file = open(out_file_name, "w")
+    for section in in_dict.keys():
+    
+      # Always print out the petri dishes settings and if it is a full dish
+      # print out the cell and organism information
+      
+      if ((section == "SETTINGS") or (empty_dish == False)):
+        out_freezer_file.write("*" + section + "\n")
+        info_dict = in_dict[section]
+        for info_key in info_dict.keys():
+          out_freezer_file.write(str(info_key) + " " + str(info_dict[info_key]) + "\n")
+    out_freezer_file.close()
+    
+  def simplifyPopulation(self, in_dict = None):
+    if in_dict.has_key("POPULATION"):
+      pop_dict = in_dict["POPULATION"]
+      del in_dict["POPULATION"]
+      
+      # Create a unique number ID for each genome.  Make a dictionary with 
+      # that ID as a key and the genome string as the value.  Make a second
+      # (temporary) directory that has reverse key/values.  Create a third
+      # dictionary that has the cell location as the key and the genome ID
+      # as the value
+      
+      organism_dict = {}
+      in_dict["ORGANISMS"] = {}
+      in_dict["CELLS"] = {}
+      new_genome_num = 0
+      for cell in pop_dict.keys():
+        genome = pop_dict[cell]
+        if (organism_dict.has_key(genome) == False):
+          new_genome_num = new_genome_num + 1
+          curr_genome_num = new_genome_num
+          in_dict["ORGANISMS"][new_genome_num] = genome
+          organism_dict[genome] = new_genome_num
+        else:
+          curr_genome_num = organism_dict[genome]
+        in_dict["CELLS"][cell] = curr_genome_num
+      
+      
\ No newline at end of file




More information about the Avida-cvs mailing list