diff --git a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py index 90158959ec..6a8c37c183 100644 --- a/src/sas/qtgui/Calculators/GenericScatteringCalculator.py +++ b/src/sas/qtgui/Calculators/GenericScatteringCalculator.py @@ -18,6 +18,8 @@ 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 @@ -80,7 +82,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 @@ -562,7 +566,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) @@ -857,10 +863,69 @@ 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(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 + CoM = self.centerOfMass() + + #Now Calculate RoG + RoGNumerator = RoGDenominator = 0.0 + + for i in range(len(self.nuc_sld_data.pos_x)): + 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 + + #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 + + #Avoid division by zero - May occur through contrast matching + RoG = str(round(numpy.sqrt(RoGNumerator/RoGDenominator),1)) if RoGDenominator != 0 else "NaN" + + 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] + + for i in range(len(self.nuc_sld_data.pos_x)): + 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 j in range(3): #sets CiN + CoMnumerator[j] += (coordinates[j]*cohB) + CoMdenominator[j] += cohB + + 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 + + def update_geometry_effects(self): """This function updates the number of pixels and total volume when the number of nodes/stepsize is changed @@ -998,8 +1063,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 @@ -1279,6 +1346,7 @@ def onCompute(self): self.cancelCalculation = False #self.cmdCompute.setEnabled(False) d = threads.deferToThread(self.complete, inputs, self._update) + # Add deferred callback for call return # d.addCallback(self.plot_1_2d) d.addCallback(self.calculateComplete) @@ -1357,12 +1425,66 @@ 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() 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() + self.data_betaQ = [] + + # Default values + xmax = self.qmax_x + xmin = self.qmax_x * _Q1D_MIN + qstep = self.npts_x + + currentQValue = [] + formFactor = self.data_to_plot + + 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 + + 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(r_x**2 + r_y**2 + r_z**2) + + fQ += (cohB * (numpy.sin(currentQValue[a] * magnitudeRelativeCoordinate) / (currentQValue[a] * magnitudeRelativeCoordinate))) + + #Beta Q Calculation + self.data_betaQ.append((fQ**2)/(formFactor[a])) + + #Scale Beta Q to 0-1 + scalingFactor = self.data_betaQ[0] + self.data_betaQ = [x/scalingFactor for x in self.data_betaQ] + + return def onSaveFile(self): """Save data as .sld file""" @@ -1435,6 +1557,12 @@ def plot_1_2d(self): data.yaxis(r'\rm{Intensity}', 'cm^{-1}') self.graph_num += 1 + 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)) + 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, @@ -1457,6 +1585,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): """ diff --git a/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui b/src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui index 0eccfce6e8..e5189be3e8 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,57 @@ 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. + + + + + Full avg. w/ β(Q) + + + + + + Qt::Horizontal - 3 + 40 20 @@ -948,80 +993,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 +1028,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 +1077,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> + + + + + + + + + + + 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 + - 0.0 + 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 +1320,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 +1356,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 +1404,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 +1542,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 +1621,10 @@ Number of Qbins &isin; [2, 1000]. - - - - Qt::Vertical - - - - 50 false @@ -1513,7 +1636,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1525,7 +1647,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1547,7 +1668,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1563,7 +1683,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1576,7 +1695,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1598,7 +1716,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1614,7 +1731,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1627,7 +1743,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1649,7 +1764,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1665,7 +1779,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1681,7 +1794,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1693,7 +1805,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1715,7 +1826,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1731,7 +1841,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1744,7 +1853,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1766,7 +1874,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1782,7 +1889,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1795,7 +1901,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1817,7 +1922,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1833,7 +1937,6 @@ Number of Qbins &isin; [2, 1000]. - 50 false @@ -1848,9 +1951,6 @@ Number of Qbins &isin; [2, 1000]. - - - @@ -1864,212 +1964,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 - - -