for day in range(duration):
patient.cancer_cells = [cell for cell in patient.cancer_cells if cell.health > 0.1]
patient.stem_cells = [cell for cell in patient.stem_cells if cell.health > 0.1]
patient.b_cells = [cell for cell in patient.b_cells if cell.health > 0.1]
patient.wbc = [cell for cell in patient.wbc if cell.health > 0.1]
for cell in patient.cancer_cells + patient.stem_cells + patient.b_cells + patient.wbc:
cell.mutate()
for b_cell in patient.b_cells:
if patient.cancer_cells:
b_cell.attack(np.random.choice(patient.cancer_cells))
for wbc in patient.wbc:
if patient.cancer_cells:
wbc.attack(np.random.choice(patient.cancer_cells))
# Enhanced cancer cell targeting
cancer_growth_factor = max(0.05, 0.1 - 0.001 * day) # Decreasing growth rate over time
new_cancer_cells = [Cell("cancer", health=np.random.uniform(0.8, 1.2))
for _ in range(int(len(patient.cancer_cells) * cancer_growth_factor))]
patient.cancer_cells.extend(new_cancer_cells)
new_stem_cells = [Cell("stem", health=np.random.uniform(0.9, 1.1))
for _ in range(int(len(patient.stem_cells) * 0.05))]
patient.stem_cells.extend(new_stem_cells)
new_b_cells = [Cell("b_cell", efficacy=np.random.uniform(0.4, 0.6))
for _ in range(int(len(patient.b_cells) * 0.05))]
patient.b_cells.extend(new_b_cells)
new_wbc = [Cell("wbc", efficacy=np.random.uniform(0.3, 0.7))
for _ in range(int(len(patient.wbc) * 0.05))]
patient.wbc.extend(new_wbc)
if day % 7 == 0:
best_stem = clone_most_effective_cell(patient.stem_cells, "stem")
best_b = clone_most_effective_cell(patient.b_cells, "b_cell")
best_wbc = clone_most_effective_cell(patient.wbc, "wbc")
if best_stem: patient.stem_cells.append(best_stem)
if best_b: patient.b_cells.append(best_b)
if best_wbc: patient.wbc.append(best_wbc)
for treatment in treatments:
treatment.apply(patient, intensity=norm.pdf(day, loc=duration/2, scale=duration/6), day=day)
# Enhanced immune response
immune_efficacy = patient.immune_strength * (1 + 0.005 * day) # Increasing efficacy over time
patient.cancer_cells = [cell for cell in patient.cancer_cells
if np.random.random() > immune_efficacy * 0.02]
if patient.cancer_cells:
prob_elimination = 1 - np.prod([1 - (b.efficacy * immune_efficacy)
for b in patient.b_cells + patient.wbc])
else:
prob_elimination = 1.0
cancer_cell_counts.append(len(patient.cancer_cells))
stem_cell_counts.append(len(patient.stem_cells))
b_cell_counts.append(len(patient.b_cells))
wbc_counts.append(len(patient.wbc))
immune_strength.append(patient.immune_strength)
elimination_probability.append(prob_elimination)
return cancer_cell_counts, stem_cell_counts, b_cell_counts, wbc_counts, immune_strength, elimination_probability
Set up simulation with doubled efficacy for chemo, nanotherapy, and WBCs
import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm
class Cell: def init(self, cell_type, health=1.0, mutation_rate=0.001, efficacy=0.5): self.cell_type = cell_type self.health = health self.mutation_rate = mutation_rate self.efficacy = efficacy
class Patient: def init(self, id, age, cancer_type, genetic_risk): self.id = id self.age = age self.cancer_type = cancer_type self.genetic_risk = genetic_risk self.stemcells = [Cell("stem") for in range(1000)] self.cancercells = [Cell("cancer", health=np.random.uniform(0.5, 1.5)) for in range(100)] self.b_cells = [Cell("bcell", efficacy=np.random.uniform(0.4, 0.6)) for in range(500)] self.wbc = [Cell("wbc", efficacy=np.random.uniform(0.3, 0.7)) for _ in range(1000)] self.immune_strength = np.random.uniform(0.7, 1.0) self.treatment_sensitivity = np.random.uniform(0.8, 1.2)
class Treatment: def init(self, name, base_efficacy, side_effect_profile, immune_boost=0, synergy_factor=1.0): self.name = name self.base_efficacy = base_efficacy self.side_effect_profile = side_effect_profile self.immune_boost = immune_boost self.synergy_factor = synergy_factor
def clone_most_effective_cell(cells, cell_type): if not cells: return None most_effective = max(cells, key=lambda c: c.efficacy) return Cell(cell_type, health=most_effective.health, mutation_rate=most_effective.mutation_rate, efficacy=most_effective.efficacy)
def simulate_treatment_cycle(patient, treatments, duration): cancer_cell_counts = [] stem_cell_counts = [] b_cell_counts = [] wbc_counts = [] immune_strength = [] elimination_probability = []
Set up simulation with doubled efficacy for chemo, nanotherapy, and WBCs
patient = Patient(id="12345", age=50, cancer_type="lung", genetic_risk=0.2)
chemo = Treatment("Enhanced Chemotherapy", base_efficacy=1.4, side_effect_profile=0.4, synergy_factor=2.4) nano = Treatment("Enhanced Nanotherapy", base_efficacy=1.7, side_effect_profile=0.2, synergy_factor=2.6) stem_cell_boost = Treatment("Enhanced Stem Cell Therapy", base_efficacy=1.2, side_effect_profile=0.1, immune_boost=0.3)
Combine treatments into a list
treatments = [chemo, nano, stem_cell_boost] duration = 120 # Extended treatment duration for sustained therapy
Run simulation
cancer_cells, stem_cells, b_cells, wbc, immune_strength, elimination_probability = simulate_treatment_cycle(patient, treatments, duration)
Plot results
days = list(range(duration))
plt.figure(figsize=(14, 10))