Spaces:
Running
Running
Update core/evolution/evolution.py
Browse files- core/evolution/evolution.py +25 -0
core/evolution/evolution.py
CHANGED
|
@@ -157,6 +157,31 @@ class MolecularEvolution:
|
|
| 157 |
self._log_generation_stats(gen)
|
| 158 |
|
| 159 |
survivors = self.population.get_survivors()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
offspring = self._generate_offspring(survivors)
|
| 161 |
|
| 162 |
# Create new population
|
|
|
|
| 157 |
self._log_generation_stats(gen)
|
| 158 |
|
| 159 |
survivors = self.population.get_survivors()
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
sample_smiles = []
|
| 163 |
+
if survivors:
|
| 164 |
+
# best survivor (matches CLI optimisation logic)
|
| 165 |
+
if self.config.maximize_cn:
|
| 166 |
+
best = max(survivors, key=lambda m: m.cn)
|
| 167 |
+
else:
|
| 168 |
+
best = min(survivors, key=lambda m: m.cn_error)
|
| 169 |
+
sample_smiles.append(best.smiles)
|
| 170 |
+
|
| 171 |
+
# a few random other survivors (small, illustrative)
|
| 172 |
+
k = min(3, len(survivors))
|
| 173 |
+
sample_smiles.extend([m.smiles for m in random.sample(survivors, k)])
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
# remove duplicates while keeping order
|
| 177 |
+
sample_smiles = list(dict.fromkeys(sample_smiles))
|
| 178 |
+
|
| 179 |
+
self.history.append({
|
| 180 |
+
"generation": gen,
|
| 181 |
+
"smiles": sample_smiles
|
| 182 |
+
})
|
| 183 |
+
|
| 184 |
+
|
| 185 |
offspring = self._generate_offspring(survivors)
|
| 186 |
|
| 187 |
# Create new population
|