1 /* Copyright (c) 2015  Gerald Knizia
2  *
3  * This file is part of the IboView program (see: http://www.iboview.org)
4  *
5  * IboView is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * IboView is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/
16  *
17  * Please see IboView documentation in README.txt for:
18  * -- A list of included external software and their licenses. The included
19  *    external software's copyright is not touched by this agreement.
20  * -- Notes on re-distribution and contributions to/further development of
21  *    the IboView software
22  */
23 
24 #ifndef IV_ORBITAL_FILE_H
25 #define IV_ORBITAL_FILE_H
26 
27 // Code for loading export formats of quantum chemistry programs:
28 //
29 // - Molpro xml (preferred format)
30 // - Molden (worst format)
31 
32 
33 #include <map>
34 #include <string>
35 #include <stdexcept>
36 #include "CxPodArray.h"
37 #include "CtBasisSet.h"
38 #include "CtAtomSet.h"
39 
40 namespace orbital_file {
41 
42 class FFileLoadError : public std::runtime_error
43 {
44 public:
45    typedef std::runtime_error
46       FBase;
47    FFileLoadError(std::string const &What, std::string const &Where = "");
48 };
49 
50 class FFileTypeUnrecognizedError : public FFileLoadError
51 {
52 public:
53    FFileTypeUnrecognizedError(std::string const &What, std::string const &Where = "");
54 };
55 
56 enum FLoadFlags {
57    LOADFILE_SkipVirtualOrbs = 0x0001
58 };
59 
60 struct FLoadOptions {
FLoadOptionsFLoadOptions61    FLoadOptions(unsigned Flags) : m_Flags(Flags) {};
62 
SkipVirtualsFLoadOptions63    bool SkipVirtuals() const { return bool(m_Flags & LOADFILE_SkipVirtualOrbs); }
64 protected:
65    unsigned m_Flags;
66 };
67 
68 // keeps a list of the stuff stored under `[Molpro variables]`
69 struct FVariableSet
70 {
71    typedef std::map<std::string, std::string>
72       FVariableMap;
73    FVariableMap
74       // keeps assignments of all variables -- in string format.
75       Map;
76    // return if a variable is assigned.
77    bool Has(std::string const &Name);
78    // try to convert the content of a variable to a float and to
79    // return it. raises var_not_found_error if not possible.
80    double GetFloat(std::string const &Name);
81 };
82 
83 
84 
85 typedef boost::intrusive_ptr<ct::FAtomSet>
86    FAtomSetPtr;
87 typedef ct::TArray<double>
88    FScalarData;
89 using ct::FBasisSetPtr;
90 
91 enum FOrbitalSpin {
92    ORBSPIN_SpinFree,
93    ORBSPIN_Alpha,
94    ORBSPIN_Beta,
95    ORBSPIN_Unknown
96 };
97 
98 
99 struct FOrbitalInfo : public ct::FIntrusivePtrDest
100 {
101    double
102       fEnergy;
103    double
104       fOcc;
105    int
106       iSym;
107    FScalarData
108       Orb;
109    FBasisSetPtr
110       pBasisSet;
111    std::string
112       sDesc;
113    FOrbitalSpin
114       Spin;
DescFOrbitalInfo115    std::string Desc() const { return sDesc; };
116    FOrbitalInfo();
117 };
118 
119 typedef boost::intrusive_ptr<FOrbitalInfo>
120    FOrbitalInfoPtr;
121 
122 struct FOrbitalSet : public ct::FIntrusivePtrDest
123 {
124    typedef std::vector<FOrbitalInfoPtr>
125       FOrbitalInfoList;
126    // ^- FIXME: make this a FOrbitalInfoPtr.
127    // note also: in principle there could be more than one orbital set in a file
128    // (e.g., for multiple states in MCSCF)
129    FOrbitalInfoList
130       OrbInfos;
131 };
132 
133 typedef boost::intrusive_ptr<FOrbitalSet>
134    FOrbitalSetPtr;
135 
136 
137 struct FMolproXmlData : public ct::FIntrusivePtrDest
138 {
139    FOrbitalSetPtr
140       pOrbSet;
141    FAtomSetPtr
142       pAtoms;
143    FBasisSetPtr
144       pBasisOrb;
145 };
146 
147 typedef boost::intrusive_ptr<FMolproXmlData>
148    FMolproXmlDataPtr;
149 // FMolproXmlDataPtr LoadMolproXmlFile(std::string const &FileName);
150 FMolproXmlDataPtr LoadOrbitalFile(std::string const &FileName, FLoadOptions const &LoadOptions);
151 
152 
153 } // namespace orbital_file
154 
155 
156 
157 #endif // IV_ORBITAL_FILE_H
158