Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Nov 20, 2024
1 parent 1fc0aa4 commit 956e36f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/dials/algorithms/correlation/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
source=iotbx.phil.parse(
"""\
cc_weights=sigma
weights=standard_error
weights=count
"""
)
)
Expand Down Expand Up @@ -150,8 +150,8 @@ def __init__(
# If dimensions are optimised for clustering, need cc_weights=sigma
# Otherwise results end up being nonsensical even for high-quality data
# Outlier rejection was also found to be beneficial for optimising clustering dimensionality
if self.params.dimensions is Auto and self.params.cc_weights != "sigma":
raise ValueError("To optimise dimensions, cc_weights=sigma is required.")
# if self.params.dimensions is Auto and self.params.cc_weights != "sigma":
# raise ValueError("To optimise dimensions, cc_weights=sigma is required.")

self.cosym_analysis = CosymAnalysis(self.datasets, self.params)

Expand Down
2 changes: 1 addition & 1 deletion src/dials/algorithms/symmetry/cosym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
.type = bool
.short_caption = "Use curvatures"
weights = count standard_error
weights = *count standard_error
.type = choice
.short_caption = "Weights"
.help = "If not None, a weights matrix is used in the cosym procedure."
Expand Down
4 changes: 2 additions & 2 deletions src/dials/algorithms/symmetry/cosym/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def minimize_scitbx_lbfgs(
max_iterations=max_iterations,
max_calls=max_calls,
traditional_convergence_test=True,
traditional_convergence_test_eps=1,
traditional_convergence_test_eps=0.001,
drop_convergence_test_n_test_points=5,
drop_convergence_test_max_drop_eps=1.0e-5,
drop_convergence_test_max_drop_eps=1e-7,
drop_convergence_test_iteration_coefficient=2,
)
result = lbfgs_with_curvs(
Expand Down
27 changes: 25 additions & 2 deletions src/dials/algorithms/symmetry/cosym/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _compute_rij_wij_ccweights(self):
wij_matrix += wij

rij_matrix = rij_matrix.toarray().astype(np.float64)
if wij_matrix is not None:
if self._weights:
wij_matrix = wij_matrix.toarray().astype(np.float64)
if self._weights == "standard_error":
# N.B. using effective n due to sigma weighting, which can be below 2
Expand All @@ -341,6 +341,11 @@ def _compute_rij_wij_ccweights(self):
se = np.sqrt((1 - np.square(rij_matrix[sel])) / (wij_matrix[sel] - 1))
wij_matrix = np.zeros_like(rij_matrix)
wij_matrix[sel] = 1 / se
else:
## make wij matrix with ones on off-diagonal elements.
wij_matrix = wij_matrix.toarray().astype(np.float64)
sel = np.where(wij_matrix > 0)
wij_matrix[sel] = 1

return rij_matrix, wij_matrix

Expand Down Expand Up @@ -462,7 +467,25 @@ def sample_size(x, y):
+ "\nIncreasing min_reflections may overcome this problem."
)
else:
wij = None
wij = np.zeros_like(rij)
right_up = np.triu_indices_from(wij, k=1)

# For each correlation coefficient, set the weight equal to the size of
# the sample used to calculate that coefficient
pairwise_combos = itertools.combinations(np.isfinite(all_intensities), 2)

def sample_size(x, y):
pairs = np.count_nonzero(x & y)
if pairs < self._min_pairs:
return 0
else:
return pairs

wij[right_up] = list(itertools.starmap(sample_size, pairwise_combos))
sel = np.where(wij > 0)
wij[sel] = 1
# Symmetrise the wij matrix
wij += wij.T

return rij, wij

Expand Down
2 changes: 1 addition & 1 deletion tests/command_line/test_cosym.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@pytest.mark.parametrize(
"space_group,engine,weights,cc_weights",
[
(None, "scitbx", None, None),
(None, "scitbx", "count", "sigma"),
("P 1", "scipy", None, None),
("P 4", "scipy", "standard_error", "sigma"),
],
Expand Down

0 comments on commit 956e36f

Please sign in to comment.