keyword stringclasses 7 values | repo_name stringlengths 8 98 | file_path stringlengths 4 244 | file_extension stringclasses 29 values | file_size int64 0 84.1M | line_count int64 0 1.6M | content stringlengths 1 84.1M ⌀ | language stringclasses 14 values |
|---|---|---|---|---|---|---|---|
3D | mcellteam/mcell | appveyor_windows/mdllex.c | .c | 162,248 | 4,636 | #line 2 "/home/jczech/mcell/build/deps/mdllex.c"
#line 4 "/home/jczech/mcell/build/deps/mdllex.c"
#define YY_INT_ALIGNED long int
/* A lexical scanner generated by flex */
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
#define YY_FLEX_SUBMINOR_VERSION 0
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
/* end standard C headers. */
/* flex integer type definitions */
#ifndef FLEXINT_H
#define FLEXINT_H
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
* if you want the limit (max/min) macros for int types.
*/
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS 1
#endif
#include <inttypes.h>
typedef int8_t flex_int8_t;
typedef uint8_t flex_uint8_t;
typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
/* Limits of integral types. */
#ifndef INT8_MIN
#define INT8_MIN (-128)
#endif
#ifndef INT16_MIN
#define INT16_MIN (-32767-1)
#endif
#ifndef INT32_MIN
#define INT32_MIN (-2147483647-1)
#endif
#ifndef INT8_MAX
#define INT8_MAX (127)
#endif
#ifndef INT16_MAX
#define INT16_MAX (32767)
#endif
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX (255U)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX (65535U)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST
#else /* ! __cplusplus */
/* C99 requires __STDC__ to be defined as 1. */
#if defined (__STDC__)
#define YY_USE_CONST
#endif /* defined (__STDC__) */
#endif /* ! __cplusplus */
#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif
/* Returned upon end-of-file. */
#define YY_NULL 0
/* Promotes a possibly negative, possibly signed char to an unsigned
* integer for use as an array index. If the signed char is negative,
* we want to instead treat it as an 8-bit unsigned char, hence the
* double cast.
*/
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t;
#endif
/* For convenience, these vars (plus the bison vars far below)
are macros in the reentrant scanner. */
#define yyin yyg->yyin_r
#define yyout yyg->yyout_r
#define yyextra yyg->yyextra_r
#define yyleng yyg->yyleng_r
#define yytext yyg->yytext_r
#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
#define yy_flex_debug yyg->yy_flex_debug_r
/* Enter a start condition. This macro really ought to take a parameter,
* but we do it the disgusting crufty way forced on us by the ()-less
* definition of BEGIN.
*/
#define BEGIN yyg->yy_start = 1 + 2 *
/* Translate the current start state into a value that can be later handed
* to BEGIN to return to the state. The YYSTATE alias is for lex
* compatibility.
*/
#define YY_START ((yyg->yy_start - 1) / 2)
#define YYSTATE YY_START
/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE mdlrestart(yyin ,yyscanner )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
*/
#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
#define YY_TYPEDEF_YY_BUFFER_STATE
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2
#define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
do \
{ \
/* Undo effects of setting up yytext. */ \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
*yy_cp = yyg->yy_hold_char; \
YY_RESTORE_YY_MORE_OFFSET \
yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
{
FILE *yy_input_file;
char *yy_ch_buf; /* input buffer */
char *yy_buf_pos; /* current position in input buffer */
/* Size of input buffer in bytes, not including room for EOB
* characters.
*/
yy_size_t yy_buf_size;
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
* delete it.
*/
int yy_is_our_buffer;
/* Whether this is an "interactive" input source; if so, and
* if we're using stdio for input, then we want to use getc()
* instead of fread(), to make sure we stop fetching input after
* each newline.
*/
int yy_is_interactive;
/* Whether we're considered to be at the beginning of a line.
* If so, '^' rules will be active on the next match, otherwise
* not.
*/
int yy_at_bol;
int yy_bs_lineno; /**< The line count. */
int yy_bs_column; /**< The column count. */
/* Whether to try to fill the input buffer when we reach the
* end of it.
*/
int yy_fill_buffer;
int yy_buffer_status;
#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
/* When an EOF's been seen but there's still some text to process
* then we mark the buffer as YY_EOF_PENDING, to indicate that we
* shouldn't try reading from the input source any more. We might
* still have a bunch of tokens to match, though, because of
* possible backing-up.
*
* When we actually see the EOF, we change the status to "new"
* (via mdlrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
};
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
/* We provide macros for accessing buffer states in case in the
* future we want to put the buffer states in a more general
* "scanner state".
*
* Returns the top of the stack, or NULL.
*/
#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
: NULL)
/* Same as previous macro, but useful when we know that the buffer stack is not
* NULL or when we need an lvalue. For internal use only.
*/
#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
void mdlrestart (FILE *input_file ,yyscan_t yyscanner );
void mdl_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
YY_BUFFER_STATE mdl_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
void mdl_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
void mdl_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
void mdlpush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
void mdlpop_buffer_state (yyscan_t yyscanner );
static void mdlensure_buffer_stack (yyscan_t yyscanner );
static void mdl_load_buffer_state (yyscan_t yyscanner );
static void mdl_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
#define YY_FLUSH_BUFFER mdl_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
YY_BUFFER_STATE mdl_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE mdl_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
YY_BUFFER_STATE mdl_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
void *mdlalloc (yy_size_t ,yyscan_t yyscanner );
void *mdlrealloc (void *,yy_size_t ,yyscan_t yyscanner );
void mdlfree (void * ,yyscan_t yyscanner );
#define yy_new_buffer mdl_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
mdlensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
mdl_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
}
#define yy_set_bol(at_bol) \
{ \
if ( ! YY_CURRENT_BUFFER ){\
mdlensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
mdl_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
}
#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
#define mdlwrap(yyscanner) (/*CONSTCOND*/1)
#define YY_SKIP_YYWRAP
typedef unsigned char YY_CHAR;
typedef int yy_state_type;
#define yytext_ptr yytext_r
static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
static int yy_get_next_buffer (yyscan_t yyscanner );
#if defined(__GNUC__) && __GNUC__ >= 3
__attribute__((__noreturn__))
#endif
static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
yyleng = (size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 278
#define YY_END_OF_BUFFER 279
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
{
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int32_t yy_accept[2301] =
{ 0,
0, 0, 3, 3, 279, 276, 9, 277, 276, 276,
275, 276, 275, 272, 275, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 3, 5, 278, 9, 277, 11, 0, 274, 0,
271, 2, 0, 271, 272, 0, 0, 10, 0, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 162, 273,
273, 273, 171, 273, 273, 273, 273, 273, 185, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 236, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 3, 5, 5, 7, 4, 6, 274, 0,
0, 1, 271, 0, 0, 271, 0, 0, 12, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 34,
273, 273, 273, 273, 273, 273, 273, 273, 273, 50,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 89, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 131, 132, 273, 273,
273, 141, 273, 145, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 170, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 213, 273, 273,
273, 273, 273, 273, 273, 225, 273, 228, 273, 273,
273, 273, 237, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 262, 273, 273, 273,
273, 0, 271, 0, 0, 271, 0, 0, 273, 273,
15, 273, 273, 273, 27, 273, 29, 30, 273, 273,
273, 37, 273, 273, 273, 273, 273, 51, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 61, 58,
273, 273, 273, 273, 273, 273, 88, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
125, 273, 273, 128, 273, 273, 273, 273, 273, 273,
273, 146, 273, 273, 273, 273, 273, 273, 164, 273,
166, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 210, 273, 273, 273, 273, 273, 221,
273, 223, 273, 273, 273, 273, 273, 273, 273, 273,
273, 243, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 0, 271, 0, 0,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 26, 273, 273, 273, 273, 36, 273, 273,
273, 45, 273, 273, 273, 53, 54, 273, 273, 273,
71, 273, 273, 273, 273, 273, 273, 82, 273, 273,
273, 273, 92, 273, 273, 273, 97, 273, 98, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 130, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 206,
273, 273, 209, 211, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 261, 273,
273, 273, 273, 0, 268, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 33, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 91, 273, 273, 273, 8, 273, 273,
273, 273, 273, 105, 273, 273, 108, 273, 273, 273,
273, 273, 273, 273, 273, 273, 151, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
163, 273, 273, 169, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 207, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 270, 273, 273, 263, 273, 269, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
49, 273, 273, 273, 273, 72, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 109, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 242, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 259,
273, 264, 273, 265, 273, 273, 273, 273, 16, 273,
273, 20, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 80, 273,
273, 273, 93, 273, 273, 273, 273, 273, 273, 103,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 129, 273, 273, 273, 273, 273, 273,
273, 273, 150, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 260, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
24, 273, 273, 273, 32, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 152, 273, 157, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 187, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 208, 273, 273, 273, 273, 217, 273, 273, 273,
273, 273, 273, 273, 273, 232, 273, 234, 273, 273,
240, 273, 244, 273, 273, 273, 273, 273, 251, 273,
273, 273, 273, 273, 273, 273, 273, 273, 13, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 46, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 90, 273, 273, 273, 273,
100, 273, 273, 273, 273, 273, 273, 273, 273, 273,
114, 273, 273, 273, 118, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 181, 182, 183, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 199, 273,
273, 273, 273, 273, 273, 273, 273, 273, 216, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 249, 273, 273,
273, 273, 273, 257, 258, 273, 266, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 38,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 115, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 135,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 176, 177, 178, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 197, 273, 273, 273, 273,
273, 273, 273, 273, 215, 273, 273, 273, 273, 273,
273, 273, 229, 273, 273, 233, 273, 273, 273, 241,
273, 273, 273, 248, 273, 273, 273, 255, 273, 256,
267, 273, 273, 273, 18, 19, 273, 273, 273, 25,
28, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 79, 273, 273, 273, 273, 273, 273, 273,
273, 273, 101, 273, 273, 273, 273, 273, 111, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
172, 273, 273, 273, 180, 273, 186, 273, 273, 273,
273, 273, 193, 273, 273, 273, 273, 273, 273, 273,
204, 273, 273, 273, 273, 273, 273, 273, 273, 273,
227, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 17, 273, 22, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 52, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 83, 273, 86, 273, 273, 273, 96, 273,
273, 104, 273, 273, 273, 112, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 134, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 158,
273, 273, 273, 165, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 194, 273, 273, 273, 273,
273, 273, 273, 273, 273, 214, 273, 273, 273, 224,
226, 273, 273, 273, 235, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 21, 273, 31, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 87, 273, 273, 273, 273, 273, 273,
273, 113, 273, 273, 119, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 238, 239, 273, 273, 273, 273, 273, 273,
273, 273, 124, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 63, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 94, 273,
99, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 149, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 190, 273, 273, 273,
273, 273, 273, 273, 202, 273, 205, 212, 273, 219,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 57, 64, 65, 273, 273, 273,
273, 273, 74, 273, 273, 273, 273, 85, 273, 273,
273, 273, 110, 273, 273, 273, 121, 273, 273, 273,
273, 155, 273, 273, 273, 142, 273, 273, 273, 273,
148, 273, 273, 159, 273, 273, 167, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
201, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 23, 273, 273, 40,
273, 273, 273, 44, 273, 273, 273, 56, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 120, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
168, 273, 273, 273, 273, 273, 273, 191, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 231,
273, 273, 273, 250, 273, 273, 273, 273, 273, 273,
273, 41, 273, 273, 273, 55, 273, 273, 273, 273,
59, 273, 273, 273, 273, 273, 95, 273, 273, 273,
116, 273, 273, 273, 127, 126, 273, 273, 136, 137,
138, 273, 273, 273, 273, 273, 273, 154, 273, 273,
173, 273, 273, 273, 273, 188, 273, 273, 273, 273,
273, 273, 273, 273, 222, 273, 273, 273, 273, 273,
252, 273, 273, 273, 273, 273, 273, 43, 47, 273,
273, 273, 273, 70, 273, 273, 273, 78, 273, 273,
273, 273, 273, 273, 273, 273, 133, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 192, 273, 273, 273, 273, 203, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 68, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 179, 184,
273, 195, 273, 273, 200, 273, 220, 77, 273, 273,
273, 273, 273, 253, 14, 273, 273, 42, 273, 273,
273, 273, 62, 60, 273, 273, 76, 81, 273, 273,
273, 273, 273, 122, 273, 139, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 273, 273, 273, 273, 66, 69,
67, 273, 273, 84, 273, 273, 273, 273, 273, 273,
273, 273, 147, 273, 273, 273, 161, 273, 273, 273,
196, 273, 218, 273, 273, 273, 273, 273, 273, 273,
48, 273, 273, 102, 273, 273, 273, 273, 273, 273,
273, 273, 273, 273, 174, 273, 273, 273, 230, 273,
245, 273, 273, 35, 39, 273, 273, 273, 273, 117,
273, 273, 273, 273, 273, 273, 273, 273, 273, 198,
273, 273, 273, 73, 273, 273, 107, 273, 140, 143,
273, 153, 273, 273, 175, 273, 273, 273, 273, 273,
106, 273, 273, 156, 273, 273, 247, 246, 273, 273,
273, 144, 160, 273, 273, 273, 123, 189, 273, 273,
273, 273, 273, 273, 254, 273, 273, 273, 75, 0
} ;
static yyconst YY_CHAR yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 4, 5, 6, 7, 1, 1, 7, 7, 7,
7, 8, 9, 7, 9, 10, 11, 12, 13, 14,
15, 16, 16, 16, 16, 16, 16, 7, 7, 7,
17, 7, 1, 7, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
7, 44, 7, 7, 45, 1, 46, 46, 47, 46,
48, 49, 46, 46, 50, 46, 46, 51, 52, 53,
54, 55, 46, 56, 57, 58, 46, 46, 46, 46,
46, 46, 7, 7, 7, 7, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1
} ;
static yyconst YY_CHAR yy_meta[59] =
{ 0,
1, 1, 2, 1, 1, 1, 1, 3, 1, 4,
3, 4, 4, 4, 4, 4, 1, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 1, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4
} ;
static yyconst flex_uint32_t yy_base[2308] =
{ 0,
0, 0, 56, 57, 2439, 2440, 59, 2435, 2420, 56,
2440, 57, 66, 66, 79, 65, 57, 81, 73, 88,
104, 69, 71, 101, 0, 2414, 94, 109, 122, 124,
135, 146, 149, 159, 114, 170, 89, 2413, 43, 2378,
2378, 0, 97, 2424, 144, 2428, 2440, 145, 2440, 146,
185, 2440, 2427, 196, 207, 222, 2380, 2440, 2374, 0,
2391, 117, 2405, 2396, 206, 2406, 2403, 139, 2396, 199,
2399, 147, 210, 137, 227, 2397, 2388, 189, 2395, 184,
2382, 2379, 227, 2386, 164, 2382, 2378, 2380, 2382, 2372,
2377, 2390, 2389, 2382, 2374, 229, 2382, 2381, 2367, 2378,
191, 237, 2359, 222, 223, 137, 2369, 245, 245, 241,
2371, 2374, 0, 2370, 2358, 2372, 2358, 2357, 0, 243,
2359, 252, 257, 2366, 247, 2371, 2366, 256, 258, 272,
2352, 274, 263, 268, 2349, 2350, 2354, 2350, 276, 2353,
2359, 271, 2345, 2336, 271, 2343, 2342, 2340, 2324, 2318,
2323, 2316, 0, 270, 293, 2440, 2440, 2440, 299, 304,
2368, 2440, 309, 320, 325, 332, 2316, 2314, 2336, 2329,
2330, 2320, 2319, 2337, 2331, 2339, 2329, 2331, 2321, 2312,
2334, 2326, 2325, 2316, 2332, 2321, 2314, 2329, 2317, 0,
2316, 2320, 2308, 2318, 2321, 2324, 2305, 2317, 2321, 2317,
2316, 2314, 2305, 2308, 2301, 2306, 2302, 2293, 2294, 2306,
2291, 2304, 2307, 2292, 2293, 2291, 2292, 2284, 2289, 2285,
2296, 2291, 2283, 2285, 2275, 2275, 2289, 2292, 2274, 2275,
2283, 2269, 2283, 2286, 2266, 2284, 2288, 2274, 2268, 2266,
2262, 0, 2260, 285, 2273, 2272, 2258, 2274, 2250, 2268,
2263, 2259, 2268, 2264, 0, 2263, 2251, 2248, 2245, 2255,
2238, 2253, 291, 2252, 2256, 2256, 2238, 2245, 2251, 2240,
2246, 2252, 2238, 2239, 2246, 2233, 2225, 0, 2242, 2243,
2240, 2224, 2229, 2226, 2232, 0, 2234, 0, 2232, 2210,
2222, 2231, 0, 323, 2228, 2229, 2224, 2220, 2230, 2205,
2209, 2200, 2206, 2221, 2211, 2212, 0, 2186, 2189, 2185,
2187, 346, 351, 359, 364, 369, 2181, 2187, 2199, 2198,
0, 2197, 366, 2205, 0, 2210, 0, 2184, 2196, 2190,
2203, 0, 2206, 2202, 2195, 2189, 2199, 2198, 2197, 2181,
2197, 2184, 2184, 2183, 2171, 2186, 2173, 2180, 0, 0,
2189, 2186, 2174, 2171, 2175, 2166, 0, 2181, 2167, 2179,
297, 2171, 2164, 2180, 2160, 2154, 2159, 2172, 2168, 2170,
2146, 2155, 2151, 2151, 2169, 2151, 2156, 2166, 2138, 2160,
0, 2144, 2149, 0, 2142, 2166, 2147, 2131, 2140, 2142,
304, 0, 2150, 2152, 2126, 2148, 2132, 2142, 0, 2144,
0, 2144, 2145, 2133, 2125, 2122, 2135, 2128, 2135, 2121,
2139, 2121, 2137, 2109, 2116, 2134, 2129, 2132, 2110, 2111,
2110, 2125, 2123, 0, 2122, 2098, 2097, 2119, 2105, 0,
2118, 0, 2107, 2119, 2114, 2113, 2096, 2088, 2101, 2095,
2106, 0, 2099, 2106, 2096, 2100, 2103, 361, 2094, 2094,
2096, 2100, 2063, 2066, 2060, 2064, 395, 400, 2068, 2062,
2081, 2095, 2090, 2076, 2092, 321, 2083, 2071, 2075, 2074,
2079, 2086, 0, 2066, 331, 2072, 2066, 0, 2071, 2064,
2065, 2052, 2051, 2064, 2059, 0, 2048, 2062, 2069, 2068,
0, 2052, 2052, 2061, 2049, 2054, 2047, 0, 2065, 2061,
2045, 2049, 0, 2061, 2046, 2032, 0, 2039, 2030, 2029,
2047, 2035, 2026, 2035, 320, 2047, 2047, 2022, 2035, 2047,
2038, 2026, 2042, 2016, 2034, 2038, 2032, 0, 2019, 368,
2014, 2019, 2033, 2022, 2010, 2013, 2021, 2013, 2022, 2010,
2020, 2010, 2007, 2006, 2005, 2006, 2003, 2018, 2006, 2011,
2017, 2013, 2005, 366, 2007, 2001, 2011, 1994, 2007, 0,
2006, 1982, 0, 0, 2004, 384, 1980, 1998, 2005, 1998,
2001, 1983, 1990, 1994, 365, 1972, 388, 1994, 1989, 1978,
1993, 1981, 1970, 1972, 1991, 1986, 1962, 1975, 0, 1957,
1946, 373, 1945, 1949, 2440, 1964, 1963, 1969, 1966, 1960,
1974, 1975, 1957, 1971, 1963, 1954, 1960, 1954, 1943, 1952,
1960, 0, 1959, 1962, 1938, 1950, 1961, 1947, 1942, 1942,
1942, 1931, 1930, 1939, 1931, 1946, 1951, 1938, 1932, 1942,
1930, 1944, 1929, 0, 1934, 1925, 1926, 0, 400, 1926,
1942, 1924, 1925, 0, 1922, 1934, 1934, 1932, 1930, 1915,
1931, 1929, 1923, 1923, 1917, 1916, 1900, 1906, 1904, 1905,
1892, 21, 89, 89, 181, 171, 195, 216, 271, 288,
0, 349, 325, 0, 377, 357, 397, 398, 400, 396,
396, 403, 394, 386, 414, 402, 402, 411, 399, 415,
393, 0, 407, 399, 415, 424, 407, 424, 410, 401,
425, 403, 427, 425, 425, 420, 416, 433, 437, 438,
422, 421, 424, 419, 438, 418, 427, 436, 421, 447,
444, 0, 424, 412, 0, 422, 2440, 446, 452, 443,
441, 460, 449, 451, 445, 447, 462, 459, 464, 456,
453, 457, 453, 473, 461, 463, 468, 463, 478, 462,
0, 476, 463, 471, 484, 0, 471, 459, 470, 463,
489, 488, 466, 486, 491, 477, 477, 481, 491, 500,
488, 478, 503, 490, 505, 0, 479, 499, 500, 490,
483, 497, 508, 499, 510, 500, 503, 490, 518, 507,
505, 507, 505, 496, 506, 521, 508, 500, 524, 529,
516, 512, 531, 514, 520, 534, 510, 525, 528, 522,
538, 522, 535, 531, 525, 538, 520, 544, 544, 550,
551, 549, 534, 554, 552, 538, 531, 545, 548, 546,
544, 555, 560, 545, 553, 548, 551, 0, 565, 543,
544, 545, 562, 559, 555, 573, 563, 570, 571, 562,
541, 0, 550, 0, 562, 557, 564, 568, 0, 584,
575, 0, 590, 589, 587, 575, 586, 595, 578, 579,
585, 596, 586, 588, 589, 586, 604, 594, 591, 599,
594, 605, 590, 592, 599, 607, 587, 613, 589, 590,
614, 605, 593, 606, 610, 609, 606, 613, 600, 0,
609, 629, 630, 629, 624, 636, 629, 624, 626, 638,
630, 615, 629, 0, 627, 635, 647, 649, 635, 647,
634, 633, 636, 636, 641, 630, 639, 654, 647, 654,
644, 646, 653, 640, 657, 651, 662, 644, 664, 653,
656, 670, 649, 666, 657, 675, 669, 676, 680, 672,
677, 682, 676, 661, 675, 689, 679, 690, 676, 678,
685, 684, 683, 682, 698, 700, 702, 685, 689, 693,
701, 690, 707, 712, 700, 694, 697, 692, 0, 686,
685, 717, 725, 719, 716, 712, 708, 708, 708, 721,
0, 717, 712, 714, 0, 727, 730, 724, 717, 735,
719, 720, 736, 741, 730, 732, 744, 728, 742, 720,
744, 743, 736, 743, 735, 751, 743, 756, 753, 745,
744, 740, 749, 744, 745, 761, 748, 747, 767, 749,
758, 762, 771, 768, 769, 755, 761, 756, 759, 768,
775, 761, 763, 763, 779, 780, 768, 779, 788, 769,
773, 0, 789, 0, 779, 777, 792, 788, 770, 771,
785, 795, 797, 776, 804, 798, 0, 788, 791, 793,
810, 794, 799, 811, 815, 812, 796, 805, 819, 812,
817, 0, 803, 820, 806, 815, 804, 829, 806, 823,
818, 824, 827, 826, 821, 0, 822, 815, 843, 840,
0, 832, 0, 832, 843, 831, 831, 831, 0, 832,
837, 842, 835, 842, 837, 853, 824, 829, 0, 857,
834, 849, 844, 860, 857, 855, 865, 862, 861, 862,
851, 855, 869, 847, 871, 868, 869, 878, 877, 876,
877, 880, 879, 879, 858, 884, 873, 871, 876, 872,
887, 878, 889, 875, 889, 0, 879, 878, 898, 881,
0, 886, 897, 898, 902, 896, 901, 895, 888, 902,
0, 905, 897, 892, 0, 901, 898, 913, 909, 909,
915, 901, 904, 903, 922, 923, 909, 922, 914, 925,
910, 920, 924, 925, 927, 932, 923, 919, 922, 927,
936, 929, 932, 930, 928, 0, 0, 0, 928, 923,
944, 945, 947, 943, 935, 953, 934, 941, 0, 955,
941, 942, 948, 944, 952, 938, 947, 949, 0, 951,
966, 958, 972, 965, 963, 951, 957, 950, 960, 967,
961, 964, 963, 972, 984, 971, 967, 960, 988, 985,
966, 976, 973, 0, 0, 963, 0, 967, 983, 990,
979, 995, 985, 996, 1001, 984, 989, 991, 994, 0,
1004, 999, 995, 990, 996, 993, 1008, 987, 1013, 998,
1018, 1019, 1005, 1007, 1010, 1015, 1011, 1006, 1015, 1014,
1016, 1027, 1022, 1027, 1005, 1016, 1026, 1023, 1025, 1020,
1030, 1025, 1028, 1037, 1040, 1035, 0, 1017, 1030, 1038,
1027, 1044, 1035, 1030, 1034, 1038, 1034, 1039, 1051, 0,
1048, 1030, 1039, 1054, 1060, 1050, 1049, 1051, 1064, 1047,
1053, 1067, 1063, 1069, 1057, 1054, 1068, 1055, 1070, 1048,
1062, 0, 0, 0, 1054, 1078, 1060, 1053, 1066, 1080,
1075, 1084, 1073, 1067, 1068, 1061, 1076, 1086, 1072, 1091,
1089, 1090, 1076, 1092, 0, 1093, 1091, 1078, 1080, 1083,
1099, 1079, 0, 1077, 1088, 0, 1106, 1099, 1087, 0,
1089, 1093, 1110, 0, 1095, 1086, 1101, 0, 1095, 0,
0, 1099, 1113, 1100, 0, 0, 1106, 1102, 1102, 0,
0, 1116, 1123, 1104, 1112, 1106, 1123, 1109, 1121, 1117,
1128, 1106, 1116, 1115, 1128, 1119, 1136, 1125, 1127, 1137,
1139, 1139, 0, 1140, 1143, 1142, 1140, 1134, 1144, 1133,
1127, 1139, 0, 1149, 1141, 1144, 1143, 1153, 0, 1151,
1145, 1143, 1141, 1144, 1151, 1149, 1157, 1155, 1163, 1141,
1161, 1143, 1154, 1153, 1156, 1166, 1175, 1174, 1166, 1160,
1178, 1178, 1173, 1163, 1170, 1179, 1183, 1168, 1187, 1177,
0, 1172, 1176, 1189, 1165, 1190, 0, 1177, 1181, 1177,
1176, 1185, 0, 1199, 1185, 1184, 1183, 1186, 1200, 1205,
0, 1193, 1199, 1191, 1198, 1206, 1203, 1200, 1195, 1187,
0, 1213, 1212, 1194, 1204, 1219, 1208, 1219, 1222, 1219,
1210, 1222, 1207, 1223, 1210, 0, 1211, 0, 1222, 1213,
1213, 1222, 1229, 1231, 1217, 1237, 1221, 1225, 0, 1213,
1223, 1223, 1232, 1230, 1241, 1242, 1236, 1230, 1230, 1223,
1249, 1253, 1250, 1242, 0, 1243, 1249, 1254, 0, 1253,
1260, 0, 1253, 1235, 1250, 0, 1251, 1265, 1247, 1248,
1267, 1255, 1257, 1271, 1254, 1255, 1260, 1264, 0, 1268,
1273, 1264, 1277, 1276, 1273, 1274, 1279, 1280, 1266, 0,
1280, 1267, 1269, 0, 1281, 1286, 1264, 1272, 1293, 1286,
1287, 1292, 1280, 1290, 1291, 0, 1273, 1281, 1298, 1276,
1283, 1288, 1305, 1288, 1296, 0, 1305, 1299, 1311, 0,
0, 1309, 1299, 1299, 0, 1302, 1305, 1313, 1311, 1318,
1305, 1301, 1318, 1296, 1324, 1318, 0, 1312, 0, 1319,
1324, 1321, 1313, 1326, 1321, 1319, 1334, 1322, 1318, 1318,
1334, 1335, 1327, 1314, 1315, 1319, 1325, 1328, 1343, 1328,
1330, 1336, 1331, 0, 1328, 1337, 1335, 1336, 1336, 1341,
1338, 0, 1355, 1332, 0, 1356, 1344, 1343, 1346, 1357,
1358, 1353, 1363, 1354, 1348, 1357, 1367, 1345, 1355, 1355,
1358, 1364, 1369, 1367, 1361, 1372, 1368, 1382, 1365, 1365,
1366, 1373, 1368, 1373, 1370, 1376, 1373, 1378, 1374, 1383,
1378, 1396, 1384, 1390, 1381, 1396, 1401, 1391, 1384, 1400,
1392, 1392, 0, 0, 1380, 1381, 1401, 1396, 1392, 1399,
1396, 1412, 0, 1402, 1402, 1399, 1407, 1419, 1412, 1402,
1405, 1404, 1397, 1417, 1422, 1412, 1410, 1411, 1415, 1429,
1426, 1433, 1410, 1431, 1428, 1433, 1419, 1421, 0, 1426,
0, 1437, 1418, 1426, 1426, 1437, 1429, 1431, 1430, 1423,
1424, 1438, 1439, 1436, 1442, 1443, 1453, 1440, 1432, 1443,
1453, 1438, 0, 1459, 1450, 1461, 1458, 1454, 1451, 1452,
1463, 1457, 1465, 1466, 1467, 1462, 0, 1464, 1470, 1459,
1453, 1477, 1478, 1472, 0, 1473, 0, 0, 1467, 1459,
1479, 1475, 1476, 1473, 1477, 1489, 1482, 1477, 1480, 1477,
1493, 1479, 1481, 1487, 1474, 1498, 1484, 1493, 1497, 1487,
1499, 1490, 1490, 1495, 0, 0, 0, 1511, 1501, 1509,
1500, 1502, 1489, 1504, 1504, 1492, 1503, 0, 1504, 1495,
1496, 1510, 0, 1505, 1507, 1509, 0, 1523, 1526, 1519,
1514, 0, 1526, 1506, 1517, 0, 1516, 1522, 1533, 1524,
0, 1526, 1527, 0, 1527, 1529, 0, 1539, 1519, 1525,
1532, 1528, 1534, 1532, 1532, 1537, 1533, 1536, 1554, 1540,
0, 1548, 1553, 1540, 1545, 1542, 1557, 1543, 1546, 1556,
1557, 1547, 1547, 1541, 1554, 1562, 0, 1544, 1558, 0,
1565, 1570, 1563, 0, 1562, 1562, 1574, 0, 1560, 1580,
1575, 1569, 1564, 1572, 1567, 1573, 1569, 1588, 1570, 1577,
1572, 1591, 1575, 1590, 0, 1587, 1588, 1594, 1579, 1580,
1585, 1583, 1595, 1586, 1598, 1592, 1587, 1589, 1598, 1585,
0, 1609, 1595, 1602, 1608, 1604, 1599, 0, 1606, 1605,
1617, 1604, 1609, 1605, 1598, 1618, 1614, 1620, 1627, 0,
1622, 1613, 1613, 0, 1614, 1617, 1621, 1622, 1620, 1625,
1625, 0, 1636, 1628, 1642, 0, 1624, 1626, 1637, 1628,
1620, 1634, 1641, 1632, 1643, 1633, 0, 1633, 1647, 1655,
0, 1641, 1646, 1640, 0, 0, 1652, 1646, 0, 0,
0, 1653, 1645, 1655, 1656, 1638, 1639, 0, 1640, 1651,
0, 1642, 1643, 1671, 1672, 1646, 1656, 1655, 1661, 1673,
1661, 1655, 1662, 1662, 0, 1663, 1664, 1680, 1666, 1662,
0, 1683, 1671, 1676, 1686, 1664, 1679, 0, 0, 1691,
1690, 1677, 1682, 0, 1701, 1688, 1681, 0, 1682, 1694,
1691, 1687, 1704, 1679, 1703, 1693, 0, 1695, 1709, 1707,
1708, 1699, 1697, 1710, 1714, 1717, 1714, 1703, 1710, 1711,
1704, 0, 1705, 1711, 1699, 1708, 0, 1720, 1725, 1706,
1723, 1719, 1733, 1707, 1724, 1717, 1719, 1723, 1733, 1722,
1733, 1725, 1739, 1731, 1742, 1743, 1743, 1744, 1725, 1746,
1737, 1751, 1749, 1746, 1736, 1738, 1746, 1747, 1751, 1742,
1748, 1749, 1759, 1764, 1751, 1747, 1759, 1764, 0, 0,
1762, 0, 1753, 1753, 0, 1753, 0, 0, 1759, 1755,
1762, 1759, 1773, 0, 0, 1764, 1762, 0, 1767, 1768,
1764, 1765, 0, 0, 1769, 1783, 0, 0, 1773, 1783,
1770, 1778, 1782, 0, 1791, 0, 1781, 1786, 1775, 1777,
1781, 1789, 1785, 1795, 1789, 1786, 1785, 1784, 1796, 1801,
1793, 1807, 1806, 1805, 1810, 1794, 1804, 1807, 0, 0,
0, 1800, 1795, 0, 1799, 1810, 1810, 1807, 1818, 1813,
1808, 1823, 0, 1810, 1814, 1808, 0, 1823, 1814, 1825,
0, 1811, 0, 1813, 1813, 1829, 1819, 1817, 1817, 1834,
0, 1821, 1828, 0, 1826, 1822, 1838, 1839, 1825, 1834,
1827, 1830, 1828, 1830, 0, 1833, 1833, 1848, 0, 1845,
0, 1840, 1851, 0, 0, 1837, 1853, 1847, 1835, 0,
1848, 1837, 1859, 1855, 1845, 1848, 1866, 1848, 1861, 0,
1855, 1853, 1844, 0, 1845, 1870, 0, 1870, 0, 0,
1861, 0, 1872, 1864, 0, 1864, 1866, 1861, 1868, 1867,
0, 1870, 1871, 0, 1866, 1875, 0, 0, 1867, 1877,
1870, 0, 0, 1887, 1879, 1892, 0, 0, 1892, 1892,
1891, 1892, 1880, 1886, 0, 1895, 1887, 1882, 0, 2440,
1919, 1923, 1924, 1928, 1932, 1936, 1940
} ;
static yyconst flex_int32_t yy_def[2308] =
{ 0,
2300, 1, 2301, 2301, 2300, 2300, 2300, 2300, 2300, 2302,
2300, 2300, 2300, 2300, 2300, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2304, 2305, 2306, 2300, 2300, 2300, 2302, 2300, 2302,
2300, 2300, 2307, 2300, 2300, 2300, 2300, 2300, 2300, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2304, 2305, 2305, 2300, 2300, 2300, 2302, 2300,
2307, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2300, 2300, 2300, 2300,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2300, 2300, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2300, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303,
2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 2303, 0,
2300, 2300, 2300, 2300, 2300, 2300, 2300
} ;
static yyconst flex_uint32_t yy_nxt[2499] =
{ 0,
6, 7, 8, 7, 9, 10, 11, 11, 11, 12,
13, 14, 14, 14, 14, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 25, 32, 33, 34, 35, 36, 37,
25, 38, 25, 6, 6, 25, 25, 25, 39, 25,
25, 25, 25, 25, 40, 25, 41, 25, 8, 8,
45, 49, 45, 43, 43, 791, 44, 44, 51, 51,
51, 51, 51, 52, 67, 54, 53, 55, 55, 55,
55, 55, 57, 61, 62, 63, 90, 56, 68, 149,
91, 69, 93, 64, 75, 58, 94, 150, 76, 50,
65, 66, 70, 92, 155, 71, 146, 156, 792, 72,
79, 99, 73, 56, 77, 100, 80, 78, 74, 101,
147, 84, 81, 82, 95, 102, 103, 59, 83, 85,
104, 96, 86, 793, 105, 87, 170, 97, 88, 107,
106, 89, 111, 108, 140, 45, 112, 45, 171, 141,
49, 159, 117, 109, 113, 192, 118, 244, 114, 110,
119, 115, 116, 122, 186, 245, 120, 123, 126, 121,
127, 124, 193, 128, 129, 179, 134, 125, 187, 180,
135, 130, 131, 136, 137, 132, 133, 142, 50, 50,
138, 143, 212, 139, 213, 144, 51, 51, 51, 51,
51, 145, 200, 201, 794, 203, 160, 163, 163, 163,
163, 163, 204, 233, 234, 795, 54, 164, 55, 55,
55, 55, 55, 796, 182, 174, 235, 183, 56, 184,
165, 175, 160, 166, 166, 166, 166, 166, 176, 239,
188, 797, 241, 164, 189, 190, 207, 191, 224, 194,
195, 240, 208, 242, 56, 196, 236, 197, 243, 209,
237, 225, 247, 210, 226, 227, 249, 228, 248, 252,
253, 261, 264, 276, 266, 250, 267, 2300, 262, 268,
2300, 251, 265, 272, 273, 269, 270, 277, 278, 280,
299, 283, 286, 294, 279, 284, 281, 287, 288, 303,
155, 295, 289, 156, 49, 300, 392, 798, 285, 411,
393, 304, 312, 296, 412, 313, 313, 313, 313, 313,
163, 163, 163, 163, 163, 533, 799, 504, 315, 534,
314, 316, 316, 316, 316, 316, 166, 166, 166, 166,
166, 505, 50, 166, 166, 166, 166, 166, 439, 601,
610, 602, 645, 440, 646, 611, 314, 313, 313, 313,
313, 313, 313, 313, 313, 313, 313, 457, 800, 801,
458, 458, 458, 458, 458, 316, 316, 316, 316, 316,
316, 316, 316, 316, 316, 464, 465, 466, 660, 685,
467, 468, 584, 705, 802, 469, 470, 706, 661, 585,
707, 803, 471, 686, 695, 472, 458, 458, 458, 458,
458, 458, 458, 458, 458, 458, 709, 724, 696, 768,
710, 725, 804, 805, 769, 806, 807, 808, 809, 810,
811, 812, 813, 814, 815, 816, 817, 818, 819, 820,
821, 822, 823, 824, 825, 826, 827, 828, 829, 830,
831, 832, 833, 834, 836, 837, 838, 839, 835, 840,
841, 842, 843, 844, 845, 846, 847, 850, 851, 853,
854, 855, 852, 856, 857, 848, 858, 859, 860, 861,
862, 863, 849, 864, 865, 866, 867, 868, 869, 870,
871, 872, 873, 874, 875, 876, 877, 878, 879, 880,
881, 884, 885, 886, 887, 882, 883, 888, 889, 890,
891, 892, 893, 894, 895, 896, 897, 898, 899, 900,
901, 902, 903, 904, 905, 906, 907, 908, 909, 910,
911, 912, 913, 914, 915, 916, 917, 918, 919, 920,
921, 922, 923, 924, 925, 926, 927, 928, 930, 931,
932, 933, 929, 934, 935, 936, 937, 938, 939, 941,
942, 943, 944, 945, 946, 947, 948, 949, 950, 951,
952, 953, 954, 940, 955, 956, 957, 958, 959, 960,
961, 962, 963, 964, 965, 966, 967, 968, 969, 970,
971, 972, 973, 974, 976, 977, 978, 979, 980, 981,
982, 983, 984, 985, 975, 986, 987, 988, 989, 990,
991, 992, 993, 994, 995, 996, 997, 998, 999, 1000,
1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010,
1011, 1012, 1013, 1015, 1016, 1017, 1020, 1021, 1022, 1023,
1024, 1014, 1025, 1026, 1027, 1028, 1018, 1029, 1019, 1030,
1031, 1032, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042,
1043, 1033, 1044, 1034, 1045, 1046, 1047, 1048, 1049, 1050,
1051, 1052, 1054, 1055, 1057, 1058, 1059, 1056, 1060, 1061,
1053, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070,
1071, 1072, 1073, 1074, 1075, 1076, 1077, 1081, 1082, 1083,
1078, 1084, 1085, 1086, 1087, 1088, 1089, 1079, 1090, 1093,
1080, 1094, 1091, 1095, 1096, 1097, 1098, 1099, 1100, 1101,
1092, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110,
1112, 1114, 1115, 1111, 1116, 1117, 1118, 1113, 1119, 1120,
1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130,
1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140,
1141, 1142, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151,
1152, 1153, 1143, 1154, 1155, 1156, 1157, 1158, 1159, 1160,
1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170,
1171, 1172, 1173, 1174, 1175, 1177, 1178, 1179, 1180, 1181,
1182, 1183, 1184, 1176, 1185, 1186, 1187, 1188, 1189, 1190,
1193, 1194, 1195, 1197, 1198, 1199, 1200, 1201, 1202, 1191,
1203, 1192, 1204, 1209, 1210, 1211, 1196, 1212, 1213, 1214,
1215, 1216, 1218, 1219, 1220, 1221, 1222, 1224, 1225, 1226,
1205, 1227, 1217, 1228, 1206, 1207, 1208, 1229, 1230, 1231,
1232, 1233, 1234, 1223, 1235, 1236, 1237, 1238, 1239, 1240,
1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250,
1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260,
1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270,
1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280,
1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290,
1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299, 1300,
1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310,
1313, 1311, 1314, 1315, 1317, 1312, 1318, 1319, 1320, 1321,
1316, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1331,
1332, 1330, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340,
1341, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353,
1354, 1355, 1342, 1343, 1344, 1356, 1357, 1358, 1359, 1360,
1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370,
1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1380,
1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390,
1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400,
1401, 1402, 1403, 1404, 1405, 1408, 1409, 1410, 1411, 1412,
1406, 1413, 1414, 1407, 1415, 1416, 1417, 1418, 1419, 1420,
1421, 1422, 1423, 1424, 1425, 1426, 1427, 1428, 1429, 1430,
1431, 1432, 1433, 1434, 1435, 1436, 1437, 1438, 1439, 1440,
1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450,
1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460,
1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470,
1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1480,
1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488, 1489, 1490,
1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500,
1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510,
1511, 1512, 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1520,
1521, 1522, 1523, 1525, 1526, 1527, 1528, 1529, 1524, 1530,
1531, 1532, 1533, 1534, 1535, 1536, 1537, 1538, 1539, 1540,
1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549, 1550,
1551, 1552, 1553, 1554, 1555, 1556, 1557, 1558, 1559, 1560,
1561, 1562, 1563, 1564, 1565, 1566, 1567, 1568, 1569, 1570,
1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580,
1581, 1582, 1583, 1584, 1585, 1586, 1587, 1588, 1589, 1590,
1591, 1592, 1593, 1594, 1595, 1596, 1597, 1598, 1599, 1600,
1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610,
1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, 1619, 1620,
1621, 1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629, 1630,
1631, 1632, 1633, 1634, 1635, 1637, 1638, 1639, 1640, 1641,
1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1636,
1651, 1652, 1653, 1654, 1655, 1656, 1657, 1658, 1659, 1660,
1661, 1662, 1663, 1664, 1665, 1666, 1667, 1668, 1669, 1670,
1671, 1672, 1673, 1674, 1675, 1676, 1677, 1678, 1679, 1680,
1681, 1682, 1683, 1684, 1685, 1686, 1687, 1688, 1689, 1690,
1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700,
1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710,
1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720,
1721, 1722, 1723, 1724, 1725, 1726, 1727, 1728, 1729, 1730,
1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740,
1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750,
1751, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760,
1761, 1762, 1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770,
1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1780,
1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790,
1791, 1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799, 1800,
1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1810,
1811, 1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820,
1821, 1822, 1823, 1824, 1825, 1826, 1827, 1828, 1829, 1831,
1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841,
1842, 1843, 1844, 1830, 1845, 1846, 1847, 1848, 1849, 1850,
1851, 1852, 1853, 1854, 1855, 1856, 1858, 1859, 1860, 1861,
1862, 1863, 1864, 1865, 1857, 1866, 1867, 1868, 1869, 1870,
1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880,
1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890,
1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900,
1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910,
1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920,
1921, 1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930,
1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940,
1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950,
1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960,
1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970,
1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980,
1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990,
1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 1999, 2000, 2001, 2009, 2010,
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030,
2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040,
2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050,
2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060,
2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070,
2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080,
2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090,
2091, 2092, 2093, 2094, 2095, 2096, 2098, 2099, 2100, 2101,
2102, 2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110, 2111,
2112, 2113, 2114, 2115, 2116, 2097, 2117, 2118, 2119, 2120,
2121, 2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130,
2131, 2132, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2140,
2141, 2142, 2143, 2144, 2145, 2146, 2147, 2148, 2149, 2150,
2151, 2152, 2153, 2154, 2155, 2156, 2157, 2158, 2159, 2160,
2161, 2162, 2163, 2164, 2165, 2166, 2167, 2168, 2169, 2170,
2171, 2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 2180,
2181, 2182, 2183, 2184, 2185, 2186, 2187, 2188, 2189, 2190,
2191, 2192, 2193, 2194, 2195, 2196, 2197, 2198, 2199, 2200,
2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210,
2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220,
2221, 2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2230,
2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240,
2241, 2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249, 2250,
2251, 2252, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260,
2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270,
2271, 2272, 2273, 2274, 2275, 2276, 2277, 2278, 2279, 2280,
2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290,
2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299, 42,
42, 42, 42, 48, 48, 48, 48, 60, 153, 790,
789, 153, 154, 788, 154, 154, 157, 787, 157, 157,
161, 161, 161, 161, 786, 785, 784, 783, 782, 781,
780, 779, 778, 777, 776, 775, 774, 773, 772, 771,
770, 767, 766, 765, 764, 763, 762, 761, 760, 759,
758, 757, 756, 755, 754, 753, 752, 751, 750, 749,
748, 747, 746, 745, 744, 743, 742, 741, 740, 739,
738, 737, 736, 735, 734, 733, 732, 731, 730, 729,
728, 727, 726, 723, 722, 721, 720, 719, 718, 717,
716, 715, 714, 713, 712, 711, 708, 704, 703, 702,
701, 700, 699, 698, 697, 694, 693, 692, 691, 690,
689, 688, 687, 684, 683, 682, 681, 680, 679, 678,
677, 676, 675, 674, 673, 672, 671, 670, 669, 668,
667, 666, 665, 664, 663, 662, 659, 658, 657, 656,
655, 654, 653, 652, 651, 650, 649, 648, 647, 644,
643, 642, 641, 640, 639, 638, 637, 636, 635, 634,
633, 632, 631, 630, 629, 628, 627, 626, 625, 624,
623, 622, 621, 620, 619, 618, 617, 616, 615, 614,
613, 612, 609, 608, 607, 606, 605, 604, 603, 600,
599, 598, 597, 596, 595, 594, 593, 592, 591, 590,
589, 588, 587, 586, 583, 582, 581, 580, 579, 578,
577, 576, 575, 574, 573, 572, 571, 570, 569, 568,
567, 566, 565, 564, 563, 562, 561, 560, 559, 558,
557, 556, 555, 554, 553, 552, 551, 550, 549, 548,
547, 546, 545, 544, 543, 542, 541, 540, 539, 538,
537, 536, 535, 532, 531, 530, 529, 528, 527, 526,
525, 524, 523, 522, 521, 520, 519, 518, 517, 516,
515, 514, 513, 512, 511, 510, 509, 508, 507, 506,
503, 502, 501, 500, 499, 498, 497, 496, 495, 494,
493, 492, 491, 490, 489, 488, 487, 486, 485, 484,
483, 482, 481, 480, 479, 478, 477, 476, 475, 474,
473, 463, 462, 461, 460, 459, 456, 455, 454, 453,
452, 451, 450, 449, 448, 447, 446, 445, 444, 443,
442, 441, 438, 437, 436, 435, 434, 433, 432, 431,
430, 429, 428, 427, 426, 425, 424, 423, 422, 421,
420, 419, 418, 417, 416, 415, 414, 413, 410, 409,
408, 407, 406, 405, 404, 403, 402, 401, 400, 399,
398, 397, 396, 395, 394, 391, 390, 389, 388, 387,
386, 385, 384, 383, 382, 381, 380, 379, 378, 377,
376, 375, 374, 373, 372, 371, 370, 369, 368, 367,
366, 365, 364, 363, 362, 361, 360, 359, 358, 357,
356, 355, 354, 353, 352, 351, 350, 349, 348, 347,
346, 345, 344, 343, 342, 341, 340, 339, 338, 337,
336, 335, 334, 333, 332, 331, 330, 329, 328, 327,
326, 325, 324, 323, 322, 321, 320, 319, 318, 317,
162, 311, 310, 309, 308, 307, 306, 305, 302, 301,
298, 297, 293, 292, 291, 290, 282, 275, 274, 271,
263, 260, 259, 258, 257, 256, 255, 254, 246, 238,
232, 231, 230, 229, 223, 222, 221, 220, 219, 218,
217, 216, 215, 214, 211, 206, 205, 202, 199, 198,
185, 181, 178, 177, 173, 172, 169, 168, 167, 162,
46, 158, 152, 151, 148, 98, 47, 46, 2300, 5,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300
} ;
static yyconst flex_int32_t yy_chk[2499] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 3, 4,
7, 10, 7, 3, 4, 662, 3, 4, 12, 12,
12, 12, 12, 13, 17, 14, 13, 14, 14, 14,
14, 14, 15, 16, 16, 16, 22, 14, 17, 39,
22, 17, 23, 16, 19, 15, 23, 39, 19, 10,
16, 16, 18, 22, 43, 18, 37, 43, 663, 18,
20, 27, 18, 14, 19, 27, 20, 19, 18, 27,
37, 21, 20, 20, 24, 27, 28, 15, 20, 21,
28, 24, 21, 664, 28, 21, 62, 24, 21, 29,
28, 21, 30, 29, 35, 45, 30, 45, 62, 35,
48, 50, 31, 29, 30, 74, 31, 106, 30, 29,
31, 30, 30, 32, 72, 106, 31, 32, 33, 31,
33, 32, 74, 33, 33, 68, 34, 32, 72, 68,
34, 33, 33, 34, 34, 33, 33, 36, 48, 50,
34, 36, 85, 34, 85, 36, 51, 51, 51, 51,
51, 36, 78, 78, 665, 80, 51, 54, 54, 54,
54, 54, 80, 101, 101, 666, 55, 54, 55, 55,
55, 55, 55, 667, 70, 65, 101, 70, 55, 70,
56, 65, 51, 56, 56, 56, 56, 56, 65, 104,
73, 668, 105, 54, 73, 73, 83, 73, 96, 75,
75, 104, 83, 105, 55, 75, 102, 75, 105, 83,
102, 96, 108, 83, 96, 96, 109, 96, 108, 110,
110, 120, 122, 128, 123, 109, 123, 154, 120, 123,
154, 109, 122, 125, 125, 123, 123, 128, 129, 130,
142, 132, 133, 139, 129, 132, 130, 133, 134, 145,
155, 139, 134, 155, 159, 142, 244, 669, 132, 263,
244, 145, 160, 139, 263, 160, 160, 160, 160, 160,
163, 163, 163, 163, 163, 391, 670, 361, 164, 391,
163, 164, 164, 164, 164, 164, 165, 165, 165, 165,
165, 361, 159, 166, 166, 166, 166, 166, 294, 466,
475, 466, 515, 294, 515, 475, 163, 312, 312, 312,
312, 312, 313, 313, 313, 313, 313, 314, 672, 673,
314, 314, 314, 314, 314, 315, 315, 315, 315, 315,
316, 316, 316, 316, 316, 323, 323, 323, 530, 554,
323, 323, 448, 575, 675, 323, 323, 575, 530, 448,
575, 676, 323, 554, 566, 323, 457, 457, 457, 457,
457, 458, 458, 458, 458, 458, 577, 592, 566, 639,
577, 592, 677, 678, 639, 679, 680, 681, 682, 683,
684, 685, 686, 687, 688, 689, 690, 691, 693, 694,
695, 696, 697, 698, 699, 700, 701, 702, 703, 704,
705, 706, 707, 708, 709, 710, 711, 712, 708, 713,
714, 715, 716, 717, 718, 719, 720, 721, 723, 724,
726, 728, 723, 729, 730, 720, 731, 732, 733, 734,
735, 736, 720, 737, 738, 739, 740, 741, 742, 743,
744, 745, 746, 747, 748, 749, 750, 752, 753, 753,
754, 755, 757, 758, 759, 754, 754, 760, 761, 762,
763, 764, 765, 766, 767, 768, 769, 770, 771, 772,
773, 774, 775, 777, 778, 779, 780, 781, 782, 783,
784, 785, 786, 787, 788, 789, 790, 791, 792, 793,
794, 795, 796, 797, 798, 799, 800, 801, 802, 803,
804, 805, 801, 806, 807, 808, 809, 810, 811, 812,
813, 814, 815, 816, 817, 818, 819, 820, 821, 822,
823, 824, 825, 811, 826, 827, 828, 829, 830, 831,
832, 833, 834, 835, 836, 837, 839, 840, 841, 842,
843, 844, 845, 846, 847, 848, 849, 850, 851, 853,
855, 856, 857, 858, 846, 860, 861, 863, 864, 865,
866, 867, 868, 869, 870, 871, 872, 873, 874, 875,
876, 877, 878, 879, 880, 881, 882, 883, 884, 885,
886, 887, 888, 889, 890, 891, 892, 893, 894, 895,
896, 888, 897, 898, 899, 901, 891, 902, 891, 903,
904, 904, 905, 906, 907, 908, 909, 910, 911, 912,
913, 904, 915, 904, 916, 917, 918, 919, 920, 921,
922, 923, 924, 925, 926, 927, 928, 925, 929, 930,
923, 931, 932, 933, 934, 935, 936, 937, 938, 939,
940, 941, 942, 943, 944, 945, 946, 947, 948, 949,
946, 950, 951, 952, 953, 954, 955, 946, 956, 957,
946, 958, 956, 959, 960, 961, 962, 963, 964, 965,
956, 966, 967, 968, 969, 970, 971, 972, 973, 974,
975, 976, 977, 974, 978, 980, 981, 975, 982, 983,
984, 985, 986, 987, 988, 989, 990, 992, 993, 994,
996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005,
1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015,
1016, 1017, 1007, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034,
1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044,
1045, 1046, 1047, 1039, 1048, 1049, 1050, 1051, 1053, 1053,
1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1053,
1064, 1053, 1065, 1066, 1068, 1069, 1057, 1070, 1071, 1072,
1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1083,
1065, 1084, 1074, 1085, 1065, 1065, 1065, 1086, 1087, 1088,
1089, 1090, 1091, 1079, 1092, 1093, 1094, 1095, 1097, 1098,
1099, 1100, 1102, 1104, 1105, 1106, 1107, 1108, 1110, 1111,
1112, 1113, 1114, 1115, 1116, 1117, 1118, 1120, 1121, 1122,
1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132,
1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142,
1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152,
1153, 1154, 1155, 1157, 1158, 1159, 1160, 1162, 1163, 1164,
1165, 1166, 1167, 1168, 1169, 1170, 1172, 1173, 1174, 1176,
1177, 1176, 1178, 1179, 1180, 1176, 1181, 1182, 1183, 1184,
1179, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193,
1194, 1192, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202,
1203, 1204, 1205, 1209, 1210, 1211, 1212, 1213, 1214, 1215,
1216, 1217, 1203, 1203, 1203, 1218, 1220, 1221, 1222, 1223,
1224, 1225, 1226, 1227, 1228, 1230, 1230, 1231, 1232, 1233,
1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243,
1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253,
1256, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266,
1267, 1268, 1269, 1271, 1272, 1273, 1274, 1275, 1276, 1277,
1272, 1278, 1279, 1272, 1280, 1281, 1282, 1283, 1284, 1285,
1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295,
1296, 1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305,
1306, 1308, 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316,
1317, 1318, 1319, 1321, 1322, 1323, 1324, 1325, 1326, 1327,
1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337,
1338, 1339, 1340, 1341, 1345, 1346, 1347, 1348, 1349, 1350,
1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360,
1361, 1362, 1363, 1364, 1366, 1367, 1368, 1369, 1370, 1371,
1372, 1374, 1375, 1377, 1378, 1379, 1381, 1382, 1383, 1385,
1386, 1387, 1389, 1392, 1393, 1394, 1397, 1398, 1399, 1402,
1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1405, 1411,
1412, 1413, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421,
1422, 1424, 1425, 1426, 1427, 1428, 1429, 1430, 1431, 1432,
1434, 1435, 1436, 1437, 1438, 1440, 1441, 1442, 1443, 1444,
1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454,
1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464,
1465, 1466, 1467, 1468, 1469, 1470, 1472, 1473, 1474, 1475,
1476, 1478, 1479, 1480, 1481, 1482, 1484, 1485, 1486, 1487,
1488, 1489, 1490, 1492, 1493, 1494, 1495, 1496, 1497, 1498,
1499, 1500, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509,
1510, 1511, 1512, 1513, 1514, 1515, 1517, 1519, 1520, 1521,
1522, 1523, 1524, 1525, 1526, 1527, 1528, 1530, 1531, 1532,
1533, 1534, 1535, 1536, 1537, 1538, 1539, 1540, 1541, 1526,
1542, 1543, 1544, 1546, 1547, 1548, 1550, 1551, 1553, 1554,
1555, 1557, 1558, 1559, 1560, 1561, 1562, 1563, 1564, 1565,
1566, 1567, 1568, 1570, 1571, 1572, 1573, 1574, 1575, 1576,
1577, 1578, 1579, 1581, 1582, 1583, 1585, 1586, 1587, 1588,
1589, 1590, 1591, 1592, 1593, 1594, 1595, 1597, 1598, 1599,
1600, 1601, 1602, 1603, 1604, 1605, 1607, 1608, 1609, 1612,
1613, 1614, 1616, 1617, 1618, 1619, 1620, 1621, 1622, 1623,
1624, 1625, 1626, 1628, 1630, 1631, 1632, 1633, 1634, 1635,
1636, 1637, 1638, 1639, 1640, 1641, 1642, 1643, 1644, 1645,
1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653, 1655, 1656,
1657, 1658, 1659, 1660, 1661, 1663, 1664, 1666, 1667, 1668,
1669, 1670, 1671, 1672, 1673, 1674, 1675, 1676, 1677, 1678,
1679, 1680, 1681, 1682, 1683, 1684, 1685, 1686, 1687, 1688,
1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698,
1699, 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708,
1709, 1710, 1711, 1712, 1715, 1716, 1717, 1718, 1719, 1720,
1721, 1722, 1724, 1725, 1726, 1727, 1728, 1729, 1730, 1731,
1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741,
1742, 1743, 1744, 1745, 1746, 1747, 1748, 1750, 1752, 1753,
1754, 1755, 1756, 1740, 1757, 1758, 1759, 1760, 1761, 1762,
1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770, 1771, 1772,
1774, 1775, 1776, 1777, 1768, 1778, 1779, 1780, 1781, 1782,
1783, 1784, 1785, 1786, 1788, 1789, 1790, 1791, 1792, 1793,
1794, 1796, 1799, 1800, 1801, 1802, 1803, 1804, 1805, 1806,
1807, 1808, 1809, 1810, 1811, 1812, 1813, 1814, 1815, 1816,
1817, 1818, 1819, 1820, 1821, 1822, 1823, 1824, 1828, 1829,
1830, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1839, 1840,
1841, 1842, 1844, 1845, 1846, 1848, 1849, 1850, 1851, 1853,
1854, 1855, 1857, 1858, 1859, 1860, 1862, 1863, 1865, 1866,
1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877,
1878, 1879, 1880, 1882, 1883, 1884, 1885, 1886, 1887, 1888,
1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1898, 1899,
1901, 1902, 1903, 1905, 1906, 1907, 1909, 1910, 1911, 1912,
1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922,
1923, 1924, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933,
1934, 1935, 1936, 1937, 1938, 1931, 1931, 1931, 1939, 1940,
1942, 1943, 1944, 1945, 1946, 1947, 1949, 1950, 1951, 1952,
1953, 1954, 1955, 1956, 1957, 1958, 1959, 1961, 1962, 1963,
1965, 1966, 1967, 1968, 1969, 1970, 1971, 1973, 1974, 1975,
1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986,
1988, 1989, 1990, 1992, 1993, 1994, 1997, 1998, 2002, 2003,
2004, 2005, 2006, 2007, 2009, 2010, 2012, 2013, 2014, 2015,
2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2026,
2027, 2028, 2029, 2030, 2032, 2033, 2034, 2035, 2036, 2037,
2040, 2041, 2042, 2043, 2045, 2045, 2046, 2047, 2049, 2050,
2051, 2052, 2053, 2054, 2055, 2056, 2058, 2059, 2060, 2061,
2062, 2063, 2064, 2065, 2066, 2045, 2067, 2068, 2069, 2070,
2071, 2073, 2074, 2075, 2076, 2078, 2079, 2080, 2081, 2082,
2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092,
2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100, 2101, 2102,
2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110, 2111, 2112,
2113, 2114, 2115, 2116, 2117, 2118, 2121, 2123, 2124, 2126,
2129, 2130, 2131, 2132, 2133, 2136, 2137, 2139, 2140, 2141,
2142, 2145, 2146, 2149, 2150, 2151, 2152, 2153, 2155, 2157,
2158, 2159, 2160, 2161, 2162, 2163, 2164, 2165, 2166, 2167,
2168, 2169, 2170, 2171, 2172, 2173, 2174, 2175, 2176, 2177,
2178, 2182, 2183, 2185, 2186, 2187, 2188, 2189, 2190, 2191,
2192, 2194, 2195, 2196, 2198, 2199, 2200, 2202, 2204, 2205,
2206, 2207, 2208, 2209, 2210, 2212, 2213, 2215, 2216, 2217,
2218, 2219, 2220, 2221, 2222, 2223, 2224, 2226, 2227, 2228,
2230, 2232, 2233, 2236, 2237, 2238, 2239, 2241, 2242, 2243,
2244, 2245, 2246, 2247, 2248, 2249, 2251, 2252, 2253, 2255,
2256, 2258, 2261, 2263, 2264, 2266, 2267, 2268, 2269, 2270,
2272, 2273, 2275, 2276, 2279, 2280, 2281, 2284, 2285, 2286,
2289, 2290, 2291, 2292, 2293, 2294, 2296, 2297, 2298, 2301,
2301, 2301, 2301, 2302, 2302, 2302, 2302, 2303, 2304, 661,
660, 2304, 2305, 659, 2305, 2305, 2306, 658, 2306, 2306,
2307, 2307, 2307, 2307, 657, 656, 655, 654, 653, 652,
651, 650, 649, 648, 647, 646, 645, 643, 642, 641,
640, 637, 636, 635, 633, 632, 631, 630, 629, 628,
627, 626, 625, 624, 623, 622, 621, 620, 619, 618,
617, 616, 615, 614, 613, 611, 610, 609, 608, 607,
606, 605, 604, 603, 602, 601, 600, 599, 598, 597,
596, 594, 593, 591, 590, 588, 587, 586, 585, 584,
583, 582, 581, 580, 579, 578, 576, 574, 573, 572,
571, 570, 569, 568, 567, 565, 562, 561, 559, 558,
557, 556, 555, 553, 552, 551, 550, 549, 548, 547,
546, 545, 544, 543, 542, 541, 540, 539, 538, 537,
536, 535, 534, 533, 532, 531, 529, 527, 526, 525,
524, 523, 522, 521, 520, 519, 518, 517, 516, 514,
513, 512, 511, 510, 509, 508, 506, 505, 504, 502,
501, 500, 499, 497, 496, 495, 494, 493, 492, 490,
489, 488, 487, 485, 484, 483, 482, 481, 480, 479,
477, 476, 474, 472, 471, 470, 469, 468, 467, 465,
464, 463, 462, 461, 460, 459, 456, 455, 454, 453,
452, 451, 450, 449, 447, 446, 445, 444, 443, 441,
440, 439, 438, 437, 436, 435, 434, 433, 431, 429,
428, 427, 426, 425, 423, 422, 421, 420, 419, 418,
417, 416, 415, 414, 413, 412, 411, 410, 409, 408,
407, 406, 405, 404, 403, 402, 400, 398, 397, 396,
395, 394, 393, 390, 389, 388, 387, 386, 385, 383,
382, 380, 379, 378, 377, 376, 375, 374, 373, 372,
371, 370, 369, 368, 367, 366, 365, 364, 363, 362,
360, 359, 358, 356, 355, 354, 353, 352, 351, 348,
347, 346, 345, 344, 343, 342, 341, 340, 339, 338,
337, 336, 335, 334, 333, 331, 330, 329, 328, 326,
324, 322, 320, 319, 318, 317, 311, 310, 309, 308,
306, 305, 304, 303, 302, 301, 300, 299, 298, 297,
296, 295, 292, 291, 290, 289, 287, 285, 284, 283,
282, 281, 280, 279, 277, 276, 275, 274, 273, 272,
271, 270, 269, 268, 267, 266, 265, 264, 262, 261,
260, 259, 258, 257, 256, 254, 253, 252, 251, 250,
249, 248, 247, 246, 245, 243, 241, 240, 239, 238,
237, 236, 235, 234, 233, 232, 231, 230, 229, 228,
227, 226, 225, 224, 223, 222, 221, 220, 219, 218,
217, 216, 215, 214, 213, 212, 211, 210, 209, 208,
207, 206, 205, 204, 203, 202, 201, 200, 199, 198,
197, 196, 195, 194, 193, 192, 191, 189, 188, 187,
186, 185, 184, 183, 182, 181, 180, 179, 178, 177,
176, 175, 174, 173, 172, 171, 170, 169, 168, 167,
161, 152, 151, 150, 149, 148, 147, 146, 144, 143,
141, 140, 138, 137, 136, 135, 131, 127, 126, 124,
121, 118, 117, 116, 115, 114, 112, 111, 107, 103,
100, 99, 98, 97, 95, 94, 93, 92, 91, 90,
89, 88, 87, 86, 84, 82, 81, 79, 77, 76,
71, 69, 67, 66, 64, 63, 61, 59, 57, 53,
46, 44, 41, 40, 38, 26, 9, 8, 5, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300,
2300, 2300, 2300, 2300, 2300, 2300, 2300, 2300
} ;
/* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed.
*/
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
#line 1 "/home/jczech/mcell/build/deps/mdllex.l"
#line 2 "/home/jczech/mcell/build/deps/mdllex.l"
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "strfunc.h"
#include "mdlparse_aux.h"
#include "mdlparse.h"
#include "mem_util.h"
#include "logging.h"
#define YY_DECL int mdllex( YYSTYPE *yylval, struct mdlparse_vars *parse_state, yyscan_t yyscanner )
#define YY_NO_UNPUT
#ifdef __cplusplus
#define INPUT_FUNC yyinput
#else
#define INPUT_FUNC input
#endif
void *mdlalloc(yy_size_t size, yyscan_t yyscanner)
{
UNUSED(yyscanner);
return CHECKED_MALLOC(size, "memory buffer for parser");
}
void *mdlrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
{
UNUSED(yyscanner);
ptr = (void *) realloc((char *) ptr, size);
if (ptr == NULL)
mcell_allocfailed("Failed to resize memory buffer for parser.");
return ptr;
}
void mdlfree (void * ptr, yyscan_t yyscanner)
{
UNUSED(yyscanner);
free((char *) ptr);
}
#define YY_FATAL_ERROR(msg) mcell_error("%s", msg)
/* Define state for parsing comments */
/* Reentrant lexer allows safer handling of include files from the parser */
/* Set up function name prefixes and output file name */
/* Enable condition state stack */
/* Disable mdlwrap feature */
/* Eliminate unused symbols to eliminate compiler warnings */
#define YY_NO_INPUT 1
#line 1809 "/home/jczech/mcell/build/deps/mdllex.c"
#define INITIAL 0
#define IN_COMMENT 1
#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
* down here because we want the user's section 1 to have been scanned first.
* The user has a chance to override it with an option.
*/
#include <unistd.h>
#endif
#ifndef YY_EXTRA_TYPE
#define YY_EXTRA_TYPE void *
#endif
/* Holds the entire state of the reentrant scanner. */
struct yyguts_t
{
/* User-defined. Not touched by flex. */
YY_EXTRA_TYPE yyextra_r;
/* The rest are the same as the globals declared in the non-reentrant scanner. */
FILE *yyin_r, *yyout_r;
size_t yy_buffer_stack_top; /**< index of top of stack. */
size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char;
int yy_n_chars;
yy_size_t yyleng_r;
char *yy_c_buf_p;
int yy_init;
int yy_start;
int yy_did_buffer_switch_on_eof;
int yy_start_stack_ptr;
int yy_start_stack_depth;
int *yy_start_stack;
yy_state_type yy_last_accepting_state;
char* yy_last_accepting_cpos;
int yylineno_r;
int yy_flex_debug_r;
char *yytext_r;
int yy_more_flag;
int yy_more_len;
}; /* end struct yyguts_t */
static int yy_init_globals (yyscan_t yyscanner );
int mdllex_init (yyscan_t* scanner);
int mdllex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
/* Accessor methods to globals.
These are made visible to non-reentrant scanners for convenience. */
int mdllex_destroy (yyscan_t yyscanner );
int mdlget_debug (yyscan_t yyscanner );
void mdlset_debug (int debug_flag ,yyscan_t yyscanner );
YY_EXTRA_TYPE mdlget_extra (yyscan_t yyscanner );
void mdlset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
FILE *mdlget_in (yyscan_t yyscanner );
void mdlset_in (FILE * _in_str ,yyscan_t yyscanner );
FILE *mdlget_out (yyscan_t yyscanner );
void mdlset_out (FILE * _out_str ,yyscan_t yyscanner );
yy_size_t mdlget_leng (yyscan_t yyscanner );
char *mdlget_text (yyscan_t yyscanner );
int mdlget_lineno (yyscan_t yyscanner );
void mdlset_lineno (int _line_number ,yyscan_t yyscanner );
int mdlget_column (yyscan_t yyscanner );
void mdlset_column (int _column_no ,yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
*/
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int mdlwrap (yyscan_t yyscanner );
#else
extern int mdlwrap (yyscan_t yyscanner );
#endif
#endif
#ifndef YY_NO_UNPUT
#endif
#ifndef yytext_ptr
static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput (yyscan_t yyscanner );
#else
static int input (yyscan_t yyscanner );
#endif
#endif
static void yy_push_state (int _new_state ,yyscan_t yyscanner);
static void yy_pop_state (yyscan_t yyscanner );
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
* is returned in "result".
*/
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
errno=0; \
while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
{ \
if( errno != EINTR) \
{ \
YY_FATAL_ERROR( "input in flex scanner failed" ); \
break; \
} \
errno=0; \
clearerr(yyin); \
}\
\
#endif
/* No semi-colon after return; correct usage is to write "yyterminate();" -
* we don't want an extra ';' after the "return" because that will cause
* some compilers to complain about unreachable statements.
*/
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif
/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif
/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
#endif
/* end tables serialization structures and prototypes */
/* Default declaration of generated scanner - a define so the user can
* easily add parameters.
*/
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
extern int mdllex (yyscan_t yyscanner);
#define YY_DECL int mdllex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
* have been set up.
*/
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif
/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK /*LINTED*/break;
#endif
#define YY_RULE_SETUP \
YY_USER_ACTION
/** The main scanner function which does all the work.
*/
YY_DECL
{
yy_state_type yy_current_state;
char *yy_cp, *yy_bp;
int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( !yyg->yy_init )
{
yyg->yy_init = 1;
#ifdef YY_USER_INIT
YY_USER_INIT;
#endif
if ( ! yyg->yy_start )
yyg->yy_start = 1; /* first start state */
if ( ! yyin )
yyin = stdin;
if ( ! yyout )
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
mdlensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
mdl_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
}
mdl_load_buffer_state(yyscanner );
}
{
#line 77 "/home/jczech/mcell/build/deps/mdllex.l"
#line 2060 "/home/jczech/mcell/build/deps/mdllex.c"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
yy_cp = yyg->yy_c_buf_p;
/* Support of yytext. */
*yy_cp = yyg->yy_hold_char;
/* yy_bp points to the position in yy_ch_buf of the start of
* the current run.
*/
yy_bp = yy_cp;
yy_current_state = yyg->yy_start;
yy_match:
do
{
YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
yyg->yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 2301 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 2440 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
if ( yy_act == 0 )
{ /* have to back up */
yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
yy_act = yy_accept[yy_current_state];
}
YY_DO_BEFORE_ACTION;
do_action: /* This label is used only to access EOF actions. */
switch ( yy_act )
{ /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yyg->yy_hold_char;
yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
goto yy_find_action;
case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
#line 79 "/home/jczech/mcell/build/deps/mdllex.l"
{ parse_state->line_num[parse_state->include_stack_ptr - 1] ++; }
YY_BREAK
case 2:
YY_RULE_SETUP
#line 81 "/home/jczech/mcell/build/deps/mdllex.l"
{
parse_state->comment_started = parse_state->line_num[parse_state->include_stack_ptr - 1];
yy_push_state(IN_COMMENT, yyscanner);
}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 86 "/home/jczech/mcell/build/deps/mdllex.l"
{ }
YY_BREAK
case 4:
YY_RULE_SETUP
#line 87 "/home/jczech/mcell/build/deps/mdllex.l"
{ }
YY_BREAK
case 5:
YY_RULE_SETUP
#line 88 "/home/jczech/mcell/build/deps/mdllex.l"
{ }
YY_BREAK
case 6:
YY_RULE_SETUP
#line 89 "/home/jczech/mcell/build/deps/mdllex.l"
{ yy_push_state(YY_START, yyscanner); }
YY_BREAK
case 7:
YY_RULE_SETUP
#line 90 "/home/jczech/mcell/build/deps/mdllex.l"
{ yy_pop_state(yyscanner); }
YY_BREAK
case YY_STATE_EOF(IN_COMMENT):
#line 91 "/home/jczech/mcell/build/deps/mdllex.l"
{
parse_state->line_num[parse_state->include_stack_ptr - 1]--;
mdlerror_fmt(parse_state,
"Unterminated comment started on line %d",
parse_state->comment_started);
return 1;
}
YY_BREAK
case 8:
YY_RULE_SETUP
#line 100 "/home/jczech/mcell/build/deps/mdllex.l"
{ return FORMAT; }
YY_BREAK
case 9:
YY_RULE_SETUP
#line 101 "/home/jczech/mcell/build/deps/mdllex.l"
;
YY_BREAK
case 10:
YY_RULE_SETUP
#line 102 "/home/jczech/mcell/build/deps/mdllex.l"
{ return EQUAL; }
YY_BREAK
case 11:
YY_RULE_SETUP
#line 103 "/home/jczech/mcell/build/deps/mdllex.l"
{ return NOT_EQUAL; }
YY_BREAK
case 12:
YY_RULE_SETUP
#line 104 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ABS);}
YY_BREAK
case 13:
YY_RULE_SETUP
#line 105 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ABSORPTIVE);}
YY_BREAK
case 14:
YY_RULE_SETUP
#line 106 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ACCURATE_3D_REACTIONS);}
YY_BREAK
case 15:
YY_RULE_SETUP
#line 107 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ACOS);}
YY_BREAK
case 16:
YY_RULE_SETUP
#line 108 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_DATA);}
YY_BREAK
case 17:
YY_RULE_SETUP
#line 109 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_CROSSINGS);}
YY_BREAK
case 18:
YY_RULE_SETUP
#line 110 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_ELEMENTS);}
YY_BREAK
case 19:
YY_RULE_SETUP
#line 111 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_ENCLOSED);}
YY_BREAK
case 20:
YY_RULE_SETUP
#line 112 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_HITS);}
YY_BREAK
case 21:
YY_RULE_SETUP
#line 113 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_ITERATIONS);}
YY_BREAK
case 22:
YY_RULE_SETUP
#line 114 "/home/jczech/mcell/build/deps/mdllex.l"
{return (ALL_MOLECULES);}
YY_BREAK
case 23:
YY_RULE_SETUP
#line 115 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_NOTIFICATIONS);}
YY_BREAK
case 24:
YY_RULE_SETUP
#line 116 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_TIMES);}
YY_BREAK
case 25:
YY_RULE_SETUP
#line 117 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ALL_WARNINGS);}
YY_BREAK
case 26:
YY_RULE_SETUP
#line 118 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ASCII);}
YY_BREAK
case 27:
YY_RULE_SETUP
#line 119 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ASIN);}
YY_BREAK
case 28:
YY_RULE_SETUP
#line 120 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ASPECT_RATIO);}
YY_BREAK
case 29:
YY_RULE_SETUP
#line 121 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ATAN);}
YY_BREAK
case 30:
YY_RULE_SETUP
#line 122 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BACK);}
YY_BREAK
case 31:
YY_RULE_SETUP
#line 123 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BACK_CROSSINGS);}
YY_BREAK
case 32:
YY_RULE_SETUP
#line 124 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BACK_HITS);}
YY_BREAK
case 33:
YY_RULE_SETUP
#line 125 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BOTTOM);}
YY_BREAK
case 34:
YY_RULE_SETUP
#line 126 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BOX);}
YY_BREAK
case 35:
YY_RULE_SETUP
#line 127 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BOX_TRIANGULATION_REPORT);}
YY_BREAK
case 36:
YY_RULE_SETUP
#line 128 "/home/jczech/mcell/build/deps/mdllex.l"
{return(BRIEF);}
YY_BREAK
case 37:
YY_RULE_SETUP
#line 129 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CEIL);}
YY_BREAK
case 38:
YY_RULE_SETUP
#line 130 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CELLBLENDER);}
YY_BREAK
case 39:
YY_RULE_SETUP
#line 131 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CENTER_MOLECULES_ON_GRID);}
YY_BREAK
case 40:
YY_RULE_SETUP
#line 132 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CHECKPOINT_INFILE);}
YY_BREAK
case 41:
YY_RULE_SETUP
#line 133 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CHECKPOINT_OUTFILE);}
YY_BREAK
case 42:
YY_RULE_SETUP
#line 134 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CHECKPOINT_ITERATIONS);}
YY_BREAK
case 43:
YY_RULE_SETUP
#line 135 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CHECKPOINT_REALTIME);}
YY_BREAK
case 44:
YY_RULE_SETUP
#line 136 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CHECKPOINT_REPORT);}
YY_BREAK
case 45:
#line 138 "/home/jczech/mcell/build/deps/mdllex.l"
case 46:
#line 139 "/home/jczech/mcell/build/deps/mdllex.l"
case 47:
YY_RULE_SETUP
#line 139 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CLAMP_CONCENTRATION);}
YY_BREAK
case 48:
YY_RULE_SETUP
#line 140 "/home/jczech/mcell/build/deps/mdllex.l"
{return CLOSE_PARTITION_SPACING;}
YY_BREAK
case 49:
YY_RULE_SETUP
#line 141 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CORNERS);}
YY_BREAK
case 50:
YY_RULE_SETUP
#line 142 "/home/jczech/mcell/build/deps/mdllex.l"
{return(COS);}
YY_BREAK
case 51:
#line 144 "/home/jczech/mcell/build/deps/mdllex.l"
case 52:
YY_RULE_SETUP
#line 144 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CONCENTRATION);}
YY_BREAK
case 53:
YY_RULE_SETUP
#line 145 "/home/jczech/mcell/build/deps/mdllex.l"
{return(COUNT);}
YY_BREAK
case 54:
YY_RULE_SETUP
#line 146 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CUBIC);}
YY_BREAK
case 55:
YY_RULE_SETUP
#line 147 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CUBIC_RELEASE_SITE);}
YY_BREAK
case 56:
YY_RULE_SETUP
#line 148 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CUSTOM_SPACE_STEP); }
YY_BREAK
case 57:
YY_RULE_SETUP
#line 149 "/home/jczech/mcell/build/deps/mdllex.l"
{return(CUSTOM_TIME_STEP);}
YY_BREAK
case 58:
#line 151 "/home/jczech/mcell/build/deps/mdllex.l"
case 59:
#line 152 "/home/jczech/mcell/build/deps/mdllex.l"
case 60:
YY_RULE_SETUP
#line 152 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DIFFUSION_CONSTANT_3D);}
YY_BREAK
case 61:
#line 154 "/home/jczech/mcell/build/deps/mdllex.l"
case 62:
YY_RULE_SETUP
#line 154 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DIFFUSION_CONSTANT_2D);}
YY_BREAK
case 63:
YY_RULE_SETUP
#line 155 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_MOLECULE);}
YY_BREAK
case 64:
YY_RULE_SETUP
#line 156 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_MOLECULES);}
YY_BREAK
case 65:
YY_RULE_SETUP
#line 157 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_REACTIONS);}
YY_BREAK
case 66:
YY_RULE_SETUP
#line 158 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_RELEASE_PATTERN);}
YY_BREAK
case 67:
YY_RULE_SETUP
#line 159 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_SURFACE_REGIONS);}
YY_BREAK
case 68:
YY_RULE_SETUP
#line 160 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_SURFACE_CLASS);}
YY_BREAK
case 69:
YY_RULE_SETUP
#line 161 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEFINE_SURFACE_CLASSES);}
YY_BREAK
case 70:
YY_RULE_SETUP
#line 162 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DEGENERATE_POLYGONS);}
YY_BREAK
case 71:
YY_RULE_SETUP
#line 163 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DELAY);}
YY_BREAK
case 72:
YY_RULE_SETUP
#line 164 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DENSITY);}
YY_BREAK
case 73:
YY_RULE_SETUP
#line 165 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DIFFUSION_CONSTANT_REPORT);}
YY_BREAK
case 74:
YY_RULE_SETUP
#line 166 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DYNAMIC_GEOMETRY);}
YY_BREAK
case 75:
YY_RULE_SETUP
#line 167 "/home/jczech/mcell/build/deps/mdllex.l"
{return(DYNAMIC_GEOMETRY_MOLECULE_PLACEMENT);}
YY_BREAK
case 76:
#line 169 "/home/jczech/mcell/build/deps/mdllex.l"
case 77:
YY_RULE_SETUP
#line 169 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EFFECTOR_GRID_DENSITY);}
YY_BREAK
case 78:
YY_RULE_SETUP
#line 170 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ELEMENT_CONNECTIONS);}
YY_BREAK
case 79:
YY_RULE_SETUP
#line 171 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INCLUDE_ELEMENTS);}
YY_BREAK
case 80:
YY_RULE_SETUP
#line 172 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ELLIPTIC);}
YY_BREAK
case 81:
YY_RULE_SETUP
#line 173 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ELLIPTIC_RELEASE_SITE);}
YY_BREAK
case 82:
YY_RULE_SETUP
#line 174 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ERROR);}
YY_BREAK
case 83:
#line 176 "/home/jczech/mcell/build/deps/mdllex.l"
case 84:
YY_RULE_SETUP
#line 176 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ESTIMATE_CONCENTRATION);}
YY_BREAK
case 85:
YY_RULE_SETUP
#line 177 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXCLUDE_ELEMENTS);}
YY_BREAK
case 86:
YY_RULE_SETUP
#line 178 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXCLUDE_PATCH);}
YY_BREAK
case 87:
YY_RULE_SETUP
#line 179 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXCLUDE_REGION);}
YY_BREAK
case 88:
YY_RULE_SETUP
#line 180 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXIT);}
YY_BREAK
case 89:
YY_RULE_SETUP
#line 181 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXP);}
YY_BREAK
case 90:
YY_RULE_SETUP
#line 182 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXPRESSION);}
YY_BREAK
case 91:
YY_RULE_SETUP
#line 183 "/home/jczech/mcell/build/deps/mdllex.l"
{return(EXTERN);}
YY_BREAK
case 92:
YY_RULE_SETUP
#line 184 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FALSE);}
YY_BREAK
case 93:
YY_RULE_SETUP
#line 185 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FILENAME);}
YY_BREAK
case 94:
YY_RULE_SETUP
#line 186 "/home/jczech/mcell/build/deps/mdllex.l"
{return FILENAME_PREFIX;}
YY_BREAK
case 95:
YY_RULE_SETUP
#line 187 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FILE_OUTPUT_REPORT);}
YY_BREAK
case 96:
YY_RULE_SETUP
#line 188 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FINAL_SUMMARY);}
YY_BREAK
case 97:
YY_RULE_SETUP
#line 189 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FLOOR);}
YY_BREAK
case 98:
YY_RULE_SETUP
#line 190 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FRONT);}
YY_BREAK
case 99:
YY_RULE_SETUP
#line 191 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FRONT_CROSSINGS);}
YY_BREAK
case 100:
YY_RULE_SETUP
#line 192 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FRONT_HITS);}
YY_BREAK
case 101:
YY_RULE_SETUP
#line 193 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FULLY_RANDOM);}
YY_BREAK
case 102:
YY_RULE_SETUP
#line 194 "/home/jczech/mcell/build/deps/mdllex.l"
{return(GAUSSIAN_RELEASE_NUMBER);}
YY_BREAK
case 103:
YY_RULE_SETUP
#line 195 "/home/jczech/mcell/build/deps/mdllex.l"
{return(GEOMETRY);}
YY_BREAK
case 104:
YY_RULE_SETUP
#line 196 "/home/jczech/mcell/build/deps/mdllex.l"
{return(GRAPH_PATTERN);}
YY_BREAK
case 105:
YY_RULE_SETUP
#line 197 "/home/jczech/mcell/build/deps/mdllex.l"
{return(HEADER);}
YY_BREAK
case 106:
YY_RULE_SETUP
#line 198 "/home/jczech/mcell/build/deps/mdllex.l"
{return(HIGH_PROBABILITY_THRESHOLD);}
YY_BREAK
case 107:
YY_RULE_SETUP
#line 199 "/home/jczech/mcell/build/deps/mdllex.l"
{return(HIGH_REACTION_PROBABILITY);}
YY_BREAK
case 108:
#line 201 "/home/jczech/mcell/build/deps/mdllex.l"
case 109:
YY_RULE_SETUP
#line 201 "/home/jczech/mcell/build/deps/mdllex.l"
{return(IGNORED);}
YY_BREAK
case 110:
YY_RULE_SETUP
#line 202 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INCLUDE_ELEMENTS);}
YY_BREAK
case 111:
YY_RULE_SETUP
#line 203 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INCLUDE_FILE);}
YY_BREAK
case 112:
YY_RULE_SETUP
#line 204 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INCLUDE_PATCH);}
YY_BREAK
case 113:
YY_RULE_SETUP
#line 205 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INCLUDE_REGION);}
YY_BREAK
case 114:
YY_RULE_SETUP
#line 206 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INPUT_FILE);}
YY_BREAK
case 115:
YY_RULE_SETUP
#line 207 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INSTANTIATE);}
YY_BREAK
case 116:
YY_RULE_SETUP
#line 208 "/home/jczech/mcell/build/deps/mdllex.l"
{return(INTERACTION_RADIUS);}
YY_BREAK
case 117:
YY_RULE_SETUP
#line 209 "/home/jczech/mcell/build/deps/mdllex.l"
{ return INVALID_OUTPUT_STEP_TIME; }
YY_BREAK
case 118:
YY_RULE_SETUP
#line 210 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ITERATIONS);}
YY_BREAK
case 119:
YY_RULE_SETUP
#line 211 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ITERATION_LIST);}
YY_BREAK
case 120:
YY_RULE_SETUP
#line 212 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ITERATION_NUMBERS);}
YY_BREAK
case 121:
YY_RULE_SETUP
#line 213 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ITERATION_REPORT);}
YY_BREAK
case 122:
YY_RULE_SETUP
#line 214 "/home/jczech/mcell/build/deps/mdllex.l"
{return(KEEP_CHECKPOINT_FILES);}
YY_BREAK
case 123:
YY_RULE_SETUP
#line 215 "/home/jczech/mcell/build/deps/mdllex.l"
{ return LARGE_MOLECULAR_DISPLACEMENT; }
YY_BREAK
case 124:
YY_RULE_SETUP
#line 216 "/home/jczech/mcell/build/deps/mdllex.l"
{ return ADD_REMOVE_MESH; }
YY_BREAK
case 125:
YY_RULE_SETUP
#line 217 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LEFT);}
YY_BREAK
case 126:
YY_RULE_SETUP
#line 218 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LIFETIME_TOO_SHORT);}
YY_BREAK
case 127:
YY_RULE_SETUP
#line 219 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LIFETIME_THRESHOLD);}
YY_BREAK
case 128:
YY_RULE_SETUP
#line 220 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LIST);}
YY_BREAK
case 129:
YY_RULE_SETUP
#line 221 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LOCATION);}
YY_BREAK
case 130:
YY_RULE_SETUP
#line 222 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LOG10);}
YY_BREAK
case 131:
YY_RULE_SETUP
#line 223 "/home/jczech/mcell/build/deps/mdllex.l"
{return(LOG);}
YY_BREAK
case 132:
YY_RULE_SETUP
#line 224 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MAX_TOK);}
YY_BREAK
case 133:
YY_RULE_SETUP
#line 225 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MAXIMUM_STEP_LENGTH);}
YY_BREAK
case 134:
YY_RULE_SETUP
#line 226 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MEAN_DIAMETER);}
YY_BREAK
case 135:
YY_RULE_SETUP
#line 227 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MEAN_NUMBER);}
YY_BREAK
case 136:
YY_RULE_SETUP
#line 228 "/home/jczech/mcell/build/deps/mdllex.l"
{ return MEMORY_PARTITION_X; }
YY_BREAK
case 137:
YY_RULE_SETUP
#line 229 "/home/jczech/mcell/build/deps/mdllex.l"
{ return MEMORY_PARTITION_Y; }
YY_BREAK
case 138:
YY_RULE_SETUP
#line 230 "/home/jczech/mcell/build/deps/mdllex.l"
{ return MEMORY_PARTITION_Z; }
YY_BREAK
case 139:
YY_RULE_SETUP
#line 231 "/home/jczech/mcell/build/deps/mdllex.l"
{ return MEMORY_PARTITION_POOL; }
YY_BREAK
case 140:
YY_RULE_SETUP
#line 232 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MICROSCOPIC_REVERSIBILITY);}
YY_BREAK
case 141:
YY_RULE_SETUP
#line 233 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MIN_TOK);}
YY_BREAK
case 142:
YY_RULE_SETUP
#line 234 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MISSED_REACTIONS);}
YY_BREAK
case 143:
YY_RULE_SETUP
#line 235 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MISSED_REACTION_THRESHOLD);}
YY_BREAK
case 144:
YY_RULE_SETUP
#line 236 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MISSING_SURFACE_ORIENTATION);}
YY_BREAK
case 145:
YY_RULE_SETUP
#line 237 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOD);}
YY_BREAK
case 146:
YY_RULE_SETUP
#line 238 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MODE);}
YY_BREAK
case 147:
YY_RULE_SETUP
#line 239 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MODIFY_SURFACE_REGIONS);}
YY_BREAK
case 148:
YY_RULE_SETUP
#line 240 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOLECULE_DENSITY);}
YY_BREAK
case 149:
YY_RULE_SETUP
#line 241 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOLECULE_NUMBER);}
YY_BREAK
case 150:
#line 243 "/home/jczech/mcell/build/deps/mdllex.l"
case 151:
YY_RULE_SETUP
#line 243 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOLECULE);}
YY_BREAK
case 152:
YY_RULE_SETUP
#line 244 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOLECULES);}
YY_BREAK
case 153:
YY_RULE_SETUP
#line 245 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOLECULE_COLLISION_REPORT);}
YY_BREAK
case 154:
#line 247 "/home/jczech/mcell/build/deps/mdllex.l"
case 155:
YY_RULE_SETUP
#line 247 "/home/jczech/mcell/build/deps/mdllex.l"
{return(MOLECULE_POSITIONS);}
YY_BREAK
case 156:
YY_RULE_SETUP
#line 248 "/home/jczech/mcell/build/deps/mdllex.l"
{ return MOLECULE_PLACEMENT_FAILURE; }
YY_BREAK
case 157:
YY_RULE_SETUP
#line 249 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NAME_LIST);}
YY_BREAK
case 158:
YY_RULE_SETUP
#line 250 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NEAREST_POINT);}
YY_BREAK
case 159:
YY_RULE_SETUP
#line 251 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NEAREST_TRIANGLE);}
YY_BREAK
case 160:
YY_RULE_SETUP
#line 252 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NEGATIVE_DIFFUSION_CONSTANT);}
YY_BREAK
case 161:
YY_RULE_SETUP
#line 253 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NEGATIVE_REACTION_RATE);}
YY_BREAK
case 162:
YY_RULE_SETUP
#line 254 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NO);}
YY_BREAK
case 163:
YY_RULE_SETUP
#line 255 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NOEXIT);}
YY_BREAK
case 164:
YY_RULE_SETUP
#line 256 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NONE);}
YY_BREAK
case 165:
YY_RULE_SETUP
#line 257 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NOTIFICATIONS);}
YY_BREAK
case 166:
YY_RULE_SETUP
#line 258 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NO_SPECIES);}
YY_BREAK
case 167:
YY_RULE_SETUP
#line 259 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NUMBER_OF_TRAINS);}
YY_BREAK
case 168:
YY_RULE_SETUP
#line 260 "/home/jczech/mcell/build/deps/mdllex.l"
{return(NUMBER_TO_RELEASE);}
YY_BREAK
case 169:
YY_RULE_SETUP
#line 261 "/home/jczech/mcell/build/deps/mdllex.l"
{return(OBJECT);}
YY_BREAK
case 170:
YY_RULE_SETUP
#line 262 "/home/jczech/mcell/build/deps/mdllex.l"
{return(OFF);}
YY_BREAK
case 171:
YY_RULE_SETUP
#line 263 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ON);}
YY_BREAK
case 172:
YY_RULE_SETUP
#line 264 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ORIENTATIONS);}
YY_BREAK
case 173:
YY_RULE_SETUP
#line 265 "/home/jczech/mcell/build/deps/mdllex.l"
{return(OUTPUT_BUFFER_SIZE);}
YY_BREAK
case 174:
YY_RULE_SETUP
#line 266 "/home/jczech/mcell/build/deps/mdllex.l"
{return(OVERWRITTEN_OUTPUT_FILE);}
YY_BREAK
case 175:
YY_RULE_SETUP
#line 267 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PARTITION_LOCATION_REPORT);}
YY_BREAK
case 176:
YY_RULE_SETUP
#line 268 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PARTITION_X);}
YY_BREAK
case 177:
YY_RULE_SETUP
#line 269 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PARTITION_Y);}
YY_BREAK
case 178:
YY_RULE_SETUP
#line 270 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PARTITION_Z);}
YY_BREAK
case 179:
YY_RULE_SETUP
#line 271 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PERIODIC_BOX_INITIAL);}
YY_BREAK
case 180:
YY_RULE_SETUP
#line 272 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PERIODIC_BOX);}
YY_BREAK
case 181:
YY_RULE_SETUP
#line 273 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PERIODIC_X);}
YY_BREAK
case 182:
YY_RULE_SETUP
#line 274 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PERIODIC_Y);}
YY_BREAK
case 183:
YY_RULE_SETUP
#line 275 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PERIODIC_Z);}
YY_BREAK
case 184:
YY_RULE_SETUP
#line 276 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PERIODIC_TRADITIONAL);}
YY_BREAK
case 185:
YY_RULE_SETUP
#line 277 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PI_TOK);}
YY_BREAK
case 186:
YY_RULE_SETUP
#line 278 "/home/jczech/mcell/build/deps/mdllex.l"
{return(POLYGON_LIST);}
YY_BREAK
case 187:
YY_RULE_SETUP
#line 279 "/home/jczech/mcell/build/deps/mdllex.l"
{return(POSITIONS);}
YY_BREAK
case 188:
YY_RULE_SETUP
#line 280 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PROBABILITY_REPORT);}
YY_BREAK
case 189:
YY_RULE_SETUP
#line 281 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PROBABILITY_REPORT_THRESHOLD);}
YY_BREAK
case 190:
YY_RULE_SETUP
#line 282 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PROGRESS_REPORT);}
YY_BREAK
case 191:
YY_RULE_SETUP
#line 283 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RADIAL_DIRECTIONS);}
YY_BREAK
case 192:
YY_RULE_SETUP
#line 284 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RADIAL_SUBDIVISIONS);}
YY_BREAK
case 193:
YY_RULE_SETUP
#line 285 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RAND_UNIFORM);}
YY_BREAK
case 194:
YY_RULE_SETUP
#line 286 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RAND_GAUSSIAN);}
YY_BREAK
case 195:
YY_RULE_SETUP
#line 287 "/home/jczech/mcell/build/deps/mdllex.l"
{return(REACTION_DATA_OUTPUT);}
YY_BREAK
case 196:
YY_RULE_SETUP
#line 288 "/home/jczech/mcell/build/deps/mdllex.l"
{ return REACTION_OUTPUT_REPORT; }
YY_BREAK
case 197:
YY_RULE_SETUP
#line 289 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RECTANGULAR_TOKEN);}
YY_BREAK
case 198:
YY_RULE_SETUP
#line 290 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RECTANGULAR_RELEASE_SITE); }
YY_BREAK
case 199:
YY_RULE_SETUP
#line 291 "/home/jczech/mcell/build/deps/mdllex.l"
{return(REFLECTIVE);}
YY_BREAK
case 200:
YY_RULE_SETUP
#line 292 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RELEASE_EVENT_REPORT);}
YY_BREAK
case 201:
YY_RULE_SETUP
#line 293 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RELEASE_INTERVAL);}
YY_BREAK
case 202:
YY_RULE_SETUP
#line 294 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RELEASE_PATTERN);}
YY_BREAK
case 203:
YY_RULE_SETUP
#line 295 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RELEASE_PROBABILITY);}
YY_BREAK
case 204:
YY_RULE_SETUP
#line 296 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RELEASE_SITE);}
YY_BREAK
case 205:
YY_RULE_SETUP
#line 297 "/home/jczech/mcell/build/deps/mdllex.l"
{return(REMOVE_ELEMENTS);}
YY_BREAK
case 206:
YY_RULE_SETUP
#line 298 "/home/jczech/mcell/build/deps/mdllex.l"
{return(RIGHT);}
YY_BREAK
case 207:
YY_RULE_SETUP
#line 299 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ROTATE);}
YY_BREAK
case 208:
YY_RULE_SETUP
#line 300 "/home/jczech/mcell/build/deps/mdllex.l"
{return(ROUND_OFF);}
YY_BREAK
case 209:
YY_RULE_SETUP
#line 301 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SCALE);}
YY_BREAK
case 210:
YY_RULE_SETUP
#line 302 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SEED);}
YY_BREAK
case 211:
YY_RULE_SETUP
#line 303 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SHAPE);}
YY_BREAK
case 212:
YY_RULE_SETUP
#line 304 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SHOW_EXACT_TIME);}
YY_BREAK
case 213:
YY_RULE_SETUP
#line 305 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SIN);}
YY_BREAK
case 214:
YY_RULE_SETUP
#line 306 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SITE_DIAMETER);}
YY_BREAK
case 215:
YY_RULE_SETUP
#line 307 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SITE_RADIUS);}
YY_BREAK
case 216:
YY_RULE_SETUP
#line 308 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SPACE_STEP);}
YY_BREAK
case 217:
YY_RULE_SETUP
#line 309 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SPHERICAL);}
YY_BREAK
case 218:
YY_RULE_SETUP
#line 310 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SPHERICAL_RELEASE_SITE);}
YY_BREAK
case 219:
YY_RULE_SETUP
#line 311 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SPHERICAL_SHELL);}
YY_BREAK
case 220:
YY_RULE_SETUP
#line 312 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SPHERICAL_SHELL_SITE); }
YY_BREAK
case 221:
YY_RULE_SETUP
#line 313 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SQRT);}
YY_BREAK
case 222:
YY_RULE_SETUP
#line 314 "/home/jczech/mcell/build/deps/mdllex.l"
{return(STANDARD_DEVIATION);}
YY_BREAK
case 223:
YY_RULE_SETUP
#line 315 "/home/jczech/mcell/build/deps/mdllex.l"
{return(STEP);}
YY_BREAK
case 224:
YY_RULE_SETUP
#line 316 "/home/jczech/mcell/build/deps/mdllex.l"
{return(STRING_TO_NUM);}
YY_BREAK
case 225:
YY_RULE_SETUP
#line 317 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SUMMATION_OPERATOR);}
YY_BREAK
case 226:
YY_RULE_SETUP
#line 318 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SURFACE_CLASS);}
YY_BREAK
case 227:
YY_RULE_SETUP
#line 319 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SURFACE_ONLY);}
YY_BREAK
case 228:
YY_RULE_SETUP
#line 320 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TAN);}
YY_BREAK
case 229:
YY_RULE_SETUP
#line 321 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TARGET_ONLY);}
YY_BREAK
case 230:
YY_RULE_SETUP
#line 322 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TET_ELEMENT_CONNECTIONS);}
YY_BREAK
case 231:
YY_RULE_SETUP
#line 323 "/home/jczech/mcell/build/deps/mdllex.l"
{return THROUGHPUT_REPORT;}
YY_BREAK
case 232:
YY_RULE_SETUP
#line 324 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TIME_LIST);}
YY_BREAK
case 233:
YY_RULE_SETUP
#line 325 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TIME_POINTS);}
YY_BREAK
case 234:
YY_RULE_SETUP
#line 326 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TIME_STEP);}
YY_BREAK
case 235:
YY_RULE_SETUP
#line 327 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TIME_STEP_MAX);}
YY_BREAK
case 236:
YY_RULE_SETUP
#line 328 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TO);}
YY_BREAK
case 237:
YY_RULE_SETUP
#line 329 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TOP);}
YY_BREAK
case 238:
YY_RULE_SETUP
#line 330 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TRAIN_DURATION);}
YY_BREAK
case 239:
YY_RULE_SETUP
#line 331 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TRAIN_INTERVAL);}
YY_BREAK
case 240:
YY_RULE_SETUP
#line 332 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TRANSLATE);}
YY_BREAK
case 241:
YY_RULE_SETUP
#line 333 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TRANSPARENT);}
YY_BREAK
case 242:
YY_RULE_SETUP
#line 334 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TRIGGER);}
YY_BREAK
case 243:
YY_RULE_SETUP
#line 335 "/home/jczech/mcell/build/deps/mdllex.l"
{return(TRUE);}
YY_BREAK
case 244:
YY_RULE_SETUP
#line 336 "/home/jczech/mcell/build/deps/mdllex.l"
{return(UNLIMITED);}
YY_BREAK
case 245:
YY_RULE_SETUP
#line 337 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VACANCY_SEARCH_DISTANCE);}
YY_BREAK
case 246:
YY_RULE_SETUP
#line 338 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VARYING_PROBABILITY_REPORT);}
YY_BREAK
case 247:
YY_RULE_SETUP
#line 339 "/home/jczech/mcell/build/deps/mdllex.l"
{return(USELESS_VOLUME_ORIENTATION); }
YY_BREAK
case 248:
YY_RULE_SETUP
#line 340 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VERTEX_LIST);}
YY_BREAK
case 249:
YY_RULE_SETUP
#line 341 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VIZ_OUTPUT);}
YY_BREAK
case 250:
YY_RULE_SETUP
#line 342 "/home/jczech/mcell/build/deps/mdllex.l"
{ return VIZ_OUTPUT_REPORT; }
YY_BREAK
case 251:
YY_RULE_SETUP
#line 343 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VIZ_VALUE);}
YY_BREAK
case 252:
YY_RULE_SETUP
#line 344 "/home/jczech/mcell/build/deps/mdllex.l"
{return VOLUME_DATA_OUTPUT; }
YY_BREAK
case 253:
YY_RULE_SETUP
#line 345 "/home/jczech/mcell/build/deps/mdllex.l"
{ return VOLUME_OUTPUT_REPORT; }
YY_BREAK
case 254:
YY_RULE_SETUP
#line 346 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VOLUME_DEPENDENT_RELEASE_NUMBER);}
YY_BREAK
case 255:
YY_RULE_SETUP
#line 347 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VOLUME_ONLY);}
YY_BREAK
case 256:
YY_RULE_SETUP
#line 348 "/home/jczech/mcell/build/deps/mdllex.l"
{return VOXEL_COUNT; }
YY_BREAK
case 257:
YY_RULE_SETUP
#line 349 "/home/jczech/mcell/build/deps/mdllex.l"
{return(VOXEL_LIST);}
YY_BREAK
case 258:
YY_RULE_SETUP
#line 350 "/home/jczech/mcell/build/deps/mdllex.l"
{return VOXEL_SIZE; }
YY_BREAK
case 259:
YY_RULE_SETUP
#line 351 "/home/jczech/mcell/build/deps/mdllex.l"
{return(WARNING);}
YY_BREAK
case 260:
YY_RULE_SETUP
#line 352 "/home/jczech/mcell/build/deps/mdllex.l"
{return(WARNINGS);}
YY_BREAK
case 261:
YY_RULE_SETUP
#line 353 "/home/jczech/mcell/build/deps/mdllex.l"
{return(WORLD);}
YY_BREAK
case 262:
YY_RULE_SETUP
#line 354 "/home/jczech/mcell/build/deps/mdllex.l"
{return(YES);}
YY_BREAK
case 263:
YY_RULE_SETUP
#line 355 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PRINTF);}
YY_BREAK
case 264:
YY_RULE_SETUP
#line 356 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FPRINTF);}
YY_BREAK
case 265:
YY_RULE_SETUP
#line 357 "/home/jczech/mcell/build/deps/mdllex.l"
{return(SPRINTF);}
YY_BREAK
case 266:
YY_RULE_SETUP
#line 358 "/home/jczech/mcell/build/deps/mdllex.l"
{return(PRINT_TIME);}
YY_BREAK
case 267:
YY_RULE_SETUP
#line 359 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FPRINT_TIME);}
YY_BREAK
case 268:
YY_RULE_SETUP
#line 360 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FOPEN);}
YY_BREAK
case 269:
YY_RULE_SETUP
#line 361 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FOPEN);}
YY_BREAK
case 270:
YY_RULE_SETUP
#line 362 "/home/jczech/mcell/build/deps/mdllex.l"
{return(FCLOSE);}
YY_BREAK
case 271:
YY_RULE_SETUP
#line 363 "/home/jczech/mcell/build/deps/mdllex.l"
{sscanf((const char *)yytext,"%lf",&yylval->dbl); return REAL;}
YY_BREAK
case 272:
YY_RULE_SETUP
#line 364 "/home/jczech/mcell/build/deps/mdllex.l"
{sscanf((const char *)yytext,"%lld",&yylval->llival); return LLINTEGER;}
YY_BREAK
case 273:
YY_RULE_SETUP
#line 365 "/home/jczech/mcell/build/deps/mdllex.l"
{
yylval->str = CHECKED_STRDUP(yytext, "string token");
return VAR;
}
YY_BREAK
case 274:
/* rule 274 can match eol */
YY_RULE_SETUP
#line 369 "/home/jczech/mcell/build/deps/mdllex.l"
{
yylval->str = CHECKED_STRDUP(yytext, "string token");
return STR_VALUE;
}
YY_BREAK
case 275:
YY_RULE_SETUP
#line 374 "/home/jczech/mcell/build/deps/mdllex.l"
{return(yytext[0]);}
YY_BREAK
case 276:
YY_RULE_SETUP
#line 375 "/home/jczech/mcell/build/deps/mdllex.l"
;
YY_BREAK
case 277:
/* rule 277 can match eol */
YY_RULE_SETUP
#line 376 "/home/jczech/mcell/build/deps/mdllex.l"
{parse_state->line_num[parse_state->include_stack_ptr - 1] += yyleng; }
YY_BREAK
case YY_STATE_EOF(INITIAL):
#line 377 "/home/jczech/mcell/build/deps/mdllex.l"
{ yyterminate(); }
YY_BREAK
case 278:
YY_RULE_SETUP
#line 378 "/home/jczech/mcell/build/deps/mdllex.l"
ECHO;
YY_BREAK
#line 3502 "/home/jczech/mcell/build/deps/mdllex.c"
case YY_END_OF_BUFFER:
{
/* Amount of text matched not including the EOB char. */
int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
/* Undo the effects of YY_DO_BEFORE_ACTION. */
*yy_cp = yyg->yy_hold_char;
YY_RESTORE_YY_MORE_OFFSET
if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
{
/* We're scanning a new file or input source. It's
* possible that this happened because the user
* just pointed yyin at a new source and called
* mdllex(). If so, then we have to assure
* consistency between YY_CURRENT_BUFFER and our
* globals. Here is the right place to do so, because
* this is the first action (other than possibly a
* back-up) that will match for the new input source.
*/
yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
}
/* Note that here we test for yy_c_buf_p "<=" to the position
* of the first EOB in the buffer, since yy_c_buf_p will
* already have been incremented past the NUL character
* (since all states make transitions on EOB to the
* end-of-buffer state). Contrast this with the test
* in input().
*/
if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
{ /* This was really a NUL. */
yy_state_type yy_next_state;
yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state( yyscanner );
/* Okay, we're now positioned to make the NUL
* transition. We couldn't have
* yy_get_previous_state() go ahead and do it
* for us because it doesn't know how to deal
* with the possibility of jamming (and we don't
* want to build jamming into it because then it
* will run more slowly).
*/
yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
if ( yy_next_state )
{
/* Consume the NUL. */
yy_cp = ++yyg->yy_c_buf_p;
yy_current_state = yy_next_state;
goto yy_match;
}
else
{
yy_cp = yyg->yy_c_buf_p;
goto yy_find_action;
}
}
else switch ( yy_get_next_buffer( yyscanner ) )
{
case EOB_ACT_END_OF_FILE:
{
yyg->yy_did_buffer_switch_on_eof = 0;
if ( mdlwrap(yyscanner ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
* yytext, we can now set up
* yy_c_buf_p so that if some total
* hoser (like flex itself) wants to
* call the scanner after we return the
* YY_NULL, it'll still work - another
* YY_NULL will get returned.
*/
yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
yy_act = YY_STATE_EOF(YY_START);
goto do_action;
}
else
{
if ( ! yyg->yy_did_buffer_switch_on_eof )
YY_NEW_FILE;
}
break;
}
case EOB_ACT_CONTINUE_SCAN:
yyg->yy_c_buf_p =
yyg->yytext_ptr + yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state( yyscanner );
yy_cp = yyg->yy_c_buf_p;
yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
goto yy_match;
case EOB_ACT_LAST_MATCH:
yyg->yy_c_buf_p =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
yy_current_state = yy_get_previous_state( yyscanner );
yy_cp = yyg->yy_c_buf_p;
yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
goto yy_find_action;
}
break;
}
default:
YY_FATAL_ERROR(
"fatal flex scanner internal error--no action found" );
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of mdllex */
/* yy_get_next_buffer - try to read in a new buffer
*
* Returns a code representing an action:
* EOB_ACT_LAST_MATCH -
* EOB_ACT_CONTINUE_SCAN - continue scanning from current position
* EOB_ACT_END_OF_FILE - end of file
*/
static int yy_get_next_buffer (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
char *source = yyg->yytext_ptr;
yy_size_t number_to_move, i;
int ret_val;
if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
YY_FATAL_ERROR(
"fatal flex scanner internal error--end of buffer missed" );
if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
{ /* Don't try to fill the buffer, so this is an EOF. */
if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
{
/* We matched a single character, the EOB, so
* treat this as a final EOF.
*/
return EOB_ACT_END_OF_FILE;
}
else
{
/* We matched some text prior to the EOB, first
* process it.
*/
return EOB_ACT_LAST_MATCH;
}
}
/* Try to read more data. */
/* First move last chars to start of buffer. */
number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
/* don't do the read, it's not guaranteed to return an EOF,
* just force an EOF
*/
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
else
{
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset =
(int) (yyg->yy_c_buf_p - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
else
b->yy_buf_size *= 2;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
mdlrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
}
else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR(
"fatal error - scanner input buffer overflow" );
yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
number_to_move - 1;
}
if ( num_to_read > YY_READ_BUF_SIZE )
num_to_read = YY_READ_BUF_SIZE;
/* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
yyg->yy_n_chars, num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
}
if ( yyg->yy_n_chars == 0 )
{
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
mdlrestart(yyin ,yyscanner);
}
else
{
ret_val = EOB_ACT_LAST_MATCH;
YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
YY_BUFFER_EOF_PENDING;
}
}
else
ret_val = EOB_ACT_CONTINUE_SCAN;
if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) mdlrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
}
yyg->yy_n_chars += number_to_move;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
return ret_val;
}
/* yy_get_previous_state - get the state just before the EOB char was reached */
static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
{
yy_state_type yy_current_state;
char *yy_cp;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_current_state = yyg->yy_start;
for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
{
YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
yyg->yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 2301 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
}
return yy_current_state;
}
/* yy_try_NUL_trans - try to make a transition on the NUL character
*
* synopsis
* next_state = yy_try_NUL_trans( current_state );
*/
static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
{
int yy_is_jam;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
char *yy_cp = yyg->yy_c_buf_p;
YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
yyg->yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 2301 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 2300);
(void)yyg;
return yy_is_jam ? 0 : yy_current_state;
}
#ifndef YY_NO_UNPUT
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput (yyscan_t yyscanner)
#else
static int input (yyscan_t yyscanner)
#endif
{
int c;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
*yyg->yy_c_buf_p = yyg->yy_hold_char;
if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
{
/* yy_c_buf_p now points to the character we want to return.
* If this occurs *before* the EOB characters, then it's a
* valid NUL; if not, then we've hit the end of the buffer.
*/
if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
/* This was really a NUL. */
*yyg->yy_c_buf_p = '\0';
else
{ /* need more input */
yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
{
case EOB_ACT_LAST_MATCH:
/* This happens because yy_g_n_b()
* sees that we've accumulated a
* token and flags that we need to
* try matching the token before
* proceeding. But for input(),
* there's no matching to consider.
* So convert the EOB_ACT_LAST_MATCH
* to EOB_ACT_END_OF_FILE.
*/
/* Reset buffer status. */
mdlrestart(yyin ,yyscanner);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
if ( mdlwrap(yyscanner ) )
return EOF;
if ( ! yyg->yy_did_buffer_switch_on_eof )
YY_NEW_FILE;
#ifdef __cplusplus
return yyinput(yyscanner);
#else
return input(yyscanner);
#endif
}
case EOB_ACT_CONTINUE_SCAN:
yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
break;
}
}
}
c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
*yyg->yy_c_buf_p = '\0'; /* preserve yytext */
yyg->yy_hold_char = *++yyg->yy_c_buf_p;
return c;
}
#endif /* ifndef YY_NO_INPUT */
/** Immediately switch to a different input stream.
* @param input_file A readable stream.
* @param yyscanner The scanner object.
* @note This function does not reset the start condition to @c INITIAL .
*/
void mdlrestart (FILE * input_file , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! YY_CURRENT_BUFFER ){
mdlensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
mdl_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
}
mdl_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
mdl_load_buffer_state(yyscanner );
}
/** Switch to a different input buffer.
* @param new_buffer The new input buffer.
* @param yyscanner The scanner object.
*/
void mdl_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
/* TODO. We should be able to replace this entire function body
* with
* mdlpop_buffer_state();
* mdlpush_buffer_state(new_buffer);
*/
mdlensure_buffer_stack (yyscanner);
if ( YY_CURRENT_BUFFER == new_buffer )
return;
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
*yyg->yy_c_buf_p = yyg->yy_hold_char;
YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
mdl_load_buffer_state(yyscanner );
/* We don't actually know whether we did this switch during
* EOF (mdlwrap()) processing, but the only time this flag
* is looked at is after mdlwrap() is called, so it's safe
* to go ahead and always set it.
*/
yyg->yy_did_buffer_switch_on_eof = 1;
}
static void mdl_load_buffer_state (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
yyg->yy_hold_char = *yyg->yy_c_buf_p;
}
/** Allocate and initialize an input buffer state.
* @param file A readable stream.
* @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
* @param yyscanner The scanner object.
* @return the allocated buffer state.
*/
YY_BUFFER_STATE mdl_create_buffer (FILE * file, int size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE) mdlalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in mdl_create_buffer()" );
b->yy_buf_size = (yy_size_t)size;
/* yy_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters.
*/
b->yy_ch_buf = (char *) mdlalloc(b->yy_buf_size + 2 ,yyscanner );
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in mdl_create_buffer()" );
b->yy_is_our_buffer = 1;
mdl_init_buffer(b,file ,yyscanner);
return b;
}
/** Destroy the buffer.
* @param b a buffer created with mdl_create_buffer()
* @param yyscanner The scanner object.
*/
void mdl_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
return;
if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
mdlfree((void *) b->yy_ch_buf ,yyscanner );
mdlfree((void *) b ,yyscanner );
}
/* Initializes or reinitializes a buffer.
* This function is sometimes called more than once on the same buffer,
* such as during a mdlrestart() or at EOF.
*/
static void mdl_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
{
int oerrno = errno;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
mdl_flush_buffer(b ,yyscanner);
b->yy_input_file = file;
b->yy_fill_buffer = 1;
/* If b is the current buffer, then mdl_init_buffer was _probably_
* called from mdlrestart() or through yy_get_next_buffer.
* In that case, we don't want to reset the lineno or column.
*/
if (b != YY_CURRENT_BUFFER){
b->yy_bs_lineno = 1;
b->yy_bs_column = 0;
}
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
errno = oerrno;
}
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
* @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
* @param yyscanner The scanner object.
*/
void mdl_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
return;
b->yy_n_chars = 0;
/* We always need two end-of-buffer characters. The first causes
* a transition to the end-of-buffer state. The second causes
* a jam in that state.
*/
b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
b->yy_buf_pos = &b->yy_ch_buf[0];
b->yy_at_bol = 1;
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
mdl_load_buffer_state(yyscanner );
}
/** Pushes the new state onto the stack. The new state becomes
* the current state. This function will allocate the stack
* if necessary.
* @param new_buffer The new state.
* @param yyscanner The scanner object.
*/
void mdlpush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (new_buffer == NULL)
return;
mdlensure_buffer_stack(yyscanner);
/* This block is copied from mdl_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
*yyg->yy_c_buf_p = yyg->yy_hold_char;
YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
}
/* Only push if top exists. Otherwise, replace top. */
if (YY_CURRENT_BUFFER)
yyg->yy_buffer_stack_top++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
/* copied from mdl_switch_to_buffer. */
mdl_load_buffer_state(yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
/** Removes and deletes the top of the stack, if present.
* The next element becomes the new top.
* @param yyscanner The scanner object.
*/
void mdlpop_buffer_state (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!YY_CURRENT_BUFFER)
return;
mdl_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
YY_CURRENT_BUFFER_LVALUE = NULL;
if (yyg->yy_buffer_stack_top > 0)
--yyg->yy_buffer_stack_top;
if (YY_CURRENT_BUFFER) {
mdl_load_buffer_state(yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
}
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
static void mdlensure_buffer_stack (yyscan_t yyscanner)
{
yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
/* First allocation is just for 2 elements, since we don't know if this
* scanner will even need a stack. We use 2 instead of 1 to avoid an
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
yyg->yy_buffer_stack = (struct yy_buffer_state**)mdlalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
YY_FATAL_ERROR( "out of dynamic memory in mdlensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
yyg->yy_buffer_stack_max = num_to_alloc;
yyg->yy_buffer_stack_top = 0;
return;
}
if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
/* Increase the buffer to prepare for a possible push. */
yy_size_t grow_size = 8 /* arbitrary grow size */;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
yyg->yy_buffer_stack = (struct yy_buffer_state**)mdlrealloc
(yyg->yy_buffer_stack,
num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
YY_FATAL_ERROR( "out of dynamic memory in mdlensure_buffer_stack()" );
/* zero only the new slots.*/
memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
yyg->yy_buffer_stack_max = num_to_alloc;
}
}
/** Setup the input buffer state to scan directly from a user-specified character buffer.
* @param base the character buffer
* @param size the size in bytes of the character buffer
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE mdl_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
if ( size < 2 ||
base[size-2] != YY_END_OF_BUFFER_CHAR ||
base[size-1] != YY_END_OF_BUFFER_CHAR )
/* They forgot to leave room for the EOB's. */
return 0;
b = (YY_BUFFER_STATE) mdlalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in mdl_scan_buffer()" );
b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
b->yy_buf_pos = b->yy_ch_buf = base;
b->yy_is_our_buffer = 0;
b->yy_input_file = 0;
b->yy_n_chars = b->yy_buf_size;
b->yy_is_interactive = 0;
b->yy_at_bol = 1;
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
mdl_switch_to_buffer(b ,yyscanner );
return b;
}
/** Setup the input buffer state to scan a string. The next call to mdllex() will
* scan from a @e copy of @a str.
* @param yystr a NUL-terminated string to scan
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
* @note If you want to scan bytes that may contain NUL values, then use
* mdl_scan_bytes() instead.
*/
YY_BUFFER_STATE mdl_scan_string (yyconst char * yystr , yyscan_t yyscanner)
{
return mdl_scan_bytes(yystr,strlen(yystr) ,yyscanner);
}
/** Setup the input buffer state to scan the given bytes. The next call to mdllex() will
* scan from a @e copy of @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE mdl_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
yy_size_t i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
buf = (char *) mdlalloc(n ,yyscanner );
if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in mdl_scan_bytes()" );
for ( i = 0; i < _yybytes_len; ++i )
buf[i] = yybytes[i];
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
b = mdl_scan_buffer(buf,n ,yyscanner);
if ( ! b )
YY_FATAL_ERROR( "bad buffer in mdl_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
*/
b->yy_is_our_buffer = 1;
return b;
}
static void yy_push_state (int _new_state , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( yyg->yy_start_stack_ptr >= yyg->yy_start_stack_depth )
{
yy_size_t new_size;
yyg->yy_start_stack_depth += YY_START_STACK_INCR;
new_size = yyg->yy_start_stack_depth * sizeof( int );
if ( ! yyg->yy_start_stack )
yyg->yy_start_stack = (int *) mdlalloc(new_size ,yyscanner );
else
yyg->yy_start_stack = (int *) mdlrealloc((void *) yyg->yy_start_stack,new_size ,yyscanner );
if ( ! yyg->yy_start_stack )
YY_FATAL_ERROR( "out of memory expanding start-condition stack" );
}
yyg->yy_start_stack[yyg->yy_start_stack_ptr++] = YY_START;
BEGIN(_new_state);
}
static void yy_pop_state (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( --yyg->yy_start_stack_ptr < 0 )
YY_FATAL_ERROR( "start-condition stack underflow" );
BEGIN(yyg->yy_start_stack[yyg->yy_start_stack_ptr]);
}
#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif
static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
(void) fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
/* Redefine yyless() so it works in section 3 code. */
#undef yyless
#define yyless(n) \
do \
{ \
/* Undo effects of setting up yytext. */ \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
yytext[yyleng] = yyg->yy_hold_char; \
yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
yyg->yy_hold_char = *yyg->yy_c_buf_p; \
*yyg->yy_c_buf_p = '\0'; \
yyleng = yyless_macro_arg; \
} \
while ( 0 )
/* Accessor methods (get/set functions) to struct members. */
/** Get the user-defined data for this scanner.
* @param yyscanner The scanner object.
*/
YY_EXTRA_TYPE mdlget_extra (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyextra;
}
/** Get the current line number.
* @param yyscanner The scanner object.
*/
int mdlget_lineno (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (! YY_CURRENT_BUFFER)
return 0;
return yylineno;
}
/** Get the current column number.
* @param yyscanner The scanner object.
*/
int mdlget_column (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (! YY_CURRENT_BUFFER)
return 0;
return yycolumn;
}
/** Get the input stream.
* @param yyscanner The scanner object.
*/
FILE *mdlget_in (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyin;
}
/** Get the output stream.
* @param yyscanner The scanner object.
*/
FILE *mdlget_out (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyout;
}
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
yy_size_t mdlget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
}
/** Get the current token.
* @param yyscanner The scanner object.
*/
char *mdlget_text (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yytext;
}
/** Set the user-defined data. This data is never touched by the scanner.
* @param user_defined The data to be associated with this scanner.
* @param yyscanner The scanner object.
*/
void mdlset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyextra = user_defined ;
}
/** Set the current line number.
* @param _line_number line number
* @param yyscanner The scanner object.
*/
void mdlset_lineno (int _line_number , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
/* lineno is only valid if an input buffer exists. */
if (! YY_CURRENT_BUFFER )
YY_FATAL_ERROR( "mdlset_lineno called with no buffer" );
yylineno = _line_number;
}
/** Set the current column.
* @param _column_no column number
* @param yyscanner The scanner object.
*/
void mdlset_column (int _column_no , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
/* column is only valid if an input buffer exists. */
if (! YY_CURRENT_BUFFER )
YY_FATAL_ERROR( "mdlset_column called with no buffer" );
yycolumn = _column_no;
}
/** Set the input stream. This does not discard the current
* input buffer.
* @param _in_str A readable stream.
* @param yyscanner The scanner object.
* @see mdl_switch_to_buffer
*/
void mdlset_in (FILE * _in_str , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyin = _in_str ;
}
void mdlset_out (FILE * _out_str , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyout = _out_str ;
}
int mdlget_debug (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yy_flex_debug;
}
void mdlset_debug (int _bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
}
/* Accessor methods for yylval and yylloc */
/* User-visible API */
/* mdllex_init is special because it creates the scanner itself, so it is
* the ONLY reentrant function that doesn't take the scanner as the last argument.
* That's why we explicitly handle the declaration, instead of using our macros.
*/
int mdllex_init(yyscan_t* ptr_yy_globals)
{
if (ptr_yy_globals == NULL){
errno = EINVAL;
return 1;
}
*ptr_yy_globals = (yyscan_t) mdlalloc ( sizeof( struct yyguts_t ), NULL );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
return 1;
}
/* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
return yy_init_globals ( *ptr_yy_globals );
}
/* mdllex_init_extra has the same functionality as mdllex_init, but follows the
* convention of taking the scanner as the last argument. Note however, that
* this is a *pointer* to a scanner, as it will be allocated by this call (and
* is the reason, too, why this function also must handle its own declaration).
* The user defined value in the first argument will be available to mdlalloc in
* the yyextra field.
*/
int mdllex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
{
struct yyguts_t dummy_yyguts;
mdlset_extra (yy_user_defined, &dummy_yyguts);
if (ptr_yy_globals == NULL){
errno = EINVAL;
return 1;
}
*ptr_yy_globals = (yyscan_t) mdlalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
return 1;
}
/* By setting to 0xAA, we expose bugs in
yy_init_globals. Leave at 0x00 for releases. */
memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
mdlset_extra (yy_user_defined, *ptr_yy_globals);
return yy_init_globals ( *ptr_yy_globals );
}
static int yy_init_globals (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
/* Initialization is the same as for the non-reentrant scanner.
* This function is called from mdllex_destroy(), so don't allocate here.
*/
yyg->yy_buffer_stack = 0;
yyg->yy_buffer_stack_top = 0;
yyg->yy_buffer_stack_max = 0;
yyg->yy_c_buf_p = (char *) 0;
yyg->yy_init = 0;
yyg->yy_start = 0;
yyg->yy_start_stack_ptr = 0;
yyg->yy_start_stack_depth = 0;
yyg->yy_start_stack = NULL;
/* Defined in main.c */
#ifdef YY_STDINIT
yyin = stdin;
yyout = stdout;
#else
yyin = (FILE *) 0;
yyout = (FILE *) 0;
#endif
/* For future reference: Set errno on error, since we are called by
* mdllex_init()
*/
return 0;
}
/* mdllex_destroy is for both reentrant and non-reentrant scanners. */
int mdllex_destroy (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
/* Pop the buffer stack, destroying each element. */
while(YY_CURRENT_BUFFER){
mdl_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
YY_CURRENT_BUFFER_LVALUE = NULL;
mdlpop_buffer_state(yyscanner);
}
/* Destroy the stack itself. */
mdlfree(yyg->yy_buffer_stack ,yyscanner);
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
mdlfree(yyg->yy_start_stack ,yyscanner );
yyg->yy_start_stack = NULL;
/* Reset the globals. This is important in a non-reentrant scanner so the next time
* mdllex() is called, initialization will occur. */
yy_init_globals( yyscanner);
/* Destroy the main struct (reentrant only). */
mdlfree ( yyscanner , yyscanner );
yyscanner = NULL;
return 0;
}
/*
* Internal utility routines.
*/
#ifndef yytext_ptr
static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
int i;
for ( i = 0; i < n; ++i )
s1[i] = s2[i];
}
#endif
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
{
int n;
for ( n = 0; s[n]; ++n )
;
return n;
}
#endif
#define YYTABLES_NAME "yytables"
#line 378 "/home/jczech/mcell/build/deps/mdllex.l"
| C |
3D | mcellteam/mcell | appveyor_windows/debug_version.h | .h | 1,593 | 42 | /****************************************************************
* This file is automatically generated. Do not edit it.
* version.h updated at Fri Jul 17 15:14:05 PDT 2020 on ntbhusar by ahusar
****************************************************************/
/* Program version info */
#define MCELL_VERSION "3.5.1"
#define MCELL_REVISION "ea8bb986"
#define MCELL_REVISION_DATE "Fri, 17 Jul 2020 12:16:38 -0700"
#define MCELL_REVISION_COMMITTED 1
#define MCELL_REVISION_BRANCH "mcell4_bng2"
/* Build info */
#define MCELL_BUILDDATE "Fri Jul 17 15:14:05 PDT 2020"
#define MCELL_BUILDUSER "ahusar"
#define MCELL_BUILDHOST "ntbhusar"
#define MCELL_SRCDIR "/home/ahusar/src4_ref/mcell/src"
#define MCELL_BUILDDIR "/home/ahusar/src4_ref/mcell/build/debug"
#define MCELL_BUILDUNAME "Linux ntbhusar 4.9.0-12-amd64 #1 SMP Debian 4.9.210-1+deb9u1 (2020-06-07) x86_64 GNU/Linux"
/* Tool identity and version info */
#define MCELL_FLEX "flex"
#define MCELL_FLEX_PATH "/usr/bin/flex"
#define MCELL_FLEX_VERSION "flex 2.6.1"
#define MCELL_FLEX_FLAGS "-Crema"
#define MCELL_BISON "bison"
#define MCELL_BISON_PATH "/usr/bin/bison"
#define MCELL_BISON_VERSION "bison (GNU Bison) 3.0.4"
#define MCELL_BISON_FLAGS ""
#define MCELL_CC "cc"
#define MCELL_CC_PATH "/usr/bin/cc"
#define MCELL_CC_VERSION "cc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
#define MCELL_LD "ld"
#define MCELL_LD_PATH "/usr/bin/ld"
#define MCELL_LD_VERSION "GNU ld (GNU Binutils for Debian) 2.28"
/* Build options */
#define MCELL_LFLAGS "-Crema"
#define MCELL_YFLAGS ""
#define MCELL_CFLAGS ""
#define MCELL_LDFLAGS ""
| Unknown |
3D | mcellteam/mcell | libmcell/replace_in_all_files.sh | .sh | 123 | 3 | #!/bin/bash
# this is an auxiliary script used e.g. when API changes
find ./ -type f -exec sed -i "s/double/double/g" {} \; | Shell |
3D | mcellteam/mcell | libmcell/documentation/build.sh | .sh | 164 | 7 | #!/bin/bash
sphinx-build -M html . build/
if [ "$1" == "-u" ]; then
rsync -r build/html/* huxley.snl.salk.edu:/home/ahusar/public_html/mcell4_documentation
fi
| Shell |
3D | mcellteam/mcell | libmcell/documentation/conf.py | .py | 2,114 | 63 | # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'MCell4'
copyright = '2020-2021, Salk Institute'
author = 'Salk Institute'
import os
basedir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(basedir, '..', '..', 'src', 'version.txt'), 'r') as f:
version = f.readline().strip()
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx_rtd_theme",
"sphinx.ext.autosectionlabel"
]
autosectionlabel_prefix_document = True
# Add any paths that contain templates here, relative to this directory.
templates_path = ['templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['static']
| Python |
3D | mcellteam/mcell | libmcell/api/shared_structs.h | .h | 2,939 | 100 | /******************************************************************************
*
* Copyright (C) 2020-2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_SHARED_STRUCTS_H_
#define LIBMCELL_API_SHARED_STRUCTS_H_
#include "defines.h"
namespace MCell {
struct VertexMoveInfo {
// vertex index and partition defines the object index but
// it is faster to have the object id available as well
VertexMoveInfo(
const partition_id_t partition_id_,
const geometry_object_id_t geometry_object_id_,
const vertex_index_t vertex_index_,
const Vec3& displacement_)
: partition_id(partition_id_),
geometry_object_id(geometry_object_id_),
vertex_index(vertex_index_),
displacement(displacement_),
vertex_walls_are_movable(true) {
}
// id of partition of where do the move
partition_id_t partition_id;
// id of the object to move
geometry_object_id_t geometry_object_id;
// which vertex of the object to move
vertex_index_t vertex_index;
// and by how much
Vec3 displacement;
// may be set to false in apply_vertex_moves_per_object when any of the walls to which
// this vertex belongs is not movable
bool vertex_walls_are_movable;
};
struct GeometryObjectWallUnorderedPair {
GeometryObjectWallUnorderedPair(
geometry_object_id_t geometry_object_id1_,
wall_index_t wall_index1_,
geometry_object_id_t geometry_object_id2_,
wall_index_t wall_index2_) {
// the pair with lower geom obj id is always the first one
if (geometry_object_id1_ <= geometry_object_id2_) {
geometry_object_id1 = geometry_object_id1_;
wall_index1 = wall_index1_;
geometry_object_id2 = geometry_object_id2_;
wall_index2 = wall_index2_;
}
else {
geometry_object_id1 = geometry_object_id2_;
wall_index1 = wall_index2_;
geometry_object_id2 = geometry_object_id1_;
wall_index2 = wall_index1_;
}
}
// some ordering for usage in std::set
bool operator < (const GeometryObjectWallUnorderedPair& other) const {
if (geometry_object_id1 != other.geometry_object_id1) {
return geometry_object_id1 < other.geometry_object_id1;
}
else if (wall_index1 != other.wall_index1) {
return wall_index1 < other.wall_index1;
}
else if (geometry_object_id2 != other.geometry_object_id2) {
return geometry_object_id2 < other.geometry_object_id2;
}
else {
return wall_index2 < other.wall_index2;
}
}
geometry_object_id_t geometry_object_id1;
wall_index_t wall_index1;
geometry_object_id_t geometry_object_id2;
wall_index_t wall_index2;
};
}
#endif /* LIBMCELL_API_SHARED_STRUCTS_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/elementary_molecule.cpp | .cpp | 1,891 | 81 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/elementary_molecule.h"
#include "api/elementary_molecule_type.h"
#include "api/component_type.h"
#include "api/component.h"
#include "api/complex.h"
using namespace std;
namespace MCell {
namespace API {
bool ElementaryMolecule::__eq__(const ElementaryMolecule& other) const {
// do we have the same mol type?
if (!eq_nonarray_attributes(other)) {
return false;
}
string c1 = is_set(compartment_name) ? compartment_name : "";
string c2 = is_set(other.compartment_name) ? other.compartment_name : "";
if (c1 != c2) {
return false;
}
// are components the same (order does not matter)
std::set<Component> s1;
for (auto& c: components) {
s1.insert(*c);
}
std::set<Component> s2;
for (auto& c: other.components) {
s2.insert(*c);
}
return s1 == s2;
}
std::string ElementaryMolecule::to_bngl_str(const bool with_compartment) const {
std::string res;
res = elementary_molecule_type->name;
if (!components.empty()) {
res += "(";
for (size_t i = 0; i < components.size(); i++) {
res += components[i]->to_bngl_str();
if (i + 1 != components.size()) {
res += ",";
}
}
res += ")";
}
if (with_compartment && is_set(compartment_name)) {
res += "@" + compartment_name;
}
return res;
}
bool ElementaryMolecule::is_surf() const {
assert(is_set(elementary_molecule_type));
return is_set(elementary_molecule_type->diffusion_constant_2d);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/checkpoint_signals.h | .h | 1,128 | 45 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_CHECKPOINT_SIGNALS_H_
#define LIBMCELL_API_CHECKPOINT_SIGNALS_H_
#include "defines.h"
#include <string>
namespace MCell {
namespace API {
class Model;
const int SIGNO_NOT_SIGNALED = -1;
// used as a template argument for CustomFunctionCallEvent
struct CheckpointSaveEventContext {
Model* model;
std::string dir_prefix;
bool append_it_to_dir;
};
// may be called only once
void set_checkpoint_signals(Model* model);
// may be safely called multiple times
void unset_checkpoint_signals(Model* model);
// called from CustomFunctionCallEvent
void save_checkpoint_func(const double time, CheckpointSaveEventContext ctx);
} // namespace API
} // namespace MCell
#endif // LIBMCELL_API_CHECKPOINT_SIGNALS_H_
| Unknown |
3D | mcellteam/mcell | libmcell/api/python_export_utils.cpp | .cpp | 4,922 | 208 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include <fstream>
#include <regex>
#include "api/python_export_utils.h"
#include "api/python_export_constants.h"
namespace MCell {
namespace API {
using namespace std;
bool PythonExportContext::already_exported(const BaseDataClass* obj) const {
return exported_objects.count(obj) != 0;
}
std::string PythonExportContext::get_exported_name(const BaseDataClass* obj) const {
assert(already_exported(obj));
return exported_objects.find(obj)->second;
}
void PythonExportContext::add_exported(const BaseDataClass* obj, const std::string& name) {
assert(!already_exported(obj));
exported_objects[obj] = name;
}
uint PythonExportContext::postinc_counter(const std::string& underscored_class_name) {
uint res;
auto it = counters.find(underscored_class_name);
if (it != counters.end()) {
res = it->second;
it->second++;
}
else {
res = 0;
counters[underscored_class_name] = 1;
}
return res;
}
std::string fix_id(const std::string& str) {
std::string res;
for (char c: str) {
if (c == '+') {
res += "_plus_";
}
else if (c == '-') {
res += "_minus_";
}
else if (c == '*') {
res += "_mul_";
}
else if (c == '/') {
res += "_div_";
}
else if (c == '?') {
res += "_anybond_";
}
else if (c == '!') {
res += "_bond_";
}
else if (c == '(') {
res += "_ps_";
}
else if (c == ')') {
res += "_pe_";
}
else if (
c == ' ' || c == '.' || c == '_' ||
c == ',' || c == '~') {
res += "_";
}
else if (isalnum(c)) {
res += c;
}
// ignoring the rest of the characters
}
return res;
}
string get_filename(const string& output_files_prefix, const string file_suffix, const char* ext) {
if (output_files_prefix == "" || output_files_prefix.back() == '/' || output_files_prefix.back() == '\\') {
return output_files_prefix + file_suffix + ext;
}
else {
return output_files_prefix + "_" + file_suffix + ext;
}
}
void open_and_check_file_w_prefix(
const string& output_files_prefix, const string file_suffix, ofstream& out,
const bool for_append, const bool bngl) {
string file_name = get_filename(output_files_prefix, file_suffix, (bngl) ? BNGL_EXT : PY_EXT);
if (for_append) {
cout << "Appending to " + file_name + ".\n";
out.open(file_name, ios::app);
}
else {
cout << "Generating file " + file_name + ".\n";
out.open(file_name);
}
out.precision(FLOAT_OUT_PRECISION);
if (!out.is_open()) {
throw ConversionError("Could not open file '" + file_name + "' for writing.");
}
}
std::string get_description(const Json::Value& value) {
if (value.isMember(KEY_DESCRIPTION)) {
return value[KEY_DESCRIPTION].asString();
}
else {
return "";
}
}
void gen_description(std::ostream& out, const std::string desc, const std::string ind) {
if (desc != "") {
out << ind << "# " << desc << "\n";
}
}
void gen_description(std::ostream& out, Json::Value& value, const std::string ind) {
if (value.isMember(KEY_DESCRIPTION)) {
string desc = value[KEY_DESCRIPTION].asString();
if (desc != "") {
out << ind << "# " << desc << "\n";
}
}
}
void gen_ctor_call(std::ostream& out, std::string name, std::string class_name, bool has_params) {
if (name != "") {
out << make_id(name) << " = " << MDOT << class_name;
}
else {
out << MDOT << class_name;
}
if (has_params) {
out << "(\n";
}
else {
out << "()\n";
}
}
// replaces '.' with '_' and does potentially other conversions
std::string make_id(const std::string& s) {
string res = s;
// do not do changes if the ID starts with 'm.' -> constant from
// the mcell module ID that cannot have dots that we need to replace in it anyway
if (res.size() <= 2 || (res.size() > 2 && res.substr(0, strlen(MDOT)) != MDOT)) {
res = fix_id(res);
}
return res;
}
string fix_param_id(const std::string& str) {
assert(str.size() > 0);
if (str[0] == '_') {
// underscore denotes private variables in Python
return "und" + str;
}
else {
return str;
}
}
void gen_param_expr(std::ostream& out, std::string name, const std::string& value, bool comma) {
std::string python_expr;
// replace operator ^ with operator ** and '_' at the beginning with 'und_'
python_expr = fix_param_id(regex_replace(value, regex("\\^"), "**"));
out << IND << name << " = " << python_expr << (comma?",":"") << "\n";
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/count.h | .h | 1,123 | 51 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COUNT_H
#define API_COUNT_H
#include "generated/gen_count.h"
#include "api/api_common.h"
#include "api/count_term.h"
namespace MCell {
class MolOrRxnCountEvent;
namespace API {
class Count: public GenCount {
public:
COUNT_CTOR()
void set_all_custom_attributes_to_default() override {
count_event = nullptr;
}
void postprocess_in_ctor() override;
void check_semantics() const override;
double get_current_value() override;
// count event, owned by Scheduler if every_n_timesteps > 0,
// owned by World if every_n_timesteps == 0
MolOrRxnCountEvent* count_event;
private:
void set_automatically_output_format_if_needed();
};
} // namespace API
} // namespace MCell
#endif // API_COUNT_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/bindings.cpp | .cpp | 8,554 | 267 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "mcell.h"
#include "generated/gen_component_type.h"
#include "generated/gen_component.h"
#include "generated/gen_elementary_molecule_type.h"
#include "generated/gen_elementary_molecule.h"
#include "generated/gen_species.h"
#include "generated/gen_surface_class.h"
#include "generated/gen_reaction_rule.h"
#include "generated/gen_subsystem.h"
#include "generated/gen_color.h"
#include "generated/gen_region.h"
#include "generated/gen_initial_surface_release.h"
#include "generated/gen_surface_region.h"
#include "generated/gen_geometry_object.h"
#include "generated/gen_release_pattern.h"
#include "generated/gen_molecule_release_info.h"
#include "generated/gen_release_site.h"
#include "generated/gen_instantiation.h"
#include "generated/gen_count_term.h"
#include "generated/gen_count.h"
#include "generated/gen_viz_output.h"
#include "generated/gen_observables.h"
#include "generated/gen_config.h"
#include "generated/gen_notifications.h"
#include "generated/gen_warnings.h"
#include "generated/gen_model.h"
#include "generated/gen_region.h"
#include "generated/gen_molecule.h"
#include "generated/gen_wall.h"
#include "generated/gen_introspection.h"
#include "generated/gen_mol_wall_hit_info.h"
#include "generated/gen_wall_wall_hit_info.h"
#include "generated/gen_reaction_info.h"
#include "generated/gen_chkpt_vol_mol.h"
#include "generated/gen_chkpt_surf_mol.h"
#include "generated/gen_rng_state.h"
#include "generated/gen_bngl_utils.h"
#include "generated/gen_geometry_utils.h"
#include "generated/gen_run_utils.h"
#include "generated/gen_data_utils.h"
#include "generated/gen_constants.h"
#include "world.h"
#include "version.h"
#if __cplusplus < 201402L && !defined(_MSC_VER)
#error "Pybind11 overload requires at least C++14"
#endif
#ifndef PYBIND11_OVERLOAD_CAST
#error "PYBIND11_OVERLOAD_CAST must be defined"
#endif
#include "pybind11_stl_include.h"
namespace MCell {
namespace API {
// defined in gen_vectors_bind.cpp
void gen_vectors_bind(py::module& m);
void define_pybinding_Vec3(py::module& m) {
py::class_<MCell::Vec3>(m, "Vec3")
.def(
py::init<>()
)
.def(
py::init<const double>(),
py::arg("xyz")
)
.def(
py::init<const double, const double, const double>(),
py::arg("x"), py::arg("y"), py::arg("z")
)
.def("__add__", [](const Vec3& a, const Vec3& b) { return Vec3(a + b); } )
.def("__sub__", [](const Vec3& a, const Vec3& b) { return Vec3(a - b); } )
.def("__mul__", [](const Vec3& a, const Vec3& b) { return Vec3(a * b); } )
.def("__truediv__", [](const Vec3& a, const Vec3& b) { return Vec3(a / b); } )
.def("__eq__", [](const Vec3& a, const Vec3& b) { return a == b; } )
.def("__str__", [](const Vec3& a)
{ return "(" + std::to_string(a.x) + ", " + std::to_string(a.y) + ", " + std::to_string(a.z) + ")"; } )
.def("__repr__", [](const Vec3& a)
{ return "(" + std::to_string(a.x) + ", " + std::to_string(a.y) + ", " + std::to_string(a.z) + ")"; } )
.def("to_list", [](const Vec3& a) { return py::cast(std::vector<double>{a.x, a.y, a.z}); } )
.def_readwrite("x", &Vec3::x)
.def_readwrite("y", &Vec3::y)
.def_readwrite("z", &Vec3::z)
;
}
void define_pybinding_Vec2(py::module& m) {
py::class_<MCell::Vec2>(m, "Vec2")
.def(
py::init<>()
)
.def(
py::init<const double>(),
py::arg("xy")
)
.def(
py::init<const double, const double>(),
py::arg("x"), py::arg("y")
)
.def("__add__", [](const Vec2& a, const Vec2& b) { return Vec2(a + b); } )
.def("__sub__", [](const Vec2& a, const Vec2& b) { return Vec2(a - b); } )
.def("__mul__", [](const Vec2& a, const Vec2& b) { return Vec2(a * b); } )
.def("__truediv__", [](const Vec2& a, const Vec2& b) { return Vec2(a / b); } )
.def("__eq__", [](const Vec2& a, const Vec2& b) { return a == b; } )
.def("__str__", [](const Vec2& a)
{ return "(" + std::to_string(a.x) + ", " + std::to_string(a.y) + ")"; } )
.def("__repr__", [](const Vec2& a)
{ return "(" + std::to_string(a.x) + ", " + std::to_string(a.y) + ")"; } )
.def("to_list", [](const Vec2& a) { return std::vector<double>{a.x, a.y}; } )
.def_readwrite("x", &Vec2::x)
.def_readwrite("y", &Vec2::y)
.def_readwrite("u", &Vec2::u)
.def_readwrite("v", &Vec2::v)
;
}
void define_pybinding_IVec3(py::module& m) {
py::class_<MCell::IVec3>(m, "IVec3")
.def(
py::init<>()
)
.def(
py::init<const double>(),
py::arg("xyz")
)
.def(
py::init<const int, const int, const int>(),
py::arg("x"), py::arg("y"), py::arg("z")
)
// FIXME: enabling these operator breaks debug build for unknown reason,
// release is build ok, one of tests to reproduce:
// mdl_data_model_pymcell4/tests/mdl/0051_largest_partition_size
// reenable parts of testing in mcell_tests/tests/pymcell4_positive/0050_vec_operators
// once fixed
/*.def(
py::init<const double, const double, const double>(),
py::arg("x"), py::arg("y"), py::arg("z")
)
.def("__add__", [](const IVec3& a, const IVec3& b) { return IVec3(a + b); } )
.def("__sub__", [](const IVec3& a, const IVec3& b) { return IVec3(a - b); } )
.def("__mul__", [](const IVec3& a, const IVec3& b) { return IVec3(a * b); } )
.def("__truediv__", [](const IVec3& a, const IVec3& b) { return IVec3(a / b); } )
.def("__eq__", [](const IVec3& a, const IVec3& b) { return a == b; } )
*/
.def_readwrite("x", &IVec3::x)
.def_readwrite("y", &IVec3::y)
.def_readwrite("z", &IVec3::z)
;
}
// all define_binding_* functions are called here
PYBIND11_MODULE(mcell, m) {
// version
m.attr("__version__") = py::str(MCELL_VERSION);
// bindings of custom vector types
gen_vectors_bind(m);
// some classes use enums, must be defined first
define_pybinding_enums(m);
define_pybinding_Vec3(m);
define_pybinding_Vec2(m);
define_pybinding_IVec3(m);
define_pybinding_ComponentType(m);
define_pybinding_Component(m);
define_pybinding_ElementaryMoleculeType(m);
define_pybinding_ElementaryMolecule(m);
define_pybinding_Complex(m);
define_pybinding_Species(m);
define_pybinding_SurfaceProperty(m);
define_pybinding_SurfaceClass(m);
define_pybinding_ReactionRule(m);
define_pybinding_Subsystem(m);
define_pybinding_ReleasePattern(m);
define_pybinding_MoleculeReleaseInfo(m);
define_pybinding_ReleaseSite(m);
define_pybinding_Color(m);
define_pybinding_Region(m);
define_pybinding_InitialSurfaceRelease(m);
define_pybinding_SurfaceRegion(m);
define_pybinding_GeometryObject(m);
define_pybinding_Instantiation(m);
define_pybinding_CountTerm(m);
define_pybinding_Count(m);
define_pybinding_VizOutput(m);
define_pybinding_Observables(m);
define_pybinding_Config(m);
define_pybinding_Notifications(m);
define_pybinding_Warnings(m);
define_pybinding_Model(m);
define_pybinding_Molecule(m);
define_pybinding_Wall(m);
define_pybinding_WallWallHitInfo(m);
define_pybinding_MolWallHitInfo(m);
define_pybinding_ReactionInfo(m);
define_pybinding_BaseChkptMol(m);
define_pybinding_ChkptVolMol(m);
define_pybinding_ChkptSurfMol(m);
define_pybinding_RngState(m);
// constants may reference existing types, must be "bound" later
define_pybinding_constants(m);
define_pybinding_bngl_utils(m);
define_pybinding_geometry_utils(m);
define_pybinding_run_utils(m);
define_pybinding_data_utils(m);
}
void check_ctrl_c(const double current_time, World* world) {
// make sure to re-acquire lock, PyErr_CheckSignals segfaults otherwise
py::gil_scoped_acquire acquire;
if (PyErr_CheckSignals() != 0) {
std::cout << "Caught Ctrl-C signal in iteration " << current_time << ".\n";
std::cout << "Flushing buffers.\n";
release_assert(world != nullptr);
world->flush_and_close_buffers();
throw py::error_already_set();
}
}
} // API
} // MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/python_exporter.h | .h | 1,840 | 66 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_PYTHON_EXPORTER_H_
#define LIBMCELL_API_PYTHON_EXPORTER_H_
#include <string>
#include <map>
#include <ostream>
namespace MCell {
class World;
namespace API {
class Model;
class PythonExportContext;
class PythonExporter {
public:
PythonExporter(Model* model_);
void save_checkpoint(const std::string& output_dir_);
private:
void open_and_check_file(
const std::string file_name, std::ofstream& out,
const bool for_append = false,
const bool bngl = false);
std::string export_subsystem(PythonExportContext& ctx);
std::string export_geometry(PythonExportContext& ctx);
std::string export_instantiation(PythonExportContext& ctx, const std::string& geometry_objects_name);
std::string export_observables(PythonExportContext& ctx);
void export_simulation_state(
PythonExportContext& ctx, std::map<std::string, std::string>& config_variable_names);
void export_molecules(std::ostream& out, PythonExportContext& ctx);
std::string export_model(
PythonExportContext& ctx,
const std::string& subsystem_name,
const std::string& instantiation_name,
const std::string& observables_name,
const std::map<std::string, std::string>& config_variable_names);
void export_checkpoint_iterations(std::ostream& out);
Model* model;
World* world;
std::string output_dir;
};
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_PYTHON_EXPORTER_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/component_type.h | .h | 1,398 | 49 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COMPONENT_TYPE_H
#define API_COMPONENT_TYPE_H
#include "generated/gen_component_type.h"
#include "api/api_common.h"
#include "api/component.h"
namespace MCell {
namespace API {
class ComponentType: public GenComponentType, public std::enable_shared_from_this<ComponentType> {
public:
COMPONENT_TYPE_CTOR()
std::shared_ptr<Component> inst(const std::string& state, const int bond) override {
return std::make_shared<Component>(shared_from_this(), state, bond);
}
std::shared_ptr<Component> inst(const int state, const int bond) override {
return std::make_shared<Component>(shared_from_this(), std::to_string(state), bond);
}
bool __eq__(const ComponentType& other) const override;
std::string to_bngl_str() const override;
// added manually
std::string get_canonical_name() const;
// needed when defining a set of ComponentTypes
bool operator < (const ComponentType& other) const;
};
} // namespace API
} // namespace MCell
#endif // API_COMPONENT_TYPE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/notifications.h | .h | 705 | 30 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_NOTIFICATIONS_H
#define API_NOTIFICATIONS_H
#include "generated/gen_notifications.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class Notifications: public GenNotifications {
public:
NOTIFICATIONS_CTOR()
};
} // namespace API
} // namespace MCell
#endif // API_NOTIFICATIONS_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/release_pattern.h | .h | 1,001 | 39 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_RELEASE_PATTERN_H
#define API_RELEASE_PATTERN_H
#include "generated/gen_release_pattern.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class ReleasePattern: public GenReleasePattern {
public:
RELEASE_PATTERN_CTOR()
void check_semantics() const override {
GenReleasePattern::check_semantics();
if (train_interval < train_duration) {
throw ValueError(S(NAME_RELEASE_PATTERN) + name + ": " +
NAME_TRAIN_INTERVAL + " is shorter than " + NAME_TRAIN_DURATION + ".");
}
}
};
} // namespace API
} // namespace MCell
#endif // API_RELEASE_PATTERN_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/introspection.h | .h | 2,083 | 69 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_INTROSPECTION_H
#define API_INTROSPECTION_H
#include "generated/gen_introspection.h"
#include "api/api_common.h"
namespace MCell {
class World;
namespace API {
class Model;
// this class is used only as a base to Model, it is not provided through API
class Introspection: public GenIntrospection {
public:
Introspection() :
model_inst(nullptr),
world(nullptr) {
}
Introspection(DefaultCtorArgType) :
model_inst(nullptr),
world(nullptr) {
}
void initialize_introspection(Model* model_);
std::vector<int> get_molecule_ids(std::shared_ptr<Complex> pattern = nullptr) override;
std::shared_ptr<Molecule> get_molecule(const int id) override;
std::string get_species_name(const int species_id) override;
std::vector<double> get_vertex(std::shared_ptr<GeometryObject> object, const int vertex_index) override;
std::shared_ptr<Wall> get_wall(std::shared_ptr<GeometryObject> object, const int wall_index) override;
std::vector<double> get_vertex_unit_normal(std::shared_ptr<GeometryObject> object, const int vertex_index) override;
std::vector<double> get_wall_unit_normal(std::shared_ptr<GeometryObject> object, const int wall_index) override;
std::shared_ptr<Color> get_wall_color(std::shared_ptr<GeometryObject> object, const int wall_index) override;
void set_wall_color(std::shared_ptr<GeometryObject> object, const int wall_index, std::shared_ptr<Color> color) override;
void dump() const {}
private:
// not using name model because class Model inherits Introspection and
// this made code a bit confusing
Model* model_inst;
World* world;
};
} // namespace API
} // namespace MCell
#endif // API_INTROSPECTION_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/bng_converter.h | .h | 1,808 | 69 | /******************************************************************************
*
* Copyright (C) 2020-2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_BNG_CONVERTER_H_
#define LIBMCELL_API_BNG_CONVERTER_H_
#include <string>
#include "bng/bng_defines.h"
namespace BNG {
class BNGData;
class BNGConfig;
class Component;
class ElemMol;
class Cplx;
}
namespace MCell {
namespace API {
class ComponentType;
class Component;
class ElementaryMoleculeType;
class ElementaryMolecule;
class Complex;
class BNGConverter {
public:
BNGConverter(BNG::BNGData& bng_data_, const BNG::BNGConfig& bng_config_) :
bng_data(bng_data_), bng_config(bng_config_) {
}
BNG::component_type_id_t convert_component_type(
const std::string& elem_mol_type_name, API::ComponentType& api_ct);
BNG::Component convert_component_instance(
const std::string& elem_mol_type_name, API::Component& api_ci);
BNG::elem_mol_type_id_t convert_elementary_molecule_type(
API::ElementaryMoleculeType& mt, const bool in_rxn_or_observables = false);
BNG::ElemMol convert_molecule_instance(
API::ElementaryMolecule& mi, const bool in_rxn_or_observables = false);
// in_observables should be set to true if we are converting a pattern for
// matching purposes
BNG::Cplx convert_complex(
API::Complex& inst, const bool in_observables = false, const bool in_rxn = false);
private:
BNG::BNGData& bng_data;
const BNG::BNGConfig& bng_config;
};
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_BNG_CONVERTER_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/mol_wall_hit_info.h | .h | 988 | 41 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_MOL_WALL_HIT_INFO_H
#define API_MOL_WALL_HIT_INFO_H
#include "generated/gen_mol_wall_hit_info.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class MolWallHitInfo: public GenMolWallHitInfo {
public:
MolWallHitInfo() {
}
MolWallHitInfo(DefaultCtorArgType) {
}
void dump() {
std::cout << to_str();
}
// extra information to be converted in Callbacks
geometry_object_id_t geometry_object_id; // to geometry_object
wall_index_t partition_wall_index; // to wall_index
};
} // namespace API
} // namespace MCell
#endif // API_MOL_WALL_HIT_INFO_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/wall.cpp | .cpp | 916 | 37 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/wall.h"
#include "api/geometry_object.h"
#include "world.h"
#include "partition.h"
#include "geometry.h"
using namespace std;
namespace MCell {
namespace API {
void Wall::set_is_movable(const bool new_is_movable_) {
check_initialization();
is_movable = new_is_movable_;
MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL);
MCell::Wall& w = p.get_wall(geometry_object->get_partition_wall_index(wall_index));
w.is_movable = new_is_movable_;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/observables.cpp | .cpp | 5,828 | 202 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/observables.h"
#include "api/subsystem.h"
#include "bng/bng.h"
#include "api/component_type.h"
#include "api/component.h"
#include "api/elementary_molecule_type.h"
#include "api/elementary_molecule.h"
#include "api/complex.h"
#include "api/api_utils.h"
using namespace std;
using namespace BNG;
namespace MCell {
namespace API {
void Observables::dump() const {
std::cout << to_str() << "\n";
}
std::string Observables::get_first_viz_output_files_prefix(const char* method_name) {
// use the first viz_output
if (viz_outputs.empty()) {
throw ValueError(
S("Method ") + method_name + " requires a file argument when there are no instances of " +
NAME_CLASS_VIZ_OUTPUT + " present."
);
}
if (!is_set(viz_outputs[0]->output_files_prefix)) {
throw ValueError(
S("Method ") + method_name + ": the first VizOutput instance does not have its " +
NAME_OUTPUT_FILES_PREFIX + " set."
);
}
return viz_outputs[0]->output_files_prefix;
}
CountOutputFormat Observables::count_output_format_from_path_or_file(const std::string& path_or_file) {
const string gdat = ".gdat";
size_t gdat_sz = gdat.size();
size_t sz = path_or_file.size();
if (sz > gdat.size() && path_or_file.substr(sz - gdat_sz) == gdat) {
return CountOutputFormat::GDAT;
}
else {
return CountOutputFormat::DAT;
}
}
CountOutputFormat Observables::get_count_output_format(
const CountOutputFormat observables_output_format,
const std::string& observables_path_or_file
) {
CountOutputFormat fmt;
if (observables_output_format == CountOutputFormat::AUTOMATIC_FROM_EXTENSION) {
return count_output_format_from_path_or_file(observables_path_or_file);
}
else {
if (observables_path_or_file == "" &&
observables_output_format == CountOutputFormat::GDAT) {
throw RuntimeError(S("Attribute ") + NAME_OBSERVABLES_PATH_OR_FILE + " must not be empty " +
"when " + NAME_OBSERVABLES_OUTPUT_FORMAT + " is " + NAME_ENUM_COUNT_OUTPUT_FORMAT + "." +
NAME_EV_GDAT + ".");
}
return observables_output_format;
}
}
void Observables::load_bngl_observables(
const std::string& file_name,
const std::string& observables_path_or_file,
const std::map<std::string, double>& parameter_overrides,
const CountOutputFormat observables_output_format) {
BNG::BNGData bng_data;
int num_errors = BNG::parse_bngl_file(file_name, bng_data, parameter_overrides);
if (num_errors != 0) {
throw RuntimeError("Could not parse BNGL file " + file_name + ".");
}
// now convert everything we parsed into the API classes so that the user can
// inspect or manipulate it if needed
convert_bng_data_to_observables_data(
bng_data,
get_count_output_format(observables_output_format, observables_path_or_file),
observables_path_or_file);
}
void Observables::convert_bng_data_to_observables_data(
const BNG::BNGData& bng_data,
const CountOutputFormat observables_output_format,
const std::string& observables_path_or_file) {
for (const Observable& o: bng_data.get_observables()) {
convert_observable(o, bng_data, observables_path_or_file, observables_output_format);
}
}
static void set_count_molecules_or_species_pattern(
const BNG::ObservableType type,
const BNG::Cplx& bng_pattern,
const BNG::BNGData& bng_data,
API::CountTerm& count
) {
std::shared_ptr<API::Complex> pattern =
Complex::construct_from_bng_cplx(bng_data, bng_pattern);
if (type == ObservableType::Molecules) {
count.molecules_pattern = pattern;
}
else if (type == ObservableType::Species) {
count.species_pattern = pattern;
}
else {
release_assert(false);
}
}
void Observables::convert_observable(
const BNG::Observable& o,
const BNG::BNGData& bng_data,
const std::string& observables_path_or_file,
const CountOutputFormat observables_output_format) {
shared_ptr<API::Count> count = make_shared<Count>(DefaultCtorArgType());
count->expression = make_shared<CountTerm>(DefaultCtorArgType());
count->name = o.name;
if (observables_output_format == CountOutputFormat::DAT) {
if (is_set(observables_path_or_file)) {
count->file_name = observables_path_or_file + o.name + ".dat";
}
else {
// will be set during conversion
count->file_name = STR_UNSET;
}
}
else if (observables_output_format == CountOutputFormat::GDAT) {
count->file_name = observables_path_or_file;
}
else {
release_assert(false && "Invalid count output format.");
}
count->output_format = observables_output_format;
release_assert(!o.patterns.empty() && "Observable has no pattern");
if (o.patterns.size() == 1) {
set_count_molecules_or_species_pattern(o.type, o.patterns[0], bng_data, *count->expression);
}
else {
shared_ptr<API::CountTerm> top_level_term = nullptr;
for (const auto& pat: o.patterns) {
shared_ptr<API::CountTerm> term = make_shared<CountTerm>(DefaultCtorArgType());
set_count_molecules_or_species_pattern(o.type, pat, bng_data, *term);
if (is_set(top_level_term)) {
top_level_term = top_level_term->__add__(term);
}
else {
top_level_term = term;
}
}
count->expression = top_level_term;
}
// remember for conversion in mcell4 coverter
counts.push_back(count);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/component.h | .h | 898 | 37 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COMPONENT_INSTANCE_H
#define API_COMPONENT_INSTANCE_H
#include "generated/gen_component.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class Component: public GenComponent {
public:
COMPONENT_CTOR()
// default __eq__ operator is sufficient
// needed when defining a set of ComponentInstances
bool operator < (const Component& other) const;
std::string to_bngl_str() const override;
};
} // namespace API
} // namespace MCell
#endif // API_COMPONENT_INSTANCE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/subsystem.cpp | .cpp | 6,105 | 181 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include <api/component.h>
#include "subsystem.h"
#include "bng/bng.h"
#include "api/component_type.h"
#include "api/elementary_molecule_type.h"
#include "api/elementary_molecule.h"
#include "api/complex.h"
#include "api/api_utils.h"
using namespace std;
namespace MCell {
namespace API {
void Subsystem::dump() const {
std::cout << to_str() << "\n";
}
std::shared_ptr<Species> Subsystem::get_species_with_id(const species_id_t id) {
// not very efficient, we may need some caching/map later
for (auto& s: species) {
if (s->species_id == id) {
return s;
}
}
return std::shared_ptr<Species>(nullptr);
}
void Subsystem::unify_and_register_elementary_molecule_types() {
// then go through Species
for (std::shared_ptr<Species> s: species) {
for (size_t i = 0; i < s->elementary_molecules.size(); i++) {
// note the reference, we might be changing this spared ptr
std::shared_ptr<ElementaryMoleculeType>& emt = s->elementary_molecules[i]->elementary_molecule_type;
// do we have this exact object already?
auto it_ptr_eq = std::find_if(
elementary_molecule_types.begin(), elementary_molecule_types.end(),
[&emt] (const std::shared_ptr<ElementaryMoleculeType> emt_existing) {
return emt_existing.get() == emt.get(); // comparing pointers
}
);
if (it_ptr_eq != elementary_molecule_types.end()) {
// same object exists
continue;
}
// do we have an object with the same contents already?
auto it_contents_eq = std::find_if(
elementary_molecule_types.begin(), elementary_molecule_types.end(),
[&emt] (const std::shared_ptr<ElementaryMoleculeType> emt_existing) {
return *emt_existing == *emt; // comparing contents
}
);
if (it_contents_eq != elementary_molecule_types.end()) {
// same object exists, we must use this one and let shared_ptr ref counting
// destroy the previous one (creation of the EMT object to be destroyed
// occurs mainly when defining simple species, so the link from species to this emt
// is internal and not visible to the user)
emt = *it_contents_eq;
continue;
}
// one more option is that some of the elementary molecule types that we encounter are not
// fully initialized, for now expecting that the the fully initialized one is already present
auto it_name_eq = std::find_if(
elementary_molecule_types.begin(), elementary_molecule_types.end(),
[&emt] (const std::shared_ptr<ElementaryMoleculeType> emt_existing) {
return emt_existing->name == emt->name; // comparing contents
}
);
if (it_name_eq != elementary_molecule_types.end()) {
// use the one that is initialized
if (!(*it_name_eq)->all_numerical_attributes_are_unset() &&
emt->all_numerical_attributes_are_unset()
) {
// update the pointer used in the Species object
emt = *it_name_eq;
continue;
}
if ((*it_name_eq)->all_numerical_attributes_are_unset() &&
!emt->all_numerical_attributes_are_unset()
) {
// update the one in elementary_molecule_types using the Species object
*it_name_eq = emt;
continue;
}
// other cases are error and will be reported in add_elementary_molecule_type
}
// no such object is in the emt list, add it (reports error if such object already exists)
add_elementary_molecule_type(emt);
}
}
}
void Subsystem::load_bngl_molecule_types_and_reaction_rules(
const std::string& file_name,
const std::map<std::string, double>& parameter_overrides) {
BNG::BNGData bng_data;
int num_errors = BNG::parse_bngl_file(file_name, bng_data, parameter_overrides);
if (num_errors != 0) {
throw RuntimeError("Could not parse BNGL file " + file_name + ".");
}
// now convert everything we parsed into the API classes so that the user can
// inspect or manipulate it if needed
convert_bng_data_to_subsystem_data(bng_data);
}
void Subsystem::convert_bng_data_to_subsystem_data(const BNG::BNGData& bng_data) {
// elementary molecules
for (const BNG::ElemMolType& mt: bng_data.get_elem_mol_types()) {
auto res_mt = ElementaryMoleculeType::construct_from_bng_elem_mol_type(bng_data, mt);
append_to_vec_canonical_name(elementary_molecule_types, res_mt);
}
// reaction rules
for (const BNG::RxnRule& rr: bng_data.get_rxn_rules()) {
convert_reaction_rule(bng_data, rr);
}
}
void Subsystem::convert_reaction_rule(const BNG::BNGData& bng_data, const BNG::RxnRule& bng_rr) {
// always a standard rxn
if (bng_rr.type != BNG::RxnType::Standard) {
throw RuntimeError("Unexpected type of reaction from BNGL file for reaction " + bng_rr.name + ".");
}
auto res_rr = make_shared<API::ReactionRule>(DefaultCtorArgType());
if (bng_rr.name != "") {
res_rr->name = bng_rr.name;
}
// RxnRule
res_rr->fwd_rate = bng_rr.base_rate_constant;
for (const BNG::Cplx& inst: bng_rr.reactants) {
// MCell3R accepts reactants with any orientation
res_rr->reactants.push_back(
Complex::construct_from_bng_cplx_w_orientation(bng_data, inst, Orientation::ANY));
}
for (const BNG::Cplx& inst: bng_rr.products) {
// MCell3R always creates products with the orientation up
res_rr->products.push_back(
Complex::construct_from_bng_cplx_w_orientation(bng_data, inst, Orientation::UP));
}
// allow reactions with identical names
append_to_vec_canonical_name(reaction_rules, res_rr);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/geometry_object.cpp | .cpp | 3,427 | 113 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/geometry_object.h"
#include "api/surface_class.h"
using namespace std;
namespace MCell {
namespace API {
void GeometryObject::postprocess_in_ctor() {
set_all_custom_attributes_to_default();
}
void GeometryObject::set_all_custom_attributes_to_default() {
Region::set_all_custom_attributes_to_default();
// overwrite value in Region construction
region_type = RegionType::VOLUME;
node_type = RegionNodeType::LEAF_GEOMETRY_OBJECT;
partition_id = PARTITION_ID_INVALID;
geometry_object_id = GEOMETRY_OBJECT_ID_INVALID;
first_vertex_index = VERTEX_INDEX_INVALID;
parent_compartment = nullptr;
vol_compartment_id = BNG::COMPARTMENT_ID_INVALID;
surf_compartment_id = BNG::COMPARTMENT_ID_INVALID;
}
void GeometryObject::check_semantics() const {
GenGeometryObject::check_semantics();
for (auto& v: vertex_list) {
if (v.size() != 3) {
throw ValueError(
S("Each item in the '") + NAME_VERTEX_LIST + "' argument must be a triplet of floats, error for " +
vec_nonptr_to_str(v) + ".");
}
}
for (auto& e: wall_list) {
if (e.size() != 3) {
throw ValueError(
S("Each item in the '") + NAME_WALL_LIST + "' argument must be a triplet of integers, error for " +
vec_nonptr_to_str(e) + ".");
for (int vertex_index: e) {
if (vertex_index < 0 || vertex_index >= (int)vertex_list.size()) {
throw ValueError(
S("Vertex index the '") + NAME_WALL_LIST + "' is out of range, error for " +
std::to_string(vertex_index));
}
}
}
}
for (auto& sr: surface_regions) {
for (int wall_index: sr->wall_indices) {
if (wall_index >= (int)wall_list.size()) {
throw ValueError(
S("Wall index in the '") + NAME_WALL_INDICES + "' of '" + sr->name + "' is out of range, error for " +
std::to_string(wall_index));
}
}
}
}
void GeometryObject::translate(const std::vector<double> move) {
if (move.size() != 3) {
throw ValueError(S("Argument ") + NAME_MOVE + " must be a list containing exactly 3 floats.");
}
if (geometry_object_id != GEOMETRY_OBJECT_ID_INVALID) {
throw RuntimeError(S("Method ") + NAME_TRANSLATE + " may be called only before model initialization.");
}
for (auto& v: vertex_list) {
v[0] += move[0];
v[1] += move[1];
v[2] += move[2];
}
}
std::string GeometryObject::to_str(const bool all_details, const std::string ind) const {
if (!all_details) {
std::stringstream ss;
ss << get_object_name() << ": " <<
"name=" << name << ", " <<
"is_bngl_compartment=" << is_bngl_compartment << ", " <<
"surface_compartment_name=" << surface_compartment_name << ", " <<
"surface_class=" << "(" << ((surface_class != nullptr) ? surface_class->to_str(all_details, ind + " ") : "null" ) << ")" << ", " << "\n" << ind + " ";
return ss.str();
}
else {
return GenGeometryObject::to_str(true, ind);
}
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/python_export_utils.h | .h | 8,713 | 268 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_PYTHON_EXPORT_UTILS_H_
#define LIBMCELL_API_PYTHON_EXPORT_UTILS_H_
#include <exception>
#include <string>
#include <vector>
#include "defines.h"
#include "api/python_export_constants.h"
#include "json/json.h"
namespace MCell {
namespace API {
class BaseDataClass;
// class used to hold data when exporting objects to Python, e.g. for checkpointing
class PythonExportContext {
public:
bool already_exported(const BaseDataClass* obj) const;
std::string get_exported_name(const BaseDataClass* obj) const;
void add_exported(const BaseDataClass* obj, const std::string& name);
// returns current counter value (starts at 0) and increments counter for the current
// class
uint postinc_counter(const std::string& underscored_class_name);
private:
std::map<const BaseDataClass*, std::string> exported_objects;
std::map<std::string, uint> counters;
};
typedef std::invalid_argument ConversionError;
// replace all characters that cannot be present in an identifier
std::string fix_id(const std::string& str);
std::string get_filename(const std::string& output_files_prefix, const std::string file_suffix, const char* ext);
void open_and_check_file_w_prefix(
const std::string& output_files_prefix, const std::string file_suffix, std::ofstream& out,
const bool for_append = false, const bool bngl = false);
std::string make_id(const std::string& s);
std::string fix_param_id(const std::string& str);
static std::string make_section_comment(const std::string text) {
return BLOCK_BEGIN1 + text + BLOCK_BEGIN2 + "\n";
}
static std::string make_start_block_comment(const std::string text) {
return BLOCK_BEGIN1 + text + BLOCK_BEGIN2;
}
static std::string make_end_block_comment(const std::string text) {
return BLOCK_END1 + text + BLOCK_END2 + "\n";
}
static std::string make_enum_value(const std::string enum_name, const std::string value) {
return MDOT + enum_name + "." + value;
}
static void gen_comma(std::ostream& out, Json::Value::ArrayIndex index, Json::Value& array) {
if (index + 1 != array.size()) {
out << ", ";
}
}
template<typename T>
static void gen_comma(std::ostream& out, size_t index, const std::vector<T>& array) {
if (index + 1 != array.size()) {
out << ", ";
}
}
template<typename T>
void print_comma(std::ostream& out, size_t index, const std::vector<T>& array) {
if (index + 1 != array.size()) {
out << ", ";
}
}
// may return an empty string
std::string get_description(const Json::Value& value);
void gen_description(std::ostream& out, const std::string desc, const std::string ind = "");
void gen_description(std::ostream& out, Json::Value& value, const std::string ind = "");
// name might be empty
void gen_ctor_call(std::ostream& out, std::string name, std::string class_name, bool has_params = true);
static void gen_method_call(
std::ostream& out, std::string obj, std::string method,
std::string param1 = "", std::string param2 = "", std::string param3 = "") {
out << obj << "." << method << "(" << param1;
if (param2 != "" || param3 != "") {
out << ", " << param2;
}
if (param3 != "") {
out << ", " << param3;
}
out << ")\n";
}
template<typename T>
static void gen_param(std::ostream& out, std::string name, T value, bool comma) {
out << IND << name << " = " << value << (comma?",":"") << "\n";
}
template<>
void gen_param(std::ostream& out, std::string name, Json::Value& value, bool comma) {
out << IND << name << " = '" << value.asString() << "'" << (comma?",":"") << "\n";
}
template<>
void gen_param(std::ostream& out, std::string name, std::string value, bool comma) {
out << IND << name << " = '" << value << "'" << (comma?",":"") << "\n";
}
template<>
void gen_param(std::ostream& out, std::string name, const char* const value, bool comma) {
out << IND << name << " = '" << value << "'" << (comma?",":"") << "\n";
}
template<>
void gen_param(std::ostream& out, std::string name, int value, bool comma) {
out << IND << name << " = " << value << (comma?",":"") << "\n";
}
template<>
void gen_param(std::ostream& out, std::string name, double value, bool comma) {
out << IND << name << " = " << value << (comma?",":"") << "\n";
}
template<>
void gen_param(std::ostream& out, std::string name, bool value, bool comma) {
out << IND << name << " = " << (value ? "True" : "False") << (comma?",":"") << "\n";
}
static void gen_param_id(std::ostream& out, std::string name, std::string id, bool comma) {
out << IND << name << " = " << make_id(id) << (comma?",":"") << "\n";
}
static void gen_param_id(std::ostream& out, std::string name, Json::Value& id, bool comma) {
out << IND << name << " = " << make_id(id.asString()) << (comma?",":"") << "\n";
}
void gen_param_expr(std::ostream& out, std::string name, const std::string& value, bool comma);
// this should be used when printing out floating point values (doubles)
static void gen_param_expr(std::ostream& out, std::string name, Json::Value& value, bool comma) {
gen_param_expr(out, name, value.asString(), comma);
}
static void gen_param_enum(std::ostream& out, std::string name, std::string enum_name, std::string enum_value, bool comma) {
out << IND << name << " = " << make_enum_value(enum_name, enum_value) << (comma?",":"") << "\n";
}
static void gen_param_list(std::ostream& out, std::string name, const std::vector<std::string>& values, bool comma, bool as_strings = false) {
std::string q = (as_strings) ? "'" : "";
out << IND << name << " = [";
for (size_t i = 0; i < values.size(); i++) {
out << q << values[i] << q;
gen_comma(out, i , values);
}
out << "]" << (comma?",":"") << "\n";
}
static void gen_param_list_3_floats(std::ostream& out, std::string name, Json::Value& x, Json::Value& y, Json::Value& z, bool comma) {
out << IND <<
name << " = " <<
"(" << x.asString() << ", " << y.asString() << ", " << z.asString() << ")" << (comma?",":"") << "\n";
}
template<typename T>
static void gen_assign(std::ostream& out, std::string var_name, T value) {
out << var_name << " = " << value << "\n";
}
template<typename T>
static void gen_assign(std::ostream& out, std::string obj_name, std::string field_name1, T value) {
out << obj_name << "." << field_name1 << " = " << value << "\n";
}
template<>
void gen_assign(std::ostream& out, std::string obj_name, std::string field_name1, bool value) {
out << obj_name << "." << field_name1 << " = " << (value ? "True" : "False") << "\n";
}
static void gen_assign_str(std::ostream& out, std::string obj_name, std::string field_name1, std::string value) {
out << obj_name << "." << field_name1 << " = '" << value << "'\n";
}
template<typename T>
static void gen_assign(std::ostream& out, std::string obj_name, std::string field_name1, std::string field_name2, T value) {
out << obj_name << "." << field_name1 << "." << field_name2 << " = " << value << "\n";
}
// for some reason the template above casts double to int..
template<>
void gen_assign(std::ostream& out, std::string obj_name, std::string field_name1, std::string field_name2, double value) {
out << obj_name << "." << field_name1 << "." << field_name2 << " = " << value << "\n";
}
template<>
void gen_assign(std::ostream& out, std::string obj_name, std::string field_name1, std::string field_name2, float value) {
out << obj_name << "." << field_name1 << "." << field_name2 << " = " << value << "\n";
}
template<>
void gen_assign(std::ostream& out, std::string obj_name, std::string field_name1, std::string field_name2, bool value) {
out << obj_name << "." << field_name1 << "." << field_name2 << " = " << (value ? "True" : "False") << "\n";
}
static void gen_assign_vec3(
std::ostream& out, std::string obj_name, std::string field_name1, std::string field_name2,
double x, double y, double z) {
out << obj_name << "." << field_name1 << "." << field_name2 << " = [" << x << ", " << y << ", " << z << "]\n";
}
static void gen_assign_vec3(
std::ostream& out, std::string obj_name, std::string field_name1, std::string field_name2,
float x, float y, float z) {
out << obj_name << "." << field_name1 << "." << field_name2 << " = [" << x << ", " << y << ", " << z << "]\n";
}
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_PYTHON_EXPORT_UTILS_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/compartment_utils.cpp | .cpp | 5,483 | 161 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkTriangle.h>
#include <vtkCleanPolyData.h>
#include <vtkTriangleFilter.h>
#include <vtkSelectEnclosedPoints.h>
#include "compartment_utils.h"
#include "api/api_common.h"
#include "vtk_utils.h"
#include "geometry_object.h"
using namespace std;
namespace MCell {
using namespace VtkUtils;
namespace API {
// note: similar code is in convert_and_set_geometry_object_polydata but uses different input data
static void convert_compartment_objects_to_geom_object_infos(
const std::vector<std::shared_ptr<API::GeometryObject>>& compartment_objects,
GeomObjectInfoVector& compartment_infos) {
bool res = true;
for (const auto& obj_ptr: compartment_objects) {
const API::GeometryObject& obj = *obj_ptr;
// we need to convert each geometry object into VTK's polydata representation
// example: https://vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TriangleArea
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> triangles = vtkSmartPointer<vtkCellArray>::New();
GeomObjectInfo obj_info(obj.name);
obj_info.polydata = vtkSmartPointer<vtkPolyData>::New();
// first collect vertices
uint_set<vertex_index_t> vertex_indices;
for (const std::vector<double>& v: obj.vertex_list) {
assert(v.size() == 3);
points->InsertNextPoint(v[0], v[1], v[2]);
}
// store triangles
for (const std::vector<int>& wi: obj.wall_list) {
assert(wi.size() == VERTICES_IN_TRIANGLE);
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
for (uint i = 0; i < VERTICES_IN_TRIANGLE; i++) {
triangle->GetPointIds()->SetId(i, wi[i]);
}
triangles->InsertNextCell(triangle);
}
// create input polydata
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->SetPolys(triangles);
// clean them up
vtkSmartPointer<vtkTriangleFilter> tri = vtkSmartPointer<vtkTriangleFilter>::New();
tri->SetInputData(polydata);
vtkSmartPointer<vtkCleanPolyData> clean = vtkSmartPointer<vtkCleanPolyData>::New();
clean->SetInputConnection(tri->GetOutputPort());
clean->Update();
int closed = vtkSelectEnclosedPoints::IsSurfaceClosed(clean->GetOutput());
if (closed != 1) {
throw RuntimeError("Compartment object must be closed, error for " + obj.name + ".");
}
// and finally store the points and faces
obj_info.polydata = clean->GetOutput();
compartment_infos.push_back(obj_info);
}
}
static std::shared_ptr<API::GeometryObject> get_obj_by_name(
std::vector<std::shared_ptr<API::GeometryObject>>& compartment_objects,
const string& name) {
for (auto& obj: compartment_objects) {
if (obj->name == name) {
return obj;
}
}
release_assert(false);
return std::shared_ptr<API::GeometryObject>(nullptr);
}
void set_parent_and_children_compartments(
std::vector<std::shared_ptr<API::GeometryObject>>& compartment_objects) {
GeomObjectInfoVector compartment_infos;
convert_compartment_objects_to_geom_object_infos(compartment_objects, compartment_infos);
// get information on what objects are contained within each other
// e.g. CP -> {EC} - CP is contained in EC, mapping contains all compartments, not just the direct parent
ContainmentMap contained_in_mapping;
IntersectingSet intersecting_object_infos;
bool ok = compute_containement_mapping(
nullptr, compartment_infos, contained_in_mapping, intersecting_object_infos);
if (!ok) {
throw RuntimeError("Unexpected error while computing compartment hierarchy.");
}
if (!intersecting_object_infos.empty()) {
string names;
for (const GeomObjectInfo& info: intersecting_object_infos) {
names += info.name + ", ";
}
names = names.substr(0, names.size() - 2); // remove last comma
throw RuntimeError("Error while computing compartment hierarchy, following compartments intersect " +
names + ".");
}
// set children and parents
for (const auto& pair_name_parents: contained_in_mapping) {
auto child = get_obj_by_name(compartment_objects, pair_name_parents.first.name);
// select the direct parent
const GeomObjectInfo* direct_parent_info =
get_direct_parent_info(pair_name_parents.first, contained_in_mapping);
if (direct_parent_info == nullptr) {
// no parent, children set themselves as children of this compartment
}
else {
auto parent = get_obj_by_name(compartment_objects, direct_parent_info->name);
parent->child_compartments.insert(child);
if (is_set(child->parent_compartment)) {
// this should not really occur but lets better report it
throw RuntimeError("Compartment object " + child->name + " cannot have multiple parent compartments " +
child->parent_compartment->name + " and " + parent->name + ".");
}
child->parent_compartment = parent;
}
}
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/mcell4_converter.cpp | .cpp | 68,461 | 1,865 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include <sstream>
#include <iomanip>
#include "mcell4_converter.h"
#include "model.h"
#include "world.h"
#include "release_event.h"
#include "clamp_release_event.h"
#include "viz_output_event.h"
#include "mol_or_rxn_count_event.h"
#include "geometry.h"
#include "rng.h"
#include "isaac64.h"
#include "mcell_structs_shared.h"
#include "custom_function_call_event.h"
#include "bng/bng.h"
#include "api/mcell.h"
#include "api/bindings.h"
#include "api/compartment_utils.h"
#include "api/rng_state.h"
using namespace std;
namespace MCell {
namespace API {
static viz_mode_t convert_viz_mode(const VizMode m) {
switch (m) {
case VizMode::ASCII:
return ASCII_MODE;
case VizMode::CELLBLENDER_V1:
return CELLBLENDER_MODE_V1;
case VizMode::CELLBLENDER:
return CELLBLENDER_MODE_V2;
default:
throw ValueError("Invalid VizMode value " + to_string((int)m) + ".");
}
}
MCell4Converter::MCell4Converter(Model* model_, World* world_) :
model(model_), world(world_),
bng_converter(world_->bng_engine.get_data(), world_->bng_engine.get_config()) {
}
void MCell4Converter::convert_before_init() {
assert(model != nullptr);
assert(world != nullptr);
convert_simulation_setup();
convert_compartments();
convert_elementary_molecule_types();
convert_species();
convert_surface_classes();
convert_rxns();
// find out whether we have a vol vol rxn for all current species (for mcell3 compatibility)
// in BNG mode this finds a reaction as well
// this is an optimization to tell that we don't need to check the
// surroundings of subpartitions in case when there are no vol-vol rxns
// WARNING: must be done before geometry objects are converted because wall_subparts_collision_test
// depends on it
if (!world->get_all_rxns().has_bimol_vol_rxns()) {
// the default is true (or read from user)
world->config.use_expanded_list = false;
}
// at this point, we need to create the first (and for now the only) partition
// create initial partition with center at 0,0,0
partition_id_t index = world->add_partition(world->config.partition0_llf);
assert(index == PARTITION_ID_INITIAL);
convert_geometry_objects();
// - update flags that tell whether we have reactions for all volume/surface species
// and also update molecule type compartment flag
// - must be done after geometry object conversions because
// surface classes might have been defined
world->get_all_rxns().update_all_mols_and_mol_type_compartments();
// we need to schedule the initial release for surfaces before the other releases
world->create_initial_surface_region_release_event();
convert_release_events();
convert_mol_or_rxn_count_events_and_init_counting_flags();
convert_viz_output_events();
// beside of the event checking for check ctrl-c, it is a periodic event for each
// iteration so, in the following call, where time maybe be moved time for scheduler
// when a checkpoint is resumed, we always end up at the starting iteration and do not skip it
// so that later we are not inserting events to the past (from the scheduler's point of view)
add_ctrl_c_termination_event();
// sets up data loaded from checkpoint
convert_initial_iteration_and_time_and_move_scheduler_time();
// some general checks
if (world->config.rxn_radius_3d * POS_SQRT2 >= world->config.subpart_edge_length / 2) {
throw ValueError(S("Reaction radius multiplied by sqrt(2) ") +
to_string(world->config.rxn_radius_3d * world->config.length_unit * POS_SQRT2) +
" must be less than half of subpartition edge length " +
to_string(world->config.subpart_edge_length * world->config.length_unit / 2) + ". " +
"Increase the model's " + NAME_CONFIG + "." + NAME_SUBPARTITION_DIMENSION + ".");
}
check_all_mol_types_have_diffusion_const();
}
species_id_t MCell4Converter::get_species_id_for_complex(
API::Complex& ci, const std::string error_msg, const bool check_orientation) {
// check that the complex instance if fully qualified
BNG::Cplx bng_ci = bng_converter.convert_complex(ci, true, !check_orientation);
if (!bng_ci.is_fully_qualified()) {
// TODO: add test
throw ValueError(
error_msg + ": " + NAME_COMPLEX + " '" + bng_ci.to_str() + "' must be fully qualified " +
"(all components must be present and their state set).");
}
// check that all used elementary molecule types have diffusion constant
for (const BNG::ElemMol& em: bng_ci.elem_mols) {
const BNG::ElemMolType& emt = world->bng_engine.get_data().get_elem_mol_type(em.elem_mol_type_id);
if (emt.D == FLT_INVALID) {
throw RuntimeError("Molecule type '" + emt.name + "' does not have its diffusion constant specified.");
}
}
// we need to define species for our complex instance
BNG::Species s = BNG::Species(
bng_ci,
world->bng_engine.get_data(),
world->bng_engine.get_config()
);
return world->bng_engine.get_all_species().find_or_add(s);
}
species_id_t MCell4Converter::get_species_id(
API::Species& s, const std::string class_name, const std::string object_name) {
if (s.species_id != SPECIES_ID_INVALID) {
return s.species_id;
}
else {
// we fist need to create a complex instance from our species
API::Complex* s_as_cplx_inst = dynamic_cast<API::Complex*>(&s);
return get_species_id_for_complex(*s_as_cplx_inst, class_name + " " + object_name);
}
}
void MCell4Converter::get_geometry_bounding_box(Vec3& llf, Vec3& urb) {
llf = Vec3(DBL_GIGANTIC);
urb = Vec3(-DBL_GIGANTIC);
for (std::shared_ptr<API::GeometryObject>& o: model->geometry_objects) {
// go through all vertices
for (auto& vert: o->vertex_list) {
Vec3 v(vert);
if (v.x < llf.x) {
llf.x = v.x;
}
if (v.x > urb.x) {
urb.x = v.x;
}
if (v.y < llf.y) {
llf.y = v.y;
}
if (v.y > urb.y) {
urb.y = v.y;
}
if (v.z < llf.z) {
llf.z = v.z;
}
if (v.z > urb.z) {
urb.z = v.z;
}
}
}
}
void MCell4Converter::convert_simulation_setup() {
// notifications and reports
const API::Notifications& notifications = model->notifications;
world->config.rxn_and_species_report = notifications.rxn_and_species_report;
world->config.iteration_report = notifications.iteration_report;
world->config.wall_overlap_report = notifications.wall_overlap_report;
world->config.simulation_stats_every_n_iterations = notifications.simulation_stats_every_n_iterations;
world->config.notifications.bng_verbosity_level = notifications.bng_verbosity_level;
world->config.notifications.rxn_probability_changed = notifications.rxn_probability_changed;
// warnings
const API::Warnings& warnings = model->warnings;
assert(warnings.high_reaction_probability != WarningLevel::ERROR);
world->config.warnings.warn_on_bimol_rxn_probability_over_05_less_1 =
warnings.high_reaction_probability == WarningLevel::WARNING;
world->config.molecule_placement_failure = warnings.molecule_placement_failure;
// config
const API::Config& config = model->config;
world->total_iterations = config.total_iterations;
world->config.time_unit = config.time_step;
world->config.use_bng_units = config.use_bng_units;
world->config.initial_time = config.initial_time;
world->config.initial_iteration = config.initial_iteration;
pos_t grid_density = config.surface_grid_density;
world->config.grid_density = grid_density;
pos_t length_unit = 1/sqrt_f(config.surface_grid_density);
world->config.length_unit = length_unit;
if (is_set(config.interaction_radius)) {
// NOTE: mcell3 does not convert the unit of the interaction radius in parser which
// seems a bit weird
world->config.rxn_radius_3d = config.interaction_radius / length_unit;
}
else {
world->config.rxn_radius_3d = world->config.get_default_rxn_radius_3d();
}
if (is_set(config.intermembrane_interaction_radius)) {
// NOTE: mcell3 does not convert the unit of the interaction radius in parser which
// seems a bit weird
world->config.intermembrane_rxn_radius_3d = config.intermembrane_interaction_radius / length_unit;
}
else {
world->config.intermembrane_rxn_radius_3d = (1.0 / sqrt_f(MY_PI * grid_density)) / length_unit;
}
pos_t vacancy_search_dist = config.vacancy_search_distance / length_unit; // Convert units
world->config.vacancy_search_dist2 = vacancy_search_dist * vacancy_search_dist; // and take square
world->config.randomize_smol_pos = !config.center_molecules_on_grid;
world->config.sort_mols_by_subpart = config.sort_molecules;
world->config.check_overlapped_walls = config.check_overlapped_walls;
world->config.initial_seed = config.seed;
rng_init(&world->rng, world->config.initial_seed);
Vec3 llf, urb;
get_geometry_bounding_box(llf, urb);
Vec3 llf_w_margin = llf - Vec3(PARTITION_EDGE_EXTRA_MARGIN_UM);
Vec3 urb_w_margin = urb + Vec3(PARTITION_EDGE_EXTRA_MARGIN_UM);
pos_t llf_partition_dimension_diff = 0;
// TODO: simplify this code to set origin and partition dimensions
pos_t auto_partition_dimension = max3(urb_w_margin) - min3(llf_w_margin);
bool auto_origin_set = false;
if (!is_set(config.initial_partition_origin) && auto_partition_dimension > config.partition_dimension) {
cout <<
"Info: Value of " << NAME_CLASS_MODEL << "." << NAME_CONFIG << "." << NAME_PARTITION_DIMENSION <<
" " << config.partition_dimension <<
" is smaller than the automatically determined value " << auto_partition_dimension <<
", using the automatic value.\n";
world->config.partition_edge_length = auto_partition_dimension / length_unit;
// we need to move the origin, if specified, by half of this increment
llf_partition_dimension_diff =
-(world->config.partition_edge_length - (config.partition_dimension / length_unit)) / 2;
// place origin to the llf of the bounding box
world->config.partition0_llf = (llf - Vec3(PARTITION_EDGE_EXTRA_MARGIN_UM)) / Vec3(length_unit);
auto_origin_set = true;
}
else if (is_set(config.initial_partition_origin) &&
(config.initial_partition_origin[0] > llf_w_margin.x ||
config.initial_partition_origin[1] > llf_w_margin.y ||
config.initial_partition_origin[2] > llf_w_margin.z ||
config.initial_partition_origin[0] + config.partition_dimension < urb_w_margin.x ||
config.initial_partition_origin[1] + config.partition_dimension < urb_w_margin.y ||
config.initial_partition_origin[2] + config.partition_dimension < urb_w_margin.z
)
) {
Vec3 origin(config.initial_partition_origin);
Vec3 llf_diff(0);
if (origin.x > llf_w_margin.x) {
llf_diff.x = origin.x - llf_w_margin.x;
}
if (origin.y > llf_w_margin.y) {
llf_diff.y = origin.y - llf_w_margin.y;
}
if (origin.z > llf_w_margin.z) {
llf_diff.z = origin.z - llf_w_margin.z;
}
llf_partition_dimension_diff = max3(llf_diff);
Vec3 opposite(Vec3(config.initial_partition_origin) + Vec3(config.partition_dimension));
Vec3 urb_diff(0);
if (opposite.x < urb_w_margin.x) {
urb_diff.x = urb_w_margin.x - opposite.x;
}
if (opposite.y < urb_w_margin.y) {
urb_diff.y = urb_w_margin.y - opposite.y;
}
if (opposite.z < urb_w_margin.z) {
urb_diff.z = urb_w_margin.z - opposite.z;
}
pos_t max_urb_diff = max3(urb_diff);
world->config.partition_edge_length =
(config.partition_dimension + llf_partition_dimension_diff + max_urb_diff)/ length_unit;
// we need to move the origin, if specified, by half of this increment
cout <<
"Info: Value of " << NAME_INITIAL_PARTITION_ORIGIN << " " << origin <<
" does not provide enough margin"
" for model's geometry bounding box lower, left, front point " << llf << " "
" and upper, right, back " << urb << "."
" Moving the origin to " << origin - Vec3(llf_partition_dimension_diff) << " and increasing " <<
NAME_PARTITION_DIMENSION << " to " <<
world->config.partition_edge_length * length_unit << ".\n";
}
else {
world->config.partition_edge_length = config.partition_dimension / length_unit;
}
if (is_set(config.initial_partition_origin)) {
// origin set manually
world->config.partition0_llf =
(Vec3(config.initial_partition_origin) - Vec3(llf_partition_dimension_diff)) / Vec3(length_unit);
}
else if (!auto_origin_set) {
// place the partition to the center
world->config.partition0_llf = -Vec3(world->config.partition_edge_length) / Vec3(2);
}
// align the origin to a multiple of subpartition length
pos_t sp_len = config.subpartition_dimension / length_unit;
uint tentative_subparts = world->config.partition_edge_length / sp_len;
if (tentative_subparts > MAX_SUBPARTS_PER_PARTITION) {
cout <<
"Info: Approximate number of subpartitions " << tentative_subparts <<
" is too high, lowering it to a limit of " << MAX_SUBPARTS_PER_PARTITION << ".\n";
sp_len = world->config.partition_edge_length / MAX_SUBPARTS_PER_PARTITION;
}
Vec3 orig_origin = world->config.partition0_llf;
world->config.partition0_llf =
floor_to_multiple_allow_negative_p(orig_origin, sp_len);
// enlarge the partition by size we moved it in order to be aligned
Vec3 llf_moved = orig_origin - world->config.partition0_llf;
pos_t partition_edge_length_enlarged = world->config.partition_edge_length + max3(llf_moved);
world->config.partition_edge_length = ceil_to_multiple_p(partition_edge_length_enlarged, sp_len);
world->config.num_subparts_per_partition_edge =
round_f(world->config.partition_edge_length / sp_len);
// this option in MCell3 was removed in MCell4
world->config.use_expanded_list = true;
// TODO: check that the values are higher than 1
world->config.rxn_class_cleanup_periodicity = config.reaction_class_cleanup_periodicity;
world->config.species_cleanup_periodicity = config.species_cleanup_periodicity;
world->config.molecules_order_random_shuffle_periodicity = config.molecules_order_random_shuffle_periodicity;
world->config.memory_limit_gb = config.memory_limit_gb;
world->config.continue_after_sigalrm = config.continue_after_sigalrm;
// compute other constants and initialize reporting (if enabled)
world->config.init();
}
void MCell4Converter::convert_elementary_molecule_types() {
BNG::BNGData& bng_data = world->bng_engine.get_data();
for (std::shared_ptr<API::ElementaryMoleculeType>& api_mt: model->elementary_molecule_types) {
bng_converter.convert_elementary_molecule_type(*api_mt);
}
}
void MCell4Converter::convert_species() {
for (std::shared_ptr<API::Species>& s: model->species) {
BNG::Species new_species(world->bng_engine.get_data());
new_species.name = s->name;
if (is_set(s->diffusion_constant_3d)) {
new_species.D = s->diffusion_constant_3d;
new_species.set_is_vol();
}
else if (is_set(s->diffusion_constant_2d)) {
new_species.D = s->diffusion_constant_2d;
new_species.set_is_surf();
}
else if (BNG::is_species_superclass(new_species.name)) {
// these values are not really used, they are initialized for comparisons
new_species.D = 0;
new_species.space_step = 0;
new_species.time_step = 0;
}
else {
// this is a declaration of a possibly complex molecule, all used elementary molecules must be defined
if (is_set(s->custom_time_step) || is_set(s->custom_space_step)) {
throw ValueError("Species declaration " + new_species.name + " must not use " +
NAME_CUSTOM_TIME_STEP + " nor " + NAME_CUSTOM_SPACE_STEP + " because it is derived from " +
"its elementary molecule types."
);
}
BNG::Cplx bng_cplx(&world->bng_engine.get_data());
new_species.elem_mols = bng_converter.convert_complex(*s, false, false).elem_mols;
new_species.finalize_species(world->config);
if (!new_species.is_fully_qualified()) {
throw ValueError("Species declaration " + new_species.name + " must use a fully qualified BNGL string for initialization.");
}
// check that all used elementary molecule types have their diffusion constant specified
for (const BNG::ElemMol& em: new_species.elem_mols) {
const BNG::ElemMolType& emt = world->bng_engine.get_data().get_elem_mol_type(em.elem_mol_type_id);
if (emt.D == FLT_INVALID) {
throw ValueError(S("Neither ") + NAME_DIFFUSION_CONSTANT_2D + " nor " +
NAME_DIFFUSION_CONSTANT_3D + " was set for an elementary molecule " + emt.name +
" used in " + NAME_CLASS_SPECIES + " " + s->to_bngl_str() + ".");
}
}
// register and remember which species we created
species_id_t new_species_id = world->get_all_species().find_or_add(new_species);
s->species_id = new_species_id;
// we completely converted this declaration
continue;
}
new_species.set_flag(BNG::SPECIES_MOL_FLAG_TARGET_ONLY, s->target_only); // default is false
// FIXME: the MolType below is created correctly only for simple species
release_assert(s->elementary_molecules.size() <= 1 && "TODO: Complex species");
for (auto& mi: s->elementary_molecules) {
release_assert(mi->components.empty());
}
// find elementary molecule type for our species
// must exist because it was added in Subsystem::unify_and_register_elementary_molecule_types
BNG::elem_mol_type_id_t mol_type_id = world->bng_engine.get_data().find_elem_mol_type_id(s->name);
release_assert(mol_type_id != BNG::ELEM_MOL_TYPE_ID_INVALID);
BNG::ElemMol mol_inst;
mol_inst.elem_mol_type_id = mol_type_id;
new_species.elem_mols.push_back(mol_inst);
new_species.finalize_species(world->config);
species_id_t new_species_id = world->get_all_species().find_or_add(new_species);
// remember which species we created
s->species_id = new_species_id;
// and also set superclass id for container if needed
if (new_species.name == ALL_MOLECULES) {
world->get_all_species().set_all_molecules_ids(new_species_id, mol_type_id);
}
else if (new_species.name == ALL_VOLUME_MOLECULES) {
world->get_all_species().set_all_volume_molecules_ids(new_species_id, mol_type_id);
}
else if (new_species.name == ALL_SURFACE_MOLECULES) {
world->get_all_species().set_all_surface_molecules_ids(new_species_id, mol_type_id);
}
}
}
void MCell4Converter::convert_surface_class_rxn(
API::SurfaceProperty& sp, const BNG::Species& surface_reactant) {
if (sp.type == SurfacePropertyType::REACTIVE) {
// no need to add any reaction because reactions are defined manually
return;
}
BNG::Cplx affected_pattern =
bng_converter.convert_complex(*sp.affected_complex_pattern, false, true);
BNG::RxnRule rxn(&world->bng_engine.get_data());
rxn.name = affected_pattern.to_str() + "+" + surface_reactant.name;
switch (sp.type) {
case API::SurfacePropertyType::ABSORPTIVE:
if (affected_pattern.is_surf()) {
// we are using special type for surf + absorptive surf class
rxn.type = BNG::RxnType::AbsorbRegionBorder;
}
else {
// the type is standard for vol + absorptive surf class
rxn.type = BNG::RxnType::Standard;
}
break;
case API::SurfacePropertyType::CONCENTRATION_CLAMP:
rxn.type = BNG::RxnType::Standard;
rxn.set_flag(BNG::RXN_FLAG_CREATED_FOR_CONCENTRATION_CLAMP);
break;
case API::SurfacePropertyType::FLUX_CLAMP:
rxn.type = BNG::RxnType::Reflect;
rxn.set_flag(BNG::RXN_FLAG_CREATED_FOR_FLUX_CLAMP);
break;
case API::SurfacePropertyType::REFLECTIVE:
rxn.type = BNG::RxnType::Reflect;
break;
case API::SurfacePropertyType::TRANSPARENT:
rxn.type = BNG::RxnType::Transparent;
break;
default:
throw ValueError("Invalid SurfaceProperty type for " + surface_reactant.name + ".");
}
// all these reactions happen always
rxn.base_rate_constant = DBL_GIGANTIC;
// any compartment of the
affected_pattern.set_compartment_id(BNG::COMPARTMENT_ID_NONE);
// NONE is ANY in rxns
orientation_t orient = convert_api_orientation(sp.affected_complex_pattern->orientation, true);
rxn.append_reactant(affected_pattern);
rxn.append_reactant(surface_reactant); // copies the input reactant
// this is the default orientation used for surfaces in a reaction
rxn.reactants[1].set_orientation(ORIENTATION_UP);
// add reaction and remember mapping
sp.rxn_rule_id = world->get_all_rxns().add_and_finalize(rxn);
}
void MCell4Converter::convert_surface_classes() {
for (std::shared_ptr<API::SurfaceClass>& sc: model->surface_classes) {
// each surface class is represented by a species
BNG::Species sc_species(world->bng_engine.get_data());
sc_species.name = sc->name;
sc_species.set_is_reactive_surface();
// sets steps to 0
sc_species.space_step = 0;
sc_species.time_step = 0;
sc_species.D = FLT_INVALID; // diffusion constant has no meaning for surface classes
// we must add a complex instance as the single molecule type in the new species
// define a molecule type with no components
BNG::ElemMolType mol_type;
mol_type.name = sc_species.name; // name of the mol type is the same as for our species
mol_type.set_is_reactive_surface();
BNG::elem_mol_type_id_t mol_type_id = world->bng_engine.get_data().find_or_add_elem_mol_type(mol_type);
BNG::ElemMol mol_inst;
mol_inst.elem_mol_type_id = mol_type_id;
sc_species.elem_mols.push_back(mol_inst);
// we do not care about compartments for surface classes
sc_species.set_compartment_id(BNG::COMPARTMENT_ID_NONE);
sc_species.finalize_species(world->config, false);
species_id_t new_species_id = world->get_all_species().find_or_add(sc_species);
// remember which species we created
sc->species_id = new_species_id;
// and we also need to add a reaction for each property
if (sc->properties.empty()) {
convert_surface_class_rxn(*dynamic_pointer_cast<SurfaceProperty>(sc), sc_species);
}
else {
for (shared_ptr<SurfaceProperty>& sp: sc->properties) {
convert_surface_class_rxn(*sp, sc_species);
}
}
}
}
void MCell4Converter::check_intermembrane_surface_reaction(const BNG::RxnRule& rxn) {
if (rxn.reactants.size() !=2 || rxn.products.size() != 2) {
throw ValueError("Intermembrane reaction must have exactly 2 reactants and 2 products, error for " +
rxn.to_str() + ".");
}
if (!rxn.reactants[0].is_surf() || !rxn.reactants[1].is_surf() ||
!rxn.products[0].is_surf() || !rxn.products[1].is_surf()) {
throw ValueError("Intermembrane reaction's reactants and products must be all surface complexes, error for " +
rxn.to_str() + ".");
}
// TODO: check compartments?
}
void MCell4Converter::convert_rxns() {
BNG::BNGData& bng_data = world->bng_engine.get_data();
for (std::shared_ptr<API::ReactionRule>& r: model->reaction_rules) {
bool is_reversible = is_set(r->rev_rate);
BNG::RxnRule rxn(&bng_data);
rxn.type = BNG::RxnType::Standard;
if (is_set(r->fwd_rate)) {
rxn.base_rate_constant = r->fwd_rate;
}
else {
assert(!r->variable_rate.empty());
for (auto& time_and_rate: r->variable_rate) {
assert(time_and_rate.size() == 2);
BNG::RxnRateInfo info;
info.time = time_and_rate[0] / world->config.time_unit;
info.rate_constant = time_and_rate[1];
rxn.base_variable_rates.push_back(info);
}
rxn.update_variable_rxn_rate(0, nullptr);
}
for (std::shared_ptr<API::Complex>& rinst: r->reactants) {
// convert to BNG::ComplexInstance using existing or new BNG::molecule_id
BNG::Cplx reactant = bng_converter.convert_complex(*rinst, false, true);
rxn.append_reactant(reactant);
}
for (std::shared_ptr<API::Complex>& pinst: r->products) {
// convert to BNG::ComplexInstance using existing or new BNG::molecule_id
BNG::Cplx product = bng_converter.convert_complex(*pinst, false, true);
rxn.append_product(product);
}
// sets also flags for reactants and products
rxn.finalize();
if (r->is_intermembrane_surface_reaction) {
check_intermembrane_surface_reaction(rxn);
rxn.set_is_intermembrane_surf_rxn();
// orientation is ANY in this case, we might need to update it later
// TODO: add warning if user specified explicit orientation
rxn.reactants[0].set_orientation(ORIENTATION_NONE);
rxn.reactants[1].set_orientation(ORIENTATION_NONE);
}
string error_msg = BNG::process_compartments_and_set_orientations(bng_data, rxn);
if (error_msg != "") {
throw ValueError(error_msg);
}
if (is_set(r->name)) {
rxn.name = r->name;
}
else {
// must be called after conversion
rxn.set_automatic_name(false);
}
// reverse reaction
BNG::RxnRule rxn_rev(&bng_data);
if (is_reversible) {
rxn_rev.type = BNG::RxnType::Standard;
rxn_rev.base_rate_constant = r->rev_rate;
rxn_rev.reactants = rxn.products;
rxn_rev.products = rxn.reactants;
if (r->is_intermembrane_surface_reaction) {
rxn.set_is_intermembrane_surf_rxn();
rxn.reactants[0].set_orientation(ORIENTATION_NONE);
rxn.reactants[1].set_orientation(ORIENTATION_NONE);
}
rxn_rev.finalize();
string error_msg = BNG::process_compartments_and_set_orientations(bng_data, rxn_rev);
if (error_msg != "") {
throw ValueError(error_msg);
}
if (is_set(r->rev_name)) {
rxn.name = r->rev_name;
}
else {
rxn.set_automatic_name(false);
}
}
// add reaction(s) and remember mapping
r->fwd_rxn_rule_id = world->get_all_rxns().add_and_finalize(rxn);
if (is_reversible) {
r->rev_rxn_rule_id = world->get_all_rxns().add_and_finalize(rxn_rev);
}
// the ReactionRule object also need the world pointer
r->world = world;
}
}
MCell::wall_index_t MCell4Converter::convert_wall_and_add_to_geom_object(
const API::GeometryObject& src_obj, const uint side,
MCell::Partition& p, MCell::GeometryObject& dst_obj) {
assert(src_obj.wall_list[side].size() == 3);
// TODO LATER: there is really no reason to add walls in two steps,
// can be simplified
MCell::Wall& wall = p.add_uninitialized_wall(world->get_next_wall_id());
wall.object_id = dst_obj.id;
wall.object_index = dst_obj.index;
wall.side = side;
for (uint i = 0; i < VERTICES_IN_TRIANGLE; i++) {
wall.vertex_indices[i] = src_obj.vertex_indices[src_obj.wall_list[side][i]];
}
wall.initialize_wall_constants(p);
// add wall to subpartitions
dst_obj.wall_indices.push_back(wall.index);
return wall.index;
}
void MCell4Converter::convert_initial_surface_releases(
const std::vector<std::shared_ptr<API::InitialSurfaceRelease>>& api_releases,
std::vector<MCell::InitialSurfaceReleases>& mcell_releases
) {
for (auto api_rel: api_releases) {
species_id_t species_id =
get_species_id_for_complex(*api_rel->complex, NAME_CLASS_INITIAL_SURFACE_RELEASE);
orientation_t orientation = convert_api_orientation(api_rel->complex->orientation);
if (is_set(api_rel->number_to_release)) {
if (api_rel->number_to_release > (double)UINT32_MAX) {
throw ValueError(S("Value for ") + NAME_NUMBER_TO_RELEASE + " of a " +
NAME_CLASS_INITIAL_SURFACE_RELEASE + " " + to_string(api_rel->number_to_release) +
" is too high, the maximum allowed is " + to_string(UINT32_MAX) + ".");
}
mcell_releases.push_back(
InitialSurfaceReleases(species_id, orientation, true, (uint)api_rel->number_to_release)
);
}
else if (is_set(api_rel->density)) {
mcell_releases.push_back(
InitialSurfaceReleases(species_id, orientation, false, (double)api_rel->density)
);
}
else {
assert(false);
}
}
}
void MCell4Converter::convert_concentration_clamp_release(
const partition_id_t partition_id, const API::SurfaceClass& surface_class, const MCell::Region& mcell_region) {
release_assert(surface_class.properties.empty() && "TODO");
ClampReleaseEvent* clamp_event = new ClampReleaseEvent(world);
if (surface_class.type == SurfacePropertyType::CONCENTRATION_CLAMP) {
clamp_event->type = ClampType::CONCENTRATION;
}
else if (surface_class.type == SurfacePropertyType::FLUX_CLAMP) {
clamp_event->type = ClampType::FLUX;
}
else {
assert(false);
}
// run each timestep
clamp_event->event_time = 0;
clamp_event->periodicity_interval = 1;
// which species to clamp
clamp_event->species_id = get_species_id_for_complex(
*surface_class.affected_complex_pattern,
S(NAME_CLASS_SURFACE_CLASS) + ", attribute " + NAME_AFFECTED_COMPLEX_PATTERN,
false);
// on which side
clamp_event->orientation =
convert_api_orientation(surface_class.affected_complex_pattern->orientation, true, true);
assert(world->bng_engine.get_all_species().get(surface_class.species_id).is_reactive_surface());
clamp_event->surf_class_species_id = surface_class.species_id;
clamp_event->concentration = surface_class.concentration;
// walls where to release
assert(!mcell_region.walls_and_edges.empty() && "Must be initialized");
// we are inserting the walls ordered by their wall index
for (const auto& pair_wi_edges: mcell_region.walls_and_edges) {
clamp_event->cumm_area_and_pwall_index_pairs.push_back(
CummAreaPWallIndexPair(0, PartitionWallIndexPair(partition_id, pair_wi_edges.first)));
}
clamp_event->update_cumm_areas_and_scaling();
// and schedule
world->scheduler.schedule_event(clamp_event);
}
MCell::region_index_t MCell4Converter::convert_surface_region(
MCell::Partition& p,
API::SurfaceRegion& surface_region, API::GeometryObject& o,
MCell::GeometryObject& obj) {
MCell::Region reg;
reg.name = obj.name + "," + surface_region.name;
reg.geometry_object_id = obj.id;
// simply add all walls
for (const int wall_in_object: surface_region.wall_indices) {
wall_index_t wi = o.wall_indices[wall_in_object];
reg.add_wall_to_walls_and_edges(wi, false);
}
if (is_set(surface_region.surface_class)) {
assert(surface_region.surface_class->species_id != SPECIES_ID_INVALID);
reg.species_id = surface_region.surface_class->species_id;
// define releases for concentration clamp
if (surface_region.surface_class->is_clamp()) {
convert_concentration_clamp_release(p.id, *surface_region.surface_class, reg);
}
}
if (is_set(surface_region.initial_surface_releases)) {
convert_initial_surface_releases(
surface_region.initial_surface_releases,
reg.initial_region_molecules
);
}
reg.init_surface_region_edges(p);
reg.id = world->get_next_region_id();
surface_region.region_id = reg.id;
region_index_t ri = p.add_region_and_set_its_index(reg);
return ri;
}
void MCell4Converter::convert_geometry_objects() {
MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL); // only partition 0 is supported for now
for (std::shared_ptr<API::GeometryObject>& o: model->geometry_objects) {
// set surface region parents
for (auto& sr: o->surface_regions) {
// not using shared pointers here, any attempt so far resulted in bad_weak_ptr exception
// this is safe because the geometry object (parent) has a reference to the surface region
sr->parent = o.get();
}
MCell::GeometryObject& obj = p.add_uninitialized_geometry_object(world->get_next_geometry_object_id());
obj.name = o->name;
obj.parent_name = ""; // empty, we do not really care
o->geometry_object_id = obj.id;
if (is_set(o->initial_color)) {
// set default color
obj.default_color = o->initial_color->rgba;
}
// vertices
// remember the "offset" from the first vertex in the target partition
o->first_vertex_index = p.get_geometry_vertex_count();
for (auto& v: o->vertex_list) {
// add to partition and remember its index
// must use rcp_length_unit to be identical to mcell4 with mdl
vertex_index_t vi =
p.add_geometry_vertex(Vec3(v[0], v[1], v[2]) * Vec3(world->config.rcp_length_unit));
o->vertex_indices.push_back(vi);
}
// walls (validity of indices is checked in API::GeometryObject::check_semantics)
o->first_wall_index = p.get_walls().size();
for (size_t i = 0; i < o->wall_list.size(); i++) {
wall_index_t wi = convert_wall_and_add_to_geom_object(*o, i, p, obj);
o->wall_indices.push_back(wi);
}
// initialize edges
obj.initialize_neighboring_walls_and_their_edges(p);
vector<region_index_t> region_indices;
// region "ALL"
MCell::Region reg_all;
reg_all.init_from_whole_geom_object(obj);
reg_all.id = world->get_next_region_id();
// TODO: move surf class handling code to a function and share with convert_surface_region
if (is_set(o->surface_class)) {
if (o->surface_class->species_id == SPECIES_ID_INVALID) {
throw RuntimeError("Geometry object " + o->name + " is using surface class " + o->surface_class->name +
" but this surface class was not added to the model. To add it, use method Model.add_surface_class or Subsystem.add_surface_class.");
}
reg_all.species_id = o->surface_class->species_id;
// define releases for concentration clamp
if (o->surface_class->is_clamp()) {
convert_concentration_clamp_release(p.id, *o->surface_class, reg_all);
}
}
if (is_set(o->initial_surface_releases)) {
convert_initial_surface_releases(o->initial_surface_releases, reg_all.initial_region_molecules);
}
region_index_t ri_all = p.add_region_and_set_its_index(reg_all);
region_indices.push_back(ri_all);
// we must remember that this region represents the whole object
obj.encompassing_region_id = reg_all.id;
// regions from surface areas
// mcell3 stores the regions in reverse, so we can too...
// (maybe change this in the mcell3 converter)
for (int k = (int)o->surface_regions.size() - 1; k >= 0; k--) {
std::shared_ptr<SurfaceRegion> surface_region = o->surface_regions[k];
region_index_t ri = convert_surface_region(p, *surface_region, *o, obj);
region_indices.push_back(ri);
// also set colors if they were specified
if (is_set(surface_region->initial_color)) {
rgba_t color = surface_region->initial_color->rgba;
for (wall_index_t wi: surface_region->wall_indices) {
obj.wall_specific_colors[o->get_partition_wall_index(wi)] = color;
}
}
}
// also set regions for walls
for (wall_index_t wi: obj.wall_indices) {
MCell::Wall& w = p.get_wall(wi);
for (region_index_t ri: region_indices) {
MCell::Region& reg = p.get_region(ri);
if (reg.walls_and_edges.count(wi) == 1) {
w.regions.insert(ri);
obj.regions.insert(ri);
}
}
}
// set MCell:GeometryObject compartment ids
if (o->is_bngl_compartment) {
assert(o->vol_compartment_id != BNG::COMPARTMENT_ID_INVALID &&
o->vol_compartment_id != BNG::COMPARTMENT_ID_NONE
);
obj.vol_compartment_id = o->vol_compartment_id;
if (is_set(o->surface_compartment_name)) {
assert(o->surf_compartment_id != BNG::COMPARTMENT_ID_INVALID);
obj.surf_compartment_id = o->surf_compartment_id;
}
}
}
for (MCell::GeometryObject& obj: p.get_geometry_objects()) {
obj.initialize_is_fully_transparent(p);
}
// check overlapped walls
// uses random generator state
if (world->config.check_overlapped_walls) {
bool ok = world->check_for_overlapped_walls();
if (!ok) {
throw ValueError("Walls in geometry overlap, more details were printed in the previous message.");
}
}
// check that no overlapped object is a BNGL compartment
for (MCell::GeometryObject& obj: p.get_geometry_objects()) {
if (obj.has_overlapped_walls && obj.vol_compartment_id != BNG::COMPARTMENT_ID_NONE) {
throw ValueError("Overlapped geometry object " + obj.name + " is set to be a BNGL compartment, this is not allowed.");
}
}
p.finalize_walls();
}
void MCell4Converter::check_surface_compartment_name_collision(const std::string& surface_compartment_name) {
for (std::shared_ptr<API::GeometryObject>& o: model->geometry_objects) {
for (std::shared_ptr<API::SurfaceRegion>& s: o->surface_regions) {
// o->wall_indices contains all the walls (with values counted from 0), so if size is the same
// the contents are the same
if (s->name == surface_compartment_name && o->wall_list.size() != s->wall_indices.size()) {
throw RuntimeError("Geometry object's " + o->name + " surface region " + s->name + " uses the same name "
"as a compartment, but the surface region does not represent the whole surface of the object. "
"This is not allowed because it would lead to inconsistencies when comparing to BNGL variant of the model. "
"Please use a different name either for the surface region or for the compartment.");
}
}
}
}
void MCell4Converter::convert_compartments() {
// we determine the hierarchy of compartments here since all
// we have are geometry objects
// volume of compartments is not set
BNG::BNGData& bng_data = world->bng_engine.get_data();
vector<std::shared_ptr<API::GeometryObject>> compartment_objects;
for (std::shared_ptr<API::GeometryObject>& o: model->geometry_objects) {
if (o->is_bngl_compartment) {
compartment_objects.push_back(o);
}
}
// set hierarchy of compartments
set_parent_and_children_compartments(compartment_objects);
for (std::shared_ptr<API::GeometryObject>& o: compartment_objects) {
BNG::Compartment bng_comp3d;
bng_comp3d.name = o->name;
bng_comp3d.is_3d = true;
BNG::compartment_id_t comp3d_id = bng_data.add_compartment(bng_comp3d);
o->vol_compartment_id = comp3d_id;
// unlike as in BNG, we do not require that the only child of a 3d compartment is 2d compartment,
// 2d compartments can be skipped completely
if (is_set(o->surface_compartment_name)) {
// check that there is no SurfaceRegion with this name
// this might be supported one day but now the surface compartment must be the whole
// surface of the object, reported in redmine as #28
check_surface_compartment_name_collision(o->surface_compartment_name);
BNG::Compartment bng_comp2d;
bng_comp2d.name = o->surface_compartment_name;
bng_comp2d.is_3d = false;
// the only child of a 2D compartment is the 3D compartment it encompasses
bng_comp2d.children_compartments.insert(comp3d_id);
BNG::compartment_id_t comp2d_id = bng_data.add_compartment(bng_comp2d);
o->surf_compartment_id = comp2d_id;
// if a 2d compartment is defined, it is the parent of the 3D compartment
bng_data.get_compartment(comp3d_id).parent_compartment_id = comp2d_id;
}
}
// now define their parents and children
for (std::shared_ptr<API::GeometryObject>& o: compartment_objects) {
BNG::Compartment* bng_comp3d;
bng_comp3d = bng_data.find_compartment(o->name);
release_assert(bng_comp3d != nullptr);
for (const std::shared_ptr<API::GeometryObject>& child: o->child_compartments) {
BNG::Compartment* bng_comp_child;
// the direct child is the 2d compartment if defined, 3d compartment otherwise
if (is_set(child->surface_compartment_name)) {
bng_comp_child = bng_data.find_compartment(child->surface_compartment_name);
release_assert(bng_comp_child != nullptr);
}
else {
bng_comp_child = bng_data.find_compartment(child->name);
release_assert(bng_comp_child != nullptr);
}
bng_comp3d->children_compartments.insert(bng_comp_child->id);
bng_comp_child->parent_compartment_id = bng_comp3d->id;
}
}
}
static MCell::RegionExprOperator convert_region_node_type(API::RegionNodeType t) {
switch (t) {
case API::RegionNodeType::LEAF_GEOMETRY_OBJECT:
return MCell::RegionExprOperator::LEAF_GEOMETRY_OBJECT;
case API::RegionNodeType::LEAF_SURFACE_REGION:
return MCell::RegionExprOperator::LEAF_SURFACE_REGION;
case API::RegionNodeType::UNION:
return MCell::RegionExprOperator::UNION;
case API::RegionNodeType::DIFFERENCE:
return MCell::RegionExprOperator::DIFFERENCE;
case API::RegionNodeType::INTERSECT:
return MCell::RegionExprOperator::INTERSECT;
default:
assert(false);
return MCell::RegionExprOperator::INVALID;
}
}
RegionExprNode* MCell4Converter::convert_region_expr_recursively(
const shared_ptr<API::Region>& region,
const bool is_vol,
const bool release_not_count, // for error message purposes
MCell::RegionExpr& region_expr
) {
string msg_detail;
if (release_not_count) {
msg_detail = S(" referenced by a ") + NAME_CLASS_RELEASE_SITE + " object";
}
else {
msg_detail = S(" referenced by a ") + NAME_CLASS_COUNT + " object";
}
assert(is_set(region));
if (region->node_type == RegionNodeType::LEAF_GEOMETRY_OBJECT) {
shared_ptr<API::GeometryObject> geometry_object = dynamic_pointer_cast<API::GeometryObject>(region);
assert(is_set(geometry_object));
if (is_vol) {
if (geometry_object->geometry_object_id == GEOMETRY_OBJECT_ID_INVALID) {
throw RuntimeError("Could not find geometry object with name " + geometry_object->name + msg_detail +
", it might not have been added to the model.");
}
return region_expr.create_new_expr_node_leaf_geometry_object(geometry_object->geometry_object_id);
}
else {
const MCell::Region* reg = world->find_region_by_name(geometry_object->name + MCell::REGION_ALL_SUFFIX_W_COMMA);
if (reg == nullptr) {
throw RuntimeError("Could not find region representing object with name " + geometry_object->name + msg_detail +
", it might not have been added to the model.");
}
return region_expr.create_new_expr_node_leaf_surface_region(reg->id);
}
}
else if (region->node_type == RegionNodeType::LEAF_SURFACE_REGION) {
if (is_vol) {
// TODO: message needs more details
string msg;
if (release_not_count) {
msg = "Cannot release volume molecule onto a surface region .";
}
else {
msg = "Cannot count volume molecules or reactions on a surface region .";
}
throw RuntimeError(msg + "The problematic region is:\n" + region->to_str());
}
shared_ptr<API::SurfaceRegion> surface_region = dynamic_pointer_cast<API::SurfaceRegion>(region);
assert(is_set(surface_region));
const MCell::Region* reg = world->find_region_by_name(surface_region->parent->name + "," + surface_region->name);
if (reg == nullptr) {
throw RuntimeError("Could not find region with name " + surface_region->parent->name + msg_detail +
", it might not have been added to the model.");
}
return region_expr.create_new_expr_node_leaf_surface_region(reg->id);
}
else {
return region_expr.create_new_region_expr_node_op(
convert_region_node_type(region->node_type),
convert_region_expr_recursively(region->left_node, is_vol, release_not_count, region_expr),
convert_region_expr_recursively(region->right_node, is_vol, release_not_count, region_expr)
);
}
}
void MCell4Converter::convert_rel_site_region_expr(API::ReleaseSite& rel_site, MCell::ReleaseEvent* rel_event) {
const BNG::Species& species = world->get_all_species().get(rel_event->species_id);
if (rel_site.shape == Shape::COMPARTMENT && !is_set(rel_site.complex->compartment_name)) {
// this should not happen
throw RuntimeError("Compartment for release site " + rel_site.name + " was not set.");
}
if (rel_site.shape == Shape::REGION_EXPR) {
if (!is_set(rel_site.region)) {
throw RuntimeError("Region for release site " + rel_site.name + " was not set.");
}
rel_event->region_expr.root = convert_region_expr_recursively(
rel_site.region, species.is_vol(), true, rel_event->region_expr);
// add intersection with compartment if this is a volume compartment
if (is_set(rel_site.complex->compartment_name)) {
// TODO: how to handle surface compartment intersection?
// obj is nullptr when this is not a volume compartment
const auto& obj = model->find_volume_compartment_object(rel_site.complex->compartment_name);
if (is_set(obj)) {
auto region = model->get_compartment_region(rel_site.complex->compartment_name);
RegionExprNode* compartment_region = convert_region_expr_recursively(
region, species.is_vol(), true, rel_event->region_expr);
// overwrite region expr with intersection with compartment
rel_event->region_expr.root = rel_event->region_expr.create_new_region_expr_node_op(
RegionExprOperator::INTERSECT,
rel_event->region_expr.root,
compartment_region
);
}
}
}
else if (rel_site.shape == Shape::COMPARTMENT) {
if (!is_set(rel_site.complex->compartment_name)) {
throw RuntimeError("Compartment for release site " + rel_site.name + " was not set.");
}
// make region that represents the compartment
auto region = model->get_compartment_region(rel_site.complex->compartment_name);
if (!is_set(region)) {
throw RuntimeError("Compartment " + rel_site.complex->compartment_name + " for " + rel_site.name + " was not found.");
}
rel_event->region_expr.root = convert_region_expr_recursively(
region, species.is_vol(), true, rel_event->region_expr);
}
// also set llf and urb
// TODO: this does not check anything yet
bool ok = Geometry::compute_region_expr_bounding_box(world, rel_event->region_expr.root, rel_event->region_llf, rel_event->region_urb);
if (!ok) {
throw RuntimeError("Region for releases specified by " + rel_event->region_expr.root->to_string(world) + " is not closed.");
}
}
void MCell4Converter::convert_molecule_list(
const std::vector<std::shared_ptr<MoleculeReleaseInfo>>& molecule_list,
const std::string& rel_site_name,
MCell::ReleaseEvent* rel_event) {
for (auto& item: molecule_list) {
MCell::SingleMoleculeReleaseInfo info;
info.species_id = get_species_id_for_complex(
*item->complex, S(NAME_CLASS_RELEASE_SITE) + " '" + rel_site_name + "'");
assert(item->location.size() == 3);
info.pos.x = item->location[0] * world->config.rcp_length_unit;
info.pos.y = item->location[1] * world->config.rcp_length_unit;
info.pos.z = item->location[2] * world->config.rcp_length_unit;
bool is_vol = world->get_all_species().get(info.species_id).is_vol();
info.orientation = convert_api_orientation(item->complex->orientation, true, is_vol); // not set is not allowed
if (world->get_all_species().get(info.species_id).is_vol() &&
rel_event->orientation != ORIENTATION_NONE && rel_event->orientation != ORIENTATION_NOT_SET) {
throw ValueError(
S(NAME_CLASS_RELEASE_SITE) + " " + rel_site_name + " releases a volume molecule but orientation is set.");
}
rel_event->molecule_list.push_back(info);
}
}
MCell::ReleaseEvent* MCell4Converter::convert_single_release_event(
const std::shared_ptr<API::ReleaseSite>& r) {
MCell::ReleaseEvent* rel_event = new ReleaseEvent(world);
rel_event->release_site_name = r->name;
if (!is_set(r->molecule_list)) {
assert(is_set(r->complex));
rel_event->species_id = get_species_id_for_complex(
*r->complex, S(NAME_CLASS_RELEASE_SITE) + " '" + r->name + "'");
bool is_vol = world->get_all_species().get(rel_event->species_id).is_vol();
rel_event->orientation = convert_api_orientation(r->complex->orientation, true, is_vol);
if (world->get_all_species().get(rel_event->species_id).is_surf() &&
rel_event->orientation != ORIENTATION_UP && rel_event->orientation != ORIENTATION_DOWN &&
rel_event->orientation != ORIENTATION_NONE) { // none = random orientation
throw ValueError(
S(NAME_CLASS_RELEASE_SITE) + " " + r->name +
" releases a surface molecule but orientation is not set to a valid value.");
}
if (is_vol &&
rel_event->orientation != ORIENTATION_NONE && rel_event->orientation != ORIENTATION_NOT_SET) {
throw ValueError(
S(NAME_CLASS_RELEASE_SITE) + " " + r->name +
" releases a volume molecule but orientation is set.");
}
}
rel_event->delay = r->release_time / world->config.time_unit;
// release pattern
if (is_set(r->release_pattern)) {
API::ReleasePattern rp = *r->release_pattern;
rel_event->number_of_trains = rp.number_of_trains;
rel_event->train_interval = rp.train_interval / world->config.time_unit;
rel_event->train_duration = rp.train_duration / world->config.time_unit;
rel_event->release_interval = rp.release_interval / world->config.time_unit;
}
// release_number_method
if (is_set(r->number_to_release)) {
if (r->number_to_release > (double)UINT32_MAX) {
throw ValueError(S("Value ") + to_string(r->number_to_release) + " for " +
NAME_NUMBER_TO_RELEASE + " of a " + NAME_CLASS_RELEASE_SITE + " '" + r->name +
"' is too high, the maximum allowed is " + to_string(UINT32_MAX) + ".");
}
rel_event->release_number_method = ReleaseNumberMethod::CONST_NUM;
rel_event->release_number = r->number_to_release;
}
else if (is_set(r->density)) {
rel_event->release_number_method = ReleaseNumberMethod::DENSITY_NUM;
rel_event->concentration = r->density;
}
else if (is_set(r->concentration)) {
rel_event->release_number_method = ReleaseNumberMethod::CONCENTRATION_NUM;
rel_event->concentration = r->concentration;
}
else if (is_set(r->molecule_list)) {
rel_event->release_number_method = ReleaseNumberMethod::CONST_NUM;
convert_molecule_list(r->molecule_list, r->name, rel_event);
}
else {
throw RuntimeError(
S("The only supported release number type now is constant number specified with ") + NAME_NUMBER_TO_RELEASE + "."
);
}
// release_shape
switch (r->shape) {
case Shape::SPHERICAL:
rel_event->release_shape = ReleaseShape::SPHERICAL;
assert(r->location.size() == 3);
rel_event->location = Vec3(r->location) * world->config.rcp_length_unit;
rel_event->diameter = r->site_diameter * world->config.rcp_length_unit;
break;
case Shape::REGION_EXPR:
case Shape::COMPARTMENT: {
rel_event->release_shape = ReleaseShape::REGION;
convert_rel_site_region_expr(*r, rel_event);
bool ok = rel_event->initialize_walls_for_release();
if (!ok) {
throw RuntimeError("Only simple surface regions are supported for surface releases currently, error for " + r->name + ".");
}
}
break;
case Shape::LIST:
rel_event->release_shape = ReleaseShape::LIST;
rel_event->diameter = r->site_diameter * world->config.rcp_length_unit;
break;
rel_event->release_shape = ReleaseShape::REGION;
break;
default:
// should be caught earlier
throw RuntimeError(S("The only supported shapes now are ") +
NAME_EV_SPHERICAL + ", " + NAME_EV_REGION_EXPR + ", " + NAME_EV_COMPARTMENT + " and " + NAME_EV_LIST + ".");
}
rel_event->release_probability = r->release_probability;
return rel_event;
}
void MCell4Converter::convert_release_events() {
for (std::shared_ptr<API::ReleaseSite>& r: model->release_sites) {
MCell::ReleaseEvent* rel_event = convert_single_release_event(r);
// schedule it
rel_event->update_event_time_for_next_scheduled_time();
world->scheduler.schedule_event(rel_event);
}
}
static void set_geometry_objects_are_used_in_mol_rxn_counts_recursively(
World* world, MCell::RegionExprNode* node) {
if (node->op == RegionExprOperator::LEAF_GEOMETRY_OBJECT) {
world->get_geometry_object(node->geometry_object_id).set_is_used_in_mol_rxn_counts();
}
else if (node->has_binary_op()) {
set_geometry_objects_are_used_in_mol_rxn_counts_recursively(world, node->left);
set_geometry_objects_are_used_in_mol_rxn_counts_recursively(world, node->right);
}
else {
release_assert(false && "Surface regions cannot be used here");
}
}
// appends new term to the vector terms, does not clear it
void MCell4Converter::convert_count_term_leaf_and_init_counting_flags(
const std::shared_ptr<API::CountTerm> ct,
const int sign,
MolOrRxnCountTermVector& terms
) {
MCell::MolOrRxnCountTerm res;
res.sign_in_expression = sign;
assert(is_set(ct));
assert(ct->node_type == API::ExprNodeType::LEAF);
if (is_set(ct->species_pattern) || is_set(ct->molecules_pattern)) {
if (is_set(ct->species_pattern)) {
res.species_pattern_type = SpeciesPatternType::SpeciesPattern;
res.species_molecules_pattern = bng_converter.convert_complex(*ct->species_pattern, true);
}
else {
res.species_pattern_type = SpeciesPatternType::MoleculesPattern;
res.species_molecules_pattern = bng_converter.convert_complex(*ct->molecules_pattern, true);
}
// to maintain compatibility with BioNetGen counting, we must remove the primary compartment
// from elementary molecules and keep it separately, e.g.: pattern @PM:V(s!1).S(v!1)
// which is after being read from BNGL in reality V(s!1)@PM.S(v!1)@PM must match
// V(s!1)@CP.S(v!1)@PM, therefore if we make the pattern to be V(s!1).S(v!1) + PM, it will match
res.primary_compartment_id = res.species_molecules_pattern.get_primary_compartment_id();
res.species_molecules_pattern.remove_compartment_from_elem_mols(res.primary_compartment_id);
bool is_vol = res.species_molecules_pattern.is_vol();
string name = res.species_molecules_pattern.to_str();
res.orientation = res.species_molecules_pattern.get_orientation();
if (is_set(ct->region)) {
if (is_vol) {
res.type = MCell::CountType::EnclosedInVolumeRegion;
res.region_expr.root = convert_region_expr_recursively(ct->region, is_vol, false, res.region_expr);
// and also mark the objects that we are counting molecules inside
set_geometry_objects_are_used_in_mol_rxn_counts_recursively(world, res.region_expr.root);
}
else {
// surf mols
res.type = MCell::CountType::PresentOnSurfaceRegion;
res.region_expr.root = convert_region_expr_recursively(ct->region, is_vol, false, res.region_expr);
// these are only surface regions and there is no need to set that they are counted
}
}
else {
res.type = MCell::CountType::EnclosedInWorld;
}
}
else if (is_set(ct->reaction_rule))
{
assert(!is_set(ct->reaction_rule->rev_rate));
res.rxn_rule_id = ct->reaction_rule->fwd_rxn_rule_id;
// is this a surface rxn? -> at least one of the reactants is a surface mol
BNG::RxnRule* rxn = world->get_all_rxns().get(res.rxn_rule_id);
if (is_set(ct->region)) {
// TODO: what about counting reactions with surface classes?
bool is_vol = !rxn->is_surf_rxn();
if (is_vol) {
// volume reaction
res.type = MCell::CountType::RxnCountInVolumeRegion;
rxn->set_is_counted_in_volume_regions();
res.region_expr.root = convert_region_expr_recursively(ct->region, is_vol, false, res.region_expr);
set_geometry_objects_are_used_in_mol_rxn_counts_recursively(world, res.region_expr.root);
}
else {
// surface reaction
res.type = MCell::CountType::RxnCountOnSurfaceRegion;
rxn->set_is_counted_on_surface_regions();
res.region_expr.root = convert_region_expr_recursively(ct->region, is_vol, false, res.region_expr);
// these are only surface regions and there is no need to set that they are counted
}
}
else {
res.type = MCell::CountType::RxnCountInWorld;
rxn->set_is_counted_in_world();
}
// remember the initial reactions count when resuming from a checkpoint, default is 0
res.initial_reactions_count = ct->initial_reactions_count;
}
else {
assert(false);
}
terms.push_back(res);
}
void MCell4Converter::convert_count_terms_recursively(
const std::shared_ptr<API::Count> count, // only for warning printouts
const std::shared_ptr<API::CountTerm> ct,
const int sign,
MCell::MolOrRxnCountItem& info
) {
assert(is_set(ct));
if (ct->node_type == API::ExprNodeType::LEAF) {
convert_count_term_leaf_and_init_counting_flags(ct, sign, info.terms);
}
else if (ct->node_type == API::ExprNodeType::ADD || ct->node_type == API::ExprNodeType::SUB) {
if (is_set(ct->region)) {
warns() << "Object " << NAME_CLASS_COUNT << " with " << NAME_NAME << " '" << count->name <<
"' and " << NAME_FILE_NAME << " '" << count->file_name << "' uses a " << NAME_CLASS_COUNT_TERM <<
" that has a " << NAME_REGION << " set. This region will be ignored because regions are allowed" <<
" only for leaf " << NAME_CLASS_COUNT_TERM << " objects.\n" <<
"This is the problematic " << NAME_CLASS_COUNT << " object:\n" <<
count->to_str() << "\n" <<
"-- end of warning message reporting ignored region --\n";
}
convert_count_terms_recursively(count, ct->left_node, sign, info);
int next_sign;
if (ct->node_type == API::ExprNodeType::SUB) {
next_sign = -sign;
}
else {
next_sign = sign;
}
convert_count_terms_recursively(count, ct->right_node, next_sign, info);
}
else {
// cannot really happen
throw RuntimeError("Invalid node_type in CountTerm.");
}
}
void MCell4Converter::convert_mol_or_rxn_count_events_and_init_counting_flags() {
// collect counts with gdat format outputting to the same file
std::map<std::string, vector<uint>> gdat_filename_to_count_indices;
for (uint i = 0 ; i < model->counts.size(); i++) {
std::shared_ptr<API::Count>& c = model->counts[i];
// set default file_name if not set
if (!is_set(c->file_name)) {
c->file_name = "./react_data/" + get_seed_dir_name(model->config.seed) + "/" + c->name + ".dat";
}
if (c->output_format == CountOutputFormat::AUTOMATIC_FROM_EXTENSION) {
throw RuntimeError(S(NAME_CLASS_COUNT) + "'s " + NAME_OUTPUT_FORMAT + " must not be " +
NAME_ENUM_COUNT_OUTPUT_FORMAT + "." + NAME_EV_AUTOMATIC_FROM_EXTENSION + " when the model is initialized. "
"The automatic detection should have already happened.");
}
if (c->output_format != CountOutputFormat::GDAT) {
continue;
}
auto it = gdat_filename_to_count_indices.find(c->file_name);
if (it == gdat_filename_to_count_indices.end()) {
gdat_filename_to_count_indices[c->file_name].push_back(i);
}
else {
it->second.push_back(i);
}
}
// create GDAT output buffers
std::map<std::string, pair<count_buffer_id_t, uint>> gdat_count_name_to_buffer_id_and_column_index;
for (const auto& pair_fname_indices: gdat_filename_to_count_indices) {
// prepare names for this single gdat buffer
// also check that the sampling interval is the same
assert(pair_fname_indices.second.size() >= 1);
double every_n_timesteps = model->counts[pair_fname_indices.second[0]]->every_n_timesteps;
vector<string> names;
for (uint i: pair_fname_indices.second){
std::shared_ptr<API::Count>& c = model->counts[i];
if (c->every_n_timesteps != every_n_timesteps) {
throw RuntimeError(S("When multiple ") + NAME_CLASS_COUNT + " objects output to the same .gdat file, " +
"their sampling intervals set by " + NAME_EVERY_N_TIMESTEPS + " must be identical, error for " +
c->name + ".");
}
names.push_back(c->name);
}
count_buffer_id_t buffer_id =
world->create_gdat_count_buffer(
pair_fname_indices.first, names,
API::DEFAULT_COUNT_BUFFER_SIZE, model->config.append_to_count_output_data);
// these are local column indices and must start from 0
for (uint i = 0; i < pair_fname_indices.second.size(); i++){
// however tpo get the count we must use the global index
std::shared_ptr<API::Count>& c = model->counts[pair_fname_indices.second[i]];
gdat_count_name_to_buffer_id_and_column_index[c->name] = make_pair(buffer_id, i);
}
}
// and convert the count objects
for (const std::shared_ptr<API::Count>& c: model->counts) {
MCell::MolOrRxnCountEvent* count_event = new MCell::MolOrRxnCountEvent(world);
count_event->event_time = 0;
count_event->periodicity_interval = round_f(c->every_n_timesteps + EPS);
// create buffer
vector<string> column_names = {c->name};
count_buffer_id_t buffer_id;
uint column_index;
if (c->output_format == CountOutputFormat::DAT) {
buffer_id = world->create_dat_count_buffer(
c->file_name, API::DEFAULT_COUNT_BUFFER_SIZE, model->config.append_to_count_output_data);
column_index = 0;
}
else {
auto it = gdat_count_name_to_buffer_id_and_column_index.find(c->name);
assert(it != gdat_count_name_to_buffer_id_and_column_index.end());
buffer_id = it->second.first;
column_index = it->second.second;
}
MCell::MolOrRxnCountItem info(buffer_id, column_index);
// process count terms
convert_count_terms_recursively(c, c->expression, +1, info);
info.multiplier = c->multiplier;
// having multiple MolOrRxnCountInfo per MolOrRxnCountEvent
// was useful for MCell3 conversion, however for pymcell4 each count is a separate event
count_event->add_mol_count_item(info);
// remember for get_current_value calls
c->count_event = count_event;
if (c->every_n_timesteps > 0) {
// 0 means that the event won't be ever rescheduled,
// if it were added to the schedule it would be executed once and then deleted
world->scheduler.schedule_event(count_event);
}
else {
world->add_unscheduled_count_event(count_event);
}
}
}
void MCell4Converter::convert_viz_output_events() {
for (std::shared_ptr<API::VizOutput>& v: model->viz_outputs) {
MCell::VizOutputEvent* viz_event = new VizOutputEvent(world);
viz_event->event_time = 0.0;
viz_event->periodicity_interval = round_f(v->every_n_timesteps + EPS);
viz_event->viz_mode = convert_viz_mode(v->mode);
if (!is_set(v->output_files_prefix)) {
v->output_files_prefix = "./viz_data/" + get_seed_dir_name(model->config.seed) + "/Scene";
}
viz_event->file_prefix_name = v->output_files_prefix;
if (is_set(v->species_list)) {
for (std::shared_ptr<API::Species>& s: v->species_list) {
viz_event->species_ids_to_visualize.insert(
get_species_id(*s, NAME_CLASS_VIZ_OUTPUT, NAME_SPECIES_LIST));
}
}
else {
viz_event->visualize_all_species = true;
}
world->scheduler.schedule_event(viz_event);
}
}
// sets up data loaded from checkpoint, must be run after all events were added to the scheduler
// rng state is set after model initialization in Model::initialize
void MCell4Converter::convert_initial_iteration_and_time_and_move_scheduler_time() {
if ((model->config.initial_iteration != 0) != (model->config.initial_time != 0)) {
throw RuntimeError(S("Both ") + NAME_INITIAL_ITERATION + " and " + NAME_INITIAL_TIME +
" must be either 0 or both must be greater than 0.");
}
world->stats.set_current_iteration(model->config.initial_iteration);
// skips all events, fails if some periodic events are scheduled
world->scheduler.skip_events_up_to_time(
world->config.get_simulation_start_time()
);
}
void MCell4Converter::add_ctrl_c_termination_event() {
MCell::CustomFunctionCallEvent<World*>* event =
new CustomFunctionCallEvent<World*>(check_ctrl_c, world);
event->event_time = world->config.get_simulation_start_time();
event->periodicity_interval = 1;
world->scheduler.schedule_event(event);
}
void MCell4Converter::check_all_mol_types_have_diffusion_const() {
for (const BNG::ElemMolType& mt: world->bng_engine.get_data().get_elem_mol_types()) {
if (!mt.is_reactive_surface() && mt.D == FLT_INVALID) {
throw RuntimeError("Molecule type '" + mt.name + "' does not have its diffusion constant specified.");
}
}
}
// must be called after world initialization
void MCell4Converter::convert_after_init() {
convert_rng_state();
convert_checkpointed_molecules();
}
void MCell4Converter::convert_rng_state() {
if (!is_set(model->config.initial_rng_state)) {
return; // nothing to do
}
std::shared_ptr<RngState>& src = model->config.initial_rng_state;
rng_state& dst = world->rng;
dst.randcnt = src->randcnt;
dst.aa = src->aa;
dst.bb = src->bb;
dst.cc = src->cc;
assert(RANDSIZ == RNG_SIZE);
assert(src->randslr.size() == RNG_SIZE);
std::copy(src->randslr.begin(), src->randslr.end(), dst.randrsl);
assert(src->mm.size() == RNG_SIZE);
std::copy(src->mm.begin(), src->mm.end(), dst.mm);
dst.rngblocks = src->rngblocks;
}
void MCell4Converter::convert_checkpointed_molecules() {
// single partition for now
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
uint_set<MCell::molecule_id_t> used_mol_ids;
// add each mol
for (const shared_ptr<BaseChkptMol>& m: model->checkpointed_molecules) {
MCell::Molecule res_m;
// base data
if (used_mol_ids.count(m->id) != 0) {
throw RuntimeError("Checkpointed molecule with ID " + to_string(m->id) + " was already added.");
}
res_m.id = m->id;
if (m->species->species_id == SPECIES_ID_INVALID) {
throw RuntimeError("Species " + m->species->name + " for checkpointed molecule is not present in the model.");
}
res_m.species_id = m->species->species_id;
// TODO: check that the times are not in the past
res_m.diffusion_time = m->diffusion_time / world->config.time_unit;
res_m.birthday = m->birthday / world->config.time_unit;
// TODO: check that the flags make sense
res_m.flags = m->flags;
if (is_set(m->unimol_rxn_time)) {
res_m.unimol_rxn_time = m->unimol_rxn_time / world->config.time_unit;
}
else {
res_m.unimol_rxn_time = TIME_INVALID;
}
if (m->type == MoleculeType::VOLUME) {
res_m.reset_vol_data();
const shared_ptr<ChkptVolMol>& vm = dynamic_pointer_cast<ChkptVolMol>(m);
res_m.v.pos = vm->pos * Vec3(world->config.rcp_length_unit);
p.add_volume_molecule(res_m, 0);
}
else {
res_m.reset_surf_data();
assert(m->type == MoleculeType::SURFACE);
const shared_ptr<ChkptSurfMol>& sm = dynamic_pointer_cast<ChkptSurfMol>(m);
res_m.s.pos = sm->pos * Vec2(world->config.rcp_length_unit);
res_m.s.orientation = convert_api_orientation(sm->orientation, false);
res_m.s.wall_index = sm->geometry_object->get_partition_wall_index(sm->wall_index);
res_m.s.grid_tile_index = sm->grid_tile_index;
// we must initialize grid and register the molecule there
MCell::Wall& w = p.get_wall(res_m.s.wall_index);
if (!w.has_initialized_grid()) {
w.initialize_grid(p);
}
w.grid.set_molecule_tile(res_m.s.grid_tile_index, res_m.id);
p.add_surface_molecule(res_m, 0);
}
}
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/surface_region.h | .h | 1,220 | 53 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_SURFACE_REGION_H
#define API_SURFACE_REGION_H
#include "generated/gen_surface_region.h"
#include "api/api_common.h"
#include "defines.h"
namespace MCell {
namespace API {
class GeometryObject;
class SurfaceRegion: public GenSurfaceRegion {
public:
SURFACE_REGION_CTOR()
void postprocess_in_ctor() {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
Region::set_all_custom_attributes_to_default();
region_type = RegionType::SURFACE;
region_id = REGION_ID_INVALID;
node_type = RegionNodeType::LEAF_SURFACE_REGION;
parent = nullptr;
}
// set during model initialization
GeometryObject* parent;
// simulation engine mapping
region_id_t region_id;
};
} // namespace API
} // namespace MCell
#endif // API_SURFACE_REGION_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/subsystem.h | .h | 2,825 | 102 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_SUBSYSTEM_H
#define API_SUBSYSTEM_H
#include <functional>
#include "generated/gen_subsystem.h"
#include "api/api_common.h"
#include "api/api_utils.h"
#include "api/species.h"
#include "api/surface_class.h"
#include "api/reaction_rule.h"
namespace BNG {
class ElemMolType;
class RxnRule;
class Cplx;
}
namespace MCell {
namespace API {
class Complex;
class Subsystem: public GenSubsystem {
public:
SUBSYSTEM_CTOR()
// from generated template
void add_species(std::shared_ptr<Species> s) override {
append_to_vec_canonical_name(species, s);
}
std::shared_ptr<Species> find_species(const std::string& name) override {
return vec_find_by_name(species, name);
}
void add_reaction_rule(std::shared_ptr<ReactionRule> r) override {
// reactions don't have to have name
append_to_vec_canonical_name(reaction_rules, r);
}
std::shared_ptr<ReactionRule> find_reaction_rule(const std::string& name) override {
return vec_find_by_name(reaction_rules, name);
}
void add_surface_class(std::shared_ptr<SurfaceClass> sc) override {
append_to_vec(surface_classes, sc);
}
std::shared_ptr<SurfaceClass> find_surface_class(const std::string& name) override {
return vec_find_by_name(surface_classes, name);
}
void add_elementary_molecule_type(std::shared_ptr<ElementaryMoleculeType> mt) override {
append_to_vec_canonical_name(elementary_molecule_types, mt);
}
std::shared_ptr<ElementaryMoleculeType> find_elementary_molecule_type(const std::string& name) override {
return vec_find_by_name(elementary_molecule_types, name);
}
void load_bngl_molecule_types_and_reaction_rules(
const std::string& file_name,
const std::map<std::string, double>& parameter_overrides = std::map<std::string, double>()
) override;
// added manually
// may return nullptr
std::shared_ptr<Species> get_species_with_id(const species_id_t id);
// go through all species and make sure that
// 1) all identical elementary molecule type objects exist only once and
// 2) all are also in the elementary_molecule_types array
void unify_and_register_elementary_molecule_types();
void dump() const;
protected:
void convert_bng_data_to_subsystem_data(const BNG::BNGData& bng_data);
private:
void convert_reaction_rule(const BNG::BNGData& bng_data, const BNG::RxnRule& bng_rr);
};
} // namespace API
} // namespace MCell
#endif // API_SUBSYSTEM_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/api_utils.cpp | .cpp | 2,233 | 87 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/api_utils.h"
#include <time.h>
#include <string>
using namespace std;
namespace MCell {
namespace API {
Orientation convert_mcell_orientation(const orientation_t o) {
switch (o) {
case ORIENTATION_DOWN:
return Orientation::DOWN;
case ORIENTATION_NONE:
return Orientation::NONE;
case ORIENTATION_UP:
return Orientation::UP;
case ORIENTATION_NOT_SET:
return Orientation::NOT_SET;
default:
assert(false);
return Orientation::NOT_SET;
}
}
orientation_t convert_api_orientation(const Orientation o, const bool allow_default, const bool is_vol) {
switch (o) {
case Orientation::DEFAULT:
if (!allow_default) {
throw ValueError("Invalid Orientation value " + to_string((int)o) + " (DEFAULT).");
}
if (is_vol) {
return ORIENTATION_NONE;
}
else {
return ORIENTATION_UP;
}
case Orientation::DOWN:
return ORIENTATION_DOWN;
case Orientation::NONE:
return ORIENTATION_NONE;
case Orientation::UP:
return ORIENTATION_UP;
case Orientation::NOT_SET:
throw ValueError("Invalid Orientation value " + to_string((int)o) + ".");
case Orientation::ANY:
return ORIENTATION_NONE;
default:
throw ValueError("Invalid Orientation value " + to_string((int)o) + ".");
}
}
bool is_simple_species(const std::string& name) {
// complex species always contain a parenthesis in their name
return name.find('(') == std::string::npos;
}
// get current date/time, format is YYYY-MM-DD HH:mm:ss
const std::string get_current_date_time() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct);
return buf;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/molecule_release_info.h | .h | 932 | 36 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_MOLECULE_RELEASE_INFO_H
#define API_MOLECULE_RELEASE_INFO_H
#include "generated/gen_molecule_release_info.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class MoleculeReleaseInfo: public GenMoleculeReleaseInfo {
public:
MOLECULE_RELEASE_INFO_CTOR()
void check_semantics() const override {
if (location.size() != 3) {
throw ValueError(S("Value of ") + NAME_LOCATION + " must be a triplet of floats.");
}
}
};
} // namespace API
} // namespace MCell
#endif // API_MOLECULE_RELEASE_INFO_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/wall_wall_hit_info.h | .h | 741 | 30 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_WALL_WALL_HIT_INFO_H
#define API_WALL_WALL_HIT_INFO_H
#include "generated/gen_wall_wall_hit_info.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class WallWallHitInfo: public GenWallWallHitInfo {
public:
WALL_WALL_HIT_INFO_CTOR_NOARGS()
};
} // namespace API
} // namespace MCell
#endif // API_WALL_WALL_HIT_INFO_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/surface_class.h | .h | 1,750 | 66 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_SURFACE_CLASS_H
#define API_SURFACE_CLASS_H
#include "generated/gen_surface_class.h"
#include "api/api_common.h"
#include "api/surface_property.h"
namespace MCell {
namespace API {
class SurfaceClass: public GenSurfaceClass {
public:
SURFACE_CLASS_CTOR()
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
SurfaceProperty::set_all_custom_attributes_to_default();
species_id = SPECIES_ID_INVALID;
}
void check_semantics() const override {
GenSurfaceClass::check_semantics(); // does not call further derived classes
if (properties.empty()) {
SurfaceProperty::check_semantics_custom();
}
else {
// type of used properties must be set
for (std::shared_ptr<SurfaceProperty> property: properties) {
property->check_semantics_custom();
}
}
}
bool __eq__(const SurfaceClass& other) const override;
// added methods
bool is_clamp() const {
return type == SurfacePropertyType::CONCENTRATION_CLAMP ||
type == SurfacePropertyType::FLUX_CLAMP;
}
// simulation engine mapping
// this is the species_id created for this surface class, not for the affected species
species_id_t species_id;
};
} // namespace API
} // namespace MCell
#endif // API_SURFACE_CLASS_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/component_type.cpp | .cpp | 1,708 | 73 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/component_type.h"
#include <set>
using namespace std;
namespace MCell {
namespace API {
bool ComponentType::__eq__(const ComponentType& other) const {
return
eq_nonarray_attributes(other) &&
std::set<string>(states.begin(), states.end()) ==
std::set<string>(other.states.begin(), other.states.end());
}
std::string ComponentType::to_bngl_str() const {
std::string res;
res = name;
for (const string& s: states) {
res += "~" + s;
}
return res;
}
// useful when we need to put component types to a set
bool ComponentType::operator < (const ComponentType& other) const {
if (name == other.name) {
if (!__eq__(other)) {
throw RuntimeError(
"Cannot define ordering (less) between " + to_bngl_str() + " and " + other.to_bngl_str() + ", "
"they have the same name but different states. " +
"Error might have occurred due to a call to " + NAME_CLASS_ELEMENTARY_MOLECULE_TYPE + ".__eq__().");
}
return false;
}
else {
return name < other.name;
}
}
std::string ComponentType::get_canonical_name() const {
std::string res;
res = name;
set<string> sorted(states.begin(), states.end());
for (const string& s: sorted) {
res += "~" + s;
}
return res;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/geometry_object.h | .h | 3,554 | 109 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_GEOMETRY_OBJECT_H
#define API_GEOMETRY_OBJECT_H
#include "bng/bng_defines.h"
#include "generated/gen_geometry_object.h"
#include "api/api_common.h"
#include "api/surface_region.h"
#include "defines.h"
namespace MCell {
namespace API {
class GeometryObject;
typedef std::set<std::shared_ptr<API::GeometryObject>> GeometryObjectSet;
class GeometryObject: public GenGeometryObject {
public:
GEOMETRY_OBJECT_CTOR()
public:
void postprocess_in_ctor() override;
void set_all_custom_attributes_to_default() override;
void check_semantics() const override;
void translate(const std::vector<double> move) override;
// using shorter printout when all_details is false
std::string to_str(const bool all_details=false, const std::string ind="") const override;
// --- added manually ---
void check_is_initialized() {
if (geometry_object_id == GEOMETRY_OBJECT_ID_INVALID) {
throw RuntimeError("Geometry object " + name + " is not present in model (or model was not initialized).");
}
}
vertex_index_t get_partition_vertex_index(const int vertex_index) const {
check_vertex_index(vertex_index);
return first_vertex_index + vertex_index;
}
int get_object_vertex_index(const vertex_index_t vertex_index) const {
int res = vertex_index - first_vertex_index;
assert(res >= 0 && res < (int)vertex_list.size());
return res;
}
wall_index_t get_partition_wall_index(const int wall_index) const {
check_wall_index(wall_index);
return first_wall_index + wall_index;
}
int get_object_wall_index(const wall_index_t wall_index) const {
int res = wall_index - first_wall_index;
assert(res >= 0 && res < (int)wall_list.size());
return res;
}
private:
void check_vertex_index(const int vertex_index) const {
if (vertex_index < 0 || vertex_index >= (int)vertex_list.size()) {
throw RuntimeError(
"Vertex index " + std::to_string(vertex_index) + " is out of range for " + NAME_VERTEX_LIST + " of " + name + ".");
}
}
void check_wall_index(const int wall_index) const {
if (wall_index < 0 || wall_index >= (int)wall_list.size()) {
throw RuntimeError(
"Vertex index " + std::to_string(wall_index) + " is out of range for " + NAME_VERTEX_LIST + " of " + name + ".");
}
}
public:
// extra information used in MCell4 converter
// if this is a compartment, its parent and children are set
// in API::set_children_compartments
std::shared_ptr<API::GeometryObject> parent_compartment;
GeometryObjectSet child_compartments;
// simulation engine mapping
partition_id_t partition_id;
geometry_object_id_t geometry_object_id;
vertex_index_t first_vertex_index; // index of the first vertex created in partition for this object
wall_index_t first_wall_index;
std::vector<vertex_index_t> vertex_indices; // vertex_list[i] has vertex index vertex_indices[i]
std::vector<wall_index_t> wall_indices; // wall_list[i] has wall index wall_indices[i]
BNG::compartment_id_t vol_compartment_id;
BNG::compartment_id_t surf_compartment_id;
};
} // namespace API
} // namespace MCell
#endif // API_GEOMETRY_OBJECT_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/reaction_info.h | .h | 1,568 | 64 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_VOLUME_REACTION_INFO_H
#define API_VOLUME_REACTION_INFO_H
#include "generated/gen_reaction_info.h"
#include "api/api_common.h"
#include "bng/bng_defines.h"
namespace MCell {
namespace API {
class ReactionInfo: public GenReactionInfo {
public:
void dump() {
std::cout << to_str();
}
ReactionInfo() {
set_all_custom_attributes_to_default();
}
ReactionInfo(DefaultCtorArgType) {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() {
// setting all (also inherited) attributes
rxn_rule_id = BNG::RXN_RULE_ID_INVALID;
geometry_object_id = GEOMETRY_OBJECT_ID_INVALID;
partition_wall_index = WALL_INDEX_INVALID;
// inherited attributes
type = ReactionType::UNSET;
reaction_rule = nullptr;
time = FLT_UNSET;
pos3d.clear();
geometry_object = nullptr;
wall_index = -1;
pos2d.clear();
}
// extra information to be converted in Callbacks
BNG::rxn_rule_id_t rxn_rule_id;
geometry_object_id_t geometry_object_id; // to geometry_object
wall_index_t partition_wall_index;
};
} // namespace API
} // namespace MCell
#endif // API_VOLUME_REACTION_INFO_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/rng_state.cpp | .cpp | 935 | 37 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/rng_state.h"
#include "rng.h"
using namespace std;
namespace MCell {
namespace API {
RngState::RngState(const rng_state& rng) {
assert(RNG_SIZE == RANDSIZ);
randcnt = rng.randcnt;
aa = rng.aa;
bb = rng.bb;
cc = rng.cc;
cc = rng.cc;
std::copy(&rng.randrsl[0], &rng.randrsl[RANDSIZ], std::back_inserter(randslr));
std::copy(&rng.mm[0], &rng.mm[RANDSIZ], std::back_inserter(mm));
rngblocks = rng.rngblocks; // counter for simulation stats, does not affect simulation
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/chkpt_surf_mol.h | .h | 1,233 | 54 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_CHKPT_SURF_MOL_H
#define API_CHKPT_SURF_MOL_H
#include "generated/gen_chkpt_surf_mol.h"
#include "api/api_common.h"
#include "api/base_chkpt_mol.h"
namespace MCell {
class Partition;
class Molecule;
namespace API {
class ChkptSurfMol: public GenChkptSurfMol {
public:
CHKPT_SURF_MOL_CTOR()
ChkptSurfMol(
const MCell::Molecule& sm,
const IdSpeciesMap& id_species_map, const double time_unit,
const double length_unit,
const MCell::Partition& p,
const IdGeometryObjectMap& id_geometry_object_map);
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
type = MoleculeType::SURFACE;
}
virtual ~ChkptSurfMol() {
}
};
} // namespace API
} // namespace MCell
#endif // API_CHKPT_SURF_MOL_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/color.cpp | .cpp | 1,669 | 62 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/color.h"
#include "geometry.h"
namespace MCell {
namespace API {
void Color::postprocess_in_ctor() {
if (is_set(red) && is_set(green) && is_set(blue) && is_set(alpha)) {
check_component_range(red, NAME_RED);
check_component_range(green, NAME_GREEN);
check_component_range(blue, NAME_BLUE);
check_component_range(alpha, NAME_ALPHA);
components_to_rgba();
}
else {
bool any_component_set = is_set(red) || is_set(green) || is_set(blue);
if (any_component_set) {
throw ValueError(S("Either all individual color components must be set or none in initialization of ") +
NAME_CLASS_COLOR + ".");
}
rgba_to_components();
}
}
void Color::check_component_range(const double value, const char* name) {
if (value < 0 || value > 1) {
throw ValueError(S("Value of color component ") + name + " must be within 0..1.");
}
}
void Color::components_to_rgba() {
const int MAX = 255;
rgba =
(((uint)(red * MAX) & 0xFF) << 24) |
(((uint)(green * MAX) & 0xFF) << 16) |
(((uint)(blue * MAX) & 0xFF) << 8) |
(((uint)(alpha * MAX)) & 0xFF);
}
void Color::rgba_to_components() {
Geometry::rgba_to_components(rgba, red, green, blue, alpha);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/release_site.h | .h | 5,077 | 139 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_RELEASE_SITE_H
#define API_RELEASE_SITE_H
#include "generated/gen_release_site.h"
#include "api/molecule_release_info.h"
#include "api/api_common.h"
#include "api/complex.h"
#include "bng/bng_defines.h"
namespace MCell {
namespace API {
class ReleaseSite: public GenReleaseSite {
public:
RELEASE_SITE_CTOR()
void postprocess_in_ctor() override {
if (is_set(region) && shape != Shape::REGION_EXPR) {
if (shape != Shape::UNSET) {
throw ValueError(S("When ") + NAME_REGION + " is set, "
"shape must be either unset or set to " + NAME_ENUM_SHAPE + "." + NAME_EV_REGION_EXPR + ".");
}
shape = Shape::REGION_EXPR;
}
if (is_set(complex) && is_set(complex->get_primary_compartment_name()) &&
shape != Shape::COMPARTMENT && shape != Shape::REGION_EXPR) {
if (shape != Shape::UNSET) {
throw ValueError(S("When ") + NAME_COMPARTMENT_NAME + " is set, "
"shape must be either unset or set to " + NAME_ENUM_SHAPE + "." + NAME_EV_COMPARTMENT + " or " +
NAME_ENUM_SHAPE + "." + NAME_EV_REGION_EXPR + ".");
}
shape = Shape::COMPARTMENT;
}
if (is_set(molecule_list) && shape != Shape::LIST) {
if (shape != Shape::UNSET) {
throw ValueError(S("When ") + NAME_MOLECULE_LIST + " is set, "
"shape must be either unset or set to " + NAME_ENUM_SHAPE + "." + NAME_EV_LIST + ".");
}
shape = Shape::LIST;
}
if (is_set(location) && shape != Shape::SPHERICAL) {
if (shape != Shape::UNSET) {
throw ValueError(S("When ") + NAME_LOCATION + " is set, "
"shape must be either unset or set to " + NAME_ENUM_SHAPE + "." + NAME_EV_SPHERICAL + ".");
}
shape = Shape::SPHERICAL;
}
if (release_probability < 0 || release_probability > 1) {
throw ValueError(S("Parameter ") + NAME_RELEASE_PROBABILITY + " must be >= 0 and <= 1.");
}
}
void check_semantics() const override {
// TODO: add additional checks, e.g. that site_diameter must can be set only for SPHERICAL, etc.
GenReleaseSite::check_semantics();
if (release_time < 0) {
throw ValueError(S("Value of ") + NAME_RELEASE_TIME + " must not be smaller than 0.");
}
if (get_num_set(site_diameter, site_radius) > 1) {
throw ValueError(S("Only either ") + NAME_SITE_DIAMETER + " or " + NAME_SITE_RADIUS + " can be set.");
}
if (get_num_set(number_to_release, density, concentration, molecule_list) != 1) {
throw ValueError(
S("Exactly one of ") + NAME_NUMBER_TO_RELEASE + ", " + NAME_DENSITY + ", " + NAME_CONCENTRATION +
" or " + NAME_MOLECULE_LIST + " must be set.");
}
if (shape != Shape::REGION_EXPR && get_num_set(number_to_release, density, concentration) == 1 &&
(number_to_release < 0 || density < 0 || concentration < 0)) {
const char* attribute_name;
if (is_set(number_to_release)) {
attribute_name = NAME_NUMBER_TO_RELEASE;
}
else if (is_set(density)) {
attribute_name = NAME_DENSITY;
}
else if (is_set(concentration)) {
attribute_name = NAME_CONCENTRATION;
}
else {
release_assert(false);
}
throw ValueError(
S("Negative release value of ") + attribute_name + " may be set only when " + NAME_REGION + " is set.");
}
if (get_num_set(complex, molecule_list) != 1) {
throw ValueError(
S("Exactly one of ") + NAME_COMPLEX + " or " + NAME_MOLECULE_LIST + " must be set.");
}
if (shape == Shape::COMPARTMENT &&
BNG::get_in_or_out_compartment_id(complex->compartment_name) != BNG::COMPARTMENT_ID_INVALID) {
throw ValueError(
S(NAME_CLASS_RELEASE_SITE) + " must not use compartment class name " + complex->compartment_name + ".");
}
if ( (shape == Shape::COMPARTMENT && get_num_set(region, molecule_list, location) != 0) &&
(shape != Shape::COMPARTMENT && get_num_set(region, molecule_list, location) != 1)
) {
throw ValueError(
S("Either compartment or exactly one of ") + NAME_REGION + ", " + NAME_MOLECULE_LIST +
" or " + NAME_LOCATION + " must be set.");
}
if (shape == Shape::SPHERICAL && !is_set(location)) {
throw ValueError(
S("When ") + NAME_SHAPE + " is set to " + NAME_ENUM_SHAPE + "." + NAME_EV_LIST +
" " + NAME_LOCATION + " must be set.");
}
if (is_set(location) && location.size() != 3) {
throw ValueError(S("Argument ") + NAME_LOCATION + " must be a list containing 3 floats.");
}
}
};
} // namespace API
} // namespace MCell
#endif // API_RELEASE_SITE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/wall.h | .h | 732 | 33 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_WALL_H
#define API_WALL_H
#include "generated/gen_wall.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class Wall: public GenWall {
public:
WALL_CTOR_NOARGS()
// -- overrides ---
void set_is_movable(const bool new_is_movable_) override;
};
} // namespace API
} // namespace MCell
#endif // API_WALL_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/run_utils.cpp | .cpp | 2,325 | 96 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "generated/gen_run_utils.h"
#include "bng/filesystem_utils.h"
#include "api/api_utils.h"
#include "generated/gen_names.h"
#include "bng/bng_defines.h"
#include "src4/simulation_config.h"
using namespace std;
namespace MCell {
namespace API {
namespace run_utils {
std::string get_last_checkpoint_dir(const int seed) {
// only supported parameter is seed for now
string chkpt_seed_dir =
DEFAULT_CHECKPOINTS_DIR + BNG::PATH_SEPARATOR + get_seed_dir_name(seed);
string max_it_dir_name = "";
// do we have a checkpoints/seed directory?
if (FSUtils::is_dir(chkpt_seed_dir)) {
// find the highest iteration value
int max = -1;
std::vector<std::string> dirs;
FSUtils::list_dir(chkpt_seed_dir, dirs);
for (const string& dir_name: dirs) {
// starts with "it_"?
if (dir_name.find(DEFAULT_ITERATION_DIR_PREFIX) == 0) {
string it_nr_str = dir_name.substr(
DEFAULT_ITERATION_DIR_PREFIX.size(), dir_name.size() - DEFAULT_ITERATION_DIR_PREFIX.size());
int it_nr;
try {
it_nr = stoi(it_nr_str);
}
catch (invalid_argument&) {
continue;
}
if (it_nr > max) {
// remember the directory with the highest iteration number so far
max = it_nr;
max_it_dir_name = dir_name;
}
}
}
}
if (max_it_dir_name != "") {
return chkpt_seed_dir + BNG::PATH_SEPARATOR + max_it_dir_name + BNG::PATH_SEPARATOR;
}
else {
return "";
}
}
std::vector<std::string> remove_cwd(const std::vector<std::string> paths) {
std::vector<std::string> res;
// skip everything that can be interpreted as current directory
string cwd = FSUtils::get_current_dir();
for (const string& p: paths) {
if (p != "" && p != "." && p != cwd) {
res.push_back(p);
}
}
return res;
}
} // namespace run_utils
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/model.cpp | .cpp | 23,576 | 723 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "model.h"
#include <string>
#include "api/mcell4_converter.h"
#include "api/python_exporter.h"
#include "api/api_utils.h"
#include "api/molecule.h"
#include "api/species.h"
#include "api/reaction_rule.h"
#include "api/release_site.h"
#include "api/geometry_object.h"
#include "api/viz_output.h"
#include "api/count.h"
#include "api/wall.h"
#include "api/wall_wall_hit_info.h"
#include "api/checkpoint_signals.h"
#include "world.h"
#include "scheduler.h"
#include "diffuse_react_event.h"
#include "release_event.h"
#include "rxn_utils.inl"
#include "molecule.h"
#include "viz_output_event.h"
#include "custom_function_call_event.h"
#include "bngl_exporter.h"
#include "bng/rxn_class.h"
using namespace std;
namespace MCell {
namespace API {
class RngState;
Model::~Model() {
unset_checkpoint_signals(this); // may be safely called multiple times
delete world;
}
void Model::add_subsystem(std::shared_ptr<Subsystem> subsystem) {
error_if_initialized(NAME_CLASS_SUBSYSTEM);
append_vec_to_vec_canonical_name(elementary_molecule_types, subsystem->elementary_molecule_types);
append_vec_to_vec_canonical_name(species, subsystem->species);
append_vec_to_vec(surface_classes, subsystem->surface_classes);
append_vec_to_vec_canonical_name(reaction_rules, subsystem->reaction_rules);
}
void Model::add_instantiation(std::shared_ptr<Instantiation> instantiation) {
error_if_initialized(NAME_CLASS_INSTANTIATION);
append_vec_to_vec(release_sites, instantiation->release_sites);
append_vec_to_vec(geometry_objects, instantiation->geometry_objects);
}
void Model::add_observables(std::shared_ptr<Observables> observables) {
error_if_initialized(NAME_CLASS_OBSERVABLES);
append_vec_to_vec(viz_outputs, observables->viz_outputs, true);
append_vec_to_vec(counts, observables->counts, true);
}
void Model::initialize(const bool print_copyright) {
if (world != nullptr) {
throw RuntimeError("Model.initialize() can be called only once");
}
// semantic checks of the following classes must be called manually because
// their contents may have changed and check_semantics is automatically called only from their ctor
config.check_semantics();
warnings.check_semantics();
notifications.check_semantics();
// first add species superclasses
std::vector<std::shared_ptr<Species>> superspecies = { AllMolecules, AllVolumeMolecules, AllSurfaceMolecules };
species.insert(species.begin(), superspecies.begin(), superspecies.end());
// Species objects might have created their own ElementaryMoleculeType
// objects, we must unify it first (required for python export)
unify_and_register_elementary_molecule_types();
world = new World(callbacks);
// semantic checks are done during conversion
MCell4Converter converter(this, world);
converter.convert_before_init();
// set that all used objects were initialized
vec_set_initialized(species);
vec_set_initialized(reaction_rules);
vec_set_initialized(release_sites);
vec_set_initialized(geometry_objects);
vec_set_initialized(viz_outputs);
vec_set_initialized(counts);
world->init_simulation(world->config.get_simulation_start_time());
// convert also rng state checkpointed molecules,
// must be done after world initialization
converter.convert_after_init();
initialize_introspection(this);
// set action for SIGUSR1 and SIGUSR2
set_checkpoint_signals(this);
initialized = true;
if (print_copyright) {
cout <<
"Copyright (C) 2006-2025 by\n"
" The National Center for Multiscale Modeling of Biological Systems,\n"
" The Salk Institute for Biological Studies, and\n"
" Pittsburgh Supercomputing Center, Carnegie Mellon University,\n"
"\n"
"**********************************************************************\n"
"MCell development is supported by the NIGMS-funded (P41GM103712)\n"
"National Center for Multiscale Modeling of Biological Systems (MMBioS).\n"
"Please acknowledge MCell in your publications.\n"
"**********************************************************************\n\n";
}
}
uint64_t Model::run_iterations(const double iterations) {
// release GIL before calling into long-running C++ code,
// necessary for other Python threads to be allowed to run (e.g. a timer)
py::gil_scoped_release release;
if (world == nullptr) {
throw RuntimeError("Model was not initialized, call Model.initialize() first");
}
return world->run_n_iterations(iterations, false);
}
void Model::end_simulation(const bool print_final_report) {
// the first argument specifies that the last mol/rxn count and viz_output events will be run
// cannot call callbacks anymore (no diffusion event is executed)
world->end_simulation(print_final_report);
// unset action for SIGUSR1 and SIGUSR2
unset_checkpoint_signals(this);
}
void Model::dump_internal_state(const bool with_geometry) {
world->dump(with_geometry);
}
void Model::export_geometry(const std::string& output_files_prefix) {
if (world == nullptr) {
throw RuntimeError(S("Model must be initialized before a call to ") + NAME_EXPORT_DATA_MODEL + ".");
}
if (is_set(output_files_prefix)) {
world->export_geometry_to_obj(output_files_prefix);
}
else {
stringstream prefix;
prefix <<
get_first_viz_output_files_prefix(NAME_EXPORT_GEOMETRY) << ".geom." <<
VizOutputEvent::iterations_to_string(world->stats.get_current_iteration(), config.total_iterations);
world->export_geometry_to_obj(prefix.str());
}
}
void Model::export_data_model_viz_or_full(
const std::string& file,
const bool only_for_visualization,
const char* method_name) {
if (world == nullptr) {
throw RuntimeError(S("Model must be initialized before a call to ") + NAME_EXPORT_DATA_MODEL + ".");
}
if (is_set(file)) {
world->export_data_model(file, only_for_visualization);
}
else {
world->export_data_model_to_dir(get_first_viz_output_files_prefix(method_name), only_for_visualization);
}
}
void Model::release_molecules(std::shared_ptr<ReleaseSite> release_site) {
if (!initialized) {
throw RuntimeError(S("Model must be initialized before calling ") + NAME_RELEASE_MOLECULES + ".");
}
// check that time is now or in the future
double iteration_start_time = world->stats.get_current_iteration() * world->config.time_unit;
if (release_site->release_time < iteration_start_time) {
throw ValueError("Cannot release molecules for time " + to_string(release_site->release_time) +
" before the start time of the current iteration " + to_string(iteration_start_time) + ".");
}
if (is_set(release_site->release_pattern)) {
throw ValueError(S("Cannot release molecules with a release pattern, method ") + NAME_RELEASE_MOLECULES +
" may be used only for immediate releases.");
}
// convert to a ReleaseEvent
MCell4Converter converter(this, world);
MCell::ReleaseEvent* rel_event = converter.convert_single_release_event(release_site);
assert(rel_event != nullptr);
// TODO: we must improve handling of cases when the release is in the future
rel_event->event_time = release_site->release_time / world->config.time_unit;
// figure out whether the DiffuseAndReactEvent is running
MCell::BaseEvent* current_event = world->scheduler.get_event_being_executed();
MCell::DiffuseReactEvent* diffuse_event = nullptr;
if (current_event != nullptr && current_event->type_index == EVENT_TYPE_INDEX_DIFFUSE_REACT) {
diffuse_event = dynamic_cast<MCell::DiffuseReactEvent*>(current_event);
assert(diffuse_event != nullptr);
}
// and execute the release
rel_event->release_immediatelly(diffuse_event);
delete rel_event;
}
std::vector<int> Model::run_reaction(
std::shared_ptr<ReactionRule> reaction_rule,
const std::vector<int> reactant_ids,
const double time) {
// need to release lock because we might be calling callbacks that are locking back
py::gil_scoped_release release;
if (!initialized) {
throw RuntimeError(S("Model must be initialized before calling ") + NAME_RUN_REACTION + ".");
}
if (reaction_rule->reactants.size() != reactant_ids.size()) {
throw RuntimeError("Reaction expects " + to_string(reaction_rule->reactants.size()) +
" reactants but " + to_string(reactant_ids.size()) + " reactants were provided.");
}
if (reaction_rule->fwd_rxn_rule_id == BNG::RXN_RULE_ID_INVALID) {
throw RuntimeError("Reaction rule is not present in model and was not initialized.");
}
if (reaction_rule->rev_rxn_rule_id != BNG::RXN_RULE_ID_INVALID) {
throw RuntimeError(S("Method ") + NAME_RUN_REACTION + " can be used only with irreversible reactions.");
}
const BNG::RxnRule* rxn = world->get_all_rxns().get(reaction_rule->fwd_rxn_rule_id);
if (!rxn->is_unimol()) {
throw RuntimeError(S("Method ") + NAME_RUN_REACTION + " currently supports only unimolecular reactions.");
}
MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL);
molecule_id_t id1 = reactant_ids[0];
if (!p.does_molecule_exist(id1)) {
throw RuntimeError("Molecule with id " + to_string(id1) + " does not exist.");
}
MCell::Molecule& m1 = p.get_m(id1);
if (m1.is_defunct()) {
throw RuntimeError("Molecule with id " + to_string(id1) + " was removed.");
}
std::vector<int> res;
if (rxn->is_unimol()) {
// check if the requested rxn is applicable for our reactant
// also determine pathway index
BNG::RxnClass* rxn_class = world->bng_engine.get_all_rxns().get_unimol_rxn_class(m1.species_id);
rxn_class->init_rxn_pathways_and_rates(); // initialize if needed
BNG::rxn_class_pathway_index_t index = 0;
while (index < (BNG::rxn_class_pathway_index_t)rxn_class->get_num_pathways() &&
rxn_class->get_rxn_for_pathway(index)->id != rxn->id) {
index++;
}
if (index >= (BNG::rxn_class_pathway_index_t)rxn_class->get_num_pathways()) {
const BNG::Species& species = world->get_all_species().get(m1.species_id);
throw RuntimeError("Reaction rule " + reaction_rule->to_bngl_str() +
" cannot be applied on molecule with species " + species.name);
}
// if we are in a callback, we are probably in a diffuse react event
BaseEvent* current_event = world->scheduler.get_event_being_executed();
DiffuseReactEvent* diffuse_react_event;
bool using_temporary_event;
if (current_event != nullptr && current_event->type_index == EVENT_TYPE_INDEX_DIFFUSE_REACT) {
diffuse_react_event = dynamic_cast<DiffuseReactEvent*>(current_event);
using_temporary_event = false;
}
else {
// otherwise we will instantiate a new event
diffuse_react_event = new DiffuseReactEvent(world);
using_temporary_event = true;
}
MoleculeIdsVector product_ids;
diffuse_react_event->outcome_unimolecular(p, m1, time / world->config.time_unit, rxn_class, index, &product_ids);
if (using_temporary_event) {
delete diffuse_react_event;
}
res.insert(res.begin(), product_ids.begin(), product_ids.end());
}
else {
// TODO
release_assert(false);
}
return res;
}
void Model::add_vertex_move(
std::shared_ptr<GeometryObject> object, const int vertex_index, const std::vector<double> displacement
) {
// - currently, it is not expected that the user will have access to the scheduled vertex moves
// - later we can use the object id to determine the partition
object->check_is_initialized();
release_assert(
object->first_vertex_index + vertex_index <
world->get_partition(PARTITION_ID_INITIAL).get_geometry_vertex_count()
);
if (displacement.size() != 3) {
throw ValueError(S("Argument ") + NAME_DISPLACEMENT + " must be a list of exactly three floats.");
}
Vec3 disp_vec = Vec3(displacement);
vertex_moves.push_back(
VertexMoveInfo(
PARTITION_ID_INITIAL,
object->geometry_object_id,
object->get_partition_vertex_index(vertex_index),
disp_vec * Vec3(world->config.rcp_length_unit) // convert to internal units
)
);
}
void Model::update_api_vertex_position_using_vertex_move(
const VertexMoveInfo& move_info) {
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
// get the new vertex coordinates
assert(move_info.partition_id == PARTITION_ID_INITIAL);
const Vec3& pos = p.get_geometry_vertex(move_info.vertex_index);
// API object whose vertex we need to update
std::shared_ptr<API::GeometryObject> obj =
get_geometry_object_with_id(move_info.geometry_object_id);
// API object's vertex index
int obj_vertex_index = obj->get_object_vertex_index(move_info.vertex_index);
Vec3 pos_um = pos * Vec3(world->config.length_unit);
auto& pos_to_update = obj->vertex_list[obj_vertex_index];
pos_to_update[0] = pos_um.x;
pos_to_update[1] = pos_um.y;
pos_to_update[2] = pos_um.z;
}
std::vector<std::shared_ptr<WallWallHitInfo>> Model::apply_vertex_moves(
const bool collect_wall_wall_hits,
const bool randomize_order) {
// run the actual vertex update
std::set<GeometryObjectWallUnorderedPair> colliding_walls;
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
// may update vertex_move displacements due to collisions
vector<VertexMoveInfo*> vertex_moves_due_to_paired_molecules;
p.apply_vertex_moves(
randomize_order, vertex_moves,
colliding_walls, vertex_moves_due_to_paired_molecules);
std::vector<std::shared_ptr<WallWallHitInfo>> res;
// convert information on processed hits
if (collect_wall_wall_hits) {
for (const auto& wall_pair: colliding_walls) {
auto obj1 = get_geometry_object_with_id(wall_pair.geometry_object_id1);
int obj_wall_index1 = obj1->get_object_wall_index(wall_pair.wall_index1);
auto obj2 = get_geometry_object_with_id(wall_pair.geometry_object_id2);
int obj_wall_index2 = obj2->get_object_wall_index(wall_pair.wall_index2);
auto pair = make_shared<WallWallHitInfo>(DefaultCtorArgType());
pair->wall1 = get_wall(obj1, obj_wall_index1);
pair->wall2 = get_wall(obj2, obj_wall_index2);
res.push_back(pair);
}
}
// also update the API copy of the geometry
for (const VertexMoveInfo& move_info: vertex_moves) {
update_api_vertex_position_using_vertex_move(move_info);
}
// also take into account the vertices moved due to paired molecules
for (VertexMoveInfo* move_info: vertex_moves_due_to_paired_molecules) {
update_api_vertex_position_using_vertex_move(*move_info);
delete move_info;
}
// we processed all the moves
vertex_moves.clear();
return res;
}
void Model::pair_molecules(const int id1, const int id2) {
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
string res = p.pair_molecules(id1, id2);
if (res != "") {
throw RuntimeError(res);
}
}
void Model::unpair_molecules(const int id1, const int id2) {
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
string res = p.unpair_molecules(id1, id2);
if (res != "") {
throw RuntimeError(res);
}
}
int Model::get_paired_molecule(const int id) {
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
molecule_id_t res = p.get_paired_molecule(id);
if (res == MOLECULE_ID_INVALID) {
return ID_INVALID;
}
else {
return res;
}
}
std::map<uint, uint> Model::get_paired_molecules() {
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
return p.get_paired_molecules();
}
void Model::register_mol_wall_hit_callback(
const std::function<void(std::shared_ptr<MolWallHitInfo>, py::object)> function,
py::object context,
std::shared_ptr<GeometryObject> object,
std::shared_ptr<Species> species
) {
if (!initialized) {
throw RuntimeError("Model must be initialized before registering callbacks.");
}
geometry_object_id_t geometry_object_id = GEOMETRY_OBJECT_ID_INVALID;
if (is_set(object)) {
if (object->geometry_object_id == GEOMETRY_OBJECT_ID_INVALID) {
throw RuntimeError("Geometry object " + object->name + " is not present in model.");
}
geometry_object_id = object->geometry_object_id;
}
species_id_t species_id = SPECIES_ID_INVALID;
if (is_set(species)) {
if (species->species_id == SPECIES_ID_INVALID) {
throw RuntimeError("Species object " + object->name + " is not present in model.");
}
species_id = species->species_id;
}
callbacks.register_mol_wall_hit_callback(function, context, geometry_object_id, species_id);
}
void Model::register_reaction_callback(
const std::function<bool(std::shared_ptr<ReactionInfo>, py::object)> function,
py::object context,
std::shared_ptr<ReactionRule> reaction_rule
) {
if (!initialized) {
throw RuntimeError("Model must be initialized before registering callbacks.");
}
if (reaction_rule->is_reversible()) {
throw RuntimeError(S("Reaction callback cannot be registered for reversible reactions. ") +
"Split the reaction rule's forward and reverese direction into separate " +
NAME_REACTION_RULE + " objects.");
}
BNG::rxn_rule_id_t rxn_id = reaction_rule->fwd_rxn_rule_id;
if (rxn_id == BNG::RXN_RULE_ID_INVALID) {
throw RuntimeError(S(NAME_REACTION_RULE) + reaction_rule->name + " with its BNGL representation " +
reaction_rule->to_bngl_str() + " is not present in model.");
}
callbacks.register_rxn_callback(function, context, rxn_id);
}
void Model::load_bngl(
const std::string& file_name,
const std::string& observables_path_or_file,
std::shared_ptr<Region> default_release_region,
const std::map<std::string, double>& parameter_overrides,
const CountOutputFormat observables_output_format) {
BNG::BNGData bng_data;
int num_errors = BNG::parse_bngl_file(file_name, bng_data, parameter_overrides);
if (num_errors != 0) {
throw RuntimeError("Could not parse BNGL file " + file_name + ".");
}
// now convert everything we parsed into the API classes so that the user can
// inspect or manipulate it if needed
convert_bng_data_to_subsystem_data(bng_data);
// needs subsystem data created in the last step
convert_bng_data_to_instantiation(bng_data, default_release_region);
convert_bng_data_to_observables_data(
bng_data,
get_count_output_format(observables_output_format, observables_path_or_file),
observables_path_or_file);
}
void Model::export_to_bngl(const std::string& file_name,
const BNGSimulationMethod simulation_method) {
if (!initialized) {
throw RuntimeError("Model must be initialized for BNGL export.");
}
if (simulation_method != BNGSimulationMethod::NONE &&
simulation_method != BNGSimulationMethod::ODE &&
simulation_method != BNGSimulationMethod::SSA &&
simulation_method != BNGSimulationMethod::PLA &&
simulation_method != BNGSimulationMethod::NF) {
throw ValueError(S("Invalid ") + NAME_SIMULATION_METHOD + " argument value.");
}
MCell::BNGLExporter bngl_exporter;
string err_msg = bngl_exporter.export_to_bngl(world, file_name, simulation_method);
if (err_msg != "") {
throw RuntimeError("BNGL export failed: " + err_msg);
}
}
void Model::save_checkpoint(const std::string& custom_dir) {
if (!initialized) {
throw RuntimeError(S("Model must be initialized for ") + NAME_SAVE_CHECKPOINT + ".");
}
// prepare output directory name
string dir;
if (is_set(custom_dir)) {
dir = custom_dir;
}
else {
// TODO: move the VizOutputEvent::iterations_to_string to api_utils
dir =
world->config.get_default_checkpoint_dir_prefix() +
VizOutputEvent::iterations_to_string(world->stats.get_current_iteration(), config.total_iterations) +
BNG::PATH_SEPARATOR;
}
PythonExporter exporter(this);
exporter.save_checkpoint(dir);
}
// can be called asynchronously at any point of simulation, only single-threaded
// cannot be called from signal handlers
void Model::schedule_checkpoint(
const uint64_t iteration,
const bool continue_simulation,
const std::string& custom_dir) {
// NOTE: accessing current iteration value asynchronously,
// it is a 64-bit integer so write is done atomically with a single instruction
uint64_t current_it = world->stats.get_current_iteration();
if (iteration != 0 && iteration < current_it) {
throw RuntimeError(S("Method ") + NAME_SCHEDULE_CHECKPOINT + " - cannot schedule checkpoint to the past.");
}
// same as above - 'initialized' uses a simple type, therefore writes are atomic
if (!initialized) {
throw RuntimeError(S("Method ") + NAME_SCHEDULE_CHECKPOINT + " cannot be called before model initialization.");
}
// prepare context for callback
CheckpointSaveEventContext ctx;
ctx.model = this;
if (is_set(custom_dir)) {
ctx.dir_prefix = custom_dir;
ctx.append_it_to_dir = false;
}
else {
ctx.dir_prefix = world->config.get_default_checkpoint_dir_prefix();
ctx.append_it_to_dir = true;
}
world->schedule_checkpoint_event(iteration, continue_simulation, ctx);
}
// overrides from derived classes Subsystem, Instantiation, and Observables,
// in .cpp because implementation in .h file would need too many headers to be included
void Model::add_species(std::shared_ptr<Species> s) {
error_if_initialized(NAME_CLASS_SPECIES);
Subsystem::add_species(s);
}
void Model::add_reaction_rule(std::shared_ptr<ReactionRule> r) {
error_if_initialized(NAME_CLASS_REACTION_RULE);
Subsystem::add_reaction_rule(r);
}
void Model::add_surface_class(std::shared_ptr<SurfaceClass> sc) {
error_if_initialized(NAME_CLASS_SURFACE_CLASS);
Subsystem::add_surface_class(sc);
}
void Model::add_release_site(std::shared_ptr<ReleaseSite> s) {
error_if_initialized(NAME_CLASS_RELEASE_SITE);
Instantiation::add_release_site(s);
}
void Model::add_geometry_object(std::shared_ptr<GeometryObject> o) {
error_if_initialized(NAME_CLASS_GEOMETRY_OBJECT);
Instantiation::add_geometry_object(o);
}
void Model::add_viz_output(std::shared_ptr<VizOutput> viz_output) {
error_if_initialized(NAME_CLASS_VIZ_OUTPUT);
Observables::add_viz_output(viz_output);
};
void Model::add_count(std::shared_ptr<Count> count) {
error_if_initialized(NAME_CLASS_OBSERVABLES);
Observables::add_count(count);
};
std::shared_ptr<GeometryObject> Model::get_geometry_object_with_id(const geometry_object_id_t id) {
// map for caching
auto it = geometry_object_id_to_obj_cache.find(id);
if (it != geometry_object_id_to_obj_cache.end()) {
return it->second;
}
for (auto o: geometry_objects) {
if (o->geometry_object_id == id) {
geometry_object_id_to_obj_cache[o->geometry_object_id] = o;
return o;
}
}
return std::shared_ptr<GeometryObject>(nullptr);
}
std::shared_ptr<ReactionRule> Model::get_reaction_rule_with_fwd_id(const BNG::rxn_rule_id_t id) {
// not very efficient, we may need some caching/map later
for (auto r: reaction_rules) {
if (r->fwd_rxn_rule_id == id) {
return r;
}
}
return std::shared_ptr<ReactionRule>(nullptr);
}
void Model::dump() const {
cout << to_str();
}
}
}
| C++ |
3D | mcellteam/mcell | libmcell/api/initial_surface_release.h | .h | 1,227 | 44 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_INITIAL_SURFACE_RELEASE_H
#define API_INITIAL_SURFACE_RELEASE_H
#include "generated/gen_initial_surface_release.h"
#include "api/api_common.h"
#include "api/complex.h"
namespace MCell {
namespace API {
class InitialSurfaceRelease: public GenInitialSurfaceRelease {
public:
INITIAL_SURFACE_RELEASE_CTOR()
void check_semantics() const override {
if (get_num_set(number_to_release, density) != 1) {
throw ValueError(S("Exactly one of ") + NAME_NUMBER_TO_RELEASE + " and " +
NAME_DENSITY + " must be set.");
}
if (is_set(complex->compartment_name)) {
throw ValueError(S("Compartment of the complex to be released in ") +
NAME_CLASS_INITIAL_SURFACE_RELEASE + " must not be set.");
}
}
};
} // namespace API
} // namespace MCell
#endif // API_INITIAL_SURFACE_RELEASE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/surface_property.h | .h | 3,443 | 91 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_SURFACE_PROPERTY_H
#define API_SURFACE_PROPERTY_H
#include "generated/gen_surface_property.h"
#include "api/api_common.h"
#include "bng/bng_defines.h"
#include "api/complex.h"
namespace MCell {
namespace API {
class SurfaceProperty: public GenSurfaceProperty {
public:
SURFACE_PROPERTY_CTOR()
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
rxn_rule_id = BNG::RXN_RULE_ID_INVALID;
}
void check_semantics() const override {
GenSurfaceProperty::check_semantics();
// all checks are done in SurfaceClass::check_semantics that calls
// check_semantics_custom
}
void check_semantics_custom() const {
GenSurfaceProperty::check_semantics();
if (type == SurfacePropertyType::UNSET) {
throw ValueError(S("Attribute '") + NAME_TYPE + "' of " +
NAME_CLASS_SURFACE_PROPERTY + " objects contained in " + NAME_CLASS_SURFACE_CLASS + " must be set.");
}
if (!is_set(affected_complex_pattern) && type != SurfacePropertyType::REACTIVE) {
throw ValueError(S("Attribute '") + NAME_AFFECTED_COMPLEX_PATTERN + "' of " +
NAME_CLASS_SURFACE_PROPERTY + " objects contained in " + NAME_CLASS_SURFACE_CLASS + " must be set when " +
NAME_TYPE + " is different from " + NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_REACTIVE + ".");
}
if (is_set(affected_complex_pattern) && type == SurfacePropertyType::REACTIVE) {
throw ValueError(S("Attribute '") + NAME_AFFECTED_COMPLEX_PATTERN + "' of " +
NAME_CLASS_SURFACE_PROPERTY + " objects contained in " + NAME_CLASS_SURFACE_CLASS + " must not be set when " +
NAME_TYPE + " is " + NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_REACTIVE + ".");
}
if (is_set(affected_complex_pattern) && is_set(affected_complex_pattern->compartment_name)) {
throw ValueError(S("Attribute '") + NAME_AFFECTED_COMPLEX_PATTERN + "' of " +
NAME_CLASS_SURFACE_PROPERTY + " must not have a compartment specified.");
}
if ((type == SurfacePropertyType::CONCENTRATION_CLAMP || type == SurfacePropertyType::FLUX_CLAMP) &&
!is_set(concentration)) {
throw ValueError(S("When ") + NAME_TYPE + " in " + NAME_CLASS_SURFACE_PROPERTY + " is " +
NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_CONCENTRATION_CLAMP + " or " +
NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_FLUX_CLAMP +
" then " + NAME_CONCENTRATION + " must be set.");
}
}
// needed when defining a set of SurfaceProperty(s)
bool operator < (const SurfaceProperty& other) const {
if (type != other.type) {
return type < other.type;
}
if (concentration != other.concentration) {
return concentration < other.concentration;
}
return affected_complex_pattern->get_canonical_name() <
other.affected_complex_pattern->get_canonical_name();
}
BNG::rxn_rule_id_t rxn_rule_id;
};
} // namespace API
} // namespace MCell
#endif // API_SURFACE_PROPERTY_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/checkpoint_signals.cpp | .cpp | 3,999 | 144 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "checkpoint_signals.h"
#include <iostream>
#include <set>
#include <signal.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include "api/api_common.h"
#include "api/model.h"
#include "api/python_exporter.h"
#include "src4/world.h"
#include "src4/viz_output_event.h"
using namespace std;
#ifndef _WIN64
struct sigaction g_previous_sigaction_sigusr1;
struct sigaction g_previous_sigaction_sigusr2;
struct sigaction g_previous_sigaction_sigalrm;
#endif
namespace MCell {
namespace API {
// WARNING: not multithread-safe
std::set<Model*> g_models;
// WARNING: only limited set of calls is allowed in signal handlers,
// e.g. no malloc
void checkpoint_signal_handler(int signo) {
// checkpoint can be requested multiple times even when the
// scheduling of a checkpoint is running
for (Model* m: g_models) {
if (m->get_world() != nullptr) {
m->get_world()->set_to_create_checkpoint_event_from_signal_hadler(signo, m);
}
}
}
// Set signal handlers for checkpointing on SIGUSR signals.
void set_checkpoint_signals(Model* model) {
bool already_set = !g_models.empty();
g_models.insert(model);
// Windows does not support USR signals
if (!already_set) {
#ifndef _WIN64
struct sigaction sa;
sa.sa_sigaction = NULL;
sa.sa_handler = &checkpoint_signal_handler;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
if (::sigaction(SIGUSR1, &sa, &g_previous_sigaction_sigusr1) != 0) {
throw RuntimeError("Failed to install SIGUSR1 signal handler.");
}
if (::sigaction(SIGUSR2, &sa, &g_previous_sigaction_sigusr2) != 0) {
throw RuntimeError("Failed to install SIGUSR2 signal handler.");
}
if (::sigaction(SIGALRM, &sa, &g_previous_sigaction_sigalrm) != 0) {
throw RuntimeError("Failed to install SIGUSR2 signal handler.");
}
#endif
}
}
void unset_checkpoint_signals(Model* model) {
if (g_models.count(model) == 0) {
// either not set or unset twice, ignore
return;
}
g_models.erase(model);
// Windows does not support USR signals
// SIGALRM should be supported somehow but it does not work yet
if (g_models.empty()) {
#ifndef _WIN32
if (sigaction(SIGUSR1, &g_previous_sigaction_sigusr1, nullptr) != 0) {
cout << "Warning: failed to uninstall SIGUSR1 signal handler.\n";
}
if (sigaction(SIGUSR2, &g_previous_sigaction_sigusr2, nullptr) != 0) {
cout << "Warning: failed to uninstall SIGUSR2 signal handler.\n";
}
if (sigaction(SIGALRM, &g_previous_sigaction_sigalrm, nullptr) != 0) {
cout << "Warning: failed to uninstall SIGALRM signal handler.\n";
}
#endif
}
}
void save_checkpoint_func(const double time, CheckpointSaveEventContext ctx) {
const World* world = ctx.model->get_world();
release_assert(
world->scheduler.get_event_being_executed()->type_index == EVENT_TYPE_INDEX_CALL_START_ITERATION_CHECKPOINT &&
"May be called only from event with index EVENT_TYPE_INDEX_CALL_START_ITERATION_CHECKPOINT, "
" world/model data may be inconsistent otherwise"
);
uint64_t current_it = world->stats.get_current_iteration();
std::string dir;
if (ctx.append_it_to_dir) {
dir =
ctx.dir_prefix +
VizOutputEvent::iterations_to_string(world->stats.get_current_iteration(), ctx.model->config.total_iterations) +
BNG::PATH_SEPARATOR;
}
else {
dir = ctx.dir_prefix;
}
cout << "Saving scheduled checkpoint in iteration " << current_it << " into " << dir << "\n";
PythonExporter exporter(ctx.model);
exporter.save_checkpoint(dir);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/globals.cpp | .cpp | 1,076 | 31 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/globals.h"
#include "api/species.h"
#include "generated/gen_constants.h"
namespace MCell {
namespace API {
// we need to have global shared pointers, they are added to Model in its constructor
// having simple global variables would mean that we need to make a copy
// and in model initialization we would be updating the copy (which will not reflect changes to our globals)
std::shared_ptr<Species> AllMolecules(new Species(ALL_MOLECULES, FLT_UNSET, 0));
std::shared_ptr<Species> AllVolumeMolecules(new Species(ALL_VOLUME_MOLECULES, FLT_UNSET, 0));
std::shared_ptr<Species> AllSurfaceMolecules(new Species(ALL_SURFACE_MOLECULES, 0, FLT_UNSET));
} // API
} // MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/python_export_constants.h | .h | 6,664 | 178 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_PYTHON_EXPORT_CONSTANTS_H_
#define LIBMCELL_API_PYTHON_EXPORT_CONSTANTS_H_
#include "datamodel_defines.h"
namespace MCell {
namespace API {
const int FLOAT_OUT_PRECISION = 15; // this is the precision that is used by mdl_to_data_model.py script
const int MAX_SPECIES_NAME_LENGTH = 32;
const char* const SHARED = "shared";
const char* const PARAMETERS = "parameters";
const char* const SUBSYSTEM = "subsystem";
const char* const GEOMETRY = "geometry";
const char* const INSTANTIATION = "instantiation";
const char* const OBSERVABLES = "observables";
const char* const SIMULATION_STATE = "simulation_state";
const char* const MODEL = "model";
#define CUSTOMIZATION "customization"
const char* const CUSTOM_ARGPARSE_AND_PARAMETERS = "custom_argparse_and_parameters";
const char* const CUSTOM_CONFIG = "custom_config";
const char* const CUSTOM_INIT_AND_RUN = "custom_init_and_run";
const char* const PARAMETER_OVERRIDES = "parameter_overrides";
const char* const NOT_DEFINED = "not_defined";
const char* const PY_EXT = ".py";
const char* const BNGL_EXT = ".bngl";
const char* const IMPORT = "import";
const char* const MDOT = "m.";
const char* const IND = " ";
const char* const IND4 = " "; // this indent must be 4 chars because it is used as indentation in Python
const char* const IND8 = " ";
const char* const BLOCK_BEGIN1 = "# ---- ";
const char* const BLOCK_BEGIN2 = " ----\n";
const char* const BLOCK_END1 = "# ^^^^ ";
const char* const BLOCK_END2 = " ^^^^\n\n";
const char* const CTOR_END = ")\n\n";
#define PARAM_SEED "SEED"
const char* const PARAM_ITERATIONS = "ITERATIONS";
const char* const PARAM_TIME_STEP = "TIME_STEP";
const char* const PARAM_DUMP = "DUMP";
const char* const PARAM_EXPORT_DATA_MODEL = "EXPORT_DATA_MODEL";
const char* const SET_BNGL_MOLECULE_TYPES_INFO = "set_bngl_molecule_types_info";
const char* const VAR_BNGL_PARAMS = "bngl_params";
const char* const VEC3 = "Vec3";
const char* const COMPONENT_PREFIX = "comp_";
const char* const ELEMENTARY_MOLECULE_TYPE_PREFIX = "emt_";
const char* const COUNT_PREFIX = "count_";
const char* const COUNT_TERM_PREFIX = "cterm_";
const char* const UNNAMED_REACTION_RULE_PREFIX = "unnamed_reaction_rule_";
const char* const SURFACE_CLASS_PREFIX = "surface_class_";
const char* const MOLECULE_LIST_PREFIX = "molecule_list_";
const char* const VIZ_OUTPUT_NAME = "viz_output";
const char* const DEFAULT_VIZ_OUTPUT_FILENAME_PREFIX = "./" VALUE_VIZ_DATA "/seed_' + str(" PARAM_SEED ").zfill(5) + '/Scene";
const char* const DEFAULT_RXN_OUTPUT_FILENAME_PREFIX = "./" VALUE_REACT_DATA "/seed_' + str(" PARAM_SEED ").zfill(5) + '/";
const char* const INTERPRETER = "#!/usr/bin/env python3\n\n";
const char* const GENERATED_WARNING =
"# WARNING: This is an automatically generated file and will be overwritten\n"
"# by CellBlender on the next model export.\n";
const char* const IMPORT_SYS_OS =
"import sys\n"
"import os\n"
;
const char* const IMPORT_OS = "import os\n";
const char* const IMPORT_MATH = "import math\n";
const char* const IMPORT_SHARED = "import shared\n";
#define MODEL_PATH "MODEL_PATH"
const char* const MODEL_PATH_SETUP =
MODEL_PATH " = os.path.dirname(os.path.abspath(__file__))\n"
;
const char* const MCELL_PATH_SETUP =
"\n# ---- import mcell module located in directory specified by system variable MCELL_PATH ----\n\n"
"MCELL_PATH = os.environ.get('MCELL_PATH', '')\n"
"if MCELL_PATH:\n"
" lib_path = os.path.join(MCELL_PATH, 'lib')\n"
" if os.path.exists(os.path.join(lib_path, 'mcell.so')) or \\\n"
" os.path.exists(os.path.join(lib_path, 'mcell.pyd')):\n"
" sys.path.append(lib_path)\n"
" else:\n"
" print(\"Error: Python module mcell.so or mcell.pyd was not found in \"\n"
" \"directory '\" + lib_path + \"' constructed from system variable \"\n"
" \"MCELL_PATH.\")\n"
" sys.exit(1)\n"
"else:\n"
" print(\"Error: system variable MCELL_PATH that is used to find the mcell \"\n"
" \"library was not set.\")\n"
" sys.exit(1)\n"
;
const char* const IMPORT_MCELL_AS_M = "import mcell as m\n\n";
const char* const CHECKPOINT_ITERATION = "checkpoint_iteration";
const char* const REGION_ALL_NAME = "ALL";
const char* const REGION_ALL_SUFFIX = "[ALL]";
const char* const NULL_PRODUCTS = "NULL";
const char* const COUNT = "COUNT";
const char* const WORLD = "WORLD";
const char* const WORLD_FIRST_UPPER = "World";
const char* const REV_RXN_SUFFIX = "_rev";
std::string get_customization_import(const std::string& customization_module);
std::string get_argparse_w_customization_begin(const std::string& customization_module);
std::string get_argparse_checkpoint_iteration();
std::string get_resume_from_checkpoint_code();
std::string get_argparse_w_customization_end();
std::string get_user_defined_configuration(const std::string& customization_module);
std::string get_abs_path(const std::string file);
std::string get_import(const std::string module);
std::string get_import_star(const std::string module);
const char* const TEMPLATE_CUSTOM_ARGPARSE_AND_PARAMETERS =
"\"\"\"\n"
"def custom_argparse_and_parameters():\n"
" # When uncommented, this function is called to parse \n"
" # custom commandline arguments.\n"
" # It is executed before any of the automatically generated \n"
" # parameter values are set so one can override the parameter \n"
" # values here as well.\n"
" # To override parameter values, add or overwrite an item in dictionary\n"
" # shared.parameter_overrides, e.g. shared.parameter_overrides['SEED'] = 10\n"
" pass\n"
"\"\"\"\n"
;
const char* const TEMPLATE_CUSTOM_CONFIG =
"\"\"\"\n"
"def custom_config(model):\n"
" # When uncommented, this function is called to set custom\n"
" # model configuration.\n"
" # It is executed after basic parameter setup is done and \n"
" # before any components are added to the model. \n"
" pass\n"
"\"\"\"\n"
;
std::string get_template_custom_init_and_run(const std::string& parameters_module);
} // namespace API
} // namespace MCell
#endif // LIBMCELL_API_PYTHON_EXPORT_CONSTANTS_H_
| Unknown |
3D | mcellteam/mcell | libmcell/api/surface_class.cpp | .cpp | 930 | 42 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/surface_class.h"
#include "api/surface_property.h"
#include <set>
using namespace std;
namespace MCell {
namespace API {
bool SurfaceClass::__eq__(const SurfaceClass& other) const {
if (!eq_nonarray_attributes(other)) {
return false;
}
// are surface properties the same?
std::set<SurfaceProperty> s1;
for (auto& c: properties) {
s1.insert(*c);
}
std::set<SurfaceProperty> s2;
for (auto& c: other.properties) {
s2.insert(*c);
}
return s1 == s2;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/observables.h | .h | 2,506 | 87 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_OBSERVABLES_H
#define API_OBSERVABLES_H
#include "generated/gen_observables.h"
#include "api/api_common.h"
#include "api/api_utils.h"
#include "api/viz_output.h"
#include "api/count.h"
namespace BNG {
class Observable;
class BNGData;
}
namespace MCell {
namespace API {
class Observables: public GenObservables {
public:
OBSERVABLES_CTOR()
// TODO: add checks that each observable writes to a different file
void add_viz_output(std::shared_ptr<VizOutput> viz_output) override {
append_to_vec(viz_outputs, viz_output, true);
};
void add_count(std::shared_ptr<Count> count) override {
append_to_vec(counts, count, true);
};
// throws error if viz_output is not present or if its output_files_prefix is not set
// uses argument method_name for this error report
std::string get_first_viz_output_files_prefix(const char* method_name);
std::shared_ptr<Count> find_count(const std::string& name) override {
return vec_find_by_name(counts, name);
}
void load_bngl_observables(
const std::string& file_name,
const std::string& observables_path_or_file = "",
const std::map<std::string, double>& parameter_overrides = std::map<std::string, double>(),
const CountOutputFormat observables_output_format = CountOutputFormat::AUTOMATIC_FROM_EXTENSION
) override;
// added manually
void dump() const;
protected:
void convert_bng_data_to_observables_data(
const BNG::BNGData& bng_data,
const CountOutputFormat observables_output_format,
const std::string& output_files_prefix
);
CountOutputFormat get_count_output_format(
const CountOutputFormat observables_output_format,
const std::string& observables_path_or_file
);
private:
void convert_observable(
const BNG::Observable& o,
const BNG::BNGData& bng_data,
const std::string& observables_path_or_file,
const CountOutputFormat observables_output_format
);
CountOutputFormat count_output_format_from_path_or_file(const std::string& path_or_file);
};
} // namespace API
} // namespace MCell
#endif // API_OBSERVABLES_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/count.cpp | .cpp | 2,261 | 82 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/count.h"
#include "mol_or_rxn_count_event.h"
namespace MCell {
namespace API {
void Count::postprocess_in_ctor() {
set_all_custom_attributes_to_default();
// determine count type
set_automatically_output_format_if_needed();
}
void Count::check_semantics() const {
GenCount::check_semantics(); // calls also CountTerm::check_semantics
if (!is_set(expression)) {
throw ValueError(S("Attribute ") + NAME_EXPRESSION + " must be set.");
}
expression->check_that_species_or_reaction_rule_is_set();
if (every_n_timesteps < 0) {
throw ValueError(
S("The value of ") + NAME_EVERY_N_TIMESTEPS + " must be higher or equal to 0.");
}
if (output_format == CountOutputFormat::UNSET) {
throw ValueError(S("Attribute ") + NAME_OUTPUT_FORMAT + " must be set.");
}
}
void Count::set_automatically_output_format_if_needed() {
if (output_format != CountOutputFormat::AUTOMATIC_FROM_EXTENSION) {
// specific value set
return;
}
const std::string gdat = ".gdat";
size_t gdat_sz = gdat.size();
const std::string dat = ".dat";
size_t dat_sz = dat.size();
size_t sz = file_name.size();
if (!is_set(file_name) || (sz > dat.size() && file_name.substr(sz - dat_sz) == dat)) {
output_format = CountOutputFormat::DAT;
}
else if (sz > gdat.size() && file_name.substr(sz - gdat_sz) == gdat) {
output_format = CountOutputFormat::GDAT;
}
else {
throw ValueError(S("Cannot automatically determine ") + NAME_OUTPUT_FORMAT + ", " + NAME_FILE_NAME +
" must have either .dat or .gdat extension for automatic detection.");
}
}
double Count::get_current_value() {
if (count_event == nullptr) {
throw RuntimeError(S(NAME_CLASS_COUNT) + " with name " + name + " was not initialized.");
}
return count_event->get_single_count_value();
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/species.h | .h | 6,638 | 183 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_SPECIES_H
#define API_SPECIES_H
#include "generated/gen_species.h"
#include "generated/gen_constants.h"
#include "api/api_common.h"
#include "api/api_utils.h"
#include "api/complex.h"
#include "elementary_molecule_type.h"
#include "bng/bng_defines.h"
namespace MCell {
namespace API {
class Species: public GenSpecies {
public:
SPECIES_CTOR()
Species(Complex& cplx_inst)
: GenSpecies(cplx_inst.to_bngl_str()) {
set_all_custom_attributes_to_default();
set_all_attributes_as_default_or_unset();
// set copied value, cannot use GenSpecies ctor because we need to reset the attributes
// warning: must be updated if Complex class' attributes change
name = cplx_inst.name;
elementary_molecules = cplx_inst.elementary_molecules;
// should not be really used in Species but copying it as well for consistency
orientation = cplx_inst.orientation;
}
void set_name(const std::string& name_) override {
BaseDataClass::set_name(name_);
// rerun initialization because the name is parsed as a BNGL string
elementary_molecules.clear();
postprocess_in_ctor();
}
void check_no_extra_fields_are_set() const {
std::string msg =
" must not be set for complex species because it is derived from its elementary molecule types.";
if (is_set(diffusion_constant_2d)) {
throw ValueError(S("Field ") + NAME_DIFFUSION_CONSTANT_2D + msg);
}
if (is_set(diffusion_constant_3d)) {
throw ValueError(S("Field ") + NAME_DIFFUSION_CONSTANT_3D + msg);
}
if (is_set(custom_time_step)) {
throw ValueError(S("Field ") + NAME_CUSTOM_TIME_STEP + msg);
}
if (is_set(custom_space_step)) {
throw ValueError(S("Field ") + NAME_CUSTOM_SPACE_STEP + msg);
}
if (target_only) {
throw ValueError(S("Field ") + NAME_TARGET_ONLY + msg);
}
}
// we are making changes, so semantic checks are here instead of in const check_semantics
void postprocess_in_ctor() override {
// initialization
set_all_custom_attributes_to_default();
// not calling derived check semantics
if (get_num_set(name, elementary_molecules) != 1) {
throw ValueError(
S("Exactly one of ") + NAME_NAME + " or " + NAME_ELEMENTARY_MOLECULES +
" must be set for " + NAME_CLASS_SPECIES + ".");
}
// 1) simple species defined by name
if (is_set(name) && !is_set(elementary_molecules) &&
(is_set(diffusion_constant_2d) || is_set(diffusion_constant_3d))) {
if (!is_simple_species(name)) {
throw ValueError("Only simple species can be fully defined by setting name and diffusion constant. "
"For complex species, it cannot be usually deduced what the diffusion constants of elementary molecule types should be.");
}
if (name.find('.') != std::string::npos) {
throw ValueError("Simple species name must not contain '.', this is incompatible with BNGL definition"
", error for " + name + ".");
}
if (is_set(diffusion_constant_2d) && is_set(diffusion_constant_3d)) {
throw ValueError("Only one of fields diffusion_constant_2d or diffusion_constant_3d can be set for simple species.");
}
if (get_num_set(custom_time_step, custom_space_step) > 1) {
throw ValueError(S("Only one of ") + NAME_CUSTOM_TIME_STEP + " or " + NAME_CUSTOM_SPACE_STEP +
" may be set at the same time.");
}
// create a single ElementaryMoleculeType
// will be added on initialization to model's elementary_molecule_types
auto mt = std::make_shared<ElementaryMoleculeType>(
name, std::vector<std::shared_ptr<ComponentType>>(),
diffusion_constant_2d, diffusion_constant_3d,
custom_time_step, custom_space_step,
target_only
);
// and then molecule instance out of it
elementary_molecules.push_back(
std::make_shared<ElementaryMolecule>(mt)
);
}
// 2) complex species defined through elementary_molecule_instances, or
// 3) declaration (name is parsed in Complex::postprocess_in_ctor)
else {
// do semantic check
check_no_extra_fields_are_set();
}
// need to finalize the initialization, also processes compartments
Complex::postprocess_in_ctor();
if (get_primary_compartment_name() == BNG::COMPARTMENT_NAME_IN ||
get_primary_compartment_name() == BNG::COMPARTMENT_NAME_OUT) {
throw ValueError(S(NAME_CLASS_SPECIES) + " with " + NAME_NAME + " " + name +
" must not use compartments " + BNG::COMPARTMENT_NAME_IN + " or " + BNG::COMPARTMENT_NAME_OUT + ".");
}
}
void set_all_custom_attributes_to_default() override {
Complex::set_all_custom_attributes_to_default();
species_id = SPECIES_ID_INVALID;
}
// using shorter printout when all_details is false
std::string to_str(const bool all_details=false, const std::string ind="") const override;
bool __eq__(const Species& other) const override;
std::shared_ptr<Complex> inst(const Orientation orientation = Orientation::DEFAULT, const std::string& compartment_name = "") override {
if (orientation != Orientation::DEFAULT && is_set(compartment_name)) {
throw ValueError(S("Maximum one of ") + NAME_ORIENTATION + " or " + NAME_COMPARTMENT_NAME + " can be set not both.");
}
// make a deep copy and set extra attributes
std::shared_ptr<Complex> res = deepcopy_complex();
res->orientation = orientation;
res->set_compartment_name(compartment_name);
return res;
}
bool skip_python_export() const override {
return is_species_superclass();
}
// default generated variant exports all details, we do not want this because
// we export just the BNGL name and recompute the diffusion constant
// and other fields from the elementary molecule types this species uses
std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
bool is_species_superclass() const {
return BNG::is_species_superclass(name);
}
bool warn_if_adding_identical_object() const { return true; }
// simulation engine mapping
species_id_t species_id;
};
} // namespace API
} // namespace MCell
#endif // API_SPECIES_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/elementary_molecule_type.h | .h | 2,257 | 83 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_ELEMENTARY_MOLECULE_TYPE_H
#define API_ELEMENTARY_MOLECULE_TYPE_H
#include "bng/bng_defines.h"
#include "generated/gen_elementary_molecule_type.h"
#include "api/api_common.h"
#include "api/elementary_molecule.h"
namespace BNG {
class BNGData;
class ElemMolType;
}
namespace MCell {
namespace API {
class ElementaryMoleculeType:
public GenElementaryMoleculeType, public std::enable_shared_from_this<ElementaryMoleculeType> {
public:
ELEMENTARY_MOLECULE_TYPE_CTOR()
static std::shared_ptr<API::ElementaryMoleculeType> construct_from_bng_elem_mol_type(
const BNG::BNGData& bng_data,
const BNG::ElemMolType& bng_mt);
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
mol_type_id = BNG::ELEM_MOL_TYPE_ID_INVALID;
}
std::shared_ptr<ElementaryMolecule> inst(
const std::vector<std::shared_ptr<Component>> components,
const std::string& compartment_name = STR_UNSET) override {
return std::make_shared<ElementaryMolecule>( shared_from_this(), components, compartment_name);
}
bool __eq__(const ElementaryMoleculeType& other) const override;
std::string to_bngl_str() const override;
bool skip_python_export() const override;
// added methods
std::string get_canonical_name() const;
bool all_numerical_attributes_are_unset() const {
// NOTE: this must be updated when attributtes are added
return
!is_set(diffusion_constant_2d) &&
!is_set(diffusion_constant_3d) &&
!is_set(custom_time_step) &&
!is_set(custom_space_step) &&
!target_only
;
}
bool warn_if_adding_identical_object() const { return false; }
// mapping to MCell4
BNG::elem_mol_type_id_t mol_type_id;
};
} // namespace API
} // namespace MCell
#endif // API_ELEMENTARY_MOLECULE_TYPE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/mcell4_converter.h | .h | 5,089 | 169 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_MCELL4_CONVERTER_H_
#define LIBMCELL_API_MCELL4_CONVERTER_H_
#include <vector>
#include "defines.h"
#include "mol_or_rxn_count_event.h"
#include "api/bng_converter.h"
namespace BNG {
class ComponentType;
class Component;
class ElemMolType;
class ElemMol;
class Cplx;
class Species;
}
namespace MCell {
class World;
class Partition;
class InitialSurfaceReleases;
class GeometryObject;
class RegionExprNode;
class ReleaseEvent;
class MolOrRxnCountTerm;
class MolOrRxnCountItem;
class Region;
namespace API {
class Model;
class ComponentType;
class Component;
class ElementaryMoleculeType;
class ElementaryMolecule;
class Complex;
class SurfaceProperty;
class InitialSurfaceRelease;
class Region;
class SurfaceRegion;
class GeometryObject;
class MoleculeReleaseInfo;
class ReleaseSite;
class Count;
class CountTerm;
class Species;
class SurfaceClass;
class RngState;
class MCell4Converter {
public:
MCell4Converter(Model* model_, World* world_);
// convert all items in Model into the World representation
// throws exception if anything went wrong
// modifies model as well where it stores information for cases
// when a value such a reaction rate was updated by the user
void convert_before_init();
void convert_after_init();
// converter can be also used to convert individual objects
// throws exception if anything went wrong
MCell::ReleaseEvent* convert_single_release_event(
const std::shared_ptr<API::ReleaseSite>& r);
private:
species_id_t get_species_id(API::Species& s, const std::string class_name, const std::string object_name);
species_id_t get_species_id_for_complex(API::Complex& ci, const std::string error_msg, const bool check_orientation = true);
void get_geometry_bounding_box(Vec3& llf, Vec3& urb);
void convert_simulation_setup();
void convert_elementary_molecule_types();
void convert_species();
void convert_surface_class_rxn(API::SurfaceProperty& sp, const BNG::Species& surface_reactant);
void convert_surface_classes();
void check_surface_compartments(const BNG::RxnRule& r, BNG::compartment_id_t& surf_comp_id);
void set_vol_rxn_substance_orientation_from_compartment(
BNG::RxnRule& r, const BNG::Compartment& surf_comp, BNG::Cplx& substance);
void check_intermembrane_surface_reaction(const BNG::RxnRule& rxn);
void convert_rxns();
MCell::wall_index_t convert_wall_and_add_to_geom_object(
const API::GeometryObject& src_obj, const uint side,
MCell::Partition& p, MCell::GeometryObject& dst_obj
);
void convert_initial_surface_releases(
const std::vector<std::shared_ptr<API::InitialSurfaceRelease>>& api_releases,
std::vector<MCell::InitialSurfaceReleases>& mcell_releases
);
void convert_concentration_clamp_release(
const partition_id_t partition_id, const API::SurfaceClass& surface_class, const MCell::Region& mcell_region);
MCell::region_index_t convert_surface_region(
MCell::Partition& p,
API::SurfaceRegion& surface_region, API::GeometryObject& o,
MCell::GeometryObject& obj
);
void convert_geometry_objects();
void check_surface_compartment_name_collision(const std::string& surface_compartment_name);
void convert_compartments();
MCell::RegionExprNode* convert_region_expr_recursively(
const std::shared_ptr<API::Region>& region,
const bool is_vol,
const bool release_not_count,
MCell::RegionExpr& region_expr
);
void convert_rel_site_region_expr(API::ReleaseSite& rel_site, MCell::ReleaseEvent* rel_event);
void convert_molecule_list(
const std::vector<std::shared_ptr<MoleculeReleaseInfo>>& molecule_list,
const std::string& rel_site_name,
MCell::ReleaseEvent* rel_event);
void convert_release_events();
void convert_count_term_leaf_and_init_counting_flags(
const std::shared_ptr<API::CountTerm> ct, const int sign,
MolOrRxnCountTermVector& terms
);
void convert_count_terms_recursively(
const std::shared_ptr<API::Count> count, // only for warning printouts
const std::shared_ptr<API::CountTerm> ct,
const int sign,
MCell::MolOrRxnCountItem& info
);
void convert_mol_or_rxn_count_events_and_init_counting_flags();
void init_species_counting_flags();
void convert_viz_output_events();
void convert_initial_iteration_and_time_and_move_scheduler_time();
void add_ctrl_c_termination_event();
void check_all_mol_types_have_diffusion_const();
// after init
void convert_rng_state();
void convert_checkpointed_molecules();
Model* model;
World* world;
BNGConverter bng_converter;
};
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_MCELL4_CONVERTER_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/elementary_molecule.h | .h | 940 | 36 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_ELEMENTARY_MOLECULE_INSTANCE_H
#define API_ELEMENTARY_MOLECULE_INSTANCE_H
#include "generated/gen_elementary_molecule.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class ElementaryMolecule: public GenElementaryMolecule {
public:
ELEMENTARY_MOLECULE_CTOR()
bool __eq__(const ElementaryMolecule& other) const override;
std::string to_bngl_str(const bool with_compartment = true) const override;
bool is_surf() const;
};
} // namespace API
} // namespace MCell
#endif // API_ELEMENTARY_MOLECULE_INSTANCE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/reaction_rule.h | .h | 3,422 | 120 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_REACTION_RULE_H
#define API_REACTION_RULE_H
#include "generated/gen_reaction_rule.h"
#include "api/api_common.h"
#include "bng/bng.h"
namespace MCell {
class World;
namespace API {
class ReactionRule: public GenReactionRule {
public:
REACTION_RULE_CTOR()
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
fwd_rxn_rule_id = BNG::RXN_RULE_ID_INVALID;
rev_rxn_rule_id = BNG::RXN_RULE_ID_INVALID;
}
void check_semantics() const override {
GenReactionRule::check_semantics();
if (is_set(name) && is_set(rev_rate)) {
if (!is_set(rev_name)) {
throw ValueError(
S("If name of a reaction is set, reversible reaction must have its ") + NAME_REV_NAME + " set as well."
" Error for " + name + "."
);
}
}
if (is_set(rev_name) && !is_set(rev_rate)) {
throw ValueError(
S("Parameter ") + NAME_REV_NAME + " must not be set when " + NAME_REV_RATE + " is not set."
" Error for " + name + "."
);
}
if (is_set(variable_rate)) {
if (is_set(fwd_rate) || is_set(rev_rate)) {
throw ValueError(S("Variable rates cannot be set along with fwd_rate or rev_rate in the constructor of ") +
NAME_CLASS_REACTION_RULE + ".");
}
check_variable_rate();
}
}
void check_variable_rate() const {
for (auto& time_and_rate: variable_rate) {
if (time_and_rate.size() != 2) {
std::string msg = "[]";
if (time_and_rate.size() >= 1) {
msg = " item with time " + std::to_string(time_and_rate[0]);
}
throw ValueError("Variable rate array must contain pairs [time, rate], error for " + msg + ".");
}
}
}
bool __eq__(const ReactionRule& other) const override;
std::string to_bngl_str() const override {
return to_bngl_str_w_orientation();
}
void set_fwd_rate(const double new_fwd_rate_) override;
void set_rev_rate(const double new_rev_rate_) override;
void set_variable_rate(const std::vector<std::vector<double>> new_variable_rate_) override;
// added methods
bool is_reversible() const {
return is_set(rev_rate);
}
bool eq_reactants_and_products(const ReactionRule& other) const;
std::string to_bngl_str_w_orientation(bool replace_orientation_w_up_down_compartments = false) const;
std::string get_canonical_name() const;
bool warn_if_adding_identical_object() const { return true; }
// simulation engine mapping
bool is_initialized() const {
assert((fwd_rxn_rule_id == BNG::RXN_RULE_ID_INVALID) == (world == nullptr) &&
"When initialized, both values must be set");
return world != nullptr;
}
BNG::rxn_rule_id_t fwd_rxn_rule_id;
BNG::rxn_rule_id_t rev_rxn_rule_id;
World* world;
private:
void update_reaction_rate(const BNG::rxn_rule_id_t rxn_rule_id, const double new_rate);
};
} // namespace API
} // namespace MCell
#endif // API_REACTION_RULE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/molecule.cpp | .cpp | 862 | 36 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "molecule.h"
#include "world.h"
#include "partition.h"
namespace MCell {
namespace API {
void Molecule::remove() {
check_initialization();
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
if (!p.does_molecule_exist(id)) {
throw RuntimeError("Molecule with id " + std::to_string(id) + " does not exist anymore.");
}
// set that this molecule is defunct
world->get_partition(PARTITION_ID_INITIAL).get_m(id).set_is_defunct();
}
}
}
| C++ |
3D | mcellteam/mcell | libmcell/api/api_common.h | .h | 7,004 | 273 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_COMMON_H
#define LIBMCELL_API_COMMON_H
#ifdef _MSC_VER
#undef HAVE_UNISTD_H
#undef HAVE_SYS_TIME_H
#endif
#ifdef _WIN64
// fix for _hypot compilation issue
#define _hypot hypot
#include <cmath>
#endif
#include "pybind11/include/pybind11/pybind11.h" // make sure we won't include the system header
#include "pybind11/include/pybind11/functional.h"
#include "pybind11/include/pybind11/stl_bind.h"
namespace py = pybind11;
// must be included before any usage of std::vector in API
#include "generated/gen_vectors_make_opaque.h"
#include <ostream>
#include <sstream>
#include <exception>
#include <string>
#include <memory>
#include <functional>
namespace MCell {
namespace API {
// workaround for weird MSVC behavior, this has to be defined first before anything else is included
// TODO: can we move this below?
// auxiliary method to simply convert to std::string for when concatenating string
static std::string S(const char* s) {
return std::string(s);
}
const std::string STR_UNSET = "unset";
// Raised when an operation or function receives an argument that has the
// right type but an inappropriate value, and the situation is not described
// by a more precise exception such as IndexError.
typedef std::invalid_argument ValueError; // using naming from Python
// Raised when an error is detected that doesn’t fall in any of the other categories.
// The associated value is a string indicating what precisely went wrong.
typedef std::logic_error RuntimeError; // e.g. not defined?
// forward declarations for PYBIND11_MAKE_OPAQUE
class Component;
}
}
#include "defines.h"
#include "generated/gen_constants.h"
#include "generated/gen_names.h"
namespace MCell {
namespace API {
class Species;
typedef std::map<species_id_t, std::shared_ptr<Species>> IdSpeciesMap;
class GeometryObject;
typedef std::map<geometry_object_id_t, std::shared_ptr<GeometryObject>> IdGeometryObjectMap;
const Vec3 VEC3_UNSET(POS_INVALID);
const Vec2 VEC2_UNSET(POS_INVALID);
const void* const PTR_UNSET = nullptr;
const std::string INTROSPECTED_OBJECT = "introspected object";
// specialization for each type
static inline bool is_set(const double a) {
return a != FLT_UNSET;
}
static inline bool is_set(const int a) {
return a != INT_UNSET;
}
static inline bool is_set(const uint64_t a) {
return true; // all values are valid
}
static inline bool is_set(const Vec3& a) {
return a != VEC3_UNSET;
}
static inline bool is_set(const Vec2& a) {
return a != VEC2_UNSET;
}
static inline bool is_set(const void* a) {
return a != PTR_UNSET;
}
static inline bool is_set(const std::string& a) {
return a != STR_UNSET && a != "";
}
static inline bool is_set(const Orientation& a) {
return a != Orientation::NOT_SET;
}
static inline bool is_set(const SurfacePropertyType& a) {
return a != SurfacePropertyType::UNSET;
}
template<typename T>
static inline bool is_set(const std::shared_ptr<T>& a) {
return a.use_count() != 0;
}
template<typename T>
static inline bool is_set(const std::vector<T>& a) {
return !a.empty();
}
template<typename T1, typename T2>
int get_num_set(const T1& v1, const T2& v2) {
int res = 0;
if (is_set(v1)) {
res++;
}
if (is_set(v2)) {
res++;
}
return res;
}
template<typename T1, typename T2, typename T3>
uint get_num_set(const T1& v1, const T2& v2, const T3& v3) {
int res = get_num_set(v1, v2);
if (is_set(v3)) {
res++;
}
return res;
}
template<typename T1, typename T2, typename T3, typename T4>
uint get_num_set(const T1& v1, const T2& v2, const T3& v3, const T4& v4) {
int res = get_num_set(v1, v2, v3);
if (is_set(v4)) {
res++;
}
return res;
}
template<typename T1, typename T2, typename T3, typename T4, typename T5>
uint get_num_set(const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5) {
int res = get_num_set(v1, v2, v3, v4);
if (is_set(v5)) {
res++;
}
return res;
}
// NOTE: for some reason a definition in defines.h is not found, although it works fine for Vec3
static inline std::ostream & operator<<(std::ostream &out, const IVec3& a) {
out << "(" << a.x << ", " << a.y << ", " << a.z << ")";
return out;
}
template<typename T>
static inline std::string vec_ptr_to_str(
const std::vector<T>& arr, const bool all_details=false, const std::string ind="") {
std::stringstream ss;
ss << "[\n";
for (size_t i = 0; i < arr.size(); i++) {
ss << ind << " " << i << ":(" << arr[i]->to_str(all_details, ind) << ")";
if (i + 1 != arr.size()) {
ss << ", ";
}
ss << "\n";
}
ss << ind << "]";
return ss.str();
}
template<typename T>
static inline std::string vec_nonptr_to_str(
const std::vector<T>& arr, const bool all_details=false, const std::string ind="") {
std::stringstream ss;
ss << "[";
for (size_t i = 0; i < arr.size(); i++) {
ss << i << ":" << arr[i];
if (i + 1 != arr.size()) {
ss << ", ";
}
}
ss << "]";
return ss.str();
}
template<typename T>
static inline std::string vec_nonptr_to_str(
const std::vector<std::vector<T>>& arr, const bool all_details=false, const std::string ind="") {
std::stringstream ss;
ss << "[";
for (size_t i = 0; i < arr.size(); i++) {
ss << i << ":" << vec_nonptr_to_str(arr[i], all_details, ind + " ");
if (i + 1 != arr.size()) {
ss << ", ";
}
}
ss << "]";
return ss.str();
}
template<typename T>
static inline bool vec_ptr_eq(const std::vector<std::shared_ptr<T>>& vec1, const std::vector<std::shared_ptr<T>>& vec2) {
if (vec1.size() != vec2.size()) {
return false;
}
for (size_t i = 0; i < vec1.size(); i++) {
if (!vec1[i]->__eq__(*vec2[i])) {
return false;
}
}
return true;
}
template<typename T>
static inline void vec_set_initialized(const std::vector<std::shared_ptr<T>>& vec) {
for (const std::shared_ptr<T>& item: vec) {
item->set_initialized();
}
}
// find item with name in a vector, returns shared null if not found
template<typename T>
static inline std::shared_ptr<T> vec_find_by_name(
const std::vector<std::shared_ptr<T>>& vec, const std::string& name) {
for (auto& item: vec) {
if (item->name == name) {
return item;
}
}
return std::shared_ptr<T>(nullptr);
}
// we need to distinguish generated ctors that have all default arguments
// such as Count(...) from internal default ctors required e.g. for object copy,
// for this reason we introduce this special type
struct DefaultCtorArgType {
DefaultCtorArgType() :
unused(0) {
}
int unused;
};
} // namespace API
} // namespace MCell
#endif // LIBMCELL_API_COMMON_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/python_exporter.cpp | .cpp | 13,796 | 413 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/python_exporter.h"
#include "api/python_export_constants.h"
#include "api/python_export_utils.h"
#include "api/model.h"
#include "api/species.h"
#include "api/geometry_object.h"
#include "api/chkpt_vol_mol.h"
#include "api/chkpt_surf_mol.h"
#include "api/rng_state.h"
#include "api/checkpoint_signals.h"
#include "src/util.h"
#include "src4/world.h"
#include "src4/partition.h"
#include "src4/molecule.h"
#include "src4/custom_function_call_event.h"
#include "src4/mol_or_rxn_count_event.h"
using namespace std;
namespace MCell {
namespace API {
PythonExporter::PythonExporter(Model* model_) :
model(model_) {
assert(model != nullptr);
world = model->get_world();
assert(world != nullptr);
}
void PythonExporter::open_and_check_file(
const std::string file_name, std::ofstream& out,
const bool for_append,
const bool bngl) {
open_and_check_file_w_prefix(output_dir, file_name, out, for_append, bngl);
}
void PythonExporter::save_checkpoint(const std::string& output_dir_) {
output_dir = output_dir_;
if (output_dir.back() != BNG::PATH_SEPARATOR) {
output_dir += BNG::PATH_SEPARATOR;
}
::make_parent_dir(output_dir.c_str());
PythonExportContext ctx;
// parameters - later, once we will maintain the association,
string subsystem_name = export_subsystem(ctx);
string geometry_objects_name = export_geometry(ctx);
string instantiation_name = export_instantiation(ctx, geometry_objects_name);
// need to append - some config flag?
string observables_name = export_observables(ctx);
// molecules
// - volume
// - surface
// rng state,
// starting, ending iterations, ...
// all generated variables are prefixed with state_
std::map<std::string, std::string> config_variable_names;
export_simulation_state(ctx, config_variable_names);
// model
// - config
// - warnings
// - notifications
export_model(ctx, subsystem_name, instantiation_name, observables_name, config_variable_names);
}
std::string PythonExporter::export_subsystem(PythonExportContext& ctx) {
ofstream out;
open_and_check_file(SUBSYSTEM, out);
out << IMPORT_MCELL_AS_M;
string res_name = model->Subsystem::export_to_python(out, ctx);
out.close();
return res_name;
}
std::string PythonExporter::export_geometry(PythonExportContext& ctx) {
ofstream out;
open_and_check_file(GEOMETRY, out);
out << IMPORT_MCELL_AS_M;
out << get_import_star(SUBSYSTEM);
string res_name = model->export_vec_geometry_objects(out, ctx, "");
out.close();
return res_name;
}
std::string PythonExporter::export_instantiation(PythonExportContext& ctx, const std::string& geometry_objects_name) {
// prints out everything, even past releases
// for checkpointing, we always need to fully finish the current iteration and then start the new one
std::ofstream out;
open_and_check_file(INSTANTIATION, out);
out << IMPORT_MCELL_AS_M;
out << get_import_star(GEOMETRY);
out << "\n";
string release_sites_name = model->export_vec_release_sites(out, ctx, "");
gen_ctor_call(out, INSTANTIATION, NAME_CLASS_INSTANTIATION);
gen_param_id(out, NAME_RELEASE_SITES, release_sites_name, true);
gen_param_id(out, NAME_GEOMETRY_OBJECTS, geometry_objects_name, false);
out << CTOR_END;
out.close();
return INSTANTIATION;
}
std::string PythonExporter::export_observables(PythonExportContext& ctx) {
ofstream out;
open_and_check_file(OBSERVABLES, out);
out << IMPORT_MCELL_AS_M;
out << get_import_star(SUBSYSTEM);
out << get_import_star(GEOMETRY);
out << get_import_star(INSTANTIATION);
out << "\n";
// we need to set the initial_reactions_count of reaction counts here
// reaction counts are counted from the beginning of the simulation
for (auto& count: model->counts) {
assert(is_set(count->expression));
assert(count->count_event != nullptr);
assert(count->count_event->mol_rxn_count_items.size() == 1);
auto& mol_rxn_count_items = count->count_event->mol_rxn_count_items;
for (size_t i = 0; i < mol_rxn_count_items.size(); i++) {
if (mol_rxn_count_items[i].terms.size() == 1) {
if (count->expression->node_type == ExprNodeType::LEAF) {
count->expression->initial_reactions_count_export_override = count->get_current_value();
}
else {
assert(false && "There is just one term so there must be just one leaf node");
}
}
else {
for (const auto& count_term: mol_rxn_count_items[i].terms) {
if (count_term.is_rxn_count()) {
throw RuntimeError(
"Checkpointing of Count objects that use expressions containing reaction counts is not supported yet.");
}
}
}
}
}
string res_name = model->Observables::export_to_python(out, ctx);
out.close();
return res_name;
}
// state_variable_names are indexed by Config class attribute names
void PythonExporter::export_simulation_state(
PythonExportContext& ctx,
std::map<std::string, std::string>& config_variable_names
) {
ofstream out;
open_and_check_file(SIMULATION_STATE, out);
out << IMPORT_MCELL_AS_M;
out << get_import_star(SUBSYSTEM);
out << get_import_star(GEOMETRY);
out << "\n";
// current iteration and time
gen_assign(out, NAME_INITIAL_ITERATION, world->stats.get_current_iteration());
config_variable_names[NAME_INITIAL_ITERATION] = NAME_INITIAL_ITERATION;
gen_assign(out, NAME_INITIAL_TIME, world->stats.get_current_iteration() * world->config.time_unit);
config_variable_names[NAME_INITIAL_TIME] = NAME_INITIAL_TIME;
out << "\n";
// molecules
export_molecules(out, ctx);
// rng state
RngState rng_state = RngState(world->rng);
config_variable_names[NAME_INITIAL_RNG_STATE] = rng_state.export_to_python(out, ctx);
}
void PythonExporter::export_molecules(std::ostream& out, PythonExportContext& ctx) {
// first export used species
stringstream species_out;
species_out << "# species used by molecules but not defined in subsystem\n";
species_out << NAME_SPECIES << " = m.Vector" << NAME_CLASS_SPECIES << "([ ";
int num_exported_species = 0;
// prepare species map
IdSpeciesMap id_species_map;
for (const BNG::Species* species: world->get_all_species().get_species_vector()) {
assert(id_species_map.count(species->id) == 0);
if (species->get_num_instantiations() > 0) {
std::shared_ptr<Species> subsystem_species = model->get_species_with_id(species->id);
if (is_set(subsystem_species)) {
// use existing object
id_species_map[species->id] = subsystem_species;
}
else if (!species->is_reactive_surface()){
// - reactive surfaces/surface classes must be defined in subsystem
// - create a new object and export it directly so that all the newly used species are
// in the beginning of the simulation_state module file
shared_ptr<API::Species> new_species = make_shared<API::Species>(species->name);
std::string name = new_species->export_to_python(out, ctx);
id_species_map[species->id] = new_species;
// add it to the list of species to be used
if (num_exported_species != 0 && num_exported_species % 8 == 0) {
species_out << "\n ";
}
species_out << name << ", ";
}
}
}
species_out << "\n])\n\n";
out << species_out.str();
// prepare geometry objects map
IdGeometryObjectMap id_geometry_object_map;
for (const auto& obj: model->geometry_objects) {
assert(obj->geometry_object_id != GEOMETRY_OBJECT_ID_INVALID);
id_geometry_object_map[obj->geometry_object_id] = obj;
}
// for each partition
stringstream dummy_out;
out << NAME_CHECKPOINTED_MOLECULES << " = [\n";
for (const MCell::Partition& p: world->get_partitions()) {
// for each molecule
for (const MCell::Molecule& m: p.get_molecules()) {
if (m.is_defunct()) {
continue;
}
assert(id_species_map.count(m.species_id) != 0);
// vol
PythonExportContext dummy_ctx; // we do not want to use the pointer comparison checks in export
if (m.is_vol()) {
ChkptVolMol vm = ChkptVolMol(
m, id_species_map, world->config.time_unit, world->config.length_unit);
out << IND4 << vm.export_to_python(dummy_out, ctx) << ",\n";
}
else {
assert(m.is_surf());
ChkptSurfMol sm = ChkptSurfMol(
m, id_species_map, world->config.time_unit, world->config.length_unit,
p, id_geometry_object_map);
out << IND4 << sm.export_to_python(dummy_out, ctx) << ",\n";
}
}
}
assert(dummy_out.str() == "" && "No other code must be exported.");
out << "]\n\n";
}
std::string PythonExporter::export_model(
PythonExportContext& ctx,
const std::string& subsystem_name,
const std::string& instantiation_name,
const std::string& observables_name,
const std::map<std::string, std::string>& config_variable_names) {
// prints out everything, even past releases
// for checkpointing, we always need to fully finish the current iteration and then start the new one
std::ofstream out;
open_and_check_file(MODEL, out);
// imports
out << INTERPRETER;
out << IMPORT_SYS_OS;
out << "\n";
out << MCELL_PATH_SETUP;
out << "\n";
out << IMPORT_MCELL_AS_M;
// TODO: version check, warning
out << make_section_comment("import model and saved simulation state");
out << get_import(SUBSYSTEM);
out << get_import(INSTANTIATION);
out << get_import(OBSERVABLES);
out << get_import(SIMULATION_STATE);
out << "\n";
// create model object
out << make_section_comment("model setup");
gen_ctor_call(out, MODEL, NAME_CLASS_MODEL, false);
out << "\n";
// config, notifications, warnings
gen_assign(out, MODEL, NAME_CONFIG, model->config.export_to_python(out, ctx));
out << "\n";
gen_assign(out, MODEL, NAME_NOTIFICATIONS, model->notifications.export_to_python(out, ctx));
out << "\n";
gen_assign(out, MODEL, NAME_WARNINGS, model->warnings.export_to_python(out, ctx));
out << "\n";
// subsystem
string subsystem_prefix = S(SUBSYSTEM) + "." + subsystem_name + ".";
gen_assign(out, MODEL, NAME_SPECIES, subsystem_prefix + NAME_SPECIES);
gen_assign(out, MODEL, NAME_REACTION_RULES, subsystem_prefix + NAME_REACTION_RULES);
gen_assign(out, MODEL, NAME_SURFACE_CLASSES, subsystem_prefix + NAME_SURFACE_CLASSES);
gen_assign(out, MODEL, NAME_ELEMENTARY_MOLECULE_TYPES, subsystem_prefix + NAME_ELEMENTARY_MOLECULE_TYPES);
out << "\n";
// instantiation
string instantiation_prefix = S(INSTANTIATION) + "." + instantiation_name + ".";
gen_assign(out, MODEL, NAME_RELEASE_SITES, instantiation_prefix + NAME_RELEASE_SITES);
gen_assign(out, MODEL, NAME_GEOMETRY_OBJECTS, instantiation_prefix + NAME_GEOMETRY_OBJECTS);
out << "\n";
// observables
string observables_prefix = S(OBSERVABLES) + "." + observables_name + ".";
gen_assign(out, MODEL, NAME_VIZ_OUTPUTS, observables_prefix + NAME_VIZ_OUTPUTS);
gen_assign(out, MODEL, NAME_COUNTS, observables_prefix + NAME_COUNTS);
out << "\n";
// checkpoint-specific config
out << make_section_comment("saved simulation state and checkpoint config");
// - time step (explicit)?
vector<string> config_vars = { NAME_INITIAL_ITERATION, NAME_INITIAL_TIME, NAME_INITIAL_RNG_STATE };
for (string& var: config_vars) {
auto it = config_variable_names.find(var);
release_assert(it != config_variable_names.end());
gen_assign(out, MODEL, NAME_CONFIG, it->first, S(SIMULATION_STATE) + "." + it->second);
}
gen_assign(out, MODEL, NAME_CONFIG, NAME_APPEND_TO_COUNT_OUTPUT_DATA, true);
out << "# internal type VectorSpecies does not provide operator += yet\n";
out << "for s in " << SIMULATION_STATE << "." << NAME_SPECIES << ":\n";
out << IND4 << MODEL << "." << NAME_SPECIES << ".append(s)\n";
gen_assign(out, MODEL, NAME_CHECKPOINTED_MOLECULES, S(SIMULATION_STATE) + "." + NAME_CHECKPOINTED_MOLECULES);
out << "\n";
out << make_section_comment("resume simulation");
gen_method_call(out, MODEL, NAME_INITIALIZE);
out << "\n";
export_checkpoint_iterations(out);
gen_method_call(
out, MODEL, NAME_RUN_ITERATIONS,
S(MODEL) + "." + NAME_CONFIG + "." + NAME_TOTAL_ITERATIONS + " - " + S(SIMULATION_STATE) + "." + NAME_INITIAL_ITERATION);
gen_method_call(out, MODEL, NAME_END_SIMULATION);
out.close();
return MODEL;
}
void PythonExporter::export_checkpoint_iterations(std::ostream& out) {
vector<BaseEvent*> checkpoint_events;
world->scheduler.get_all_events_with_type_index(
EVENT_TYPE_INDEX_CALL_START_ITERATION_CHECKPOINT, checkpoint_events);
for (auto be: checkpoint_events) {
auto ce = dynamic_cast<CustomFunctionCallEvent<CheckpointSaveEventContext>*>(be);
bool arg2_nondefault = !ce->return_from_run_n_iterations;
bool arg3_nondefault = !ce->function_arg.append_it_to_dir; // with custom dir, this is false
out << MODEL << "." << NAME_SCHEDULE_CHECKPOINT << "(\n";
gen_param(out, NAME_ITERATION, ce->event_time, arg2_nondefault);
if (arg2_nondefault) {
gen_param(out, NAME_CONTINUE_SIMULATION, !ce->return_from_run_n_iterations, arg3_nondefault);
}
if (arg3_nondefault) {
gen_param(out, NAME_CUSTOM_DIR, ce->function_arg.dir_prefix, true);
}
out << ")\n";
}
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/instantiation.cpp | .cpp | 7,251 | 228 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/instantiation.h"
#include <algorithm>
#include "bng/bng.h"
#include "api/subsystem.h"
#include "api/geometry_object.h"
#include "api/surface_region.h"
#include "api/region.h"
#include "api/complex.h"
#include "generated/gen_geometry_utils.h"
using namespace std;
namespace MCell {
namespace API {
const char* const RELEASE_SITE_PREFIX = "rel_";
void Instantiation::dump() const {
std::cout << to_str() << "\n";
}
std::shared_ptr<GeometryObject> Instantiation::find_volume_compartment_object(const std::string& name) {
for (auto o: geometry_objects) {
if (o->is_bngl_compartment) {
if (o->name == name) {
return o;
}
}
}
return std::shared_ptr<GeometryObject>(nullptr);
}
std::shared_ptr<GeometryObject> Instantiation::find_surface_compartment_object(const std::string& name) {
for (auto o: geometry_objects) {
if (o->is_bngl_compartment) {
if (is_set(o->surface_compartment_name) && o->surface_compartment_name == name) {
return o;
}
}
}
return std::shared_ptr<GeometryObject>(nullptr);
}
void Instantiation::load_bngl_compartments_and_seed_species(
const std::string& file_name,
std::shared_ptr<Region> default_release_region,
const std::map<std::string, double>& parameter_overrides) {
BNG::BNGData bng_data;
int num_errors = BNG::parse_bngl_file(file_name, bng_data, parameter_overrides);
if (num_errors != 0) {
throw RuntimeError("Could not parse BNGL file " + file_name + ".");
}
// now convert everything we parsed into the API classes so that the user can
// inspect or manipulate it if needed
convert_bng_data_to_instantiation(bng_data, default_release_region);
}
void Instantiation::convert_bng_data_to_instantiation(
const BNG::BNGData& bng_data,
std::shared_ptr<Region> default_release_region) {
convert_compartments(bng_data);
for (const BNG::SeedSpecies& bng_ss: bng_data.get_seed_species()) {
convert_single_seed_species_to_release_site(bng_data, bng_ss, default_release_region);
}
}
void Instantiation::convert_compartments(const BNG::BNGData& bng_data) {
if (bng_data.get_compartments().empty()) {
return;
}
// create objects and assign 2d release regions
for (const BNG::Compartment& bng_comp: bng_data.get_compartments()) {
if (bng_comp.children_compartments.size() > 2) {
throw RuntimeError("Automatic creation of compartments with more than one child compartment "
"is not supported yet, error for '" + bng_comp.name + ".");
}
if (bng_comp.is_3d) {
std::shared_ptr<GeometryObject> existing_obj = find_geometry_object(bng_comp.name);
if (is_set(existing_obj)) {
// object with this name already exists, we will use it instead
existing_obj->is_bngl_compartment = true;
continue;
}
// compute volume using children volumes - all volumes must have been provided
// for geometry object size - we won't include the volume of surface compartments
double volume = bng_comp.get_volume_including_children(bng_data, false);
double side = pow_f(volume, 1.0/3.0);
// create box for the given compartment
shared_ptr<GeometryObject> box = geometry_utils::create_box(bng_comp.name, side);
box->is_bngl_compartment = true;
// set its 2d name
if (bng_comp.has_parent()) {
box->surface_compartment_name = bng_data.get_compartment(bng_comp.parent_compartment_id).name;
}
add_geometry_object(box);
}
// TODO: assign names of 2D compartments when 3D compartment already exists
}
}
void Instantiation::convert_single_seed_species_to_release_site(
const BNG::BNGData& bng_data,
const BNG::SeedSpecies& bng_ss,
std::shared_ptr<Region> default_release_region) {
auto rel_site = make_shared<API::ReleaseSite>(DefaultCtorArgType());
// we need to create API representation for the cplx instance we got
rel_site->complex =
Complex::construct_from_bng_cplx(bng_data, bng_ss.cplx);
// releases from BNGL always used the default orientation
rel_site->complex->orientation = Orientation::DEFAULT;
if (bng_ss.cplx.has_compartment()) {
// we might not know the types of elementary molecules at this point so we cannot check
// that molecule and compartment are of the same type (vol or surf)
const BNG::Compartment& c = bng_data.get_compartment(bng_ss.cplx.get_primary_compartment_id(true));
rel_site->complex->set_compartment_name(c.name);
rel_site->shape = Shape::COMPARTMENT;
rel_site->name =
"Release of " + rel_site->complex->to_bngl_str();
if (is_set(rel_site->complex->compartment_name)) {
rel_site->name += " at " + rel_site->complex->compartment_name;
}
}
else {
if (!is_set(default_release_region)) {
throw ValueError(S("Seed species specification for complex instance ") +
rel_site->complex->to_bngl_str() + " does not have a compartment and " +
NAME_DEFAULT_RELEASE_REGION + " was not set, don't know where to release.\n"
);
}
rel_site->region = default_release_region;
rel_site->shape = Shape::REGION_EXPR;
rel_site->name =
"Release of " + rel_site->complex->to_bngl_str() +
" at " + rel_site->region->name;
}
if (bng_ss.count > (double)UINT32_MAX) {
throw ValueError(S("Value ") + to_string(bng_ss.count) + " for " +
NAME_NUMBER_TO_RELEASE + " of a " + NAME_CLASS_RELEASE_SITE + " '" + rel_site->name +
"' created from 'seed species' BNGL section is too high, the maximum allowed is " + to_string(UINT32_MAX) + ".");
}
uint truncated_count = BNG::floor_f(bng_ss.count);
if (bng_ss.count != truncated_count) {
cout << "Warning: Release count of complex instance created from loaded BNGL file '" +
rel_site->name + "' was truncated from " << bng_ss.count << " to " << truncated_count << ".\n";
}
rel_site->number_to_release = truncated_count;
rel_site->check_semantics(); // only for internal checks
rel_site->postprocess_in_ctor(); // sets shape
release_sites.push_back(rel_site);
}
std::shared_ptr<Region> Instantiation::get_compartment_region(const std::string& name) {
std::shared_ptr<GeometryObject> obj;
// first try if it is a volume compartment
obj = find_volume_compartment_object(name);
if (is_set(obj)) {
std::shared_ptr<Region> res = std::dynamic_pointer_cast<Region>(obj);
for (auto child: obj->child_compartments) {
res = res->__sub__(std::dynamic_pointer_cast<Region>(child));
}
return res;
}
// then a surface compartment
obj = find_surface_compartment_object(name);
if (is_set(obj)) {
return std::dynamic_pointer_cast<Region>(obj);
}
// no compartment found
return std::shared_ptr<Region>(nullptr);
}
}
// namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/species.cpp | .cpp | 2,448 | 92 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/complex.h"
#include "api/species.h"
#include "api/elementary_molecule.h"
#include "api/elementary_molecule_type.h"
#include "api/python_export_utils.h"
using namespace std;
namespace MCell {
namespace API {
std::string Species::to_str(const bool all_details, const std::string ind) const {
if (!all_details) {
return ind + to_bngl_str();
}
else {
return GenComplex::to_str(true, ind);
}
}
// TODO: how to make this consistent with API definition?
bool Species::__eq__(const Species& other) const {
return
name == other.name &&
diffusion_constant_2d == other.diffusion_constant_2d &&
diffusion_constant_3d == other.diffusion_constant_3d &&
custom_time_step == other.custom_time_step &&
custom_space_step == other.custom_space_step &&
target_only == other.target_only &&
orientation == other.orientation &&
compartment_name == other.compartment_name &&
Complex::__eq__(other) // make canonical comparison
;
}
// species name is sufficient
std::string Species::export_to_python(std::ostream& out, PythonExportContext& ctx) {
if (ctx.already_exported(this)) {
return ctx.get_exported_name(this);
}
if (is_species_superclass()) {
if (name == BNG::ALL_MOLECULES) {
return S(MDOT) + NAME_CV_AllMolecules;
}
else if (name == BNG::ALL_VOLUME_MOLECULES) {
return S(MDOT) + NAME_CV_AllVolumeMolecules;
}
else if (name == BNG::ALL_SURFACE_MOLECULES) {
return S(MDOT) + NAME_CV_AllSurfaceMolecules;
}
else {
assert(false);
}
}
std::string exported_name = "species_";
if (name.size() > MAX_SPECIES_NAME_LENGTH) {
exported_name += to_string(ctx.postinc_counter("species"));
}
else {
exported_name += fix_id(name);
}
ctx.add_exported(this, exported_name);
std::stringstream ss;
ss << exported_name << " = m.Species(\n";
assert(is_set(name));
ss << " name = " << "'" << name << "'" << "\n";
ss << ")\n\n";
out << ss.str();
return exported_name;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/complex.cpp | .cpp | 12,421 | 377 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/complex.h"
#include "api/species.h"
#include "api/subsystem.h"
#include "api/component.h"
#include "api/component_type.h"
#include "api/elementary_molecule.h"
#include "api/elementary_molecule_type.h"
#include "bng/bng.h"
using namespace std;
namespace MCell {
namespace API {
static int convert_bond_value(const BNG::bond_value_t bng_bond_value) {
// we would like the BNG library to be independent, therefore
// the BNG library does not use the same constants as the API
switch (bng_bond_value) {
case BNG::BOND_VALUE_INVALID:
release_assert("Invalid bond value"); // should not really happen
return -2;
case BNG::BOND_VALUE_BOUND: // represents !+
return BOND_BOUND;
case BNG::BOND_VALUE_ANY: // represents !+
return BOND_ANY;
case BNG::BOND_VALUE_UNBOUND: // no
return BOND_UNBOUND;
default:
return bng_bond_value;
}
}
std::shared_ptr<API::Complex> Complex::construct_from_bng_cplx(
const BNG::BNGData& bng_data,
const BNG::Cplx& bng_cplx) {
std::shared_ptr<API::Complex> res_cplx_inst = API::Complex::construct_empty();
// convert each molecule instance
for (const BNG::ElemMol& bmg_em: bng_cplx.elem_mols) {
// find molecule type and create an instance
const BNG::ElemMolType& emt = bng_data.get_elem_mol_type(bmg_em.elem_mol_type_id);
std::shared_ptr<ElementaryMoleculeType> api_emt =
ElementaryMoleculeType::construct_from_bng_elem_mol_type(bng_data, emt);
assert(is_set(api_emt));
// prepare a vector of component instances with their bonds set
std::vector<std::shared_ptr<API::Component>> api_comp_instances;
for (const BNG::Component& bng_ci: bmg_em.components) {
const std::string& ct_name = bng_data.get_component_type(bng_ci.component_type_id).name;
// we need to define component type here, they are not global
// and belong to the elementary molecule type
std::shared_ptr<API::ComponentType> api_ct = vec_find_by_name(api_emt->components, ct_name);
auto api_comp_inst = make_shared<API::Component>(api_ct);
if (bng_ci.state_id != BNG::STATE_ID_DONT_CARE) {
api_comp_inst->state = bng_data.get_state_name(bng_ci.state_id);
}
api_comp_inst->bond = convert_bond_value(bng_ci.bond_value);
api_comp_instances.push_back(api_comp_inst);
}
// determine compartment name
BNG::compartment_id_t cid = bmg_em.compartment_id;
string compartment_name;
if (cid == BNG::COMPARTMENT_ID_NONE) {
compartment_name = STR_UNSET;
}
else if (BNG::is_in_out_compartment_id(cid)) {
compartment_name = BNG::compartment_id_to_str(cid);
}
else {
compartment_name = bng_data.get_compartment(cid).name;
}
// and append instantiated elementary molecule type
res_cplx_inst->elementary_molecules.push_back(api_emt->inst(api_comp_instances, compartment_name));
}
return res_cplx_inst;
}
// sets orientation if the resulting cplx is a surface cplx
std::shared_ptr<API::Complex> Complex::construct_from_bng_cplx_w_orientation(
const BNG::BNGData& bng_data,
const BNG::Cplx& bng_inst,
const Orientation orientation) {
shared_ptr<API::Complex> res =
Complex::construct_from_bng_cplx(bng_data, bng_inst);
// only after conversion we can know whether a molecule is of surface volume type,
// it is determined from the diffusion constants set with MCELL_DIFFUSION_CONSTANT_*
if (res->is_surf()) {
res->orientation = orientation;
}
return res;
}
void Complex::postprocess_in_ctor() {
if (name == STR_UNSET) {
// ignore
return;
}
// species did its own pre-initialization and simple complex has its
// elementary molecule fully defined
if (!is_species_object() && get_num_set(name, elementary_molecules) != 1) {
throw ValueError(
S("Exactly one of ") + NAME_NAME + " or " + NAME_ELEMENTARY_MOLECULES +
" must be set for " + NAME_CLASS_COMPLEX + ".");
}
if (is_set(name)) {
if (is_simple_species(name) && name.find('.') != std::string::npos) {
throw ValueError("Simple species or complex name must not contain '.', this is incompatible with BNGL definition"
", error for " + name + ".");
}
}
// if name was set, parse it and initialize elementary_molecules
if (is_set(name) && !is_set(elementary_molecules)) {
// parse BNGL string
BNG::BNGData local_bng_data;
BNG::Cplx bng_cplx(&local_bng_data);
int num_errors = BNG::parse_single_cplx_string(name, local_bng_data, bng_cplx);
if (num_errors) {
throw ValueError("Could not parse BNGL string " + name + " that defines a " + NAME_CLASS_COMPLEX + ".");
}
// convert BNG data to elementary_molecules
std::shared_ptr<API::Complex> converted_complex =
Complex::construct_from_bng_cplx(local_bng_data, bng_cplx);
// set compartment name - must be done before elementary molecules are added
if (is_set(converted_complex->compartment_name)) {
if (is_set(compartment_name) && compartment_name != converted_complex->compartment_name) {
throw ValueError("Inconsistent compartment usage in complex " + name +
", parsed compartment is " + converted_complex->compartment_name + " but compartment set as " +
NAME_COMPARTMENT_NAME + " is " + compartment_name + ".");
}
set_compartment_name(converted_complex->compartment_name);
}
// copy resulting elementary molecules array - their compartments are set
elementary_molecules = converted_complex->elementary_molecules;
}
set_unset_compartments_of_elementary_molecules();
assert(!elementary_molecules.empty());
}
const std::string& Complex::get_canonical_name() const {
if (cached_data_are_uptodate && canonical_name != "") {
return canonical_name;
}
// note: using the elementary_molecules array would be faster but using parser is simpler to implement
// get BNGL string and parse it, then get canonical name
BNG::BNGConfig bng_config;
BNG::BNGEngine bng_engine(bng_config);
// parse cplx string
string bngl_str = to_bngl_str_w_custom_orientation();
BNG::Cplx cplx_inst(&bng_engine.get_data());
int num_errors = BNG::parse_single_cplx_string(
bngl_str, bng_engine.get_data(),
cplx_inst
);
if (num_errors != 0) {
throw RuntimeError("While creating canonical name for a Complex, could not parse '" + bngl_str + "'.");
}
assert(!cplx_inst.elem_mols.empty());
// create canonical name
// we don't care that the complex may not be fully qualified, we cannot know this at this point
BNG::Species new_species(cplx_inst, bng_engine.get_data(), bng_engine.get_config(), false);
// order components by name during canonicalization
new_species.canonicalize(true);
canonical_name = new_species.name;
// conversion to Species caused compartment and orientation to be ignored
if (orientation == Orientation::UP) {
canonical_name += "'";
}
else if (orientation == Orientation::DOWN) {
canonical_name += ",";
}
// compartment_name may not be set even when elementary molecules have their compartments
if (elementary_molecules.size() != 1 && is_set(compartment_name) && compartment_name != get_primary_compartment_name()) {
canonical_name = "@" + compartment_name + ":" + canonical_name;
}
cached_data_are_uptodate = true;
return canonical_name;
}
std::string Complex::to_str(const bool all_details, const std::string ind) const {
if (!all_details) {
return ind + to_bngl_str();
}
else {
return GenComplex::to_str(true, ind);
}
}
bool Complex::__eq__(const Complex& other) const {
// cannot use eq_nonarray_attributes here because we don't care about name
if (orientation != other.orientation) {
return false;
}
if (get_canonical_name() != other.get_canonical_name()) {
return false;
}
// - query for canonical name orders elementary molecules only in
// the internal BNG representation, we want to use the API representation
// here so we must sort them ourselves
// - we assume that the name is unique (checked later when added to the model)
assert(elementary_molecules.size() == other.elementary_molecules.size());
map<string, std::shared_ptr<ElementaryMoleculeType>> emts1, emts2;
for (auto& em1: elementary_molecules) {
emts1[em1->elementary_molecule_type->name] = em1->elementary_molecule_type; // we may overwrite previous values
}
for (auto& em2: other.elementary_molecules) {
emts2[em2->elementary_molecule_type->name] = em2->elementary_molecule_type; // we may overwrite previous values
}
// - compare elementary molecule types
// (elementary molecules are already checked by canonical name comparison)
assert(emts1.size() == emts2.size());
for (auto& name_em_pair1: emts1) {
const auto& name_em_it2 = emts2.find(name_em_pair1.first);
assert(name_em_it2 != emts2.end());
if (!name_em_pair1.second->__eq__(*name_em_it2->second)) {
return false;
}
}
return true;
}
std::string Complex::to_bngl_str_w_custom_orientation(const bool include_mcell_orientation) const {
string res;
bool orientation_replaced = false;
// individual compartments are printed if all elem mols do not use the same compartment
set<string> used_compartments;
size_t num_specific_compartments = 0;
for (const auto& em: elementary_molecules) {
if (is_set(em->compartment_name)) {
num_specific_compartments++;
used_compartments.insert(em->compartment_name);
}
}
bool print_individual_compartments =
used_compartments.size() > 1 || num_specific_compartments != elementary_molecules.size();
for (size_t i = 0; i < elementary_molecules.size(); i++) {
res += elementary_molecules[i]->to_bngl_str(print_individual_compartments);
if (i + 1 != elementary_molecules.size()) {
res += ".";
}
}
if (include_mcell_orientation) {
if (orientation == Orientation::UP) {
res += "'";
}
else if (orientation == Orientation::DOWN) {
res += ",";
}
}
if (!print_individual_compartments && used_compartments.size() == 1) {
string at_str = (orientation_replaced) ? "" : "@";
if (elementary_molecules.size() != 1) {
res = at_str + *used_compartments.begin() + ":" + res;
}
else {
res += at_str + *used_compartments.begin();
}
}
return res;
}
bool Complex::is_surf() const {
for (auto em: elementary_molecules) {
if (is_set(em->elementary_molecule_type->diffusion_constant_2d)) {
return true;
}
}
return false;
}
void Complex::set_unset_compartments_of_elementary_molecules() {
// called after all initialization including parsing of the BNGL name
// does not check that compartment types are correctly used (surf/vol) because we do not know them yet
if (is_set(compartment_name)) {
// set the name to all contained elementary molecules
for (auto& em: elementary_molecules) {
if (!is_set(em->compartment_name)) {
em->compartment_name = compartment_name;
}
}
}
}
bool Complex::is_species_object() const {
return dynamic_cast<const Species*>(this) != nullptr;
}
std::shared_ptr<Species> Complex::as_species() {
return std::make_shared<Species>(*this);
}
const std::string& Complex::get_primary_compartment_name() const {
if (is_set(compartment_name)) {
return compartment_name;
}
if (elementary_molecules.size() == 1) {
return elementary_molecules[0]->compartment_name;
}
else if (is_surf()) {
// get the first surface elem mol
for (const auto& em: elementary_molecules) {
if (em->is_surf()) {
return em->compartment_name;
}
}
// unreachable
throw RuntimeError("Internal error: surface complex " + to_bngl_str() + " does not contain any surface elementary molecules.");
}
else {
// all are volume and must have the same compartment
return elementary_molecules[0]->compartment_name;
}
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/base_introspection_class.h | .h | 1,771 | 62 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_BASE_INTROSPECTION_CLASS_H_
#define LIBMCELL_API_BASE_INTROSPECTION_CLASS_H_
#include "api/api_common.h"
#include "base_data_class.h"
namespace MCell {
class World;
namespace API {
// base class for all classes that hold the model input data
class BaseIntrospectionClass: public BaseDataClass {
public:
BaseIntrospectionClass()
: world(nullptr) {
name = INTROSPECTED_OBJECT;
// - introspected objects are assumed to be initialized because they are returned
// by API methods and this does not depend on model initialization
// - this flag is checked in set_* methods and must be true to avoid ignoring writes to attributes
initialized = true;
}
virtual ~BaseIntrospectionClass() {
}
void check_initialization() const {
if (world == nullptr) {
throw RuntimeError(
"Object of class " + class_name + " was not correctly initialized. "
"Introspection objects cannot be created independently. they must always be retrieved through "
"methods of the " + NAME_CLASS_MODEL + " class."
);
}
}
void set_all_attributes_as_default_or_unset() {
BaseDataClass::set_all_attributes_as_default_or_unset();
world = nullptr;
}
// internal World pointer
World* world;
};
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_BASE_INTROSPECTION_CLASS_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/bngl_utils.cpp | .cpp | 1,039 | 44 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "generated/gen_geometry_utils.h"
#include "bng/bng.h"
#include "api/geometry_object.h"
using namespace std;
namespace MCell {
namespace API {
namespace bngl_utils {
std::map<std::string, double> load_bngl_parameters(
const std::string& file_name,
const std::map<std::string, double>& parameter_overrides
) {
BNG::BNGData bng_data;
int num_errors = BNG::parse_bngl_file(file_name, bng_data, parameter_overrides);
if (num_errors != 0) {
throw RuntimeError("Could not parse BNGL file " + file_name + ".");
}
return bng_data.get_parameters();
}
} // namespace bngl_utils
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/globals.h | .h | 1,020 | 41 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
/**
* This header includes all C++ classes of MCell API.
* File should be used only from outside of this library to avoid cyclic includes.
*/
#ifndef API_GLOBALS_H
#define API_GLOBALS_H
#include <memory>
#ifdef _MSC_VER
#undef HAVE_UNISTD_H
#undef HAVE_SYS_TIME_H
#endif
#include "pybind11/include/pybind11/pybind11.h" // make sure we won't include the system header
namespace py = pybind11;
namespace MCell {
namespace API {
class Species;
extern std::shared_ptr<Species> AllMolecules;
extern std::shared_ptr<Species> AllVolumeMolecules;
extern std::shared_ptr<Species> AllSurfaceMolecules;
}
}
#endif // API_GLOBALS_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/pybind11_stl_include.h | .h | 874 | 34 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
// Windows build needs a fix otherwise this compilation error occurs:
// msys/mingw64/include/c++/10.2.0/cmath:1121:11: error: 'hypot' has not been declared in '::'
#ifndef API_PYBIND_STL_INCLUDE
#define API_PYBIND_STL_INCLUDE
#ifdef _WIN64
// fix for _hypot compilation issue
#define _hypot hypot
#include <cmath>
#endif
#ifdef _MSC_VER
#undef HAVE_UNISTD_H
#undef HAVE_SYS_TIME_H
#endif
#include "libs/pybind11/include/pybind11/stl.h"
#ifndef _WIN64
#undef _hypot
#endif
#endif
| Unknown |
3D | mcellteam/mcell | libmcell/api/introspection.cpp | .cpp | 8,422 | 241 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/introspection.h"
#include "api/model.h"
#include "api/api_utils.h"
#include "api/molecule.h"
#include "api/wall.h"
#include "api/geometry_object.h"
#include "api/color.h"
#include "api/bng_converter.h"
#include "world.h"
#include "src4/geometry_utils.h" // TODO: we should rename the src4 directory
#include "bng/cplx.h"
using namespace std;
namespace MCell {
namespace API {
static void object_is_set_and_initialized(std::shared_ptr<GeometryObject> object) {
if (!is_set(object)) {
throw ValueError(S("Argument passed as ") + NAME_CLASS_GEOMETRY_OBJECT + " must not be None.");
}
object->check_is_initialized();
}
void Introspection::initialize_introspection(Model* model_) {
model_inst = model_;
world = model_inst->get_world();
assert(world != nullptr);
}
std::vector<int> Introspection::get_molecule_ids(std::shared_ptr<Complex> pattern) {
std::vector<int> res;
// NOTE: some caching might be useful here if this function is called often
uint_set<species_id_t> matching_species, not_matching_species;
BNG::Cplx bng_pattern(&world->bng_engine.get_data());
BNG::compartment_id_t primary_compartment_id = BNG::COMPARTMENT_ID_NONE;
if (is_set(pattern)) {
// convert to its BNG representation for matching
BNGConverter converter(world->bng_engine.get_data(), world->bng_engine.get_config());
bng_pattern = converter.convert_complex(*pattern, true);
if (bng_pattern.has_compartment()) {
// remove primary compartment were set, better explanation is in
// MCell4Converter::convert_count_term_leaf_and_init_counting_flags
primary_compartment_id = bng_pattern.get_primary_compartment_id();
bng_pattern.remove_compartment_from_elem_mols(primary_compartment_id);
}
}
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
std::vector<MCell::Molecule>& molecules = p.get_molecules();
for (MCell::Molecule& m: molecules) {
if (m.is_defunct()) {
continue;
}
if (is_set(pattern)) {
// include only molecules that match the pattern
if (matching_species.count(m.species_id) != 0) {
res.push_back(m.id);
}
else if (not_matching_species.count(m.species_id) != 0) {
// nothing to do
}
else {
// not seen species
const BNG::Species& species = world->get_all_species().get(m.species_id);
BNG::compartment_id_t species_compartment = species.get_primary_compartment_id();
bool match = species.matches_pattern(bng_pattern, true) &&
(primary_compartment_id == BNG::COMPARTMENT_ID_NONE || primary_compartment_id == species_compartment);
if (match) {
matching_species.insert(m.species_id);
res.push_back(m.id);
}
else {
not_matching_species.insert(m.species_id);
}
}
}
else {
res.push_back(m.id);
}
}
return res;
}
std::shared_ptr<API::Molecule> Introspection::get_molecule(const int id) {
std::shared_ptr<API::Molecule> res;
Partition& p = world->get_partition(PARTITION_ID_INITIAL);
if (!p.does_molecule_exist(id)) {
throw RuntimeError("Molecule with id " + to_string(id) + " does not exist.");
}
MCell::Molecule& m = p.get_m(id);
assert(!m.is_defunct() && "is_defunct is checked already by does_molecule_exist()");
res = make_shared<API::Molecule>(DefaultCtorArgType());
res->id = m.id;
res->species_id = m.species_id;
if (m.is_surf()) {
const MCell::Wall& w = p.get_wall(m.s.wall_index);
const Vec3& w_vert0 = p.get_wall_vertex(w, 0);
res->type = MoleculeType::SURFACE;
res->pos2d = Vec2(m.s.pos * Vec2(world->config.length_unit)).to_vec();
res->pos3d = Vec3(GeometryUtils::uv2xyz(m.s.pos, w, w_vert0) * Vec3(world->config.length_unit)).to_vec();
res->orientation = convert_mcell_orientation(m.s.orientation);
res->geometry_object = model_inst->get_geometry_object_with_id(w.object_id);
assert(is_set(res->geometry_object));
res->wall_index = m.s.wall_index - res->geometry_object->first_wall_index;
}
else {
res->type = MoleculeType::VOLUME;
res->pos3d = Vec3(m.v.pos * Vec3(world->config.length_unit)).to_vec();
res->orientation = Orientation::NONE;
}
res->world = world;
res->set_initialized();
return res;
}
std::string Introspection::get_species_name(const int species_id) {
if (!world->get_all_species().is_valid_id(species_id)) {
throw RuntimeError("Species with id " + to_string(species_id) + " does not exist.");
}
return world->get_all_species().get(species_id).name;
}
std::vector<double> Introspection::get_vertex(std::shared_ptr<GeometryObject> object, const int vertex_index) {
const MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL);
return
Vec3(
p.get_geometry_vertex(object->get_partition_vertex_index(vertex_index)) * Vec3(world->config.length_unit)
).to_vec();
}
std::shared_ptr<Wall> Introspection::get_wall(std::shared_ptr<GeometryObject> object, const int wall_index) {
object_is_set_and_initialized(object);
const MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL);
const MCell::Wall& w = p.get_wall(object->get_partition_wall_index(wall_index));
auto res = make_shared<Wall>(DefaultCtorArgType());
res->geometry_object = object;
res->wall_index = wall_index;
for (uint i = 0; i < VERTICES_IN_TRIANGLE; i++) {
res->vertices.push_back(Vec3(p.get_geometry_vertex(w.vertex_indices[i]) * Vec3(world->config.length_unit)).to_vec());
}
res->area = w.area * world->config.length_unit * world->config.length_unit;
assert(cmp_eq(len3(w.normal), (pos_t)1));
res->unit_normal = w.normal.to_vec();
res->is_movable = w.is_movable;
res->world = world;
return res;
}
std::vector<double> Introspection::get_vertex_unit_normal(std::shared_ptr<GeometryObject> object, const int vertex_index) {
object_is_set_and_initialized(object);
const MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL);
const std::vector<wall_index_t>& walls = p.get_walls_using_vertex(object->get_partition_vertex_index(vertex_index));
if (walls.empty()) {
throw RuntimeError("Internal error: there are no walls that use vertex with index " +
to_string(vertex_index) + " of object " + object->name + ".");
}
Vec3 normals_sum = Vec3(0);
for (wall_index_t wi: walls) {
const MCell::Wall& w = p.get_wall(wi);
// wall normals are already unit vectors so we can just sum them
normals_sum = normals_sum + w.normal;
}
return Vec3(normals_sum / Vec3(len3(normals_sum))).to_vec();
}
std::vector<double> Introspection::get_wall_unit_normal(std::shared_ptr<GeometryObject> object, const int wall_index) {
object_is_set_and_initialized(object);
const MCell::Partition& p = world->get_partition(PARTITION_ID_INITIAL);
const MCell::Wall& w = p.get_wall(object->get_partition_wall_index(wall_index));
// the value is is already normalized
assert(cmp_eq(len3(w.normal), (pos_t)1));
return w.normal.to_vec();
}
std::shared_ptr<Color> Introspection::get_wall_color(std::shared_ptr<GeometryObject> object, const int wall_index) {
object_is_set_and_initialized(object);
wall_index_t wi = object->get_partition_wall_index(wall_index);
const MCell::GeometryObject& obj = world->get_geometry_object(object->geometry_object_id);
rgba_t color = obj.get_wall_color(wi);
std::shared_ptr<Color> res = make_shared<Color>(DefaultCtorArgType());
res->set_rgba(color); // must use setter - initializes also other attributes
return res;
}
void Introspection::set_wall_color(
std::shared_ptr<GeometryObject> object, const int wall_index, std::shared_ptr<Color> color) {
object_is_set_and_initialized(object);
object_is_set_and_initialized(object);
wall_index_t wi = object->get_partition_wall_index(wall_index);
MCell::GeometryObject& obj = world->get_geometry_object(object->geometry_object_id);
obj.set_wall_color(wi, color->get_rgba());
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/mcell.h | .h | 1,833 | 71 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
/**
* This header includes all C++ classes of MCell API.
* File should be used only from outside of this library to avoid cyclic includes.
*/
#ifndef API_MCELL_H
#define API_MCELL_H
#include "api/api_common.h"
#include "api/component_type.h"
#include "api/component.h"
#include "api/elementary_molecule_type.h"
#include "api/elementary_molecule.h"
#include "api/complex.h"
#include "api/species.h"
#include "api/surface_property.h"
#include "api/surface_class.h"
#include "api/reaction_rule.h"
#include "api/subsystem.h"
#include "api/color.h"
#include "api/region.h"
#include "api/initial_surface_release.h"
#include "api/surface_region.h"
#include "api/geometry_object.h"
#include "api/release_pattern.h"
#include "api/molecule_release_info.h"
#include "api/release_site.h"
#include "api/instantiation.h"
#include "api/count_term.h"
#include "api/count.h"
#include "api/viz_output.h"
#include "api/observables.h"
#include "api/api_config.h"
#include "api/notifications.h"
#include "api/warnings.h"
#include "api/model.h"
#include "api/molecule.h"
#include "api/wall.h"
#include "api/wall_wall_hit_info.h"
#include "api/introspection.h"
#include "api/mol_wall_hit_info.h"
#include "api/reaction_info.h"
#include "api/chkpt_vol_mol.h"
#include "api/chkpt_surf_mol.h"
#include "api/rng_state.h"
#include "generated/gen_geometry_utils.h"
#include "generated/gen_bngl_utils.h"
#include "api/shared_structs.h"
#endif // API_MCELL_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/chkpt_vol_mol.h | .h | 1,111 | 51 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_CHKPT_VOL_MOL_H
#define API_CHKPT_VOL_MOL_H
#include "generated/gen_chkpt_vol_mol.h"
#include "api/api_common.h"
#include "api/base_chkpt_mol.h"
namespace MCell {
class Molecule;
namespace API {
class ChkptVolMol: public GenChkptVolMol {
public:
CHKPT_VOL_MOL_CTOR()
ChkptVolMol(
const MCell::Molecule& vm,
const IdSpeciesMap& id_species_map, const double time_unit,
const double length_unit);
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
type = MoleculeType::VOLUME;
}
virtual ~ChkptVolMol() {
};
};
} // namespace API
} // namespace MCell
#endif // API_CHKPT_VOL_MOL_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/base_data_class.h | .h | 2,679 | 92 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_BASE_DATA_CLASS_H_
#define LIBMCELL_API_BASE_DATA_CLASS_H_
#include "api/api_common.h"
#include "api/base_export_class.h"
namespace MCell {
namespace API {
class PythonExportContext;
// base class for all classes that hold the model input data
class BaseDataClass: public BaseExportClass {
public:
BaseDataClass()
: class_name(STR_UNSET), name(STR_UNSET), initialized(false), cached_data_are_uptodate(false) {
}
virtual ~BaseDataClass() {
}
// we are storing class name for reporting
std::string class_name;
virtual void set_class_name(const std::string& class_name_) {
class_name = class_name_;
}
virtual const std::string& get_class_name() const {
return class_name;
}
// every object defined by the MCell API might have its name
std::string name;
virtual void set_name(const std::string& name_) {
cached_data_are_uptodate = false;
name = name_;
}
virtual const std::string& get_name() const {
cached_data_are_uptodate = false; // might be modified in theory
return name;
}
bool initialized;
virtual void set_initialized() = 0;
// attribute used when some caching is employed
mutable bool cached_data_are_uptodate;
// this method is used to identify this particular object in error messages
virtual std::string get_object_name() const {
return get_class_name() + " '" + get_name() + "'";
}
// empty implementation, to be overridden in actual derived classes
virtual void postprocess_in_ctor() { };
// empty implementation, to be overridden in actual derived classes
virtual void check_semantics() const { };
// empty implementation, to be overridden in actual derived classes
virtual std::string to_str(const bool all_details=false, const std::string ind="") const {
assert(false);
return "String dump for a derived class is not implemented.";
}
// initialization for custom constructors
virtual void set_all_attributes_as_default_or_unset() {
name = STR_UNSET;
initialized = false;
cached_data_are_uptodate = false;
};
// calls virtual method, usually no need to override
virtual void dump() const {
std::cout << to_str() << "\n";
}
};
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_BASE_DATA_CLASS_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/warnings.h | .h | 1,021 | 38 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_WARNINGS_H
#define API_WARNINGS_H
#include "generated/gen_warnings.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class Warnings: public GenWarnings {
public:
WARNINGS_CTOR()
// must be called also manually during model initialization
void check_semantics() const override {
if (high_reaction_probability == WarningLevel::ERROR) {
throw ValueError(S(NAME_CLASS_WARNINGS) + "." + NAME_HIGH_REACTION_PROBABILITY + " must not be set to " +
NAME_ENUM_WARNING_LEVEL + "." + NAME_EV_ERROR + ".");
}
}
};
} // namespace API
} // namespace MCell
#endif // API_WARNINGS_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/base_export_class.h | .h | 1,761 | 65 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_BASE_EXPORT_CLASS_H_
#define LIBMCELL_API_BASE_EXPORT_CLASS_H_
#include "api/api_common.h"
namespace MCell {
namespace API {
class PythonExportContext;
// base class for all classes that provide export to python
class BaseExportClass {
public:
virtual ~BaseExportClass() {
}
// may be overridden by the final class if needed
virtual void set_all_custom_attributes_to_default() {
}
// used in generated export_to_python to optionally skip export of some objects
virtual bool skip_python_export() const {
return false;
}
// do not export vectors (used in Complex class)
virtual bool skip_vectors_export() const {
return false;
}
// export as a string without newlines (used in Complex class),
// may not be applied to exported vectors
virtual bool export_as_string_without_newlines() const {
return false;
}
// do not check if already exported
virtual bool export_even_if_already_exported() const {
return false;
}
// either returns the whole definition as a string or prints definition to out and
// returns name
virtual std::string export_to_python(std::ostream& out, PythonExportContext& ctx) {
assert(false);
return "Export to Python for a derived class is not implemented.";
}
};
} // namespace API
} // namespace MCell
#endif /* LIBMCELL_API_BASE_EXPORT_CLASS_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/chkpt_vol_mol.cpp | .cpp | 919 | 37 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/chkpt_vol_mol.h"
#include "api/base_chkpt_mol.h"
#include "src4/molecule.h"
using namespace std;
namespace MCell {
namespace API {
ChkptVolMol::ChkptVolMol(
const MCell::Molecule& vm,
const IdSpeciesMap& id_species_map, const double time_unit,
const double length_unit) :
GEN_CHKPT_MOL_CTOR(GenChkptVolMol, vm, id_species_map, time_unit) {
assert(vm.id != MOLECULE_ID_INVALID);
type = MoleculeType::VOLUME;
pos = vm.v.pos * Vec3(length_unit);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/rng_state.h | .h | 1,120 | 44 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_RNG_STATE_H
#define API_RNG_STATE_H
#include "generated/gen_rng_state.h"
#include "api/api_common.h"
struct rng_state;
namespace MCell {
namespace API {
class RngState: public GenRngState {
public:
RNG_STATE_CTOR()
void check_semantics() const override {
if (randslr.size() != RNG_SIZE) {
throw ValueError(S("List ") + NAME_RANDSLR + " must have exactly " + std::to_string(RNG_SIZE) + " items.");
}
if (mm.size() != RNG_SIZE) {
throw ValueError(S("List ") + NAME_MM + " must have exactly " + std::to_string(RNG_SIZE) + " items.");
}
}
// internal, used for checkpointing
RngState(const rng_state& rng);
};
} // namespace API
} // namespace MCell
#endif // API_RNG_STATE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/count_term.h | .h | 4,219 | 122 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COUNT_TERM_H
#define API_COUNT_TERM_H
#include "generated/gen_count_term.h"
#include "api/api_common.h"
#include "api/region.h"
#include "api/reaction_rule.h"
#include "api/complex.h"
namespace MCell {
namespace API {
class CountTerm: public GenCountTerm, public std::enable_shared_from_this<CountTerm> {
public:
COUNT_TERM_CTOR()
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
initial_reactions_count_export_override = 0;
}
void check_semantics() const override {
GenCountTerm::check_semantics();
if (is_set(reaction_rule) && is_set(reaction_rule->rev_rate)) {
throw ValueError(S("Reversible reactions cannot counted because it is not clear which direction should be counted.") +
" Error for " + NAME_CLASS_COUNT_TERM + " " + name + ". Split the reaction rule into its forward and reverse variants if needed.");
}
// TODO: add test for this case, not sure if the check works correctly because pattern does not have to be initialized
if (is_set(get_pattern(false)) &&
BNG::get_in_or_out_compartment_id(get_pattern()->compartment_name) != BNG::COMPARTMENT_ID_INVALID) {
throw ValueError(
S(NAME_CLASS_COUNT) + " or " + NAME_CLASS_COUNT_TERM + " must not use compartment class name " +
get_pattern()->get_primary_compartment_name() + ".");
}
}
// called from Count::check_semantics()
void check_that_species_or_reaction_rule_is_set() {
if (node_type == ExprNodeType::LEAF) {
uint num_set = get_num_set(species_pattern, molecules_pattern, reaction_rule);
if (num_set != 1) {
// NOTE: does not give much information on where to search for the error
throw ValueError(
S("Exactly one of ") + NAME_SPECIES_PATTERN + ", " +
NAME_MOLECULES_PATTERN + " or " + NAME_REACTION_RULE + " must be set for one of the " +
NAME_CLASS_COUNT_TERM + " used in " + NAME_CLASS_COUNT + ".");
}
}
else {
left_node->check_that_species_or_reaction_rule_is_set();
right_node->check_that_species_or_reaction_rule_is_set();
}
}
std::shared_ptr<CountTerm> create_expr_term(ExprNodeType op, std::shared_ptr<CountTerm> op2) {
std::shared_ptr<CountTerm> res = std::make_shared<CountTerm>(DefaultCtorArgType());
res->node_type = op;
res->left_node = shared_from_this();
res->right_node = op2;
return res;
}
std::shared_ptr<CountTerm> __add__(std::shared_ptr<CountTerm> op2) override {
return create_expr_term(ExprNodeType::ADD, op2);
}
std::shared_ptr<CountTerm> __sub__(std::shared_ptr<CountTerm> op2) override {
return create_expr_term(ExprNodeType::SUB, op2);
}
// manually added, may return empty shared_ptr if reaction_rule
// is counted
std::shared_ptr<Complex> get_pattern(bool must_be_present = true) const {
if (is_set(species_pattern)) {
return species_pattern;
}
else if (is_set(molecules_pattern)) {
return molecules_pattern;
}
else {
assert(!must_be_present || is_set(reaction_rule));
return std::shared_ptr<Complex>(nullptr);
}
}
std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override {
// we need to overwrite the current value for export however we do not want to change it
// permanently
uint64_t initial_reactions_count_orig = initial_reactions_count;
initial_reactions_count = initial_reactions_count_export_override;
std::string res = GenCountTerm::export_to_python(out, ctx);
initial_reactions_count = initial_reactions_count_orig;
return res;
}
uint64_t initial_reactions_count_export_override;
};
} // namespace API
} // namespace MCell
#endif // API_COUNT_TERM_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/reaction_rule.cpp | .cpp | 4,942 | 187 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/complex.h"
#include "api/reaction_rule.h"
#include "bng/bngl_names.h"
#include "world.h"
#include <set>
using namespace std;
namespace MCell {
namespace API {
bool ReactionRule::__eq__(const ReactionRule& other) const {
// ignore name when comparing
if (!eq_nonarray_attributes(other, true)) {
return false;
}
if (variable_rate != other.variable_rate) {
return false;
}
string n1 = get_canonical_name();
string n2 = other.get_canonical_name();
return n1 == n2;
}
static std::string get_rxn_side_str(
const std::vector<std::shared_ptr<Complex>>& cplxs,
const bool canonical) {
string res;
if (!cplxs.empty()) {
for (size_t i = 0; i < cplxs.size(); i++) {
if (!canonical) {
res += cplxs[i]->to_bngl_str();
}
else {
res += cplxs[i]->get_canonical_name();
}
if (i + 1 != cplxs.size()) {
res += " + ";
}
}
}
else {
res = BNG::COMPLEX_ZERO;
}
return res;
}
static std::string get_rxn_str(
const std::vector<std::shared_ptr<Complex>>& reactants,
const std::vector<std::shared_ptr<Complex>>& products,
const double rev_rate,
bool canonical) {
string res;
res = get_rxn_side_str(reactants, canonical);
if (is_set(rev_rate)) {
res += " <-> ";
}
else {
res += " -> ";
}
res += get_rxn_side_str(products, canonical);
return res;
}
std::string ReactionRule::to_bngl_str_w_orientation(
bool replace_orientation_w_up_down_compartments) const {
return get_rxn_str(reactants, products, rev_rate, replace_orientation_w_up_down_compartments);
}
static void sort_by_canonical_name(std::vector<std::shared_ptr<Complex>>& vec) {
std::sort(vec.begin(), vec.end(),
[](const std::shared_ptr<Complex>& a, const std::shared_ptr<Complex>& b) -> bool {
return a->get_canonical_name() < b->get_canonical_name();
});
}
std::string ReactionRule::get_canonical_name() const {
std::vector<std::shared_ptr<Complex>> r_sorted = reactants;
sort_by_canonical_name(r_sorted);
std::vector<std::shared_ptr<Complex>> p_sorted = products;
sort_by_canonical_name(p_sorted);
return get_rxn_str(r_sorted, p_sorted, rev_rate, true);
}
void ReactionRule::update_reaction_rate(const BNG::rxn_rule_id_t rxn_rule_id, const double new_rate) {
assert(is_initialized());
if (world->scheduler.get_event_being_executed() != nullptr) {
throw ValueError("Reaction rates cannot be changed in callbacks or in between of iterations.");
}
BNG::RxnRule* rxn = world->get_all_rxns().get(rxn_rule_id);
bool updated = rxn->update_rxn_rate(new_rate);
if (updated && rxn->is_unimol()) {
world->reset_unimol_rxn_times(rxn_rule_id);
}
}
void ReactionRule::set_fwd_rate(const double new_fwd_rate_) {
if (!is_set(new_fwd_rate_)) {
throw ValueError(S("Attribute ") + NAME_FWD_RATE + " must be set to a different value than " +
NAME_CV_FLT_UNSET + ".");
}
if (is_initialized()) {
update_reaction_rate(fwd_rxn_rule_id, new_fwd_rate_);
cached_data_are_uptodate = false;
fwd_rate = new_fwd_rate_;
}
else {
cached_data_are_uptodate = false;
fwd_rate = new_fwd_rate_;
}
}
void ReactionRule::set_rev_rate(const double new_rev_rate_) {
if (is_initialized()) {
// TODO: add test
if (is_set(rev_rate) && !is_set(new_rev_rate_)) {
throw ValueError(S("Attribute ") + NAME_REV_RATE + " must be set to a different value than " +
NAME_CV_FLT_UNSET + " is this " + NAME_CLASS_REACTION_RULE + " was initialized as a reversible reaction.");
}
// update the existing rule
release_assert(rev_rxn_rule_id != BNG::RXN_RULE_ID_INVALID);
update_reaction_rate(rev_rxn_rule_id, new_rev_rate_);
cached_data_are_uptodate = false;
rev_rate = new_rev_rate_;
}
else {
cached_data_are_uptodate = false;
rev_rate = new_rev_rate_;
}
}
void ReactionRule::set_variable_rate(const std::vector<std::vector<double>> new_variable_rate_) {
if (initialized) {
throw RuntimeError("Value 'variable_rate' of object with name " + name + " (class " + class_name + ") "
"cannot be set after model was initialized.");
}
if (is_reversible()) {
throw RuntimeError(S("Cannot set ") + NAME_VARIABLE_RATE + " for a reversible reaction.");
}
cached_data_are_uptodate = false;
variable_rate = new_variable_rate_;
check_variable_rate();
// reset fwd rate so that the variable rate is used
fwd_rate = FLT_UNSET;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/region.h | .h | 2,780 | 88 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_REGION_H
#define API_REGION_H
#include "generated/gen_region.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
enum class RegionType {
UNKNOWN,
VOLUME,
SURFACE
};
class Region: public GenRegion, public std::enable_shared_from_this<Region> {
public:
REGION_CTOR()
void postprocess_in_ctor() {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
region_type = RegionType::UNKNOWN;
}
std::shared_ptr<Region> __add__(std::shared_ptr<Region> other) override {
check_has_compatible_type(other, false);
std::shared_ptr<Region> res = std::make_shared<Region>(RegionNodeType::UNION, shared_from_this(), other);
res->region_type = other->region_type;
return res;
}
std::shared_ptr<Region> __sub__(std::shared_ptr<Region> other) override {
check_has_compatible_type(other, true);
std::shared_ptr<Region> res = std::make_shared<Region>(RegionNodeType::DIFFERENCE, shared_from_this(), other);
res->region_type = other->region_type;
return res;
}
std::shared_ptr<Region> __mul__(std::shared_ptr<Region> other) override {
check_has_compatible_type(other, false);
std::shared_ptr<Region> res = std::make_shared<Region>(RegionNodeType::INTERSECT, shared_from_this(), other);
res->region_type = other->region_type;
return res;
}
// added
void check_has_compatible_type(std::shared_ptr<Region> other, const bool is_sub = false) {
bool ok = true;
if (is_sub) {
ok = (class_name == NAME_CLASS_GEOMETRY_OBJECT && other->region_type == RegionType::SURFACE) ||
region_type == other->region_type;
}
else {
ok = (region_type == other->region_type);
}
if (!ok) {
throw RuntimeError(S("When creating regions, one can only combine regions of identical type ") +
"(both volume or both surface)" +
", also one can subtract a " + NAME_CLASS_SURFACE_REGION + " from a " + NAME_CLASS_GEOMETRY_OBJECT + ", error for:\n" +
to_str() + "and\n" + other->to_str() +
"-- end of error message related to combining regions of different type --");
}
}
// set to true in GeometryObject, allows to find out whether it is safe to
// cast this object to a GeometryObject
RegionType region_type;
};
} // namespace API
} // namespace MCell
#endif // API_REGION_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/molecule.h | .h | 729 | 33 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_MOLECULE_H
#define API_MOLECULE_H
#include "generated/gen_molecule.h"
#include "api/api_common.h"
#include "api/species.h"
namespace MCell {
namespace API {
class Molecule: public GenMolecule {
public:
MOLECULE_CTOR_NOARGS()
void remove() override;
};
} // namespace API
} // namespace MCell
#endif // API_MOLECULE_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/bng_converter.cpp | .cpp | 8,140 | 238 | /******************************************************************************
*
* Copyright (C) 2020-2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/bng_converter.h"
#include "api/component_type.h"
#include "api/elementary_molecule_type.h"
#include "api/complex.h"
#include "api/api_utils.h"
#include "bng/bng.h"
using namespace std;
namespace MCell {
namespace API {
BNG::component_type_id_t BNGConverter::convert_component_type(
const std::string& elem_mol_type_name, API::ComponentType& api_ct) {
// component types are identified by their name and set of allowed states, not just by their name
BNG::ComponentType bng_ct;
bng_ct.name = api_ct.name;
bng_ct.elem_mol_type_name = elem_mol_type_name;
for (string& s: api_ct.states) {
bng_ct.allowed_state_ids.insert( bng_data.find_or_add_state_name(s) );
}
BNG::component_type_id_t ct_id = bng_data.find_or_add_component_type(bng_ct);
if (ct_id == BNG::COMPONENT_TYPE_ID_INVALID) {
throw ValueError("Conflicting component type " + api_ct.to_bngl_str() + ", " +
" component with the same name already exists but has different allowed states.");
}
return ct_id;
}
BNG::Component BNGConverter::convert_component_instance(
const std::string& elem_mol_type_name, API::Component& api_ci) {
BNG::Component res(convert_component_type(elem_mol_type_name, *api_ci.component_type));
if (api_ci.state == STATE_UNSET) {
res.state_id = BNG::STATE_ID_DONT_CARE;
}
else {
res.state_id = bng_data.find_state_id(api_ci.state);
assert(res.state_id != BNG::STATE_ID_INVALID);
}
if (api_ci.bond == BOND_BOUND) {
res.bond_value = BNG::BOND_VALUE_BOUND;
}
else if (api_ci.bond == BOND_UNBOUND) {
res.bond_value = BNG::BOND_VALUE_UNBOUND;
}
else if (api_ci.bond == BOND_ANY) {
res.bond_value = BNG::BOND_VALUE_ANY;
}
else {
res.bond_value = api_ci.bond;
assert(res.bond_value != BNG::BOND_VALUE_INVALID);
}
return res;
}
BNG::ElemMol BNGConverter::convert_molecule_instance(API::ElementaryMolecule& mi, const bool in_rxn_or_observables) {
BNG::ElemMol res;
res.elem_mol_type_id = convert_elementary_molecule_type(*mi.elementary_molecule_type, in_rxn_or_observables);
for (std::shared_ptr<API::Component>& api_ci: mi.components) {
res.components.push_back(convert_component_instance(mi.elementary_molecule_type->name, *api_ci));
}
if (is_set(mi.compartment_name)) {
BNG::compartment_id_t comp_id = bng_data.find_compartment_id(mi.compartment_name);
if (comp_id == BNG::COMPARTMENT_ID_INVALID) {
throw ValueError("Elementary molecule " + mi.to_bngl_str() + " uses unknown compartment " + mi.compartment_name + ".");
}
res.compartment_id = comp_id;
}
else {
res.compartment_id = BNG::COMPARTMENT_ID_NONE;
}
// we must also copy flags from the mol type
res.finalize_flags_and_sort_components(bng_data);
return res;
}
BNG::elem_mol_type_id_t BNGConverter::convert_elementary_molecule_type(
API::ElementaryMoleculeType& api_mt, const bool in_rxn_or_observables) {
if (api_mt.mol_type_id != BNG::ELEM_MOL_TYPE_ID_INVALID) {
// already converted
return api_mt.mol_type_id;
}
BNG::ElemMolType bng_mt;
bng_mt.name = api_mt.name;
if (!in_rxn_or_observables) {
if (is_set(api_mt.diffusion_constant_2d)) {
bng_mt.set_is_surf();
bng_mt.D = api_mt.diffusion_constant_2d;
}
else if (is_set(api_mt.diffusion_constant_3d)) {
bng_mt.set_is_vol();
bng_mt.D = api_mt.diffusion_constant_3d;
}
else {
throw RuntimeError(S("Diffusion constant for ") + NAME_CLASS_ELEMENTARY_MOLECULE_TYPE +
" '" + bng_mt.name + "' was not set.");
}
if (is_set(api_mt.custom_time_step)) {
bng_mt.custom_time_step = api_mt.custom_time_step;
}
else if (is_set(api_mt.custom_space_step)) {
bng_mt.custom_space_step = api_mt.custom_space_step;
}
bng_mt.set_flag(BNG::SPECIES_MOL_FLAG_TARGET_ONLY, api_mt.target_only);
}
// components
for (std::shared_ptr<API::ComponentType> api_ct: api_mt.components) {
BNG::ComponentType bng_ct;
bng_ct.name = api_ct->name;
bng_ct.elem_mol_type_name = bng_mt.name;
for (const string& state: api_ct->states) {
bng_ct.allowed_state_ids.insert_unique(bng_data.find_or_add_state_name(state));
}
BNG::component_type_id_t ct_id = bng_data.find_or_add_component_type(bng_ct);
if (ct_id == BNG::COMPONENT_TYPE_ID_INVALID) {
throw ValueError("Conflicting component type " + api_ct->to_bngl_str() + ", " +
" component with the same name already exists but has different allowed states.");
}
bng_mt.component_type_ids.push_back(ct_id);
}
if (!in_rxn_or_observables) {
// we can convert only definitions
bng_mt.compute_space_and_time_step(bng_config);
}
return bng_data.find_or_add_elem_mol_type(bng_mt);
}
BNG::Cplx BNGConverter::convert_complex(API::Complex& api_cplx, const bool in_observables, const bool in_rxn) {
// create a temporary cplx instance that we will use for search
BNG::Cplx bng_cplx(&bng_data);
if (is_set(api_cplx.elementary_molecules)) {
for (std::shared_ptr<API::ElementaryMolecule>& m: api_cplx.elementary_molecules) {
BNG::ElemMol mi = convert_molecule_instance(*m, in_observables || in_rxn);
bng_cplx.elem_mols.push_back(mi);
}
}
else {
throw ValueError(
"Complex with name " + api_cplx.name + " does not have its " + NAME_ELEMENTARY_MOLECULES + " set. "
"It should be always set because initialization of " + NAME_CLASS_COMPLEX + " from " + NAME_NAME + " is done "
"in this class' constructor."
);
}
// orientation or compartment does not have to be set for finalization,
// this sets whether this is a surf or vol cplx
bng_cplx.finalize_cplx();
// BNG compartments were already created, they were also set for individual molecules
if (is_set(api_cplx.compartment_name)) {
// override all used compartments that were not set (are NONE)
BNG::compartment_id_t in_out_id = BNG::get_in_or_out_compartment_id(api_cplx.compartment_name);
if (in_out_id != BNG::COMPARTMENT_ID_INVALID) {
bng_cplx.set_compartment_id(in_out_id, true);
}
else {
const BNG::Compartment* bng_comp = bng_data.find_compartment(api_cplx.compartment_name);
if (bng_cplx.is_vol() && (bng_comp == nullptr || !bng_comp->is_3d)) {
throw ValueError("Did not find volume compartment " + api_cplx.compartment_name +
" for a volume complex " + bng_cplx.to_str() + ".");
}
if (bng_cplx.is_surf() && (bng_comp == nullptr || bng_comp->is_3d)) {
throw ValueError("Did not find surface compartment " + api_cplx.compartment_name +
" for a surface complex " + bng_cplx.to_str() + ".");
}
bng_cplx.set_compartment_id(bng_comp->id, true);
}
}
else {
// main compartment was not set, do not change them
if (!in_rxn && bng_cplx.is_vol() && api_cplx.orientation != Orientation::NONE && api_cplx.orientation != Orientation::DEFAULT) {
throw ValueError("Orientation for a volume complex " + bng_cplx.to_str() +
" must be set either to " + NAME_ENUM_ORIENTATION + "." + NAME_EV_NONE + " or " +
NAME_ENUM_ORIENTATION + "." + NAME_EV_DEFAULT + ".");
}
else if (bng_cplx.is_surf() && api_cplx.orientation == Orientation::NONE) {
throw ValueError("Orientation for a surface complex " + bng_cplx.to_str() +
" must be set to a value other than " + NAME_ENUM_ORIENTATION + "." + NAME_EV_NONE +
" when " + NAME_COMPARTMENT_NAME + " is not specified.");
}
orientation_t orient = convert_api_orientation(api_cplx.orientation, true, bng_cplx.is_vol());
bng_cplx.set_orientation(orient);
}
return bng_cplx;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/chkpt_surf_mol.cpp | .cpp | 1,450 | 52 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/chkpt_surf_mol.h"
#include "api/api_utils.h"
#include "api/geometry_object.h"
#include "src4/molecule.h"
#include "src4/geometry.h"
#include "src4/partition.h"
using namespace std;
namespace MCell {
namespace API {
ChkptSurfMol::ChkptSurfMol(
const MCell::Molecule& sm,
const IdSpeciesMap& id_species_map, const double time_unit,
const double length_unit,
const MCell::Partition& p,
const IdGeometryObjectMap& id_geometry_object_map) :
GEN_CHKPT_MOL_CTOR(GenChkptSurfMol, sm, id_species_map, time_unit) {
assert(sm.id != MOLECULE_ID_INVALID);
type = MoleculeType::SURFACE;
pos = sm.s.pos * Vec2(length_unit);
orientation = convert_mcell_orientation(sm.s.orientation);
const Wall& w = p.get_wall(sm.s.wall_index);
auto it = id_geometry_object_map.find(w.object_id);
assert(it != id_geometry_object_map.end());
geometry_object = it->second;
wall_index = geometry_object->get_object_wall_index(sm.s.wall_index);
grid_tile_index = sm.s.grid_tile_index;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/compartment_utils.h | .h | 1,482 | 64 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COMPARTMENT_UTILS_H
#define API_COMPARTMENT_UTILS_H
#include <string>
#include <map>
#include <vector>
#include <memory>
namespace MCell {
namespace API {
class GeometryObject;
void set_parent_and_children_compartments(
std::vector<std::shared_ptr<API::GeometryObject>>& compartment_objects);
// used also from data model converter
static void get_compartment_names(const std::string& bngl_string, std::vector<std::string>& compartments) {
size_t i = 0;
bool in_compartment = false;
std::string current_name;
while (i < bngl_string.size()) {
char c = bngl_string[i];
if (c == '@') {
assert(!in_compartment);
in_compartment = true;
}
else if (in_compartment) {
if ((!isalnum(c) && c != '_')) {
compartments.push_back(current_name);
current_name = "";
in_compartment = false;
}
else {
current_name += c;
}
}
i++;
}
if (current_name != "") {
compartments.push_back(current_name);
}
}
} // namespace API
} // namespace MCell
#endif // API_COMPARTMENT_UTILS_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/api_utils.h | .h | 4,439 | 142 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_API_UTILS_H_
#define LIBMCELL_API_API_UTILS_H_
#include <memory>
#include <vector>
#include "api/api_common.h"
// functions defined here are not used in generated files
namespace MCell {
namespace API {
bool is_simple_species(const std::string& name);
Orientation convert_mcell_orientation(const orientation_t o);
orientation_t convert_api_orientation(const Orientation o, const bool allow_default = false, const bool is_vol = true);
static inline std::vector<double> mult_vec(const std::vector<double>& in, const double mult) {
std::vector<double> res(in.size());
for (size_t i = 0; i < in.size(); i++) {
res[i] = in[i] * mult;
}
return res;
}
template<class T>
void append_to_vec(
std::vector<std::shared_ptr<T>>& dst,
const std::shared_ptr<T>& item,
const bool allow_same_name_different_contents = false) {
if (!allow_same_name_different_contents) {
// check if item with this name already exists
for (std::shared_ptr<T>& existing: dst) {
if (item->name == existing->name) {
// must be identical
if (!item->__eq__(*existing)) {
throw ValueError(
"Adding object of " + item->class_name + " with name '" + item->name +
"' caused an error, object with the same name is already present but it is different, " +
"\nexisting:\n" + existing->to_str() + "\nvs. new\n:" + item->to_str() + ".\n"
"-- end of error message reporting existence of two objects with identical names --"
);
}
else {
std::cerr << "Warning: adding of " + item->class_name + " with name '" + item->name +
"' is ignored, identical object is already present.\n";
return;
}
}
}
}
dst.push_back(item);
}
template<class T>
void append_to_vec_canonical_name(
std::vector<std::shared_ptr<T>>& dst,
const std::shared_ptr<T>& item) {
// check if item with this name already exists
for (std::shared_ptr<T>& existing: dst) {
bool are_equal = item->__eq__(*existing);
std::string name_in_msg = "object of " + item->class_name + " with" +
(is_set(item->name) ? " name '" + item->name + "' and" : S("")) +
" canonical name '" + item->get_canonical_name() + "'";
if (item->get_canonical_name() == existing->get_canonical_name()) {
// must be identical
if (!are_equal) {
throw ValueError(
"Adding " + name_in_msg + " caused an error, object with the same canonical name is already present but it is different, "
"\nexisting:\n" + existing->to_str() + "\nvs. new:\n " + item->to_str() + ".\n"
"-- end of error message reporting existence of two objects with identical names --"
);
}
else {
if (item->warn_if_adding_identical_object()) {
std::cerr << "Warning: adding of " + name_in_msg + " is ignored, object with the same canonical name is already present.\n";
}
return;
}
}
// also check, if name is set, that I cannot have different objects with the same name
if (is_set(item->name) && item->name == existing->name && !are_equal) {
throw ValueError(
"Adding object of " + name_in_msg + " caused an error, object with the same name is already present but it is different."
);
}
}
dst.push_back(item);
}
template<class T>
void append_vec_to_vec(
std::vector<std::shared_ptr<T>>& dst,
const std::vector<std::shared_ptr<T>>& src,
const bool allow_same_name_different_contents = false
) {
for (const std::shared_ptr<T>& item: src) {
append_to_vec(
dst, item, allow_same_name_different_contents);
}
}
template<class T>
void append_vec_to_vec_canonical_name(
std::vector<std::shared_ptr<T>>& dst,
const std::vector<std::shared_ptr<T>>& src
) {
for (const std::shared_ptr<T>& item: src) {
append_to_vec_canonical_name(dst, item);
}
}
} // namespace API
} // namespace MCell
#endif // LIBMCELL_API_API_UTILS_H_
| Unknown |
3D | mcellteam/mcell | libmcell/api/elementary_molecule_type.cpp | .cpp | 3,406 | 122 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/elementary_molecule_type.h"
#include "api/component_type.h"
#include "bng/bng.h"
using namespace std;
namespace MCell {
namespace API {
std::shared_ptr<API::ElementaryMoleculeType> ElementaryMoleculeType::construct_from_bng_elem_mol_type(
const BNG::BNGData& bng_data, const BNG::ElemMolType& bng_mt) {
const string& name = bng_mt.name;
auto res_mt = make_shared<API::ElementaryMoleculeType>(name);
// using the MCELL_* parameters for now, see if the diffusion rate was
// specified in the model
double D2 = FLT_INVALID; // init to silence compiler warning
bool found2 = bng_data.get_parameter_value(BNG::MCELL_DIFFUSION_CONSTANT_2D_PREFIX + name, D2);
double D3 = FLT_INVALID;
bool found3 = bng_data.get_parameter_value(BNG::MCELL_DIFFUSION_CONSTANT_3D_PREFIX + name, D3);
if (found2 && found3) {
throw RuntimeError("Molecule type '" + name + "' has both 2d and 3d diffusion constants specified.");
}
// no need to check whether the diffusion constant was set, it may be set later and
// model conversion checks that it was set
if (found2) {
res_mt->diffusion_constant_2d = D2;
}
else if (found3) {
res_mt->diffusion_constant_3d = D3;
}
// process components
for (BNG::component_type_id_t ct_id: bng_mt.component_type_ids) {
const BNG::ComponentType bng_ct = bng_data.get_component_type(ct_id);
auto ct = make_shared<API::ComponentType>(bng_ct.name);
// and allowed states
for (BNG::state_id_t state_id: bng_ct.allowed_state_ids) {
ct->states.push_back(bng_data.get_state_name(state_id));
}
res_mt->components.push_back(ct);
}
return res_mt;
}
static std::string get_components_str(
const std::vector<std::shared_ptr<ComponentType>>& components,
const bool canonical = false
) {
string res;
if (!components.empty()) {
res += "(";
for (size_t i = 0; i < components.size(); i++) {
if (!canonical) {
res += components[i]->to_bngl_str();
}
else {
res += components[i]->get_canonical_name();
}
if (i + 1 != components.size()) {
res += ",";
}
}
res += ")";
}
return res;
}
std::string ElementaryMoleculeType::get_canonical_name() const {
std::vector<std::shared_ptr<ComponentType>> sorted;
sorted = components;
std::sort(sorted.begin(), sorted.end(),
[](const std::shared_ptr<ComponentType>& a, const std::shared_ptr<ComponentType>& b) -> bool {
return *a < *b;
});
return name + get_components_str(sorted, true);
}
bool ElementaryMoleculeType::__eq__(const ElementaryMoleculeType& other) const {
if (!eq_nonarray_attributes(other)) {
return false;
}
return get_canonical_name() == other.get_canonical_name();
}
std::string ElementaryMoleculeType::to_bngl_str() const {
return name + get_components_str(components);
}
bool ElementaryMoleculeType::skip_python_export() const {
return BNG::is_species_superclass(name);
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/callbacks.h | .h | 5,224 | 186 | /******************************************************************************
*
* Copyright (C) 2020-2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_CALLBACKS_H_
#define LIBMCELL_API_CALLBACKS_H_
#include <functional>
#ifdef _WIN64
// fix for _hypot compilation issue
#define _hypot hypot
#include <cmath>
#endif
#ifdef _MSC_VER
#undef HAVE_UNISTD_H
#undef HAVE_SYS_TIME_H
#endif
#include "pybind11/include/pybind11/pybind11.h"
#include "api/api_common.h"
#include "defines.h"
#include "bng/bng_defines.h"
namespace MCell {
namespace API {
class Model;
class MolWallHitInfo;
class ReactionInfo;
typedef std::function<void(std::shared_ptr<API::MolWallHitInfo>, pybind11::object)>
mol_wall_hit_callback_function_t;
typedef std::function<bool(std::shared_ptr<API::ReactionInfo>, pybind11::object)>
rxn_callback_function_t;
struct RxnCallbackInfo {
RxnCallbackInfo() :
callback_function(nullptr),
rxn_rule_id(BNG::RXN_RULE_ID_INVALID) {
}
RxnCallbackInfo(
const rxn_callback_function_t callback_function_,
const py::object context_,
const BNG::rxn_rule_id_t rxn_rule_id_) :
callback_function(callback_function_),
context(context_),
rxn_rule_id(rxn_rule_id_) {
}
rxn_callback_function_t callback_function;
py::object context;
BNG::rxn_rule_id_t rxn_rule_id;
};
struct MolWallHitCallbackInfo {
MolWallHitCallbackInfo() :
callback_function(nullptr),
geometry_object_id(GEOMETRY_OBJECT_ID_INVALID),
species_id(BNG::SPECIES_ID_INVALID) {
}
MolWallHitCallbackInfo(
const mol_wall_hit_callback_function_t callback_function_,
const py::object context_,
const geometry_object_id_t geometry_object_id_,
const BNG::species_id_t species_id_) :
callback_function(callback_function_),
context(context_),
geometry_object_id(geometry_object_id_),
species_id(species_id_) {
}
mol_wall_hit_callback_function_t callback_function;
py::object context;
geometry_object_id_t geometry_object_id; // GEOMETRY_OBJECT_ID_INVALID - any object may be hit
species_id_t species_id; // SPECIES_ID_INVALID - any species may be hit
};
// not generated
class Callbacks {
public:
// model_ is nullptr in MDL mode
Callbacks(Model* model_);
Model* model;
// -------------------- mol-wall hit callbacks --------------------
void register_mol_wall_hit_callback(
const mol_wall_hit_callback_function_t func,
py::object context,
const geometry_object_id_t geometry_object_id,
const species_id_t species_id);
bool needs_callback_for_mol_wall_hit(
const geometry_object_id_t geometry_object_id,
const species_id_t species_id) const {
if (mol_wall_hit_callbacks.empty()) {
return false;
}
auto it_specific_geom_obj = mol_wall_hit_callbacks.find(geometry_object_id);
if (it_specific_geom_obj != mol_wall_hit_callbacks.end() &&
needs_callback_for_mol_wall_hit(it_specific_geom_obj->second, species_id)) {
return true;
}
auto it_any_geom_obj = mol_wall_hit_callbacks.find(GEOMETRY_OBJECT_ID_INVALID);
if (it_any_geom_obj != mol_wall_hit_callbacks.end() &&
needs_callback_for_mol_wall_hit(it_any_geom_obj->second, species_id)) {
return true;
}
// no match
return false;
}
void do_mol_wall_hit_callbacks(std::shared_ptr<MolWallHitInfo> info);
// -------------------- reaction callbacks --------------------
void register_rxn_callback(
const rxn_callback_function_t func,
py::object context,
const BNG::rxn_rule_id_t rxn_rule_id
);
bool needs_rxn_callback(
const BNG::rxn_rule_id_t rxn_rule_id) const {
if (rxn_callbacks.empty()) {
return false;
}
else {
return rxn_callbacks.count(rxn_rule_id) != 0;
}
}
// returns true if reaction should be cancelled
bool do_rxn_callback(std::shared_ptr<ReactionInfo> info);
private:
std::map<BNG::rxn_rule_id_t, RxnCallbackInfo> rxn_callbacks;
typedef std::map<BNG::species_id_t, MolWallHitCallbackInfo> SpeciesMolWallHitCallbackInfoMap;
std::map<geometry_object_id_t, SpeciesMolWallHitCallbackInfoMap> mol_wall_hit_callbacks;
bool needs_callback_for_mol_wall_hit(
const SpeciesMolWallHitCallbackInfoMap& species_info_map,
const BNG::species_id_t species_id) const {
if (species_info_map.count(species_id) != 0) {
return true;
}
if (species_info_map.count(BNG::SPECIES_ID_INVALID) != 0) {
return true;
}
return false;
}
void do_mol_wall_hit_callback_for_specific_and_any_species(
std::shared_ptr<MolWallHitInfo> info,
const BNG::species_id_t specific_species_id,
const SpeciesMolWallHitCallbackInfoMap& species_map);
void do_individual_mol_wall_hit_callback(
std::shared_ptr<MolWallHitInfo> info, MolWallHitCallbackInfo callback_function_and_context);
};
} /* namespace API */
} /* namespace MCell */
#endif /* LIBMCELL_API_CALLBACKS_H_ */
| Unknown |
3D | mcellteam/mcell | libmcell/api/callbacks.cpp | .cpp | 6,735 | 187 | /******************************************************************************
*
* Copyright (C) 2020-2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/callbacks.h"
#include "api/model.h"
#include "api/geometry_object.h"
#include "world.h"
#include "molecule.h"
using namespace std;
namespace MCell {
namespace API {
Callbacks::Callbacks(Model* model_)
: model(model_) {
assert(model != nullptr);
}
void Callbacks::register_mol_wall_hit_callback(
const mol_wall_hit_callback_function_t func,
py::object context,
const geometry_object_id_t geometry_object_id,
const BNG::species_id_t species_id
) {
assert(model != nullptr);
auto it_geom_obj = mol_wall_hit_callbacks.find(geometry_object_id);
if (it_geom_obj != mol_wall_hit_callbacks.end() && it_geom_obj->second.count(species_id) != 0) {
string geom_name;
if (geometry_object_id != GEOMETRY_OBJECT_ID_INVALID) {
geom_name = model->get_world()->get_geometry_object(geometry_object_id).name;
}
else {
geom_name = "any";
}
string species_name;
if (species_id != BNG::SPECIES_ID_INVALID) {
species_name = model->get_world()->get_all_species().get(species_id).name;
}
else {
species_name = "any";
}
throw RuntimeError(S("Cannot register two callbacks for an identical pair or geometry object and species id, ") +
" error while trying to register second callback for geometry object '" + geom_name + "' and species '" + species_name +"'.");
}
mol_wall_hit_callbacks[geometry_object_id][species_id] = MolWallHitCallbackInfo(func, context, geometry_object_id, species_id);
// make sure that the species_id won't change in the future
if (species_id != BNG::SPECIES_ID_INVALID) {
model->get_world()->get_all_species().get(species_id).clear_flag(BNG::SPECIES_FLAG_IS_REMOVABLE);
}
}
void Callbacks::do_mol_wall_hit_callbacks(std::shared_ptr<MolWallHitInfo> info) {
// set geometry data
info->geometry_object = model->get_geometry_object_with_id(info->geometry_object_id);
assert(is_set(info->geometry_object));
assert(info->partition_wall_index >= info->geometry_object->first_wall_index);
info->wall_index = info->partition_wall_index - info->geometry_object->first_wall_index;
// convert units
assert(model->get_world() != nullptr);
info->time = info->time * model->get_world()->config.time_unit;
info->pos3d = mult_vec(info->pos3d, model->get_world()->config.length_unit);
info->time_before_hit = info->time_before_hit * model->get_world()->config.time_unit;
info->pos3d_before_hit = mult_vec(info->pos3d_before_hit, model->get_world()->config.length_unit);
geometry_object_id_t geometry_object_id = info->geometry_object->geometry_object_id;
// only one partition for now
const MCell::Molecule& m = model->get_world()->get_partition(PARTITION_ID_INITIAL).get_m(info->molecule_id);
// call callback for all matching registered callbacks
auto it_specific_geom_obj = mol_wall_hit_callbacks.find(geometry_object_id);
if (it_specific_geom_obj != mol_wall_hit_callbacks.end()) {
do_mol_wall_hit_callback_for_specific_and_any_species(
info, m.species_id, it_specific_geom_obj->second);
}
auto it_any_geom_obj = mol_wall_hit_callbacks.find(GEOMETRY_OBJECT_ID_INVALID);
if (it_any_geom_obj != mol_wall_hit_callbacks.end()) {
do_mol_wall_hit_callback_for_specific_and_any_species(
info, m.species_id, it_any_geom_obj->second);
}
}
void Callbacks::do_mol_wall_hit_callback_for_specific_and_any_species(
std::shared_ptr<MolWallHitInfo> info,
const BNG::species_id_t specific_species_id,
const SpeciesMolWallHitCallbackInfoMap& species_map) {
auto it_specific_species = species_map.find(specific_species_id);
if (it_specific_species != species_map.end()) {
do_individual_mol_wall_hit_callback(info, it_specific_species->second);
}
auto it_any_species = species_map.find(BNG::SPECIES_ID_INVALID);
if (it_any_species != species_map.end()) {
do_individual_mol_wall_hit_callback(info, it_any_species->second);
}
}
void Callbacks::do_individual_mol_wall_hit_callback(
std::shared_ptr<MolWallHitInfo> info,
MolWallHitCallbackInfo callback_function_and_context) {
// acquire GIL before calling Python code
py::gil_scoped_acquire acquire;
// call the actual callback
callback_function_and_context.callback_function(info, callback_function_and_context.context);
}
void Callbacks::register_rxn_callback(
const rxn_callback_function_t func,
py::object context,
const BNG::rxn_rule_id_t rxn_rule_id
) {
assert(model != nullptr);
assert(rxn_rule_id != BNG::RXN_RULE_ID_INVALID);
if (rxn_callbacks.count(rxn_rule_id) != 0) {
std::string name = model->get_world()->get_all_rxns().get(rxn_rule_id)->to_str();
throw RuntimeError(S("Each reaction rule can have only a single callback, error while trying to register ") +
"second callback for " + name + ".");
}
rxn_callbacks[rxn_rule_id] = RxnCallbackInfo(func, context, rxn_rule_id);
}
bool Callbacks::do_rxn_callback(std::shared_ptr<ReactionInfo> info) {
// select the correct callback
assert(rxn_callbacks.count(info->rxn_rule_id) != 0);
const RxnCallbackInfo& specific_callback = rxn_callbacks[info->rxn_rule_id];
// set reaction rule object
info->reaction_rule = model->get_reaction_rule_with_fwd_id(info->rxn_rule_id);
assert(is_set(info->reaction_rule));
// convert units
assert(model->get_world() != nullptr);
info->time = info->time * model->get_world()->config.time_unit;
info->pos3d = mult_vec(info->pos3d, model->get_world()->config.length_unit);
const BNG::RxnRule* rxn = model->get_world()->get_all_rxns().get(info->rxn_rule_id);
if (info->geometry_object_id != GEOMETRY_OBJECT_ID_INVALID) {
info->geometry_object = model->get_geometry_object_with_id(info->geometry_object_id);
assert(is_set(info->geometry_object));
assert(info->partition_wall_index >= info->geometry_object->first_wall_index);
info->wall_index = info->geometry_object->get_object_wall_index(info->partition_wall_index);
info->pos2d = mult_vec(info->pos2d, model->get_world()->config.length_unit);
}
// acquire GIL before calling Python code
py::gil_scoped_acquire acquire;
// call the actual callback
bool cancel_reaction = specific_callback.callback_function(info, specific_callback.context);
return cancel_reaction;
}
} /* namespace API */
} /* namespace MCell */
| C++ |
3D | mcellteam/mcell | libmcell/api/api_config.h | .h | 1,361 | 48 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
// NOTE: this file should be called config.h, however with MSVC, there is
// an include collision and pybind11 includes it instead of some other file
#ifndef LIBMCELL_API_CONFIG_H
#define LIBMCELL_API_CONFIG_H
#include "generated/gen_config.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class Config: public GenConfig {
public:
CONFIG_CTOR()
void check_semantics() const override {
GenConfig::check_semantics();
if (cmp_gt(subpartition_dimension, partition_dimension, EPS)) {
throw ValueError(S("Value ") + NAME_SUBPARTITION_DIMENSION + " must be smaller or equal than " + NAME_PARTITION_DIMENSION + ".");
}
if (is_set(initial_partition_origin)) {
if (initial_partition_origin.size() != 3) {
throw ValueError(S("Value ") + NAME_INITIAL_PARTITION_ORIGIN + " must be a vector of three floating point values.");
}
}
}
};
} // namespace API
} // namespace MCell
#endif // LIBMCELL_API_CONFIG_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/color.h | .h | 1,346 | 61 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COLOR_H
#define API_COLOR_H
#include "generated/gen_color.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class Color: public GenColor {
public:
COLOR_CTOR()
void postprocess_in_ctor() override;
void set_red(const double new_red_) override {
red = new_red_;
components_to_rgba();
}
void set_green(const double new_green_) override {
green = new_green_;
components_to_rgba();
}
void set_blue(const double new_blue_) override {
blue = new_blue_;
components_to_rgba();
}
void set_alpha(const double new_alpha_) override {
alpha = new_alpha_;
components_to_rgba();
}
void set_rgba(const uint new_rgba_) override {
rgba = new_rgba_;
rgba_to_components();
}
private:
void components_to_rgba();
void rgba_to_components();
void check_component_range(const double value, const char* name);
};
} // namespace API
} // namespace MCell
#endif // API_COLOR_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/python_export_constants.cpp | .cpp | 4,758 | 126 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/python_export_constants.h"
namespace MCell {
namespace API {
std::string get_customization_import(const std::string& customization_module) {
return
std::string("if os.path.exists(os.path.join(") + MODEL_PATH + ", '" + customization_module + ".py')):\n"
" import " + customization_module + "\n"
"else:\n"
" " + customization_module + " = None\n"
;
}
std::string get_argparse_w_customization_begin(const std::string& customization_module) {
return
"if " + customization_module + " and '" + CUSTOM_ARGPARSE_AND_PARAMETERS + "' in dir(" + customization_module + "):\n"
" # custom argument processing and parameter setup\n"
" " + customization_module + "." + CUSTOM_ARGPARSE_AND_PARAMETERS + "()\n"
"else:\n"
" if len(sys.argv) == 1:\n"
" # no arguments\n"
" pass\n"
" elif len(sys.argv) == 3 and sys.argv[1] == '-seed':\n"
" # overwrite value of seed defined in module parameters\n"
" " + SHARED + "." + PARAMETER_OVERRIDES + "['" + PARAM_SEED + "'] = int(sys.argv[2])\n"
;
}
std::string get_argparse_checkpoint_iteration() {
return
std::string(" elif len(sys.argv) == 3 and sys.argv[1] == '-chkpt':\n") +
" " + CHECKPOINT_ITERATION + " = int(sys.argv[2])\n" +
" elif len(sys.argv) == 5 and sys.argv[1] == '-seed' and sys.argv[3] == '-chkpt':\n" +
" " + SHARED + "." + PARAMETER_OVERRIDES + "['" + PARAM_SEED + "'] = int(sys.argv[2])\n" +
" " + CHECKPOINT_ITERATION + " = int(sys.argv[4])\n"
;
}
std::string get_resume_from_checkpoint_code() {
return
"# resume simulation if a checkpoint was created\n"
"checkpoint_dir = m.run_utils.get_last_checkpoint_dir(" PARAM_SEED ")\n"
"if checkpoint_dir:\n"
" # change sys.path so that the only the checkpointed files are loaded\n"
" sys.path = m.run_utils.remove_cwd(sys.path)\n"
" sys.path.append(checkpoint_dir)\n"
" \n"
" # prepare import of the 'model' module from the checkpoint\n"
" model_spec = importlib.util.spec_from_file_location(\n"
" 'model', os.path.join(checkpoint_dir, 'model.py'))\n"
" model_module = importlib.util.module_from_spec(model_spec)\n"
" \n"
" # run import, this also resumes simulation from the checkpoint\n"
" model_spec.loader.exec_module(model_module)\n"
"\n"
" # exit after simulation has finished successfully\n"
" sys.exit(0)\n\n"
;
}
std::string get_argparse_w_customization_end() {
return
" else:\n"
" print(\"Error: invalid command line arguments\")\n"
" print(\" usage: \" + sys.argv[0] + \"[-seed N]\")\n"
" sys.exit(1)\n";
}
std::string get_user_defined_configuration(const std::string& customization_module) {
return
"if " + customization_module + " and '" + CUSTOM_CONFIG + "' in dir(" + customization_module + "):\n"
" # user-defined model configuration\n"
" " + customization_module + "." + CUSTOM_CONFIG + "(" + MODEL + ")\n"
;
}
std::string get_abs_path(const std::string file) {
return std::string("os.path.join(") + MODEL_PATH + ", '" + file + "')";
}
std::string get_import(const std::string module) {
return "import " + module + "\n";
}
std::string get_import_star(const std::string module) {
return "from " + module + " import *\n";
}
std::string get_template_custom_init_and_run(const std::string& parameters_module) {
return
"\"\"\"\n"
"def custom_init_and_run(model):\n"
" # When uncommented, this function is called after all the model\n"
" # components defined in CellBlender were added to the model.\n"
" # It allows to add additional model components before initialization \n"
" # is done and then to customize how simulation is ran.\n"
" # The module parameters must be imported locally otherwise\n"
" # changes to shared.parameter_overrides done elsewhere won't be applied.\n"
" import " + parameters_module + " as " + PARAMETERS + "\n" +
" model.initialize()\n"
" model.run_iterations(parameters.ITERATIONS)\n"
" model.end_simulation()\n"
"\"\"\"\n";
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/model.h | .h | 5,856 | 180 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_MODEL_H
#define API_MODEL_H
#include "generated/gen_model.h"
#include "api/api_common.h"
#include "api/globals.h"
#include "api/subsystem.h"
#include "api/instantiation.h"
#include "api/observables.h"
#include "api/api_config.h"
#include "api/warnings.h"
#include "api/notifications.h"
#include "api/shared_structs.h"
#include "api/callbacks.h"
#include "api/introspection.h"
#include "api/geometry_object.h"
namespace MCell {
class World;
namespace API {
class MolWallHitInfo;
class WallWallHitInfo;
class Model: public GenModel {
public:
Model() : initialized(false), world(nullptr), callbacks(this) {
}
Model(DefaultCtorArgType) : initialized(false), world(nullptr), callbacks(this) {
}
virtual ~Model();
// from generated template
void initialize(const bool print_copyright = true) override;
uint64_t run_iterations(const double iterations) override;
void end_simulation(const bool print_final_report = true) override;
void add_subsystem(std::shared_ptr<Subsystem> subsystem) override;
void add_instantiation(std::shared_ptr<Instantiation> instantiation) override;
void add_observables(std::shared_ptr<Observables> observables) override;
void dump_internal_state(const bool with_geometry = false) override;
void export_data_model(const std::string& file = STR_UNSET) override {
export_data_model_viz_or_full(file, false, NAME_EXPORT_DATA_MODEL);
}
void export_viz_data_model(const std::string& file = STR_UNSET) override {
export_data_model_viz_or_full(file, true, NAME_EXPORT_VIZ_DATA_MODEL);
}
void export_geometry(const std::string& output_files_prefix = STR_UNSET) override;
void release_molecules(std::shared_ptr<ReleaseSite> release_site) override;
std::vector<int> run_reaction(
std::shared_ptr<ReactionRule> reaction_rule,
const std::vector<int> reactant_ids,
const double time) override;
void add_vertex_move(
std::shared_ptr<GeometryObject> object, const int vertex_index, const std::vector<double> displacement
) override;
std::vector<std::shared_ptr<WallWallHitInfo>> apply_vertex_moves(
const bool collect_wall_wall_hits = false,
const bool randomize_order = true
) override;
void pair_molecules(const int id1, const int id2) override;
void unpair_molecules(const int id1, const int id2) override;
int get_paired_molecule(const int id) override;
std::map<uint, uint> get_paired_molecules() override;
void register_mol_wall_hit_callback(
const std::function<void(std::shared_ptr<MolWallHitInfo>, py::object)> function,
py::object context,
std::shared_ptr<GeometryObject> object = nullptr,
std::shared_ptr<Species> species = nullptr
) override;
void register_reaction_callback(
const std::function<bool(std::shared_ptr<ReactionInfo>, py::object)> function,
py::object context,
std::shared_ptr<ReactionRule> reaction_rule
) override;
void load_bngl(
const std::string& file_name,
const std::string& observables_path_or_file = "",
std::shared_ptr<Region> default_release_region = nullptr,
const std::map<std::string, double>& parameter_overrides = std::map<std::string, double>(),
const CountOutputFormat observables_output_format = CountOutputFormat::AUTOMATIC_FROM_EXTENSION
) override;
void export_to_bngl(
const std::string& file_name,
const BNGSimulationMethod simulation_method = BNGSimulationMethod::NONE) override;
void save_checkpoint(const std::string& custom_dir = STR_UNSET) override;
void schedule_checkpoint(
const uint64_t iteration = 0,
const bool continue_simulation = false,
const std::string& custom_dir = STR_UNSET) override;
// overrides from derived classes Subsystem, Instantiation, and Observables
void add_species(std::shared_ptr<Species> s) override;
void add_reaction_rule(std::shared_ptr<ReactionRule> r) override;
void add_surface_class(std::shared_ptr<SurfaceClass> sc) override;
void add_release_site(std::shared_ptr<ReleaseSite> s) override;
void add_geometry_object(std::shared_ptr<GeometryObject> o) override;
void add_viz_output(std::shared_ptr<VizOutput> viz_output) override;
void add_count(std::shared_ptr<Count> count) override;
// TODO: this belongs to Instantiation
std::shared_ptr<GeometryObject> get_geometry_object_with_id(const geometry_object_id_t id);
// TODO: this belongs to Subsystem
std::shared_ptr<ReactionRule> get_reaction_rule_with_fwd_id(const BNG::rxn_rule_id_t id);
bool is_initialized() const {
return initialized;
}
void error_if_initialized(const char* what) {
if (initialized) {
throw RuntimeError(S("It is not possible to add ") + what + " once a model was initialized.");
}
}
void dump() const;
const World* get_world() const {
return world;
}
World* get_world() {
return world;
}
private:
void update_api_vertex_position_using_vertex_move(
const VertexMoveInfo& move_info);
void export_data_model_viz_or_full(
const std::string& file,
const bool only_for_visualization,
const char* method_name
);
volatile bool initialized;
World* world;
Callbacks callbacks;
std::vector<VertexMoveInfo> vertex_moves;
// used in get_geometry_object_with_id
std::map<geometry_object_id_t, std::shared_ptr<API::GeometryObject>> geometry_object_id_to_obj_cache;
};
} // namespace API
} // namespace MCell
#endif // API_MODEL_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/component.cpp | .cpp | 1,148 | 60 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "api/component.h"
#include "api/component_type.h"
using namespace std;
namespace MCell {
namespace API {
bool Component::operator < (const Component& other) const {
if (name != other.name) {
return name < other.name;
}
if (state != other.state) {
return state < other.state;
}
return bond < other.bond;
}
std::string Component::to_bngl_str() const {
std::string res;
res = component_type->name;
if (state != STATE_UNSET) {
res += "~" + state;
}
if (bond != BOND_UNBOUND) {
if (bond == BOND_BOUND) {
res += "!+";
}
else if (bond == BOND_ANY) {
res += "!?";
}
else {
res += "!" + std::to_string(bond);
}
}
return res;
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/geometry_utils.cpp | .cpp | 9,335 | 341 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include "generated/gen_geometry_utils.h"
#include "api/geometry_object.h"
#include "api/model.h"
#include "world.h"
#include "geometry.h"
#include "partition.h"
#include <vtkPlatonicSolidSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
using namespace std;
namespace MCell {
namespace API {
namespace geometry_utils {
std::shared_ptr<GeometryObject> create_box(
const std::string& name,
const double edge_dimension,
const std::vector<double> xyz_dimensions) {
string err_msg = S("Exactly one ") + NAME_EDGE_DIMENSION + " or individual x, y, z dimensions can be set.";
double x, y, z;
if (is_set(edge_dimension)) {
if (is_set(xyz_dimensions)) {
throw ValueError(err_msg);
}
x = edge_dimension / 2;
y = edge_dimension / 2;
z = edge_dimension / 2;
}
else {
if (xyz_dimensions.size() != 3) {
throw ValueError(err_msg);
}
x = xyz_dimensions[0] / 2;
y = xyz_dimensions[1] / 2;
z = xyz_dimensions[2] / 2;
}
// using the same ordering of vertices and faces as what is generated by
// CellBlender, changing this impacts surface molecule releases
vector<vector<double>> vertex_list {
{-x, -y, -z},
{-x, -y, z},
{-x, y, -z},
{-x, y, z},
{ x, -y, -z},
{ x, -y, z},
{ x, y, -z},
{ x, y, z}
};
vector<vector<int>> wall_list {
{1, 2, 0},
{3, 6, 2},
{7, 4, 6},
{5, 0, 4},
{6, 0, 2},
{3, 5, 7},
{1, 3, 2},
{3, 7, 6},
{7, 5, 4},
{5, 1, 0},
{6, 4, 0},
{3, 1, 5}
};
auto res = make_shared<GeometryObject>(
name,
vertex_list,
wall_list
);
return res;
}
// used code from the link below due to absence of any reasonable library
// https://github.com/caosdoar/spheres/blob/master/src/spheres.cpp
// published under MIT license
struct Edge
{
uint32_t v0;
uint32_t v1;
Edge(uint32_t v0, uint32_t v1)
: v0(v0 < v1 ? v0 : v1)
, v1(v0 < v1 ? v1 : v0)
{
}
bool operator <(const Edge &rhs) const
{
return v0 < rhs.v0 || (v0 == rhs.v0 && v1 < rhs.v1);
}
};
static Vec3 normalize(const Vec3 &a)
{
const double lrcp = 1.0 / std::sqrt(dot(a, a));
return Vec3(a.x * lrcp, a.y * lrcp, a.z * lrcp);
}
static void init_icosphere(
vector<Vec3>& vertex_list,
vector<vector<int>>& wall_list) {
vertex_list.clear();
wall_list.clear();
const double t = (1.0 + std::sqrt(5.0)) / 2.0;
// Vertices
vertex_list.push_back(normalize(Vec3(-1.0, t, 0.0)));
vertex_list.push_back(normalize(Vec3( 1.0, t, 0.0)));
vertex_list.push_back(normalize(Vec3(-1.0, -t, 0.0)));
vertex_list.push_back(normalize(Vec3( 1.0, -t, 0.0)));
vertex_list.push_back(normalize(Vec3(0.0, -1.0, t)));
vertex_list.push_back(normalize(Vec3(0.0, 1.0, t)));
vertex_list.push_back(normalize(Vec3(0.0, -1.0, -t)));
vertex_list.push_back(normalize(Vec3(0.0, 1.0, -t)));
vertex_list.push_back(normalize(Vec3( t, 0.0, -1.0)));
vertex_list.push_back(normalize(Vec3( t, 0.0, 1.0)));
vertex_list.push_back(normalize(Vec3(-t, 0.0, -1.0)));
vertex_list.push_back(normalize(Vec3(-t, 0.0, 1.0)));
// Faces
wall_list.push_back(vector<int>{0, 11, 5});
wall_list.push_back(vector<int>{0, 5, 1});
wall_list.push_back(vector<int>{0, 1, 7});
wall_list.push_back(vector<int>{0, 7, 10});
wall_list.push_back(vector<int>{0, 10, 11});
wall_list.push_back(vector<int>{1, 5, 9});
wall_list.push_back(vector<int>{5, 11, 4});
wall_list.push_back(vector<int>{11, 10, 2});
wall_list.push_back(vector<int>{10, 7, 6});
wall_list.push_back(vector<int>{7, 1, 8});
wall_list.push_back(vector<int>{3, 9, 4});
wall_list.push_back(vector<int>{3, 4, 2});
wall_list.push_back(vector<int>{3, 2, 6});
wall_list.push_back(vector<int>{3, 6, 8});
wall_list.push_back(vector<int>{3, 8, 9});
wall_list.push_back(vector<int>{4, 9, 5});
wall_list.push_back(vector<int>{2, 4, 11});
wall_list.push_back(vector<int>{6, 2, 10});
wall_list.push_back(vector<int>{8, 6, 7});
wall_list.push_back(vector<int>{9, 8, 1});
}
int subdivide_icosphere_edge(
int f0, int f1,
const Vec3& v0, const Vec3& v1,
vector<Vec3>& vertex_list_out,
std::map<Edge, uint32_t> &io_divisions
)
{
// required to make the mesh watertight
const Edge edge(f0, f1);
auto it = io_divisions.find(edge);
if (it != io_divisions.end()) {
return it->second;
}
const Vec3 v = normalize(Vec3(0.5) * (v0 + v1));
const uint32_t f = vertex_list_out.size();
vertex_list_out.push_back(v);
io_divisions[edge] = f;
return f;
}
static void subdivide_icosphere_mesh(
const vector<Vec3>& vertex_list_in,
const vector<vector<int>>& wall_list_in,
vector<Vec3>& vertex_list_out,
vector<vector<int>>& wall_list_out) {
vertex_list_out = vertex_list_in;
std::map<Edge, uint32_t> divisions; // Edge -> new vertex
for (size_t i = 0; i < wall_list_in.size(); ++i)
{
const int f0 = wall_list_in[i][0];
const int f1 = wall_list_in[i][1];
const int f2 = wall_list_in[i][2];
const Vec3& v0 = vertex_list_in[f0];
const Vec3& v1 = vertex_list_in[f1];
const Vec3& v2 = vertex_list_in[f2];
const int f3 = subdivide_icosphere_edge(f0, f1, v0, v1, vertex_list_out, divisions);
const int f4 = subdivide_icosphere_edge(f1, f2, v1, v2, vertex_list_out, divisions);
const int f5 = subdivide_icosphere_edge(f2, f0, v2, v0, vertex_list_out, divisions);
wall_list_out.push_back(vector<int>{f0, f3, f5});
wall_list_out.push_back(vector<int>{f3, f1, f4});
wall_list_out.push_back(vector<int>{f4, f2, f5});
wall_list_out.push_back(vector<int>{f3, f4, f5});
}
}
std::shared_ptr<GeometryObject> create_icosphere(
const std::string& name, const double radius, const int subdivisions) {
if (subdivisions < 1) {
throw ValueError(S("Value of parameter ") + NAME_SUBDIVISIONS + " must be greater or equal to 1.");
}
if (subdivisions > 8) {
throw ValueError(S("Value of parameter ") + NAME_SUBDIVISIONS + " must be less or equal to 8.");
}
vector<Vec3> vertex_list;
vector<vector<int>> wall_list;
init_icosphere(vertex_list, wall_list);
for (int i = 0; i < subdivisions - 1; i++) {
vector<Vec3> vertex_list_new;
vector<vector<int>> wall_list_new;
subdivide_icosphere_mesh(vertex_list, wall_list, vertex_list_new, wall_list_new);
vertex_list.swap(vertex_list_new);
wall_list.swap(wall_list_new);
}
// convert vertices to the required format and scale
vector<vector<double>> double_vertices;
for (const Vec3& v: vertex_list) {
double_vertices.push_back(vector<double>{v.x * radius, v.y * radius, v.z * radius});
}
auto res = make_shared<GeometryObject>(
name,
double_vertices,
wall_list
);
return res;
}
#if 0
// keeping this code as an example on how to transform vtkPolyData
std::shared_ptr<GeometryObject> create_sphere(
const std::string& name, const double radius, const int resolution) {
vtkNew<vtkSphereSource> sphere;
sphere->SetCenter(0.0, 0.0, 0.0);
sphere->SetRadius(radius);
sphere->SetPhiResolution(resolution);
sphere->SetThetaResolution(resolution);
sphere->Update();
vtkSmartPointer<vtkPolyData> polydata = sphere->GetOutput();
vtkPoints* points = polydata->GetPoints();
vector<vector<double>> vertex_list;
int num_vertices = points->GetNumberOfPoints();
for (int i = 0; i < num_vertices; i++) {
double pt[3];
points->GetPoint(i, pt);
vertex_list.push_back(vector<double>{pt[0], pt[1], pt[2]});
}
vector<vector<int>> wall_list;
int num_walls = polydata->GetNumberOfCells();
for (int i = 0; i < num_walls; i++) {
vtkCell* cell = polydata->GetCell(i);
vector<int> wall;
for (int k = 0; k < 3; k++) {
wall.push_back(cell->GetPointId(k));
}
wall_list.push_back(wall);
}
auto res = make_shared<GeometryObject>(
name,
vertex_list,
wall_list
);
return res;
}
#endif
void validate_volumetric_mesh(
std::shared_ptr<Model> model,
std::shared_ptr<GeometryObject> geometry_object) {
if (!model->is_initialized()) {
throw RuntimeError(S("Function ") + NAME_VALIDATE_VOLUMETRIC_MESH + " may be called only after model initialization.");
}
if (geometry_object->geometry_object_id == GEOMETRY_OBJECT_ID_INVALID) {
throw RuntimeError(S("Function ") + NAME_VALIDATE_VOLUMETRIC_MESH + " may be called on " + NAME_CLASS_GEOMETRY_OBJECT + " used during model initialization.");
}
const Partition& p = model->get_world()->get_partition(PARTITION_ID_INITIAL);
const MCell::GeometryObject& obj = p.get_geometry_object(geometry_object->geometry_object_id);
string msg = obj.validate_volumetric_mesh(p);
if (msg != "") {
throw RuntimeError("Validation of volumetric mesh failed with following error:\n" + msg);
}
}
} // namespace geometry_utils
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/viz_output.h | .h | 916 | 39 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_VIZ_OUTPUT_H
#define API_VIZ_OUTPUT_H
#include "generated/gen_viz_output.h"
#include "api/api_common.h"
namespace MCell {
namespace API {
class VizOutput: public GenVizOutput {
public:
VIZ_OUTPUT_CTOR()
void check_semantics() const override {
GenVizOutput::check_semantics();
if (every_n_timesteps < 0) {
throw ValueError(
S("The value of ") + NAME_EVERY_N_TIMESTEPS + " must not be less than 0.");
}
}
};
} // namespace API
} // namespace MCell
#endif // API_VIZ_OUTPUT_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/data_utils.cpp | .cpp | 2,550 | 102 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include <fstream>
#include <cerrno>
#include "generated/gen_data_utils.h"
using namespace std;
namespace MCell {
namespace API {
namespace data_utils {
// trim from start (in place)
static void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
}
// trim from end (in place)
static void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
// trim from both ends (in place)
static void trim(std::string &s) {
ltrim(s);
rtrim(s);
}
std::vector<std::vector<double>> load_dat_file(const std::string& file_name) {
std::vector<std::vector<double>> res;
ifstream fin;
fin.open(file_name, ios::in);
int linenr = 1;
string line;
while(getline(fin, line)) {
// is only whitespace? -> skip
trim(line);
if (line == "") {
continue;
}
size_t pos = line.find_first_of(" \t");
if (pos == string::npos) {
throw RuntimeError("Invalid format of input file " + file_name +
", did not find a column separator on line " + to_string(linenr) + ".");
}
string col1 = line.substr(0, pos);
string col2 = line.substr(pos + 1);
char* end;
errno = 0;
double col1_value = strtod(col1.c_str(), &end);
if (errno != 0 || *end != '\0') {
throw RuntimeError("Invalid format of input file " + file_name +
", could not convert value in the first column " + col1 + " to a float, error on line " +
to_string(linenr) + ".");
}
errno = 0;
double col2_value = strtod(col2.c_str(), &end);
if (errno != 0 || *end != '\0') {
throw RuntimeError("Invalid format of input file " + file_name +
", could not convert value in the second column " + col2 + " to a float, error on line " +
to_string(linenr) + ".");
}
res.push_back(std::vector<double>());
res.back().push_back(col1_value);
res.back().push_back(col2_value);
linenr++;
}
return res;
}
} // namespace data_utils
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/api/base_chkpt_mol.h | .h | 1,605 | 65 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_BASE_CHKPT_MOL_H
#define LIBMCELL_API_BASE_CHKPT_MOL_H
#include "generated/gen_base_chkpt_mol.h"
#include "api/api_common.h"
namespace MCell {
class Molecule;
namespace API {
// macro for GenChpt*Mol construction, used in Chpt*Mol constructors
#define GEN_CHKPT_MOL_CTOR(GEN_CLASS_NAME, M, ID_SPECIES_MAP, TIME_UNIT) \
GEN_CLASS_NAME(\
M.id, \
ID_SPECIES_MAP.find(M.species_id)->second, \
M.diffusion_time * TIME_UNIT, \
M.birthday * TIME_UNIT, \
M.flags, \
((M.unimol_rxn_time != TIME_INVALID) ? M.unimol_rxn_time * TIME_UNIT : FLT_UNSET) \
)
class BaseChkptMol: public GenBaseChkptMol {
public:
BASE_CHKPT_MOL_CTOR()
BaseChkptMol() {
}
void postprocess_in_ctor() override {
set_all_custom_attributes_to_default();
}
void set_all_custom_attributes_to_default() override {
type = MoleculeType::UNSET;
}
bool export_as_string_without_newlines() const override {
return true;
}
bool export_even_if_already_exported() const override {
return true;
}
// used when casting to a derived class
MoleculeType type;
};
} // namespace API
} // namespace MCell
#endif // LIBMCELL_API_BASE_CHKPT_MOL_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/complex.h | .h | 4,242 | 141 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_COMPLEX_H
#define API_COMPLEX_H
#include "generated/gen_complex.h"
#include "api/api_common.h"
#include "api/api_utils.h"
#include "api/compartment_utils.h"
#include "bng/bngl_names.h"
namespace BNG {
class BNGData;
class Cplx;
}
namespace MCell {
namespace API {
class Species;
// WARNING: do not set compartment_name through attribute, use set_compartment_name
class Complex: public GenComplex {
public:
COMPLEX_CTOR()
static std::shared_ptr<API::Complex> construct_empty() {
// to avoid Complex object semantic check, we need to insert a dummy name
// when creating the object
auto res_cplx_inst = std::make_shared<API::Complex>(STR_UNSET);
res_cplx_inst->name = STR_UNSET;
return res_cplx_inst;
}
static std::shared_ptr<API::Complex> construct_from_bng_cplx(
const BNG::BNGData& bng_data,
const BNG::Cplx& bng_inst);
static std::shared_ptr<API::Complex> construct_from_bng_cplx_w_orientation(
const BNG::BNGData& bng_data,
const BNG::Cplx& bng_inst,
const Orientation orientation);
void set_name(const std::string& name_) override {
BaseDataClass::set_name(name_);
// rerun initialization because the name is parsed as a BNGL string
elementary_molecules.clear();
postprocess_in_ctor();
}
void postprocess_in_ctor() override;
void check_semantics() const override {
if (is_species_object()) {
// all semantic checks will be done in Species
return;
}
if (compartment_name == BNG::DEFAULT_COMPARTMENT_NAME) {
throw ValueError("Compartment name '" + compartment_name + "' is reserved, please use a different name.");
}
GenComplex::check_semantics();
}
// using shorter printout when all_details is false
std::string to_str(const bool all_details=false, const std::string ind="") const override;
bool __eq__(const Complex& other) const override;
std::string to_bngl_str() const override {
return to_bngl_str_w_custom_orientation();
}
std::shared_ptr<Species> as_species() override;
// do not export elementary_molecules (they are represented by name)
bool skip_vectors_export() const override {
return true;
}
// export into a single line
bool export_as_string_without_newlines() const override {
return true;
}
std::string export_to_python(std::ostream& out, PythonExportContext& ctx) {
// we must set name for export if it was not set
if (!is_set(name)) {
name = to_bngl_str_w_custom_orientation();
}
return GenComplex::export_to_python(out, ctx);
}
// complexes can be only either surf or vol, there is no other option
// WARNING: information on whether this is a surface or volume complex
// may not be available all the time, e.g. when complex is constructed with m.Complex('A')
bool is_vol() const {
return !is_surf();
}
// WARNING: same as above
bool is_surf() const;
std::string to_bngl_str_w_custom_orientation(const bool include_mcell_orientation = false) const;
// not really const, sets mutable members that serve as cache
const std::string& get_canonical_name() const;
// WARNING: information on whether this is a surface or volume complex - used when determining the
// compartment may not be available all the time, e.g. when complex is constructed with m.Complex('A')
const std::string& get_primary_compartment_name() const;
void set_compartment_name(const std::string& new_compartment_name) {
compartment_name = new_compartment_name;
set_unset_compartments_of_elementary_molecules();
}
private:
void set_unset_compartments_of_elementary_molecules();
bool is_species_object() const;
// set when __eq__ is called, valid if cached_data_are_uptodate is true
mutable std::string canonical_name;
};
} // namespace API
} // namespace MCell
#endif // API_COMPLEX_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/exports.cpp | .cpp | 390 | 23 | // temporary workaround,
// I was unable to figure out so far how to make cmake link a static library to
// a shared one and export its symbols
extern "C" {
void PyInit_mcell();
}
// exported functions
static volatile int x = 0;
class UseSymbol {
public:
UseSymbol() {
if (x != 0) {
// make the symbol be used, but not called
PyInit_mcell();
}
}
};
UseSymbol z;
| C++ |
3D | mcellteam/mcell | libmcell/api/libmcell_dummy.cpp | .cpp | 2,076 | 75 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
// this is an empty implementation of some functions from libmcell
// MCell executable (not mcell.so) references but not uses Callbacks class and other
// functions and we do not want to link all the Python libraries it needs
#include "api/reaction_info.h"
#include "api/callbacks.h"
#include "api/mol_wall_hit_info.h"
#include "api/checkpoint_signals.h"
#if PYTHON_VERSION == 39 && !defined(_MSC_VER)
extern "C" {
// including pybind11 with Python 3.9 requires this symbol, however, must not be used
void __attribute__((weak)) _Py_Dealloc(PyObject*) {
release_assert("must not be called");
}
}
#endif
namespace MCell {
namespace API {
void save_checkpoint_func(double, MCell::API::CheckpointSaveEventContext) {
release_assert("must not be called");
}
Callbacks::Callbacks(Model*) {
// empty
}
void Callbacks::do_mol_wall_hit_callbacks(std::shared_ptr<MolWallHitInfo>) {
release_assert("must not be called");
}
// we also need some implementations for MolWallHitInfo
bool GenMolWallHitInfo::__eq__(const MolWallHitInfo&) const {
release_assert("must not be called");
return false;
}
bool GenMolWallHitInfo::eq_nonarray_attributes(const MolWallHitInfo&, const bool) const {
release_assert("must not be called");
return false;
}
bool Callbacks::do_rxn_callback(std::shared_ptr<ReactionInfo>) {
release_assert("must not be called");
return false;
}
bool GenReactionInfo::__eq__(const ReactionInfo&) const {
release_assert("must not be called");
return false;
}
bool GenReactionInfo::eq_nonarray_attributes(const ReactionInfo&, const bool) const {
release_assert("must not be called");
return false;
}
} /* namespace API */
} /* namespace MCell */
| C++ |
3D | mcellteam/mcell | libmcell/api/bindings.h | .h | 665 | 27 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef LIBMCELL_API_BINDINGS_H
#define LIBMCELL_API_BINDINGS_H
namespace MCell {
namespace API {
// used to detect Ctrl-C signal from the user,
// throws an exception if so
void check_ctrl_c(const double current_time, World* arg);
}
}
#endif // LIBMCELL_API_BINDINGS_H
| Unknown |
3D | mcellteam/mcell | libmcell/api/instantiation.h | .h | 2,423 | 84 | /******************************************************************************
*
* Copyright (C) 2020 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef API_INSTANTIATION_H
#define API_INSTANTIATION_H
#include "generated/gen_instantiation.h"
#include "api/api_common.h"
#include "api/api_utils.h"
#include "api/release_site.h"
namespace BNG {
class BNGData;
class SeedSpecies;
class Compartment;
}
namespace MCell {
namespace API {
class Instantiation: public GenInstantiation {
public:
INSTANTIATION_CTOR()
// from generated template
void add_release_site(std::shared_ptr<ReleaseSite> s) override {
append_to_vec(release_sites, s);
}
std::shared_ptr<ReleaseSite> find_release_site(const std::string& name) override {
return vec_find_by_name(release_sites, name);
}
void add_geometry_object(std::shared_ptr<GeometryObject> o) override {
append_to_vec(geometry_objects, o);
}
std::shared_ptr<GeometryObject> find_geometry_object(const std::string& name) override {
return vec_find_by_name(geometry_objects, name);
}
void load_bngl_compartments_and_seed_species(
const std::string& file_name,
std::shared_ptr<Region> default_release_region = nullptr,
const std::map<std::string, double>& parameter_overrides = std::map<std::string, double>()
) override;
std::shared_ptr<GeometryObject> find_volume_compartment_object(const std::string& name) override;
std::shared_ptr<GeometryObject> find_surface_compartment_object(const std::string& name) override;
// added manually
void dump() const;
// returns empty shared ptr if compartment was not found
std::shared_ptr<Region> get_compartment_region(const std::string& name);
protected:
void convert_bng_data_to_instantiation(
const BNG::BNGData& bng_data,
std::shared_ptr<Region> default_release_region);
private:
void convert_compartments(
const BNG::BNGData& bng_data);
void convert_single_seed_species_to_release_site(
const BNG::BNGData& bng_data,
const BNG::SeedSpecies& bng_ss,
std::shared_ptr<Region> default_release_region);
};
} // namespace API
} // namespace MCell
#endif // API_INSTANTIATION_H
| Unknown |
3D | mcellteam/mcell | libmcell/generated/gen_component_type.cpp | .cpp | 6,098 | 154 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#include <sstream>
#include "api/pybind11_stl_include.h"
#include "api/python_export_utils.h"
#include "gen_component_type.h"
#include "api/component_type.h"
#include "api/component.h"
namespace MCell {
namespace API {
void GenComponentType::check_semantics() const {
if (!is_set(name)) {
throw ValueError("Parameter 'name' must be set.");
}
}
void GenComponentType::set_initialized() {
initialized = true;
}
void GenComponentType::set_all_attributes_as_default_or_unset() {
class_name = "ComponentType";
name = STR_UNSET;
states = std::vector<std::string>();
}
std::shared_ptr<ComponentType> GenComponentType::copy_component_type() const {
std::shared_ptr<ComponentType> res = std::make_shared<ComponentType>(DefaultCtorArgType());
res->class_name = class_name;
res->name = name;
res->states = states;
return res;
}
std::shared_ptr<ComponentType> GenComponentType::deepcopy_component_type(py::dict) const {
std::shared_ptr<ComponentType> res = std::make_shared<ComponentType>(DefaultCtorArgType());
res->class_name = class_name;
res->name = name;
res->states = states;
return res;
}
bool GenComponentType::__eq__(const ComponentType& other) const {
return
name == other.name &&
states == other.states;
}
bool GenComponentType::eq_nonarray_attributes(const ComponentType& other, const bool ignore_name) const {
return
(ignore_name || name == other.name) &&
true /*states*/;
}
std::string GenComponentType::to_str(const bool all_details, const std::string ind) const {
std::stringstream ss;
ss << get_object_name() << ": " <<
"name=" << name << ", " <<
"states=" << vec_nonptr_to_str(states, all_details, ind + " ");
return ss.str();
}
py::class_<ComponentType> define_pybinding_ComponentType(py::module& m) {
return py::class_<ComponentType, std::shared_ptr<ComponentType>>(m, "ComponentType", "Multiple functional attributes for each molecule type are described using components. And this class defines a type of a component. For example, proteins have multiple functional substructures such as domains, motifs, and binding sites. These components can be unchanging (called stateless) or exist in one of many different internal states For example, certain binding motifs may have different behaviors depending on whether they are unphosphorylated or phosphorylated.")
.def(
py::init<
const std::string&,
const std::vector<std::string>
>(),
py::arg("name"),
py::arg("states") = std::vector<std::string>()
)
.def("check_semantics", &ComponentType::check_semantics)
.def("__copy__", &ComponentType::copy_component_type)
.def("__deepcopy__", &ComponentType::deepcopy_component_type, py::arg("memo"))
.def("__str__", &ComponentType::to_str, py::arg("all_details") = false, py::arg("ind") = std::string(""))
.def("__eq__", &ComponentType::__eq__, py::arg("other"))
.def("inst", py::overload_cast<const std::string&, const int>(&ComponentType::inst), py::arg("state") = "STATE_UNSET", py::arg("bond") = BOND_UNBOUND, "Instantiate a component from this component type.\n- state: Selected state, must be from the list of the allowed states.\n\n- bond: Bond information for the created component instance.\n\n")
.def("inst", py::overload_cast<const int, const int>(&ComponentType::inst), py::arg("state") = STATE_UNSET_INT, py::arg("bond") = BOND_UNBOUND, "Instantiate a component from this component type.\n- state: Selected state, must be from the list of the allowed, converted to string.\n\n- bond: Bond information for the created component instance.\n\n")
.def("to_bngl_str", &ComponentType::to_bngl_str, "Creates a string that corresponds to its BNGL representation.")
.def("dump", &ComponentType::dump)
.def_property("name", &ComponentType::get_name, &ComponentType::set_name, "Name of this component type.")
.def_property("states", &ComponentType::get_states, &ComponentType::set_states, py::return_value_policy::reference, "List of states allowed by this component.")
;
}
std::string GenComponentType::export_to_python(std::ostream& out, PythonExportContext& ctx) {
if (!export_even_if_already_exported() && ctx.already_exported(this)) {
return ctx.get_exported_name(this);
}
std::string exported_name = std::string("component_type") + "_" + (is_set(name) ? fix_id(name) : std::to_string(ctx.postinc_counter("component_type")));
if (!export_even_if_already_exported()) {
ctx.add_exported(this, exported_name);
}
bool str_export = export_as_string_without_newlines();
std::string nl = "";
std::string ind = " ";
std::stringstream ss;
if (!str_export) {
nl = "\n";
ind = " ";
ss << exported_name << " = ";
}
ss << "m.ComponentType(" << nl;
ss << ind << "name = " << "'" << name << "'" << "," << nl;
if (states != std::vector<std::string>() && !skip_vectors_export()) {
ss << ind << "states = " << export_vec_states(out, ctx, exported_name) << "," << nl;
}
ss << ")" << nl << nl;
if (!str_export) {
out << ss.str();
return exported_name;
}
else {
return ss.str();
}
}
std::string GenComponentType::export_vec_states(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name) {
// does not print the array itself to 'out' and returns the whole list
std::stringstream ss;
ss << "[";
for (size_t i = 0; i < states.size(); i++) {
const auto& item = states[i];
if (i == 0) {
ss << " ";
}
else if (i % 16 == 0) {
ss << "\n ";
}
ss << "'" << item << "', ";
}
ss << "]";
return ss.str();
}
} // namespace API
} // namespace MCell
| C++ |
3D | mcellteam/mcell | libmcell/generated/gen_vectors_make_opaque.h | .h | 2,660 | 69 | /******************************************************************************
*
* Copyright (C) 2021 by
* The Salk Institute for Biological Studies
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*
******************************************************************************/
#ifndef GEN_VECTORS_MAKE_OPAQUE_H
#define GEN_VECTORS_MAKE_OPAQUE_H
#include <vector>
#include <memory>
#include "pybind11/include/pybind11/pybind11.h"
#include "defines.h"
namespace MCell {
namespace API {
class BaseChkptMol;
class Complex;
class Component;
class ComponentType;
class Count;
class ElementaryMolecule;
class ElementaryMoleculeType;
class GeometryObject;
class InitialSurfaceRelease;
class MoleculeReleaseInfo;
class ReactionRule;
class ReleaseSite;
class Species;
class SurfaceClass;
class SurfaceProperty;
class SurfaceRegion;
class VizOutput;
} // namespace API
} // namespace MCell
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::BaseChkptMol>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::Complex>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::Component>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::ComponentType>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::Count>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::ElementaryMolecule>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::ElementaryMoleculeType>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::GeometryObject>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::InitialSurfaceRelease>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::vector<double>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::vector<int>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::MoleculeReleaseInfo>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::ReactionRule>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::ReleaseSite>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::Species>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::SurfaceClass>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::SurfaceProperty>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::SurfaceRegion>>);
PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<MCell::API::VizOutput>>);
PYBIND11_MAKE_OPAQUE(std::vector<double>);
PYBIND11_MAKE_OPAQUE(std::vector<int>);
PYBIND11_MAKE_OPAQUE(std::vector<std::string>);
PYBIND11_MAKE_OPAQUE(std::vector<uint64_t>);
#endif // GEN_VECTORS_MAKE_OPAQUE_H
| Unknown |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.