diff --git a/XAFSmass/XAFSmassQt.py b/XAFSmass/XAFSmassQt.py index 3e783a7..e4fb55a 100644 --- a/XAFSmass/XAFSmassQt.py +++ b/XAFSmass/XAFSmassQt.py @@ -6,6 +6,7 @@ import os import re from functools import partial +from collections import OrderedDict import webbrowser import numpy as np import matplotlib as mpl @@ -115,9 +116,11 @@ def paintEvent(self, event): if self.currentIndex() < 0: painter.setPen(QColor('#888888')) - if self.placeholderText(): - opt.currentText = self.placeholderText() - + try: + if self.placeholderText(): + opt.currentText = self.placeholderText() + except AttributeError: + pass painter.drawControl(myQtGUI.QStyle.CE_ComboBoxLabel, opt) @@ -230,16 +233,25 @@ def __init__(self, parent=None): # self.compoundListsLabel = QLabel("can also be defined from") self.compoundList1 = ComboBoxWithPlaceholder() self.compoundList1.addItems( - [k for k in - dict(sorted(compounds.items(), key=lambda it: it[1]['rho']))]), - self.compoundList1.setPlaceholderText("compounds (sorted by density)") + [k for k in OrderedDict( + sorted(compounds.items(), key=lambda it: it[1]['rho']))]), + try: + self.compoundList1.setPlaceholderText( + "compounds (sorted by density)") + except AttributeError: + pass self.compoundList1.setToolTip("sorted by density") self.compoundList1.setMaxVisibleItems(18) self.compoundList1.setCurrentIndex(-1) self.compoundList1.activated.connect(self.compoundActivated) self.compoundList2 = ComboBoxWithPlaceholder() - self.compoundList2.addItems(elemental.keys()) - self.compoundList2.setPlaceholderText("elements") + self.compoundList2.addItems( + [k for k in OrderedDict( # have to sort it in Py2 + sorted(elemental.items(), key=lambda it: it[1]['Z']))]), + try: + self.compoundList2.setPlaceholderText("elements") + except AttributeError: + pass self.compoundList2.setMaxVisibleItems(18) self.compoundList2.setCurrentIndex(-1) self.compoundList2.activated.connect(self.elementActivated) @@ -603,7 +615,7 @@ def read_energies(self): self.energies.append(pre + edges[ic] + ' ' + c + ' + 50') def compoundActivated(self): - txt = self.compoundList1.currentText() + txt = str(self.compoundList1.currentText()) # otherwise u'' in Py2 self.compoundEdit.setText(compounds[txt]['formula']) if self.what in [POWDER, FOIL]: rho = compounds[txt]['rho'] @@ -614,7 +626,7 @@ def compoundActivated(self): self.calculate() def elementActivated(self): - txt = self.compoundList2.currentText() + txt = str(self.compoundList2.currentText()) # otherwise u'' in Py2 self.compoundEdit.setText(txt) if self.what in [POWDER, FOIL]: rho = elemental[txt]['rho'] @@ -821,7 +833,7 @@ def isWin11(): print("do 'pip install distro' for a better view of Linux" " distro string") elif 'Windows' in locos: - if isWin11: + if isWin11(): locos = 'Winows 11' if use_pyside: diff --git a/XAFSmass/materials_simple.py b/XAFSmass/materials_simple.py index 89c0a18..2042f47 100644 --- a/XAFSmass/materials_simple.py +++ b/XAFSmass/materials_simple.py @@ -49,98 +49,98 @@ 'Pa': 231.036, 'U': 238.039} elemental = dict( - H=dict(name='Hydrogen', elements='H', rho=8.375e-05), - He=dict(name='Helium', elements='He', rho=1.663e-04), - Li=dict(name='Lithium', elements='Li', rho=5.340e-01), - Be=dict(name='Beryllium', elements='Be', rho=1.848e+00), - B=dict(name='Boron', elements='B', rho=2.370e+00), - C=dict(name='Carbon', elements='C', rho=1.700e+00), - N=dict(name='Nitrogen', elements='N', rho=1.165e-03), - O=dict(name='Oxygen', elements='O', rho=1.332e-03), - F=dict(name='Fluorine', elements='F', rho=1.580e-03), - Ne=dict(name='Neon', elements='Ne', rho=8.385e-04), - Na=dict(name='Sodium', elements='Na', rho=9.710e-01), - Mg=dict(name='Magnesium', elements='Mg', rho=1.740e+00), - Al=dict(name='Aluminum', elements='Al', rho=2.699e+00), - Si=dict(name='Silicon', elements='Si', rho=2.330e+00), - P=dict(name='Phosphorus', elements='P', rho=2.200e+00), - S=dict(name='Sulfur', elements='S', rho=2.000e+00), - Cl=dict(name='Chlorine', elements='Cl', rho=2.995e-03), - Ar=dict(name='Argon', elements='Ar', rho=1.662e-03), - K=dict(name='Potassium', elements='K', rho=8.620e-01), - Ca=dict(name='Calcium', elements='Ca', rho=1.550e+00), - Sc=dict(name='Scandium', elements='Sc', rho=2.989e+00), - Ti=dict(name='Titanium', elements='Ti', rho=4.540e+00), - V=dict(name='Vanadium', elements='V', rho=6.110e+00), - Cr=dict(name='Chromium', elements='Cr', rho=7.180e+00), - Mn=dict(name='Manganese', elements='Mn', rho=7.440e+00), - Fe=dict(name='Iron', elements='Fe', rho=7.874e+00), - Co=dict(name='Cobalt', elements='Co', rho=8.900e+00), - Ni=dict(name='Nickel', elements='Ni', rho=8.902e+00), - Cu=dict(name='Copper', elements='Cu', rho=8.960e+00), - Zn=dict(name='Zinc', elements='Zn', rho=7.133e+00), - Ga=dict(name='Gallium', elements='Ga', rho=5.904e+00), - Ge=dict(name='Germanium', elements='Ge', rho=5.323e+00), - As=dict(name='Arsenic', elements='As', rho=5.730e+00), - Se=dict(name='Selenium', elements='Se', rho=4.500e+00), - Br=dict(name='Bromine', elements='Br', rho=7.072e-03), - Kr=dict(name='Krypton', elements='Kr', rho=3.478e-03), - Rb=dict(name='Rubidium', elements='Rb', rho=1.532e+00), - Sr=dict(name='Strontium', elements='Sr', rho=2.540e+00), - Y=dict(name='Yttrium', elements='Y', rho=4.469e+00), - Zr=dict(name='Zirconium', elements='Zr', rho=6.506e+00), - Nb=dict(name='Niobium', elements='Nb', rho=8.570e+00), - Mo=dict(name='Molybdenum', elements='Mo', rho=1.022e+01), - Tc=dict(name='Technetium', elements='Tc', rho=1.150e+01), - Ru=dict(name='Ruthenium', elements='Ru', rho=1.241e+01), - Rh=dict(name='Rhodium', elements='Rh', rho=1.241e+01), - Pd=dict(name='Palladium', elements='Pd', rho=1.202e+01), - Ag=dict(name='Silver', elements='Ag', rho=1.050e+01), - Cd=dict(name='Cadmium', elements='Cd', rho=8.650e+00), - In=dict(name='Indium', elements='In', rho=7.310e+00), - Sn=dict(name='Tin', elements='Sn', rho=7.310e+00), - Sb=dict(name='Antimony', elements='Sb', rho=6.691e+00), - Te=dict(name='Tellurium', elements='Te', rho=6.240e+00), - I=dict(name='Iodine', elements='I', rho=4.930e+00), - Xe=dict(name='Xenon', elements='Xe', rho=5.485e-03), - Cs=dict(name='Cesium', elements='Cs', rho=1.873e+00), - Ba=dict(name='Barium', elements='Ba', rho=3.500e+00), - La=dict(name='Lanthanum', elements='La', rho=6.154e+00), - Ce=dict(name='Cerium', elements='Ce', rho=6.657e+00), - Pr=dict(name='Praseodymium', elements='Pr', rho=6.710e+00), - Nd=dict(name='Neodymium', elements='Nd', rho=6.900e+00), - Pm=dict(name='Promethium', elements='Pm', rho=7.220e+00), - Sm=dict(name='Samarium', elements='Sm', rho=7.460e+00), - Eu=dict(name='Europium', elements='Eu', rho=5.243e+00), - Gd=dict(name='Gadolinium', elements='Gd', rho=7.900e+00), - Tb=dict(name='Terbium', elements='Tb', rho=8.229e+00), - Dy=dict(name='Dysprosium', elements='Dy', rho=8.550e+00), - Ho=dict(name='Holmium', elements='Ho', rho=8.795e+00), - Er=dict(name='Erbium', elements='Er', rho=9.066e+00), - Tm=dict(name='Thulium', elements='Tm', rho=9.321e+00), - Yb=dict(name='Ytterbium', elements='Yb', rho=6.730e+00), - Lu=dict(name='Lutetium', elements='Lu', rho=9.840e+00), - Hf=dict(name='Hafnium', elements='Hf', rho=1.331e+01), - Ta=dict(name='Tantalum', elements='Ta', rho=1.665e+01), - W=dict(name='Tungsten', elements='W', rho=1.930e+01), - Re=dict(name='Rhenium', elements='Re', rho=2.102e+01), - Os=dict(name='Osmium', elements='Os', rho=2.257e+01), - Ir=dict(name='Iridium', elements='Ir', rho=2.242e+01), - Pt=dict(name='Platinum', elements='Pt', rho=2.145e+01), - Au=dict(name='Gold', elements='Au', rho=1.932e+01), - Hg=dict(name='Mercury', elements='Hg', rho=1.355e+01), - Tl=dict(name='Thallium', elements='Tl', rho=1.172e+01), - Pb=dict(name='Lead', elements='Pb', rho=1.135e+01), - Bi=dict(name='Bismuth', elements='Bi', rho=9.747e+00), - Po=dict(name='Polonium', elements='Po', rho=9.320e+00), - At=dict(name='Astatine', elements='At', rho=8.91e+00), - Rn=dict(name='Radon', elements='Rn', rho=9.066e-03), - Fr=dict(name='Francium', elements='Fr', rho=2.48e+00), - Ra=dict(name='Radium', elements='Ra', rho=5.000e+00), - Ac=dict(name='Actinium', elements='Ac', rho=1.007e+01), - Th=dict(name='Thorium', elements='Th', rho=1.172e+01), - Pa=dict(name='Protactinium', elements='Pa', rho=1.537e+01), - U=dict(name='Uranium', elements='U', rho=1.895e+01), + H=dict(Z=1, name='Hydrogen', elements='H', rho=8.375e-05), + He=dict(Z=2, name='Helium', elements='He', rho=1.663e-04), + Li=dict(Z=3, name='Lithium', elements='Li', rho=5.340e-01), + Be=dict(Z=4, name='Beryllium', elements='Be', rho=1.848e+00), + B=dict(Z=5, name='Boron', elements='B', rho=2.370e+00), + C=dict(Z=6, name='Carbon', elements='C', rho=1.700e+00), + N=dict(Z=7, name='Nitrogen', elements='N', rho=1.165e-03), + O=dict(Z=8, name='Oxygen', elements='O', rho=1.332e-03), + F=dict(Z=9, name='Fluorine', elements='F', rho=1.580e-03), + Ne=dict(Z=10, name='Neon', elements='Ne', rho=8.385e-04), + Na=dict(Z=11, name='Sodium', elements='Na', rho=9.710e-01), + Mg=dict(Z=12, name='Magnesium', elements='Mg', rho=1.740e+00), + Al=dict(Z=13, name='Aluminum', elements='Al', rho=2.699e+00), + Si=dict(Z=14, name='Silicon', elements='Si', rho=2.330e+00), + P=dict(Z=15, name='Phosphorus', elements='P', rho=2.200e+00), + S=dict(Z=16, name='Sulfur', elements='S', rho=2.000e+00), + Cl=dict(Z=17, name='Chlorine', elements='Cl', rho=2.995e-03), + Ar=dict(Z=18, name='Argon', elements='Ar', rho=1.662e-03), + K=dict(Z=19, name='Potassium', elements='K', rho=8.620e-01), + Ca=dict(Z=20, name='Calcium', elements='Ca', rho=1.550e+00), + Sc=dict(Z=21, name='Scandium', elements='Sc', rho=2.989e+00), + Ti=dict(Z=22, name='Titanium', elements='Ti', rho=4.540e+00), + V=dict(Z=23, name='Vanadium', elements='V', rho=6.110e+00), + Cr=dict(Z=24, name='Chromium', elements='Cr', rho=7.180e+00), + Mn=dict(Z=25, name='Manganese', elements='Mn', rho=7.440e+00), + Fe=dict(Z=26, name='Iron', elements='Fe', rho=7.874e+00), + Co=dict(Z=27, name='Cobalt', elements='Co', rho=8.900e+00), + Ni=dict(Z=28, name='Nickel', elements='Ni', rho=8.902e+00), + Cu=dict(Z=29, name='Copper', elements='Cu', rho=8.960e+00), + Zn=dict(Z=30, name='Zinc', elements='Zn', rho=7.133e+00), + Ga=dict(Z=31, name='Gallium', elements='Ga', rho=5.904e+00), + Ge=dict(Z=32, name='Germanium', elements='Ge', rho=5.323e+00), + As=dict(Z=33, name='Arsenic', elements='As', rho=5.730e+00), + Se=dict(Z=34, name='Selenium', elements='Se', rho=4.500e+00), + Br=dict(Z=35, name='Bromine', elements='Br', rho=7.072e-03), + Kr=dict(Z=36, name='Krypton', elements='Kr', rho=3.478e-03), + Rb=dict(Z=37, name='Rubidium', elements='Rb', rho=1.532e+00), + Sr=dict(Z=38, name='Strontium', elements='Sr', rho=2.540e+00), + Y=dict(Z=39, name='Yttrium', elements='Y', rho=4.469e+00), + Zr=dict(Z=40, name='Zirconium', elements='Zr', rho=6.506e+00), + Nb=dict(Z=41, name='Niobium', elements='Nb', rho=8.570e+00), + Mo=dict(Z=42, name='Molybdenum', elements='Mo', rho=1.022e+01), + Tc=dict(Z=43, name='Technetium', elements='Tc', rho=1.150e+01), + Ru=dict(Z=44, name='Ruthenium', elements='Ru', rho=1.241e+01), + Rh=dict(Z=45, name='Rhodium', elements='Rh', rho=1.241e+01), + Pd=dict(Z=46, name='Palladium', elements='Pd', rho=1.202e+01), + Ag=dict(Z=47, name='Silver', elements='Ag', rho=1.050e+01), + Cd=dict(Z=48, name='Cadmium', elements='Cd', rho=8.650e+00), + In=dict(Z=49, name='Indium', elements='In', rho=7.310e+00), + Sn=dict(Z=50, name='Tin', elements='Sn', rho=7.310e+00), + Sb=dict(Z=51, name='Antimony', elements='Sb', rho=6.691e+00), + Te=dict(Z=52, name='Tellurium', elements='Te', rho=6.240e+00), + I=dict(Z=53, name='Iodine', elements='I', rho=4.930e+00), + Xe=dict(Z=54, name='Xenon', elements='Xe', rho=5.485e-03), + Cs=dict(Z=55, name='Cesium', elements='Cs', rho=1.873e+00), + Ba=dict(Z=56, name='Barium', elements='Ba', rho=3.500e+00), + La=dict(Z=57, name='Lanthanum', elements='La', rho=6.154e+00), + Ce=dict(Z=58, name='Cerium', elements='Ce', rho=6.657e+00), + Pr=dict(Z=59, name='Praseodymium', elements='Pr', rho=6.710e+00), + Nd=dict(Z=60, name='Neodymium', elements='Nd', rho=6.900e+00), + Pm=dict(Z=61, name='Promethium', elements='Pm', rho=7.220e+00), + Sm=dict(Z=62, name='Samarium', elements='Sm', rho=7.460e+00), + Eu=dict(Z=63, name='Europium', elements='Eu', rho=5.243e+00), + Gd=dict(Z=64, name='Gadolinium', elements='Gd', rho=7.900e+00), + Tb=dict(Z=65, name='Terbium', elements='Tb', rho=8.229e+00), + Dy=dict(Z=66, name='Dysprosium', elements='Dy', rho=8.550e+00), + Ho=dict(Z=67, name='Holmium', elements='Ho', rho=8.795e+00), + Er=dict(Z=68, name='Erbium', elements='Er', rho=9.066e+00), + Tm=dict(Z=69, name='Thulium', elements='Tm', rho=9.321e+00), + Yb=dict(Z=70, name='Ytterbium', elements='Yb', rho=6.730e+00), + Lu=dict(Z=71, name='Lutetium', elements='Lu', rho=9.840e+00), + Hf=dict(Z=72, name='Hafnium', elements='Hf', rho=1.331e+01), + Ta=dict(Z=73, name='Tantalum', elements='Ta', rho=1.665e+01), + W=dict(Z=74, name='Tungsten', elements='W', rho=1.930e+01), + Re=dict(Z=75, name='Rhenium', elements='Re', rho=2.102e+01), + Os=dict(Z=76, name='Osmium', elements='Os', rho=2.257e+01), + Ir=dict(Z=77, name='Iridium', elements='Ir', rho=2.242e+01), + Pt=dict(Z=78, name='Platinum', elements='Pt', rho=2.145e+01), + Au=dict(Z=79, name='Gold', elements='Au', rho=1.932e+01), + Hg=dict(Z=80, name='Mercury', elements='Hg', rho=1.355e+01), + Tl=dict(Z=81, name='Thallium', elements='Tl', rho=1.172e+01), + Pb=dict(Z=82, name='Lead', elements='Pb', rho=1.135e+01), + Bi=dict(Z=83, name='Bismuth', elements='Bi', rho=9.747e+00), + Po=dict(Z=84, name='Polonium', elements='Po', rho=9.320e+00), + At=dict(Z=85, name='Astatine', elements='At', rho=8.91e+00), + Rn=dict(Z=86, name='Radon', elements='Rn', rho=9.066e-03), + Fr=dict(Z=87, name='Francium', elements='Fr', rho=2.48e+00), + Ra=dict(Z=88, name='Radium', elements='Ra', rho=5.000e+00), + Ac=dict(Z=89, name='Actinium', elements='Ac', rho=1.007e+01), + Th=dict(Z=90, name='Thorium', elements='Th', rho=1.172e+01), + Pa=dict(Z=91, name='Protactinium', elements='Pa', rho=1.537e+01), + U=dict(Z=92, name='Uranium', elements='U', rho=1.895e+01), ) compounds = dict(