Skip to content

Commit 9acc689

Browse files
committed
removed wildcard imports; enforced usage of new transform method
1 parent 8b06af4 commit 9acc689

22 files changed

+47
-38
lines changed

src/sas/qtgui/Calculators/Shape2SAS/ViewerModel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
# Local Perspectives
1212
from sas.qtgui.Calculators.Shape2SAS.ViewerAllOptions import ViewerButtons, ViewerModelRadius
13-
from sas.sascalc.shape2sas.Shape2SAS import ModelPointDistribution, TheoreticalScattering
13+
from sas.sascalc.shape2sas.Models import ModelPointDistribution
14+
from sas.sascalc.shape2sas.TheoreticalScattering import TheoreticalScattering
1415

1516

1617
class ViewerModel(QWidget):

src/sas/sascalc/shape2sas/ExperimentalScattering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
from sas.sascalc.shape2sas.Typing import *
5+
from sas.sascalc.shape2sas.Typing import Vector2D
66

77

88
@dataclass

src/sas/sascalc/shape2sas/HelperFunctions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from sas.sascalc.shape2sas.Typing import *
5-
64

75
################################ Shape2SAS helper functions ###################################
86
class Qsampling:

src/sas/sascalc/shape2sas/Models.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import numpy as np
44

55
from sas.sascalc.shape2sas.HelperFunctions import Qsampling, euler_rotation_matrix
6-
from sas.sascalc.shape2sas.models import *
7-
from sas.sascalc.shape2sas.Typing import *
6+
from sas.sascalc.shape2sas.models import \
7+
Cube, Cuboid, Cylinder, CylinderRing, Disc, DiscRing, Ellipsoid, \
8+
EllipticalCylinder, HollowCube, HollowSphere, Sphere, SuperEllipsoid
9+
from sas.sascalc.shape2sas.Typing import Vectors, Vector3D, Vector4D
810

911

1012
@dataclass
@@ -68,20 +70,22 @@ def __init__(self, matrix: np.ndarray, center_mass: np.ndarray):
6870
self.cm = center_mass # center of mass
6971
Translation = np.ndarray
7072

71-
def transform(coords: np.ndarray[Vector3D], T: Translation, R: Rotation):
73+
def transform(coords: np.ndarray[Vector3D], translate: Translation = np.array([0, 0, 0]), rotate: Rotation = Rotation(np.eye(3), np.array([0, 0, 0]))):
7274
"""Transform a set of coordinates by a rotation R and translation T"""
75+
if isinstance(rotate, np.ndarray):
76+
rotate = Rotation(rotate, np.array([0, 0, 0]))
7377
assert coords.shape[0] == 3
74-
assert T.shape == (3,)
75-
assert R.M.shape == (3, 3)
76-
assert R.cm.shape == (3,)
78+
assert translate.shape == (3,)
79+
assert rotate.M.shape == (3, 3)
80+
assert rotate.cm.shape == (3,)
7781

7882
# The transform is:
7983
# v' = R*(v - R_cm) + R_cm + T
8084
# = R*v - R*R_cm + R_cm + T
81-
# = R*v + (-R*R_cm + R_cm + T)
85+
# = R*v + T'
8286

83-
Tp = -np.dot(R.M, R.cm) + R.cm + T
84-
return np.dot(R.M, coords) + Tp[:, np.newaxis]
87+
Tp = -np.dot(rotate.M, rotate.cm) + rotate.cm + translate
88+
return np.dot(rotate.M, coords) + Tp[:, np.newaxis]
8589

8690

