Psi4
coordentry.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2019 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef COORDENTRY_H
30 #define COORDENTRY_H
31 
32 #include <map>
33 #include <string>
34 #include <cmath>
35 #include "vector3.h"
36 #include "psi4/pragma.h"
37 PRAGMA_WARNING_PUSH
38 PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS
39 #include <memory>
41 
42 #define CLEANUP_THRESH 1.0E-14
43 
44 namespace psi {
45 
51 class CoordValue {
52  protected:
54  bool fixed_;
55 
56  public:
57  CoordValue() : fixed_(false) {}
58 
59  CoordValue(bool fixed) : fixed_(fixed) {}
60 
61  virtual ~CoordValue() {}
62 
63  void set_fixed(bool fixed) { fixed_ = fixed; }
64  bool fixed() const { return fixed_; }
65 
73  virtual double compute() = 0;
75  virtual void set(double val) = 0;
77  virtual CoordValueType type() = 0;
79  virtual std::shared_ptr<CoordValue> clone(std::map<std::string, double>& map) = 0;
80 };
81 
85 class NumberValue : public CoordValue {
86  double value_;
87 
88  public:
89  NumberValue(double value, bool fixed = false) : CoordValue(fixed), value_(value) {}
90  double compute() override { return value_; }
91  void set(double val) override {
92  if (!fixed_) value_ = val;
93  }
94  CoordValueType type() override { return NumberType; }
95  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& /*map*/) override {
96  return std::make_shared<NumberValue>(value_, fixed_);
97  }
98 };
99 
104 class VariableValue : public CoordValue {
105  const std::string name_;
106  std::map<std::string, double>& geometryVariables_;
107  bool negate_;
108 
109  public:
110  VariableValue(const std::string name, std::map<std::string, double>& geometryVariables, bool negate = false,
111  bool fixed = false)
112  : CoordValue(fixed), name_(name), geometryVariables_(geometryVariables), negate_(negate) {}
113  double compute() override;
114  bool negated() const { return negate_; }
115  const std::string& name() const { return name_; }
116  void set(double val) override {
117  if (!fixed_) {
118  geometryVariables_[name_] = negate_ ? -val : val;
119  }
120  }
121  CoordValueType type() override { return VariableType; }
122  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& map) override {
123  return std::make_shared<VariableValue>(name_, map, negate_, fixed_);
124  }
125 };
126 
127 class CoordEntry {
128 
129  protected:
131  bool computed_;
133 
135  double Z_;
136  double charge_;
137  double mass_;
138  int A_;
139 
141  std::string symbol_;
143  std::string label_;
145  bool ghosted_;
146 
148  // option name, basis name
149  std::map<std::string, std::string> basissets_;
150 
152  // set assigned to this atom.
153  // option name, hash string
154  std::map<std::string, std::string> shells_;
155 
157  static double r(const Vector3& a1, const Vector3& a2) { return a1.distance(a2); }
159  static double a(const Vector3& a1, const Vector3& a2, const Vector3& a3) {
160  Vector3 eBA(a2 - a1), eBC(a2 - a3);
161  eBA.normalize();
162  eBC.normalize();
163  double costheta = eBA.dot(eBC);
164  if (costheta > 1.0 - CLEANUP_THRESH) costheta = 1.0;
165  if (costheta < CLEANUP_THRESH - 1.0) costheta = -1.0;
166  return acos(costheta);
167  }
169  static double d(const Vector3& a1, const Vector3& a2, const Vector3& a3, const Vector3& a4) {
170  Vector3 eBA(a2 - a1), eDC(a4 - a3), eCB(a3 - a2);
171  double CBNorm = eCB.norm();
172  Vector3 DCxCB(eDC.cross(eCB));
173  Vector3 CBxBA(eCB.cross(eBA));
174  return -atan2(CBNorm * eDC.dot(eCB.cross(eBA)), DCxCB.dot(CBxBA));
175  }
176 
177  public:
184  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
185  const std::string& label = "", int A = -1);
186  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
187  const std::string& label, int A, const std::map<std::string, std::string>& basis,
188  const std::map<std::string, std::string>& shells);
189  virtual ~CoordEntry();
190 
192  virtual const Vector3& compute() = 0;
195  virtual void set_coordinates(double x, double y, double z) = 0;
197  virtual CoordEntryType type() = 0;
199  virtual void print_in_input_format() = 0;
201  virtual std::string string_in_input_format() = 0;
203  bool is_computed() const { return computed_; }
205  bool is_equivalent_to(const std::shared_ptr<CoordEntry>& other) const;
207  void invalidate() {
208  computed_ = false;
209  }
211  virtual std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& atoms,
212  std::map<std::string, double>& map) = 0;
213 
215  const bool& is_ghosted() const { return ghosted_; }
217  void set_ghosted(bool ghosted) { ghosted_ = ghosted; }
218 
220  const double& Z() const;
222  const double& charge() const { return charge_; }
224  const double& mass() const { return mass_; }
226  const int& A() const { return A_; }
228  const std::string& symbol() const { return symbol_; }
230  const std::string& label() const { return label_; }
232  const int& entry_number() const { return entry_number_; }
233 
235  void set_nuclear_charge(double newZ) { Z_ = newZ; }
236 
241  void set_basisset(const std::string& name, const std::string& type = "BASIS");
242 
247  const std::string& basisset(const std::string& type = "BASIS") const;
248  const std::map<std::string, std::string>& basissets() const { return basissets_; }
249 
254  void set_shell(const std::string& name, const std::string& type = "BASIS");
255 
260  const std::string& shell(const std::string& type = "BASIS") const;
261  const std::map<std::string, std::string>& shells() const { return shells_; }
262 
263  // Assign the mass of the atom (useful for isotopic substitutions)
264  void set_mass(double mass) { mass_ = mass; }
265 
266  // Assign the mass number of the atom
267  void set_A(int A) { A_ = A; }
268 };
269 
270 class CartesianEntry : public CoordEntry {
271  std::shared_ptr<CoordValue> x_;
272  std::shared_ptr<CoordValue> y_;
273  std::shared_ptr<CoordValue> z_;
274 
275  public:
276  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
277  const std::string& label, int A, std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y,
278  std::shared_ptr<CoordValue> z);
279  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
280  const std::string& label, int A, std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y,
281  std::shared_ptr<CoordValue> z, const std::map<std::string, std::string>& basis,
282  const std::map<std::string, std::string>& shells);
283 
284  const Vector3& compute() override;
285  void set_coordinates(double x, double y, double z) override;
286  CoordEntryType type() override { return CartesianCoord; }
287  void print_in_input_format() override;
288  std::string string_in_input_format() override;
289  std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& /*atoms*/,
290  std::map<std::string, double>& map) override {
291  std::shared_ptr<CoordEntry> temp =
292  std::make_shared<CartesianEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, x_->clone(map),
293  y_->clone(map), z_->clone(map), basissets_, shells_);
294  if (computed_) temp->compute(); // The constructor sets the coords we want, so this just sets computed_.
295  return temp;
296  }
297 };
298 
299 class ZMatrixEntry : public CoordEntry {
300  std::shared_ptr<CoordEntry> rto_;
301  std::shared_ptr<CoordValue> rval_;
302  std::shared_ptr<CoordEntry> ato_;
303  std::shared_ptr<CoordValue> aval_;
304  std::shared_ptr<CoordEntry> dto_;
305  std::shared_ptr<CoordValue> dval_;
306 
307  public:
308  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
309  const std::string& label, int A, std::shared_ptr<CoordEntry> rto = std::shared_ptr<CoordEntry>(),
310  std::shared_ptr<CoordValue> rval = std::shared_ptr<CoordValue>(),
311  std::shared_ptr<CoordEntry> ato = std::shared_ptr<CoordEntry>(),
312  std::shared_ptr<CoordValue> aval = std::shared_ptr<CoordValue>(),
313  std::shared_ptr<CoordEntry> dto = std::shared_ptr<CoordEntry>(),
314  std::shared_ptr<CoordValue> dval = std::shared_ptr<CoordValue>());
315  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
316  const std::string& label, int A, const std::map<std::string, std::string>& basis,
317  const std::map<std::string, std::string>& shells,
318  std::shared_ptr<CoordEntry> rto = std::shared_ptr<CoordEntry>(),
319  std::shared_ptr<CoordValue> rval = std::shared_ptr<CoordValue>(),
320  std::shared_ptr<CoordEntry> ato = std::shared_ptr<CoordEntry>(),
321  std::shared_ptr<CoordValue> aval = std::shared_ptr<CoordValue>(),
322  std::shared_ptr<CoordEntry> dto = std::shared_ptr<CoordEntry>(),
323  std::shared_ptr<CoordValue> dval = std::shared_ptr<CoordValue>());
324 
325  ~ZMatrixEntry() override;
326  const Vector3& compute() override;
327  void print_in_input_format() override;
328  std::string string_in_input_format() override;
329  void set_coordinates(double x, double y, double z) override;
330  CoordEntryType type() override { return ZMatrixCoord; }
331  std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& atoms,
332  std::map<std::string, double>& map) override {
333  std::shared_ptr<CoordEntry> temp;
334  if (rto_ == 0 && ato_ == 0 && dto_ == 0) {
335  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
336  shells_);
337  } else if (ato_ == 0 && dto_ == 0) {
338  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
339  shells_, atoms[rto_->entry_number()], rval_->clone(map));
340  } else if (dto_ == 0) {
341  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
342  shells_, atoms[rto_->entry_number()], rval_->clone(map),
343  atoms[ato_->entry_number()], aval_->clone(map));
344  } else {
345  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
346  shells_, atoms[rto_->entry_number()], rval_->clone(map),
347  atoms[ato_->entry_number()], aval_->clone(map),
348  atoms[dto_->entry_number()], dval_->clone(map));
349  }
350  if (computed_) temp->set_coordinates(coordinates_[0], coordinates_[1], coordinates_[2]);
351  return temp;
352  }
353 };
354 } // namespace psi
355 
356 #endif // COORDENTRY_H
CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label, int A, std::shared_ptr< CoordValue > x, std::shared_ptr< CoordValue > y, std::shared_ptr< CoordValue > z)
Definition: coordentry.cc:151
bool fixed() const
Definition: coordentry.h:64
virtual void set(double val)=0
Sets the current value.
CoordEntryType type() override
The type of CoordEntry Specialization.
Definition: coordentry.h:286
virtual void print_in_input_format()=0
Prints the updated geometry, in the format provided by the user.
std::shared_ptr< CoordValue > clone(std::map< std::string, double > &) override
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:95
const double & Z() const
The nuclear charge of the current atom (0 if ghosted).
Definition: coordentry.cc:102
const std::map< std::string, std::string > & basissets() const
Definition: coordentry.h:248
static double a(const Vector3 &a1, const Vector3 &a2, const Vector3 &a3)
Computes the angle (in rad.) between three sets of coordinates.
Definition: coordentry.h:159
CoordValueType
Definition: coordentry.h:71
virtual std::shared_ptr< CoordValue > clone(std::map< std::string, double > &map)=0
Clones the current object, using a user-provided variable array, for deep copying.
std::shared_ptr< BasisSet > basis
Definition: dx_write.cc:59
void set_coordinates(double x, double y, double z) override
Definition: coordentry.cc:192
double value_
Definition: coordentry.h:86
const std::string & name() const
Definition: coordentry.h:115
Vector3 cross(const Vector3 &) const
Definition: vector3.h:66
virtual double compute()=0
Computes the current value, and returns it.
void set(double val) override
Sets the current value.
Definition: coordentry.h:91
Definition: coordentry.h:299
std::shared_ptr< CoordValue > z_
Definition: coordentry.h:273
virtual CoordValueType type()=0
The type of variable representation.
const Vector3 & compute() override
Computes the values of the coordinates (in whichever units were inputted), returning them in a Vector...
Definition: coordentry.cc:182
void print_in_input_format() override
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc:261
virtual ~CoordValue()
Definition: coordentry.h:61
Definition: coordentry.h:183
void set_A(int A)
Definition: coordentry.h:267
bool is_equivalent_to(const std::shared_ptr< CoordEntry > &other) const
Whether this atom has the same mass and basis sets as another atom.
Definition: coordentry.cc:114
bool fixed_
Fixed coordinate?
Definition: coordentry.h:54
std::shared_ptr< CoordValue > rval_
Definition: coordentry.h:301
void set_coordinates(double x, double y, double z) override
Definition: coordentry.cc:233
const std::string & symbol() const
The atomic symbol.
Definition: coordentry.h:228
virtual std::shared_ptr< CoordEntry > clone(std::vector< std::shared_ptr< CoordEntry > > &atoms, std::map< std::string, double > &map)=0
Clones the current object, using a user-provided variable array, for deep copying.
void set_shell(const std::string &name, const std::string &type="BASIS")
Definition: coordentry.cc:140
std::shared_ptr< CoordValue > y_
Definition: coordentry.h:272
std::map< std::string, std::string > shells_
Short string representation of the numerical contents of basis.
Definition: coordentry.h:154
Definition: vector3.h:40
std::shared_ptr< CoordValue > clone(std::map< std::string, double > &map) override
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:122
int A_
Definition: coordentry.h:138
const Vector3 & compute() override
Definition: coordentry.cc:345
std::shared_ptr< CoordEntry > clone(std::vector< std::shared_ptr< CoordEntry > > &atoms, std::map< std::string, double > &map) override
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:331
const double & charge() const
The &quot;atomic charge&quot; of the current atom (for SAD purposes).
Definition: coordentry.h:222
void print_in_input_format() override
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc:163
std::map< std::string, double > & geometryVariables_
Definition: coordentry.h:106
virtual CoordEntryType type()=0
The type of CoordEntry Specialization.
std::string label_
Original label from the molecule from the input file (H1)
Definition: coordentry.h:143
Definition: coordentry.h:183
~ZMatrixEntry() override
Definition: coordentry.cc:231
virtual std::string string_in_input_format()=0
String of the updated geometry, in the format provided by the user (analog of print_in_input_format) ...
void set(double val) override
Sets the current value.
Definition: coordentry.h:116
std::shared_ptr< CoordValue > aval_
Definition: coordentry.h:303
NumberValue(double value, bool fixed=false)
Definition: coordentry.h:89
const double & mass() const
The atomic mass of the current atom.
Definition: coordentry.h:224
virtual const Vector3 & compute()=0
Computes the values of the coordinates (in whichever units were inputted), returning them in a Vector...
static double d(const Vector3 &a1, const Vector3 &a2, const Vector3 &a3, const Vector3 &a4)
Computes the dihedral (in rad.) between four sets of coordinates.
Definition: coordentry.h:169
std::shared_ptr< CoordEntry > dto_
Definition: coordentry.h:304
std::shared_ptr< CoordValue > x_
Definition: coordentry.h:271
const bool & is_ghosted() const
Whether the current atom is ghosted or not.
Definition: coordentry.h:215
const int & entry_number() const
The order in which this appears in the full atom list.
Definition: coordentry.h:232
const std::string & shell(const std::string &type="BASIS") const
Definition: coordentry.cc:142
int entry_number_
Definition: coordentry.h:130
#define CLEANUP_THRESH
Definition: coordentry.h:42
const std::string & basisset(const std::string &type="BASIS") const
Definition: coordentry.cc:131
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:43
CoordValueType type() override
The type of variable representation.
Definition: coordentry.h:94
Definition: coordentry.h:71
CoordValue()
Definition: coordentry.h:57
CoordValueType type() override
The type of variable representation.
Definition: coordentry.h:121
CoordValue(bool fixed)
Definition: coordentry.h:59
const int & A() const
The mass number of the current atom, if known, else -1.
Definition: coordentry.h:226
VariableValue(const std::string name, std::map< std::string, double > &geometryVariables, bool negate=false, bool fixed=false)
Definition: coordentry.h:110
void set_nuclear_charge(double newZ)
Set the nuclear charge for this atom (primarily used in ECP calculations to modify Z)...
Definition: coordentry.h:235
bool ghosted_
Is this a ghost atom?
Definition: coordentry.h:145
Definition: coordentry.h:104
const std::string name_
Definition: coordentry.h:105
Definition: coordentry.h:127
double compute() override
Computes the current value, and returns it.
Definition: coordentry.cc:67
void set_ghosted(bool ghosted)
Flag the atom as either ghost or real.
Definition: coordentry.h:217
static double r(const Vector3 &a1, const Vector3 &a2)
Computes the distance between two sets of coordinates.
Definition: coordentry.h:157
Definition: coordentry.h:85
Definition: coordentry.h:51
const std::map< std::string, std::string > & shells() const
Definition: coordentry.h:261
void normalize()
Definition: vector3.h:57
void set_mass(double mass)
Definition: coordentry.h:264
bool computed_
Definition: coordentry.h:131
virtual ~CoordEntry()
Definition: coordentry.cc:100
void set_fixed(bool fixed)
Definition: coordentry.h:63
bool is_computed() const
Whether the current atom&#39;s coordinates are up-to-date.
Definition: coordentry.h:203
CoordEntryType
Definition: coordentry.h:183
const std::string & label() const
The atom label.
Definition: coordentry.h:230
std::string string_in_input_format() override
String of the updated geometry, in the format provided by the user (analog of print_in_input_format) ...
Definition: coordentry.cc:170
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:207
double charge_
Definition: coordentry.h:136
std::string symbol_
Label of the atom minus any extra info (H1 =&gt; H)
Definition: coordentry.h:141
bool negate_
Definition: coordentry.h:107
std::shared_ptr< CoordEntry > ato_
Definition: coordentry.h:302
double compute() override
Computes the current value, and returns it.
Definition: coordentry.h:90
double distance(const Vector3 &) const
Definition: vector3.h:50
virtual void set_coordinates(double x, double y, double z)=0
CoordEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label="", int A=-1)
Definition: coordentry.cc:73
void set_basisset(const std::string &name, const std::string &type="BASIS")
Definition: coordentry.cc:129
Vector3 coordinates_
Definition: coordentry.h:132
std::shared_ptr< CoordValue > dval_
Definition: coordentry.h:305
std::map< std::string, std::string > basissets_
Different types of basis sets that can be assigned to this atom.
Definition: coordentry.h:149
std::shared_ptr< CoordEntry > rto_
Definition: coordentry.h:300
std::shared_ptr< CoordEntry > clone(std::vector< std::shared_ptr< CoordEntry > > &, std::map< std::string, double > &map) override
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:289
double mass_
Definition: coordentry.h:137
Definition: coordentry.h:270
double norm() const
Definition: vector3.h:155
Definition: coordentry.h:71
bool negated() const
Definition: coordentry.h:114
CoordEntryType type() override
The type of CoordEntry Specialization.
Definition: coordentry.h:330
std::string string_in_input_format() override
String of the updated geometry, in the format provided by the user (analog of print_in_input_format) ...
Definition: coordentry.cc:297
double Z_
Atomic number of the atom.
Definition: coordentry.h:135
ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label, int A, std::shared_ptr< CoordEntry > rto=std::shared_ptr< CoordEntry >(), std::shared_ptr< CoordValue > rval=std::shared_ptr< CoordValue >(), std::shared_ptr< CoordEntry > ato=std::shared_ptr< CoordEntry >(), std::shared_ptr< CoordValue > aval=std::shared_ptr< CoordValue >(), std::shared_ptr< CoordEntry > dto=std::shared_ptr< CoordEntry >(), std::shared_ptr< CoordValue > dval=std::shared_ptr< CoordValue >())
Definition: coordentry.cc:204