1 /******************************************************************************
2 
3   This source file is part of the Avogadro project.
4 
5   Copyright 2008-2009 Marcus D. Hanwell
6   Copyright 2010-2013 Kitware, Inc.
7 
8   This source code is released under the New BSD License, (the "License").
9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 
16 ******************************************************************************/
17 
18 #ifndef AVOGADRO_CORE_BASISSET_H
19 #define AVOGADRO_CORE_BASISSET_H
20 
21 #include "avogadrocore.h"
22 
23 #include <string>
24 
25 namespace Avogadro {
26 namespace Core {
27 
28 class Molecule;
29 
30 /**
31  * @class BasisSet basisset.h <avogadro/core/basisset.h>
32  * @brief BasisSet contains basis set data.
33  * @author Marcus D. Hanwell
34  *
35  * This is the base class for basis sets, and has two derived classes -
36  * GaussianSet and SlaterSet. It must be populated with data, with other classes
37  * capable of performing calculations on the data or writing it out.
38  */
39 
40 class AVOGADROCORE_EXPORT BasisSet
41 {
42 public:
43   /**
44    * Constructor.
45    */
BasisSet()46   BasisSet() {}
47 
48   /**
49    * Destructor.
50    */
~BasisSet()51   virtual ~BasisSet() {}
52 
53   /**
54    * Clone.
55    */
56   virtual BasisSet* clone() const = 0;
57 
58   /**
59    * @brief The ElectronType enum describes the type of electrons being set or
60    * retrieved. If Paired, then Alpha and Beta cannot be set, if Alpha or Beta
61    * then both must be set.
62    */
63   enum ElectronType
64   {
65     Paired,
66     Alpha,
67     Beta
68   };
69 
70   /**
71    * Set the number of electrons in the BasisSet.
72    * @param n The number of electrons in the BasisSet.
73    * @param type The type of the electrons (Alpha, Beta, or Paired).
74    */
75   virtual void setElectronCount(unsigned int n, ElectronType type = Paired);
76 
77   /**
78    * @param type The type of the electrons (Alpha, Beta, or Paired).
79    * @return The number of electrons in the molecule.
80    */
81   unsigned int electronCount(ElectronType type = Paired) const;
82 
83   /**
84    * Set the molecule for the basis set.
85    */
setMolecule(Molecule * molecule_)86   void setMolecule(Molecule* molecule_) { m_molecule = molecule_; }
87 
88   /**
89    * Get the molecule this basis set belongs to.
90    */
molecule()91   Molecule* molecule() { return m_molecule; }
molecule()92   const Molecule* molecule() const { return m_molecule; }
93 
94   /**
95    * Set the name of the basis set.
96    */
setName(const std::string & name)97   void setName(const std::string& name) { m_name = name; }
98 
99   /**
100    * Get the name of the basis set.
101    */
name()102   std::string name() const { return m_name; }
103 
104   /**
105    * Set the name of the basis set.
106    */
setTheoryName(const std::string & name)107   void setTheoryName(const std::string& name) { m_theoryName = name; }
108 
109   /**
110    * Get the name of the basis set.
111    */
theoryName()112   std::string theoryName() const { return m_theoryName; }
113 
114   /**
115    * @return The number of molecular orbitals in the BasisSet.
116    */
117   virtual unsigned int molecularOrbitalCount(ElectronType type = Paired) = 0;
118 
119   /**
120    * Check if the given MO number is the HOMO or not.
121    * @param n The MO number.
122    * @return True if the given MO number is the HOMO.
123    */
homo(unsigned int n)124   bool homo(unsigned int n) { return n == homo(); }
125 
126   /**
127    * @return The molecular orbital number corresponding to the HOMO orbital.
128    */
homo()129   unsigned int homo() const { return m_electrons[0] / 2; }
130 
131   /**
132    * Check if the given MO number is the LUMO or not.
133    * @param n The MO number.
134    * @return True if the given MO number is the LUMO.
135    */
lumo(unsigned int n)136   bool lumo(unsigned int n) { return n == lumo(); }
137   /**
138    * @return The molecular orbital number corresponding to the LUMO orbital.
139    */
lumo()140   unsigned int lumo() const { return m_electrons[0] / 2 + 1; }
141 
142   /**
143    * @return True of the basis set is valid, false otherwise.
144    * Default is true, if false then the basis set is likely unusable.
145    */
146   virtual bool isValid() = 0;
147 
148 protected:
149   /**
150    * Total number of electrons, 0 is alpha electrons and 1 is beta electrons.
151    * For closed shell calculations alpha is doubly occupied and there are no
152    * beta electrons.
153    */
154   unsigned int m_electrons[2];
155 
156   /**
157    * The Molecule holds the atoms (and possibly bonds) read in from the output
158    * file. Most basis sets have orbitals around these atoms, but this is not
159    * necessarily the case.
160    */
161   Molecule* m_molecule;
162 
163   /**
164    * The name of the basis set, this is usually a string identifier referencing
165    * a standard basis set when only one is used.
166    */
167   std::string m_name;
168 
169   /**
170    * The name of the theory used for the calculation.
171    */
172   std::string m_theoryName;
173 };
174 
setElectronCount(unsigned int n,ElectronType type)175 inline void BasisSet::setElectronCount(unsigned int n, ElectronType type)
176 {
177   switch (type) {
178     case Paired:
179       m_electrons[0] = n;
180       m_electrons[1] = 0;
181       break;
182     case Alpha:
183       m_electrons[0] = n;
184       break;
185     case Beta:
186       m_electrons[1] = n;
187       break;
188     default:
189       // Shouldn't hit this condition.
190       ;
191   }
192 }
193 
electronCount(ElectronType type)194 inline unsigned int BasisSet::electronCount(ElectronType type) const
195 {
196   switch (type) {
197     case Paired:
198     case Alpha:
199       return m_electrons[0];
200     case Beta:
201       return m_electrons[1];
202     default:
203       // Shouldn't hit this condition.
204       return 0;
205   }
206 }
207 
208 } // End namesapce Core
209 } // End namespace Avogadro
210 
211 #endif
212