Skip to content

Commit

Permalink
pool settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Oct 28, 2024
1 parent 5416648 commit 08b88d6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 37 deletions.
4 changes: 1 addition & 3 deletions meteor/diffmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
32 changes: 8 additions & 24 deletions meteor/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand Down
5 changes: 2 additions & 3 deletions meteor/iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
*,
Expand Down Expand Up @@ -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
Expand Down
42 changes: 37 additions & 5 deletions meteor/settings.py
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 4 additions & 2 deletions test/unit/scripts/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down

0 comments on commit 08b88d6

Please sign in to comment.