Skip to content

Commit

Permalink
Merge branch 'release_6.0.0' into 2732-fill-in-whats-new-boxes-for-re…
Browse files Browse the repository at this point in the history
…lease-600-1
  • Loading branch information
lucas-wilkins committed May 23, 2024
2 parents 3e223dc + d263a86 commit a865d83
Show file tree
Hide file tree
Showing 12 changed files with 2,091 additions and 1,607 deletions.
265 changes: 139 additions & 126 deletions src/sas/qtgui/Calculators/GenericScatteringCalculator.py

Large diffs are not rendered by default.

3,020 changes: 1,575 additions & 1,445 deletions src/sas/qtgui/Calculators/UI/GenericScatteringCalculator.ui

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions src/sas/qtgui/Calculators/media/gsc_ex_customModel_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.. gsc_ex_customModel_data.rst
.. _gsc_ex_customModel_data:

Example: Fit the experimental data using the calculated $P(Q)$ from a PDB file
==================================

(Pictures in this document were generated using SasView 6.0.0.) To calculate $P(Q)$ from a PDB file, use the Generic Scattering Calculator in the Tools menu. In this example, a PDB file for apoferritin was downloaded from the PDB data bank (https://www.rcsb.org/structure/6z6u). The custom model function, custom_apoferritinLong, was obtained from the scattering calculator using the Debye full avg. w/ $\beta(Q)$ option after loading the apoferritin PDB file (see print-screen below). Note that the q-range and the number of data points can be customized. The Export Model box should be checked to enable a file name for the custom plugin model that will be produced (custom_apoferritinLong). Clicking "Compute" launches the calculation of $P(Q)$ and $\beta(Q)$, and generate the file into the plugin model directory of the SasView. Once the computation is finished, the plugin model is ready to use to fit scattering data.

.. figure:: gsc_ex_customModel_data_Fig3.jpg

To use the calculated custom apoferritinLong model in Fit panel, one selects "Plugin Models" in the Category box. The custom model should already exist in the SasView directory and can be found in the drop down menu of the "Model name". This custom model, custom_apoferritinLong, returns both the normalized form factor, $\tilde{P}(Q)$, and $\beta(Q)$ caculated using the PDB file. But $\beta(Q)$ is only used if one needs to fit the data with the inter-particle structure factor, $S(Q)$, with the static decoupling approximation.

Warning: when generating the custom plugin model using the Generic Scattering Calculator, please be careful about the following two issues before using it:

1) There should be $enough$ number of data points included in the plugin model. Because the plugin model calculates the theoretical $I(Q)$ by interpolating the data during the fitting, the more data points generated by the Generic Scattering Calculator, the more accurate the theoretical curves is.

2) Because each instrument has a resolution function for each $Q$ value, the theoretical curve needs to be calculated by considering the resolution function. To make the fitting function working properly, the $Q$ range calculated for the plugin model in the Generic Scattering Calculator should be larger than the $Q$ range of the experimental data. If the $Q$ range of theoretical data is too close to (or smaller than) that of the experimental data, the calculated theoretical values may all return as "NaN". When this happens, the plugin model will not function properly to fit experimental data.

The following example is to demonstrate how to fit the data with the calculated form factor.

.. figure:: gsc_ex_customModel_data_Fig1.jpg

The scattering pattern, $I(Q)$, is calculated as

.. math::
I(Q) = \frac{scale}{V}(SLD - SLD_{solvent})^2V_{protein} \tilde{P}(Q\alpha)S_{eff}(Q) + background
$SLD$ is the scattering length density of the protein (or particle). And $SLD\_solvent$ is the scattering length density of solvent.

$V_{protein}$ is the protein volume. If the scattering length density and protein volume are assigned with correct values, $scale$ is the volume fraction of the protein ( or particle).

$\alpha$ is the swelling factor. In general, $\alpha$ should be one (or close to one). The parameter is introduced just in case that there is a slight swelling of the particle.

$S_{eff}(Q)$ is the effective structure factor with

.. math::
S_{eff}(Q) = 1 + \beta(Q\alpha)(S(Q)+1)
And $S(Q)$ is the interparticule structure factor.

For dilute solutions, it is simplified as

