OpenCAP
Electronic structure of metastable states
utils.h
Go to the documentation of this file.
1 /*Copyright (c) 2021 James Gayvert
2 
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
9 
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE.
20 */
21 
25 #ifndef UTILS_H_
26 #define UTILS_H_
27 
28 #include <Eigen/Dense>
29 #include <map>
30 
31 
32 //useful constants
33 #ifndef M_PIl
34 #define M_PIl 3.141592653589793238462643383279502884
35 #endif
36 #define euler 2.718281828459045235360287471352662497
37 
40 double fact2(int n);
44 double fact(int n);
48 int parity(int i);
53 double binom(int p, int q);
59 std::vector<std::string> split(const std::string& s, char delimiter);
65 /*
66 void fill_LT(std::vector<double> matrix_elements, Eigen::MatrixXd &opdm);
71 /*
72 void fill_mat(std::vector<double> &matrix_elements, Eigen::MatrixXd &opdm);
77 template <typename T>
78 void fill_mat(std::vector<T> &matrix_elements, Eigen::MatrixXd &opdm)
79 {
80  size_t vec_idx = 0;
81  for (size_t row_idx=0;row_idx<opdm.rows();row_idx++)
82  {
83  for (size_t col_idx=0;col_idx<opdm.cols();col_idx++)
84  {
85  opdm(row_idx,col_idx) = matrix_elements[vec_idx];
86  vec_idx++;
87  }
88  }
89 }
90 
91 template <typename T>
92 void fill_LT(std::vector<T> matrix_elements, Eigen::MatrixXd &opdm)
93 {
94  size_t vec_idx = 0;
95  size_t row_idx = 0;
96  while(row_idx<opdm.rows() && vec_idx<matrix_elements.size())
97  {
98  //elements are added to each column <= row index
99  for (size_t col_idx=0;col_idx<=row_idx;col_idx++)
100  {
101  opdm(row_idx,col_idx) = matrix_elements[vec_idx];
102  opdm(col_idx,row_idx) = matrix_elements[vec_idx];
103  vec_idx++;
104  }
105  row_idx++;
106  }
107 }
108 
109 void fortran_dfloats_to_efloats(std::string &str);
112 int shell2angmom(std::string angmom);
115 bool compare_strings(std::string s1, std::string s2);
118 bool is_number(const std::string &s);
121 bool is_letter(const std::string &s);
124 Eigen::MatrixXd read_matrix(size_t N, std::string filename);
125 
126 #endif /* UTILS_H_ */
double fact(int n)
int parity(int i)
std::vector< std::string > split(const std::string &s, char delimiter)
double binom(int p, int q)
double fact2(int n)