-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tjlane
committed
Aug 11, 2024
1 parent
2a14c79
commit e86e9b2
Showing
2 changed files
with
10 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,17 @@ | ||
import numpy as np | ||
import scipy.optimize as opt | ||
|
||
import reciprocalspaceship as rs | ||
|
||
def scale_iso(data1, data2, ds): | ||
""" | ||
Isotropic resolution-dependent scaling of data2 to data1. | ||
(minimize [dataset1 - c*exp(-B*sintheta**2/lambda**2)*dataset2] | ||
Input : | ||
1. dataset1 in form of 1D numpy array | ||
2. dataset2 in form of 1D numpy array | ||
3. dHKLs for the datasets in form of 1D numpy array | ||
Returns : | ||
1. entire results from least squares fitting | ||
2. c (as float) | ||
3. B (as float) | ||
2. scaled dataset2 in the form of a 1D numpy array | ||
|
||
def scale_structure_factors(reference: rs.DataSet, dataset_to_scale: rs.DataSet) -> rs.DataSet: | ||
""" | ||
Apply an anisotropic scaling so that `dataset_to_scale` is on the same scale as `reference`. | ||
def scale_func(p, x1, x2, qs): | ||
return x1 - (p[0] * np.exp(-p[1] * (qs**2))) * x2 | ||
C * exp{ -(h**2 B11 + k**2 B22 + l**2 B33 + | ||
2hk B12 + 2hl B13 + 2kl B23) } | ||
p0 = np.array([1.0, -20]) | ||
qs = 1 / (2 * ds) | ||
matrix = opt.least_squares(scale_func, p0, args=(data1, data2, qs)) | ||
This is the same procedure implemented by CCP4's SCALEIT. | ||
return ( | ||
matrix.x[0], | ||
matrix.x[1], | ||
(matrix.x[0] * np.exp(-matrix.x[1] * (qs**2))) * data2, | ||
) | ||
|
||
|
||
def scale_aniso(x_dataset, y_dataset, Miller_indx): | ||
""" " | ||
Author: Virginia Apostolopoulou | ||
Anisotropically scales y_dataset to x_dataset given an ndarray of Miller indices. | ||
.. https://www.ccp4.ac.uk/html/scaleit.html | ||
""" | ||
|
||
p0 = np.array([1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], dtype=np.float32) | ||
matrix_ani = opt.least_squares( | ||
aniso_scale_func, p0, args=(x_dataset, y_dataset, Miller_indx) | ||
) | ||
|
||
h = Miller_indx[:, 0] | ||
k = Miller_indx[:, 1] | ||
l = Miller_indx[:, 2] | ||
h_sq = np.square(h) | ||
k_sq = np.square(k) | ||
l_sq = np.square(l) | ||
|
||
hk_prod = h * k | ||
hl_prod = h * l | ||
kl_prod = k * l | ||
|
||
t = -( | ||
h_sq * matrix_ani.x[1] | ||
+ k_sq * matrix_ani.x[2] | ||
+ l_sq * matrix_ani.x[3] | ||
+ 2 * hk_prod * matrix_ani.x[4] | ||
+ 2 * hl_prod * matrix_ani.x[5] | ||
+ 2 * kl_prod * matrix_ani.x[6] | ||
) | ||
|
||
data_ani_scaled = (matrix_ani.x[0] * np.exp(t)) * y_dataset | ||
|
||
return matrix_ani, t, data_ani_scaled | ||
|
||
|
||
def aniso_scale_func(p, x1, x2, H_arr): | ||
"Author: Virginia Apostolopoulou" | ||
|
||
h = H_arr[:, 0] | ||
k = H_arr[:, 1] | ||
l = H_arr[:, 2] | ||
|
||
h_sq = np.square(h) | ||
k_sq = np.square(k) | ||
l_sq = np.square(l) | ||
|
||
hk_prod = h * k | ||
hl_prod = h * l | ||
kl_prod = k * l | ||
|
||
t = -( | ||
h_sq * p[1] | ||
+ k_sq * p[2] | ||
+ l_sq * p[3] | ||
+ 2 * hk_prod * p[4] | ||
+ 2 * hl_prod * p[5] | ||
+ 2 * kl_prod * p[6] | ||
) | ||
expnt = np.exp(t) | ||
r = x1 - p[0] * expnt * x2 | ||
return r | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ authors = [ | |
dependencies = [ | ||
"numpy", | ||
"scipy", | ||
"skimage", | ||
"scikit-image", | ||
"reciprocalspaceship", | ||
] | ||
|
||
|