.. math::
I(Q) = \frac{scale}{V}(SLD - SLD_{solvent})^2V_{protein} \tilde{P}(Q\alpha) + background
The following figure shows the comparison between one experimental apoferritin protein SANS data of a dilute sample with the calculated $I(Q)$ using this model.

.. figure:: gsc_ex_customModel_data_Fig2.jpg

If one needs to fit concentrated protein solutions, an appropriate structure factor model needs to be chosen. If a protein is anisotropic, one also needs to use the static decoupling approximation. $\beta(Q)$ will be automatially used during the fitting. One fitting parameter to calculate $S(Q)$ using the models available in the SasView is the effective radius that is called radius\_effective in the SasView. One needs to choose how to correlate the effective radius with the size of a protein. Note that the effective radius is related with the interaciton between porteins, and could be different from the radius of a protein/particle. It is therefore ok, and sometimes recommended, to use unconstrained method for the "radius\_effective_mode" since there is no fitting prameter related with the protein size in this custom fitting model. If a protein is nearly spherical such as apoferritin, there is no need to use the static decoupling approximation.


*Document History*

| 2023-10-30 Yun Liu
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 25 additions & 20 deletions src/sas/qtgui/Calculators/media/sas_calculator_help.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.. _SANS_Calculator_Tool:

Generic SANS Calculator Tool
Generic SAS Calculator Tool
============================

Description
Expand Down Expand Up @@ -41,7 +41,7 @@ data), in a variety of shapes, such as tetrahedra, cubes or hexahedra.

The scattering length density (SLD) is assumed uniform for each pixel or
element. Depending on the data format the property is either nuclear (in units
of 10\ :sup:`-6`\ |Ang|:sup:`-2`) (`PDB <PDB Files_>`_ file) or
of |Ang|:sup:`-2`) (`PDB <PDB Files_>`_ file) or
magnetic SLDs (`OMF <OMF Files_>`_ file) or a combination of both
(`SLD <SLD Files_>`_ and `VTK <VTK Files_>`_ files). For magnetic neutron
scattering, the :ref:`magnetism` documentation gives further details and
Expand All @@ -59,9 +59,9 @@ discretized with $N$ 3-dimensional rectangular pixels.
The elastic scattering intensity is defined as

.. math::
I(\mathbf{Q}) = \frac{1}{V}\left\lvert\sum_j^Nv_j\beta_j\exp(i\mathbf{Q}\cdot\mathbf{r_j})\right\rvert^2
I(\mathbf{Q}) = \frac{1}{V}\left\lvert\sum_j^Nv_j\rho_j\exp(i\mathbf{Q}\cdot\mathbf{r_j})\right\rvert^2
where $\beta_j$ and $\mathbf{r}_j$ are the scattering length density and
where $\rho_j$ and $\mathbf{r}_j$ are the scattering length density and
the position of the $j^\text{th}$ pixel respectively.

The total volume $V_s$ of structures different than the homogenous media is
Expand All @@ -71,9 +71,9 @@ equal to
V_s = \sum_j^N v_j
for $\beta_j \ne 0$ where $v_j$ is the volume of the $j^\text{th}$
for $\rho_j \ne 0$ where $v_j$ is the volume of the $j^\text{th}$
pixel or natural atomic volume (for .pdb). For atomic structures
$v_j \beta_j \equiv b_j$ is the scattering length of the $j^\text{th}$ atom and
$v_j \rho_j \equiv b_j$ is the scattering length of the $j^\text{th}$ atom and
the natural atomic volume is given by:

$\frac{\text{atomic mass}}{\text{natural molar density}\times\text{Avogadro number}}$
Expand All @@ -86,11 +86,11 @@ For non-magnetic, grid-type data the 1D orientationally averaged scatting intens
can also be calculated using the *Debye full average* option which uses the Debye formula:

