From 61287640848a06cced0646aba8cb17aa379c536b Mon Sep 17 00:00:00 2001 From: smalex-z Date: Fri, 23 Jun 2023 12:24:12 -0400 Subject: [PATCH 01/10] Radius of Gyration added to GSC --- .../GenericScatteringCalculator.py | 58 +- .../UI/GenericScatteringCalculator.ui | 1002 ++++---- .../GenericScatteringCalculator.ui.autosave | 2031 +++++++++++++++++ 3 files changed, 2544 insertions(+), 547 deletions(-) create mode 100644 src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 90158959ec..a1235692a9 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -5,6 +5,7 @@ import logging import time import timeit +import periodictable from scipy.spatial.transform import Rotation @@ -16,6 +17,8 @@ from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import __version__ as mpl_version +from periodictable import * + from twisted.internet import threads import sas.qtgui.Utilities.GuiUtils as GuiUtils @@ -821,7 +824,7 @@ def update_gui(self): if self.nuc_sld_data.is_elements: self.txtNoPixels.setText(str(len(self.nuc_sld_data.elements))) else: - self.txtNoPixels.setText(str(len(self.nuc_sld_data.sld_n))) + self.txtNoPixels.setText(str(len(self.nuc_sld_data.sld_n))) elif self.is_mag: if self.mag_sld_data.is_elements: self.txtNoPixels.setText(str(len(self.mag_sld_data.elements))) @@ -857,10 +860,63 @@ def update_gui(self): self.txtZstepsize.setText(GuiUtils.formatValue(self.mag_sld_data.zstepsize)) # otherwise leave as set since editable by user + # update the value of the Radius of Gyration with values from the loaded data + if self.is_nuc: + if self.nuc_sld_data.is_elements: + self.txtROG.setText(str("N/A for Elements")) + else: + self.txtROG.setText(str(self.radius_of_gyration())) + elif self.is_mag: + self.txtROG.setText(str("N/A for magnetic data")) + else: + self.txtROG.setText(str("N/A for no data")) + + # If nodes or stepsize changed then this may effect what values are allowed self.gui_text_changed(sender=self.txtNoQBins) self.gui_text_changed(sender=self.txtQxMax) + def radius_of_gyration(self): + #Calculate Center of Mass(CoM) First + CoMnumerator= [0.0,0.0,0.0] + CoMdenominator = [0.0,0.0,0.0] + CoM = [0.0,0.0,0.0] + + for i in range(len(self.nuc_sld_data.pos_x)): + coordinates = [0.0,0.0,0.0] + coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] + + #Coh b - Coherent Scattering Length(fm) + cohB = eval("periodictable." + str(self.nuc_sld_data.pix_symbol[i]) + ".neutron.b_c") + + for i in range(3): #sets CiN + CoMnumerator[i] += (coordinates[i]*cohB) + CoMdenominator[i] += cohB + + for i in range(3): + CoM[i] = CoMnumerator[i]/CoMdenominator[i] #center of mass + + #Now Calculate RoG + RoGNumerator = RoGDenominator = 0.0 + + for i in range(len(self.nuc_sld_data.pos_x)): + coordinates = [0.0,0.0,0.0] + coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] + + #Coh b - Coherent Scattering Length(fm) + cohB = eval("periodictable." + str(self.nuc_sld_data.pix_symbol[i]) + ".neutron.b_c") + + #Calculate the Magnitude of the Coordinate vector for the atom and the center of mass + MagnitudeOfCoM = numpy.sqrt(numpy.power(CoM[0]-coordinates[0],2) + numpy.power(CoM[1]-coordinates[1],2) + numpy.power(CoM[2]-coordinates[2],2)) + + #Calculate Rate of Gyration (Squared) with the formular + RoGNumerator += cohB * (numpy.power(MagnitudeOfCoM,2)) + RoGDenominator += cohB + + RoG = numpy.sqrt(RoGNumerator/RoGDenominator) + + return (RoG) + def update_geometry_effects(self): """This function updates the number of pixels and total volume when the number of nodes/stepsize is changed diff --git a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui index 0eccfce6e8..973990080c 100644 --- a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui +++ b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui @@ -36,11 +36,37 @@ :/res/ball.ico:/res/ball.ico + + + + Qt::Horizontal + + + + 3 + 20 + + + + + + + + Qt::Vertical + + + + + + + Qt::Vertical + + + - 50 false @@ -54,7 +80,6 @@ - 50 false @@ -89,7 +114,6 @@ - 50 false @@ -117,7 +141,6 @@ - 50 false @@ -136,7 +159,6 @@ - 50 false @@ -171,7 +193,6 @@ - 50 false @@ -199,7 +220,6 @@ - 50 false @@ -218,7 +238,6 @@ - 50 false @@ -240,7 +259,6 @@ - 50 false @@ -273,7 +291,6 @@ - 50 false @@ -293,10 +310,30 @@ - - - - Qt::Vertical + + + + + 0 + 30 + + + + + false + + + + Verification Error + + + + + + Qt::AlignHCenter + + + true @@ -304,7 +341,6 @@ - 50 false @@ -316,7 +352,6 @@ - 50 false @@ -342,7 +377,6 @@ Not editable. - 50 false @@ -358,7 +392,6 @@ Not editable. - 50 false @@ -372,7 +405,6 @@ Not editable. - 50 false @@ -394,7 +426,6 @@ Not editable. - 50 false @@ -410,7 +441,6 @@ Not editable. - 50 false @@ -423,7 +453,6 @@ Not editable. - 50 false @@ -445,7 +474,6 @@ Not editable. - 50 false @@ -461,7 +489,6 @@ Not editable. - 50 false @@ -474,7 +501,6 @@ Not editable. - 50 false @@ -496,7 +522,6 @@ Not editable. - 50 false @@ -512,7 +537,6 @@ Not editable. - 50 false @@ -525,7 +549,6 @@ Not editable. - 50 false @@ -547,7 +570,6 @@ Not editable. - 50 false @@ -560,7 +582,6 @@ Not editable. - 50 false @@ -578,7 +599,6 @@ Not editable. - 50 false @@ -592,7 +612,6 @@ Not editable. - 50 false @@ -611,7 +630,6 @@ Not editable. - 50 false @@ -624,7 +642,6 @@ Not editable. - 50 false @@ -643,7 +660,6 @@ Not editable. - 50 false @@ -656,7 +672,6 @@ Not editable. - 50 false @@ -675,7 +690,6 @@ Not editable. - 50 false @@ -693,7 +707,6 @@ Not editable. - 50 false @@ -707,7 +720,6 @@ Not editable. - 50 false @@ -726,7 +738,6 @@ Not editable. - 50 false @@ -739,7 +750,6 @@ Not editable. - 50 false @@ -752,7 +762,6 @@ Not editable. - 50 false @@ -771,7 +780,6 @@ Not editable. - 50 false @@ -784,7 +792,6 @@ Not editable. - 50 false @@ -797,7 +804,6 @@ Not editable. - 50 false @@ -816,7 +822,6 @@ Not editable. - 50 false @@ -829,7 +834,6 @@ Not editable. - 50 false @@ -856,7 +860,6 @@ Not editable. - 50 false @@ -897,7 +900,6 @@ Not editable. - 50 false @@ -922,14 +924,52 @@ Not editable. groupBox_Stepsize - - + + + + + + + + 0 + 0 + + + + + 155 + 23 + + + + + 155 + 26 + + + + <html><head/><body><p>Option of orientation to perform calculations:</p><p>- Scattering calculated for fixed orientation &#8594; 2D output</p><p>- Scattering orientation averaged over all orientations &#8594; 1D output</p><p>This choice is only available for pdb files.</p></body></html> + + + + Fixed orientation + + + + + Debye full avg. + + + + + + Qt::Horizontal - 3 + 40 20 @@ -948,80 +988,33 @@ Not editable. - - + + - 50 false - Input Parameters + Q Range - + - - - QLayout::SetMinimumSize - - - - - - 50 - false - - - - Parameter - - - - - - - - 50 - false - - - - Value - - - - - - - - 50 - false - - - - Unit - - - - - + + + - 50 false - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - Up_frac_in + <html><head/><body><p>Å<span style=" vertical-align:super;">-1</span></p></body></html> - + 0 @@ -1030,74 +1023,47 @@ Not editable. - 50 - false - - - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> - - - 1.0 - - - - - - - - 50 false - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - Up_frac_out + 0.3 - - - - - 0 - 18 - - + + - 50 false - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> + <html><head/><body><p>Maximum value of Q<span style=" vertical-align:sub;">x,y</span>.</p><p>Q<span style=" vertical-align:sub;">x,ymax </span>&isin; ]0, 1000].</p></body></html> - 1.0 + Qx (Qy) Max - - + + - 50 false - <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + Number of bins in reciprocal space for the 1D or 2D plot generated by 'Compute'. +Number of Qbins &isin; [2, 1000]. - Up_theta + No. of Qx (Qy) bins - - + + 0 @@ -1106,129 +1072,241 @@ Not editable. - 50 - false - - - - <html><head/><body><p>Polarization angle.</p></body></html> - - - 0.0 - - - - - - - - 50 - false - - - - <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - - Up_phi - - - - - - - - 50 false - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + 30 - - - - - 0 - 18 - - - - - 50 - false - - - - <html><head/><body><p>Polarization angle.</p></body></html> - - - 0.0 - + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 75 + 23 + + + + Close the calculator. + + + Close + + + + 17 + 16 + + + + false + + + + + + + + 0 + 0 + + + + + 75 + 23 + + + + Reset the interface to its default values + + + Reset + + + false + + + + + + + + 0 + 0 + + + + + 75 + 23 + + + + Display 'Help' information about the calculator + + + Help + + + false + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Compute the scattering pattern and display 1D or 2D plot depending on the settings.</p></body></html> + + + Compute + + + false + + + + + + + + + + false + + + + Input Parameters + + + + + + QLayout::SetMinimumSize + + + + + + false + + + + Parameter + - - + + - 50 false - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + Value - - - - - 0 - 18 - + + + + + false + + + + Unit + + + + - 50 false + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + - 0.0 + Up_frac_in - - + + + + + 0 + 18 + + - 50 false + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> + - <html><head/><body><p>cm<span style=" vertical-align:super;">-1</span></p></body></html> + 1.0 - - + + - 50 false + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + - Scale + Up_frac_out - - + + 0 @@ -1237,30 +1315,34 @@ Not editable. - 50 false + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> + 1.0 - - + + - 50 false + + <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + - Solvent_SLD + Up_theta - - + + 0 @@ -1269,33 +1351,46 @@ Not editable. - 50 false + + <html><head/><body><p>Polarization angle.</p></body></html> + 0.0 - - + + - 50 false - Default total volume calculated from the pixel information (or natural density for pdb file). + <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - Total volume + Up_phi - - + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + 0 @@ -1304,122 +1399,136 @@ Not editable. - 50 false - <html><head/><body><p>Default total volume calculated from the pixel information (or natural density for pdb file)</p></body></html> + <html><head/><body><p>Polarization angle.</p></body></html> - 216000.0 + 0.0 - - + + - 50 false - <html><head/><body><p>Å<span style=" vertical-align:super;">3</span></p></body></html> + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - + + + + + 0 + 18 + + - 50 false - Background + 0.0 - - - - - 0 - 0 - + + + + + false + + + + <html><head/><body><p>cm<span style=" vertical-align:super;">-1</span></p></body></html> + + + + + + + + false + + + + Scale + + + + 0 - 0 + 18 - - - 0 - 0 - + + + false + + + + 1.0 + + + + - 50 false - <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + Solvent_SLD - - false + + + + + + + 0 + 18 + - - 0 + + + false + - - -1 + + 0.0 - - - - - - - - - - 50 - false - - - - Q Range - - - - - - + + - 50 false - Number of bins in reciprocal space for the 1D or 2D plot generated by 'Compute'. -Number of Qbins &isin; [2, 1000]. + Default total volume calculated from the pixel information (or natural density for pdb file). - No. of Qx (Qy) bins + Total volume - - + + 0 @@ -1428,60 +1537,77 @@ Number of Qbins &isin; [2, 1000]. - 50 false + + <html><head/><body><p>Default total volume calculated from the pixel information (or natural density for pdb file)</p></body></html> + - 30 + 216000.0 - - + + - 50 false - - <html><head/><body><p>Maximum value of Q<span style=" vertical-align:sub;">x,y</span>.</p><p>Q<span style=" vertical-align:sub;">x,ymax </span>&isin; ]0, 1000].</p></body></html> - - Qx (Qy) Max + <html><head/><body><p>Å<span style=" vertical-align:super;">3</span></p></body></html> - - - - - 0 - 18 - - + + - 50 false - 0.3 + Background - - + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + - 50 false - <html><head/><body><p>Å<span style=" vertical-align:super;">-1</span></p></body></html> + <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + + + false + + + 0 + + + -1 @@ -1490,18 +1616,10 @@ Number of Qbins &isin; [2, 1000]. - - - - Qt::Vertical - - - - 50 false @@ -1513,7 +1631,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1525,7 +1642,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1547,7 +1663,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1563,7 +1678,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1576,7 +1690,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1598,7 +1711,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1614,7 +1726,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1627,7 +1738,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1649,7 +1759,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1665,7 +1774,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1681,7 +1789,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1693,7 +1800,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1715,7 +1821,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1731,7 +1836,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1744,7 +1848,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1766,7 +1869,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1782,7 +1884,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1795,7 +1896,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1817,7 +1917,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1833,7 +1932,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1848,9 +1946,6 @@ Number of Qbins &isin; [2, 1000]. - - - @@ -1864,212 +1959,27 @@ Number of Qbins &isin; [2, 1000]. - - - - - 0 - 0 - - - - - 155 - 23 - - - - - 155 - 26 - - - - <html><head/><body><p>Option of orientation to perform calculations:</p><p>- Scattering calculated for fixed orientation &#8594; 2D output</p><p>- Scattering orientation averaged over all orientations &#8594; 1D output</p><p>This choice is only available for pdb files.</p></body></html> - - - - Fixed orientation - - - - - Debye full avg. - - - - - - - - Qt::Vertical - - - - 20 - 54 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - <html><head/><body><p>Compute the scattering pattern and display 1D or 2D plot depending on the settings.</p></body></html> - - - Compute - - - false - - - - - - - - 0 - 0 - - - - - 75 - 23 - - - - Reset the interface to its default values - + + + + - Reset - - - false + Radius of Gyration - - - - - 0 - 0 - - - - - 75 - 23 - - - - Close the calculator. - - - Close - - - - 17 - 16 - - - + + + false - - - - - - - 0 - 0 - - - - - 75 - 23 - - - - Display 'Help' information about the calculator - - Help - - - false + 0 - - - - - 0 - 30 - - - - - 50 - false - - - - Verification Error - - - - - - Qt::AlignHCenter - - - true - - - diff --git a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave new file mode 100644 index 0000000000..973990080c --- /dev/null +++ b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave @@ -0,0 +1,2031 @@ + + + GenericScatteringCalculator + + + + 0 + 0 + 1024 + 625 + + + + + 0 + 0 + + + + + 660 + 550 + + + + + 1150 + 700 + + + + Generic Scattering Calculator + + + + :/res/ball.ico:/res/ball.ico + + + + + + Qt::Horizontal + + + + 3 + 20 + + + + + + + + Qt::Vertical + + + + + + + Qt::Vertical + + + + + + + + false + + + + SLD Data File + + + + + + + + + false + + + + <html><head/><body><p>Nuclear data used to simulate SANS.</p></body></html> + + + Nuclear Data + + + + + + + + + + + + + + + 0 + 0 + + + + + 151 + 0 + + + + + false + + + + Display name of loaded datafile. + + + No File Loaded + + + + + + + + 0 + 0 + + + + + 80 + 23 + + + + + false + + + + <html><head/><body><p>Only .txt, .sld, .vtk and .pdb datafile formats are supported. </p><p>Load Nuclear sld data.</p></body></html> + + + Load + + + false + + + + + + + + false + + + + <html><head/><body><p>Magnetic data used to simulate SANS.</p></body></html> + + + Magnetic Data + + + + + + + + + + + + + + + 0 + 0 + + + + + 151 + 0 + + + + + false + + + + Display name of loaded datafile. + + + No File Loaded + + + + + + + + 0 + 0 + + + + + 80 + 23 + + + + + false + + + + <html><head/><body><p>Only .txt, .omf, .vtk and .sld datafile formats are supported. </p><p>Load Magnetic sld data.</p></body></html> + + + Load + + + false + + + + + + + + false + + + + <html><head/><body><p>Default shape of the sample.</p></body></html> + + + Shape + + + + + + + + 0 + 0 + + + + + false + + + + <html><head/><body><p>Select the default shape of the sample.</p></body></html> + + + + Rectangular + + + + + + + + true + + + + 0 + 0 + + + + + 80 + 23 + + + + + false + + + + <html><head/><body><p>Generate a 3D plot with arrows for the magnetic vectors.</p><p>It is not recommanded for a large number of pixels.</p></body></html> + + + Draw + + + false + + + + + + + + + + + + + 0 + 30 + + + + + false + + + + Verification Error + + + + + + Qt::AlignHCenter + + + true + + + + + + + + false + + + + SLD Pixel Info + + + + + + + false + + + + Number of pixels. +Not editable. + + + No. of Pixels + + + + + + + false + + + + 110 + 27 + + + + + false + + + + 1000 + + + true + + + + + + + + false + + + + Mean SLD + + + + + + + + + false + + + + <html><head/><body><p>Mean value of M<span style=" vertical-align:sub;">x</span> (x-component of the magnetisation vector).</p></body></html> + + + Mx + + + + + + + + 70 + 18 + + + + + false + + + + x component of the magnetization vector in the laboratory xyz frame + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>Mean value of My (y-component of the magnetisation vector).</p></body></html> + + + My + + + + + + + + 70 + 18 + + + + + false + + + + y component of the magnetization vector in the laboratory xyz frame + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>Mean value of M<span style=" vertical-align:sub;">z</span> (z-component of the magnetisation vector).</p></body></html> + + + Mz + + + + + + + + 70 + 18 + + + + + false + + + + z component of the magnetization vector in the laboratory xyz frame + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>Average of the nuclear scattering density.</p></body></html> + + + Nucl. + + + + + + + + 70 + 18 + + + + + false + + + + 6.97e-06 + + + + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + + + + + + + + + + + + + false + + + + Nodes + + + + + + + + + false + + + + xnodes + + + + + + + + 56 + 18 + + + + + false + + + + 10 + + + + + + + + false + + + + ynodes + + + + + + + + 56 + 18 + + + + + false + + + + 10 + + + + + + + + false + + + + znodes + + + + + + + + 56 + 18 + + + + + false + + + + 10 + + + + + + + + + + + + + false + + + + Step Size + + + + + + + + + false + + + + xstepsize + + + + + + + + 50 + 18 + + + + + false + + + + 6 + + + + + + + + false + + + + Å + + + + + + + + false + + + + ystepsize + + + + + + + + 50 + 18 + + + + + false + + + + 6 + + + + + + + + false + + + + Å + + + + + + + + false + + + + zstepsize + + + + + + + + 50 + 18 + + + + + false + + + + 6 + + + + + + + + false + + + + Å + + + + + + + + + + + + true + + + + 0 + 0 + + + + + false + + + + <html><head/><body><p>Draw a scatter plot for sld profile (without arrows)</p></body></html> + + + Draw Points + + + false + + + + + + + Qt::Horizontal + + + + 7 + 20 + + + + + + + + false + + + + 0 + 0 + + + + + false + + + + <html><head/><body><p>Save the sld data as sld format.</p></body></html> + + + Save SLD Data + + + false + + + + + cmdDrawpoints + cmdSave + lblNoPixels + txtNoPixels + groupBox_5 + groupBox_6 + groupBox_Stepsize + + + + + + + + + + 0 + 0 + + + + + 155 + 23 + + + + + 155 + 26 + + + + <html><head/><body><p>Option of orientation to perform calculations:</p><p>- Scattering calculated for fixed orientation &#8594; 2D output</p><p>- Scattering orientation averaged over all orientations &#8594; 1D output</p><p>This choice is only available for pdb files.</p></body></html> + + + + Fixed orientation + + + + + Debye full avg. + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + false + + + + Q Range + + + + + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">-1</span></p></body></html> + + + + + + + + 0 + 18 + + + + + false + + + + 0.3 + + + + + + + + false + + + + <html><head/><body><p>Maximum value of Q<span style=" vertical-align:sub;">x,y</span>.</p><p>Q<span style=" vertical-align:sub;">x,ymax </span>&isin; ]0, 1000].</p></body></html> + + + Qx (Qy) Max + + + + + + + + false + + + + Number of bins in reciprocal space for the 1D or 2D plot generated by 'Compute'. +Number of Qbins &isin; [2, 1000]. + + + No. of Qx (Qy) bins + + + + + + + + 0 + 18 + + + + + false + + + + 30 + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 75 + 23 + + + + Close the calculator. + + + Close + + + + 17 + 16 + + + + false + + + + + + + + 0 + 0 + + + + + 75 + 23 + + + + Reset the interface to its default values + + + Reset + + + false + + + + + + + + 0 + 0 + + + + + 75 + 23 + + + + Display 'Help' information about the calculator + + + Help + + + false + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Compute the scattering pattern and display 1D or 2D plot depending on the settings.</p></body></html> + + + Compute + + + false + + + + + + + + + + false + + + + Input Parameters + + + + + + QLayout::SetMinimumSize + + + + + + false + + + + Parameter + + + + + + + + false + + + + Value + + + + + + + + false + + + + Unit + + + + + + + + false + + + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + + + Up_frac_in + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> + + + 1.0 + + + + + + + + false + + + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + + + Up_frac_out + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> + + + 1.0 + + + + + + + + false + + + + <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + + + Up_theta + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>Polarization angle.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> + + + Up_phi + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>Polarization angle.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + 0 + 18 + + + + + false + + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p>cm<span style=" vertical-align:super;">-1</span></p></body></html> + + + + + + + + false + + + + Scale + + + + + + + + 0 + 18 + + + + + false + + + + 1.0 + + + + + + + + false + + + + Solvent_SLD + + + + + + + + 0 + 18 + + + + + false + + + + 0.0 + + + + + + + + false + + + + Default total volume calculated from the pixel information (or natural density for pdb file). + + + Total volume + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>Default total volume calculated from the pixel information (or natural density for pdb file)</p></body></html> + + + 216000.0 + + + + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">3</span></p></body></html> + + + + + + + + false + + + + Background + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + false + + + + <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> + + + false + + + 0 + + + -1 + + + + + + + + + + + + + false + + + + Coordinate System Info + + + + + + + false + + + + Environment Coordinates (uvw) + + + + + + + false + + + + <html><head/><body><p>The yaw angle of the environment coordinates from the beamline coordinates.</p></body></html> + + + Yaw + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>The yaw angle of the environment coordinates from the beamline coordinates.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>The pitch angle of the environment coordinates from the beamline coordinates.</p></body></html> + + + Pitch + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>The pitch angle of the environment coordinates from the beamline coordinates.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>The roll angle of the environment coordinates from the beamline coordinates.</p></body></html> + + + Roll + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>The roll angle of the environment coordinates from the beamline coordinates.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + + + + false + + + + Sample Coordinates (xyz) + + + + + + + false + + + + <html><head/><body><p>The yaw angle of the sample coordinates from the environment coordinates.</p></body></html> + + + Yaw + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>The yaw angle of the sample coordinates from the environment coordinates.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>The pitch angle of the sample coordinates from the environment coordinates.</p></body></html> + + + Pitch + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>The pitch angle of the sample coordinates from the environment coordinates.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + false + + + + <html><head/><body><p>The roll angle of the sample coordinates from the environment coordinates.</p></body></html> + + + Roll + + + + + + + + 0 + 18 + + + + + false + + + + <html><head/><body><p>The roll angle of the sample coordinates from the enivronment coordinates.</p></body></html> + + + 0.0 + + + + + + + + false + + + + <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> + + + + + + + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + Radius of Gyration + + + + + + + false + + + 0 + + + + + + + + + checkboxNucData + txtNucData + checkboxMagData + txtMagData + cbShape + cmdNucLoad + cmdMagLoad + cmdDraw + txtUpFracIn + txtUpFracOut + txtUpTheta + txtUpPhi + txtBackground + txtScale + txtSolventSLD + txtTotalVolume + txtNoQBins + txtQxMax + cbOptionsCalc + txtNoPixels + txtMx + txtMy + txtMz + txtNucl + cmdDrawpoints + cmdSave + txtXnodes + txtYnodes + txtZnodes + txtXstepsize + txtYstepsize + txtZstepsize + txtEnvYaw + txtEnvPitch + txtEnvRoll + txtSampleYaw + txtSamplePitch + txtSampleRoll + cmdCompute + cmdReset + cmdClose + cmdHelp + + + + From 5f3292cf0a504bd8c4d90c24dd5ba7378b441787 Mon Sep 17 00:00:00 2001 From: smalex-z Date: Fri, 23 Jun 2023 15:18:20 -0400 Subject: [PATCH 02/10] changed obtaining cohB from eval function for safety --- src/sas/qtgui/Calculators/GenericScatteringCalculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index a1235692a9..90f7ffa19d 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -904,7 +904,7 @@ def radius_of_gyration(self): coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] #Coh b - Coherent Scattering Length(fm) - cohB = eval("periodictable." + str(self.nuc_sld_data.pix_symbol[i]) + ".neutron.b_c") + cohB = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c #Calculate the Magnitude of the Coordinate vector for the atom and the center of mass MagnitudeOfCoM = numpy.sqrt(numpy.power(CoM[0]-coordinates[0],2) + numpy.power(CoM[1]-coordinates[1],2) + numpy.power(CoM[2]-coordinates[2],2)) From 0de0c0b7c7753631379d5a43922f7f827f61f60b Mon Sep 17 00:00:00 2001 From: smalex-z Date: Fri, 23 Jun 2023 15:59:05 -0400 Subject: [PATCH 03/10] also changed 2nd eval function for safety --- src/sas/qtgui/Calculators/GenericScatteringCalculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 90f7ffa19d..20f25ee13b 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -887,7 +887,7 @@ def radius_of_gyration(self): coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] #Coh b - Coherent Scattering Length(fm) - cohB = eval("periodictable." + str(self.nuc_sld_data.pix_symbol[i]) + ".neutron.b_c") + cohB = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c for i in range(3): #sets CiN CoMnumerator[i] += (coordinates[i]*cohB) From f0adf640e45e92e2e2a46a9c4630a757310d22c7 Mon Sep 17 00:00:00 2001 From: smalex-z Date: Mon, 26 Jun 2023 15:27:52 -0400 Subject: [PATCH 04/10] moved Center of Mass computation to seperate function from the RoG Calculation --- .../GenericScatteringCalculator.py | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 20f25ee13b..97e5b9b76f 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -878,23 +878,7 @@ def update_gui(self): def radius_of_gyration(self): #Calculate Center of Mass(CoM) First - CoMnumerator= [0.0,0.0,0.0] - CoMdenominator = [0.0,0.0,0.0] - CoM = [0.0,0.0,0.0] - - for i in range(len(self.nuc_sld_data.pos_x)): - coordinates = [0.0,0.0,0.0] - coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] - - #Coh b - Coherent Scattering Length(fm) - cohB = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c - - for i in range(3): #sets CiN - CoMnumerator[i] += (coordinates[i]*cohB) - CoMdenominator[i] += cohB - - for i in range(3): - CoM[i] = CoMnumerator[i]/CoMdenominator[i] #center of mass + CoM = self.centerOfMass() #Now Calculate RoG RoGNumerator = RoGDenominator = 0.0 @@ -916,6 +900,29 @@ def radius_of_gyration(self): RoG = numpy.sqrt(RoGNumerator/RoGDenominator) return (RoG) + + def centerOfMass(self): + """Calculate Center of Mass(CoM) of provided atom""" + CoMnumerator= [0.0,0.0,0.0] + CoMdenominator = [0.0,0.0,0.0] + CoM = [0.0,0.0,0.0] + + for i in range(len(self.nuc_sld_data.pos_x)): + coordinates = [0.0,0.0,0.0] + coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] + + #Coh b - Coherent Scattering Length(fm) + cohB = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c + + for i in range(3): #sets CiN + CoMnumerator[i] += (coordinates[i]*cohB) + CoMdenominator[i] += cohB + + for i in range(3): + CoM[i] = CoMnumerator[i]/CoMdenominator[i] #center of mass + + return CoM + def update_geometry_effects(self): """This function updates the number of pixels and total volume when the number of nodes/stepsize is changed From 1e1caf502316bfe5cfbbf6dd29576f1ecfd550f1 Mon Sep 17 00:00:00 2001 From: smalex-z Date: Mon, 26 Jun 2023 15:30:08 -0400 Subject: [PATCH 05/10] Tweaked UI and Backend to include BetaQ Caclulations. Still need to bring BetaQ from Backend into UI and revise calculation method (sleep) --- .../GenericScatteringCalculator.py | 79 +- .../UI/GenericScatteringCalculator.ui | 5 + .../GenericScatteringCalculator.ui.autosave | 2031 ----------------- 3 files changed, 82 insertions(+), 2033 deletions(-) delete mode 100644 src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 97e5b9b76f..bf5ce8f42e 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -6,6 +6,7 @@ import time import timeit import periodictable +import time from scipy.spatial.transform import Rotation @@ -83,7 +84,9 @@ def __init__(self, parent=None): self.is_avg = False self.is_nuc = False self.is_mag = False + self.is_beta = False self.data_to_plot = None + self.data_betaQ = None self.graph_num = 1 # index for name of graph # finish UI setup - install qml window @@ -565,7 +568,9 @@ def change_is_avg(self): # update the averaging option fromthe button on the GUI # required as the button may have been previously hidden with # any value, and preserves this - we must update the variable to match the GUI - self.is_avg = (self.cbOptionsCalc.currentIndex() == 1) + self.is_avg = (self.cbOptionsCalc.currentIndex() in (1,2)) + # did user request Beta(Q) calculation? + self.is_beta = (self.cbOptionsCalc.currentIndex() == 2) # If averaging then set to 0 and diable the magnetic SLD textboxes if self.is_avg: self.txtMx.setEnabled(False) @@ -865,7 +870,7 @@ def update_gui(self): if self.nuc_sld_data.is_elements: self.txtROG.setText(str("N/A for Elements")) else: - self.txtROG.setText(str(self.radius_of_gyration())) + self.txtROG.setText(str(round(self.radius_of_gyration(),1)) + " Å") elif self.is_mag: self.txtROG.setText(str("N/A for magnetic data")) else: @@ -1061,8 +1066,10 @@ def onReset(self): # reset all file data to its default empty state self.is_nuc = False self.is_mag = False + self.is_beta = False self.nuc_sld_data = None self.mag_sld_data = None + self.beta_data = None # update the gui for the no files loaded case self.change_data_type() # verify that the new enabled files are compatible @@ -1342,6 +1349,13 @@ def onCompute(self): self.cancelCalculation = False #self.cmdCompute.setEnabled(False) d = threads.deferToThread(self.complete, inputs, self._update) + + # if Beta(Q) Calculation has been requested, run calculation + if self.is_beta: + time.sleep(30) + print("Calculating Beta(Q)...") + self.create_betaPlot() + print("done") # Add deferred callback for call return # d.addCallback(self.plot_1_2d) d.addCallback(self.calculateComplete) @@ -1426,6 +1440,67 @@ def complete(self, input, update=None): self.cmdCompute.clicked.connect(self.onCompute) self.cmdCompute.setEnabled(True) return + + def create_betaPlot(self): + """Carry out the compuation of beta Q using provided & calculated data + Returns a list of BetaQ values + + """ + + #Center Of Mass Calculation + CoM = self.centerOfMass() + betaQ = [] + + # Default values + xmax = self.qmax_x + xmin = self.qmax_x * _Q1D_MIN + qstep = self.npts_x + + fQ = [0 for j in range(self.npts_x)] + currentQValue = [] + for a in range(self.npts_x): + if(self.npts_x == 1): + currentQValue.append(xmin) + else: + currentQValue.append(xmin + (xmax - xmin)/(self.npts_x-1)*a) + formFactor = self.data_to_plot + + print(len(self.data_to_plot)) + + for a in range(self.npts_x): + for b in range(len(self.data.x)): + #atoms + atomName = str(self.nuc_sld_data.pix_symbol[b]) + #Coherent Scattering Length of Atom + cohB = periodictable.elements.symbol(atomName).neutron.b_c + + coordinates = [float(self.nuc_sld_data.pos_x[b]),float(self.nuc_sld_data.pos_y[b]),float(self.nuc_sld_data.pos_z[b])] + + relativeCoordinate = [0.0,0.0,0.0] + relativeCoordinate[0] = coordinates[0] - CoM[0] + relativeCoordinate[1] = coordinates[1] - CoM[1] + relativeCoordinate[2] = coordinates[2] - CoM[2] + + magnitudeRelativeCoordinate = numpy.sqrt(relativeCoordinate[0]**2 + relativeCoordinate[1]**2 + relativeCoordinate[2]**2) + + fQ[a] += (cohB * (numpy.sin(currentQValue[a] * magnitudeRelativeCoordinate) / (currentQValue[a] * magnitudeRelativeCoordinate))) + + + #Beta Q calculation + print('Q Value: '+ str(currentQValue[a])) + print('fQ Value: '+str(fQ[a])) + print('Form Factor Value: '+str(formFactor[a])) + + betaQ.append((fQ[a] **2)/(formFactor[a])) + + print('X length:' + str(len(currentQValue))) + print('Y length:' + str(len(betaQ))) + + scalingFactor = betaQ[0] + for i in range (len(betaQ)): + betaQ[i] = (betaQ[i]/scalingFactor) + + return betaQ def onSaveFile(self): """Save data as .sld file""" diff --git a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui index 973990080c..e5189be3e8 100644 --- a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui +++ b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui @@ -960,6 +960,11 @@ Not editable. Debye full avg. + + + Full avg. w/ β(Q) + + diff --git a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave deleted file mode 100644 index 973990080c..0000000000 --- a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui.autosave +++ /dev/null @@ -1,2031 +0,0 @@ - - - GenericScatteringCalculator - - - - 0 - 0 - 1024 - 625 - - - - - 0 - 0 - - - - - 660 - 550 - - - - - 1150 - 700 - - - - Generic Scattering Calculator - - - - :/res/ball.ico:/res/ball.ico - - - - - - Qt::Horizontal - - - - 3 - 20 - - - - - - - - Qt::Vertical - - - - - - - Qt::Vertical - - - - - - - - false - - - - SLD Data File - - - - - - - - - false - - - - <html><head/><body><p>Nuclear data used to simulate SANS.</p></body></html> - - - Nuclear Data - - - - - - - - - - - - - - - 0 - 0 - - - - - 151 - 0 - - - - - false - - - - Display name of loaded datafile. - - - No File Loaded - - - - - - - - 0 - 0 - - - - - 80 - 23 - - - - - false - - - - <html><head/><body><p>Only .txt, .sld, .vtk and .pdb datafile formats are supported. </p><p>Load Nuclear sld data.</p></body></html> - - - Load - - - false - - - - - - - - false - - - - <html><head/><body><p>Magnetic data used to simulate SANS.</p></body></html> - - - Magnetic Data - - - - - - - - - - - - - - - 0 - 0 - - - - - 151 - 0 - - - - - false - - - - Display name of loaded datafile. - - - No File Loaded - - - - - - - - 0 - 0 - - - - - 80 - 23 - - - - - false - - - - <html><head/><body><p>Only .txt, .omf, .vtk and .sld datafile formats are supported. </p><p>Load Magnetic sld data.</p></body></html> - - - Load - - - false - - - - - - - - false - - - - <html><head/><body><p>Default shape of the sample.</p></body></html> - - - Shape - - - - - - - - 0 - 0 - - - - - false - - - - <html><head/><body><p>Select the default shape of the sample.</p></body></html> - - - - Rectangular - - - - - - - - true - - - - 0 - 0 - - - - - 80 - 23 - - - - - false - - - - <html><head/><body><p>Generate a 3D plot with arrows for the magnetic vectors.</p><p>It is not recommanded for a large number of pixels.</p></body></html> - - - Draw - - - false - - - - - - - - - - - - - 0 - 30 - - - - - false - - - - Verification Error - - - - - - Qt::AlignHCenter - - - true - - - - - - - - false - - - - SLD Pixel Info - - - - - - - false - - - - Number of pixels. -Not editable. - - - No. of Pixels - - - - - - - false - - - - 110 - 27 - - - - - false - - - - 1000 - - - true - - - - - - - - false - - - - Mean SLD - - - - - - - - - false - - - - <html><head/><body><p>Mean value of M<span style=" vertical-align:sub;">x</span> (x-component of the magnetisation vector).</p></body></html> - - - Mx - - - - - - - - 70 - 18 - - - - - false - - - - x component of the magnetization vector in the laboratory xyz frame - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>Mean value of My (y-component of the magnetisation vector).</p></body></html> - - - My - - - - - - - - 70 - 18 - - - - - false - - - - y component of the magnetization vector in the laboratory xyz frame - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>Mean value of M<span style=" vertical-align:sub;">z</span> (z-component of the magnetisation vector).</p></body></html> - - - Mz - - - - - - - - 70 - 18 - - - - - false - - - - z component of the magnetization vector in the laboratory xyz frame - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>Average of the nuclear scattering density.</p></body></html> - - - Nucl. - - - - - - - - 70 - 18 - - - - - false - - - - 6.97e-06 - - - - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> - - - - - - - - - - - - - false - - - - Nodes - - - - - - - - - false - - - - xnodes - - - - - - - - 56 - 18 - - - - - false - - - - 10 - - - - - - - - false - - - - ynodes - - - - - - - - 56 - 18 - - - - - false - - - - 10 - - - - - - - - false - - - - znodes - - - - - - - - 56 - 18 - - - - - false - - - - 10 - - - - - - - - - - - - - false - - - - Step Size - - - - - - - - - false - - - - xstepsize - - - - - - - - 50 - 18 - - - - - false - - - - 6 - - - - - - - - false - - - - Å - - - - - - - - false - - - - ystepsize - - - - - - - - 50 - 18 - - - - - false - - - - 6 - - - - - - - - false - - - - Å - - - - - - - - false - - - - zstepsize - - - - - - - - 50 - 18 - - - - - false - - - - 6 - - - - - - - - false - - - - Å - - - - - - - - - - - - true - - - - 0 - 0 - - - - - false - - - - <html><head/><body><p>Draw a scatter plot for sld profile (without arrows)</p></body></html> - - - Draw Points - - - false - - - - - - - Qt::Horizontal - - - - 7 - 20 - - - - - - - - false - - - - 0 - 0 - - - - - false - - - - <html><head/><body><p>Save the sld data as sld format.</p></body></html> - - - Save SLD Data - - - false - - - - - cmdDrawpoints - cmdSave - lblNoPixels - txtNoPixels - groupBox_5 - groupBox_6 - groupBox_Stepsize - - - - - - - - - - 0 - 0 - - - - - 155 - 23 - - - - - 155 - 26 - - - - <html><head/><body><p>Option of orientation to perform calculations:</p><p>- Scattering calculated for fixed orientation &#8594; 2D output</p><p>- Scattering orientation averaged over all orientations &#8594; 1D output</p><p>This choice is only available for pdb files.</p></body></html> - - - - Fixed orientation - - - - - Debye full avg. - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - false - - - - Q Range - - - - - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">-1</span></p></body></html> - - - - - - - - 0 - 18 - - - - - false - - - - 0.3 - - - - - - - - false - - - - <html><head/><body><p>Maximum value of Q<span style=" vertical-align:sub;">x,y</span>.</p><p>Q<span style=" vertical-align:sub;">x,ymax </span>&isin; ]0, 1000].</p></body></html> - - - Qx (Qy) Max - - - - - - - - false - - - - Number of bins in reciprocal space for the 1D or 2D plot generated by 'Compute'. -Number of Qbins &isin; [2, 1000]. - - - No. of Qx (Qy) bins - - - - - - - - 0 - 18 - - - - - false - - - - 30 - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 75 - 23 - - - - Close the calculator. - - - Close - - - - 17 - 16 - - - - false - - - - - - - - 0 - 0 - - - - - 75 - 23 - - - - Reset the interface to its default values - - - Reset - - - false - - - - - - - - 0 - 0 - - - - - 75 - 23 - - - - Display 'Help' information about the calculator - - - Help - - - false - - - - - - - - 0 - 0 - - - - <html><head/><body><p>Compute the scattering pattern and display 1D or 2D plot depending on the settings.</p></body></html> - - - Compute - - - false - - - - - - - - - - false - - - - Input Parameters - - - - - - QLayout::SetMinimumSize - - - - - - false - - - - Parameter - - - - - - - - false - - - - Value - - - - - - - - false - - - - Unit - - - - - - - - false - - - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - - Up_frac_in - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons after the analyzer.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> - - - 1.0 - - - - - - - - false - - - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - - Up_frac_out - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>Ratio of spin up/(spin up + spin down) neutrons before the sample.</p><p>It must be between 0 and 1.</p><p>It is equal to 0.5 for unpolarized neutrons.</p></body></html> - - - 1.0 - - - - - - - - false - - - - <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - - Up_theta - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>Polarization angle.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p>Polarization angle.</p><p>The editing is disabled if data are from .omf, .sld, .pdb files.</p></body></html> - - - Up_phi - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>Polarization angle.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - 0 - 18 - - - - - false - - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p>cm<span style=" vertical-align:super;">-1</span></p></body></html> - - - - - - - - false - - - - Scale - - - - - - - - 0 - 18 - - - - - false - - - - 1.0 - - - - - - - - false - - - - Solvent_SLD - - - - - - - - 0 - 18 - - - - - false - - - - 0.0 - - - - - - - - false - - - - Default total volume calculated from the pixel information (or natural density for pdb file). - - - Total volume - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>Default total volume calculated from the pixel information (or natural density for pdb file)</p></body></html> - - - 216000.0 - - - - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">3</span></p></body></html> - - - - - - - - false - - - - Background - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - false - - - - <html><head/><body><p>Å<span style=" vertical-align:super;">-2</span></p></body></html> - - - false - - - 0 - - - -1 - - - - - - - - - - - - - false - - - - Coordinate System Info - - - - - - - false - - - - Environment Coordinates (uvw) - - - - - - - false - - - - <html><head/><body><p>The yaw angle of the environment coordinates from the beamline coordinates.</p></body></html> - - - Yaw - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>The yaw angle of the environment coordinates from the beamline coordinates.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>The pitch angle of the environment coordinates from the beamline coordinates.</p></body></html> - - - Pitch - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>The pitch angle of the environment coordinates from the beamline coordinates.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>The roll angle of the environment coordinates from the beamline coordinates.</p></body></html> - - - Roll - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>The roll angle of the environment coordinates from the beamline coordinates.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - - - - false - - - - Sample Coordinates (xyz) - - - - - - - false - - - - <html><head/><body><p>The yaw angle of the sample coordinates from the environment coordinates.</p></body></html> - - - Yaw - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>The yaw angle of the sample coordinates from the environment coordinates.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>The pitch angle of the sample coordinates from the environment coordinates.</p></body></html> - - - Pitch - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>The pitch angle of the sample coordinates from the environment coordinates.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - false - - - - <html><head/><body><p>The roll angle of the sample coordinates from the environment coordinates.</p></body></html> - - - Roll - - - - - - - - 0 - 18 - - - - - false - - - - <html><head/><body><p>The roll angle of the sample coordinates from the enivronment coordinates.</p></body></html> - - - 0.0 - - - - - - - - false - - - - <html><head/><body><p><span style=" vertical-align:super;">o</span></p></body></html> - - - - - - - - - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - - Radius of Gyration - - - - - - - false - - - 0 - - - - - - - - - checkboxNucData - txtNucData - checkboxMagData - txtMagData - cbShape - cmdNucLoad - cmdMagLoad - cmdDraw - txtUpFracIn - txtUpFracOut - txtUpTheta - txtUpPhi - txtBackground - txtScale - txtSolventSLD - txtTotalVolume - txtNoQBins - txtQxMax - cbOptionsCalc - txtNoPixels - txtMx - txtMy - txtMz - txtNucl - cmdDrawpoints - cmdSave - txtXnodes - txtYnodes - txtZnodes - txtXstepsize - txtYstepsize - txtZstepsize - txtEnvYaw - txtEnvPitch - txtEnvRoll - txtSampleYaw - txtSamplePitch - txtSampleRoll - cmdCompute - cmdReset - cmdClose - cmdHelp - - - - From 22a56fd4e0f6c3970c99f39a6a45460345dda69f Mon Sep 17 00:00:00 2001 From: smalex-z Date: Mon, 26 Jun 2023 15:54:12 -0400 Subject: [PATCH 06/10] BetaQ graph added, removing timer + adding threading to be added in the future --- .../GenericScatteringCalculator.py | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index bf5ce8f42e..61905fdaf0 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -1352,7 +1352,7 @@ def onCompute(self): # if Beta(Q) Calculation has been requested, run calculation if self.is_beta: - time.sleep(30) + time.sleep(15) print("Calculating Beta(Q)...") self.create_betaPlot() print("done") @@ -1449,7 +1449,7 @@ def create_betaPlot(self): #Center Of Mass Calculation CoM = self.centerOfMass() - betaQ = [] + self.data_betaQ = [] # Default values xmax = self.qmax_x @@ -1484,23 +1484,19 @@ def create_betaPlot(self): magnitudeRelativeCoordinate = numpy.sqrt(relativeCoordinate[0]**2 + relativeCoordinate[1]**2 + relativeCoordinate[2]**2) fQ[a] += (cohB * (numpy.sin(currentQValue[a] * magnitudeRelativeCoordinate) / (currentQValue[a] * magnitudeRelativeCoordinate))) - - - #Beta Q calculation - print('Q Value: '+ str(currentQValue[a])) - print('fQ Value: '+str(fQ[a])) - print('Form Factor Value: '+str(formFactor[a])) - betaQ.append((fQ[a] **2)/(formFactor[a])) + #Beta Q Calculation + self.data_betaQ.append((fQ[a] **2)/(formFactor[a])) print('X length:' + str(len(currentQValue))) - print('Y length:' + str(len(betaQ))) + print('Y length:' + str(len(self.data_betaQ))) - scalingFactor = betaQ[0] - for i in range (len(betaQ)): - betaQ[i] = (betaQ[i]/scalingFactor) + #Scale Beta Q to 0-1 + scalingFactor = self.data_betaQ[0] + for i in range (len(self.data_betaQ)): + self.data_betaQ[i] = (self.data_betaQ[i]/scalingFactor) - return betaQ + return def onSaveFile(self): """Save data as .sld file""" @@ -1573,6 +1569,14 @@ def plot_1_2d(self): data.yaxis(r'\rm{Intensity}', 'cm^{-1}') self.graph_num += 1 + if self.is_beta: + print("leng x: " + str(len(self.data.x))) + print("leng y: " + str(len(self.data_betaQ))) + dataBetaQ = Data1D(x=self.data.x, y=self.data_betaQ) + dataBetaQ.title = "GenSAS {} #{} BetaQ".format(self.file_name(), + int(self.graph_num)) + dataBetaQ.xaxis(r'\rm{Q_{x}}', r'\AA^{-1}') + dataBetaQ.yaxis(r'\rm{Beta(Q)}', 'cm^{-1}') else: data = Data2D(image=numpy.nan_to_num(self.data_to_plot), qx_data=self.data.qx_data, @@ -1595,6 +1599,10 @@ def plot_1_2d(self): new_item = GuiUtils.createModelItemWithPlot(data, name=data.title) self.communicator.updateModelFromPerspectiveSignal.emit(new_item) self.communicator.forcePlotDisplaySignal.emit([new_item, data]) + if self.is_beta: + new_item = GuiUtils.createModelItemWithPlot(dataBetaQ, name=dataBetaQ.title) + self.communicator.updateModelFromPerspectiveSignal.emit(new_item) + self.communicator.forcePlotDisplaySignal.emit([new_item, dataBetaQ]) class Plotter3DWidget(PlotterBase): """ From 99657f5128cb668031fb75d1ba376519502cdd49 Mon Sep 17 00:00:00 2001 From: smalex-z Date: Tue, 27 Jun 2023 10:26:41 -0400 Subject: [PATCH 07/10] added betaQ calculation to threading, removed temporary test code --- .../GenericScatteringCalculator.py | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 61905fdaf0..6428bb25c8 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -1350,12 +1350,6 @@ def onCompute(self): #self.cmdCompute.setEnabled(False) d = threads.deferToThread(self.complete, inputs, self._update) - # if Beta(Q) Calculation has been requested, run calculation - if self.is_beta: - time.sleep(15) - print("Calculating Beta(Q)...") - self.create_betaPlot() - print("done") # Add deferred callback for call return # d.addCallback(self.plot_1_2d) d.addCallback(self.calculateComplete) @@ -1434,6 +1428,11 @@ def complete(self, input, update=None): out = numpy.hstack(out) self.data_to_plot = out logging.info('Gen computation completed.') + + # if Beta(Q) Calculation has been requested, run calculation + if self.is_beta: + self.create_betaPlot() + self.cmdCompute.setText('Compute') self.cmdCompute.setToolTip("

