source: sasmodels/explore/transform_angles.py @ 9f2216f

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 9f2216f was 20fe0cd, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

move paracrystal integration tests with the rest of the non-rotationally symmetric tests

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#!/usr/bin/env python
2from __future__ import print_function, division
3
4import sys
5
6import numpy as np
7from numpy import pi, cos, sin, sqrt, exp, degrees, radians
8from scipy.optimize import fmin
9
10# Definition of rotation matrices comes from wikipedia:
11#    https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
12def Rx(angle):
13    """Construct a matrix to rotate points about *x* by *angle* degrees."""
14    a = radians(angle)
15    R = [[1, 0, 0],
16         [0, +cos(a), -sin(a)],
17         [0, +sin(a), +cos(a)]]
18    return np.matrix(R)
19
20def Ry(angle):
21    """Construct a matrix to rotate points about *y* by *angle* degrees."""
22    a = radians(angle)
23    R = [[+cos(a), 0, +sin(a)],
24         [0, 1, 0],
25         [-sin(a), 0, +cos(a)]]
26    return np.matrix(R)
27
28def Rz(angle):
29    """Construct a matrix to rotate points about *z* by *angle* degrees."""
30    a = radians(angle)
31    R = [[+cos(a), -sin(a), 0],
32         [+sin(a), +cos(a), 0],
33         [0, 0, 1]]
34    return np.matrix(R)
35
36
37def transform_angles(theta, phi, psi, qx=0.1, qy=0.1):
38    Rold = Rz(-psi)*Rx(theta)*Ry(-(90 - phi))
39    cost = lambda p: np.linalg.norm(Rz(-p[2])*Ry(-p[0])*Rz(-p[1]) - Rold)
40    result = fmin(cost, (theta, phi, psi))
41    theta_p, phi_p, psi_p = result
42    Rnew = Rz(-psi_p)*Ry(-theta_p)*Rz(-phi_p)
43
44    print("old: theta, phi, psi =", ", ".join(str(v) for v in (theta, phi, psi)))
45    print("new: theta, phi, psi =", ", ".join(str(v) for v in result))
46    try:
47        point = np.matrix([qx, qy, [0]*len(qx)])
48    except TypeError:
49        point = np.matrix([[qx],[qy],[0]])
50    for p in point.T:
51        print("q abc old for", p, (Rold*p.T).T)
52        print("q abc new for", p, (Rnew*p.T).T)
53
54if __name__ == "__main__":
55    theta, phi, psi = (float(v) for v in sys.argv[1:])
56    #transform_angles(theta, phi, psi)
57    transform_angles(theta, phi, psi, qx=-0.017, qy=0.035)
Note: See TracBrowser for help on using the repository browser.