forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkMolecule.h
487 lines (416 loc) · 13.1 KB
/
vtkMolecule.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMolecule.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkMolecule
* @brief class describing a molecule
*
*
*
* vtkMolecule and the convenience classes vtkAtom and vtkBond
* describe the geometry and connectivity of a molecule. The molecule
* can be constructed using the AppendAtom() and AppendBond() methods in one
* of two ways; either by fully specifying the atom/bond in a single
* call, or by incrementally setting the various attributes using the
* convenience vtkAtom and vtkBond classes:
*
* Single call:
* \code
* vtkMolecule *mol = vtkMolecule::New();
* vtkAtom h1 = mol->AppendAtom(1, 0.0, 0.0, -0.5);
* vtkAtom h2 = mol->AppendAtom(1, 0.0, 0.0, 0.5);
* vtkBond b = mol->AppendBond(h1, h2, 1);
* \endcode
*
* Incremental:
* \code
* vtkMolecule *mol = vtkMolecule::New();
*
* vtkAtom h1 = mol->AppendAtom();
* h1.SetAtomicNumber(1);
* h1.SetPosition(0.0, 0.0, -0.5);
*
* vtkAtom h2 = mol->AppendAtom();
* h2.SetAtomicNumber(1);
* vtkVector3d displacement (0.0, 0.0, 1.0);
* h2.SetPosition(h1.GetPositionAsVector3d() + displacement);
*
* vtkBond b = mol->AppendBond(h1, h2, 1);
* \endcode
*
* Both of the above methods will produce the same molecule, two
* hydrogens connected with a 1.0 Angstrom single bond, aligned to the
* z-axis. The second example also demonstrates the use of VTK's
* vtkVector class, which is fully supported by the Chemistry kit.
*
* The vtkMolecule object is intended to be used with the
* vtkMoleculeMapper class for visualizing molecular structure using
* common rendering techniques.
*
* \warning While direct use of the underlying vtkUndirectedGraph
* structure is possible due to vtkMolecule's public inheritance, this
* should not be relied upon and may change in the future.
*
* @sa
* vtkAtom vtkBond vtkMoleculeMapper vtkPeriodicTable
*/
#ifndef vtkMolecule_h
#define vtkMolecule_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkUndirectedGraph.h"
#include "vtkSmartPointer.h" // For vtkSmartPointer
#include "vtkAtom.h" // Simple proxy class dependent on vtkMolecule
#include "vtkBond.h" // Simple proxy class dependent on vtkMolecule
#include "vtkVector.h" // Small templated vector convenience class
class vtkAbstractElectronicData;
class vtkDataArray;
class vtkInformation;
class vtkInformationVector;
class vtkMatrix3x3;
class vtkPlane;
class vtkPoints;
class vtkUnsignedCharArray;
class vtkUnsignedShortArray;
class VTKCOMMONDATAMODEL_EXPORT vtkMolecule : public vtkUndirectedGraph
{
public:
static vtkMolecule *New();
vtkTypeMacro(vtkMolecule,vtkUndirectedGraph);
void PrintSelf(ostream &os, vtkIndent indent) override;
void Initialize() override;
/**
* Return what type of dataset this is.
*/
int GetDataObjectType() override {return VTK_MOLECULE;}
/**
* Add new atom with atomic number 0 (dummy atom) at origin. Return
* a vtkAtom that refers to the new atom.
*/
vtkAtom AppendAtom()
{
return this->AppendAtom(0, vtkVector3f(0, 0, 0));
}
/**
* Add new atom with the specified atomic number and position. Return a
* vtkAtom that refers to the new atom.
*/
vtkAtom AppendAtom(unsigned short atomicNumber, const vtkVector3f &pos);
/**
* Convenience methods to append a new atom with the specified atomic number
* and position.
*/
vtkAtom AppendAtom(unsigned short atomicNumber, double x, double y, double z)
{
return this->AppendAtom(atomicNumber, vtkVector3f(x, y, z));
}
/**
* Return a vtkAtom that refers to the atom with the specified id.
*/
vtkAtom GetAtom(vtkIdType atomId);
/**
* Return the number of atoms in the molecule.
*/
vtkIdType GetNumberOfAtoms();
//@{
/**
* Add a bond between the specified atoms, optionally setting the
* bond order (default: 1). Return a vtkBond object referring to the
* new bond.
*/
vtkBond AppendBond(vtkIdType atom1, vtkIdType atom2,
unsigned short order = 1);
vtkBond AppendBond(const vtkAtom &atom1, const vtkAtom &atom2,
unsigned short order = 1)
{
return this->AppendBond(atom1.Id, atom2.Id, order);
}
//@}
/**
* Return a vtkAtom that refers to the bond with the specified id.
*/
vtkBond GetBond(vtkIdType bondId);
/**
* Return the number of bonds in the molecule.
*/
vtkIdType GetNumberOfBonds();
/**
* Return the atomic number of the atom with the specified id.
*/
unsigned short GetAtomAtomicNumber(vtkIdType atomId);
/**
* Set the atomic number of the atom with the specified id.
*/
void SetAtomAtomicNumber(vtkIdType atomId,
unsigned short atomicNum);
//@{
/**
* Set the position of the atom with the specified id.
*/
void SetAtomPosition(vtkIdType atomId, const vtkVector3f &pos);
void SetAtomPosition(vtkIdType atomId, double x, double y, double z);
//@}
//@{
/**
* Get the position of the atom with the specified id.
*/
vtkVector3f GetAtomPosition(vtkIdType atomId);
void GetAtomPosition(vtkIdType atomId, float pos[3]);
//@}
//@{
/**
* Get/Set the bond order of the bond with the specified id
*/
void SetBondOrder(vtkIdType bondId, unsigned short order);
unsigned short GetBondOrder(vtkIdType bondId);
//@}
/**
* Get the bond length of the bond with the specified id
* \note If the associated vtkBond object is already available,
* vtkBond::GetBondLength is potentially much faster than this
* function, as a list of all bonds may need to be constructed to
* locate the appropriate bond.
* \sa UpdateBondList()
*/
double GetBondLength(vtkIdType bondId);
//@{
/**
* Access the raw arrays used in this vtkMolecule instance
*/
vtkPoints * GetAtomicPositionArray();
vtkUnsignedShortArray * GetAtomicNumberArray();
vtkUnsignedShortArray * GetBondOrdersArray();
//@}
//@{
/**
* Set/Get the AbstractElectronicData-subclassed object for this molecule.
*/
vtkGetObjectMacro(ElectronicData, vtkAbstractElectronicData);
virtual void SetElectronicData(vtkAbstractElectronicData*);
//@}
/**
* Performs the same operation as ShallowCopy(),
* but instead of reporting an error for an incompatible graph,
* returns false.
*/
bool CheckedShallowCopy(vtkGraph *g) override;
/**
* Performs the same operation as DeepCopy(),
* but instead of reporting an error for an incompatible graph,
* returns false.
*/
bool CheckedDeepCopy(vtkGraph *g) override;
/**
* Shallow copies the data object into this molecule.
*/
void ShallowCopy(vtkDataObject *obj) override;
/**
* Deep copies the data object into this molecule.
*/
void DeepCopy(vtkDataObject *obj) override;
/**
* Shallow copies the atoms and bonds from @a m into @a this.
*/
virtual void ShallowCopyStructure(vtkMolecule *m);
/**
* Deep copies the atoms and bonds from @a m into @a this.
*/
virtual void DeepCopyStructure(vtkMolecule *m);
/**
* Shallow copies attributes (i.e. everything besides atoms and bonds) from
* @a m into @a this.
*/
virtual void ShallowCopyAttributes(vtkMolecule *m);
/**
* Deep copies attributes (i.e. everything besides atoms and bonds) from
* @a m into @a this.
*/
virtual void DeepCopyAttributes(vtkMolecule *m);
//@{
/**
* Obtain the plane that passes through the indicated bond with the given
* normal. If the plane is set successfully, the function returns true.
* If the normal is not orthogonal to the bond, a new normal will be
* constructed in such a way that the plane will be orthogonal to
* the plane spanned by the bond vector and the input normal vector.
* This ensures that the plane passes through the bond, and the
* normal is more of a "hint" indicating the orientation of the plane.
* The new normal (n) is defined as the input normal vector (n_i) minus
* the projection of itself (proj[n_i]_v) onto the bond vector (v):
* @verbatim
* v ^
* | n = (n_i - proj[n_j]_v)
* proj[n_i]_v ^ |----x
* | | /
* | | / n_i
* | | /
* | |/
* @endverbatim
* If n_i is parallel to v, a warning will be printed and no plane will be
* added. Obviously, n_i must not be parallel to v.
*/
static bool GetPlaneFromBond(const vtkBond &bond, const vtkVector3f &normal,
vtkPlane *plane);
static bool GetPlaneFromBond(const vtkAtom &atom1, const vtkAtom &atom2,
const vtkVector3f &normal, vtkPlane *plane);
//@}
/**
* Return true if a unit cell lattice is defined.
*/
bool HasLattice();
/**
* Remove any unit cell lattice information from the molecule.
*/
void ClearLattice();
//@{
/**
* The unit cell vectors. The matrix is stored using a row-major layout, with
* the vectors encoded as columns.
*/
void SetLattice(vtkMatrix3x3 *matrix);
void SetLattice(const vtkVector3d &a,
const vtkVector3d &b,
const vtkVector3d &c);
//@}
/**
* Get the unit cell lattice vectors. The matrix is stored using a row-major
* layout, with the vectors encoded as columns. Will return nullptr if no
* unit cell information is available.
* @sa GetLatticeOrigin
*/
vtkMatrix3x3* GetLattice();
//@{
/**
* Get the unit cell lattice vectors, and optionally, the origin.
*/
void GetLattice(vtkVector3d &a, vtkVector3d &b, vtkVector3d &c);
void GetLattice(vtkVector3d &a, vtkVector3d &b, vtkVector3d &c,
vtkVector3d &origin);
//@}
//@{
/**
* Get the unit cell origin (for rendering purposes).
*/
vtkGetMacro(LatticeOrigin, vtkVector3d)
vtkSetMacro(LatticeOrigin, vtkVector3d)
//@}
/**
* Get the array that defines the ghost type of each atom.
*/
vtkUnsignedCharArray* GetAtomGhostArray();
/**
* Allocate ghost array for atoms.
*/
void AllocateAtomGhostArray();
/**
* Get the array that defines the ghost type of each bond.
*/
vtkUnsignedCharArray* GetBondGhostArray();
/**
* Allocate ghost array for bonds.
*/
void AllocateBondGhostArray();
/**
* Initialize a molecule with an atom per input point.
* Parameters atomPositions and atomicNumberArray should have the same size.
*/
int Initialize(vtkPoints* atomPositions,
vtkDataArray* atomicNumberArray,
vtkDataSetAttributes* atomData);
/**
* Overloads Initialize method.
*/
int Initialize(vtkPoints* atomPositions,
vtkDataSetAttributes* atomData)
{
return this->Initialize(atomPositions, nullptr, atomData);
}
/**
* Use input molecule points, atomic number and atomic data to initialize the new molecule.
*/
int Initialize(vtkMolecule* molecule);
//@{
/**
* Retrieve a molecule from an information vector.
*/
static vtkMolecule* GetData(vtkInformation *info);
static vtkMolecule* GetData(vtkInformationVector *v, int i=0);
//@}
/**
* Return the VertexData of the underlying graph
*/
vtkDataSetAttributes* GetAtomData()
{
return this->GetVertexData();
}
/**
* Return the EdgeData of the underlying graph
*/
vtkDataSetAttributes* GetBondData()
{
return this->GetEdgeData();
}
/**
* Return the edge id from the underlying graph.
*/
vtkIdType GetBondId(vtkIdType a, vtkIdType b)
{
return this->GetEdgeId(a, b);
}
//@{
/**
* Get/Set the atomic number array name.
*/
vtkSetStringMacro(AtomicNumberArrayName);
vtkGetStringMacro(AtomicNumberArrayName);
//@}
//@{
/**
* Get/Set the bond orders array name.
*/
vtkSetStringMacro(BondOrdersArrayName);
vtkGetStringMacro(BondOrdersArrayName);
//@}
protected:
vtkMolecule();
~vtkMolecule() override;
/**
* Copy bonds and atoms.
*/
virtual void CopyStructureInternal(vtkMolecule *m, bool deep);
/**
* Copy everything but bonds and atoms.
*/
virtual void CopyAttributesInternal(vtkMolecule *m, bool deep);
//@{
/**
* The graph superclass does not provide fast random access to the
* edge (bond) data. All random access is performed using a lookup
* table that must be rebuilt periodically. These allow for lazy
* building of the lookup table
*/
bool BondListIsDirty;
void SetBondListDirty() {this->BondListIsDirty = true;}
void UpdateBondList();
vtkIdTypeArray* GetBondList();
//@}
friend class vtkAtom;
friend class vtkBond;
vtkAbstractElectronicData *ElectronicData;
vtkSmartPointer<vtkMatrix3x3> Lattice;
vtkVector3d LatticeOrigin;
vtkUnsignedCharArray* AtomGhostArray;
vtkUnsignedCharArray* BondGhostArray;
char* AtomicNumberArrayName;
char* BondOrdersArrayName;
private:
vtkMolecule(const vtkMolecule&) = delete;
void operator=(const vtkMolecule&) = delete;
};
#endif