47 Index numberofmultipoles = 0;
48 Vector9d multipoles = Vector9d::Zero();
51 if (!intt.is_open()) {
52 throw std::runtime_error(
"File:" + filename +
" could not be opened");
58 std::vector<std::string> split = toker.ToVector();
60 if (!split.size() || split[0] ==
"!" || split[0].substr(0, 1) ==
"!") {
76 if (split[0] ==
"Units") {
77 std::string units = split[1];
78 if (units !=
"bohr" && units !=
"angstrom") {
79 throw std::runtime_error(
"Unit " + units +
" in file " + filename +
82 if (units ==
"bohr") {
83 unit_conversion = 1.0;
85 }
else if (split.size() == 6) {
87 std::string name = split[0];
90 pos[0] = boost::lexical_cast<double>(split[1]);
91 pos[1] = boost::lexical_cast<double>(split[2]);
92 pos[2] = boost::lexical_cast<double>(split[3]);
93 rank = boost::lexical_cast<Index>(split[5]);
94 numberofmultipoles = (rank + 1) * (rank + 1);
95 multipoles = Vector9d::Zero();
96 pos *= unit_conversion;
97 this->atomlist_.push_back(T(
id, name, pos));
100 else if (split[0] ==
"P") {
102 if (split.size() == 7) {
103 double pxx = boost::lexical_cast<double>(split[1]);
104 double pxy = boost::lexical_cast<double>(split[2]);
105 double pxz = boost::lexical_cast<double>(split[3]);
106 double pyy = boost::lexical_cast<double>(split[4]);
107 double pyz = boost::lexical_cast<double>(split[5]);
108 double pzz = boost::lexical_cast<double>(split[6]);
109 p1 << pxx, pxy, pxz, pxy, pyy, pyz, pxz, pyz, pzz;
110 }
else if (split.size() == 2) {
111 double pxx = boost::lexical_cast<double>(split[1]);
112 p1 = pxx * Eigen::Matrix3d::Identity();
114 throw std::runtime_error(
"Invalid line in " + filename +
": " + line);
117 p1 = p1 * unit_conversion_3;
118 this->atomlist_.back().setpolarization(p1);
123 for (
const std::string& entry : split) {
124 double qXYZ = boost::lexical_cast<double>(entry);
125 if (multipoles.size() < readinmultipoles) {
126 throw std::runtime_error(
"ReadMpsFile: File" + filename +
127 "is not properly formatted");
129 multipoles(readinmultipoles) = qXYZ;
132 if (readinmultipoles == numberofmultipoles) {
133 Eigen::Vector3d temp_dipoles = multipoles.segment<3>(1);
136 multipoles(1) = temp_dipoles(1);
137 multipoles(2) = temp_dipoles(2);
138 multipoles(3) = temp_dipoles(0);
139 this->atomlist_.back().setMultipole(multipoles, rank);
140 readinmultipoles = 0;
150 for (
const T& site : this->atomlist_) {
151 Q += site.getCharge();
158 Eigen::Vector3d dipole = Eigen::Vector3d::Zero();
160 Eigen::Vector3d CoM = this->getPos();
161 for (
const T& site : this->atomlist_) {
162 dipole += (site.getPos() - CoM) * site.getCharge();
163 dipole += site.getDipole();