-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from CompuCell3D/textbook
Rewrote Steppable, Potts, Contact Plugin, & Cell Sorting
- Loading branch information
Showing
45 changed files
with
872 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,49 @@ | ||
SteppableBasePy class | ||
===================== | ||
What is a Steppable? (SteppableBasePy class) | ||
=================================================== | ||
|
||
In the example above you may wonder how it is possible that it is | ||
sufficient to type: | ||
``SteppableBasePy`` has built-in **functions that are called automatically** during the simulation. | ||
The most important functions are ``start`` and ``step``. | ||
|
||
.. code-block:: python | ||
for cell in self.cell_list: | ||
to iterate over a list of all cells in the simulation. Where does | ||
``self.cell_list`` come from and how it accesses/stores information about all | ||
cells? The full answer to this question is beyond the scope of this | ||
manual so we will give you only a hint what happens here. The | ||
``self.cell_list`` is a member of a ``SteppableBasePy`` class. All CC3D Python | ||
steppable inherit this class and consequently ``self.cell_list`` is a member | ||
of all steppables (please see a chapter on class inheritance from any | ||
Python manual if this looks unfamiliar). Under the hood the | ||
``self.cell_list`` is a handle, or a “pointer”, if you prefer this | ||
terminology, to the C++ object that stores all cells in the simulation. | ||
The content of cell inventory, and cell ordering of cells there is fully | ||
managed by C++ code. We use self.cellList to access C++ cell objects | ||
usually iterating over entire list of cells. The cell in the | ||
|
||
.. code-block:: python | ||
for cell in self.cell_list: | ||
.. note:: | ||
Functions | ||
**************************** | ||
|
||
old syntax ``self.cellList`` is still supported | ||
**def __init__(self, frequency=1):** This code runs as the simulation is set up, and, in most cases, you will not need to edit it. | ||
|
||
is a pointer to C++ cell object. You can easily see what members C++ | ||
cell object has by modifying the step function as follows: | ||
**def start(self):** This is called after cells are created but before the simulation starts, so use it to assign custom cell properties or create `plots <example_plots_histograms.html>`_. | ||
|
||
.. code-block:: python | ||
**def step(self, mcs):** Almost everything will happen here. For example, you might grow, divide, or kill your cells here. | ||
|
||
def step(self, mcs): | ||
for cell in self.cellList: | ||
print dir(cell) | ||
break | ||
**def on_stop(self):** This runs when you click the stop button. | ||
|
||
The result looks as follows: | ||
**def finish(self):** This function is called at the end of the simulation, but it is used very infrequently. | ||
Be careful: it will only run if the simulation reaches the maximum number of steps as specified by the XML attribute ``<Steps>``. | ||
|
||
|image5| | ||
********************************************** | ||
|
||
*Figure 6 Checking out properties of a cell C++ object* | ||
|
||
The dir built-in Python function prints out names of members of any | ||
Python object. Here it printed out members of ``CellG`` class which | ||
represents CC3D cells. We will go over these properties later. | ||
|
||
The simplicity of the above code snippets is mainly due to underlying | ||
implementation of ``SteppableBasePy`` class. You can find this class in | ||
``<CC3D\_installation\_dir>/pythonSetupScripts/PySteppables.py``. The | ||
definition of this class goes on for several hundreds lines of code | ||
(clearly a bit too much to present it here). If you are interested in | ||
checking out what members this class has use the dir Python function | ||
again: | ||
A very common line in a Python steppable will read: | ||
|
||
.. code-block:: python | ||
def step(self,mcs): | ||
print ('Members of SteppableBasePy class') | ||
print dir(self) | ||
for cell in self.cell_list: | ||
You should know from Python programing manual that ``self`` refers to the | ||
class object. Therefore by printing ``dir(self)`` we are actually printing | ||
Python list of all members of ``cellsortingSteppable`` class. Because | ||
``cellsortingSteppable`` class contains all the functions of ``SteppableBasePy`` | ||
class we can inspect this way base class ``SteppableBasePy``. The output of | ||
the above simulation should look as follows: | ||
``cell_list`` is a variable of the ``SteppableBasePy`` class, which | ||
means that every steppable you create will automatically store | ||
every cell it creates in that list. | ||
|
||
|image6| | ||
All steppables in CompuCell3D are extensions of SteppableBasePy, so they, | ||
too, can use ``cell_list``. | ||
|
||
*Figure 7 Printing all members of SteppableBasePy class* | ||
**If you're new to programming:** The word ``self`` refers to the class we're inside, which would the steppable. | ||
Please see chapters on classes and inheritance from any Python manual if this looks unfamiliar. | ||
Also, if you want a full list of the cell attributes, see `Appendix B <appendix_b.rst>`_. | ||
|
||
If you look carefully, you can see that cellList is a member of | ||
``SteppabeBasePy`` class. Alternatively you can study source code of | ||
``SteppablBasePy``. | ||
**If you're a programmer:** Under the hood, the ``self.cell_list`` is a handle, or a “pointer”, to the C++ object that stores all cells in the simulation. | ||
The content of cell inventory and cell ordering of cells there is fully | ||
managed by C++ code. | ||
You can easily see what member variables the C++ | ||
cell object has by calling ``dir(cell)`` with one of the cells from the ``self.cell_list`` or by checking out `Appendix B <appendix_b.rst>`_. | ||
|
||
One of the goals of this manual is to teach you how to effectively use | ||
features of ``SteppableBasePy`` class to create complex biological | ||
simulations. This class is very powerful and has many constructs which | ||
make coding simple. | ||
.. note:: | ||
|
||
.. |image5| image:: images/image6.jpeg | ||
:width: 5.98958in | ||
:height: 0.89583in | ||
.. |image6| image:: images/image7.jpeg | ||
:width: 6.00000in | ||
:height: 2.03125in | ||
Old syntax like ``self.cellList`` is still supported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
How to Output Energy Changes | ||
====================================================== | ||
|
||
**EnergyFunctionCalculator**: allows you to output statistical data from the simulation for further analysis. | ||
|
||
You can define this in XML like so: | ||
|
||
.. code-block:: xml | ||
<Potts> | ||
<Dimensions x="256" y="256" z="1"/> | ||
<Steps>100000</Steps> | ||
<Temperature>5</Temperature> | ||
<NeighborOrder>2</NeighborOrder> | ||
<EnergyFunctionCalculator Type="Statistics"> | ||
<OutputFileName Frequency="10">statData.txt</OutputFileName> | ||
<OutputCoreFileNameSpinFlips Frequency="1" GatherResults="" OutputAccepted="" OutputRejected="" OutputTotal=""/> | ||
</EnergyFunctionCalculator> | ||
</Potts> | ||
.. note:: | ||
|
||
CC3D has the option to run in parallel mode, but | ||
output from the energy calculator will only work when running in single-CPU mode. | ||
|
||
The ``OutputFileName`` tag is used to specify the name of the file to which | ||
CompuCell3D will write average changes in energies returned by each | ||
plugin along with the corresponding standard deviations. | ||
``Frequency`` controls how often to record this data. In the above example, we would write data every 10 MCS. | ||
|
||
Furthermore, the ``OutputCoreFileNameSpinFlips`` tag is used to tell | ||
CompuCell3D to output the energy change for every plugin's pixel-copy operations. | ||
|
||
Finally, ``GatherResults=””`` will ensure | ||
that there is only one file written for accepted (``OutputAccepted``), | ||
rejected (``OutputRejected``), and both accepted and rejected (``OutputTotal``) pixel copies. | ||
If you do not specify ``GatherResults``, CompuCell3D will output | ||
separate files for different MCS's, and depending on the Frequency, you | ||
may end up with many files in your directory. |
Oops, something went wrong.