|
2 | 2 | Smoldyn Code Documentation |
3 | 3 | ========================== |
4 | 4 | ------------ |
5 | | -Version 2.66 |
| 5 | +Version 2.67 |
6 | 6 | ------------ |
7 | 7 |
|
8 | 8 | :Author: Steve Andrews |
9 | | -:Date: ©June, 2021 |
| 9 | +:Date: ©November, 2021 |
10 | 10 |
|
11 | 11 | Programmer’s introduction |
12 | 12 | ========================= |
@@ -11106,6 +11106,18 @@ Individual command functions |
11106 | 11106 | purged from this list, partly because those molecules might have |
11107 | 11107 | gone away due to reactions. |
11108 | 11108 |
|
| 11109 | + The ``scanportion`` region scans over all molecules that fit the |
| 11110 | + :math:`species_1` category. Each of these molecules is returned, one |
| 11111 | + at a time, in ``mptr``. This ``mptr`` is added to ``moleclist``. The |
| 11112 | + function then scans over all possible :math:`species_2` molecules |
| 11113 | + that are within ``rmax`` distance of this molecule and checks to see |
| 11114 | + if they interact. The ``duplicate`` test investigates whether |
| 11115 | + ``mptr2`` is an instance of :math:`species_1` because if it is, then |
| 11116 | + it’s already in the ``moleclist``, and if it’s not then it needs to |
| 11117 | + be put in that list, which is done. If it’s put in the list, then |
| 11118 | + that might shift the list by one, in which case ``j`` becomes |
| 11119 | + incorrect; to address this, ``j`` is recomputed. |
| 11120 | + |
11109 | 11121 | *Internal functions* |
11110 | 11122 | ``void cmdv1free(cmdptr cmd);`` |
11111 | 11123 | | |
@@ -11170,6 +11182,94 @@ the shell. This source code file is not included in Libsmoldyn. |
11170 | 11182 | ``smolsimulate`` or ``smolsimulategl`` to run the simulation. At |
11171 | 11183 | the end, it returns to the shell. |
11172 | 11184 |
|
| 11185 | +Libsmoldyn (functions in libsmoldyn.cpp) |
| 11186 | +---------------------------------------- |
| 11187 | + |
| 11188 | +Libsmoldyn is a C/C++ API for the Smoldyn code. It is designed to be |
| 11189 | +redundant with the configuration file input, but accessible from code. |
| 11190 | +This description is far from complete but needs to be finished at some |
| 11191 | +point. See also documentation for it in the SmoldynManual. |
| 11192 | + |
| 11193 | +Error handling |
| 11194 | +~~~~~~~~~~~~~~ |
| 11195 | + |
| 11196 | +Essentially every user-accessible function returns an error code. Also, |
| 11197 | +functions define their function name in |
| 11198 | +``const char* funcname="``\ :math:`function`\ ``";``. Errors are checked |
| 11199 | +with either the ``LCHECK`` or ``LCHECKNT`` macros. These are supposed to |
| 11200 | +differ with ``LCHECK`` dealing with the error itself and throwing an |
| 11201 | +exception if necessary, and the ``LCHECKNT`` (no throw) macro not |
| 11202 | +dealing with the error but just copying the message over into global |
| 11203 | +variables. However, in practice, throwing doesn’t work anyhow, so the |
| 11204 | +only real difference is that the regular version displays an error |
| 11205 | +message to standard error, whereas the ``NT`` version doesn’t. Anyhow, |
| 11206 | +if an error is detected, these macros send the function name, the error |
| 11207 | +code, a string error message, and any simulation flags to the libsmoldyn |
| 11208 | +functions ``smolSetError`` or ``smolSetErrorNT``. |
| 11209 | + |
| 11210 | +At ``smolSetError`` and ``smolSetErrorNT``, which are essentially |
| 11211 | +identical, several function inputs are copied over to global variables: |
| 11212 | +the function name to ``Liberrorfunction``, the error code to |
| 11213 | +``Liberrorcode``, and the error message to ``Liberrorstring``. These |
| 11214 | +items are also displayed to standard error if appropriate. |
| 11215 | + |
| 11216 | +The global error variables are pretty much only used in one place, which |
| 11217 | +is the ``smolGetError`` function, which copies their values over to new |
| 11218 | +variables and returns those to the calling code. In addition, each |
| 11219 | +function in the library returns ``Liberrorcode``, which it just set if |
| 11220 | +an error occurred. |
| 11221 | + |
| 11222 | +A few more error handling steps arise if ``smolPrepareSimFromFile`` or |
| 11223 | +``smolLoadSimFromFile`` are used. |
| 11224 | + |
| 11225 | +In ``smolLoadSimFromFile``, this calls the smolsim.c function |
| 11226 | +``loadsim``. Here, errors are written by the macro ``CHECKS``, which |
| 11227 | +copies the error message to the global variable ``ErrorString``. Errors |
| 11228 | +are then handled by ``simParseError``, which concatenates the error |
| 11229 | +message from ``Parse_ReadFailure`` (the file name and file line) with |
| 11230 | +the error message from ``ErrorString``. ``simParseError`` sends the |
| 11231 | +result off to ``simLog``, which writes the error to a logfile if one has |
| 11232 | +been created or to standard output otherwise. |
| 11233 | + |
| 11234 | +Here is a typical example of error handling. Starting with stand-alone |
| 11235 | +Smoldyn first, the program starts in ``main`` in smoldyn.cpp, which |
| 11236 | +calls ``simInitAndLoad`` in smolsim.c, which calls ``loadsim``, which |
| 11237 | +calls ``simreadstring``. In the ``simreadstring`` function, the input |
| 11238 | +parser encounters an error. It writes an error message to the global |
| 11239 | +variable ``ErrorString``, goes to its failure label, and then on to |
| 11240 | +``simParseError``. Here, ``Parse_ReadFailure`` is called and sent an |
| 11241 | +empty string, and that function returns the string with text that reads |
| 11242 | +“Error reading file in line *number*. \\n line: *text of line* \\n file: |
| 11243 | +*filename*”; if the input line included substituted text, it also gives |
| 11244 | +the substituted version of the line in the string as well. |
| 11245 | +``Parse_ReadFailure`` also closes files and stops the input process. |
| 11246 | +Back in ``simParseError``, the input file information is concatanated |
| 11247 | +with the error message to create the complete error string. This is done |
| 11248 | +twice; first to create an error string in the global variable |
| 11249 | +``ErrorLineAndString`` and also as the input to ``simLog``. The |
| 11250 | +``simLog`` function prints the error message to the logging file if one |
| 11251 | +was declared or to standard output if not (unless the ‘s’ runtime flags |
| 11252 | +was selected, in which case the error output is supressed). Next, |
| 11253 | +``simParseError`` returns to ``simreadstring``, which returns an error |
| 11254 | +code to ``loadsim``, which returns an error code to ``simInitAndLoad``, |
| 11255 | +which returns an error code to ``main``. Here, the code sees the error |
| 11256 | +message, skips the simulation, and quits with an exit code of 0. |
| 11257 | + |
| 11258 | +For Libsmoldyn, the flow is similar, but here an entry point is |
| 11259 | +``smolPrepareSimFromFile``. This calls ``simInitAndLoad``. As before, an |
| 11260 | +error is encountered, it is displayed to the standard output if the ‘s’ |
| 11261 | +flag isn’t selected (it often should be selected for Libsmoldyn use) and |
| 11262 | +also written to ``ErrorLineAndString``. Then, control returns back to |
| 11263 | +``smolPrepareSimFromFile``. This sees the error, so it follows the |
| 11264 | +``LCHECK`` macro to head off to ``smolSetError``, with the |
| 11265 | +``ErrorLineAndString`` contents as the error message. This function |
| 11266 | +prints the error message out a second time, which is a little inelegant, |
| 11267 | +and also copies the message into the library global variable |
| 11268 | +``Liberrorstring``. At this point, control returns to the calling |
| 11269 | +program. If desired, that program can then call ``smolGetError`` to get |
| 11270 | +the error string again, now in a string variable rather than displayed |
| 11271 | +to the output. |
| 11272 | + |
11173 | 11273 | Code design |
11174 | 11274 | =========== |
11175 | 11275 |
|
@@ -14490,6 +14590,30 @@ Modifications for version 2.27 (released 7/26/12) |
14490 | 14590 |
|
14491 | 14591 | - Minor additions to Python API: Simulation.counts and getError. |
14492 | 14592 |
|
| 14593 | + .. rubric:: Modifications for version 2.66 (not released yet) |
| 14594 | + :name: modifications-for-version-2.66-not-released-yet |
| 14595 | + :class: unnumbered |
| 14596 | + |
| 14597 | +- Added “-s” command line flag for silent operation. |
| 14598 | + |
| 14599 | +- Improved error reporting for Libsmoldyn ``smolPrepareSimFromFile`` |
| 14600 | + and ``smolLoadSimFromFile`` functions. |
| 14601 | + |
| 14602 | +- Added a test for Perl availability in bngrunBNGL, in smolbng.c. |
| 14603 | + |
| 14604 | +- Added smolGetSpecies function to libsmoldyn. I haven’t tested it yet. |
| 14605 | + |
| 14606 | + .. rubric:: Modifications for version 2.67 (released 11/2/21) |
| 14607 | + :name: modifications-for-version-2.67-released-11221 |
| 14608 | + :class: unnumbered |
| 14609 | + |
| 14610 | +- Dilawar fixed a typo in the filament code. |
| 14611 | + |
| 14612 | +- Fixed the ``longrangeforce`` command, where an index value could be |
| 14613 | + off by one. |
| 14614 | + |
| 14615 | +- Jonathan Karr and Dilawar updated the Biosimulators links. |
| 14616 | + |
14493 | 14617 | The wish/ to do list |
14494 | 14618 | ==================== |
14495 | 14619 |
|
|
0 commit comments