Compute the scattering pattern and display 1D or 2D plot depending on the settings.

") self.cmdCompute.clicked.disconnect() @@ -1465,8 +1464,6 @@ def create_betaPlot(self): currentQValue.append(xmin + (xmax - xmin)/(self.npts_x-1)*a) formFactor = self.data_to_plot - print(len(self.data_to_plot)) - for a in range(self.npts_x): for b in range(len(self.data.x)): #atoms @@ -1487,9 +1484,6 @@ def create_betaPlot(self): #Beta Q Calculation self.data_betaQ.append((fQ[a] **2)/(formFactor[a])) - - print('X length:' + str(len(currentQValue))) - print('Y length:' + str(len(self.data_betaQ))) #Scale Beta Q to 0-1 scalingFactor = self.data_betaQ[0] @@ -1569,14 +1563,12 @@ def plot_1_2d(self): data.yaxis(r'\rm{Intensity}', 'cm^{-1}') self.graph_num += 1 - if self.is_beta: - print("leng x: " + str(len(self.data.x))) - print("leng y: " + str(len(self.data_betaQ))) + if self.is_beta or self.is_beta is None: dataBetaQ = Data1D(x=self.data.x, y=self.data_betaQ) dataBetaQ.title = "GenSAS {} #{} BetaQ".format(self.file_name(), int(self.graph_num)) - dataBetaQ.xaxis(r'\rm{Q_{x}}', r'\AA^{-1}') - dataBetaQ.yaxis(r'\rm{Beta(Q)}', 'cm^{-1}') + dataBetaQ.xaxis(r'\rm{Q_{x}}', r'\AA^{-1}') + dataBetaQ.yaxis(r'\rm{Beta(Q)}', 'cm^{-1}') else: data = Data2D(image=numpy.nan_to_num(self.data_to_plot), qx_data=self.data.qx_data, From 63f84abe4a5824df0cbbd418be0adecdd8b149a6 Mon Sep 17 00:00:00 2001 From: smalex-z Date: Tue, 27 Jun 2023 16:04:35 -0400 Subject: [PATCH 08/10] fixed BetaQ calculation from previous versions --- src/sas/qtgui/Calculators/GenericScatteringCalculator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 6428bb25c8..32e793241a 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -1464,8 +1464,9 @@ def create_betaPlot(self): currentQValue.append(xmin + (xmax - xmin)/(self.npts_x-1)*a) formFactor = self.data_to_plot - for a in range(self.npts_x): - for b in range(len(self.data.x)): + for a in range(self.npts_x): + + for b in range(len(self.nuc_sld_data.pos_x)): #atoms atomName = str(self.nuc_sld_data.pix_symbol[b]) #Coherent Scattering Length of Atom From 4e3bcf2fb240b2fbfd8bb1b812b654c59b47741e Mon Sep 17 00:00:00 2001 From: smalex-z Date: Tue, 27 Jun 2023 16:08:19 -0400 Subject: [PATCH 09/10] removed import time (used as a test) --- src/sas/qtgui/Calculators/GenericScatteringCalculator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 32e793241a..fa5693d93f 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -6,7 +6,6 @@ import time import timeit import periodictable -import time from scipy.spatial.transform import Rotation From 536ee8a41a2b2fd4531039d0377e3d233a4187f7 Mon Sep 17 00:00:00 2001 From: smalex-z Date: Wed, 28 Jun 2023 12:47:28 -0400 Subject: [PATCH 10/10] made more pythonic + corrected issue with zero/negative sld. --- .../GenericScatteringCalculator.py | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index fa5693d93f..6a8c37c183 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -5,7 +5,6 @@ import logging import time import timeit -import periodictable from scipy.spatial.transform import Rotation @@ -17,10 +16,10 @@ from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import __version__ as mpl_version -from periodictable import * - from twisted.internet import threads +import periodictable + import sas.qtgui.Utilities.GuiUtils as GuiUtils from sas.qtgui.Utilities.GenericReader import GenReader from sasdata.dataloader.data_info import Detector, Source @@ -828,7 +827,7 @@ def update_gui(self): if self.nuc_sld_data.is_elements: self.txtNoPixels.setText(str(len(self.nuc_sld_data.elements))) else: - self.txtNoPixels.setText(str(len(self.nuc_sld_data.sld_n))) + self.txtNoPixels.setText(str(len(self.nuc_sld_data.sld_n))) elif self.is_mag: if self.mag_sld_data.is_elements: self.txtNoPixels.setText(str(len(self.mag_sld_data.elements))) @@ -869,7 +868,7 @@ def update_gui(self): if self.nuc_sld_data.is_elements: self.txtROG.setText(str("N/A for Elements")) else: - self.txtROG.setText(str(round(self.radius_of_gyration(),1)) + " Å") + self.txtROG.setText(self.radius_of_gyration() + " Å") elif self.is_mag: self.txtROG.setText(str("N/A for magnetic data")) else: @@ -888,7 +887,6 @@ def radius_of_gyration(self): RoGNumerator = RoGDenominator = 0.0 for i in range(len(self.nuc_sld_data.pos_x)): - coordinates = [0.0,0.0,0.0] coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] #Coh b - Coherent Scattering Length(fm) @@ -901,29 +899,29 @@ def radius_of_gyration(self): RoGNumerator += cohB * (numpy.power(MagnitudeOfCoM,2)) RoGDenominator += cohB - RoG = numpy.sqrt(RoGNumerator/RoGDenominator) + #Avoid division by zero - May occur through contrast matching + RoG = str(round(numpy.sqrt(RoGNumerator/RoGDenominator),1)) if RoGDenominator != 0 else "NaN" - return (RoG) + return RoG def centerOfMass(self): """Calculate Center of Mass(CoM) of provided atom""" CoMnumerator= [0.0,0.0,0.0] CoMdenominator = [0.0,0.0,0.0] - CoM = [0.0,0.0,0.0] for i in range(len(self.nuc_sld_data.pos_x)): - coordinates = [0.0,0.0,0.0] coordinates = [float(self.nuc_sld_data.pos_x[i]),float(self.nuc_sld_data.pos_y[i]),float(self.nuc_sld_data.pos_z[i])] #Coh b - Coherent Scattering Length(fm) cohB = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c - for i in range(3): #sets CiN - CoMnumerator[i] += (coordinates[i]*cohB) - CoMdenominator[i] += cohB + for j in range(3): #sets CiN + CoMnumerator[j] += (coordinates[j]*cohB) + CoMdenominator[j] += cohB - for i in range(3): - CoM[i] = CoMnumerator[i]/CoMdenominator[i] #center of mass + CoM = [] + for i in range(3): + CoM.append(CoMnumerator[i]/CoMdenominator[i] if CoMdenominator != 0 else 0) #center of mass, test for division by zero return CoM @@ -1454,41 +1452,37 @@ def create_betaPlot(self): xmin = self.qmax_x * _Q1D_MIN qstep = self.npts_x - fQ = [0 for j in range(self.npts_x)] currentQValue = [] - for a in range(self.npts_x): - if(self.npts_x == 1): - currentQValue.append(xmin) - else: - currentQValue.append(xmin + (xmax - xmin)/(self.npts_x-1)*a) formFactor = self.data_to_plot - for a in range(self.npts_x): - + for a in range(self.npts_x): + fQ = 0 + currentQValue.append(xmin + (xmax - xmin)/(self.npts_x-1)*a) + for b in range(len(self.nuc_sld_data.pos_x)): #atoms atomName = str(self.nuc_sld_data.pix_symbol[b]) #Coherent Scattering Length of Atom cohB = periodictable.elements.symbol(atomName).neutron.b_c - coordinates = [float(self.nuc_sld_data.pos_x[b]),float(self.nuc_sld_data.pos_y[b]),float(self.nuc_sld_data.pos_z[b])] - - relativeCoordinate = [0.0,0.0,0.0] - relativeCoordinate[0] = coordinates[0] - CoM[0] - relativeCoordinate[1] = coordinates[1] - CoM[1] - relativeCoordinate[2] = coordinates[2] - CoM[2] + x = float(self.nuc_sld_data.pos_x[b]) + y = float(self.nuc_sld_data.pos_y[b]) + z = float(self.nuc_sld_data.pos_z[b]) + + r_x = x - CoM[0] + r_y = y - CoM[1] + r_z = z - CoM[2] - magnitudeRelativeCoordinate = numpy.sqrt(relativeCoordinate[0]**2 + relativeCoordinate[1]**2 + relativeCoordinate[2]**2) + magnitudeRelativeCoordinate = numpy.sqrt(r_x**2 + r_y**2 + r_z**2) - fQ[a] += (cohB * (numpy.sin(currentQValue[a] * magnitudeRelativeCoordinate) / (currentQValue[a] * magnitudeRelativeCoordinate))) + fQ += (cohB * (numpy.sin(currentQValue[a] * magnitudeRelativeCoordinate) / (currentQValue[a] * magnitudeRelativeCoordinate))) #Beta Q Calculation - self.data_betaQ.append((fQ[a] **2)/(formFactor[a])) + self.data_betaQ.append((fQ**2)/(formFactor[a])) #Scale Beta Q to 0-1 scalingFactor = self.data_betaQ[0] - for i in range (len(self.data_betaQ)): - self.data_betaQ[i] = (self.data_betaQ[i]/scalingFactor) + self.data_betaQ = [x/scalingFactor for x in self.data_betaQ] return @@ -1563,7 +1557,7 @@ def plot_1_2d(self): data.yaxis(r'\rm{Intensity}', 'cm^{-1}') self.graph_num += 1 - if self.is_beta or self.is_beta is None: + if self.is_beta: dataBetaQ = Data1D(x=self.data.x, y=self.data_betaQ) dataBetaQ.title = "GenSAS {} #{} BetaQ".format(self.file_name(), int(self.graph_num))