-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathPhysiCell_cell.cpp
More file actions
3603 lines (2947 loc) · 120 KB
/
PhysiCell_cell.cpp
File metadata and controls
3603 lines (2947 loc) · 120 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
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
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
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
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
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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
###############################################################################
# If you use PhysiCell in your project, please cite PhysiCell and the version #
# number, such as below: #
# #
# We implemented and solved the model using PhysiCell (Version x.y.z) [1]. #
# #
# [1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin, #
# PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu- #
# lar Systems, PLoS Comput. Biol. 14(2): e1005991, 2018 #
# DOI: 10.1371/journal.pcbi.1005991 #
# #
# See VERSION.txt or call get_PhysiCell_version() to get the current version #
# x.y.z. Call display_citations() to get detailed information on all cite-#
# able software used in your PhysiCell application. #
# #
# Because PhysiCell extensively uses BioFVM, we suggest you also cite BioFVM #
# as below: #
# #
# We implemented and solved the model using PhysiCell (Version x.y.z) [1], #
# with BioFVM [2] to solve the transport equations. #
# #
# [1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin, #
# PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu- #
# lar Systems, PLoS Comput. Biol. 14(2): e1005991, 2018 #
# DOI: 10.1371/journal.pcbi.1005991 #
# #
# [2] A Ghaffarizadeh, SH Friedman, and P Macklin, BioFVM: an efficient para- #
# llelized diffusive transport solver for 3-D biological simulations, #
# Bioinformatics 32(8): 1256-8, 2016. DOI: 10.1093/bioinformatics/btv730 #
# #
###############################################################################
# #
# BSD 3-Clause License (see https://opensource.org/licenses/BSD-3-Clause) #
# #
# Copyright (c) 2015-2025, Paul Macklin and the PhysiCell Project #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its #
# contributors may be used to endorse or promote products derived from this #
# software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" #
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE #
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR #
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF #
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS #
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN #
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
# POSSIBILITY OF SUCH DAMAGE. #
# #
###############################################################################
*/
#include "PhysiCell_cell.h"
#include "PhysiCell_cell_container.h"
#include "PhysiCell_utilities.h"
#include "PhysiCell_constants.h"
#include "../BioFVM/BioFVM_vector.h"
#ifdef ADDON_PHYSIBOSS
#include "../addons/PhysiBoSS/src/maboss_intracellular.h"
#endif
#ifdef ADDON_ROADRUNNER
#include "../addons/libRoadrunner/src/librr_intracellular.h"
#endif
#ifdef ADDON_PHYSIDFBA
#include "../addons/dFBA/src/dfba_intracellular.h"
#endif
#include<limits.h>
#include <signal.h> // for segfault
#include <algorithm>
#include <iterator>
namespace PhysiCell{
std::unordered_map<std::string,Cell_Definition*> cell_definitions_by_name;
std::unordered_map<int,Cell_Definition*> cell_definitions_by_type;
std::vector<Cell_Definition*> cell_definitions_by_index;
std::unordered_map<std::string,int> cell_definition_indices_by_name;
std::unordered_map<int,int> cell_definition_indices_by_type;
// function pointer on how to choose cell orientation at division
// in case you want the legacy method
std::vector<double> (*cell_division_orientation)(void) = UniformOnUnitSphere; // LegacyRandomOnUnitSphere;
Cell* standard_instantiate_cell()
{ return new Cell; }
Cell_Parameters::Cell_Parameters()
{
o2_hypoxic_threshold = 15.0; // HIF-1alpha at half-max around 1.5-2%, and tumors often are below 2%
o2_hypoxic_response = 8.0; // genomic / proteomic changes observed at 7-8 mmHg
o2_hypoxic_saturation = 4.0; // maximum HIF-1alpha at 0.5% o2 (McKeown)
o2_necrosis_threshold = 5.0;
o2_necrosis_max = 2.5;
o2_proliferation_threshold = 5.0; // assume no proliferation at same level as starting necrosis
o2_proliferation_saturation = 160.0; // 5% = 38, 21% = 160 mmHg
o2_reference = 160.0; // assume all was measured in normoxic 21% o2
pReference_live_phenotype = NULL; // reference live (usually physioxic) phenotype
// necrosis parameters
max_necrosis_rate = 1.0 / (6.0 * 60.0); // assume cells survive 6 hours in very low oxygen
necrosis_type = PhysiCell_constants::deterministic_necrosis;;
return;
}
Cell_Definition::Cell_Definition()
{
// set the microenvironment pointer
pMicroenvironment = NULL;
if( BioFVM::get_default_microenvironment() != NULL )
{ pMicroenvironment = BioFVM::get_default_microenvironment(); }
// extern std::unordered_map<std::string,int> cell_definition_indices_by_name;
// int number_of_cell_defs = cell_definition_indices_by_name.size();
// set up the default parameters
// the default Cell_Parameters constructor should take care of this
type = 0;
name = "unnamed";
is_movable = true;
parameters.pReference_live_phenotype = &phenotype;
// set up the default custom data
// the default Custom_Cell_Data constructor should take care of this
// set up the default functions
functions.instantiate_cell = NULL;
functions.volume_update_function = NULL; // standard_volume_update_function;
functions.update_migration_bias = NULL;
functions.update_phenotype = NULL;
functions.custom_cell_rule = NULL;
functions.update_velocity = NULL; // standard_update_cell_velocity;
functions.add_cell_basement_membrane_interactions = NULL;
functions.calculate_distance_to_membrane = NULL;
// bug fix July 31 2023
functions.plot_agent_SVG = standard_agent_SVG;
functions.plot_agent_legend = standard_agent_legend;
// bug fix July 31 2023
functions.set_orientation = NULL;
// new March 2022 : make sure Cell_Interactions and Cell_Transformations
// are appropriately sized. Same on motiltiy.
phenotype.cell_interactions.sync_to_cell_definitions();
phenotype.cell_transformations.sync_to_cell_definitions();
phenotype.motility.sync_to_current_microenvironment();
phenotype.mechanics.sync_to_cell_definitions();
cell_definitions_by_index.push_back( this );
return;
}
Cell_Definition::Cell_Definition( Cell_Definition& cd )
{
// set the microenvironment pointer
pMicroenvironment = cd.pMicroenvironment;
// set up the default parameters
// the default Cell_Parameters constructor should take care of this
type = cd.type;
name = cd.name;
parameters = cd.parameters;
custom_data = cd.custom_data;
functions = cd.functions;
phenotype = cd.phenotype;
// this is the whole reason we need ot make a copy constructor
parameters.pReference_live_phenotype = &phenotype;
cell_definitions_by_index.push_back( this );
return;
}
Cell_Definition& Cell_Definition::operator=( const Cell_Definition& cd )
{
// set the microenvironment pointer
pMicroenvironment = cd.pMicroenvironment;
// set up the default parameters
// the default Cell_Parameters constructor should take care of this
type = cd.type;
name = cd.name;
parameters = cd.parameters;
custom_data = cd.custom_data;
functions = cd.functions;
phenotype = cd.phenotype;
// this is the whole reason we need ot make a copy constructor
parameters.pReference_live_phenotype = &phenotype;
// commented out on March 10, 2020
// cell_definitions_by_index.push_back( this );
return *this;
}
Cell_Definition cell_defaults;
Cell_State::Cell_State()
{
neighbors.resize(0);
spring_attachments.resize(0);
orientation.resize( 3 , 0.0 );
simple_pressure = 0.0;
attached_cells.clear();
spring_attachments.clear();
number_of_nuclei = 1;
// damage = 0.0;
total_attack_time = 0.0;
contact_with_basement_membrane = false;
return;
}
void Cell::update_motility_vector( double dt_ )
{
if( phenotype.motility.is_motile == false )
{
phenotype.motility.motility_vector.assign( 3, 0.0 );
return;
}
if( UniformRandom() < dt_ / phenotype.motility.persistence_time || phenotype.motility.persistence_time < dt_ )
{
/*
// choose a uniformly random unit vector
double temp_angle = 6.28318530717959*UniformRandom();
double temp_phi = 3.1415926535897932384626433832795*UniformRandom();
double sin_phi = sin(temp_phi);
double cos_phi = cos(temp_phi);
if( phenotype.motility.restrict_to_2D == true )
{
sin_phi = 1.0;
cos_phi = 0.0;
}
std::vector<double> randvec;
randvec.resize(3,sin_phi);
randvec[0] *= cos( temp_angle ); // cos(theta)*sin(phi)
randvec[1] *= sin( temp_angle ); // sin(theta)*sin(phi)
randvec[2] = cos_phi; // cos(phi)
*/
std::vector<double> randvec(3,0.0);
if( phenotype.motility.restrict_to_2D == true )
{ randvec = UniformOnUnitCircle(); }
else
{ randvec = UniformOnUnitSphere(); }
// if the update_bias_vector function is set, use it
if( functions.update_migration_bias )
{
functions.update_migration_bias( this,phenotype,dt_ );
}
phenotype.motility.motility_vector = phenotype.motility.migration_bias_direction; // motiltiy = bias_vector
phenotype.motility.motility_vector *= phenotype.motility.migration_bias; // motility = bias*bias_vector
double one_minus_bias = 1.0 - phenotype.motility.migration_bias;
axpy( &(phenotype.motility.motility_vector), one_minus_bias, randvec ); // motility = (1-bias)*randvec + bias*bias_vector
normalize( &(phenotype.motility.motility_vector) );
phenotype.motility.motility_vector *= phenotype.motility.migration_speed;
}
return;
}
void Cell::advance_bundled_phenotype_functions( double dt_ )
{
// New March 2022
// perform transformations
standard_cell_transformations( this,this->phenotype,dt_ );
// New March 2023 in Version 1.12.0
// call the rules-based code to update the phenotype
if( PhysiCell_settings.rules_enabled )
{ apply_ruleset( this ); }
if( get_single_signal(this,"necrotic") > 0.5 )
{
double rupture = this->phenotype.volume.rupture_volume;
double volume = this->phenotype.volume.total;
if( volume > rupture )
{
std::cout << this->phenotype.volume.total << " vs " << this->phenotype.volume.rupture_volume <<
" dead: " << get_single_signal( this, "dead") << std::endl;
std::cout << this->phenotype.cycle.current_phase_index() << " "
<< this->phenotype.cycle.pCycle_Model->name << std::endl;
}
}
// if( functions.update_phenotype )
// { functions.update_phenotype( this , phenotype , dt_ ); }
// call the custom code to update the phenotype
if( functions.update_phenotype )
{ functions.update_phenotype( this , phenotype , dt_ ); }
// update volume
if( functions.volume_update_function )
{
functions.volume_update_function(this,phenotype,dt_);
// The following line is needed in every volume
// regulation method (it sets BioFVM total_volume)
set_total_volume( phenotype.volume.total );
}
// update geometry
phenotype.geometry.update( this, phenotype, dt_ );
// update integrity
phenotype.cell_integrity.advance_damage( dt_ );
// check for new death events
if( phenotype.death.check_for_death( dt_ ) == true )
{
// if so, change the cycle model to the current death model
phenotype.cycle.sync_to_cycle_model( phenotype.death.current_model() );
// also, turn off motility.
phenotype.motility.is_motile = false;
phenotype.motility.motility_vector.assign( 3, 0.0 );
functions.update_migration_bias = NULL;
// turn off secretion, and reduce uptake by a factor of 10
phenotype.secretion.set_all_secretion_to_zero();
phenotype.secretion.scale_all_uptake_by_factor( 0.10 );
// make sure to run the death entry function
if( phenotype.cycle.current_phase().entry_function )
{
phenotype.cycle.current_phase().entry_function( this, phenotype, dt_ );
}
}
// advance cycle model (for both cell cycle and death cycle models)
phenotype.cycle.advance_cycle( this, phenotype, dt_ );
if( phenotype.flagged_for_removal )
{
flag_for_removal();
phenotype.flagged_for_removal = false;
}
if( phenotype.flagged_for_division )
{
flag_for_division();
phenotype.flagged_for_division = false;
}
return;
}
Cell::Cell()
{
// use the cell defaults;
type = cell_defaults.type;
type_name = cell_defaults.name;
custom_data = cell_defaults.custom_data;
parameters = cell_defaults.parameters;
functions = cell_defaults.functions;
phenotype = cell_defaults.phenotype;
phenotype.molecular.sync_to_cell( this );
// cell state should be fine by the default constructor
current_mechanics_voxel_index=-1;
updated_current_mechanics_voxel_index = 0;
is_movable = true;
is_out_of_domain = false;
displacement.resize(3,0.0); // state?
assign_orientation();
container = NULL;
set_total_volume( phenotype.volume.total );
return;
}
Cell::~Cell()
{
// std::cout << std::endl << "=====-----------------------------=====" << std::endl;
// std::cout << "\tcell destructor " << this << " " << type_name << " at " << position << std::endl;
// std::cout << "\t\tattached cells: " << this->state.attached_cells.size() << std::endl << std::endl;
auto result = std::find( std::begin(*all_cells),std::end(*all_cells),this );
if( result != std::end(*all_cells) )
{
std::cout << "Warning: Cell was never removed from data structure " << std::endl ;
std::cout << "I am of type " << this->type << " at " << this->position << std::endl;
int temp_index = -1;
bool found = false;
for( int n= 0 ; n < (*all_cells).size() ; n++ )
{
std::cout << this << " vs " << (*all_cells)[n] << std::endl;
if( (*all_cells)[n] == this )
{ found = true; temp_index = n; }
}
if( found )
{
// release any attached cells (as of 1.7.2 release)
this->remove_all_attached_cells();
// 1.11.0
this->remove_all_spring_attachments();
// new Dec 5, 2024:
this->remove_self_from_all_neighbors();
// released internalized substrates (as of 1.5.x releases)
this->release_internalized_substrates();
// performance goal: don't delete in the middle -- very expensive reallocation
// alternative: copy last element to index position, then shrink vector by 1 at the end O(constant)
// move last item to index location
(*all_cells)[ (*all_cells).size()-1 ]->index=temp_index;
(*all_cells)[temp_index] = (*all_cells)[ (*all_cells).size()-1 ];
// shrink the vector
(*all_cells).pop_back();
// deregister agent in from the agent container
this->get_container()->remove_agent(this);
}
}
return;
}
void Cell::flag_for_division( void )
{
get_container()->flag_cell_for_division( this );
return;
}
void Cell::flag_for_removal( void )
{
get_container()->flag_cell_for_removal( this );
return;
}
void Cell::start_death( int death_model_index )
{
// set the death data struture to the indicated death model
phenotype.death.trigger_death( death_model_index );
// change the cycle model to the current death model
phenotype.cycle.sync_to_cycle_model( phenotype.death.current_model() );
// turn off secretion, and reduce uptake by a factor of 10
phenotype.secretion.set_all_secretion_to_zero();
phenotype.secretion.scale_all_uptake_by_factor( 0.10 );
// turn off motility.
phenotype.motility.is_motile = false;
phenotype.motility.motility_vector.assign( 3, 0.0 );
functions.update_migration_bias = NULL;
// make sure to run the death entry function
if( phenotype.cycle.current_phase().entry_function )
{
phenotype.cycle.current_phase().entry_function( this, phenotype, 0.0 );
}
return;
}
void Cell::assign_orientation()
{
state.orientation.resize(3,0.0);
if( functions.set_orientation != NULL )
{
functions.set_orientation(this, phenotype, 0.0 );
}
else
{
//assign a random unit vector
double theta= UniformRandom()*6.28318530717959; //rand*2*pi
double z= 2* UniformRandom()-1;
double temp= sqrt(1-z*z);
state.orientation[0]= temp * cos(theta);
state.orientation[1]= temp * sin(theta);
state.orientation[2]= z;
}
return;
}
Cell* Cell::divide( )
{
// phenotype.flagged_for_division = false;
// phenotype.flagged_for_removal = false;
// make sure ot remove adhesions
remove_all_attached_cells();
remove_all_spring_attachments();
// version 1.10.3:
// conserved quantitites in custom data aer divided in half
// so that each daughter cell gets half of the original ;
for( int nn = 0 ; nn < custom_data.variables.size() ; nn++ )
{
if( custom_data.variables[nn].conserved_quantity == true )
{ custom_data.variables[nn].value *= 0.5; }
}
for( int nn = 0 ; nn < custom_data.vector_variables.size() ; nn++ )
{
if( custom_data.vector_variables[nn].conserved_quantity == true )
{ custom_data.vector_variables[nn].value *= 0.5; }
}
Cell* child = create_cell(functions.instantiate_cell);
child->copy_data( this );
child->copy_function_pointers(this);
child->parameters = parameters;
// evenly divide internalized substrates
// if these are not actively tracked, they are zero anyway
*internalized_substrates *= 0.5;
*(child->internalized_substrates) = *internalized_substrates ;
// The following is already performed by create_cell(). JULY 2017 ***
// child->register_microenvironment( get_microenvironment() );
// randomly place the new agent close to me, accounting for orientation and
// polarity (if assigned)
// May 30, 2020:
// Set cell_division_orientation = LegacyRandomOnUnitSphere to
// reproduce this code
/*
double temp_angle = 6.28318530717959*UniformRandom();
double temp_phi = 3.1415926535897932384626433832795*UniformRandom();
double radius= phenotype.geometry.radius;
std::vector<double> rand_vec (3, 0.0);
rand_vec[0]= cos( temp_angle ) * sin( temp_phi );
rand_vec[1]= sin( temp_angle ) * sin( temp_phi );
rand_vec[2]= cos( temp_phi );
rand_vec = rand_vec- phenotype.geometry.polarity*(rand_vec[0]*state.orientation[0]+
rand_vec[1]*state.orientation[1]+rand_vec[2]*state.orientation[2])*state.orientation;
if( norm(rand_vec) < 1e-16 )
{
std::cout<<"************ERROR********************"<<std::endl;
}
normalize( &rand_vec );
rand_vec *= radius; // multiply direction times the displacement
*/
std::vector<double> rand_vec = cell_division_orientation();
rand_vec = rand_vec- phenotype.geometry.polarity*(rand_vec[0]*state.orientation[0]+
rand_vec[1]*state.orientation[1]+rand_vec[2]*state.orientation[2])*state.orientation;
rand_vec *= phenotype.geometry.radius;
child->assign_position(position[0] + rand_vec[0],
position[1] + rand_vec[1],
position[2] + rand_vec[2]);
//change my position to keep the center of mass intact
// and then see if I need to update my voxel index
static double negative_one_half = -0.5;
axpy( &position, negative_one_half , rand_vec ); // position = position - 0.5*rand_vec;
//If this cell has been moved outside of the boundaries, mark it as such.
//(If the child cell is outside of the boundaries, that has been taken care of in the assign_position function.)
if( !get_container()->underlying_mesh.is_position_valid(position[0], position[1], position[2]))
{
is_out_of_domain = true;
is_active = false;
is_movable = false;
}
update_voxel_in_container();
phenotype.volume.divide();
child->phenotype.volume.divide();
child->set_total_volume(child->phenotype.volume.total);
set_total_volume(phenotype.volume.total);
// child->set_phenotype( phenotype );
child->phenotype = phenotype;
if (child->phenotype.intracellular){
child->phenotype.intracellular->start();
child->phenotype.intracellular->inherit(this);
}
// #ifdef ADDON_PHYSIDFBA
// child->fba_model = this->fba_model;
// #endif
// changes for new phenotyp March 2022
// state.damage = 0.0;
// phenotype.integrity.damage = 0.0; // leave alone - damage is heritable
state.total_attack_time = 0;
// child->state.damage = 0.0;
// child->phenotype.integrity.damage = 0.0; // leave alone - damage is heritable
child->state.total_attack_time = 0.0;
if( this->functions.cell_division_function )
{ this->functions.cell_division_function( this, child); }
return child;
}
bool Cell::assign_position(std::vector<double> new_position)
{
return assign_position(new_position[0], new_position[1], new_position[2]);
}
void Cell::set_previous_velocity(double xV, double yV, double zV)
{
previous_velocity[0] = xV;
previous_velocity[1] = yV;
previous_velocity[2] = zV;
return;
}
bool Cell::assign_position(double x, double y, double z)
{
position[0]=x;
position[1]=y;
position[2]=z;
// update microenvironment current voxel index
update_voxel_index();
// update current_mechanics_voxel_index
current_mechanics_voxel_index= get_container()->underlying_mesh.nearest_voxel_index( position );
// Since it is most likely our first position, we update the max_cell_interactive_distance_in_voxel
// which was not initialized at cell creation
if( get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()] <
phenotype.geometry.radius * phenotype.mechanics.relative_maximum_adhesion_distance )
{
// get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()]= phenotype.geometry.radius*parameters.max_interaction_distance_factor;
get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()] = phenotype.geometry.radius
* phenotype.mechanics.relative_maximum_adhesion_distance;
}
get_container()->register_agent(this);
if( !get_container()->underlying_mesh.is_position_valid(x,y,z) )
{
is_out_of_domain = true;
is_active = false;
is_movable = false;
return false;
}
return true;
}
void Cell::set_total_volume(double volume)
{
Basic_Agent::set_total_volume(volume);
// If the new volume is significantly different than the
// current total volume, adjust all the sub-volumes
// proportionally.
// if( fabs( phenotype.volume.total - volume ) < 1e-16 )
if( fabs( phenotype.volume.total - volume ) > 1e-16 )
{
double ratio= volume/ (phenotype.volume.total + 1e-16);
phenotype.volume.multiply_by_ratio(ratio);
}
phenotype.geometry.update( this, phenotype, 0.0 );
// phenotype.update_radius();
//if( get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()] <
// phenotype.geometry.radius * parameters.max_interaction_distance_factor )
// Here the current mechanics voxel index may not be initialized, when position is still unknown.
if (get_current_mechanics_voxel_index() >= 0)
{
if( get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()] <
phenotype.geometry.radius * phenotype.mechanics.relative_maximum_adhesion_distance )
{
// get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()]= phenotype.geometry.radius*parameters.max_interaction_distance_factor;
get_container()->max_cell_interactive_distance_in_voxel[get_current_mechanics_voxel_index()] = phenotype.geometry.radius
* phenotype.mechanics.relative_maximum_adhesion_distance;
}
}
return;
}
void Cell::set_target_volume( double new_volume )
{
// this function will keep the prior ratios (from targets)
// first compute the actual raw totals on all these things
double old_target_solid = phenotype.volume.target_solid_nuclear +
phenotype.volume.target_solid_cytoplasmic;
double old_target_total = old_target_solid / ( 1.0 - phenotype.volume.target_fluid_fraction );
double old_target_fluid = phenotype.volume.target_fluid_fraction * old_target_total;
// next whats the relative new size?
double ratio = new_volume / (1e-16 + old_target_total );
// scale the target solid cyto and target solid nuclear by this ratio
phenotype.volume.target_solid_cytoplasmic *= ratio;
phenotype.volume.target_solid_nuclear *= ratio;
return;
}
void Cell::set_target_radius(double new_radius )
{
static double four_thirds_pi = 4.188790204786391;
// calculate the new target volume
double new_volume = four_thirds_pi;
new_volume *= new_radius;
new_volume *= new_radius;
new_volume *= new_radius;
// now call the set_target_volume funciton
this->set_target_volume( new_volume );
return;
}
void Cell::set_radius(double new_radius )
{
static double four_thirds_pi = 4.188790204786391;
// calculate the new target volume
double new_volume = four_thirds_pi;
new_volume *= new_radius;
new_volume *= new_radius;
new_volume *= new_radius;
this->set_total_volume( new_volume );
return;
}
double& Cell::get_total_volume(void)
{
static bool I_warned_you = false;
if( I_warned_you == false )
{
std::cout << "Warning! Do not use " << __FUNCTION__ << "!" << std::endl
<< "Use (some_cell).phenotype.volume.total instead!" << std::endl;
I_warned_you = true;
}
return phenotype.volume.total;
}
void Cell::turn_off_reactions(double dt)
{
is_active = false;
for(int i=0;i< phenotype.secretion.uptake_rates.size();i++)
{
phenotype.secretion.uptake_rates[i] = 0.0;
phenotype.secretion.secretion_rates[i] = 0.0;
phenotype.secretion.net_export_rates[i] = 0.0;
}
set_internal_uptake_constants(dt);
return;
}
Cell_Container * Cell::get_container()
{
if(container == NULL)
{
container = (Cell_Container *)get_microenvironment()->agent_container;
}
return container;
}
void Cell::die()
{
delete_cell(this);
return;
}
void Cell::update_position( double dt )
{
// BioFVM Basic_Agent::update_position(dt) returns without doing anything.
// So we remove this to avoid any future surprises.
//
// Basic_Agent::update_position(dt);
// use Adams-Bashforth
static double d1;
static double d2;
static bool constants_defined = false;
if( constants_defined == false )
{
d1 = dt;
d1 *= 1.5;
d2 = dt;
d2 *= -0.5;
constants_defined = true;
}
// new AUgust 2017
if( default_microenvironment_options.simulate_2D == true )
{ velocity[2] = 0.0; }
std::vector<double> old_position(position);
axpy( &position , d1 , velocity );
axpy( &position , d2 , previous_velocity );
// overwrite previous_velocity for future use
// if(sqrt(dist(old_position, position))>3* phenotype.geometry.radius)
// std::cout<<sqrt(dist(old_position, position))<<"old_position: "<<old_position<<", new position: "<< position<<", velocity: "<<velocity<<", previous_velocity: "<< previous_velocity<<std::endl;
previous_velocity = velocity;
velocity[0]=0; velocity[1]=0; velocity[2]=0;
if(get_container()->underlying_mesh.is_position_valid(position[0],position[1],position[2]))
{
updated_current_mechanics_voxel_index=get_container()->underlying_mesh.nearest_voxel_index( position );
}
else
{
updated_current_mechanics_voxel_index=-1;
is_out_of_domain = true;
is_active = false;
is_movable = false;
}
return;
}
int Cell::get_current_mechanics_voxel_index()
{
return current_mechanics_voxel_index;
}
void Cell::update_voxel_in_container()
{
// call the method from BioFVM_basic_agent to update microenvironment's voxel index
update_voxel_index();
// int temp_current_voxel_index;
// Check to see if we need to remove agents that are pushed out of boundary
// if(!get_container()->underlying_mesh.is_position_valid(position[0],position[1],position[2]))
if(updated_current_mechanics_voxel_index==-1)// updated_current_mechanics_voxel_index is updated in update_position
{
// check if this agent has a valid voxel index, if so, remove it from previous voxel
if( get_current_mechanics_voxel_index() >= 0)
{
{get_container()->remove_agent_from_voxel(this, get_current_mechanics_voxel_index());}
}
{get_container()->add_agent_to_outer_voxel(this);}
// std::cout<<"cell out of boundary..."<< __LINE__<<" "<<ID<<std::endl;
current_mechanics_voxel_index=-1;
is_out_of_domain=true;
is_active=false;
return;
}
// temp_current_voxel_index= get_current_mechanics_voxel_index();
// updated_current_mechanics_voxel_index=get_container()->underlying_mesh.nearest_voxel_index( position );
// update mesh indices (if needed)
if(updated_current_mechanics_voxel_index!= get_current_mechanics_voxel_index())
{
{
container->remove_agent_from_voxel(this, get_current_mechanics_voxel_index());
container->add_agent_to_voxel(this, updated_current_mechanics_voxel_index);
}
current_mechanics_voxel_index=updated_current_mechanics_voxel_index;
}
return;
}
void Cell::copy_data(Cell* copy_me)
{
// phenotype=copyMe->phenotype; //it is taken care in set_phenotype
type = copy_me->type;
type_name = copy_me->type_name;
custom_data = copy_me->custom_data;
parameters = copy_me->parameters;
velocity = copy_me->velocity;
// expected_phenotype = copy_me-> expected_phenotype; //it is taken care in set_phenotype
cell_source_sink_solver_temp1 = std::vector<double>(copy_me->cell_source_sink_solver_temp1);
cell_source_sink_solver_temp2 = std::vector<double>(copy_me->cell_source_sink_solver_temp2);
return;
}
void Cell::copy_function_pointers(Cell* copy_me)
{
functions = copy_me->functions;
return;
}
void Cell::add_potentials(Cell* other_agent)
{
// if( this->ID == other_agent->ID )
if( this == other_agent )
{ return; }
/*
// new April 2022: don't interact with cells with 0 volume
// does not seem to really help
if( other_agent->phenotype.volume.total < 1e-15 )
{ std::cout << "zero size cell in mechanics!" << std::endl; return; }
*/
// 12 uniform neighbors at a close packing distance, after dividing out all constants
static double simple_pressure_scale = 0.027288820670331; // 12 * (1 - sqrt(pi/(2*sqrt(3))))^2
// 9.820170012151277; // 12 * ( 1 - sqrt(2*pi/sqrt(3)))^2
double distance = 0;
for( int i = 0 ; i < 3 ; i++ )
{
displacement[i] = position[i] - (*other_agent).position[i];
distance += displacement[i] * displacement[i];
}
// Make sure that the distance is not zero
distance = std::max(sqrt(distance), 0.00001);
//Repulsive
double R = phenotype.geometry.radius+ (*other_agent).phenotype.geometry.radius;
// double RN = phenotype.geometry.nuclear_radius + (*other_agent).phenotype.geometry.nuclear_radius;
double temp_r, c;
if( distance > R )
{
temp_r=0;
}
// else if( distance < RN )
// {
// double M = 1.0;
// c = 1.0 - RN/R;
// c *= c;
// c -= M;