Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated rG&rg #2548

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions src/sas/qtgui/Calculators/GenericScatteringCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def __init__(self, parent=None):
self.txtMy.textChanged.connect(self.check_for_magnetic_controls)
self.txtMz.textChanged.connect(self.check_for_magnetic_controls)

#check for SLD changes
#TODO: Implement a scientifically sound method for obtaining protein volume - Current value is a inprecise approximation. Until then Solvent SLD does not impact RG - SLD.
# self.txtSolventSLD.editingFinished.connect(self.update_Rg)

#update coord display
self.txtEnvYaw.textChanged.connect(self.update_coords)
self.txtEnvPitch.textChanged.connect(self.update_coords)
Expand Down Expand Up @@ -862,47 +866,80 @@ def update_gui(self):
self.txtYstepsize.setText(GuiUtils.formatValue(self.mag_sld_data.ystepsize))
self.txtZstepsize.setText(GuiUtils.formatValue(self.mag_sld_data.zstepsize))
# otherwise leave as set since editable by user
self.update_Rg()

# 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)
krzywon marked this conversation as resolved.
Show resolved Hide resolved

def update_Rg(self):
# update the value of the Radius of Gyration with values from the loaded data
if self.is_nuc:
krzywon marked this conversation as resolved.
Show resolved Hide resolved
if self.nuc_sld_data.is_elements:
self.txtROG.setText(str("N/A for Elements"))
self.txtRgMass.setText(str("N/A"))
self.txtRG.setText(str("N/A "))
logging.info("SasView does not support computation of Radius of Gyration for elements.")
else:
self.txtROG.setText(self.radius_of_gyration() + " Å")
threads.deferToThread(self.radius_of_gyration)

elif self.is_mag:
self.txtROG.setText(str("N/A for magnetic data"))
self.txtRgMass.setText(str("N/A"))
self.txtRG.setText(str("N/A"))
logging.info("SasView does not support computation of Radius of Gyration for Magnetic Data.")
else:
self.txtROG.setText(str("N/A for no data"))
self.txtRgMass.setText(str("No Data"))
self.txtRG.setText(str("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
RGNumerator = RGDenominator = RgMassNum = RgMassDen = 0.0

for i in range(len(self.nuc_sld_data.pos_x)):
krzywon marked this conversation as resolved.
Show resolved Hide resolved
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])]
atom = periodictable.formula(self.nuc_sld_data.pix_symbol[i])

#Coh b - Coherent Scattering Length(fm)
cohB = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c
mass = atom.mass

#adjust for solvent sld
sld = periodictable.elements.symbol(self.nuc_sld_data.pix_symbol[i]).neutron.b_c #fentometer
solvent_sld = (atom.volume() * 10**24 * float(self.txtSolventSLD.text())) * 10**5 #vol in cm^3, solventSLD in Angstrom^-2 NOTE: atom.volume() is an approximation, will not work accurately


#TODO: Implement a scientifically sound method for obtaining protein volume - Current value is a inprecise approximation. Until then Solvent SLD does not impact RG - SLD.
# contrastSLD = sld - solvent_sld #fentometer
contrastSLD = sld #fentometer

#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
#Calculate Rate of Gyration (Squared) with the formula
RgMassNum += mass * (numpy.power(MagnitudeOfCoM,2))
RgMassDen += mass
RGNumerator += contrastSLD * (numpy.power(MagnitudeOfCoM,2))
RGDenominator += contrastSLD

#Avoid division by zero - May occur through contrast matching
RoG = str(round(numpy.sqrt(RoGNumerator/RoGDenominator),1)) if RoGDenominator != 0 else "NaN"
if RgMassDen <= 0: #Should never happen as there are no zero or negative mass atoms
rgMassValue = "NaN"
logging.warning("Atomic Mass is zero for all atoms in the system.")
else:
rgMassValue = (str(round(numpy.sqrt(RgMassNum/RgMassDen),1)) + " Å")

return RoG
#Avoid division by zero - May occur through contrast matching
if RGDenominator == 0:
rGValue = "NaN"
logging.warning("Effective Coherent Scattering Length is zero for all atoms in the system.")
elif (RGNumerator/RGDenominator) < 0:
rGValue = (str(round(numpy.sqrt(-RGNumerator/RGDenominator),1)) + " Å")
logging.warning("Radius of Gyration Squared is negative. R(G)^2 is assumed to be |R(G)|* R(G).")
else:
rGValue = (str(round(numpy.sqrt(RGNumerator/RGDenominator),1)) + " Å")

self.txtRgMass.setText(rgMassValue)
self.txtRG.setText(rGValue)

def centerOfMass(self):
"""Calculate Center of Mass(CoM) of provided atom"""
Expand Down
Loading