LIBINT  2.1.0-stable
atom.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Library General Public License, version 2,
7  * as published by the Free Software Foundation.
8  *
9  * This program 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 more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program. If not, see http://www.gnu.org/licenses/.
16  *
17  */
18 
19 #ifndef _libint2_src_lib_libint_atom_h_
20 #define _libint2_src_lib_libint_atom_h_
21 
22 #include <libint2/cxxstd.h>
23 #if LIBINT2_CPLUSPLUS_STD < 2011
24 # error "libint2/atom.h requires C++11 support"
25 #endif
26 
27 #include <iostream>
28 #include <sstream>
29 #include <vector>
30 
31 #include <libint2.h>
32 
33 namespace libint2 {
34 
35  struct Atom {
36  int atomic_number;
37  double x, y, z;
38  };
39 
40  namespace {
41  bool strcaseequal(const std::string& a, const std::string& b) {
42  return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin(),
43  [](char a, char b) {return ::tolower(a) == ::tolower(b);}
44  );
45  }
46  }
47 
49  inline std::vector<Atom> read_dotxyz(std::istream& is) {
50  // first line = # of atoms
51  size_t natom;
52  is >> natom;
53  // read off the rest of first line and discard
54  std::string rest_of_line;
55  std::getline(is, rest_of_line);
56 
57  // second line = comment
58  std::string comment;
59  std::getline(is, comment);
60 
61  // rest of lines are atoms
62  std::vector<Atom> atoms(natom);
63  for (auto i = 0; i < natom; i++) {
64  // read line
65  std::string line;
66  std::getline(is, line);
67  std::istringstream iss(line);
68  // then parse ... this handles "extended" XYZ formats
69  std::string element_symbol;
70  double x, y, z;
71  iss >> element_symbol >> x >> y >> z;
72 
73  // .xyz files report element labels, hence convert to atomic numbers
74  int Z = -1;
75  using libint2::chemistry::element_info;
76  for(const auto& e: element_info) {
77  if (strcaseequal(e.symbol, element_symbol)) {
78  Z = e.Z;
79  break;
80  }
81  }
82  if (Z == -1) {
83  std::cerr << "read_dotxyz: element symbol \"" << element_symbol << "\" is not recognized" << std::endl;
84  throw "Did not recognize element symbol in .xyz file";
85  }
86 
87  atoms[i].atomic_number = Z;
88 
89  // .xyz files report Cartesian coordinates in angstroms; convert to bohr
90  const auto angstrom_to_bohr = 1 / 0.52917721092; // 2010 CODATA value
91  //const auto angstrom_to_bohr = 1 / 0.529177249; // 1986 CODATA value, used by MPQC
92  atoms[i].x = x * angstrom_to_bohr;
93  atoms[i].y = y * angstrom_to_bohr;
94  atoms[i].z = z * angstrom_to_bohr;
95  }
96 
97  return atoms;
98  }
99 
100 } // namespace libint2
101 
102 #endif /* _libint2_src_lib_libint_atom_h_ */
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
Definition: atom.h:35
std::vector< Atom > read_dotxyz(std::istream &is)
reads the list of atoms from a file in the standard XYZ format supported by most chemistry software ...
Definition: atom.h:49