8791
class GeneratePoints:
@@ -226,7 +230,7 @@ def onCheckOverlap(
226230

227231
if any(r != 0 for r in rotation):
228232
## effective coordinates, shifted by (x_com,y_com,z_com)
229-
x_eff, y_eff, z_eff = Translation(x, y, z, -com[0], -com[1], -com[2]).onTranslatingPoints()
233+
x_eff, y_eff, z_eff = transform(np.vstack([x, y, z]), translate=np.array([-com[0], -com[1], -com[2]]))
230234

231235
#rotate backwards with minus rotation angles
232236
alpha, beta, gam = rotation
@@ -235,12 +239,12 @@ def onCheckOverlap(
235239
beta = np.radians(beta)
236240
gam = np.radians(gam)
237241

238-
x_eff, y_eff, z_eff = Rotation(x_eff, y_eff, z_eff, -alpha, -beta, -gam, rotp_x, rotp_y, rotp_z).onRotatingPoints()
242+
rotation = Rotation(euler_rotation_matrix(-alpha, -beta, -gam), np.array([rotp_x, rotp_y, rotp_z]))
243+
x_eff, y_eff, z_eff = transform(np.vstack([x_eff, y_eff, z_eff]), rotate=rotation)
239244

240245
else:
241246
## effective coordinates, shifted by (x_com,y_com,z_com)
242-
x_eff, y_eff, z_eff = Translation(x, y, z, -com[0], -com[1], -com[2]).onTranslatingPoints()
243-
247+
x_eff, y_eff, z_eff = transform(np.vstack([x, y, z]), translate=np.array([-com[0], -com[1], -com[2]]))
244248

245249
idx = subunitClass(dimensions).checkOverlap(x_eff, y_eff, z_eff)
246250
x_add, y_add, z_add, p_add = x[idx], y[idx], z[idx], p[idx]

src/sas/sascalc/shape2sas/Shape2SAS.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import numpy as np
77

8-
from sas.sascalc.shape2sas.ExperimentalScattering import *
8+
from sas.sascalc.shape2sas.ExperimentalScattering import SimulateScattering, getSimulatedScattering
99
from sas.sascalc.shape2sas.HelperFunctions import generate_pdb, plot_2D, plot_results
10-
from sas.sascalc.shape2sas.Models import *
10+
from sas.sascalc.shape2sas.Models import Qsampling, ModelProfile, SimulationParameters, getPointDistribution
1111
from sas.sascalc.shape2sas.StructureFactor import StructureFactor
12-
from sas.sascalc.shape2sas.TheoreticalScattering import *
12+
from sas.sascalc.shape2sas.TheoreticalScattering import \
13+
TheoreticalScatteringCalculation, ModelSystem, ITheoretical, WeightedPairDistribution, \
14+
getTheoreticalScattering, getTheoreticalHistogram
1315

1416
################################ Shape2SAS batch version ################################
1517
if __name__ == "__main__":

src/sas/sascalc/shape2sas/StructureFactor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
import numpy as np
33

4-
from sas.sascalc.shape2sas.structure_factors import *
5-
from sas.sascalc.shape2sas.Typing import *
4+
from sas.sascalc.shape2sas.structure_factors import HardSphereStructure, Aggregation, NoStructure
65

76

87
class StructureFactor:

src/sas/sascalc/shape2sas/TheoreticalScattering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sas.sascalc.shape2sas.HelperFunctions import sinc
66
from sas.sascalc.shape2sas.Models import ModelSystem, SimulationParameters
77
from sas.sascalc.shape2sas.StructureFactor import StructureFactor
8-
from sas.sascalc.shape2sas.Typing import *
8+
from sas.sascalc.shape2sas.Typing import Vector2D, Vector3D
99

1010

1111
@dataclass

src/sas/sascalc/shape2sas/Typing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import numpy as np
32

43
Vectors = list[list[float]]

src/sas/sascalc/shape2sas/models/Cube.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from sas.sascalc.shape2sas.Typing import *
1+
import numpy as np
2+
from sas.sascalc.shape2sas.Typing import Vector3D
23

34

45
class Cube:

src/sas/sascalc/shape2sas/models/Cuboid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from sas.sascalc.shape2sas.Typing import *
1+
import numpy as np
2+
from sas.sascalc.shape2sas.Typing import Vector3D
23

34

45
class Cuboid:

0 commit comments

Comments
 (0)