Psi4
pointgrp.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2018 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 //
30 // pointgrp.h
31 //
32 // Additional modifications made by Justin Turney <jturney@ccqc.uga.edu>
33 // for use in PSI4.
34 //
35 // Modifications are
36 // Copyright (C) 1996 Limit Point Systems, Inc.
37 //
38 // Author: Edward Seidl <seidl@janed.com>
39 // Maintainer: LPS
40 //
41 // This file is part of the SC Toolkit.
42 //
43 // The SC Toolkit is free software; you can redistribute it and/or modify
44 // it under the terms of the GNU Library General Public License as published by
45 // the Free Software Foundation; either version 2, or (at your option)
46 // any later version.
47 //
48 // The SC Toolkit is distributed in the hope that it will be useful,
49 // but WITHOUT ANY WARRANTY; without even the implied warranty of
50 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 // GNU Library General Public License for more details.
52 //
53 // You should have received a copy of the GNU General Public License along
54 // with this program; if not, write to the Free Software Foundation, Inc.,
55 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
56 //
57 // The U.S. Government is granted a limited license as per AL 91-7.
58 //
59 
60 /* pointgrp.h -- definition of the point group classes
61  *
62  * THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
63  * "UNITED STATES GOVERNMENT WORK". IT WAS WRITTEN AS A PART OF THE
64  * AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE. THIS MEANS IT
65  * CANNOT BE COPYRIGHTED. THIS SOFTWARE IS FREELY AVAILABLE TO THE
66  * PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
67  * RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
68  *
69  * Author:
70  * E. T. Seidl
71  * Bldg. 12A, Rm. 2033
72  * Computer Systems Laboratory
73  * Division of Computer Research and Technology
74  * National Institutes of Health
75  * Bethesda, Maryland 20892
76  * Internet: seidl@alw.nih.gov
77  * June, 1993
78  */
79 
80 #ifndef _math_symmetry_pointgrp_h
81 #define _math_symmetry_pointgrp_h
82 
83 #include "psi4/libmints/vector3.h"
84 #include "psi4/psi4-dec.h"
85 
86 #include <cstring>
87 #include <cstdio>
88 #include <cstdint>
89 #include <vector>
90 #include <map>
91 
92 #include "psi4/pragma.h"
93 PRAGMA_WARNING_PUSH
94 PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS
95 #include <memory>
97 
98 namespace psi {
99 
100 #define NUM_TO_OPERATOR_ID(x) ((x) ? 1 << ((x)-1) : 0)
101 #define SKIP_THIS_OPERATOR(num, bit) ((bit) ? !((1 << ((bit)-1)) & (num)) : 0)
102 
103 namespace SymmOps {
104 enum Operations { E = 0, C2_z = 1, C2_y = 2, C2_x = 4, i = 8, Sigma_xy = 16, Sigma_xz = 32, Sigma_yz = 64, ID = 128 };
105 }
106 
107 namespace PointGroups {
108 enum Groups {
126 };
127 
128 void similar(unsigned char bits, unsigned char* sim, char& cnt);
129 
130 } // namespace PointGroups
131 
132 // //////////////////////////////////////////////////////////////////
133 
138  private:
139  // Some necessary Python imports become nightmarish if you try double[3][3]
140  // While a std::array<double, 9> would be simpler, it hurts code readability...
141  // ...and forces an otherwise unnecessary reshape, Py-side.
142  std::array<std::array<double, 3>, 3> d;
143  unsigned short bits_;
144 
145  void analyze_d();
146 
147  public:
151 
152  SymmetryOperation& operator=(SymmetryOperation const& a); // Assignment operator
153 
155  double trace() const { return d[0][0] + d[1][1] + d[2][2]; }
156 
157  // For the sake of Python export, expose d to reading
158  const std::array<std::array<double, 3>, 3>& matrix() { return d; }
159 
161  double* operator[](int i) { return &d[i][0]; }
162 
164  const double* operator[](int i) const { return &d[i][0]; }
165 
168  double& operator()(int i, int j) { return d[i][j]; }
169 
171  double operator()(int i, int j) const { return d[i][j]; }
172 
174  void zero() { ::memset(&d, 0, sizeof(double) * 9); }
175 
178 
181 
183  unsigned char bit() const { return bits_; }
184 
186  void unit() {
187  zero();
188  d[0][0] = d[1][1] = d[2][2] = 1.0;
189  }
190 
192  void E() {
193  unit();
194  bits_ = SymmOps::E;
195  }
196 
198  void i() {
199  zero();
200  d[0][0] = d[1][1] = d[2][2] = -1.0;
201  bits_ = SymmOps::i;
202  }
203 
205  void sigma_xy() {
206  unit();
207  d[2][2] = -1.0;
209  }
210 
212  void sigma_xz() {
213  unit();
214  d[1][1] = -1.0;
216  }
217 
219  void sigma_yz() {
220  unit();
221  d[0][0] = -1.0;
223  }
224 
226  void rotation(int n);
227  void rotation(double theta);
228 
230  void c2_x() {
231  i();
232  d[0][0] = 1.0;
234  }
235 
237  void c2_y() {
238  i();
239  d[1][1] = 1.0;
241  }
242 
244  void c2_z() {
245  i();
246  d[2][2] = 1.0;
248  }
249 
250  void transpose();
251 
253  void print(std::string out);
254 };
255 
256 // //////////////////////////////////////////////////////////////////
257 
263 class SymRep {
264  private:
265  int n;
266  double d[5][5];
267 
268  public:
269  SymRep(int = 0);
270  SymRep(const SymmetryOperation&);
271  ~SymRep();
272 
274  operator SymmetryOperation() const;
275 
277  inline double trace() const;
278 
280  void set_dim(int i) { n = i; }
281 
283  double* operator[](int i) { return d[i]; }
285  const double* operator[](int i) const { return d[i]; }
286 
289  double& operator()(int i, int j) { return d[i][j]; }
291  double operator()(int i, int j) const { return d[i][j]; }
292 
294  void zero() { ::memset(d, 0, sizeof(double) * 25); }
295 
297  SymRep operate(const SymRep& r) const;
298 
300  SymRep transform(const SymRep& r) const;
301 
303  void unit() {
304  zero();
305  d[0][0] = d[1][1] = d[2][2] = d[3][3] = d[4][4] = 1.0;
306  }
307 
309  void E() { unit(); }
310 
312  void i() {
313  zero();
314  d[0][0] = d[1][1] = d[2][2] = d[3][3] = d[4][4] = -1.0;
315  }
316 
318  void sigma_h();
319 
321  void sigma_xz();
322 
324  void sigma_yz();
325 
327  void rotation(int n);
328  void rotation(double theta);
329 
331  void c2_x();
332 
334  void c2_y();
335 
337  void c2_z();
338 
340  // void print(std::ostream& =ExEnv::out0()) const;
341 };
342 
343 inline double SymRep::trace() const {
344  double r = 0;
345  for (int i = 0; i < n; i++) r += d[i][i];
346  return r;
347 }
348 
349 // //////////////////////////////////////////////////////////////////
350 
352 
361  friend class CharacterTable;
362 
363  private:
364  int g; // the order of the group
365  int degen; // the degeneracy of the irrep
366  int nrot_; // the number of rotations in this irrep
367  int ntrans_; // the number of translations in this irrep
368  int complex_; // true if this irrep has a complex representation
369  char* symb; // mulliken symbol for this irrep
370  char* csymb; // mulliken symbol for this irrep w/o special characters
371 
372  SymRep* rep; // representation matrices for the symops
373 
374  public:
380  IrreducibleRepresentation(int, int, const char*, const char* = nullptr);
381 
383 
385 
387  void init(int = 0, int = 0, const char* = nullptr, const char* = nullptr);
388 
390  int order() const { return g; }
391 
393  int degeneracy() const { return degen; }
394 
396  int complex() const { return complex_; }
397 
399  int nproj() const { return degen * degen; }
400 
402  int nrot() const { return nrot_; }
403 
405  int ntrans() const { return ntrans_; }
406 
408  const char* symbol() const { return symb; }
409 
413  const char* symbol_ns() const { return (csymb ? csymb : symb); }
414 
417  double character(int i) const { return complex_ ? 0.5 * rep[i].trace() : rep[i].trace(); }
418 
420  double p(int x1, int x2, int i) const { return rep[i](x1, x2); }
421 
424  double p(int d, int i) const {
425  int dc = d / degen;
426  int dr = d % degen;
427  return rep[i](dr, dc);
428  }
429 
433  void print(std::string = "outfile") const;
434 };
435 
436 // ///////////////////////////////////////////////////////////
446  int nt;
448  int nirrep_;
451  int* _inv;
452  std::string symb;
453  unsigned char bits_;
454 
456  int make_table();
457  void common_init();
458 
459  public:
460  CharacterTable();
463  CharacterTable(const std::string&);
466  CharacterTable(unsigned char);
467 
469  ~CharacterTable();
470 
472 
474  int nirrep() const { return nirrep_; }
476  int order() const { return nirrep_; }
478  const std::string& symbol() const { return symb; }
480  IrreducibleRepresentation& gamma(int i) const { return gamma_[i]; }
482  SymmetryOperation& symm_operation(int i) const { return symop[i]; }
483 
487  int complex() const { return 0; }
488 
490  int inverse(int i) const { return _inv[i]; }
491 
492  int ncomp() const {
493  int ret = 0;
494  for (int i = 0; i < nirrep_; i++) {
495  int nc = (gamma_[i].complex()) ? 1 : gamma_[i].degen;
496  ret += nc;
497  }
498  return ret;
499  }
500 
502  int which_irrep(int i) {
503  for (int ir = 0, cn = 0; ir < nirrep_; ir++) {
504  int nc = (gamma_[ir].complex()) ? 1 : gamma_[ir].degen;
505  for (int c = 0; c < nc; c++, cn++)
506  if (cn == i) return ir;
507  }
508  return -1;
509  }
510 
512  int which_comp(int i) {
513  for (int ir = 0, cn = 0; ir < nirrep_; ir++) {
514  int nc = (gamma_[ir].complex()) ? 1 : gamma_[ir].degen;
515  for (int c = 0; c < nc; c++, cn++)
516  if (cn == i) return c;
517  }
518  return -1;
519  }
520 
521  unsigned char bits();
522 
524  void print(std::string = "outfile") const;
525 };
526 
527 // ///////////////////////////////////////////////////////////
528 
537  private:
538  std::string symb;
540  unsigned char bits_;
541 
542  public:
543  PointGroup();
544 
545  // These 2 constructors do not work right now.
548  PointGroup(const std::string&);
551  PointGroup(const std::string&, const Vector3&);
552 
554  PointGroup(unsigned char bits);
556  PointGroup(unsigned char bits, const Vector3&);
557 
592  // PointGroup(const Ref<KeyVal>&);
593 
594  // PointGroup(StateIn&);
595  PointGroup(const PointGroup&);
596  PointGroup(const std::shared_ptr<PointGroup>&);
597  ~PointGroup();
598 
599  PointGroup& operator=(const PointGroup&);
600 
602  int equiv(const std::shared_ptr<PointGroup>&, double tol = 1.0e-6) const;
603 
605  CharacterTable char_table() const;
607  int order() const { return char_table().order(); }
609  std::string symbol() const { return symb; }
612  Vector3& origin() { return origin_; }
613  const Vector3& origin() const { return origin_; }
614 
616  void set_symbol(const std::string&);
617 
619  unsigned char bits() const { return bits_; }
620 
621  static const char* bits_to_full_name(unsigned char bits);
622  static const char* bits_to_basic_name(unsigned char bits);
623  static bool full_name_to_bits(const std::string& pg, unsigned char& bits);
624 
625  void print(std::string out_fname = "outfile") const;
626 
628  std::string irrep_bits_to_string(int irrep_bits) const;
629 };
630 
631 } // namespace psi
632 
633 #endif
634 
635 // Local Variables:
636 // mode: c++
637 // c-file-style: "ETS"
638 // End:
unsigned short bits_
Definition: pointgrp.h:143
SymRep * rep
Definition: pointgrp.h:372
Definition: pointgrp.h:104
void print(std::string="outfile") const
This prints the irrep to the given file, or stdout if none is given.
Definition: chartab.cc:149
void c2_z()
Set equal to C2 about the z axis.
Definition: rep.cc:264
int g
Definition: pointgrp.h:364
Definition: pointgrp.h:119
double trace() const
returns the trace of the transformation matrix
Definition: pointgrp.h:155
int complex_
Definition: pointgrp.h:368
void unit()
Set equal to a unit matrix.
Definition: pointgrp.h:303
int order() const
Returns the order of this point group.
Definition: pointgrp.h:607
const std::string & symbol() const
Returns the Schoenflies symbol for the point group.
Definition: pointgrp.h:478
CharacterTable()
Definition: chartab.cc:91
SymmetryOperation & symm_operation(int i) const
Returns the i&#39;th symmetry operation.
Definition: pointgrp.h:482
int nirrep() const
Returns the number of irreps.
Definition: pointgrp.h:474
int complex() const
Definition: pointgrp.h:487
IrreducibleRepresentation()
Definition: irrep.cc:87
std::array< std::array< double, 3 >, 3 > d
Definition: pointgrp.h:142
int nproj() const
Returns the number of projection operators for the irrep.
Definition: pointgrp.h:399
void set_dim(int i)
set the dimension of d
Definition: pointgrp.h:280
void unit()
Set equal to a unit matrix.
Definition: pointgrp.h:186
int inverse(int i) const
Returns the index of the symop which is the inverse of symop[i].
Definition: pointgrp.h:490
Definition: pointgrp.h:263
double * operator[](int i)
returns the i&#39;th row of the transformation matrix
Definition: pointgrp.h:161
void E()
Set equal to the identity.
Definition: pointgrp.h:309
Definition: pointgrp.h:104
unsigned char bit() const
Get the bit value.
Definition: pointgrp.h:183
void E()
Set equal to E.
Definition: pointgrp.h:192
SymmetryOperation transform(const SymmetryOperation &r) const
This performs the transform r * this * r~.
Definition: symop.cc:126
int make_table()
this fills in the irrep and symop arrays.
Definition: maketab.cc:96
void c2_x()
Set equal to C2 about the x axis.
Definition: pointgrp.h:230
std::string symb
Definition: pointgrp.h:538
int degeneracy() const
Returns the degeneracy of the irrep.
Definition: pointgrp.h:393
void transpose()
Definition: symop.cc:174
void print(std::string="outfile") const
Definition: irrep.cc:142
Definition: pointgrp.h:113
Definition: pointgrp.h:116
int complex() const
Returns the value of complex_.
Definition: pointgrp.h:396
~CharacterTable()
Definition: chartab.cc:99
Definition: pointgrp.h:112
const double * operator[](int i) const
const version of the above
Definition: pointgrp.h:285
void zero()
zero out the symop
Definition: pointgrp.h:174
SymRep transform(const SymRep &r) const
This performs the transform r * this * r~.
Definition: rep.cc:115
Definition: vector3.h:38
Definition: pointgrp.h:104
double character(int i) const
Definition: pointgrp.h:417
SymmetryOperation * symop
the matrices describing sym ops
Definition: pointgrp.h:450
SymRep(int=0)
Definition: rep.cc:68
void sigma_h()
Set equal to reflection in xy plane.
Definition: rep.cc:149
double p(int x1, int x2, int i) const
Returns the element (x1,x2) of the i&#39;th representation matrix.
Definition: pointgrp.h:420
Groups
Definition: pointgrp.h:108
void analyze_d()
Definition: symop.cc:93
PointGroups::Groups pg
the class of the point group
Definition: pointgrp.h:447
int * _inv
index of the inverse symop
Definition: pointgrp.h:451
int ntrans() const
Returns the number of translations associated with the irrep.
Definition: pointgrp.h:405
void c2_y()
Set equal to C2 about the y axis.
Definition: pointgrp.h:237
Definition: pointgrp.h:104
CharacterTable & operator=(const CharacterTable &)
Definition: chartab.cc:109
double * operator[](int i)
returns the i&#39;th row of the transformation matrix
Definition: pointgrp.h:283
void rotation(int n)
Set equal to a clockwise rotation by 2pi/n.
Definition: rep.cc:181
void similar(unsigned char bits, unsigned char *sim, char &cnt)
Definition: pointgrp.cc:93
double d[5][5]
Definition: pointgrp.h:266
Vector3 origin_
Definition: pointgrp.h:539
int degen
Definition: pointgrp.h:365
Definition: pointgrp.h:104
Definition: pointgrp.h:110
void c2_x()
Set equal to C2 about the x axis.
Definition: rep.cc:242
double p(int d, int i) const
Definition: pointgrp.h:424
~SymRep()
Definition: rep.cc:76
double operator()(int i, int j) const
const version of the above
Definition: pointgrp.h:171
int order() const
Returns the order of the group.
Definition: pointgrp.h:390
unsigned char bits() const
Returns the bitwise representation of the point group.
Definition: pointgrp.h:619
void sigma_yz()
Set equal to reflection in yz plane.
Definition: rep.cc:170
void i()
Set equal to an inversion.
Definition: pointgrp.h:312
unsigned char bits_
Bitwise representation of the symmetry operations.
Definition: pointgrp.h:453
SymmetryOperation()
Definition: symop.cc:70
Definition: pointgrp.h:104
Operations
Definition: pointgrp.h:104
SymRep operate(const SymRep &r) const
This operates on this with r (i.e. return r * this).
Definition: rep.cc:94
Definition: pointgrp.h:123
const std::array< std::array< double, 3 >, 3 > & matrix()
Definition: pointgrp.h:158
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:43
IrreducibleRepresentation & operator=(const IrreducibleRepresentation &)
Definition: irrep.cc:102
Definition: pointgrp.h:114
Definition: pointgrp.h:120
int which_irrep(int i)
Returns the irrep component i belongs to.
Definition: pointgrp.h:502
Definition: pointgrp.h:124
Definition: pointgrp.h:117
const Vector3 & origin() const
Definition: pointgrp.h:613
SymmetryOperation & operator=(SymmetryOperation const &a)
Definition: symop.cc:82
void sigma_xz()
Set equal to reflection in xz plane.
Definition: pointgrp.h:212
IrreducibleRepresentation & gamma(int i) const
Returns the i&#39;th irrep.
Definition: pointgrp.h:480
void i()
Set equal to an inversion.
Definition: pointgrp.h:198
int order() const
Returns the order of the point group.
Definition: pointgrp.h:476
const double * operator[](int i) const
const version of the above
Definition: pointgrp.h:164
int ntrans_
Definition: pointgrp.h:367
int ncomp() const
Definition: pointgrp.h:492
int nrot_
Definition: pointgrp.h:366
const char * symbol_ns() const
Definition: pointgrp.h:413
int nirrep_
the number of irreps in this pg
Definition: pointgrp.h:448
void init(int=0, int=0, const char *=nullptr, const char *=nullptr)
Initialize the order, degeneracy, and Mulliken symbol of the irrep.
Definition: irrep.cc:114
~IrreducibleRepresentation()
Definition: irrep.cc:100
Definition: pointgrp.h:122
char * csymb
Definition: pointgrp.h:370
int nt
order of the princ rot axis
Definition: pointgrp.h:446
Definition: pointgrp.h:111
#define PSI_API
Definition: pragma.h:155
char * symb
Definition: pointgrp.h:369
void rotation(int n)
Set equal to a clockwise rotation by 2pi/n.
Definition: symop.cc:153
Definition: pointgrp.h:115
IrreducibleRepresentation * gamma_
an array of irreps
Definition: pointgrp.h:449
Definition: pointgrp.h:121
Definition: pointgrp.h:109
double trace() const
returns the trace of the transformation matrix
Definition: pointgrp.h:343
Definition: pointgrp.h:104
double operator()(int i, int j) const
const version of double&amp; operator()(int i, int j)
Definition: pointgrp.h:291
SymmetryOperation operate(const SymmetryOperation &r) const
This operates on this with r (i.e. return r * this).
Definition: symop.cc:114
int nrot() const
Returns the number of rotations associated with the irrep.
Definition: pointgrp.h:402
Definition: pointgrp.h:536
Definition: pointgrp.h:104
unsigned char bits()
Definition: chartab.cc:196
~SymmetryOperation()
Definition: symop.cc:80
const char * symbol() const
Returns the Mulliken symbol for the irrep.
Definition: pointgrp.h:408
void common_init()
Definition: chartab.cc:165
unsigned char bits_
Definition: pointgrp.h:540
Definition: pointgrp.h:118
void sigma_xz()
Set equal to reflection in xz plane.
Definition: rep.cc:159
Vector3 & origin()
Definition: pointgrp.h:612
void c2_y()
Set equal to C2 about the y axis.
Definition: rep.cc:253
void sigma_xy()
Set equal to reflection in xy plane.
Definition: pointgrp.h:205
Definition: pointgrp.h:445
int which_comp(int i)
Returns which component i is.
Definition: pointgrp.h:512
Definition: pointgrp.h:360
void c2_z()
Set equal to C2 about the z axis.
Definition: pointgrp.h:244
std::string symbol() const
Returns the Schoenflies symbol for this point group.
Definition: pointgrp.h:609
Definition: pointgrp.h:137
void zero()
zero out the symop
Definition: pointgrp.h:294
double & operator()(int i, int j)
Definition: pointgrp.h:289
std::string symb
the Schoenflies symbol for the pg
Definition: pointgrp.h:452
void print(std::string out)
print the matrix
Definition: symop.cc:185
double & operator()(int i, int j)
Definition: pointgrp.h:168
void sigma_yz()
Set equal to reflection in yz plane.
Definition: pointgrp.h:219
Definition: pointgrp.h:104
int n
Definition: pointgrp.h:265