From 858602fb03f8e9f49eb4dc8acd4c3087da7a33b6 Mon Sep 17 00:00:00 2001 From: Hanjin Liu Date: Sun, 30 Jun 2024 14:55:14 +0900 Subject: [PATCH] fix random seed problem --- cylindra/project/_layer_info.py | 12 ++++++++---- src/annealing/core.rs | 14 +++++++------- src/annealing/random.rs | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cylindra/project/_layer_info.py b/cylindra/project/_layer_info.py index 190c0890..4707b279 100644 --- a/cylindra/project/_layer_info.py +++ b/cylindra/project/_layer_info.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: + from acryo import Molecules from napari.layers import Layer from pydantic import BaseModel @@ -75,11 +76,9 @@ def from_layer( point_size=layer.point_size, ) - def to_layer(self, gui: "CylindraMainWidget", project_dir: Path): + def to_molecules(self, project_dir: Path) -> "Molecules": from acryo import Molecules - from cylindra._napari import MoleculesLayer - path = project_dir / self.name if not path.exists(): warnings.warn( @@ -88,7 +87,12 @@ def to_layer(self, gui: "CylindraMainWidget", project_dir: Path): stacklevel=2, ) return - mole = Molecules.from_file(path) + return Molecules.from_file(path) + + def to_layer(self, gui: "CylindraMainWidget", project_dir: Path): + from cylindra._napari import MoleculesLayer + + mole = self.to_molecules(project_dir) if self.source is not None: src = gui.tomogram.splines[self.source] diff --git a/src/annealing/core.rs b/src/annealing/core.rs index 5fa421be..25ffa036 100644 --- a/src/annealing/core.rs +++ b/src/annealing/core.rs @@ -276,14 +276,14 @@ impl CylindricAnnealingModel { reject_count = 0; } else { reject_count += 1; - } - if reject_count > self.reject_limit { - if self.graph.energy() == std::f32::INFINITY { - self.optimization_state = OptimizationState::Failed; - } else { - self.optimization_state = OptimizationState::Converged; + if reject_count > self.reject_limit { + if self.graph.energy() == std::f32::INFINITY { + self.optimization_state = OptimizationState::Failed; + } else { + self.optimization_state = OptimizationState::Converged; + } + break; } - break; } self.iteration += 1; self.reservoir.cool(self.iteration); diff --git a/src/annealing/random.rs b/src/annealing/random.rs index 6a93baa6..a364cbce 100644 --- a/src/annealing/random.rs +++ b/src/annealing/random.rs @@ -56,7 +56,7 @@ impl Clone for RandomNumberGenerator { } } -const BUF: usize = 1; +const BUF: usize = 2; const SCALE: f32 = (1 << (24 - BUF)) as f32; impl RandomNumberGenerator {