diff --git a/meteor/diffmaps.py b/meteor/diffmaps.py index d905940..bfd3f85 100644 --- a/meteor/diffmaps.py +++ b/meteor/diffmaps.py @@ -6,12 +6,10 @@ import reciprocalspaceship as rs from .rsmap import Map, _assert_is_map -from .settings import MAP_SAMPLING +from .settings import DEFAULT_KPARAMS_TO_SCAN, MAP_SAMPLING from .utils import filter_common_indices from .validate import ScalarMaximizer, negentropy -DEFAULT_KPARAMS_TO_SCAN = np.linspace(0.0, 1.0, 101) - def set_common_crystallographic_metadata(map1: Map, map2: Map, *, output: Map) -> None: if hasattr(map1, "cell"): diff --git a/meteor/io.py b/meteor/io.py index 8a12a62..f89aa54 100644 --- a/meteor/io.py +++ b/meteor/io.py @@ -5,30 +5,14 @@ from __future__ import annotations import re -from typing import Final - -OBSERVED_INTENSITY_COLUMNS: Final[list[str]] = [ - "I", # generic - "IMEAN", # CCP4 - "I-obs", # phenix -] - -OBSERVED_AMPLITUDE_COLUMNS: Final[list[str]] = [ - "F", # generic - "FP", # CCP4 & GLPh native - r"FPH\d", # CCP4 derivative - "F-obs", # phenix -] - -OBSERVED_UNCERTAINTY_COLUMNS: Final[list[str]] = [ - "SIGF", # generic - "SIGFP", # CCP4 & GLPh native - r"SIGFPH\d", # CCP4 -] - -COMPUTED_AMPLITUDE_COLUMNS: Final[list[str]] = ["FC"] - -COMPUTED_PHASE_COLUMNS: Final[list[str]] = ["PHIC"] + +from .settings import ( + COMPUTED_AMPLITUDE_COLUMNS, + COMPUTED_PHASE_COLUMNS, + OBSERVED_AMPLITUDE_COLUMNS, + OBSERVED_INTENSITY_COLUMNS, + OBSERVED_UNCERTAINTY_COLUMNS, +) class AmbiguousMtzColumnError(ValueError): ... diff --git a/meteor/iterative.py b/meteor/iterative.py index 5e6bab7..4f08c9e 100644 --- a/meteor/iterative.py +++ b/meteor/iterative.py @@ -6,14 +6,13 @@ import pandas as pd from .rsmap import Map +from .settings import DEFAULT_TV_WEIGHTS_TO_SCAN_AT_EACH_ITERATION from .tv import TvDenoiseResult, tv_denoise_difference_map from .utils import ( average_phase_diff_in_degrees, complex_array_to_rs_dataseries, ) -DEFAULT_TV_WEIGHTS_TO_SCAN = [0.001, 0.01, 0.1, 1.0] - def _project_derivative_on_experimental_set( *, @@ -140,7 +139,7 @@ def iterative_tv_phase_retrieval( *, convergence_tolerance: float = 1e-4, max_iterations: int = 1000, - tv_weights_to_scan: list[float] = DEFAULT_TV_WEIGHTS_TO_SCAN, + tv_weights_to_scan: list[float] = DEFAULT_TV_WEIGHTS_TO_SCAN_AT_EACH_ITERATION, ) -> tuple[Map, pd.DataFrame]: """ Here is a brief pseudocode sketch of the alogrithm. Structure factors F below are complex unless diff --git a/meteor/settings.py b/meteor/settings.py index 279b4e6..b306012 100644 --- a/meteor/settings.py +++ b/meteor/settings.py @@ -1,12 +1,44 @@ from __future__ import annotations +import numpy as np + +# map computation +COMPUTED_MAP_RESOLUTION_LIMIT: float = 1.0 +GEMMI_HIGH_RESOLUTION_BUFFER: float = 1e-6 + + +# known map labels +OBSERVED_INTENSITY_COLUMNS: list[str] = [ + "I", # generic + "IMEAN", # CCP4 + "I-obs", # phenix +] +OBSERVED_AMPLITUDE_COLUMNS: list[str] = [ + "F", # generic + "FP", # CCP4 & GLPh native + r"FPH\d", # CCP4 derivative + "F-obs", # phenix +] +OBSERVED_UNCERTAINTY_COLUMNS: list[str] = [ + "SIGF", # generic + "SIGFP", # CCP4 & GLPh native + r"SIGFPH\d", # CCP4 +] +COMPUTED_AMPLITUDE_COLUMNS: list[str] = ["FC"] +COMPUTED_PHASE_COLUMNS: list[str] = ["PHIC"] + + +# k-weighting +KWEIGHT_PARAMETER_DEFAULT: float = 0.05 +DEFAULT_KPARAMS_TO_SCAN = np.linspace(0.0, 1.0, 101) + + +# tv denoising +TV_WEIGHT_DEFAULT: float = 0.01 BRACKET_FOR_GOLDEN_OPTIMIZATION: tuple[float, float] = (0.0, 0.05) TV_STOP_TOLERANCE: float = 0.00000005 TV_MAX_NUM_ITER: int = 50 MAP_SAMPLING: int = 3 -KWEIGHT_PARAMETER_DEFAULT: float = 0.05 -TV_WEIGHT_DEFAULT: float = 0.01 - -COMPUTED_MAP_RESOLUTION_LIMIT: float = 1.0 -GEMMI_HIGH_RESOLUTION_BUFFER: float = 1e-6 +# iterative tv +DEFAULT_TV_WEIGHTS_TO_SCAN_AT_EACH_ITERATION = [0.001, 0.01, 0.1, 1.0] diff --git a/test/unit/scripts/test_common.py b/test/unit/scripts/test_common.py index 230fcd4..a8e0237 100644 --- a/test/unit/scripts/test_common.py +++ b/test/unit/scripts/test_common.py @@ -51,7 +51,9 @@ def test_diffmap_set_scale(diffmap_set: DiffMapSet, use_uncertainties: bool) -> assert np.all(derivative_amps_before * 2 == diffmap_set.derivative["F"].to_numpy()) -def test_diffmap_argparser_parse_args(base_cli_arguments: list[str]) -> None: +def test_diffmap_argparser_parse_args( + base_cli_arguments: list[str], fixed_kparameter: float +) -> None: parser = DiffmapArgParser() args = parser.parse_args(base_cli_arguments) @@ -65,7 +67,7 @@ def test_diffmap_argparser_parse_args(base_cli_arguments: list[str]) -> None: assert args.mtzout == Path("fake-output.mtz") assert args.metadataout == Path("fake-output-metadata.csv") assert args.kweight_mode == WeightMode.fixed - assert args.kweight_parameter == 0.75 + assert args.kweight_parameter == fixed_kparameter def test_diffmap_argparser_check_output_filepaths(