.. math::
I(\left\lvert\mathbf{Q}\right\rvert) = \frac{1}{V}\sum_j^N v_j\beta_j \sum_k^N v_k\beta_k
I(\left\lvert\mathbf{Q}\right\rvert) = \frac{1}{V}\sum_j^N v_j\rho_j \sum_k^N v_k\rho_k
\frac{\sin\left(\left\lvert\mathbf{Q}\right\rvert\left\lvert\mathbf{r_j}-\mathbf{r_k}\right\rvert\right)}
{\left\lvert\mathbf{Q}\right\rvert\left\lvert\mathbf{r_j}-\mathbf{r_k}\right\rvert}
*NOTE:* $\beta_j$ *displayed in the GUI may be incorrect (input
*NOTE:* $\rho_j$ *displayed in the GUI may be incorrect (input
parameter* solvent_SLD *) but this will not affect the scattering computation if
the correction of the total volume V is made.*

Expand All @@ -104,15 +104,15 @@ For example this cube is formed of five finite elements:
:align: center

Each element has an associated scattering length
density ($\beta_j$) for the occupied space $V_j$ and the elastic scattering
density ($\rho_j$) for the occupied space $V_j$ and the elastic scattering
intensity is calculated as

.. math::
I(\mathbf{Q}) = \frac{1}{V}\left\lvert\sum_j^N\beta_j\iiint\limits_{V_j}\exp(i\mathbf{Q}\cdot\mathbf{r_j})\text{d}V\right\rvert^2
I(\mathbf{Q}) = \frac{1}{V}\left\lvert\sum_j^N\rho_j\iiint\limits_{V_j}\exp(i\mathbf{Q}\cdot\mathbf{r_j})\text{d}V\right\rvert^2
Note that the Fourier transform is calculated over each element - allowing
regions of space with little variation in $\beta$ to have larger finite
regions of space with little variation in $\rho$ to have larger finite
elements, and regions of interest to have much smaller finite elements, and
hence more detail.

Expand Down Expand Up @@ -175,7 +175,7 @@ How to use the Tool
-------------------
Upon loading the calculator we are shown the following interface:

.. figure:: gen_gui_help.png
.. figure:: GSC_Oct282023_GUI_Index2.jpg
:align: center

..
Expand Down Expand Up @@ -229,6 +229,7 @@ Inputs
In some circumstances these textboxes will be highlighted orange, as a
warning that with the values chosen numerical artefacts may appear due to
the Nyquist criterion, or simulation box size.
* When calculating 1D data, Q values are evenly spaced in the log scale if "Log Spacing" box is checked.

Information Panel
^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -259,14 +260,17 @@ Information Panel
and the mousewheel used to zoom in and out.
19) This choice appears only for grid type data and without magnetic SLD.
This tool allows to either compute the fully oriented 2D scattering pattern,
or calculating the 1D orientational averaged intensity $I(Q)$ by the Debye
equation.
or calculating the 1D orientational averaged intensity $I(Q)$ by the Debye equation. One can also choose a compuation option, Debye full avg. w/ $\beta(Q)$, to calculate 1D scattering pattern together with $\beta(Q)$. $\beta(Q)$ is needed when fitting scattering patterns of concentrated solutions using the inter-particle structure factor, $S(Q)$, with the static decoupling approximation.
20) Starts the computation of the scattering pattern.
21) Reset GUI to the initial state.


As an example :ref:`here <gsc_ex_default_data>` you can find a simple demonstration of
the functionality of the Generic scattering calculator using the default
22) If a PDB file is loaded, the radius of gyration is calculated and displayed. "Rg-MASS" is the radius of gyration based on the mass of all atoms in a molecule. "RG-SLD" is the radius of gyration based on the scattering length of all atoms.
23) If the option, Debye full avg. w/ $\beta(Q)$, is chosen, one has the option to check the box "Export Model". Once checked, one can input a file name in the box below. During the computation, the program then exports the calculated normalized form factor, $P(Q)$, and $\beta(Q)$ into this file that automatically become a model in the "Plugin Models". The model name is the same as the file name given in the blox below "Export Model".

One example is given here ( Click :ref:`here <gsc_ex_customModel_data>` ) to illustrate how to calculate $P(Q)$ and $\beta(Q)$ using a PDB file of a protein. These are 1D functions after averaging over all orientiations of proteins. The program can generate a custom model function, which can be used to fit the 1D small angle scattering data.


One other example ( Click :ref:`here <gsc_ex_default_data>` ) is a simple demonstration of
the functionality of the Generic scattering calculator to calculate the 2D scattering pattern using the default
starting values with no files loaded.

After computation the result will appear in the
Expand Down Expand Up @@ -370,9 +374,9 @@ the SLD at the centre of each element. This weighted average is given by:

.. math::
\bar{\beta} = \frac{\sum\limits_j^n \beta_j r_j^{\prime -2}}{\sum\limits_j^nr_j^{\prime -2}}
\bar{\rho} = \frac{\sum\limits_j^n \rho_j r_j^{\prime -2}}{\sum\limits_j^nr_j^{\prime -2}}
Where $\bar{\beta}$ is the estimated SLD for an element and $\beta_j$, $r'_j$
Where $\bar{\rho}$ is the estimated SLD for an element and $\rho_j$, $r'_j$
are the SLDs and distances from the centre of the element of each of the $n$
vertices of the element respectively. $r'_j$ is taken as:

Expand Down Expand Up @@ -638,3 +642,4 @@ References

| 2015-05-01 Steve King
| 2021-09-14 Robert Bourne
| 2023-10-30 Yun Liu
26 changes: 11 additions & 15 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,14 @@ def appendLog(self, signal):
(message, record) = signal
self.listWidget.append(message.strip())

# Display log if message is error or worse
if record.levelno >= 40:
# Display log if message is warning (30) or higher
# 10: Debug
# 20: Info
# 30: Warning
# 40: Error
# 50: Critical

if record.levelno >= 30:
self.logDockWidget.setVisible(True)

def createGuiData(self, item, p_file=None):
Expand Down Expand Up @@ -804,7 +810,7 @@ def actionOpen_Analysis(self):
"""
"""
self.filesWidget.loadAnalysis()
pass


def actionSave_Project(self):
"""
Expand Down Expand Up @@ -874,13 +880,11 @@ def actionUndo(self):
"""
"""
print("actionUndo TRIGGERED")
pass

def actionRedo(self):
"""
"""
print("actionRedo TRIGGERED")
pass

def actionCopy(self):
"""
Expand Down Expand Up @@ -917,7 +921,7 @@ def actionReset(self):
logging.warning(" *** actionOpen_Analysis logging *******")
print("actionReset print TRIGGERED")
sys.stderr.write("STDERR - TRIGGERED")
pass


def actionExcel(self):
"""
Expand Down Expand Up @@ -967,7 +971,6 @@ def actionHide_Toolbar(self):
else:
self._workspace.actionHide_Toolbar.setText("Hide Toolbar")
self._workspace.toolBar.setVisible(True)
pass

def actionHide_DataExplorer(self):
"""
Expand All @@ -977,7 +980,6 @@ def actionHide_DataExplorer(self):
self.dockedFilesWidget.setVisible(False)
else:
self.dockedFilesWidget.setVisible(True)
pass

def actionHide_LogExplorer(self):
"""
Expand All @@ -987,13 +989,11 @@ def actionHide_LogExplorer(self):
self.logDockWidget.setVisible(False)
else:
self.logDockWidget.setVisible(True)
pass

def actionStartup_Settings(self):
"""
"""
print("actionStartup_Settings TRIGGERED")
pass

def actionCategory_Manager(self):
"""
Expand Down Expand Up @@ -1119,15 +1119,14 @@ def actionCombine_Batch_Fit(self):
"""
"""
print("actionCombine_Batch_Fit TRIGGERED")
pass


def actionFit_Options(self):
"""
"""
if hasattr(self._current_perspective, "fit_options_widget"):
self.preferences.show()
self.preferences.setMenuByName(self._current_perspective.fit_options_widget.name)
pass

def actionGPU_Options(self):
"""
Expand All @@ -1136,7 +1135,6 @@ def actionGPU_Options(self):
if hasattr(self._current_perspective, "gpu_options_widget"):
self.preferences.show()
self.preferences.setMenuByName(self._current_perspective.gpu_options_widget.name)
pass

def actionFit_Results(self):
"""
Expand Down Expand Up @@ -1246,14 +1244,12 @@ def actionClosePlots(self):
Closes all Plotters and Plotter2Ds.
"""
self.filesWidget.closeAllPlots()
pass

def actionMinimizePlots(self):
"""
Minimizes all Plotters and Plotter2Ds.
"""
self.filesWidget.minimizeAllPlots()
pass

#============ HELP =================
def actionDocumentation(self):
Expand Down

0 comments on commit a865d83

Please sign in to comment.