/**************************************************************************** ** ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick ** All rights reserved. ** Contact: chuebsch@moliso.de ** ** This file is part of the ShelXle ** ** This file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file COPYING included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** ****************************************************************************/ #ifndef MOLECULE_H #define MOLECULE_H 1 #include #if defined _MSC_VER && _MSC_VER == 1500 #ifndef fmin #define fmin(x, y) (((x) < (y)) ? (x) : (y)) #endif #ifndef fmax #define fmax(x, y) (((x) > (y)) ? (x) : (y)) #endif #ifndef round #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5)) #endif #endif #include #include #include #include #include //#if defined (Q_WS_MAC) || defined(Q_OS_MAC) //#include // //#include //#else //#include //#endif //#include "glureplace.h" #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_PIf #define M_PIf 3.14159265358979323846f #endif #define ATOM_STYLE_WALLS 1 #define ATOM_STYLE_RINGS 2 #define ATOM_STYLE_SPHERE 4 #define ATOM_STYLE_SOLID 8 #define ATOM_STYLE_WHITERING 16 #define ATOM_STYLE_NOLABEL 32 #define ATOM_STYLE_NOADP 64 #define ATOM_STYLE_PLAID 128 #define ATOM_STYLE_METAL 256 #include #ifndef GLAPIENTRY #if defined(_MSC_VER) || defined(__MINGW32__) #define GLAPIENTRY __stdcall #else #define GLAPIENTRY #endif #endif #ifndef GLAPIENTRYP #define GLAPIENTRYP GLAPIENTRY * #endif typedef void (GLAPIENTRYP GLU_func_ptr)(void); //GLOBAL SETTINGS //static int global_zero_counter=0; //! V3 is a three dimensional vector in cartesian space struct V3 { double x//! x is the X coordinate ,y//! y is the Y coordinate ,z//! z is the Z coordinate ; // int rc; inline V3( void ){} inline V3( const double& _x, const double& _y, const double& _z ) : x(_x), y(_y), z(_z)//!< initializer //,rc(0) { ; } inline V3& operator *= ( const double& d ){ x *= d; y *= d; z *= d; return *this; }//!< The *= operator to scale by a scalar inline V3& operator += ( const V3& v ){ x += v.x; y += v.y; z += v.z; return *this; }//!< The += operator to add a V3 inline V3& operator += ( const double& v ){ x += v; y += v; z += v; return *this; }//!< The += operator to add a scalar }; inline V3 operator + ( const V3& v1, const V3& v2 ) { V3 t; t.x = v1.x + v2.x; t.y = v1.y + v2.y; t.z = v1.z + v2.z; return t; }//!< The + operator to add two V3 inline V3 operator - ( const V3& v1, const V3& v2 ) { V3 t; t.x = v1.x - v2.x; t.y = v1.y - v2.y; t.z = v1.z - v2.z; return t; }//!< The + operator to subtract two V3 inline V3 operator * ( const V3& v, const double& d ) { V3 t; t.x = v.x*d; t.y = v.y*d; t.z = v.z*d; return t; }//!< The * to scale a V3 inline V3 operator * ( const double& d, const V3& v ) { V3 t; t.x = v.x*d; t.y = v.y*d; t.z = v.z*d; return t; }//!< The * to scale a V3 inline V3 operator % ( const V3& v1, const V3& v2 ) { V3 t; t.x = v1.y*v2.z - v2.y*v1.z; t.y = v1.z*v2.x - v2.z*v1.x; t.z = v1.x*v2.y - v2.x*v1.y; return t; }//!< The % operator the cross product of two V3 inline double operator * ( const V3& v1, const V3& v2 ) { return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; }//!< The * operator the scalar product of two V3 inline double Norm( const V3& v ) { return v.x*v.x + v.y*v.y + v.z*v.z; }//!< The squared lenght of a V3 inline double Distance( const V3& v1, const V3& v2 ) { return Norm(v1 - v2); }//!< The squared distance between two V3 inline bool operator == (const V3& v1, const V3& v2 ) { // return ((v1.x==v2.x)&&(v1.y==v2.y)&&(v1.z==v2.z)); return (Distance(v1,v2)<0.005); } inline V3& Normalize( V3 v ) { static V3 erg=V3(1,0,0); if (Norm(v)) erg= (v * (1.0/sqrt(Norm(v)))); return erg; } //! Matrix is a 3 x 3 Matrix with all needed operators struct Matrix{ double m11, m21, m31, m12, m22, m32, m13, m23, m33; inline Matrix(void){} inline Matrix( const V3 &a, const V3 &b, const V3 &c): m11(a.x), m21(b.x), m31(c.x), m12(a.y), m22(b.y), m32(c.y), m13(a.z), m23(b.z), m33(c.z){;} inline Matrix( const double& x11, const double& x21, const double& x31, const double& x12, const double& x22, const double& x32, const double& x13, const double& x23, const double& x33): m11(x11), m21(x21), m31(x31), m12(x12), m22(x22), m32(x32), m13(x13), m23(x23), m33(x33){;} inline Matrix( const QMatrix4x4 &m44): m11(m44(0,0)), m21(m44(0,1)), m31(m44(0,2)), m12(m44(1,0)), m22(m44(1,1)), m32(m44(1,2)), m13(m44(2,0)), m23(m44(2,1)), m33(m44(2,2)) {;} inline Matrix( const QMatrix3x3 &m33): m11(m33(0,0)), m21(m33(0,1)), m31(m33(0,2)), m12(m33(1,0)), m22(m33(1,1)), m32(m33(1,2)), m13(m33(2,0)), m23(m33(2,1)), m33(m33(2,2)) {;} inline Matrix operator *= (const double a){ m11 *= a; m21 *= a; m31 *= a; m12 *= a; m22 *= a; m32 *= a; m13 *= a; m23 *= a; m33 *= a; return *this; } }; inline Matrix transponse (Matrix a){//transponse return Matrix( a.m11, a.m12, a.m13, a.m21, a.m22, a.m23, a.m31, a.m32, a.m33); } inline double determinant (Matrix a){ 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; } inline Matrix inverse (Matrix A){ double D = determinant(A); if (D==0) return A; D=1.0/D; return Matrix( D*(A.m22*A.m33-A.m23*A.m32),//x11 D*(A.m13*A.m32-A.m12*A.m33),//x21 D*(A.m21*A.m23-A.m13*A.m22),//x31 D*(A.m23*A.m31-A.m21*A.m33),//x12 D*(A.m11*A.m33-A.m13*A.m31),//x22 D*(A.m13*A.m21-A.m11*A.m23),//x32 D*(A.m21*A.m32-A.m22*A.m31),//x13 D*(A.m12*A.m31-A.m11*A.m32),//x23 D*(A.m11*A.m22-A.m12*A.m21)//x33 ); } inline bool operator == (const Matrix &a,const Matrix &b){ return ((a.m11 == b.m11)&&(a.m21 == b.m21)&&(a.m31 == b.m31)&& (a.m12 == b.m12)&&(a.m22 == b.m22)&&(a.m23 == b.m23)&& (a.m13 == b.m13)&&(a.m32 == b.m32)&&(a.m33 == b.m33)); } inline Matrix operator * (const Matrix &a,const Matrix &b){ Matrix erg; erg.m11 = a.m11 * b.m11 + a.m21 * b.m12 + a.m31 * b.m13; erg.m21 = a.m11 * b.m21 + a.m21 * b.m22 + a.m31 * b.m23; erg.m31 = a.m11 * b.m31 + a.m21 * b.m32 + a.m31 * b.m33; erg.m12 = a.m12 * b.m11 + a.m22 * b.m12 + a.m32 * b.m13; erg.m22 = a.m12 * b.m21 + a.m22 * b.m22 + a.m32 * b.m23; erg.m32 = a.m12 * b.m31 + a.m22 * b.m32 + a.m32 * b.m33; erg.m13 = a.m13 * b.m11 + a.m23 * b.m12 + a.m33 * b.m13; erg.m23 = a.m13 * b.m21 + a.m23 * b.m22 + a.m33 * b.m23; erg.m33 = a.m13 * b.m31 + a.m23 * b.m32 + a.m33 * b.m33; return erg; } inline V3 operator * (const Matrix &a, const V3 &b){ V3 erg; erg.x = a.m11*b.x + a.m21*b.y + a.m31*b.z; erg.y = a.m12*b.x + a.m22*b.y + a.m32*b.z; erg.z = a.m13*b.x + a.m23*b.y + a.m33*b.z; return erg; } inline V3 operator * (const V3 &a, const Matrix &b){ V3 erg; erg.x = b.m11*a.x + b.m12*a.y + b.m13*a.z; erg.y = b.m21*a.x + b.m22*a.y + b.m23*a.z; erg.z = b.m31*a.x + b.m32*a.y + b.m33*a.z; return erg; } inline Matrix operator * (const Matrix &a,const double &b){ Matrix erg; erg.m11 = a.m11*b; erg.m21 = a.m21*b; erg.m31 = a.m31*b; erg.m12 = a.m12*b; erg.m22 = a.m22*b; erg.m32 = a.m32*b; erg.m13 = a.m13*b; erg.m23 = a.m23*b; erg.m33 = a.m33*b; return erg; } inline Matrix operator + (const Matrix &a, const Matrix &b){ Matrix erg; erg.m11 = a.m11+b.m11; erg.m21 = a.m21+b.m21; erg.m31 = a.m31+b.m31; erg.m12 = a.m12+b.m12; erg.m22 = a.m22+b.m22; erg.m32 = a.m32+b.m32; erg.m13 = a.m13+b.m13; erg.m23 = a.m23+b.m23; erg.m33 = a.m33+b.m33; return erg; } inline bool operator < (const Matrix &a, const Matrix &b){ return ( (a.m11