1use super::dna_structures::DnaDataStructure;
4use crate::error::OxirsResult;
5
6#[derive(Debug, Clone)]
8pub struct CellularDivision {
9 pub mitotic_apparatus: MitoticApparatus,
11 pub checkpoint_system: CheckpointSystem,
13 pub cycle_state: CellCycleState,
15 pub dna_content: Vec<DnaDataStructure>,
17}
18
19#[derive(Debug, Clone)]
21pub struct MitoticApparatus {
22 pub centrosomes: (Centrosome, Centrosome),
24 pub spindle_apparatus: SpindleApparatus,
26 pub kinetochores: Vec<Kinetochore>,
28 pub division_state: DivisionState,
30}
31
32#[derive(Debug, Clone)]
34pub struct SpindleApparatus {
35 pub kinetochore_microtubules: Vec<Microtubule>,
37 pub polar_microtubules: Vec<Microtubule>,
39 pub astral_microtubules: Vec<Microtubule>,
41 pub poles: (SpindlePole, SpindlePole),
43}
44
45#[derive(Debug, Clone)]
47pub struct Centrosome {
48 pub centrioles: (Centriole, Centriole),
50 pub pericentriolar_material: PericentriolarMaterial,
52 pub position: Position3D,
54}
55
56#[derive(Debug, Clone)]
58pub struct Centriole {
59 pub barrel: BarrelStructure,
61 pub triplets: Vec<TripletMicrotubule>,
63 pub orientation: Orientation,
65}
66
67#[derive(Debug, Clone)]
69pub struct BarrelStructure {
70 pub diameter: f64,
72 pub length: f64,
74 pub wall_thickness: f64,
76}
77
78#[derive(Debug, Clone)]
80pub struct TripletMicrotubule {
81 pub a_tubule: Microtubule,
83 pub b_tubule: Microtubule,
85 pub c_tubule: Microtubule,
87}
88
89#[derive(Debug, Clone)]
91pub struct Microtubule {
92 pub protofilaments: Vec<Protofilament>,
94 pub length: f64,
96 pub dynamic_state: DynamicState,
98 pub plus_end: MicrotubuleEnd,
100 pub minus_end: MicrotubuleEnd,
102}
103
104#[derive(Debug, Clone)]
106pub struct Protofilament {
107 pub tubulin_dimers: Vec<TubulinDimer>,
109 pub lateral_bonds: Vec<LateralBond>,
111}
112
113#[derive(Debug, Clone)]
115pub struct TubulinDimer {
116 pub alpha_tubulin: AlphaTubulin,
118 pub beta_tubulin: BetaTubulin,
120 pub nucleotide_state: NucleotideState,
122}
123
124#[derive(Debug, Clone)]
126pub struct AlphaTubulin {
127 pub molecular_weight: f64,
129 pub conformation: TubulinConformation,
131}
132
133#[derive(Debug, Clone)]
135pub struct BetaTubulin {
136 pub molecular_weight: f64,
138 pub conformation: TubulinConformation,
140 pub gtp_binding_site: GtpBindingSite,
142}
143
144#[derive(Debug, Clone)]
146pub struct CheckpointSystem {
147 pub spindle_checkpoint: SpindleCheckpoint,
149 pub dna_damage_checkpoint: DnaDamageCheckpoint,
151 pub replication_checkpoint: ReplicationCheckpoint,
153}
154
155#[derive(Debug, Clone)]
157pub struct SpindleCheckpoint {
158 pub mad_proteins: Vec<MadProtein>,
160 pub bub_proteins: Vec<BubProtein>,
162 pub apc_c_regulation: ApcCRegulation,
164}
165
166#[derive(Debug, Clone)]
168pub struct MadProtein {
169 pub protein_type: MadProteinType,
171 pub activity_level: f64,
173 pub localization: ProteinLocalization,
175}
176
177#[derive(Debug, Clone)]
179pub struct BubProtein {
180 pub protein_type: BubProteinType,
182 pub activity_level: f64,
184 pub kinetochore_binding: bool,
186}
187
188#[derive(Debug, Clone)]
190pub struct ApcCRegulation {
191 pub cdc20_level: f64,
193 pub cdh1_level: f64,
195 pub activity_state: ApcCActivityState,
197}
198
199#[derive(Debug, Clone)]
201pub enum CellCycleState {
202 G1,
203 S,
204 G2,
205 M(MitosisPhase),
206}
207
208#[derive(Debug, Clone)]
209pub enum MitosisPhase {
210 Prophase,
211 Prometaphase,
212 Metaphase,
213 Anaphase(AnaphaseStage),
214 Telophase,
215}
216
217#[derive(Debug, Clone)]
218pub enum AnaphaseStage {
219 A, B, }
222
223#[derive(Debug, Clone)]
224pub enum DivisionState {
225 Interphase,
226 Mitosis(MitosisPhase),
227 Cytokinesis,
228}
229
230#[derive(Debug, Clone)]
231pub struct Position3D {
232 pub x: f64,
233 pub y: f64,
234 pub z: f64,
235}
236
237#[derive(Debug, Clone)]
238pub struct Orientation {
239 pub angle: f64,
240 pub axis: Vec3D,
241}
242
243#[derive(Debug, Clone)]
244pub struct Vec3D {
245 pub x: f64,
246 pub y: f64,
247 pub z: f64,
248}
249
250#[derive(Debug, Clone)]
251pub enum DynamicState {
252 Growing,
253 Shrinking,
254 Paused,
255}
256
257#[derive(Debug, Clone)]
258pub struct MicrotubuleEnd {
259 pub cap_structure: CapStructure,
260 pub growth_rate: f64,
261}
262
263#[derive(Debug, Clone)]
264pub enum CapStructure {
265 GtpCap,
266 GdpCap,
267 Frayed,
268}
269
270#[derive(Debug, Clone)]
271pub struct LateralBond {
272 pub strength: f64,
273 pub bond_type: BondType,
274}
275
276#[derive(Debug, Clone)]
277pub enum BondType {
278 Hydrogen,
279 VanDerWaals,
280 Electrostatic,
281}
282
283#[derive(Debug, Clone)]
284#[allow(clippy::upper_case_acronyms)]
285pub enum NucleotideState {
286 GTP,
287 GDP,
288}
289
290#[derive(Debug, Clone)]
291pub enum TubulinConformation {
292 Straight,
293 Curved,
294 Intermediate(f64),
295}
296
297#[derive(Debug, Clone)]
298pub struct GtpBindingSite {
299 pub occupied: bool,
300 pub binding_affinity: f64,
301}
302
303#[derive(Debug, Clone)]
304pub struct SpindlePole {
305 pub centrosome: Centrosome,
306 pub microtubule_nucleation_sites: Vec<NucleationSite>,
307}
308
309#[derive(Debug, Clone)]
310pub struct NucleationSite {
311 pub gamma_tubulin_complex: GammaTubulinComplex,
312 pub activity: f64,
313}
314
315#[derive(Debug, Clone)]
316pub struct GammaTubulinComplex {
317 pub gamma_tubulin_count: usize,
318 pub associated_proteins: Vec<String>,
319}
320
321#[derive(Debug, Clone)]
322pub struct Kinetochore {
323 pub chromosome_attachment: bool,
324 pub microtubule_attachments: Vec<MicrotubuleAttachment>,
325 pub tension: f64,
326}
327
328#[derive(Debug, Clone)]
329pub struct MicrotubuleAttachment {
330 pub microtubule_id: String,
331 pub attachment_strength: f64,
332 pub attachment_type: AttachmentType,
333}
334
335#[derive(Debug, Clone)]
336pub enum AttachmentType {
337 Amphitelic, Syntelic, Merotelic, Monotelic, }
342
343#[derive(Debug, Clone)]
344pub struct PericentriolarMaterial {
345 pub gamma_tubulin: f64,
346 pub pericentrin: f64,
347 pub ninein: f64,
348}
349
350#[derive(Debug, Clone)]
351pub struct DnaDamageCheckpoint {
352 pub atm_activity: f64,
353 pub atr_activity: f64,
354 pub p53_level: f64,
355}
356
357#[derive(Debug, Clone)]
358pub struct ReplicationCheckpoint {
359 pub replication_forks: Vec<ReplicationFork>,
360 pub checkpoint_active: bool,
361}
362
363#[derive(Debug, Clone)]
364pub struct ReplicationFork {
365 pub position: usize,
366 pub stalled: bool,
367 pub proteins: Vec<String>,
368}
369
370#[derive(Debug, Clone)]
371pub enum MadProteinType {
372 Mad1,
373 Mad2,
374 Mad3,
375}
376
377#[derive(Debug, Clone)]
378pub enum BubProteinType {
379 Bub1,
380 Bub3,
381 BubR1,
382}
383
384#[derive(Debug, Clone)]
385pub enum ProteinLocalization {
386 Kinetochore,
387 SpindlePole,
388 Cytoplasm,
389 Nucleus,
390}
391
392#[derive(Debug, Clone)]
393pub enum ApcCActivityState {
394 Active,
395 Inactive,
396 PartiallyActive(f64),
397}
398
399impl CellularDivision {
400 pub fn new() -> Self {
402 Self {
403 mitotic_apparatus: MitoticApparatus::new(),
404 checkpoint_system: CheckpointSystem::new(),
405 cycle_state: CellCycleState::G1,
406 dna_content: Vec::new(),
407 }
408 }
409
410 pub fn initiate_division(&mut self) -> OxirsResult<()> {
412 self.progress_to_mitosis()?;
414 self.execute_mitosis()?;
415 self.complete_division()?;
416 Ok(())
417 }
418
419 fn progress_to_mitosis(&mut self) -> OxirsResult<()> {
421 match self.cycle_state {
422 CellCycleState::G1 => {
423 self.cycle_state = CellCycleState::S;
424 self.replicate_dna()?;
426 self.cycle_state = CellCycleState::G2;
427 }
428 CellCycleState::G2 if self.checkpoint_system.check_dna_integrity()? => {
429 self.cycle_state = CellCycleState::M(MitosisPhase::Prophase);
431 }
432 _ => {
433 }
435 }
436 Ok(())
437 }
438
439 fn execute_mitosis(&mut self) -> OxirsResult<()> {
441 let current_phase = if let CellCycleState::M(ref phase) = self.cycle_state {
443 phase.clone()
444 } else {
445 return Ok(());
446 };
447
448 let new_phase = match current_phase {
449 MitosisPhase::Prophase => {
450 self.mitotic_apparatus.prepare_spindle()?;
451 MitosisPhase::Prometaphase
452 }
453 MitosisPhase::Prometaphase => {
454 self.mitotic_apparatus.attach_chromosomes()?;
455 MitosisPhase::Metaphase
456 }
457 MitosisPhase::Metaphase => {
458 if self
459 .checkpoint_system
460 .spindle_checkpoint
461 .check_alignment()?
462 {
463 MitosisPhase::Anaphase(AnaphaseStage::A)
464 } else {
465 MitosisPhase::Metaphase
466 }
467 }
468 MitosisPhase::Anaphase(stage) => match stage {
469 AnaphaseStage::A => {
470 self.separate_chromosomes()?;
471 MitosisPhase::Anaphase(AnaphaseStage::B)
472 }
473 AnaphaseStage::B => {
474 self.elongate_spindle()?;
475 MitosisPhase::Telophase
476 }
477 },
478 MitosisPhase::Telophase => {
479 self.reform_nuclei()?;
480 self.cycle_state = CellCycleState::G1;
481 return Ok(());
482 }
483 };
484
485 if let CellCycleState::M(ref mut phase) = self.cycle_state {
487 *phase = new_phase;
488 }
489
490 Ok(())
491 }
492
493 fn complete_division(&mut self) -> OxirsResult<()> {
495 self.mitotic_apparatus.reset()?;
497
498 let (daughter1, _daughter2) = self.distribute_dna_content()?;
500
501 self.dna_content = daughter1;
503
504 Ok(())
505 }
506
507 fn replicate_dna(&mut self) -> OxirsResult<()> {
509 let mut replicated = Vec::new();
510
511 for dna in &self.dna_content {
512 let mut copy = dna.clone();
513 copy.replication_machinery
515 .replicate_strand(&dna.primary_strand)?;
516 replicated.push(copy);
517 }
518
519 self.dna_content.extend(replicated);
520 Ok(())
521 }
522
523 fn separate_chromosomes(&mut self) -> OxirsResult<()> {
525 for kinetochore in &mut self.mitotic_apparatus.kinetochores {
527 kinetochore.tension = 0.0; for attachment in &mut kinetochore.microtubule_attachments {
531 if matches!(attachment.attachment_type, AttachmentType::Amphitelic) {
532 attachment.attachment_strength *= 0.5; }
534 }
535 }
536 Ok(())
537 }
538
539 fn elongate_spindle(&mut self) -> OxirsResult<()> {
541 for microtubule in &mut self.mitotic_apparatus.spindle_apparatus.polar_microtubules {
543 microtubule.length *= 1.5; microtubule.dynamic_state = DynamicState::Growing;
545 }
546 Ok(())
547 }
548
549 fn reform_nuclei(&mut self) -> OxirsResult<()> {
551 Ok(())
554 }
555
556 fn distribute_dna_content(
558 &self,
559 ) -> OxirsResult<(Vec<DnaDataStructure>, Vec<DnaDataStructure>)> {
560 let midpoint = self.dna_content.len() / 2;
561 let daughter1 = self.dna_content[..midpoint].to_vec();
562 let daughter2 = self.dna_content[midpoint..].to_vec();
563 Ok((daughter1, daughter2))
564 }
565
566 pub fn add_dna_content(&mut self, dna: DnaDataStructure) {
568 self.dna_content.push(dna);
569 }
570
571 pub fn current_state(&self) -> &CellCycleState {
573 &self.cycle_state
574 }
575}
576
577impl Default for MitoticApparatus {
578 fn default() -> Self {
579 Self::new()
580 }
581}
582
583impl MitoticApparatus {
584 pub fn new() -> Self {
586 Self {
587 centrosomes: (Centrosome::new(), Centrosome::new()),
588 spindle_apparatus: SpindleApparatus::new(),
589 kinetochores: Vec::new(),
590 division_state: DivisionState::Interphase,
591 }
592 }
593
594 pub fn prepare_spindle(&mut self) -> OxirsResult<()> {
596 self.division_state = DivisionState::Mitosis(MitosisPhase::Prophase);
597
598 self.centrosomes.0.position = Position3D {
600 x: -10.0,
601 y: 0.0,
602 z: 0.0,
603 };
604 self.centrosomes.1.position = Position3D {
605 x: 10.0,
606 y: 0.0,
607 z: 0.0,
608 };
609
610 self.spindle_apparatus.nucleate_microtubules()?;
612
613 Ok(())
614 }
615
616 pub fn attach_chromosomes(&mut self) -> OxirsResult<()> {
618 for i in 0..10 {
620 let kinetochore = Kinetochore {
622 chromosome_attachment: true,
623 microtubule_attachments: vec![MicrotubuleAttachment {
624 microtubule_id: format!("mt_{i}"),
625 attachment_strength: 1.0,
626 attachment_type: AttachmentType::Amphitelic,
627 }],
628 tension: 0.5,
629 };
630 self.kinetochores.push(kinetochore);
631 }
632 Ok(())
633 }
634
635 pub fn reset(&mut self) -> OxirsResult<()> {
637 self.division_state = DivisionState::Interphase;
638 self.kinetochores.clear();
639 self.spindle_apparatus = SpindleApparatus::new();
640 Ok(())
641 }
642}
643
644impl Default for SpindleApparatus {
645 fn default() -> Self {
646 Self::new()
647 }
648}
649
650impl SpindleApparatus {
651 pub fn new() -> Self {
653 Self {
654 kinetochore_microtubules: Vec::new(),
655 polar_microtubules: Vec::new(),
656 astral_microtubules: Vec::new(),
657 poles: (SpindlePole::new(), SpindlePole::new()),
658 }
659 }
660
661 pub fn nucleate_microtubules(&mut self) -> OxirsResult<()> {
663 for i in 0..20 {
665 let microtubule = Microtubule::new(format!("kt_mt_{i}"));
666 self.kinetochore_microtubules.push(microtubule);
667 }
668
669 for i in 0..10 {
670 let microtubule = Microtubule::new(format!("polar_mt_{i}"));
671 self.polar_microtubules.push(microtubule);
672 }
673
674 for i in 0..15 {
675 let microtubule = Microtubule::new(format!("astral_mt_{i}"));
676 self.astral_microtubules.push(microtubule);
677 }
678
679 Ok(())
680 }
681}
682
683impl Default for CheckpointSystem {
684 fn default() -> Self {
685 Self::new()
686 }
687}
688
689impl CheckpointSystem {
690 pub fn new() -> Self {
692 Self {
693 spindle_checkpoint: SpindleCheckpoint::new(),
694 dna_damage_checkpoint: DnaDamageCheckpoint::new(),
695 replication_checkpoint: ReplicationCheckpoint::new(),
696 }
697 }
698
699 pub fn check_dna_integrity(&self) -> OxirsResult<bool> {
701 let damage_level =
702 self.dna_damage_checkpoint.atm_activity + self.dna_damage_checkpoint.atr_activity;
703 Ok(damage_level < 0.1) }
705}
706
707impl Default for SpindleCheckpoint {
708 fn default() -> Self {
709 Self::new()
710 }
711}
712
713impl SpindleCheckpoint {
714 pub fn new() -> Self {
716 Self {
717 mad_proteins: vec![
718 MadProtein {
719 protein_type: MadProteinType::Mad1,
720 activity_level: 1.0,
721 localization: ProteinLocalization::Kinetochore,
722 },
723 MadProtein {
724 protein_type: MadProteinType::Mad2,
725 activity_level: 1.0,
726 localization: ProteinLocalization::Kinetochore,
727 },
728 ],
729 bub_proteins: vec![
730 BubProtein {
731 protein_type: BubProteinType::Bub1,
732 activity_level: 1.0,
733 kinetochore_binding: true,
734 },
735 BubProtein {
736 protein_type: BubProteinType::Bub3,
737 activity_level: 1.0,
738 kinetochore_binding: true,
739 },
740 ],
741 apc_c_regulation: ApcCRegulation {
742 cdc20_level: 0.5,
743 cdh1_level: 0.1,
744 activity_state: ApcCActivityState::Inactive,
745 },
746 }
747 }
748
749 pub fn check_alignment(&self) -> OxirsResult<bool> {
751 let mad_activity: f64 = self.mad_proteins.iter().map(|p| p.activity_level).sum();
753 Ok(mad_activity < 0.5)
754 }
755}
756
757impl Default for Centrosome {
759 fn default() -> Self {
760 Self::new()
761 }
762}
763
764impl Centrosome {
765 pub fn new() -> Self {
766 Self {
767 centrioles: (Centriole::new(), Centriole::new()),
768 pericentriolar_material: PericentriolarMaterial {
769 gamma_tubulin: 1.0,
770 pericentrin: 1.0,
771 ninein: 1.0,
772 },
773 position: Position3D {
774 x: 0.0,
775 y: 0.0,
776 z: 0.0,
777 },
778 }
779 }
780}
781
782impl Default for Centriole {
783 fn default() -> Self {
784 Self::new()
785 }
786}
787
788impl Centriole {
789 pub fn new() -> Self {
790 Self {
791 barrel: BarrelStructure {
792 diameter: 0.2,
793 length: 0.5,
794 wall_thickness: 0.02,
795 },
796 triplets: Vec::new(),
797 orientation: Orientation {
798 angle: 0.0,
799 axis: Vec3D {
800 x: 0.0,
801 y: 0.0,
802 z: 1.0,
803 },
804 },
805 }
806 }
807}
808
809impl Microtubule {
810 pub fn new(_id: String) -> Self {
811 Self {
812 protofilaments: Vec::new(),
813 length: 10.0,
814 dynamic_state: DynamicState::Growing,
815 plus_end: MicrotubuleEnd {
816 cap_structure: CapStructure::GtpCap,
817 growth_rate: 1.0,
818 },
819 minus_end: MicrotubuleEnd {
820 cap_structure: CapStructure::GdpCap,
821 growth_rate: 0.0,
822 },
823 }
824 }
825}
826
827impl Default for SpindlePole {
828 fn default() -> Self {
829 Self::new()
830 }
831}
832
833impl SpindlePole {
834 pub fn new() -> Self {
835 Self {
836 centrosome: Centrosome::new(),
837 microtubule_nucleation_sites: Vec::new(),
838 }
839 }
840}
841
842impl Default for DnaDamageCheckpoint {
843 fn default() -> Self {
844 Self::new()
845 }
846}
847
848impl DnaDamageCheckpoint {
849 pub fn new() -> Self {
850 Self {
851 atm_activity: 0.0,
852 atr_activity: 0.0,
853 p53_level: 0.1,
854 }
855 }
856}
857
858impl Default for ReplicationCheckpoint {
859 fn default() -> Self {
860 Self::new()
861 }
862}
863
864impl ReplicationCheckpoint {
865 pub fn new() -> Self {
866 Self {
867 replication_forks: Vec::new(),
868 checkpoint_active: false,
869 }
870 }
871}
872
873impl Default for CellularDivision {
874 fn default() -> Self {
875 Self::new()
876 }
877}
878
879#[cfg(test)]
880mod tests {
881 use super::*;
882
883 #[test]
884 fn test_cellular_division_creation() {
885 let division = CellularDivision::new();
886 assert!(matches!(division.cycle_state, CellCycleState::G1));
887 assert_eq!(division.dna_content.len(), 0);
888 }
889
890 #[test]
891 fn test_mitotic_apparatus() {
892 let apparatus = MitoticApparatus::new();
893 assert!(matches!(
894 apparatus.division_state,
895 DivisionState::Interphase
896 ));
897 assert_eq!(apparatus.kinetochores.len(), 0);
898 }
899
900 #[test]
901 fn test_checkpoint_system() {
902 let checkpoint = CheckpointSystem::new();
903 assert!(checkpoint
904 .check_dna_integrity()
905 .expect("operation should succeed"));
906 }
907}