21#ifndef _libint2_src_lib_libint_atom_h_
22#define _libint2_src_lib_libint_atom_h_
24#include <libint2/util/cxxstd.h>
25#if LIBINT2_CPLUSPLUS_STD < 2011
26# error "libint2/atom.h requires C++11 support"
36#include <libint2/chemistry/elements.h>
44 inline bool operator==(
const Atom& atom1,
const Atom& atom2) {
45 return atom1.atomic_number == atom2.atomic_number && atom1.x == atom2.x &&
46 atom1.y == atom2.y && atom1.z == atom2.z;
52 static constexpr double bohr_to_angstrom = 0.529177210903;
53 static constexpr double angstrom_to_bohr = 1 / bohr_to_angstrom;
57 static constexpr double bohr_to_angstrom = 0.52917721067;
58 static constexpr double angstrom_to_bohr = 1 / bohr_to_angstrom;
62 static constexpr double bohr_to_angstrom = 0.52917721092;
63 static constexpr double angstrom_to_bohr = 1 / bohr_to_angstrom;
71bool strcaseequal(
const std::string &a,
const std::string &b) {
72 return a.size() == b.size() &&
73 std::equal(a.begin(), a.end(), b.begin(), [](
char a,
char b) {
74 return ::tolower(a) == ::tolower(b);
81inline std::tuple<std::vector<libint2::Atom>,
83__libint2_read_dotxyz(std::istream &is,
const double bohr_to_angstrom,
84 const bool pbc =
false) {
86 const std::string caller = std::string(
"libint2::read_dotxyz") + (pbc ?
"_pbc" :
"");
93 std::string rest_of_line;
94 std::getline(is, rest_of_line);
98 std::getline(is, comment);
101 const auto nlines_expected = natom + (pbc ? 3 : 0);
102 std::vector<Atom> atoms(natom, Atom{0, 0.0, 0.0, 0.0});
104 bool found_abc[3] = {
false,
false,
false};
105 for (
size_t line = 0, atom_index = 0; line < nlines_expected; ++line) {
107 throw std::logic_error(caller +
": expected " +
108 std::to_string(nlines_expected) +
109 " sets of coordinates but only " +
110 std::to_string(line) +
" received");
114 std::getline(is, linestr);
115 std::istringstream iss(linestr);
117 std::string element_symbol;
119 iss >> element_symbol >> x >> y >> z;
122 const auto angstrom_to_bohr = 1 / bohr_to_angstrom;
124 auto assign_atom = [angstrom_to_bohr](Atom &atom,
int Z,
double x,
double y,
126 atom.atomic_number = Z;
127 atom.x = x * angstrom_to_bohr;
128 atom.y = y * angstrom_to_bohr;
129 atom.z = z * angstrom_to_bohr;
132 double y,
double z) {
133 xyz[0] = x * angstrom_to_bohr;
134 xyz[1] = y * angstrom_to_bohr;
135 xyz[2] = z * angstrom_to_bohr;
141 if (strcaseequal(
"AA", element_symbol))
143 if (strcaseequal(
"BB", element_symbol))
145 if (strcaseequal(
"CC", element_symbol))
149 throw std::logic_error(
150 caller +
": unit cell parameter along Cartesian axis " +
151 std::to_string(axis) +
" appears more than once");
152 assign_xyz(unit_cell[axis], x, y, z);
153 found_abc[axis] =
true;
160 for (
const auto &e : libint2::chemistry::get_element_info()) {
161 if (strcaseequal(e.symbol, element_symbol)) {
167 std::ostringstream oss;
168 oss << caller <<
": element symbol \"" << element_symbol
169 <<
"\" is not recognized" << std::endl;
170 throw std::logic_error(oss.str().c_str());
173 if (pbc && atom_index == atoms.size()) {
174 throw std::logic_error(caller +
": too many atoms");
176 assign_atom(atoms[atom_index++], Z, x, y, z);
182 for(
auto xyz=0; xyz!=3; ++xyz)
183 if (!found_abc[xyz]) {
184 throw std::logic_error(caller +
185 ": unit cell parameter along Cartesian axis " +
186 std::to_string(xyz) +
" not given");
190 return std::make_tuple(atoms, unit_cell);
212 const double bohr_to_angstrom = constants::codata_2018::bohr_to_angstrom) {
213 std::vector<Atom> atoms;
214 std::tie(atoms, std::ignore) =
215 __libint2_read_dotxyz(is, bohr_to_angstrom,
false);
236 const double bohr_to_angstrom = constants::codata_2018::bohr_to_angstrom)
237 ->
decltype(__libint2_read_dotxyz(is, bohr_to_angstrom,
true)) {
238 return __libint2_read_dotxyz(is, bohr_to_angstrom,
true);
243 const std::vector<libint2::Atom> &atoms) {
244 std::vector<std::pair<double, std::array<double, 3>>> q;
245 q.reserve(atoms.size());
246 for (
const auto &atom : atoms) {
247 q.emplace_back(
static_cast<double>(atom.atomic_number),
Array idential to C++0X arrays.
Definition: stdarray_bits.h:14
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
auto read_dotxyz_pbc(std::istream &is, const double bohr_to_angstrom=constants::codata_2018::bohr_to_angstrom) -> decltype(__libint2_read_dotxyz(is, bohr_to_angstrom, true))
reads the list of atoms from a file in the PBC-extended XYZ format
Definition: atom.h:234
std::vector< std::pair< double, std::array< double, 3 > > > make_point_charges(const std::vector< libint2::Atom > &atoms)
converts a vector of Atoms to a vector of point charges
Definition: atom.h:242
std::vector< Atom > read_dotxyz(std::istream &is, const double bohr_to_angstrom=constants::codata_2018::bohr_to_angstrom)
reads the list of atoms from a file in the standard XYZ format supported by most chemistry software (...
Definition: atom.h:210
the 2010 CODATA reference set, available at DOI 10.1103/RevModPhys.84.1527
Definition: atom.h:61
the 2014 CODATA reference set, available at DOI 10.1103/RevModPhys.88.035009
Definition: atom.h:56
the 2018 CODATA reference set, available at https://physics.nist.gov/cuu/pdf/wall_2018....
Definition: atom.h:51