4
* Gnome Chemistry Utils
7
* Copyright (C) 2002-2005 Jean Bréfort <jean.brefort@normalesup.org>
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License as
11
* published by the Free Software Foundation; either version 2 of the
12
* License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
27
#include "crystalatom.h"
29
#include "xml-utils.h"
36
CrystalAtom::CrystalAtom(): Atom()
38
m_Radius.Z = (unsigned char) GetZ();
39
m_Radius.type = GCU_RADIUS_UNKNOWN;
40
m_Radius.scale = NULL;
41
m_Radius.spin = GCU_N_A_SPIN,
43
m_Radius.value.value = 0.0;
44
m_Radius.value.prec = 0;
46
m_bCustomColor = false;
47
m_fRed = m_fBlue = m_fGreen = 0;
52
CrystalAtom::~CrystalAtom()
56
CrystalAtom::CrystalAtom(int Z, double x, double y, double z): Atom(Z, x, y, z)
58
m_Radius.Z = (unsigned char) GetZ();
59
m_Radius.type = GCU_RADIUS_UNKNOWN;
60
m_Radius.scale = NULL;
61
m_Radius.spin = GCU_N_A_SPIN,
63
m_Radius.value.value = 0.0;
64
m_Radius.value.prec = 0;
67
if (Z) SetDefaultColor();
71
CrystalAtom::CrystalAtom(CrystalAtom& caAtom): Atom(caAtom)
73
m_Radius.scale = NULL;
74
SetRadius(caAtom.m_Radius);
75
m_bCustomColor = caAtom.m_bCustomColor;
76
m_fRed = caAtom.m_fRed;
77
m_fGreen = caAtom.m_fGreen;
78
m_fBlue = caAtom.m_fBlue;
79
m_fAlpha = caAtom.m_fAlpha;
83
CrystalAtom& CrystalAtom::operator=(CrystalAtom& caAtom)
87
caAtom.GetCoords(&x, &y, &z);
89
SetRadius(caAtom.m_Radius);
90
m_bCustomColor = caAtom.m_bCustomColor;
91
m_fRed = caAtom.m_fRed ;
92
m_fGreen = caAtom.m_fGreen ;
93
m_fBlue = caAtom.m_fBlue ;
94
m_fAlpha = caAtom.m_fAlpha ;
99
void CrystalAtom::Draw()
101
if (m_nCleave) return ;
102
GLUquadricObj *quadObj ;
104
glTranslated(y(), z(), x()) ;
105
glColor4f(m_fRed, m_fGreen, m_fBlue, m_fAlpha) ;
106
quadObj = gluNewQuadric() ;
107
gluQuadricDrawStyle(quadObj, GL_FILL);
108
gluQuadricNormals(quadObj, GL_SMOOTH) ;
109
gluSphere(quadObj, m_Radius.value.value, 20, 10) ;
110
gluDeleteQuadric(quadObj) ;
114
void CrystalAtom::SetColor(float red, float green, float blue, float alpha)
116
m_bCustomColor = true;
123
void CrystalAtom::SetDefaultColor()
125
m_bCustomColor = false;
126
double *Colors = Element::GetElement(GetZ())->GetDefaultColor();
127
m_fRed = (float) Colors[0];
128
m_fGreen = (float) Colors[1];
129
m_fBlue = (float) Colors[2];
132
void CrystalAtom::GetColor(double *red, double *green, double *blue, double *alpha)
140
void CrystalAtom::SetSize(double r)
142
m_Radius.Z = (unsigned char) GetZ();
143
m_Radius.type = GCU_RADIUS_UNKNOWN;
144
m_Radius.scale = NULL;
145
m_Radius.spin = GCU_N_A_SPIN,
147
m_Radius.value.value = 0.0;
148
m_Radius.value.prec = 0;
150
m_Radius.value.value = 0.0;
151
m_Radius.value.prec = 0;
155
double CrystalAtom::GetSize()
157
return m_Radius.value.value;
160
bool CrystalAtom::operator==(CrystalAtom& caAtom)
162
return (x() == caAtom.x()) &&
163
(y() == caAtom.y()) &&
164
(z() == caAtom.z()) ;
167
double CrystalAtom::ScalProd(int h, int k, int l)
169
return x() * h + y() * k + z() * l ;
172
double CrystalAtom::Distance(double dx, double dy, double dz, bool bFixed)
174
if ((m_nCleave > 0) && ! bFixed) return 0. ;
178
return sqrt(dx * dx + dy * dy + dz * dz) + m_Radius.value.value ;
181
void CrystalAtom::NetToCartesian(double a, double b, double c, double alpha, double beta, double gamma)
183
double dx = x() * a ;
184
double dy = y() * b ;
185
double dz = z() * c ;
186
SetCoords(dx * sqrt(1-square(cos(beta)) - square((cos(gamma) - cos(beta)*cos(alpha))/sin(alpha))),
187
dx * (cos(gamma) - cos(beta)*cos(alpha))/sin(alpha) + dy * sin(alpha),
188
(dx * cos(beta) + dy * cos(alpha) + dz));
191
bool CrystalAtom::SaveNode (xmlDocPtr xml, xmlNodePtr node)
193
if (!WriteRadius (xml, node, m_Radius))
196
if (m_bCustomColor && !WriteColor (xml, node, NULL, m_fRed, m_fGreen, m_fBlue, m_fAlpha))
202
bool CrystalAtom::LoadNode(xmlNodePtr node)
204
xmlNodePtr child = FindNodeByNameAndId(node, "color");
205
if (!child) SetDefaultColor();
208
if (!ReadColor(node, NULL, &m_fRed, &m_fGreen, &m_fBlue, &m_fAlpha)) return false;
209
m_bCustomColor = true;
211
child = FindNodeByNameAndId(node, "radius");
212
if (!child) return false;
214
bool result = ReadRadius(child, m_Radius);
218
void CrystalAtom::SetRadius(const GcuAtomicRadius& r)
220
m_Radius.type = r.type;
221
m_Radius.value = r.value;
222
m_Radius.charge = r.charge;
223
m_Radius.scale = r.scale;
224
m_Radius.cn = r.cn; //coordination number: -1: unspecified
225
m_Radius.spin = r.spin;