-
Notifications
You must be signed in to change notification settings - Fork 17
/
Yeast.cpp
157 lines (110 loc) · 4.74 KB
/
Yeast.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/////////////////////////////////////////////////////////////////////////////////////////
//
// gro is protected by the UW OPEN SOURCE LICENSE, which is summarized here.
// Please see the file LICENSE.txt for the complete license.
//
// THE SOFTWARE (AS DEFINED BELOW) AND HARDWARE DESIGNS (AS DEFINED BELOW) IS PROVIDED
// UNDER THE TERMS OF THIS OPEN SOURCE LICENSE (“LICENSE”). THE SOFTWARE IS PROTECTED
// BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THIS SOFTWARE OTHER THAN AS
// AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
//
// BY EXERCISING ANY RIGHTS TO THE SOFTWARE AND/OR HARDWARE PROVIDED HERE, YOU ACCEPT AND
// AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE
// CONSIDERED A CONTRACT, THE UNIVERSITY OF WASHINGTON (“UW”) GRANTS YOU THE RIGHTS
// CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
//
// TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
//
//
#include "Yeast.h"
#include "Programs.h"
Yeast::Yeast ( World * w, float x, float y, float a, float v, bool b )
: Cell ( w ), volume ( v ), bud ( NULL ), is_bud ( b ) {
float r = radius();
cpBody *body = cpSpaceAddBody(space, cpBodyNew(r, cpMomentForCircle(10*v, 0.0f, r, cpvzero)));
parent_cell = NULL;
body->p = cpv ( x, y );
body->v = cpv ( 0, 0 );
body->a = a;
shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius(), cpvzero));
shape->e = ELASTIC; shape->u = FRICTION;
int i;
for ( i=0; i<MAX_STATE_NUM; i++ ) q[i] = 0;
for ( i=0; i<MAX_REP_NUM; i++ ) rep[i] = 0;
}
#define YFMULT 500
void Yeast::render ( Theme * theme, GroPainter * painter ) {
float r = radius();
float vol;
if ( is_bud == false && bud == NULL ) { // normal cell
vol = volume;
} else if ( is_bud == false && bud != NULL ) { // cell is budding
float vol = volume + bud->get_volume();
} else if ( is_bud ) { // cell is a bud
float vol = volume + parent_cell->get_volume();
}
double
gfp = 500*( rep[GFP] / vol - world->get_param ( "gfp_saturation_min" ) ) / ( world->get_param ( "gfp_saturation_max" ) - world->get_param ( "gfp_saturation_min" ) ),
rfp = 500*( rep[RFP] / vol - world->get_param ( "rfp_saturation_min" ) ) / ( world->get_param ( "rfp_saturation_max" ) - world->get_param ( "rfp_saturation_min" ) ),
yfp = 500*( rep[YFP] / vol - world->get_param ( "yfp_saturation_min" ) ) / ( world->get_param ( "yfp_saturation_max" ) - world->get_param ( "yfp_saturation_min" ) ),
cfp = 500*( rep[CFP] / vol - world->get_param ( "cfp_saturation_min" ) ) / ( world->get_param ( "cfp_saturation_max" ) - world->get_param ( "cfp_saturation_min" ) );
theme->apply_ecoli_edge_color ( painter, is_selected() );
QColor col;
col.setRgbF( qMax(0.0,qMin(1.0,rfp + yfp)),
qMax(0.0,qMin(1.0,gfp + yfp + cfp)),
qMax(0.0,qMin(1.0,cfp)),
0.75);
painter->setBrush(col);
QPointF center (get_x(),get_y());
painter->drawEllipse(center,r,r);
if ( bud )
bud->render ( theme,painter );
return;
}
void Yeast::update ( void ) {
if ( !is_bud ) {
if ( !bud ) {
inc_volume ( 600*get_param("yeast_growth_rate") );
} else {
bud->inc_volume ( 600*get_param("yeast_growth_rate") );
}
if ( volume > 750*get_param("yeast_division_size_mean") && bud == NULL && frand() < 0.01 ) {
float theta = 6.28*frand(), r = radius();
bud = new Yeast ( world, get_x()+(r+1)*sin(theta), get_y()+(r+1)*cos(theta), 0.78, rad_to_vol ( 1.0 ), true );
bud->set_parent_cell ( this );
cord = cpDampedSpringNew ( get_shape()->body, bud->get_shape()->body, cpv(0,0), cpv(0,0), r+0.1, 10, 10 );
cpSpaceAddConstraint ( space, cord );
}
if ( program != NULL )
program->update ( world, this );
}
cpCircleShapeSetRadius ( shape, radius() );
if ( bud ) cpCircleShapeSetRadius ( bud->get_shape(), bud->radius() );
}
Yeast * Yeast::divide ( void ) {
if ( is_bud == false && bud != NULL ) {
if ( bud->get_volume() > 5000.0 && frand() > 0.01 ) {
int i;
float frac = volume / ( volume + bud->get_volume() );
for ( i=0; i<MAX_STATE_NUM; i++ ) {
float temp = q[i];
set ( i, (int) floor ( frac*temp ) );
bud->set ( i, (int) ceil ( (1-frac)*temp ) );
}
for ( i=0; i<MAX_REP_NUM; i++ ) {
float temp = rep[i];
set_rep ( i, (int) floor ( frac*temp ) );
bud->set_rep ( i, (int) ceil ( (1-frac)*temp ) );
}
if ( gro_program != NULL )
bud->set_gro_program ( split_gro_program ( gro_program, frac ) );
bud->set_bud ( false );
world->add_cell ( bud );
bud = NULL;
cpSpaceRemoveConstraint ( space, cord );
cpConstraintFree ( cord );
cord = NULL;
}
}
return NULL;
}