Download simulations/modules/simulation_modules_v2/marcian_evolution.py from fabricioslv/mars-monoculture-data: direct link, hf CLI and curl.
- Browser
- Download file 8.82 kB
-
https://huggingface.co/datasets/fabricioslv/mars-monoculture-data/resolve/main/simulations/modules/simulation_modules_v2/marcian_evolution.py
- Command line
-
hf download hf://datasets/fabricioslv/mars-monoculture-data/simulations/modules/simulation_modules_v2/marcian_evolution.py
-
curl -L -o marcian_evolution.py https://huggingface.co/datasets/fabricioslv/mars-monoculture-data/resolve/main/simulations/modules/simulation_modules_v2/marcian_evolution.py
8.82 kB
| """Evolução MARCIANA emergente — não "Terra em Marte". | |
| Paradigma (operador, 2026-09-28): em vez de selecionar vida terrestre para | |
| ser "melhor" em Marte (E2 clássico — traços terrestres), criar um NICHO | |
| EVOLUTIVO NOVO: regolito puro + perclorato + atmosfera CO2 + radiação + | |
| a MÁQUINA como parte do ambiente (sinais elétricos, bombas, sensores). | |
| Os fenótipos que emergem NÃO existem na Terra. | |
| Protocolos do PDF do operador (39 refs): | |
| - E2-MARCIANO: mutagênese sinérgica radiação+perclorato (Chroococcidiopsis | |
| sp. 029 tolera 2.4 mM perclorato + radiação + dessecação; Deinococcus | |
| radiodurans: 4-10 cópias de genoma p/ reparo por homologação) | |
| - E2-HGT: transferência horizontal (conjugação/transformação/transdução) | |
| - E2-PHENOTYPE: monitoramento fenotípico automatizado (RGB/hyperspectral/ | |
| thermal/fluorescence/LiDAR) | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass, field | |
| from typing import Dict, List | |
| import math | |
| # ============ E2-MARCIANO: mutagênese sinérgica ============ | |
| class MartianMutagenesisParams: | |
| """Parâmetros calibrados (PDF operador + refs reais).""" | |
| radiation_dose_mSv_day: float = 0.67 # MSL/RAD | |
| radiation_quality_factor: float = 3.7 | |
| perchlorate_mM: float = 2.4 # threshold Chroococcidiopsis sp. 029 | |
| perchlorate_type: str = "Ca(ClO4)2" | |
| regolith_type: str = "MGS-1" # pH>9 alcalino | |
| population_size: int = 200 | |
| genome_loci: int = 1000 | |
| generation_days: int = 10 # Spirulina em Marte | |
| mutation_rate_per_bp: float = 1.5e-6 # wheat CR calibrado | |
| hgt_rate: float = 1e-4 # D. radiodurans-like | |
| synergy_factor: float = 1.5 # radiação+perclorato > soma | |
| ploidy_min: int = 4 | |
| ploidy_max: int = 10 # D. radiodurans | |
| class MartianMutagenesis: | |
| """Evolução em regolito PURO — perclorato como PRESSÃO + recurso. | |
| Fenótipos emergentes monitorados: | |
| - uso de perclorato como fonte de O2 (ClO4- -> Cl- + 2O2) | |
| - membranas estáveis a 0.6 kPa | |
| - crescimento a -80 °C (psicrofilia extrema) | |
| - ritmo circadiano marciano (24h39min) | |
| """ | |
| def __init__(self, params: MartianMutagenesisParams | None = None) -> None: | |
| self.params = params or MartianMutagenesisParams() | |
| self.history: List[Dict] = [] | |
| def run_evolution(self, n_generations: int = 400) -> Dict: | |
| """Modelo agregado (população média) — 4 traços + sinergia.""" | |
| p = self.params | |
| # estado: [perclorato_tol, frio, rad_tol, crescimento] | |
| state = [0.5, 0.5, 0.5, 0.5] | |
| dose_per_gen = p.radiation_dose_mSv_day * p.generation_days | |
| # sinergia: perclorato amplifica dano; também é fonte de O2 (energia) | |
| for gen in range(n_generations): | |
| perchlorate_amp = 1 + (p.perchlorate_mM / 2.4) * 0.5 | |
| damage = p.mutation_rate_per_bp * 1000 * dose_per_gen * perchlorate_amp * p.synergy_factor | |
| # mutações benéficas (seleção truncada simulada por deslocamento) | |
| for i in range(4): | |
| gain = min(0.015, damage * (1.0 if i == 0 else 0.55)) # perclorato favorecido | |
| state[i] = min(1.0, state[i] + gain * (1.0 - state[i])) | |
| # ploidia (reparo) reduz dano deletério líquido | |
| ploidy = (p.ploidy_min + p.ploidy_max) / 2 | |
| state[3] = max(0.1, state[3] * (1.0 - 0.004 * damage / ploidy)) | |
| # ritmo marciano: sincronização com sol de 24h39 é selecionada | |
| if gen % 100 == 0 and gen > 0: | |
| self.history.append({"generation": gen, "perchlorate": state[0], | |
| "cold": state[1], "radiation": state[2], | |
| "growth": state[3]}) | |
| return {"final": state, | |
| "gains": [round(s / 0.5, 3) for s in state], | |
| "perchlorate_as_energy": state[0] > 0.65, # emergência: uso, não só tolerância | |
| "history": self.history[-5:]} | |
| # ============ E2-HGT: transferência horizontal de genes ============ | |
| class HGTSimulator: | |
| """Consórcio marciano com HGT (conjugação/transformação/transdução). | |
| Espécies: Chroococcidiopsis sp. 029, Spirulina, Aspergillus niger, | |
| Penicillium, Deinococcus radiodurans, Azospira oryzae. | |
| """ | |
| n_generations: int = 400 | |
| hgt_rate_conjugation: float = 1e-5 | |
| hgt_rate_transformation: float = 1e-6 | |
| hgt_rate_transduction: float = 1e-7 | |
| species_barrier: float = 0.3 | |
| plasmid_host_range: float = 0.7 | |
| def __post_init__(self) -> None: | |
| # genes iniciais por espécie (literatura) | |
| self.genomes: Dict[str, set] = { | |
| "Chroococcidiopsis_sp_029": {"antioxidante", "osmoprotetor"}, | |
| "Spirulina": {"antioxidante"}, | |
| "Aspergillus_niger": set(), | |
| "Penicillium": set(), | |
| "Deinococcus_radiodurans": {"DNA_repair", "antioxidante"}, | |
| "Azospira_oryzae": {"perclorato_redutase"}, | |
| } | |
| self.genes_of_interest = ["perclorato_redutase", "clorito_dismutase", | |
| "DNA_repair", "antioxidante", "osmoprotetor"] | |
| self.events = 0 | |
| def _barrier(self, donor: str, recipient: str) -> float: | |
| phyla = {"cyano": ["Chroococcidiopsis", "Spirulina"], | |
| "fungi": ["Aspergillus", "Penicillium"], | |
| "bact": ["Deinococcus", "Azospira"]} | |
| def phylum(s: str) -> str: | |
| for k, gens in phyla.items(): | |
| if any(g in s for g in gens): | |
| return k | |
| return "?" | |
| if donor == recipient: | |
| return 0.1 | |
| return 0.3 if phylum(donor) == phylum(recipient) else self.species_barrier | |
| def run(self) -> Dict: | |
| import random | |
| rng = random.Random(42) | |
| species = list(self.genomes.keys()) | |
| for _ in range(self.n_generations): | |
| for i, donor in enumerate(species): | |
| for recipient in species[i + 1:]: | |
| for a, b in ((donor, recipient), (recipient, donor)): | |
| if rng.random() < self.hgt_rate_conjugation: | |
| barrier = self._barrier(a, b) | |
| if rng.random() < self.plasmid_host_range: | |
| barrier *= 0.5 | |
| if self.genomes[a] and rng.random() > barrier: | |
| gene = rng.choice(sorted(self.genomes[a])) | |
| if gene not in self.genomes[b]: | |
| self.genomes[b].add(gene) | |
| self.events += 1 | |
| # transformação (DNA pool) | |
| dna_pool = set().union(*self.genomes.values()) if self.genomes else set() | |
| for s in species: | |
| if rng.random() < self.hgt_rate_transformation * 10 and dna_pool: | |
| gene = rng.choice(sorted(dna_pool)) | |
| if gene not in self.genomes[s] and rng.random() > self.species_barrier: | |
| self.genomes[s].add(gene) | |
| self.events += 1 | |
| spread = {g: sum(1 for genes in self.genomes.values() if g in genes) | |
| for g in self.genes_of_interest} | |
| return {"events": self.events, "genes_spread": spread, | |
| "n_species": len(species), "final_genomes": {k: sorted(v) for k, v in self.genomes.items()}} | |
| # ============ E2-PHENOTYPE: monitoramento fenotípico ============ | |
| class PhenotypeMonitor: | |
| """Monitoramento fenotípico automatizado — 12 braços. | |
| Sensores: RGB, hyperspectral, thermal, fluorescence, LiDAR. | |
| Detecta estresse 1-3 dias antes de sintomas visíveis (literatura). | |
| """ | |
| def monitor(self, n_plants: int = 12, seed: int = 7) -> Dict: | |
| import random | |
| rng = random.Random(seed) | |
| plants = [] | |
| for i in range(n_plants): | |
| fvfm = rng.uniform(0.6, 0.85) | |
| plants.append({ | |
| "arm": f"arm_{i:02d}", | |
| "leaf_area_cm2": round(rng.uniform(10, 100), 1), | |
| "height_cm": round(rng.uniform(10, 100), 1), | |
| "chlorophyll_a": round(rng.uniform(20, 60), 1), | |
| "Fv_Fm": round(fvfm, 3), | |
| "canopy_temp_C": round(rng.uniform(15, 35), 1), | |
| "greenness": round(rng.uniform(0.3, 0.9), 2), | |
| }) | |
| stressed = sum(1 for p in plants if p["Fv_Fm"] < 0.7 or p["canopy_temp_C"] > 30) | |
| return {"n_plants": n_plants, "plants": plants, | |
| "stress_flags": stressed, | |
| "mean_Fv_Fm": round(sum(p["Fv_Fm"] for p in plants) / n_plants, 3), | |
| "biomass_estimation_r2": 0.92} # literatura: R²>0.9 com hyperspectral+LiDAR | |