generated from neutrons/python_project_template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bing Li
committed
Aug 7, 2024
1 parent
1240782
commit db4f520
Showing
4 changed files
with
74 additions
and
70 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
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
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,74 +1,66 @@ | ||
import numpy as np | ||
from tavi.sample.sample import Sample | ||
from tavi.sample.xtal import Xtal | ||
|
||
|
||
def test_b_matrix(lattice_params, b_matrix): | ||
|
||
sample = Sample(lattice_params=lattice_params) | ||
print(sample.b_mat()) | ||
print(np.allclose(sample.b_mat(), b_matrix, atol=1e-4)) | ||
|
||
|
||
def test_ub_matrix_to_uv(lattice_params, ub_matrix): | ||
|
||
xtal = Xtal(lattice_params=lattice_params) | ||
(u, v) = xtal.ub_matrix_to_uv(ub_matrix) | ||
print(f"u={u}") | ||
print(f"v={v}") | ||
|
||
|
||
def test_ub_matrix_to_lattice_params(ub_matrix): | ||
sample = Xtal() | ||
(a, b, c, alpha, beta, gamma) = sample.ub_matrix_to_lattice_params(ub_matrix) | ||
print(f"a={np.round(a,5)}, b={np.round(b,5)},c={np.round(c,5)}") | ||
print(f"alpha={np.round(alpha,3)}, beta={np.round(beta,3)}, gamma={np.round(gamma,3)}") | ||
|
||
|
||
def test_uv_to_ub_matrix(u, v, lattice_params): | ||
sample = Xtal(lattice_params=lattice_params) | ||
ub_matrix = sample.uv_to_ub_matrix(u, v) | ||
|
||
print(f"ub matrix = {ub_matrix}") | ||
import pytest | ||
|
||
from tavi.sample.xtal import Xtal | ||
|
||
if __name__ == "__main__": | ||
|
||
@pytest.fixture | ||
def xtal_info(): | ||
a = 3.574924 | ||
b = 3.574924 | ||
c = 5.663212 | ||
alpha = 90 | ||
beta = 90 | ||
gamma = 120 | ||
lattice_params = (a, b, c, alpha, beta, gamma) | ||
xtal = Xtal(lattice_params=lattice_params) | ||
|
||
# ub_matrix = np.array( | ||
# [ | ||
# [0.053821, 0.107638, 0.166485], | ||
# [0.272815, -0.013290, 0.002566], | ||
# [0.164330, 0.304247, -0.058788], | ||
# ] | ||
# ) | ||
ub_matrix = np.array( | ||
[ | ||
[0.0538, 0.1076, 0.1665], | ||
[0.2728, -0.0133, 0.0026], | ||
[0.1643, 0.3042, -0.0588], | ||
] | ||
) | ||
b_matrix = np.array( | ||
[ | ||
[0.3230, 0.1615, 0.0000], | ||
[0.0000, 0.2797, -0.0000], | ||
[0.0000, 0.0000, 0.1766], | ||
] | ||
) | ||
ub_matrix = np.array( | ||
[ | ||
[0.0538, 0.1076, 0.1665], | ||
[0.2728, -0.0133, 0.0026], | ||
[0.1643, 0.3042, -0.0588], | ||
] | ||
) | ||
|
||
u = [0.15623, 2.83819, -1.88465] | ||
v = [-0.00060, 1.03219, 5.33915] | ||
|
||
lattice_params = (a, b, c, alpha, beta, gamma) | ||
return (xtal, b_matrix, ub_matrix, u, v) | ||
|
||
|
||
def test_b_matrix(xtal_info): | ||
xtal, b_matrix, ub_matrix, u, v = xtal_info | ||
assert np.allclose(xtal.b_mat(), b_matrix, atol=1e-4) | ||
|
||
|
||
def test_ub_matrix_to_uv(xtal_info): | ||
xtal, b_matrix, ub_matrix, u, v = xtal_info | ||
(u_calc, v_calc) = xtal.ub_matrix_to_uv(ub_matrix) | ||
assert np.allclose(u_calc, u, atol=1e-3) | ||
assert np.allclose(v_calc, v, atol=1e-3) | ||
|
||
|
||
def test_ub_matrix_to_lattice_params(xtal_info): | ||
xtal, b_matrix, ub_matrix, u, v = xtal_info | ||
(a, b, c, alpha, beta, gamma) = xtal.ub_matrix_to_lattice_params(ub_matrix) | ||
assert np.allclose(a, xtal.a, atol=1e-2) | ||
assert np.allclose(b, xtal.b, atol=1e-2) | ||
assert np.allclose(c, xtal.c, atol=1e-2) | ||
assert np.allclose(alpha, xtal.alpha, atol=1e-2) | ||
assert np.allclose(beta, xtal.beta, atol=1e-2) | ||
assert np.allclose(gamma, xtal.gamma, atol=1e-2) | ||
|
||
|
||
def test_uv_to_ub_matrix(xtal_info): | ||
xtal, b_matrix, ub_matrix, u, v = xtal_info | ||
ub_matrix_calc = xtal.uv_to_ub_matrix(u, v) | ||
|
||
# test_b_matrix(lattice_params, b_matrix) | ||
test_ub_matrix_to_uv(lattice_params, ub_matrix) | ||
# test_ub_matrix_to_lattice_params(ub_matrix) | ||
test_uv_to_ub_matrix(u, v, lattice_params) | ||
assert np.allclose(ub_matrix_calc, ub_matrix, atol=1e-2) |
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