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"
29#include <libint2/chemistry/elements.h>
44inline 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;
53 static constexpr double bohr_to_angstrom = 0.529177210903;
54 static constexpr double angstrom_to_bohr = 1 / bohr_to_angstrom;
58 static constexpr double bohr_to_angstrom = 0.52917721067;
59 static constexpr double angstrom_to_bohr = 1 / bohr_to_angstrom;
63 static constexpr double bohr_to_angstrom = 0.52917721092;
64 static constexpr double angstrom_to_bohr = 1 / bohr_to_angstrom;
72bool strcaseequal(
const std::string &a,
const std::string &b) {
73 return a.size() == b.size() &&
74 std::equal(a.begin(), a.end(), b.begin(), [](
char a,
char b) {
75 return ::tolower(a) == ::tolower(b);
81inline std::tuple<std::vector<libint2::Atom>,
82 std::array<std::array<double, 3>, 3>>
83__libint2_read_dotxyz(std::istream &is,
const double bohr_to_angstrom,
84 const bool pbc =
false) {
86 const std::string caller =
87 std::string(
"libint2::read_dotxyz") + (pbc ?
"_pbc" :
"");
94 std::string rest_of_line;
95 std::getline(is, rest_of_line);
99 std::getline(is, comment);
102 const auto nlines_expected = natom + (pbc ? 3 : 0);
103 std::vector<Atom> atoms(natom, Atom{0, 0.0, 0.0, 0.0});
104 std::array<std::array<double, 3>, 3> unit_cell({{{0.0, 0.0, 0.0}}});
105 bool found_abc[3] = {
false,
false,
false};
106 for (
size_t line = 0, atom_index = 0; line < nlines_expected; ++line) {
108 throw std::logic_error(caller +
": expected " +
109 std::to_string(nlines_expected) +
110 " sets of coordinates but only " +
111 std::to_string(line) +
" received");
115 std::getline(is, linestr);
116 std::istringstream iss(linestr);
118 std::string element_symbol;
120 iss >> element_symbol >> x >> y >> z;
123 const auto angstrom_to_bohr = 1 / bohr_to_angstrom;
125 auto assign_atom = [angstrom_to_bohr](Atom &atom,
int Z,
double x,
double y,
127 atom.atomic_number = Z;
128 atom.x = x * angstrom_to_bohr;
129 atom.y = y * angstrom_to_bohr;
130 atom.z = z * angstrom_to_bohr;
132 auto assign_xyz = [angstrom_to_bohr](std::array<double, 3> &xyz,
double x,
133 double y,
double z) {
134 xyz[0] = x * angstrom_to_bohr;
135 xyz[1] = y * angstrom_to_bohr;
136 xyz[2] = z * angstrom_to_bohr;
142 if (strcaseequal(
"AA", element_symbol)) axis = 0;
143 if (strcaseequal(
"BB", element_symbol)) axis = 1;
144 if (strcaseequal(
"CC", element_symbol)) axis = 2;
147 throw std::logic_error(
148 caller +
": unit cell parameter along Cartesian axis " +
149 std::to_string(axis) +
" appears more than once");
150 assign_xyz(unit_cell[axis], x, y, z);
151 found_abc[axis] =
true;
158 for (
const auto &e :
libint2::chemistry::get_element_info()) {
159 if (strcaseequal(e.symbol, element_symbol)) {
165 std::ostringstream oss;
166 oss << caller <<
": element symbol \"" << element_symbol
167 <<
"\" is not recognized" << std::endl;
168 throw std::logic_error(oss.str().c_str());
172 atom_index == atoms.size()) {
173 throw std::logic_error(caller +
": too many atoms");
175 assign_atom(atoms[atom_index++], Z, x, y, z);
181 for (
auto xyz = 0; xyz != 3; ++xyz)
182 if (!found_abc[xyz]) {
183 throw std::logic_error(caller +
184 ": unit cell parameter along Cartesian axis " +
185 std::to_string(xyz) +
" not given");
189 return std::make_tuple(atoms, unit_cell);
211 const double bohr_to_angstrom = constants::codata_2018::bohr_to_angstrom) {
212 std::vector<Atom> atoms;
213 std::tie(atoms, std::ignore) =
214 __libint2_read_dotxyz(is, bohr_to_angstrom,
false);
235 const double bohr_to_angstrom = constants::codata_2018::bohr_to_angstrom)
236 ->
decltype(__libint2_read_dotxyz(is, bohr_to_angstrom,
true)) {
237 return __libint2_read_dotxyz(is, bohr_to_angstrom,
true);
242 const std::vector<libint2::Atom> &atoms) {
243 std::vector<std::pair<double, std::array<double, 3>>> q;
244 q.reserve(atoms.size());
245 for (
const auto &atom : atoms) {
246 q.emplace_back(
static_cast<double>(atom.atomic_number),
247 std::array<double, 3>{{atom.x, atom.y, atom.z}});
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:233
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:241
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:209
the 2010 CODATA reference set, available at DOI 10.1103/RevModPhys.84.1527
Definition atom.h:62
the 2014 CODATA reference set, available at DOI 10.1103/RevModPhys.88.035009
Definition atom.h:57
the 2018 CODATA reference set, available at https://physics.nist.gov/cuu/pdf/wall_2018....
Definition atom.h:52