27 #include "ObjCryst/ObjCryst/Atom.h"
29 #include "ObjCryst/Quirks/VFNStreamFormat.h"
30 #include "ObjCryst/Quirks/VFNDebug.h"
34 #include <OpenGL/glu.h>
41 #include "ObjCryst/wxCryst/wxAtom.h"
58 :mScattCompList(1),mpScattPowAtom(0)
60 VFN_DEBUG_MESSAGE(
"Atom::Atom()",5)
67 :mScattCompList(1),mpScattPowAtom(pow)
69 VFN_DEBUG_MESSAGE(
"Atom::Atom(x,y,z,name,ScatteringPower):"<<name,5)
70 this->
Init(x,y,z,name,pow,1);
73 Atom::Atom(
const REAL x,
const REAL y,
const REAL z,
const string &name,
75 :mScattCompList(1),mpScattPowAtom(pow)
77 VFN_DEBUG_MESSAGE(
"Atom::Atom(x,y,z,P,B,name,ScatteringPower):"<<name,5)
82 :
Scatterer(old),mScattCompList(1),mpScattPowAtom(old.mpScattPowAtom)
84 VFN_DEBUG_MESSAGE(
"Atom::Atom(&old):/Name="<<old.
mName,5)
97 VFN_DEBUG_MESSAGE(
"Atom::CreateCopy():/Name="<<
mName,10)
98 return new Atom(*
this);
104 VFN_DEBUG_MESSAGE(
"Atom::~Atom():("<<
mName<<
")",5)
109 const static string className=
"Atom";
113 void Atom::operator=(
const Atom &rhs)
115 VFN_DEBUG_MESSAGE(
"Atom::operator=():/Name="<<rhs.
mName,5)
120 this->
Init(rhs.
mXYZ(0),rhs.mXYZ(1),rhs.mXYZ(2),
123 this->
GetPar(mXYZ.data()). CopyAttributes(rhs.
GetPar(rhs.mXYZ.data()));
124 this->
GetPar(mXYZ.data()+1).CopyAttributes(rhs.
GetPar(rhs.mXYZ.data()+1));
125 this->
GetPar(mXYZ.data()+2).CopyAttributes(rhs.
GetPar(rhs.mXYZ.data()+2));
126 this->
GetPar(&mOccupancy). CopyAttributes(rhs.
GetPar(&(rhs.mOccupancy)));
129 void Atom::
Init(const REAL x, const REAL y, const REAL z,
133 VFN_DEBUG_MESSAGE(
"Atom::Init():"<<name,3)
140 if(0==mpScattPowAtom)
142 VFN_DEBUG_MESSAGE(
"Atom::Init()Dummy Atom:/Name="<<this->
GetName(),5)
146 mpScattPowAtom->RegisterClient(*
this);
152 VFN_DEBUG_MESSAGE(
"Atom::Init():End.",5)
170 VFN_DEBUG_MESSAGE(
"Atom::Print()",1)
177 if(this->
IsDummy()) cout <<
" DUMMY! ";
189 if(
true==this->
IsDummy())
return 0;
195 if(this->
IsDummy())
return 0.5;
204 const REAL xMin=options.
mXmin;
const REAL xMax=options.mXmax;
205 const REAL yMin=options.mYmin;
const REAL yMax=options.mYmax;
206 const REAL zMin=options.mZmin;
const REAL zMax=options.mZmax;
214 CrystMatrix_REAL xyzCoords ;
216 int nbSymmetrics=xyzCoords.rows();
217 os <<
"// Description of Atom :" << this->
GetName()<< endl;
218 for(
int i=0;i<nbSymmetrics;i++)
223 x0 = fmod((
float) x0,(
float)1);
if(x0<0) x0+=1.;
224 y0 = fmod((
float) y0,(
float)1);
if(y0<0) y0+=1.;
225 z0 = fmod((
float) z0,(
float)1);
if(z0<0) z0+=1.;
227 CrystMatrix_int translate(27,3);
255 for(
int j=0;j<translate.rows();j++)
257 REAL x=x0+translate(j,0);
258 REAL y=y0+translate(j,1);
259 REAL z=z0+translate(j,2);
260 const bool isinside=((x>=xMin) && (x<=xMax)) && ((y>=yMin) && (y<=yMax)) && ((z>=zMin) && (z<=zMax));
262 if(isinside) borderdist=0;
266 if(xMin>x) borderdist+=(xMin-x)*aa*(xMin-x)*aa;
267 if(yMin>y) borderdist+=(yMin-y)*bb*(yMin-y)*bb;
268 if(zMin>z) borderdist+=(zMin-z)*cc*(zMin-z)*cc;
269 if(xMax<x) borderdist+=(xMax-x)*aa*(xMax-x)*aa;
270 if(yMax<y) borderdist+=(yMax-y)*bb*(yMax-y)*bb;
271 if(zMax<z) borderdist+=(zMax-z)*cc*(zMax-z)*cc;
272 borderdist=sqrt(borderdist);
279 os <<
" ObjCrystAtom("
294 const REAL xMin,
const REAL xMax,
295 const REAL yMin,
const REAL yMax,
296 const REAL zMin,
const REAL zMax,
297 const bool displayEnantiomer,
298 const bool displayNames,
299 const bool hideHydrogens)
const
302 VFN_DEBUG_MESSAGE(
"Atom::GLInitDisplayList():"<<this->
GetName(),5)
304 if(displayEnantiomer==
true) en=-1;
311 const GLfloat colour0[] = {.0, .0, .0, 0.0};
312 GLfloat colourChar [] = {1.0, 1.0, 1.0, 1.0};
313 if((r>0.8)&&(g>0.8)&&(b>0.8))
325 GLUquadricObj* pQuadric = gluNewQuadric();
326 if(
true==onlyIndependentAtoms)
328 const GLfloat colourAtom [] = {r, g, b, f};
333 x = fmod((REAL)x,(
int)1);
if(x<0) x+=1.;
334 y = fmod((REAL)y,(
int)1);
if(y<0) y+=1.;
335 z = fmod((REAL)z,(
int)1);
if(z<0) z+=1.;
338 glTranslatef(x*en, y, z);
341 glMaterialfv(GL_FRONT, GL_AMBIENT, colour0);
342 glMaterialfv(GL_FRONT, GL_DIFFUSE, colour0);
343 glMaterialfv(GL_FRONT, GL_SPECULAR, colour0);
344 glMaterialfv(GL_FRONT, GL_EMISSION, colourChar);
345 glMaterialfv(GL_FRONT, GL_SHININESS, colour0);
346 glRasterPos3f(0,0,0);
351 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colourAtom);
352 glMaterialfv(GL_FRONT, GL_SPECULAR, colour0);
353 glMaterialfv(GL_FRONT, GL_EMISSION, colour0);
354 glMaterialfv(GL_FRONT, GL_SHININESS, colour0);
355 glPolygonMode(GL_FRONT, GL_FILL);
356 gluSphere(pQuadric,this->
GetRadius()/3.,20,20);
366 CrystMatrix_REAL xyzCoords ;
368 int nbSymmetrics=xyzCoords.rows();
369 for(
int i=0;i<nbSymmetrics;i++)
374 x0 = fmod((REAL) x0,(
int)1);
if(x0<0) x0+=1.;
375 y0 = fmod((REAL) y0,(
int)1);
if(y0<0) y0+=1.;
376 z0 = fmod((REAL) z0,(
int)1);
if(z0<0) z0+=1.;
378 CrystMatrix_int translate(27,3);
406 for(
int j=0;j<translate.rows();j++)
408 REAL x=x0+translate(j,0);
409 REAL y=y0+translate(j,1);
410 REAL z=z0+translate(j,2);
411 const bool isinside=((x>=xMin) && (x<=xMax)) && ((y>=yMin) && (y<=yMax)) && ((z>=zMin) && (z<=zMax));
413 if(isinside) borderdist=0;
417 if(xMin>x) borderdist+=(xMin-x)*aa*(xMin-x)*aa;
418 if(yMin>y) borderdist+=(yMin-y)*bb*(yMin-y)*bb;
419 if(zMin>z) borderdist+=(zMin-z)*cc*(zMin-z)*cc;
420 if(xMax<x) borderdist+=(xMax-x)*aa*(xMax-x)*aa;
421 if(yMax<y) borderdist+=(yMax-y)*bb*(yMax-y)*bb;
422 if(zMax<z) borderdist+=(zMax-z)*cc*(zMax-z)*cc;
423 borderdist=sqrt(borderdist);
432 const GLfloat colourAtom [] = {r, g, b, f*fout};
435 glTranslatef(x*en, y, z);
440 glMaterialfv(GL_FRONT, GL_AMBIENT, colour0);
441 glMaterialfv(GL_FRONT, GL_DIFFUSE, colour0);
442 glMaterialfv(GL_FRONT, GL_SPECULAR, colour0);
443 glMaterialfv(GL_FRONT, GL_EMISSION, colourChar);
444 glMaterialfv(GL_FRONT, GL_SHININESS, colour0);
445 glRasterPos3f(0,0,0);
451 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colourAtom);
452 glMaterialfv(GL_FRONT, GL_SPECULAR, colour0);
453 glMaterialfv(GL_FRONT, GL_EMISSION, colour0);
454 glMaterialfv(GL_FRONT, GL_SHININESS, colour0);
455 glPolygonMode(GL_FRONT, GL_FILL);
456 gluSphere(pQuadric,this->
GetRadius()/3.,20,20);
463 gluDeleteQuadric(pQuadric);
464 VFN_DEBUG_MESSAGE(
"Atom::GLInitDisplayList():End",5)
474 CrystVector_uint & groupIndex,
475 unsigned int &first)
const
478 unsigned int posIndex=0;
479 VFN_DEBUG_MESSAGE(
"Atom::GetGeneGroup()",4)
481 for(
long j=0;j<this->
GetNbPar();j++)
486 if(posIndex==0) posIndex=first++;
487 groupIndex(i)=posIndex;
489 else groupIndex(i)= first++;
496 VFN_DEBUG_MESSAGE(
"Atom::InitRefParList()",5)
501 REFPAR_DERIV_STEP_ABSOLUTE,
false,
false,
true,
true,1.,1.);
507 REFPAR_DERIV_STEP_ABSOLUTE,
false,
false,
true,
true,1.,1.);
513 REFPAR_DERIV_STEP_ABSOLUTE,
false,
false,
true,
true,1.,1.);
521 gpRefParTypeScattOccup,REFPAR_DERIV_STEP_ABSOLUTE,
true,
true);
532 mpWXCrystObj=
new WXAtom(parent,
this);
CrystVector_REAL GetLatticePar() const
Lattice parameters (a,b,c,alpha,beta,gamma) as a 6-element vector in Angstroems and radians...
void Init(const REAL x, const REAL y, const REAL z, const string &name, const ScatteringPower *pow, const REAL popu=1)
initialize the atom (used for arrays of atoms).
void AddPar(const RefinablePar &newRefPar)
Add a refinable parameter.
REAL mXmin
Display limits in reduced coordinates.
virtual int GetNbComponent() const
Number of components in the scatterer (eg number of point scatterers)
virtual void GLInitDisplayList(const bool onlyIndependentAtoms=false, const REAL xMin=-.1, const REAL xMax=1.1, const REAL yMin=-.1, const REAL yMax=1.1, const REAL zMin=-.1, const REAL zMax=1.1, const bool displayEnantiomer=false, const bool displayNames=false, const bool hideHydrogens=false) const
void FractionalToOrthonormalCoords(REAL &x, REAL &y, REAL &z) const
Get orthonormal cartesian coordinates for a set of (x,y,z) fractional coordinates.
CrystVector_REAL mXYZ
coordinates of the scatterer (or of its center..)
void Click()
Record an event for this clock (generally, the 'time' an object has been modified, or some computation has been made)
virtual void Print() const
Print some info about the scatterer (ideally this should be one line...).
long GetNbPar() const
Total number of refinable parameter in the object.
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual Atom * CreateCopy() const
virtual REAL GetRadius() const =0
Return the physical radius of this type of scatterer (for 3D display purposes).
Generic Refinable Object.
REAL GetMass() const
Returns the molar mass of the atom.
const SpaceGroup & GetSpaceGroup() const
Access to the SpaceGroup object.
void ResetParList()
Re-init the list of refinable parameters, removing all parameters.
REAL GetZ() const
Z coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
REAL GetOccupancy() const
Get the occupancy of the scatterer (0.
Abstract base class for all objects in wxCryst.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
The basic atom scatterer, in a crystal.
ScatteringComponentList mScattCompList
The list of scattering components.
Class to store POV-Ray output options.
const ScatteringPower * mpScattPowAtom
The ScatteringPowerAtom associated to that atom.
RefinableObjClock mClockScattCompList
void AssignClock(RefinableObjClock &clock)
bool mShowHydrogens
Show hydrogens ?
REAL GetX() const
X coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
virtual void GetGeneGroup(const RefinableObj &obj, CrystVector_uint &groupIndex, unsigned int &firstGroup) const
Get the gene group assigned to each parameter.
CrystMatrix_REAL GetAllSymmetrics(const REAL x, const REAL y, const REAL z, const bool noCenter=false, const bool noTransl=false, const bool noIdentical=false) const
Get all equivalent positions of a (xyz) position.
virtual const ScatteringComponentList & GetScatteringComponentList() const
Get the list of all scattering components for this scatterer.
REAL mOccupancy
Occupancy : 0 <= occ <= 1 For a multi-atom scatterer (polyhedron,..), this is the overall occupancy o...
output a number as a formatted float:
REAL GetDynPopCorr(const Scatterer *pscatt, unsigned int component) const
Access the Dynamical Occupancy Correction for a given component (atom) in a given Scatterer...
Atom()
Default constructor.
output a string with a fixed length (adding necessary space or removing excess characters) : ...
const Crystal & GetCrystal() const
In which crystal is this Scatterer included ?
bool IsDescendantFromOrSameAs(const RefParType *type) const
Returns true if the parameter is a descendant of 'type'.
virtual REAL GetForwardScatteringFactor(const RadiationType) const =0
Get the scattering factor at (0,0,0).
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Generic class for parameters of refinable objects.
virtual string GetComponentName(const int i) const
Name for the i-th component of this scatterer.
virtual const string & GetName() const
Name of the object.
virtual void InitRefParList()
Prepare refinable parameters for the scatterer object.
REAL GetY() const
Y coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
REAL GetBiso() const
Returns the isotropic temperature B factor.
virtual ostream & POVRayDescription(ostream &os, const CrystalPOVRayOptions &options) const
XMLOutput a description of the scatterer for POVRay.
RefinableObjClock mClockScatterer
Last time anything (number of atoms, positions, scattering power) was changed.
list of scattering positions in a crystal, associated with the corresponding occupancy and a pointer ...
bool IsDummy() const
Is this a dummy atom ? (ie no ScatteringPower) Dummy atoms should not exist !
virtual const string & GetSymbol() const
Symbol for this Scattering power (the atom name for atoms)
Generic type of scatterer: can be an atom, or a more complex assembly of atoms.
REAL GetRadius() const
Returns the radius (in Angstroems) of the atom.
const ScatteringPower & GetScatteringPower() const
Get the ScatteringPowerAtom corresponding to this atom.
void SetGlobalOptimStep(const REAL)
Maximum step to use during Global Optimization algorithms.
const float * GetColourRGB() const
Get the float[3] array of RGB components defining the colour of this scattering power.
Abstract Base Class to describe the scattering power of any Scatterer component in a crystal...