1 2 /**************************************************************************** 3 ** 4 ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick 5 ** All rights reserved. 6 ** Contact: chuebsch@moliso.de 7 ** 8 ** This file is part of the ShelXle 9 ** 10 ** This file may be used under the terms of the GNU Lesser 11 ** General Public License version 2.1 as published by the Free Software 12 ** Foundation and appearing in the file COPYING included in the 13 ** packaging of this file. Please review the following information to 14 ** ensure the GNU Lesser General Public License version 2.1 requirements 15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 16 ** 17 ** 18 ****************************************************************************/ 19 #ifndef FOURXLE_H 20 #define FOURXLE_H 1 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include <math.h> 24 #include <ctype.h> 25 #include <string.h> 26 #include <locale.h> 27 //#include <fftw3.h> //if you want you can try to uncoment this, but then you have to coment the following line 28 #include "kissfft/kiss_fftnd.h" 29 #include "molecule.h" 30 #include "chgl.h" 31 #include <QObject> 32 #include <QCheckBox> 33 #include <QMutex> 34 #include <QMutexLocker> 35 36 //! Rec is a reflection type of a fcf 6 file. 37 typedef struct { 38 int ih,//!< h 39 ik,//!< k 40 il;//!< l 41 float fo,//!< F observed 42 so,//!< \f$\sigma(observed)\f$ 43 fc,//!< F calculated 44 phi; //!< \f$\varphi\f$ 45 } Rec; 46 #define LM 2000000 47 //! FNode is a struct for the 3 different edges of a cube 48 struct FNode { 49 V3 vertex;//!< vertex is the 3d position of the node 50 V3 normal;//!< normal is the plane normal of the surface 51 char flag;//!< this flag is set when the surface crosses this node 52 inline operator char (){ 53 //! \returns the flag parameter. No Coala ;-) 54 return flag; 55 } V3FNode56 inline operator V3(){ 57 //! \returns the vertex of the node. 58 return vertex; 59 } DistanceFNode60 friend inline double Distance( const FNode& n1, const FNode& n2 ){ 61 /*! @param n1,n2 nodes vor which the squared distance should be calculated. 62 \returns te positional squared distance between two nodes 63 */ 64 return Norm(n1.vertex-n2.vertex); 65 } 66 }; 67 68 struct Polygn { 69 V3 vertex; 70 int n; 71 int ii[13]; 72 }; 73 74 struct Ort { 75 V3 vertex; 76 V3 normal; 77 GLfloat color; 78 char direct; 79 }; 80 81 struct Node { 82 int index; 83 unsigned char flag; 84 inline operator unsigned char (){return flag;} 85 }; 86 87 // 88 //! FourXle is an QObject that loads a fcf 6 file and creates iso-surfaces in meshed style \inherit QObject 89 class FourXle:public QObject{ 90 Q_OBJECT 91 public: 92 int HKLMX;//!< Maximum of h,k and l values can be used to make a resulution cut. 93 float *datfo,//!<data pointer for the fobs map in real space 94 *datfo_fc;//!<data pointer for the fobs-fcalc map in real space 95 float f000; 96 float overridef000; 97 bool isBelo; 98 FourXle(Molecule *mole_, ChGL *chgl_,QToolBar *toolView, double resol=2.5, double wght=1.1); 99 /*!< @param mole_ pointer to the Molecule of ShelXle 100 * @param chgl_ pointer to the ChGL widged of ShelXle 101 * @param toolView pointer to the View Toolbar of ShelXle 102 * @param resol resolution factor (the higher the more grid points) 103 * @param wght a parameter to downweight weak reflections 104 */ 105 ~FourXle(); 106 QDialogButtonBox *buttonBoxMC; 107 QPushButton *applyMC; 108 QPushButton *applyDF; 109 QPushButton *jnkButton; 110 QLabel *wl, *pl, *dl, *ol, *rl, *sl, *lw, *ltz; 111 QDialog *md; 112 bool MYFCF; 113 QDoubleSpinBox *maprad,*fomaps,*difmaps,*weak,*mapprec,*lineTrans,*lineWidth,*cutrange; 114 QPushButton *foPlusButton,*foMinusButton,*diffPlusButton,*diffMinusButton, *defColorButton; 115 QComboBox *mapSchnitt; 116 QGridLayout *mdl; 117 QVBoxLayout *amdl; 118 QAction *keepiso; 119 QAction *mapcontrol; 120 QCheckBox *ownfcf6, *ownfcf6_; 121 QString fouName; 122 void drawMap(int faps); 123 int maptrunc; 124 double map_radius; //!< radius of the map in Angstrom around the rotaion center (used only in a mode of FourXle). 125 126 bool loadFouAndPerform(const char filename[],bool neu=true); 127 bool loadMap(int NX, int NY, int NZ, float *dat); 128 QDir resDir; 129 QCheckBox *keepIso;//!<keeps the initial iso values good for idieal presentations 130 float sigma[3];//!<sigma values 131 float iso[3];//!<iso values 132 // double mInimum[2],mAximum[2]; 133 V3 urs;//!< origin 134 double rr,//!< resolution factor (the higher the more grid points) 135 rw;//!< a parameter to downweight weak reflections 136 137 QCheckBox *doMaps;//!< do or notthing todo is the question 138 Molecule *mole;//!< pointer to the Molecule object 139 ChGL *chgl;//!< pointer to the ChGL widget 140 QString voxelstr;//!< a string to fix dimensions to desired values by comand line option '-voxel 92x92x92 ' 141 //void deleteLists(); 142 void killmaps(); 143 void jnk(); 144 float sigmaFo(); 145 float sigmaFoFc(); 146 void exportMaps(int na, const char filename[], const char atomlist[]); 147 int n1,//!< dimension of the map in a diRection 148 n2,//!< dimension of the map in b diRection 149 n3,//!< dimension of the map in c diRection 150 n4;//!< \f$ n4 = n1 \times n2\f$ 151 int n5;//!< \f$ n5 = n1 \times n2 \times n3\f$ 152 V3 dx,//!< vector in a direction for each map voxel 153 dy,//!< vector in b direction for each map voxel 154 dz;//!< vector in c direction for each map voxel 155 QVector<Ort> Planorte; 156 QVector<Polygn> Planpgns; 157 // QList<double> data; Intersect(GLfloat & vm,GLfloat & vp)158 inline int Intersect( GLfloat& vm, GLfloat& vp ){ 159 return vm*vp <= 0.0 && (vm<0.0 || vp<0.0); 160 } 161 Node *nodeX; 162 Node *nodeY; 163 Node *nodeZ; 164 QCheckBox *extendUnit; 165 void CalcPlaneVertex( int ix, int iy, int iz ,V3 n,V3 ap,V3 off); 166 void makeFacesp(int nn, Node poly[] ); 167 void MakeElementp( int ix, int iy, int iz ,int s1, int s2); 168 int IndexSelectedP( Node& node0, Node& node1, Node& node2, Node& node3 ); 169 void findContour(QList<V3> &lines, GLfloat value); 170 void makePlane(QList<V3> &lines,int a1, int a2, int a3); 171 double min,max; 172 V3 orig,test3; 173 V3 pnormal,aufpunkt; 174 QLineEdit *contMapFile, *contourValueEdit, *contEPSFile; 175 QComboBox *aspectRatios, *centerIsOn, *sourceMap; 176 QDoubleSpinBox *cScopeBx, *heightScale; winkel(V3 a,V3 b)177 inline double winkel(V3 a,V3 b){ 178 return acos((a.x*b.x+a.y*b.y+a.z*b.z)/(sqrt(a.x*a.x+a.y*a.y+a.z*a.z)*sqrt(b.x*b.x+b.y*b.y+b.z*b.z))); 179 } 180 public slots: 181 void bewegt(V3 v); 182 void inimap(); 183 void change_iso(int numsteps,int diff); 184 void chglDestroyed(); 185 void foactDestroyed(); 186 void fofcactDestroyed(); 187 void doMapsNow(bool b);//!<destroys maps or (re)calculates them freshly. 188 void mapDefault();//!< restores the defaults of the Map Control dialog. 189 void schnittart(int trunc);//!< the truncation type of the electron density maps changes to trunc @param trunc new truncation type. 190 void controlMap();//!<Shows the Map-Control Dialog. 191 void keepIsoValues(bool b); 192 void killFourXleFirst();//!< attempt to run killmaps before chgl gets destryed 193 void colorDLGFOP();//!<Color Dialog for Fobs plus. Positive values of Fo map are drawn with a mesh in this color. 194 void colorDLGFOM();//!<Color Dialog for Fobs minus. Negative values of Fo map are drawn with a mesh in this color. 195 void colorDLGDIP();//!<Color Dialog for Fobs-Fcalc plus. Positive values of Fo-Fc map are drawn with a mesh in this color. 196 void colorDLGDIM();//!<Color Dialog for Fobs-Fcalc minus. Negative values of Fo-Fc map are drawn with a mesh in this color. 197 void defaultColors();//!<Restores the default colors of the electron density maps (Fo+ blue Fo- yellow Fo-Fc+ green Fo-Fc- red). 198 void openMapControl();//!< shows the Map Control dialog. 199 void updateLines(); 200 void reportInfo(); 201 signals: 202 void bigmessage(const QString &);//!< to comunicate with the informaton window 203 void reloadRes(); 204 void haltMW();//stop the map worker 205 206 private: 207 mutable QMutex mutex; 208 double C[15],D[9],sy[12][192],wave; Intersect(double & vm,double & vp)209 inline int Intersect( double& vm, double& vp ){ return vm*vp <= 0.0 && (vm<0.0 || vp<0.0); } 210 inline int dex(int x,int y,int z); 211 inline int dex3(int x,int y,int z); 212 int oldatomsize; 213 int acnt; 214 QString info; 215 V3 oc,dxc,dyc,dzc; 216 V3 delDA[27]; 217 #ifdef FFTW3_H 218 fftwf_plan fwd_plan;//!!! 219 fftwf_complex *B;//!!! 220 #else 221 kiss_fftnd_cfg fwd_plan;//!!! 222 kiss_fft_cpx *B;//!!! 223 #endif 224 FNode *nodex,*nodey,*nodez; 225 int *noGoMap; 226 Rec lr[LM]; 227 char cen,git; 228 int nr,nc,ns; 229 int mtyp,tri; 230 QTime foti,suti; 231 // double minnor,maxnor; 232 void gen_surface(bool neu,int imin=0, int imax=4); 233 void CalcVertex( int ix, int iy, int iz); 234 // V3 CalcNormalX( int ix, int iy, int iz ); 235 // V3 CalcNormalY( int ix, int iy, int iz ); 236 // V3 CalcNormalZ( int ix, int iy, int iz ); 237 int IndexSelected( FNode& node0, FNode& node1, FNode& node2, FNode& node3); 238 // V3& VectorSelected( FNode& node0, FNode& node1, FNode& node2, FNode& node3); 239 void MakeElement( int ix, int iy, int iz, int faps); 240 void makeFaces(int n, int faps, FNode poly[] ); 241 char titl[80];/*fcmax=0,f000=0,resmax=99999.0,*/ 242 void trimm(char s[]); 243 void deletes(char *s, int count); 244 int readHeader(const char *filename); 245 void sorthkl(int nr, Rec r[]); 246 247 friend class GenMapWorker; 248 }; 249 250 251 252 class GenMapWorker : public QThread{ 253 Q_OBJECT 254 public: 255 GenMapWorker(ChGL *chgl_,Molecule *mol_, FourXle *parent, bool neu_=true,int imin_=0, int imax_=4){ 256 chgl = chgl_; 257 mole=mol_; 258 fxle = parent;// maybe I need it later? 259 neu=neu_; 260 imin=imin_; 261 imax=imax_; 262 } ~GenMapWorker()263 ~GenMapWorker(){ 264 //printf("destruct GenMapWorker\n"); 265 } 266 run()267 void run() { 268 /* expensive or blocking operation */ 269 gen_surface(neu, imin,imax); 270 } 271 void gen_surface(bool neu,int imin=0, int imax=4); 272 ChGL *chgl; 273 FourXle *fxle;//parent 274 Molecule *mole; 275 bool neu; 276 int imin,imax; 277 }; 278 279 280 #endif 281