/usr/include/libint2/basis.h is in libint2-dev 2.1.0~beta2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* This file is a part of Libint.
* Copyright (C) 2004-2014 Edward F. Valeev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License, version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/
#ifndef _libint2_src_lib_libint_basis_h_
#define _libint2_src_lib_libint_basis_h_
#if __cplusplus <= 199711L
# error "The simple Libint API requires C++11 support"
#endif
#include <iostream>
#include <fstream>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libint2.h>
#include <libint2/shell.h>
#include <libint2/atom.h>
namespace libint2 {
/// BasisSet is a slightly decorated \c std::vector of \c libint2::Shell objects.
class BasisSet : public std::vector<libint2::Shell> {
public:
BasisSet() : name_(""), nbf_(-1), max_nprim_(0), max_l_(-1) {}
BasisSet(const BasisSet&) = default;
BasisSet(BasisSet&&) = default;
~BasisSet() = default;
/// Construct from basis set name and vector of atoms
/**
* @param name basis set name
* @param atoms \c std::vector of Atom objects
* \note All atoms receive the same basis set
* \note \c name will be "canonicalized" using BasisSet::canonicalize(name) to
* produce the file name where the basis will be sought. This file needs to contain
* the basis set definition in Gaussian94 format (see \c lib/basis directory for examples).
* The file will be searched in the following directories (in decreasing order of preference)
* <ol>
* <li> specified by LIBINT_DATA_PATH environmental variable, if defined </li>
* <li> specified by DATADIR macro variable, if defined </li>
* <li> specified by SRCDATADIR macro variable, if defined </li>
* <li> hardwired to directory \c /usr/share/libint/2.1.0/basis </li>
* </ol>
*/
BasisSet(std::string name,
const std::vector<Atom>& atoms) : name_(std::move(name)) {
// read in the library file contents
std::string file_dot_g94 = data_path();
file_dot_g94 += "/" + canonicalize_name(name_) + ".g94";
std::vector<std::vector<libint2::Shell>> ref_shells = read_g94_basis_library(file_dot_g94);
// for each atom find the corresponding basis
for(auto a=0; a<atoms.size(); ++a) {
auto Z = atoms[a].atomic_number;
if (ref_shells[Z].empty())
throw std::string("did not find the basis for this Z in ") + file_dot_g94;
for(auto s: ref_shells[Z]) {
this->push_back(std::move(s));
this->back().move({{atoms[a].x, atoms[a].y, atoms[a].z}});
}
}
// technical step: rescale contraction coefficients to include primitive normalization coefficients
for(auto& s: *this) {
s.renorm();
}
init();
}
/// @return the number of basis functions in the basis; -1 if uninitialized
long nbf() const {
return nbf_;
}
/// @return the maximum number of primitives in a contracted Shell, i.e. maximum contraction length; 0 if uninitialized
size_t max_nprim() const {
return max_nprim_;
}
/// @return the maximum angular momentum of a contraction; -1 if uninitialized
size_t max_l() const {
return max_l_;
}
/// @return the map from shell index to index of the first basis function from this shell
/// \note basis functions are ordered as shells, i.e. shell2bf[i] >= shell2bf[j] iff i >= j
const std::vector<size_t>& shell2bf() const {
return shell2bf_;
}
private:
std::string name_;
long nbf_;
size_t max_nprim_;
int max_l_;
std::vector<size_t> shell2bf_;
void init() {
nbf_ = nbf(*this);
max_nprim_ = max_nprim(*this);
max_l_ = max_l(*this);
shell2bf_ = compute_shell2bf(*this);
}
struct canonicalizer {
char operator()(char c) {
char cc = ::tolower(c);
switch (cc) {
case '/': cc = 'I'; break;
}
return cc;
}
};
static std::string canonicalize_name(const std::string& name) {
auto result = name;
std::transform(name.begin(), name.end(),
result.begin(), BasisSet::canonicalizer());
return result;
}
/** determines the path to the data directory, as follows:
* <ol>
* <li> specified by LIBINT_DATA_PATH environmental variable, if defined </li>
* <li> specified by DATADIR macro variable, if defined </li>
* <li> specified by SRCDATADIR macro variable, if defined </li>
* <li> hardwired to directory \c /usr/share/libint/2.1.0/basis </li>
* </ol>
* @throw std::runtime_error if the path is not valid, or cannot be determined
* @return valid path to the data directory
*/
static std::string data_path() {
std::string path;
const char* data_path_env = getenv("LIBINT_DATA_PATH");
if (data_path_env) {
path = data_path_env;
}
else {
#if defined(DATADIR)
path = std::string{DATADIR};
#elif defined(SRCDATADIR)
path = std::string{SRCDATADIR};
#else
path = std::string("/usr/share/libint/2.1.0") + std::string("/basis");
#endif
}
// validate path
bool error = true;
if (not path.empty()) {
struct stat sb;
error = (::stat(path.c_str(), &sb) == -1);
error = error && not S_ISDIR(sb.st_mode);
}
if (error) {
std::ostringstream oss; oss << "BasisSet::data_path(): path \"" << path << "\" is not valid";
throw std::runtime_error(oss.str());
}
return path;
}
public:
/** reads in all basis sets from a Gaussian94-formatted basis set file (see https://bse.pnl.gov/bse/portal)
* @param[in] file_dot_g94 file name
* @throw std::runtime_error if the path is not valid, or cannot be determined
* @return vector of basis sets for each element
*/
static std::vector<std::vector<libint2::Shell>> read_g94_basis_library(std::string file_dot_g94) {
std::cout << "Will read basis set from " << file_dot_g94 << std::endl;
std::ifstream is(file_dot_g94);
if (not is.good()) {
std::ostringstream oss;
oss << "BasisSet::read_g94_basis_library(): could not open \"" << file_dot_g94 << "\"" << std::endl;
throw std::runtime_error(oss.str());
}
std::vector<std::vector<libint2::Shell>> ref_shells(118); // 118 = number of chemical elements
std::string comment, rest;
// skip till first basis
while(std::getline(is, comment) && comment != "****") {
}
size_t Z;
auto nextbasis = true, nextshell = false;
while(std::getline(is, comment) && comment != "") {
if (comment == "****") {
nextbasis = true;
nextshell = false;
continue;
}
if (nextbasis) {
nextbasis = false;
std::istringstream iss(comment);
std::string elemsymbol;
iss >> elemsymbol >> rest;
bool found = false;
using libint2::chemistry::element_info;
for(const auto& e: element_info) {
if (strcaseequal(e.symbol, elemsymbol)) {
Z = e.Z;
found = true;
break;
}
}
if (not found) {
std::ostringstream oss;
oss << "in file " << file_dot_g94
<< " found G94 basis set for element symbol \""
<< elemsymbol << "\", not found in Periodic Table.";
throw std::runtime_error(oss.str());
}
nextshell = true;
continue;
}
if (nextshell) {
std::istringstream iss(comment);
std::string amlabel;
unsigned nprim;
iss >> amlabel >> nprim >> rest;
if (amlabel != "SP" && amlabel != "sp") {
assert(amlabel.size() == 1);
auto l = Shell::am_symbol_to_l(amlabel[0]);
std::vector<double> exps;
std::vector<double> coeffs;
for(auto p = 0; p!=nprim; ++p) {
std::getline(is, comment);
std::istringstream iss(comment);
double e, c;
iss >> e >> c;
exps.emplace_back(e);
coeffs.emplace_back(c);
}
auto pure = l>1;
ref_shells[Z].push_back(
libint2::Shell{
exps,
{
{l, pure, coeffs}
},
{{0.0, 0.0, 0.0}}
}
);
}
else { // split the SP shells
std::vector<double> exps;
std::vector<double> coeffs_s, coeffs_p;
for(auto p = 0; p!=nprim; ++p) {
std::getline(is, comment);
std::istringstream iss(comment);
double e, c1, c2;
iss >> e >> c1 >> c2;
exps.emplace_back(e);
coeffs_s.emplace_back(c1);
coeffs_p.emplace_back(c2);
}
ref_shells[Z].push_back(
libint2::Shell{exps,
{
{0, false, coeffs_s}
},
{{0.0, 0.0, 0.0}}
}
);
ref_shells[Z].push_back(
libint2::Shell{ exps,
{
{1, false, coeffs_p}
},
{{0.0, 0.0, 0.0}}
}
);
}
}
}
return ref_shells;
}
static size_t nbf(const std::vector<libint2::Shell>& shells) {
size_t n = 0;
for (const auto& shell: shells)
n += shell.size();
return n;
}
static size_t max_nprim(const std::vector<libint2::Shell>& shells) {
size_t n = 0;
for (auto shell: shells)
n = std::max(shell.nprim(), n);
return n;
}
static int max_l(const std::vector<libint2::Shell>& shells) {
int l = 0;
for (auto shell: shells)
for (auto c: shell.contr)
l = std::max(c.l, l);
return l;
}
static std::vector<size_t> compute_shell2bf(const std::vector<libint2::Shell>& shells) {
std::vector<size_t> result;
result.reserve(shells.size());
size_t n = 0;
for (auto shell: shells) {
result.push_back(n);
n += shell.size();
}
return result;
}
}; // BasisSet
} // namespace libint2
#endif /* _libint2_src_lib_libint_basis_h_ */
|