| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 Pavlo V. Solntsev |
| 4 | ** All rights reserved. |
| 5 | ** Contact: [email protected] |
| 6 | ** |
| 7 | ** This file is part of the ShelXle |
| 8 | ** |
| 9 | ** This file may be used under the terms of the GNU Lesser |
| 10 | ** General Public License version 2.1 as published by the Free Software |
| 11 | ** Foundation and appearing in the file COPYING included in the |
| 12 | ** packaging of this file. Please review the following information to |
| 13 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
| 14 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 15 | ** |
| 16 | ** |
| 17 | ****************************************************************************/ |
| 18 | #ifndef CALCULATOR_H |
| 19 | #define CALCULATOR_H |
| 20 | |
| 21 | #include <QDialog> |
| 22 | #include <QPushButton> |
| 23 | #include <QVBoxLayout> |
| 24 | #include <QTableWidget> |
| 25 | #include <QGridLayout> |
| 26 | #include <QLabel> |
| 27 | #include <QLineEdit> |
| 28 | #include <QDialogButtonBox> |
| 29 | #include <QList> |
| 30 | #include <QPair> |
| 31 | #include <QStringList> |
| 32 | #include <QComboBox> |
| 33 | #include <QDoubleSpinBox> |
| 34 | #include <QString> |
| 35 | #include <cmath> |
| 36 | #include "molecule.h" |
| 37 | // some compilers do not have M_PI defined |
| 38 | #ifndef M_PI |
| 39 | #define M_PI 3.14159265358979323846 |
| 40 | #endif |
| 41 | |
| 42 | #define DEG2RAD(x) M_PI/180*x |
| 43 | #define RAD2DEG(x) 180/M_PI*x |
| 44 | |
| 45 | #define NM2EV(x) 12398.41858/x |
| 46 | #define NM2KEV(x) 12.39841858/x |
| 47 | #define EV2NM(x) 12398.41858/x |
| 48 | #define KEV2NM(x) 12.39841858/x |
| 49 | |
| 50 | //! XraySource class holds information about source of radiation |
| 51 | /*! |
| 52 | The class is designed to store information about source. For now, |
| 53 | it supports only one wavelength, but in the future it may and should |
| 54 | be redisigned to hold all components of K edge radiation. |
| 55 | */ |
| 56 | class XraySource |
| 57 | { |
| 58 | public: |
| 59 | //! A source of the radiation |
| 60 | /*! Predefined sources that can be supported by the class */ |
| 61 | enum Sources{ |
| 62 | INPUT = 0, /*! Information from the input file */ |
| 63 | Mg, |
| 64 | Al, |
| 65 | Si, |
| 66 | Cr, /*! Cr radiation */ |
| 67 | Mn, |
| 68 | Fe, |
| 69 | Co, |
| 70 | Ni, |
| 71 | Cu, /*! Cu radiation */ |
| 72 | Ga, /*! Ga radiation (for metal jet) */ |
| 73 | Zr, |
| 74 | Mo, /*! Mo radiation */ |
| 75 | Ag, /*! Ag radiation */ |
| 76 | In, |
| 77 | CUSTOM |
| 78 | }; |
| 79 | // Do not change this order (!) |
| 80 | enum XrayType { |
| 81 | WAVELENGTH= 0, |
| 82 | KALPHA1, |
| 83 | KALPHA2, |
| 84 | KBETA1, |
| 85 | KBETA3 |
| 86 | }; |
| 87 | //! Contstructor to create the object. |
| 88 | XraySource(XraySource::Sources source = Mo); |
| 89 | ~XraySource(){} |
| 90 | inline QString name()const{return _name;} |
| 91 | double wavelength(XraySource::XrayType type = WAVELENGTH)const; |
| 92 | |
| 93 | private: |
| 94 | QString _name; //!< Name of the X-ray source. Available values: INPUT, Mo, Cu, Ag, Cr |
| 95 | double _Kalpha1; |
| 96 | double _Kalpha2; |
| 97 | double _Kbeta1; |
| 98 | double _Kbeta3; |
| 99 | }; |
| 100 | |
| 101 | //! Calculator class desinged to support a dialog for Crystallographic Calculator |
| 102 | /*! |
| 103 | A main class for Crystallographic Calculator. |
| 104 | */ |
| 105 | class Calculator : public QWidget |
| 106 | { |
| 107 | Q_OBJECT |
| 108 | public: |
| 109 | //! Constructor to initiate the class. |
| 110 | /*! |
| 111 | Wavelength from the SHELX file should be provided. |
| 112 | */ |
| 113 | explicit Calculator(QString cellLine, QWidget *parent = 0); |
| 114 | //! Wavelength can be changed using this method |
| 115 | /*! |
| 116 | \param wavelength is a wavelength of the X-ray source. |
| 117 | */ |
| 118 | inline void setwavelength(double &wavelength){lambda = wavelength;} |
| 119 | //! Wavelength can be changed using this method |
| 120 | /*! |
| 121 | \param wavelength is a wavelength of the X-ray source. |
| 122 | */ |
| 123 | // inline void setwavelength(double wavelength){lambda = wavelength;} |
| 124 | //! Wavelength can be changed using this method |
| 125 | /*! |
| 126 | \param wavelength is a wavelength of the X-ray source. |
| 127 | */ |
| 128 | inline void setwavelength(const double &wavelength){lambda = wavelength;} |
| 129 | //! Wavelength can be changed using this method |
| 130 | /*! |
| 131 | \param wavelength is a wavelength of the X-ray source. |
| 132 | */ |
| 133 | inline void setwavelength(const double wavelength){lambda = wavelength;} |
| 134 | virtual ~Calculator(); |
| 135 | signals: |
| 136 | void currentCellrequest(); |
| 137 | |
| 138 | public slots: |
| 139 | void dresline_changed(); //!< Update values if dresline has been changed |
| 140 | void sinthoverlmline_changed(); //!< Update values if sin(theta)/lambda has been changed |
| 141 | void thetaline_changed(); //!< Update values if Theta has been changed |
| 142 | void twothetaline_changed(); //!< Update values if 2Theta has been changed |
| 143 | void wl_changed(int a); //!< Update values if X-ray source has been changed |
| 144 | void wl_type_changed(int a); //!< Update values for current wavelength |
| 145 | void wl_custom_changed(); //!< manual wavelength setup |
| 146 | |
| 147 | void d1line_changed(); //!< Update values if d1 has been changed |
| 148 | void d2line_changed(); //!< Update values if d2 has been changed |
| 149 | void angleline_changed(); //!< Update values if angle has been changed |
| 150 | void dline_changed(); //!< Update angle if d distance was changed. d1 and d2 remain the same |
| 151 | void wlcellChanged(); |
| 152 | void changeWlCell(); |
| 153 | void hkl2stl2(); |
| 154 | void hKLChanged(); |
| 155 | void changeHKLEdit(); |
| 156 | void setHKLEdit(QString text); |
| 157 | |
| 158 | private: |
| 159 | QVBoxLayout *mainvlayout; //!< Main container to keep buttons and tab widget |
| 160 | QDialogButtonBox *buttonBox; //!< Container for dialog button |
| 161 | QPushButton *CloseButton; //!< Close button |
| 162 | QTabWidget *tabwidget; //!< A tab widget |
| 163 | QGridLayout *resgrid; //!< Layout for resolution page of the tab widget |
| 164 | |
| 165 | QLabel *dres; //!< d obtained from Bregs law: 2dsin(Theta) = labda |
| 166 | QLabel *sinthoverlm; //!< Sin(Theta)/labda is the same as 1/(2d) obtained from Bregs law: 2dsin(Theta) = 1 labda |
| 167 | QLabel *theta; //!< Theta angle |
| 168 | QLabel *twotheta; //!< 2Theta angle |
| 169 | QLabel *sourcelabel; //!< Wavelength selector |
| 170 | |
| 171 | QLineEdit *dresline; //!< input line for dres. |
| 172 | QLineEdit *sinthoverlmline; //!< input line for sin(Theta)/lambda |
| 173 | QLineEdit *thetaline; //!< input line for theta angle |
| 174 | QLineEdit *twothetaline; //!< input line for 2theta angle |
| 175 | QStringList *wllist; //!< String list to store wavelength sources for the dialog |
| 176 | QStringList *xraytype; //!< Type of X-ray wave: Kalpha1,Kalpha2, etc |
| 177 | QList<XraySource> *wavelist; //!< Interal container to store wavelengths |
| 178 | QComboBox *wavebox; //!< Widget to select an appropriate source |
| 179 | QComboBox *xraytypebox; //!< Widget to select an appropriate type of radiation |
| 180 | QLineEdit *waveline; //!< line to output wavelength number |
| 181 | QLabel *dangpicturelabel; //!< widget to hold a picture for dang |
| 182 | |
| 183 | // private members for resolution tab |
| 184 | double lambda; //!< wavelength |
| 185 | double _dres; //!< Resolution |
| 186 | double _sintl; //!< sin(theta)/lambda |
| 187 | double _theta; //!< theta angle |
| 188 | double _twotheta; //!< 2theta angle |
| 189 | double _shelxlambda; //!< Wavelength from the SHELX file |
| 190 | // 1-3 Distances tab setup |
| 191 | QVBoxLayout *danglayout; //!< Main layout for DANG tab page |
| 192 | QGridLayout *danggrid; //!< 1-3 distances page (a la DANG) |
| 193 | QLabel *d1label; //!< A label for d1 distance |
| 194 | QLabel *d2label; //!< A label for d2 distance |
| 195 | QLabel *angle; //!< Angle to be restrained |
| 196 | QLabel *dlabel; //!< A label for d distance. This is a DANG distance |
| 197 | |
| 198 | QLineEdit *d1line; //!< Input line for d1 distance |
| 199 | QLineEdit *d2line;//!< Input line for d2 distance |
| 200 | QLineEdit *angleline; //!< Angel to be restrained |
| 201 | QLineEdit *dline; //!< Input line for d distance. DANG distance |
| 202 | // Private members for DANG tab |
| 203 | double _d1; //!< d1 distance |
| 204 | double _d2; //!< d2 distance |
| 205 | double _d; //!< d1,3 distance |
| 206 | double _angle; //!< Angle between d1 and d2 |
| 207 | //hkl tab |
| 208 | QDoubleSpinBox *lambdaSpin; |
| 209 | QDoubleSpinBox *aSpin; |
| 210 | QDoubleSpinBox *bSpin; |
| 211 | QDoubleSpinBox *cSpin; |
| 212 | QDoubleSpinBox *alSpin; |
| 213 | QDoubleSpinBox *beSpin; |
| 214 | QDoubleSpinBox *gaSpin; |
| 215 | QSpinBox *hSpin; |
| 216 | QSpinBox *kSpin; |
| 217 | QSpinBox *lSpin; |
| 218 | QLineEdit *LCell; |
| 219 | QLineEdit *HKLedit; |
| 220 | Molecule mole; |
| 221 | QLabel *resolutionL; |
| 222 | |
| 223 | |
| 224 | }; |
| 225 | |
| 226 | #endif // CALCULATOR_H |