Debian Codegraph @

molecule.h

raw symbols SCIP
1
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick
5 ** All rights reserved.
6 ** Contact: [email protected]
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 MOLECULE_H
20 #define MOLECULE_H 1
21 #include <math.h>
22 #if defined _MSC_VER && _MSC_VER == 1500
23 #ifndef fmin
24 #define fmin(x, y) (((x) < (y)) ? (x) : (y))
25 #endif
26 #ifndef fmax
27 #define fmax(x, y) (((x) > (y)) ? (x) : (y))
28 #endif
29 #ifndef round
30 #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
31 #endif
32 #endif
33 #include <QString>
34 #include <QStringList>
35 #include <QList>
36 #include <QtOpenGL>
37 #include <QOpenGLShaderProgram>
38 //#if defined (Q_WS_MAC) || defined(Q_OS_MAC)
39 //#include <OpenGL/glu.h>
40 // //#include <glu.h>
41 //#else
42 //#include <GL/glu.h>
43 //#endif
44 //#include "glureplace.h"
45 #include <QtCore>
46 #ifndef M_PI
47 #define M_PI 3.14159265358979323846
48 #endif
49 #ifndef M_PIf
50 #define M_PIf 3.14159265358979323846f
51 #endif
52 #define ATOM_STYLE_WALLS 1
53 #define ATOM_STYLE_RINGS 2
54 #define ATOM_STYLE_SPHERE 4
55 #define ATOM_STYLE_SOLID 8
56 #define ATOM_STYLE_WHITERING 16
57 #define ATOM_STYLE_NOLABEL 32
58 #define ATOM_STYLE_NOADP 64
59 #define ATOM_STYLE_PLAID 128
60 #define ATOM_STYLE_METAL 256
61 #include <QSettings>
62 #ifndef GLAPIENTRY
63 #if defined(_MSC_VER) || defined(__MINGW32__)
64 #define GLAPIENTRY __stdcall
65 #else
66 #define GLAPIENTRY
67 #endif
68 #endif
69
70 #ifndef GLAPIENTRYP
71 #define GLAPIENTRYP GLAPIENTRY *
72 #endif
73
74 typedef void (GLAPIENTRYP GLU_func_ptr)(void);
75 //GLOBAL SETTINGS
76 //static int global_zero_counter=0;
77 //! V3 is a three dimensional vector in cartesian space
78 struct V3 {
79 double x//! x is the X coordinate
80 ,y//! y is the Y coordinate
81 ,z//! z is the Z coordinate
82 ;
83 // int rc;
84 inline V3( void ){}
85 inline V3( const double& _x, const double& _y, const double& _z ) :
86 x(_x), y(_y), z(_z)//!< initializer
87 //,rc(0)
88 {
89 ;
90 }
91 inline V3& operator *= ( const double& d ){
92 x *= d;
93 y *= d;
94 z *= d;
95 return *this;
96 }//!< The *= operator to scale by a scalar
97 inline V3& operator += ( const V3& v ){
98 x += v.x;
99 y += v.y;
100 z += v.z;
101 return *this;
102 }//!< The += operator to add a V3
103 inline V3& operator += ( const double& v ){
104 x += v;
105 y += v;
106 z += v;
107 return *this;
108 }//!< The += operator to add a scalar
109 };
110 inline V3 operator + ( const V3& v1, const V3& v2 ) {
111 V3 t;
112 t.x = v1.x + v2.x;
113 t.y = v1.y + v2.y;
114 t.z = v1.z + v2.z;
115 return t;
116 }//!< The + operator to add two V3
117 inline V3 operator - ( const V3& v1, const V3& v2 ) {
118 V3 t;
119 t.x = v1.x - v2.x;
120 t.y = v1.y - v2.y;
121 t.z = v1.z - v2.z;
122 return t;
123 }//!< The + operator to subtract two V3
124 inline V3 operator * ( const V3& v, const double& d ) {
125 V3 t;
126 t.x = v.x*d;
127 t.y = v.y*d;
128 t.z = v.z*d;
129 return t;
130 }//!< The * to scale a V3
131 inline V3 operator * ( const double& d, const V3& v ) {
132 V3 t;
133 t.x = v.x*d;
134 t.y = v.y*d;
135 t.z = v.z*d;
136 return t;
137 }//!< The * to scale a V3
138 inline V3 operator % ( const V3& v1, const V3& v2 ) {
139 V3 t;
140 t.x = v1.y*v2.z - v2.y*v1.z;
141 t.y = v1.z*v2.x - v2.z*v1.x;
142 t.z = v1.x*v2.y - v2.x*v1.y;
143 return t;
144 }//!< The % operator the cross product of two V3
145 inline double operator * ( const V3& v1, const V3& v2 ) {
146 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
147 }//!< The * operator the scalar product of two V3
148 inline double Norm( const V3& v ) {
149 return v.x*v.x + v.y*v.y + v.z*v.z;
150 }//!< The squared lenght of a V3
151 inline double Distance( const V3& v1, const V3& v2 ) {
152 return Norm(v1 - v2);
153 }//!< The squared distance between two V3
154 inline bool operator == (const V3& v1, const V3& v2 ) {
155 // return ((v1.x==v2.x)&&(v1.y==v2.y)&&(v1.z==v2.z));
156 return (Distance(v1,v2)<0.005);
157 }
158 inline V3& Normalize( V3 v ) {
159 static V3 erg=V3(1,0,0);
160 if (Norm(v)) erg= (v * (1.0/sqrt(Norm(v))));
161 return erg;
162 }
163 //! Matrix is a 3 x 3 Matrix with all needed operators
164 struct Matrix{
165 double m11, m21, m31, m12, m22, m32, m13, m23, m33;
166 inline Matrix(void){}
167 inline Matrix( const V3 &a, const V3 &b, const V3 &c):
168 m11(a.x), m21(b.x), m31(c.x),
169 m12(a.y), m22(b.y), m32(c.y),
170 m13(a.z), m23(b.z), m33(c.z){;}
171 inline Matrix( const double& x11, const double& x21, const double& x31,
172 const double& x12, const double& x22, const double& x32,
173 const double& x13, const double& x23, const double& x33):
174 m11(x11), m21(x21), m31(x31),
175 m12(x12), m22(x22), m32(x32),
176 m13(x13), m23(x23), m33(x33){;}
177 inline Matrix( const QMatrix4x4 &m44):
178 m11(m44(0,0)), m21(m44(0,1)), m31(m44(0,2)),
179 m12(m44(1,0)), m22(m44(1,1)), m32(m44(1,2)),
180 m13(m44(2,0)), m23(m44(2,1)), m33(m44(2,2))
181 {;}
182 inline Matrix( const QMatrix3x3 &m33):
183 m11(m33(0,0)), m21(m33(0,1)), m31(m33(0,2)),
184 m12(m33(1,0)), m22(m33(1,1)), m32(m33(1,2)),
185 m13(m33(2,0)), m23(m33(2,1)), m33(m33(2,2))
186 {;}
187 inline Matrix operator *= (const double a){
188 m11 *= a;
189 m21 *= a;
190 m31 *= a;
191
192 m12 *= a;
193 m22 *= a;
194 m32 *= a;
195
196 m13 *= a;
197 m23 *= a;
198 m33 *= a;
199 return *this;
200 }
201 };
202 inline Matrix transponse (Matrix a){//transponse
203 return Matrix(
204 a.m11, a.m12, a.m13,
205 a.m21, a.m22, a.m23,
206 a.m31, a.m32, a.m33);
207 }
208 inline double determinant (Matrix a){
209 return a.m11*a.m22*a.m33 - a.m11*a.m23*a.m32 - a.m12*a.m21*a.m33 + a.m12*a.m23*a.m31 +a.m13*a.m21*a.m32 -a.m13*a.m22*a.m31;
210 }
211 inline Matrix inverse (Matrix A){
212 double D = determinant(A);
213 if (D==0) return A;
214 D=1.0/D;
215 return Matrix(
216 D*(A.m22*A.m33-A.m23*A.m32),//x11
217 D*(A.m13*A.m32-A.m12*A.m33),//x21
218 D*(A.m21*A.m23-A.m13*A.m22),//x31
219 D*(A.m23*A.m31-A.m21*A.m33),//x12
220 D*(A.m11*A.m33-A.m13*A.m31),//x22
221 D*(A.m13*A.m21-A.m11*A.m23),//x32
222 D*(A.m21*A.m32-A.m22*A.m31),//x13
223 D*(A.m12*A.m31-A.m11*A.m32),//x23
224 D*(A.m11*A.m22-A.m12*A.m21)//x33
225 );
226 }
227 inline bool operator == (const Matrix &a,const Matrix &b){
228 return ((a.m11 == b.m11)&&(a.m21 == b.m21)&&(a.m31 == b.m31)&&
229 (a.m12 == b.m12)&&(a.m22 == b.m22)&&(a.m23 == b.m23)&&
230 (a.m13 == b.m13)&&(a.m32 == b.m32)&&(a.m33 == b.m33));
231 }
232 inline Matrix operator * (const Matrix &a,const Matrix &b){
233 Matrix erg;
234 erg.m11 = a.m11 * b.m11 + a.m21 * b.m12 + a.m31 * b.m13;
235 erg.m21 = a.m11 * b.m21 + a.m21 * b.m22 + a.m31 * b.m23;
236 erg.m31 = a.m11 * b.m31 + a.m21 * b.m32 + a.m31 * b.m33;
237
238 erg.m12 = a.m12 * b.m11 + a.m22 * b.m12 + a.m32 * b.m13;
239 erg.m22 = a.m12 * b.m21 + a.m22 * b.m22 + a.m32 * b.m23;
240 erg.m32 = a.m12 * b.m31 + a.m22 * b.m32 + a.m32 * b.m33;
241
242 erg.m13 = a.m13 * b.m11 + a.m23 * b.m12 + a.m33 * b.m13;
243 erg.m23 = a.m13 * b.m21 + a.m23 * b.m22 + a.m33 * b.m23;
244 erg.m33 = a.m13 * b.m31 + a.m23 * b.m32 + a.m33 * b.m33;
245 return erg;
246 }
247 inline V3 operator * (const Matrix &a, const V3 &b){
248 V3 erg;
249 erg.x = a.m11*b.x + a.m21*b.y + a.m31*b.z;
250 erg.y = a.m12*b.x + a.m22*b.y + a.m32*b.z;
251 erg.z = a.m13*b.x + a.m23*b.y + a.m33*b.z;
252 return erg;
253 }
254 inline V3 operator * (const V3 &a, const Matrix &b){
255 V3 erg;
256 erg.x = b.m11*a.x + b.m12*a.y + b.m13*a.z;
257 erg.y = b.m21*a.x + b.m22*a.y + b.m23*a.z;
258 erg.z = b.m31*a.x + b.m32*a.y + b.m33*a.z;
259 return erg;
260 }
261 inline Matrix operator * (const Matrix &a,const double &b){
262 Matrix erg;
263 erg.m11 = a.m11*b;
264 erg.m21 = a.m21*b;
265 erg.m31 = a.m31*b;
266
267 erg.m12 = a.m12*b;
268 erg.m22 = a.m22*b;
269 erg.m32 = a.m32*b;
270
271 erg.m13 = a.m13*b;
272 erg.m23 = a.m23*b;
273 erg.m33 = a.m33*b;
274 return erg;
275 }
276
277 inline Matrix operator + (const Matrix &a, const Matrix &b){
278 Matrix erg;
279 erg.m11 = a.m11+b.m11;
280 erg.m21 = a.m21+b.m21;
281 erg.m31 = a.m31+b.m31;
282
283 erg.m12 = a.m12+b.m12;
284 erg.m22 = a.m22+b.m22;
285 erg.m32 = a.m32+b.m32;
286
287 erg.m13 = a.m13+b.m13;
288 erg.m23 = a.m23+b.m23;
289 erg.m33 = a.m33+b.m33;
290 return erg;
291 }
292
293 inline bool operator < (const Matrix &a, const Matrix &b){
294 return (
295 (a.m11<b.m11)&&
296 (a.m21<b.m21)&&
297 (a.m31<b.m31)&&
298 (a.m12<b.m12)&&
299 (a.m22<b.m22)&&
300 (a.m32<b.m32)&&
301 (a.m13<b.m13)&&
302 (a.m23<b.m23)&&
303 (a.m33<b.m33));
304 }
305 //! MyAtom an atom object
306 typedef struct MyAtom{
307 //! Label is the atom label with residue nuber seperated by '_' and the symmetry operation number seperated by french quotes.
308 QString Label;
309 //! ResiClass is the four or three letters residue class
310 QString ResiClass;
311 //! The original line in the res file.
312 QString orginalLine;
313 //! fragment number of the structure part
314 int molindex;
315 //! Binary flag for fixed (tied to first FVAR) atom parameters.
316 int fixFlag;
317 //! the symmetry number
318 int symmGroup ;
319 //!symmetry operation number
320 int sg;
321 //! platon style symetry code (s555)
322 int scod;
323 //! index of the source atom in the asymmetric unit
324 int auidx;
325 //! a is hidden flag
326 int hidden;
327 //! the site occupancy factor as it is the file e.g. 11.000
328 double sof_org;
329 //! the site occupancy factor e.g. 1.0 or 0.5
330 double sof;
331 //! isotropric flag
332 bool isIso;
333 //! the Uiso string as it appears in the res file eg -1.5 for 150% of the ueq of the horse atom
334 QString ufiso_org;
335 //! the fractional Uij
336 Matrix uf;
337 //! the cartesian Uij
338 Matrix uc;
339 //! the cartesian coordinates.
340 V3 pos;
341 //! the fractional coordinates.
342 V3 frac;
343 //! the electrondensity value of a Q-Peak.
344 double peakHeight;
345 //! the residue number
346 int resiNr;
347 //! the atomic number
348 int an;
349 //! the (dissordered) part number
350 int part;
351 //! the style type of the atom
352 int style;
353 //! the afix type of the parent atom
354 int afixParent;
355 //! the afix type
356 int afix;
357 //! the screen position X
358 GLdouble screenX;
359 //! the screen position Y
360 GLdouble screenY;
361 QString toAtomString() const{
362 return QString("%1!%2!%3!%4!%5!%6!%7!%8!%9!%10!%11!%12!%13!%14!%15!%16!%17!%18!%19!%20!%21!%22!%23!%24!%25!%26!%27!%28!%29!%30!%31!%32!%33!%34!%35!%36!%37!%38!%39!%40!%41!%42!%43!%44!%45\n")
363 .arg(Label,ResiClass,orginalLine)//1
364 .arg(molindex)
365 .arg(fixFlag)
366 .arg(symmGroup)
367 .arg(sg)
368 .arg(scod)
369 .arg(auidx)
370 .arg(hidden)
371 .arg(sof_org)
372 .arg(sof)
373 .arg(isIso)
374 .arg(ufiso_org)
375 .arg(uf.m11).arg(uf.m12).arg(uf.m13).arg(uf.m21).arg(uf.m22).arg(uf.m23).arg(uf.m31).arg(uf.m32).arg(uf.m33)
376 .arg(uc.m11).arg(uc.m12).arg(uc.m13).arg(uc.m21).arg(uc.m22).arg(uc.m23).arg(uc.m31).arg(uc.m32).arg(uc.m33)
377 .arg(pos.x).arg(pos.y).arg(pos.z)
378 .arg(frac.x).arg(frac.y).arg(frac.z)
379 .arg(peakHeight)
380 .arg(resiNr)
381 .arg(an)
382 .arg(part)
383 .arg(style)
384 .arg(afixParent)
385 .arg(afix)
386 ;
387 }
388 }MyAtom;
389 inline bool operator == (const MyAtom &a1,const MyAtom &a2){
390 return ((a1.Label == a2.Label)&&(a1.resiNr == a2.resiNr)&&(a1.part == a2.part)&&(a1.symmGroup == a2.symmGroup));
391 }
392 inline bool operator < (const MyAtom &a1, const MyAtom &a2){
393 return (a1.Label < a2.Label);
394 }
395 inline bool operator < (MyAtom &a1, MyAtom &a2){
396 return (a1.Label < a2.Label);
397 }
398
399 //! MyBond a bond object
400 typedef struct MyBond{
401 //! a pointer to the atom where the bond starts
402 MyAtom const *ato1;
403 //! a pointer to the atom where the bond ends
404 MyAtom const *ato2;
405 //! the bond length
406 double length;
407 //! the index of the atom where the bond starts
408 int a1;
409 //! the index of the atom where the bond ends
410 int a2;
411 }MyBond;
412 inline bool operator ==(const MyBond &a1,const MyBond &a2){
413 return ((a1.a1==a2.a1)&&(a1.a2==a2.a2))||((a1.a2==a2.a1)&&(a1.a1==a2.a2));
414 }
415 //! for the BIND instruction
416 typedef struct MyBind{
417 QString Lab1,Lab2;
418 }MyBind;
419
420 struct Vert {
421 int faces[3];
422 V3 pos;
423 };
424
425 typedef struct VPoly{
426 V3 mid,nor,verts0,verts1,color;
427 int acol,intra;
428 }VPoly;
429
430 typedef struct PPoly{
431 V3 mid,nor,verts0,verts1;
432 int colr,n;
433 V3 glide;
434 }PPoly;
435
436 typedef QList<MyBond> Connection;
437 typedef QList<MyAtom> CEnvironment;
438 //! Unit cell parameters
439 struct Cell {
440 //! the dimension a in Angstrom
441 double a;
442 //! the dimension b in Angstrom
443 double b;
444 //! the dimension c in Angstrom
445 double c;
446 //! the angle alpha in degrees
447 double al;
448 //! the angle beta in degrees
449 double be;
450 //! the angle gamma in degrees
451 double ga;
452 //! \f$\varphi = \sqrt(1 - (\cos(\alpha)^2) - (\cos(\beta)^2) - (\cos(\gamma)^2) + 2\cos(\alpha)\cos(\beta)\cos(\gamma))\f$
453 double phi;
454 //! the cell volume in Angstrom^3
455 double V;
456 //! the reciprocal dimension a
457 double as;
458 //! the reciprocal dimension b
459 double bs;
460 //! the reciprocal dimension c
461 double cs;
462
463 //! \f$ \tau = c ((\cos(\alpha) - \cos(\beta) \cos(\gamma)) / \sin(\gamma))\f$
464 double tau;
465 //! \f$ \cos(\gamma)\f$
466 double cosga;
467 //! \f$ \cos(\alpha) \f$
468 double cosal;
469 //! \f$ \cos(\beta) \f$
470 double cosbe;
471 //! \f$ \sin(\alpha) \f$
472 double sinal;
473 //! \f$ \sin(\beta) \f$
474 double sinbe;
475 //! \f$ \sin(\gamma) \f$
476 double singa;
477 //! \f$ \tan(\gamma) \f$
478 double tanga;
479 double cosra;//! cos reciprocal alpha
480 double cosrb;//! cos reciprocal beta
481 double cosrg;//! cos reciprocal gamma
482 //! List of symmetry operators
483 QList<Matrix> symmops;
484 //! List of translations
485 QList<V3> trans;
486 //!number of symmops without centring and inversion applyed
487 int ns0;
488 //! space group is centred (A,B,C,I,F)
489 bool centered;
490 //! space group is centro symmetric
491 bool centeric;
492 //! ZERR string as it is from the res file
493 QString Z;
494 //! the wavelenth \f$ \lambda \f$ in Angstroms
495 double wave;
496 Matrix G,Gi;//metric tensor and its inverse
497 QMatrix3x3 Cholesky;
498 };
499 //! shortest distance matrix item type
500 struct SdmItem{
501 //! shortest contact distance
502 double d;
503 //! atom index of the starting atom
504 int a1;
505 //! atom index of the ending atom
506 int a2;
507 //! symmetry number of the contact
508 int sn;
509 V3 floorD;
510 //! contact is covalent
511 bool covalent;
512 };
513
514 inline bool operator < (const SdmItem &a1, const SdmItem &a2){
515 return (a1.d<a2.d);
516 }
517
518 struct Tripel{
519 int n[3];
520 V3 midcenter;
521 };
522 inline bool operator == (const Tripel& v1, const Tripel& v2 ) {
523 return ((v1.n[0]==v2.n[0])&&(v1.n[1]==v2.n[1])&&(v1.n[2]==v2.n[2]));
524 }
525 //!Knopf is a list of neighbors of an atom
526 struct Knopf{
527 //! neighbors is list of atom indices of neigbours of that atom
528 QList<int> neighbors;
529 };
530 class Ring;
531 /*! \brief Molecule is a crystallography and molecular structure object of shelXle.
532 *
533 * It has routines to convert coordinates and
534 * ADPs from fractional to cartesian space, symmetry operations etc. It provides also routintes to draw atoms bonds and q-peaks.
535 * It is thought that there is only one instance of this class in ShelXle during runtime. Molecule accesses the settings file of ShelXle.
536 */
537 class Molecule{
538 public:
539 GLfloat fgc[4];
540 bool mist;
541 QString theIconPath;
542 float fibo,fibom1;//1.618034f
543 GLfloat q_bondWidth = 1.0f;
544 int fogrange;
545 bool nopm1;//!< No part minus n ghost
546 bool highlightEquivalents;//!< Symmetry generated objects will be drawn in lighter colors if this is true
547 bool qbeforehkl;//!< There are Q-Peaks before HKLF instruction
548 bool growQPeak;//!< Q-Peaks should be treated with symmetry operators
549 bool monoQrom;//!< Q-Peaks in a single color instead of a gradient.
550 bool noQPeaksPlease;//!< Q-Peaks are not shown if this is true
551 bool HFixSuitableAtomsOnly;//!< Prevent fixing H atoms on atoms with mallformed ADPs
552 QColor mQolor;//!< the single Q-Peak color
553 double qboMin,qboMax;
554 double exti,swat,osf;
555 int hklf;
556 double hklScale,hklSigmaScale,hklOmitSig,hklOmit2th,hklShellLow,hklShellHig;
557 Matrix hklMat;
558 QString titl;
559 QString mynewnameis;
560 int LOD;//!< The Level of Detail
561 QOpenGLShaderProgram *g_Program,*saveProg;//shaders with Qt
562 int g_program;//GL handle for shader program
563 Molecule();//!<The constructor
564 int icocnt;
565 int latt;
566 int afix5(int idx);//!< retuns fo example 65 if less then 6 non H atoms (in AFIX 66) are before this line.
567 int afix5(const CEnvironment &atm, int idx);
568 void setHBondMaxDist(double d);
569 void setHBondMaxAngl(double w);
570 int genSymCode(int s, int h, int k, int l);//!< creates a platon style symmetry code as an integer (s555)
571 V3 applySymCode(const V3 &frac, int scode);//!< applies a platon style symmetry code as an integer (s555)
572 double hbdist();
573 double hbangl();
574 QMatrix3x3 cholesky();
575 int installShader();
576 void Farbverlauf (GLfloat wrt,GLfloat min,GLfloat max);//!<computes a gradient color for wrt which is between min and max and calls glColor. @param wrt value for which a color should be assigned. @param min minimum value of wrt. @param max maximum value of wrt.
577 Cell cell;//!<The unit cell parameters
578 QString Fragments;//!<A html string of the kind "<b>The asymmetric unit contains N fragments.</b><br>" were N is the number of fragments.
579 QList<SdmItem> sdm;//!< shortest distance matrix.
580 QList<SdmItem> envi_sdm;//!< shortest distance matrix for the ENVIron ment listing functionality.
581 QList<SdmItem> contact;//!< shortest distance matrix with possible hydrogen bonds for auto HFIX.
582 QList<Matrix> symmopsEQIV;//!< list of symmetry operations from EQIV instructions.
583 QStringList labelEQIV;//!< list of atom lable from EQIV instructions.
584 QList<V3> transEQIV;//!< list of translation from EQIV instructions.
585 QMap<QString,int> eqivMap;//!< maps labelEQIV and symmetry operation indices.
586 QList<MyBind> freeatoms,//!< bond list for FREE instructions
587 bindatoms;//!< bond list for BIND instructions
588 QList<Knopf> knoepfe;//!< neighbors list of each atom
589 QMap<int,int> bindPart;
590 bool canbeDonor(int an);
591 bool canbeAcceptor(int an);
592 bool is2Dissordered4H(const MyAtom &atom);
593 QList<int> theseAreAcceptors;
594 QList<int> theseAreDonors;
595 int adp,//!<if non zero the atoms and bons are drwn in ellipsoid style.
596 intern,
597 bondColorStyle;//!< uni colored bonds or bonds half and half colored like the connected atoms.
598 double bondStrength;//!< cylinder radius of the bonds in Angstrom
599 double qPeakRad;//!< icosahedron size in Angstrom
600 double beloRad;//!< triacontahedron size in Angstrom
601 QColor beloColor;//!< triacontahedron color
602 bool beloColorByDefden;
603 bool beloLabels;
604 Matrix rotarb(double *arr);
605 Matrix rotarb(double angle, V3 &arr);
606 void rotarb(Matrix &mat, double angle, V3 &arr);
607
608 //GLuint hbtex; //!< texture handle for hydrogen bonds
609 QOpenGLTexture *hbtex = nullptr;
610 // hbtex2; //!< texture handle for
611 //GLuint adpwall,//!< texture handle elipsoid walls
612 // adpwall_plaid;//!< texture handle elipsoid walls different style
613 // int nonPositiveDefinite;
614 int proba,//!< probability level of the ellipsoids
615 tubes,//!< tube mode instead of ball stick
616 dratom;//!< wire style of atoms
617 //V3 VZ;
618 QColor deuteriumColor;
619 QColor atomColor(int an, bool isD=false);
620 QColor AtomColor[109];//!<List of colors for all supported elements.
621 int AtomStyle[109];//!<List of atom style types for all supported elements.
622 double arad[109];//!<List of ball radii for ball stick visulaization for all supported elements.
623 unsigned short Kovalenz_Radien[109];//!<List of covalent radii for all supported elements.
624 int pseFontSize;//!< Font size for the PSEWidget to be stored in the settings.
625 double pmin,//!< minimum peak height of the Q-Peaks.
626 pmax;//!< maximum peak height of the Q-Peaks.
627 double lmin,//!< minimum a for belo.
628 lmax;//!< maximum a for belo.
629 QColor bondColor;//!< the color of the bonds in uni colored mode.
630
631 QColor enviBondColor,//!< covalent color in ENVI
632 enviHBColor,//!< hydrogen bond color in ENVI
633 enviDefaultColor;//!< default color in ENVI
634 CEnvironment asymm;//!< atom list containing the asymertic unit
635 CEnvironment showatoms;//!< atom list containing all atoms to be drawn.
636 CEnvironment splitLeftAtoms;
637 CEnvironment splitRightAtoms;
638 CEnvironment selectedatoms;//!< atom list of selected atoms.
639 CEnvironment duplicateAtoms;//!< atom list of identcal labeled atoms.
640 CEnvironment legendAtoms;//!< Atoms in a key legend.
641 Connection showbonds;//!< list of visible bonds.
642 Connection splitLbonds;
643 Connection splitRbonds;
644 Connection lbonds;//!< list of line bonds (for Q-Peaks)
645 CEnvironment fitatoms;//!<
646 Connection fitbonds;//!<
647 Connection theH_Bonds;
648 QStringList usedSymmetry;//!< List of internal symmetry codes of symmetry operations curently applied.
649 QString HumanSymmetry;//!< A human readable list of symmetry operations in use.
650 //QSettings *einstellung;//!< the QSetttings for ShelXle.
651 QString ffmpegexe;
652 int vorobas;
653 QString voroMsg;
654 MyAtom fromAtomString(const QString &s);
655 V3 findGlide(V3 normal, V3 test, int n);
656 V3 findGlide(V3 normal, V3 test, Matrix mat, V3 trans);
657 QList<VPoly> vtriangles;
658 double planeTransparence;
659 QList<PPoly> ptriangles;
660 QList<V3> axvecs;
661 QList<int> axcols;
662 QList<int> axoprs;
663 QList<int> invoprs;
664 QList<V3> invvecs;
665 QList<int> dontshowSop;
666 QList<int> dontshowSel;
667 QList<QColor> symmColors;
668 void spitze(V3 dir, V3 pos);
669 void voronoij(CEnvironment au, int intat=-1);
670 void drawVoronoi(V3 auge);
671 void drawPlanes();
672 void drawAxses();
673 void drawInversionCenters();
674 double ueq(Matrix m);
675 double averageUeq();
676 V3 intersectPoint(V3 rayVector, V3 rayPoint, V3 planeNormal, V3 planePoint, bool &ok);
677 void make1Plane(V3 planeNormal, V3 pointOnPlane,V3 glide, int ac, int n);
678 void findSymmElements();
679 void packPoint(const V3 &point, QList<V3> &wearein);//!< Pack inside cell
680 void packLine(const V3 &p1,const V3 &p2, QList<V3> &wearein, int c,QList<int> &dc);//!< Pack inside cell
681 void specialPts(const Matrix &mat, const V3 &trans, QList<V3> &points);
682 //unsigned short ElNeg[83];
683 //
684 //
685 QString nameSymmOp(Matrix m, int &fold, V3 &axis);
686 QStringList sdmcompleter();
687 QList<SdmItem> computeSDM(CEnvironment au);
688 void atoms(CEnvironment atom,int proba=50,double radscal=1.0);
689 bool shaders_work;//!< can glsl shader run on this machine?
690 bool program_in_use;//!< glsl program active
691 //bool useShaders;//!< the user whats shader
692 void shaderAtoms(CEnvironment atom,int proba=50, double radScal=1.0);//!< like void atoms(CEnvironment atom,int proba=50); but with shaders
693 void pappe();//!< the inner walls of an ellipsoid (use ony with shaders and 'wall' uniform set)
694 void bonds(Connection bond, double radScal=1.0);
695 void dbond(Connection bond,int ccode=0);
696 void lbond();
697 void billBoard();
698 QString h_bonds(Connection bond,CEnvironment atoms);
699 void h_bonds2(Connection bond,CEnvironment atoms);
700 void h_bonds3(Connection bond,CEnvironment atoms);
701 void unitCell();
702 Connection connecting(const CEnvironment &atom, bool eac=false);
703 bool decodeSymmCard(const QString symmCard);
704 bool decodeSymmCardEQIV(const QString symmCard);
705 //void countMols(QList<INP> & xdinp);
706 //bool applyLatticeCentro(const QChar latt,const bool centro);
707 QString symmcode2human(QStringList brauchSymm);//!< converts a list of internal symmetry codes in human readable ones.
708 QString symmcode2human(QString brauchSymm);//!< converts an internal symmetry code into human readable symmetry operation description
709 QString symmcode2human(QString brauchSymm, int j);//!< converts an internal symmetry code into human readable symmetry operation description prepends french quotes j:
710 QString symmcode2human(int s);
711 QString symmCard2Code(QString symmCard);
712 void frac2kart (V3 x, V3 & y);
713 void kart2frac (V3 x, V3 & y);
714 int getOZ(QString S1);//!< returns the atomic number (starting from 0) for a given chmical elememt symbol S1. @param S1 element symbol.
715 double shortestDistance(QString sc);
716 static double winkel(V3 a,V3 b);//!< calculates the angle in degrees between two vectors
717 double dieder(V3 a,V3 b, V3 c);//!< calculates a torsion angle from 3 given vectors
718 static V3 kreuzX(double x1,double y1,double z1,double x2,double y2,double z2) ;//!< a cross product
719 double fl(double x,double y, double z);//!< calculates the length of a vector given by x,y,z in fractional coordinates in Angstroms @param x,y,z fractional coordinates of a vector.
720 double wl(V3 f2, V3 f1, V3 f3);//!< calculates angle in degrees of the 3 positional vectors in fractional space.
721 void cellSetup();//!< calculates unit cell parameters from a,b,c, alpha, beta, gammma
722 void fuse();
723 void grow();
724 void grow_plus();
725 void fillCell();
726 void uniqueInCell();
727 void packer(QStringList brauchSymm);
728 void packInLimits(double ami, double ama, double bmi, double bma, double cmi, double cma);//!< Pack inside given limits (eg multiple unit cells)
729 CEnvironment packInLimits(CEnvironment &au, double ami, double ama, double bmi, double bma, double cmi, double cma);//!< Pack inside given limits (eg multiple unit cells)
730 void applyLatticeCentro(int gitter);
731 void Uf2Uo(const Matrix x, Matrix & y) ;
732 void Usym (Matrix x,Matrix sym, Matrix & y);
733 void USymCode(Matrix x,int scod, Matrix & y);
734 double dimension();
735 double dimension(CEnvironment ce);
736 void expandAt(int index);
737 void expandAll();
738 void complete();
739 void enviSDM(double range);
740 QString pse(int oz);//!< returns the chemical symbol for the given atomic number (starting from 0)
741 void loadSettings();
742 void dodecaeder(GLfloat r);
743 void icosaeder(GLfloat r);
744 void triacontaeder(GLfloat r);
745 void cube(GLfloat r);
746 int maxmols(){return maxmol;}//!< returns the number of fragments (molecules)
747 void newstructure(){maxmol=0;}//!< new structure initialize maxmol to 0
748 const QStringList thepse(){return PSE;}
749 int pseSize(){return PSE.size();}
750 Matrix u2b(Matrix u);//!< compute Bij values from Uij
751 Matrix b2u(Matrix u);//!< compute Uij values from Bij
752 double * jacobi(const Matrix &uij, V3 &ev);
753 void exportOBJ(QString fileName,const CEnvironment &atoms, const Connection &_bonds);
754
755 int rankMySymmOp(Matrix m, V3 t);
756 void message(const QString &);//!< small text messages to the status bar.
757 private:
758 void neighborSort(Knopf &kn);
759 bool checkExtensions();
760 double HAMax,HAWink;
761 //void ellipse(int style);
762 void hirsh(Connection bond);
763 void sphere(int adp,int style=7);
764 void mySphere(int bal);
765 void myCylinder(int rod);
766 void myCone();
767 void cylinder(double strength, double length);
768 // void ikosa(double R);
769 // V3 eigenvalues(const Matrix m);
770 // Matrix eigenvectors(const Matrix m,const V3 l);
771
772 int maxmol;
773
774 int lichtH;
775 int whiteringH;
776 int wallH;
777 int ballH;
778 int ringH;
779 int openH;
780 int adpsH;
781 int Licht;
782 int lodH;
783 int fogH;
784 int fograngeH;
785 int bgH;
786
787 QStringList PSE;
788 };
789
790 class Ring{
791 private:
792 bool complete;
793
794 public:
795 bool done;
796 QList<Tripel> t;
797 QList<int> members;
798 V3 center;
799 Ring(Tripel t1,Tripel t2){
800 complete=false;
801 done=false;
802 t.append(t1);
803 t.append(t2);
804 center = t1.midcenter + t2.midcenter;
805 members.append(t1.n[1]);
806 members.append(t1.n[0]);
807 members.append(t1.n[2]);
808 if (!members.contains(t2.n[1])) members.append(t2.n[1]);
809 if (!members.contains(t2.n[0])) members.append(t2.n[0]);
810 if (!members.contains(t2.n[2])) members.append(t2.n[2]);
811
812 }
813 ~Ring(){
814 t.clear();
815 members.clear();
816 }
817
818 bool isComplete(){
819 if (complete) return complete;
820 complete = (members.size()==t.size());
821 if (complete) bringInOrder();
822 //printf("CPLTE%d %d %d\n",complete,members.size(),t.size());
823 return complete;
824 }
825
826 V3 theCenter(){
827 return center*(1.0/t.size());
828 }
829
830 void bringInOrder(){
831 //printf("bio\n");
832 //for (int aai=0; aai<members.size(); aai++)printf("Members %d\n",members.at(aai));
833 members.clear();
834 members.append(t.at(0).n[0]);
835 int loop=0;
836 while (members.size()!=t.size()){
837 loop++;
838 for (int i=0; i<t.size(); i++){
839 if ((members.last()==t.at(i).n[1])&&(!members.contains(t.at(i).n[0]))&&((members.size()+1==t.size())||(members.first()!=t.at(i).n[2])))
840 members.append(t.at(i).n[0]); else
841 if ((members.last()==t.at(i).n[2])&&(!members.contains(t.at(i).n[0]))&&((members.size()+1==t.size())||(members.first()!=t.at(i).n[1])))
842 members.append(t.at(i).n[0]);
843 }
844 if (loop>50){
845 /*printf("ALARM? %d %d %d\n",members.size(),t.size(),loop);
846 for (int aai=0; aai<members.size(); aai++)printf("members %d\n",members.at(aai));
847 for (int tai=0; tai<t.size(); tai++)printf("t %d %d %d\n",t.at(tai).n[0],t.at(tai).n[1],t.at(tai).n[2]);*/
848 complete=false;
849 done=true;
850 members.clear();
851 return;
852 }
853 }
854 isItARealRing();
855 }
856
857 void isItARealRing(){
858 //printf("complete %d length %d %d\n",complete,t.size(),members.size());
859 if (complete==false) return;
860 bool killme=false;
861 killme = (t.size()!=members.size());
862 for (int i=0; i<t.size(); i++){
863 int u,v,w;
864 u=members.indexOf(t.at(i).n[0]);
865 v=members.indexOf(t.at(i).n[1]);
866 w=members.indexOf(t.at(i).n[2]);
867 killme|=!((((u+1)%t.size()==v)&&((u-1+t.size())%t.size()==w))||(((u+1)%t.size()==w)&&((u-1+t.size())%t.size()==v)));
868 killme|=(u*v*w<0);
869 /*printf("%d?%d %d %d %d ?%d\n",i,u,v,w,
870 (((u+1)%t.size()==v)&&((u-1+t.size())%t.size()==w))||
871 (((u+1)%t.size()==w)&&((u-1+t.size())%t.size()==v)),
872 u*v*w<0);// */
873
874 }
875 if (killme) {
876 //printf("NOT A REAL RING!\n");
877 complete=false;
878 members.clear();
879 done=true;
880 }
881 }
882
883 void printRing(Molecule *mol){
884 QString str="+";
885 for (int i = 0; i < members.size(); i++){
886 str.append(mol->asymm.at(members.at(i)).Label);
887 str.append((i==members.size()-1)?"+\n+":"=");
888 }
889 int l=str.size()-4;
890 for (int i=0; i<l; i++) str.append("=");
891 str.append("+\n");
892 printf("%s",str.toStdString().c_str());
893 str.clear();
894 }
895
896 void debugRing(Molecule *mol){
897 printRing(mol);
898 QString str="+";
899 for (int i = 0; i < t.size(); i++){
900 str.append("|");
901 str.append(mol->asymm.at(t.at(i).n[1]).Label);
902 str.append("~");
903 str.append(mol->asymm.at(t.at(i).n[0]).Label);
904 str.append("~");
905 str.append(mol->asymm.at(t.at(i).n[2]).Label);
906 str.append((i==t.size()-1)?"+\n+":"=");
907 }
908 int l=str.size()-4;
909 for (int i=0; i<l; i++) str.append("=");
910 str.append("+\n");
911 printf("%s",str.toStdString().c_str());
912 str.clear();
913
914 }
915
916 void addTripel(Tripel nt){
917 if (t.contains(nt)) return;
918 t.append(nt);
919 center += nt.midcenter;
920 if (!members.contains(nt.n[1])) members.append(nt.n[1]);
921 if (!members.contains(nt.n[0])) members.append(nt.n[0]);
922 if (!members.contains(nt.n[2])) members.append(nt.n[2]);
923 isComplete();
924 }
925
926 };
927 #endif