| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "mt_tip.hpp" | |||
| 2 | #include "trajectory.hpp" | |||
| 3 | #include "microtubule.hpp" | |||
| 4 | #include "region.hpp" | |||
| 5 | ||||
| 6 | ✗ | MTTip::MTTip(Microtubule* m, TrajectoryVector tv, double v, DeterministicQueue* q, double queue_v): | ||
| 7 | ✗ | mt(m), | ||
| 8 | ✗ | trajectory(tv.trajectory), | ||
| 9 | ✗ | dir(tv.dir), | ||
| 10 | ✗ | velocity(v), | ||
| 11 | ✗ | event(m, q, queue_v), | ||
| 12 | ✗ | next_collision(tv.trajectory->intersections.end()) | ||
| 13 | { | |||
| 14 | // WARNING: Do not use the mt pointer in this function, as it has not been initialized | |||
| 15 | #ifdef DBG_MTS | |||
| 16 | cout << "DBG/MTS: MTTip created.\n"; | |||
| 17 | #endif | |||
| 18 | ||||
| 19 | ✗ | return; | ||
| 20 | } | |||
| 21 | ||||
| 22 | ✗ | MTTip::~MTTip() | ||
| 23 | { | |||
| 24 | #ifdef DBG_MTS | |||
| 25 | cout << "DBG/MTS: MTTip destroyed.\n"; | |||
| 26 | #endif | |||
| 27 | ||||
| 28 | ✗ | return; | ||
| 29 | ✗ | } | ||
| 30 | ||||
| 31 | ✗ | void MTTip::initialize() | ||
| 32 | { | |||
| 33 | // register the tip for notification in the current trajectory | |||
| 34 | ✗ | notification_tag = trajectory->register_for_notifications(this); | ||
| 35 | ||||
| 36 | // get the region tag of the tip | |||
| 37 | ✗ | region_tag = trajectory->base.region->register_on_region(this, type(), mt->type); | ||
| 38 | ||||
| 39 | // locate the next intersection position of the tip | |||
| 40 | ✗ | locate_intersection(); | ||
| 41 | ||||
| 42 | // determine the kind of event the tip is going to encounter | |||
| 43 | ✗ | determine_event(); | ||
| 44 | ||||
| 45 | ✗ | return; | ||
| 46 | } | |||
| 47 | ||||
| 48 | ✗ | void MTTip::unlink_from_trajectory() | ||
| 49 | { | |||
| 50 | // unregister the tip from current region | |||
| 51 | ✗ | trajectory->base.region->unregister_from_region(region_tag, type(), mt->type); | ||
| 52 | ||||
| 53 | // also unregister its notification from current trajectory | |||
| 54 | ✗ | trajectory->unregister_for_notifications(notification_tag); | ||
| 55 | ✗ | return; | ||
| 56 | } | |||
| 57 | ||||
| 58 | ✗ | void MTTip::locate_intersection() | ||
| 59 | { | |||
| 60 | // go through the intersection list looking for the first event that can take place | |||
| 61 | #ifdef DBG_MTS | |||
| 62 | cout << "DBG/MTS: MTTip ::locateIntersection()\n"; | |||
| 63 | #endif | |||
| 64 | ||||
| 65 | // find the first intersection after current 'position()' | |||
| 66 | ✗ | next_collision = trajectory->intersections.upper_bound(position()); | ||
| 67 | ||||
| 68 | IntersectionItr temp = next_collision; | |||
| 69 | ||||
| 70 | // if necessary, step down to the intersection on the other side of the tip [minus end can have velocity zero (=0)] | |||
| 71 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (((static_cast<double>(dir) * velocity) < 0) || ((velocity == 0) && (dir == Direction::FORWARD))) | |
| 72 | { | |||
| 73 | next_collision--; | |||
| 74 | } | |||
| 75 | ||||
| 76 | // if direction of the tip is backward then only step down the segment interator | |||
| 77 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (dir == Direction::BACKWARD) | |
| 78 | { | |||
| 79 | temp--; | |||
| 80 | } | |||
| 81 | ||||
| 82 | // plus tip (must be on the end of top segment) | |||
| 83 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (type() == TipType::PLUS) | |
| 84 | { | |||
| 85 | ✗ | mt->segments.last()->end_itr = temp; | ||
| 86 | } | |||
| 87 | ||||
| 88 | // minus tip (must be on the start of bottom segment | |||
| 89 | else | |||
| 90 | { | |||
| 91 | ✗ | mt->segments.first()->start_itr = temp; | ||
| 92 | } | |||
| 93 | ||||
| 94 | ✗ | return; | ||
| 95 | } | |||
| 96 | ||||
| 97 | ✗ | void MTTip::advance_intersection() | ||
| 98 | { | |||
| 99 | // next collission site in front | |||
| 100 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((static_cast<double>(dir) * velocity > 0) || ((velocity == 0) && (dir == Direction::BACKWARD))) | |
| 101 | { | |||
| 102 | #ifdef DBG_ASSERT | |||
| 103 | if (nextCollision == trajectory->wallEnd()) | |||
| 104 | { | |||
| 105 | cerr << "DBG/ASSERT: ERROR: Cannot advance position of tip that is at the boundary.\n"; | |||
| 106 | return; | |||
| 107 | } | |||
| 108 | #endif | |||
| 109 | ||||
| 110 | next_collision++; | |||
| 111 | } | |||
| 112 | ||||
| 113 | // next collission site in back | |||
| 114 | else | |||
| 115 | { | |||
| 116 | #ifdef DBG_ASSERT | |||
| 117 | if (nextCollision == trajectory->wallBegin()) | |||
| 118 | { | |||
| 119 | cerr << "DBG/ASSERT: ERROR: Cannot advance position of tip that is at the boundary.\n"; | |||
| 120 | return; | |||
| 121 | } | |||
| 122 | #endif | |||
| 123 | ||||
| 124 | next_collision--; | |||
| 125 | } | |||
| 126 | ||||
| 127 | ✗ | IntersectionItr temp = next_collision; | ||
| 128 | ||||
| 129 | // for minus end velocity (if direction of the tip is backward then step down the segment interator else step up) | |||
| 130 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (velocity <= 0) | |
| 131 | { | |||
| 132 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (dir == Direction::BACKWARD) | |
| 133 | { | |||
| 134 | temp--; | |||
| 135 | } | |||
| 136 | else | |||
| 137 | { | |||
| 138 | temp++; | |||
| 139 | } | |||
| 140 | } | |||
| 141 | ||||
| 142 | // plus tip (must be on the end of top segment) | |||
| 143 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (type() == TipType::PLUS) | |
| 144 | { | |||
| 145 | ✗ | mt->segments.last()->end_itr = temp; | ||
| 146 | } | |||
| 147 | ||||
| 148 | // minus tip (must be on the start of bottom segment | |||
| 149 | else | |||
| 150 | { | |||
| 151 | ✗ | mt->segments.first()->start_itr = temp; | ||
| 152 | } | |||
| 153 | ||||
| 154 | ✗ | return; | ||
| 155 | } | |||
| 156 | ||||
| 157 | ✗ | void MTTip::determine_event() | ||
| 158 | { | |||
| 159 | double event_pos(0.0); | |||
| 160 | DeterministicEventType event_type; | |||
| 161 | ||||
| 162 | // get the current position of the tip on the trajectory | |||
| 163 | ✗ | double pos = position(); | ||
| 164 | ||||
| 165 | // a tip that is polymerizing | |||
| 166 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (velocity > 0) | |
| 167 | { | |||
| 168 | // next collision on wall begenning (at the bottom of the trajectory) | |||
| 169 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (next_collision == trajectory->wall_begin()) | |
| 170 | { | |||
| 171 | event_type = DeterministicEventType::WALL; | |||
| 172 | event_pos = 0; | |||
| 173 | } | |||
| 174 | ||||
| 175 | // next collision on wall end (at the top of the trajectory) | |||
| 176 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | else if (next_collision == trajectory->wall_end()) | |
| 177 | { | |||
| 178 | event_type = DeterministicEventType::WALL; | |||
| 179 | ✗ | event_pos = trajectory->length; | ||
| 180 | } | |||
| 181 | ||||
| 182 | // next collision, some where at the middle of trajectory | |||
| 183 | else | |||
| 184 | { | |||
| 185 | event_type = DeterministicEventType::COLLISION; | |||
| 186 | ✗ | event_pos = next_collision->first; | ||
| 187 | } | |||
| 188 | } | |||
| 189 | ||||
| 190 | // a tip that is either paused or depolymerizing | |||
| 191 | else | |||
| 192 | { | |||
| 193 | // next collision on wall begenning (at the bottom of the trajectory) | |||
| 194 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (next_collision == trajectory->wall_begin()) | |
| 195 | { | |||
| 196 | // the segment will be removed | |||
| 197 | event_type = DeterministicEventType::END_OF_SEGMENT; | |||
| 198 | event_pos = 0; | |||
| 199 | } | |||
| 200 | ||||
| 201 | // next collision on wall end (at the top of the trajectory) | |||
| 202 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | else if (next_collision == trajectory->wall_end()) | |
| 203 | { | |||
| 204 | // the segment will be removed | |||
| 205 | event_type = DeterministicEventType::END_OF_SEGMENT; | |||
| 206 | ✗ | event_pos = trajectory->length; | ||
| 207 | } | |||
| 208 | ||||
| 209 | // plus end tip and the next collision is some where at the middle of trajectory | |||
| 210 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | else if ((mt->segments.size() != 1) && (this == &(mt->plus)) | |
| 211 | ✗ | && (next_collision == mt->segments.last()->start_itr)) | ||
| 212 | { | |||
| 213 | // the segment will be removed | |||
| 214 | event_type = DeterministicEventType::END_OF_SEGMENT; | |||
| 215 | ✗ | event_pos = mt->segments.last()->start_itr->first; | ||
| 216 | } | |||
| 217 | ||||
| 218 | // minus end tip and the next collision is some where at the middle of trajectory | |||
| 219 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | else if ((mt->segments.size() != 1) && (this == &(mt->minus)) | |
| 220 | ✗ | && (next_collision == mt->segments.first()->end_itr)) | ||
| 221 | { | |||
| 222 | // the segment will be removed | |||
| 223 | event_type = DeterministicEventType::END_OF_SEGMENT; | |||
| 224 | ✗ | event_pos = mt->segments.first()->end_itr->first; | ||
| 225 | } | |||
| 226 | ||||
| 227 | // next collision is some where at the middle of trajectory and a back-track event will occur | |||
| 228 | else | |||
| 229 | { | |||
| 230 | event_type = DeterministicEventType::BACKTRACK; | |||
| 231 | ✗ | event_pos = next_collision->first; | ||
| 232 | } | |||
| 233 | } | |||
| 234 | ||||
| 235 | // store the event with: (a) type of event and (b) distance to travel | |||
| 236 | ✗ | event.push_on_queue((event_pos - pos) * static_cast<double>(dir), event_type); | ||
| 237 | ||||
| 238 | // transfer the value of the calculated event position to the next event position | |||
| 239 | ✗ | next_event_pos = event_pos; | ||
| 240 | ||||
| 241 | #ifdef DBG_EVENT | |||
| 242 | if (event.type != ev_none) | |||
| 243 | { | |||
| 244 | cout << "DBG/EVENT: event created. type: " << eventType << ", distance: " << (eventPos - pos) * dir << "\n"; | |||
| 245 | cout << "tip position: " << position() << ", tip velocity: " << dir * velocity | |||
| 246 | << ", trajectory length: " << trajectory->length << "\n"; | |||
| 247 | if (nextCollision != trajectory->intersections.end()) | |||
| 248 | { | |||
| 249 | cout << "event position: " << nextCollision->first << "\n"; | |||
| 250 | } | |||
| 251 | } | |||
| 252 | #endif | |||
| 253 | ||||
| 254 | ✗ | return; | ||
| 255 | } | |||
| 256 | ||||
| 257 | ✗ | void MTTip::notify_remove(IntersectionItr& old_is) | ||
| 258 | { | |||
| 259 | // update the length of MT | |||
| 260 | ✗ | mt->update_length(); | ||
| 261 | ||||
| 262 | // scheduled next collision is at this invalid intersection point, so skip it to reach the next intersection point | |||
| 263 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (old_is == next_collision) | |
| 264 | { | |||
| 265 | ✗ | advance_intersection(); | ||
| 266 | ✗ | determine_event(); | ||
| 267 | } | |||
| 268 | ||||
| 269 | // get the tip start/end iterator | |||
| 270 | ✗ | IntersectionItr& ref = (type() == TipType::PLUS) ? mt->segments.last()->end_itr : mt->segments.first()->start_itr; | ||
| 271 | ||||
| 272 | // link the tip start/end iterator to the new inserted iterator | |||
| 273 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (ref == old_is) | |
| 274 | { | |||
| 275 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (dir == Direction::FORWARD) | |
| 276 | { | |||
| 277 | ref++; | |||
| 278 | } | |||
| 279 | else | |||
| 280 | { | |||
| 281 | ref--; | |||
| 282 | } | |||
| 283 | } | |||
| 284 | ||||
| 285 | ✗ | return; | ||
| 286 | } | |||
| 287 | ||||
| 288 | ✗ | void MTTip::notify_insert(IntersectionItr& new_is) | ||
| 289 | { | |||
| 290 | ||||
| 291 | // update the MT | |||
| 292 | ✗ | mt->update_length(); | ||
| 293 | ||||
| 294 | ✗ | IntersectionItr temp = new_is; | ||
| 295 | ||||
| 296 | // next collission site in front | |||
| 297 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((static_cast<double>(dir) * velocity > 0) || ((velocity == 0) && (dir == Direction::BACKWARD))) | |
| 298 | { | |||
| 299 | // if the scheduled next collision is located after the new intersection point, then replace it by the new | |||
| 300 | // intersection | |||
| 301 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((++temp == next_collision) && (new_is->first > position())) | |
| 302 | { | |||
| 303 | ✗ | next_collision = new_is; | ||
| 304 | ✗ | determine_event(); | ||
| 305 | } | |||
| 306 | } | |||
| 307 | ||||
| 308 | // next collission site in back | |||
| 309 | else | |||
| 310 | { | |||
| 311 | // if the scheduled next collision is located after the new intersection point, then replace it by the new | |||
| 312 | // intersection | |||
| 313 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((--temp == next_collision) && (new_is->first < position())) | |
| 314 | { | |||
| 315 | ✗ | next_collision = new_is; | ||
| 316 | ✗ | determine_event(); | ||
| 317 | } | |||
| 318 | } | |||
| 319 | ||||
| 320 | ✗ | temp = new_is; | ||
| 321 | ||||
| 322 | // get the tip start/end iterator | |||
| 323 | IntersectionItr& ref_itr | |||
| 324 | ✗ | = (type() == TipType::PLUS) ? mt->segments.last()->end_itr : mt->segments.first()->start_itr; | ||
| 325 | ||||
| 326 | // get the tip start/end position | |||
| 327 | ✗ | double& ref_pos = (type() == TipType::PLUS) ? mt->segments.last()->end : mt->segments.first()->start; | ||
| 328 | ||||
| 329 | // link the tip start/end iterator to the new inserted iterator | |||
| 330 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (dir == Direction::FORWARD) | |
| 331 | { | |||
| 332 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((++temp == ref_itr) && (new_is->first > ref_pos)) | |
| 333 | { | |||
| 334 | ✗ | ref_itr = new_is; | ||
| 335 | } | |||
| 336 | } | |||
| 337 | ||||
| 338 | else | |||
| 339 | { | |||
| 340 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if ((--temp == ref_itr) && (new_is->first < ref_pos)) | |
| 341 | { | |||
| 342 | ✗ | ref_itr = new_is; | ||
| 343 | } | |||
| 344 | } | |||
| 345 | ||||
| 346 | ✗ | return; | ||
| 347 | } | |||
| 348 | ||||
| 349 | ✗ | TipType MTTip::type() | ||
| 350 | { | |||
| 351 | // get tip type of MT | |||
| 352 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (this == &(mt->plus)) | |
| 353 | { | |||
| 354 | return TipType::PLUS; | |||
| 355 | } | |||
| 356 | else | |||
| 357 | { | |||
| 358 | ✗ | return TipType::MINUS; | ||
| 359 | } | |||
| 360 | } | |||
| 361 | ||||
| 362 | ✗ | double MTTip::position() | ||
| 363 | { | |||
| 364 | // get current tip (top) position on trajectory | |||
| 365 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (this == &(mt->minus)) | |
| 366 | { | |||
| 367 | ✗ | return mt->segments.first()->start; | ||
| 368 | } | |||
| 369 | else | |||
| 370 | { | |||
| 371 | ✗ | return mt->segments.last()->end; | ||
| 372 | } | |||
| 373 | } | |||
| 374 | ||||
| 375 | ✗ | double MTTip::other_position() | ||
| 376 | { | |||
| 377 | // get the (bottom) position of an active segment | |||
| 378 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (this == &(mt->minus)) | |
| 379 | { | |||
| 380 | ✗ | return mt->segments.first()->end; | ||
| 381 | } | |||
| 382 | else | |||
| 383 | { | |||
| 384 | ✗ | return mt->segments.last()->start; | ||
| 385 | } | |||
| 386 | } | |||
| 387 | ||||
| 388 | ✗ | Segment& MTTip::segment() | ||
| 389 | { | |||
| 390 | // get the current segement of the tip | |||
| 391 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (this == &(mt->minus)) | |
| 392 | { | |||
| 393 | ✗ | return *(mt->segments.first()); | ||
| 394 | } | |||
| 395 | else | |||
| 396 | { | |||
| 397 | ✗ | return *(mt->segments.last()); | ||
| 398 | } | |||
| 399 | } | |||
| 400 | ||||
| 401 | ✗ | void MTTip::switch_trajectory(Trajectory* new_tr, Direction d, IntersectionItr intersect, bool advance) | ||
| 402 | { | |||
| 403 | ||||
| 404 | // copy old trajectory of the tip (required to unregister the tip from old trajectory region) | |||
| 405 | ✗ | Trajectory* old_tr(trajectory); | ||
| 406 | ||||
| 407 | // assign new trajectory to the tip | |||
| 408 | ✗ | trajectory = new_tr; | ||
| 409 | ||||
| 410 | // assign new direction to the tip | |||
| 411 | ✗ | dir = d; | ||
| 412 | ✗ | next_collision = intersect; | ||
| 413 | ||||
| 414 | // set the tip at the next intersection point | |||
| 415 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (advance) | |
| 416 | { | |||
| 417 | ✗ | advance_intersection(); | ||
| 418 | } | |||
| 419 | ||||
| 420 | // assign an event to the tip | |||
| 421 | ✗ | determine_event(); | ||
| 422 | ||||
| 423 | // unregister the tip from old trajectory | |||
| 424 | ✗ | old_tr->base.region->unregister_from_region(region_tag, type(), mt->type); | ||
| 425 | ||||
| 426 | // find the new regiontag of the tip | |||
| 427 | ✗ | region_tag = new_tr->base.region->register_on_region(this, type(), mt->type); | ||
| 428 | ||||
| 429 | // copy old notification tag of the tip (required to unregister the tip from old trajectory notification list) | |||
| 430 | ✗ | TrjMTTipTag temp_tag = notification_tag; | ||
| 431 | ||||
| 432 | // assign new notification tag to the tip | |||
| 433 | ✗ | notification_tag = new_tr->register_for_notifications(this); | ||
| 434 | ||||
| 435 | // unregister notification of the tip from old trajectory | |||
| 436 | ✗ | old_tr->unregister_for_notifications(temp_tag); | ||
| 437 | ||||
| 438 | ✗ | return; | ||
| 439 | } | |||
| 440 |