Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ setup.cfg

# Rever
rever/

# PyCharm
.idea/
45 changes: 13 additions & 32 deletions src/diffpy/utils/scattering_objects/diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
XQUANTITIES = ANGLEQUANTITIES + DQUANTITIES + QQUANTITIES
XUNITS = ["degrees", "radians", "rad", "deg", "inv_angs", "inv_nm", "nm-1", "A-1"]

x_grid_emsg = (
"objects are not on the same x-grid. You may add them using the self.add method "
"and specifying how to handle the mismatch."
)


class Diffraction_object:
def __init__(self, name="", wavelength=None):
Expand Down Expand Up @@ -57,10 +62,7 @@ def __add__(self, other):
elif not isinstance(other, Diffraction_object):
raise TypeError("I only know how to sum two Diffraction_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may add them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
summed.on_tth[1] = self.on_tth[1] + other.on_tth[1]
summed.on_q[1] = self.on_q[1] + other.on_q[1]
Expand All @@ -74,10 +76,7 @@ def __radd__(self, other):
elif not isinstance(other, Diffraction_object):
raise TypeError("I only know how to sum two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may add them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
summed.on_tth[1] = self.on_tth[1] + other.on_tth[1]
summed.on_q[1] = self.on_q[1] + other.on_q[1]
Expand All @@ -91,10 +90,7 @@ def __sub__(self, other):
elif not isinstance(other, Diffraction_object):
raise TypeError("I only know how to subtract two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may subtract them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
subtracted.on_tth[1] = self.on_tth[1] - other.on_tth[1]
subtracted.on_q[1] = self.on_q[1] - other.on_q[1]
Expand All @@ -108,10 +104,7 @@ def __rsub__(self, other):
elif not isinstance(other, Diffraction_object):
raise TypeError("I only know how to subtract two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may subtract them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
subtracted.on_tth[1] = other.on_tth[1] - self.on_tth[1]
subtracted.on_q[1] = other.on_q[1] - self.on_q[1]
Expand All @@ -125,10 +118,7 @@ def __mul__(self, other):
elif not isinstance(other, Diffraction_object):
raise TypeError("I only know how to multiply two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may multiply them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
multiplied.on_tth[1] = self.on_tth[1] * other.on_tth[1]
multiplied.on_q[1] = self.on_q[1] * other.on_q[1]
Expand All @@ -140,10 +130,7 @@ def __rmul__(self, other):
multiplied.on_tth[1] = other * self.on_tth[1]
multiplied.on_q[1] = other * self.on_q[1]
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may multiply them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
multiplied.on_tth[1] = self.on_tth[1] * other.on_tth[1]
multiplied.on_q[1] = self.on_q[1] * other.on_q[1]
Expand All @@ -157,10 +144,7 @@ def __truediv__(self, other):
elif not isinstance(other, Diffraction_object):
raise TypeError("I only know how to multiply two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"objects are not on the same x-grid. You may multiply them using the self.add method and"
"specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
divided.on_tth[1] = self.on_tth[1] / other.on_tth[1]
divided.on_q[1] = self.on_q[1] / other.on_q[1]
Expand All @@ -172,10 +156,7 @@ def __rtruediv__(self, other):
divided.on_tth[1] = other / self.on_tth[1]
divided.on_q[1] = other / self.on_q[1]
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(
"Diffraction objects are not on the same x-grid. You may multiply them using the self.add"
"method and specifying how to handle the mismatch."
)
raise RuntimeError(x_grid_emsg)
else:
divided.on_tth[1] = other.on_tth[1] / self.on_tth[1]
divided.on_q[1] = other.on_q[1] / self.on_q[1]
Expand Down