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-2018 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 
48 
54 class CoordValue {
55  protected:
57  bool fixed_;
59  bool computed_;
60 
61  public:
62  CoordValue() : fixed_(false), computed_(false) {}
63 
64  CoordValue(bool fixed) : fixed_(fixed), computed_(false) {}
65 
66  CoordValue(bool fixed, bool computed) : fixed_(fixed), computed_(computed) {}
67 
68  virtual ~CoordValue() {}
69 
70  void set_fixed(bool fixed) { fixed_ = fixed; }
71  bool fixed() const { return fixed_; }
72 
80  virtual double compute() = 0;
82  virtual void set(double val) = 0;
84  virtual CoordValueType type() = 0;
86  void invalidate() { computed_ = false; }
88  virtual std::shared_ptr<CoordValue> clone(std::map<std::string, double>& map) = 0;
89 };
90 
94 class NumberValue : public CoordValue {
95  double value_;
96 
97  public:
98  NumberValue(double value, bool fixed = false) : CoordValue(fixed, true), value_(value) {}
99  double compute() { return value_; }
100  void set(double val) {
101  if (!fixed_) value_ = val;
102  }
104  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& /*map*/) {
105  return std::make_shared<NumberValue>(value_, fixed_);
106  }
107 };
108 
113 class VariableValue : public CoordValue {
114  const std::string name_;
115  std::map<std::string, double>& geometryVariables_;
116  bool negate_;
117 
118  public:
119  VariableValue(const std::string name, std::map<std::string, double>& geometryVariables, bool negate = false,
120  bool fixed = false)
121  : CoordValue(fixed, true), name_(name), geometryVariables_(geometryVariables), negate_(negate) {}
122  double compute();
123  bool negated() const { return negate_; }
124  const std::string& name() const { return name_; }
125  void set(double val) {
126  if (!fixed_) {
127  geometryVariables_[name_] = negate_ ? -val : val;
128  }
129  }
131  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& map) {
132  return std::make_shared<VariableValue>(name_, map, negate_, fixed_);
133  }
134 };
135 
136 class CoordEntry {
137  template <class Archive>
138  friend void save(Archive& ar, const psi::Vector3& t, size_t /*version*/);
139  template <class Archive>
140  friend void load(Archive& ar, psi::Vector3& t, size_t /*version*/);
141 
142  protected:
144  bool computed_;
146 
148  double Z_;
149  double charge_;
150  double mass_;
151  int A_;
152 
154  std::string symbol_;
156  std::string label_;
158  bool ghosted_;
159 
161  // option name, basis name
162  std::map<std::string, std::string> basissets_;
163 
165  // set assigned to this atom.
166  // option name, hash string
167  std::map<std::string, std::string> shells_;
168 
170  static double r(const Vector3& a1, const Vector3& a2) { return a1.distance(a2); }
172  static double a(const Vector3& a1, const Vector3& a2, const Vector3& a3) {
173  Vector3 eBA(a2 - a1), eBC(a2 - a3);
174  eBA.normalize();
175  eBC.normalize();
176  double costheta = eBA.dot(eBC);
177  if (costheta > 1.0 - CLEANUP_THRESH) costheta = 1.0;
178  if (costheta < CLEANUP_THRESH - 1.0) costheta = -1.0;
179  return acos(costheta);
180  }
182  static double d(const Vector3& a1, const Vector3& a2, const Vector3& a3, const Vector3& a4) {
183  Vector3 eBA(a2 - a1), eDC(a4 - a3), eCB(a3 - a2);
184  double CBNorm = eCB.norm();
185  Vector3 DCxCB(eDC.cross(eCB));
186  Vector3 CBxBA(eCB.cross(eBA));
187  return -atan2(CBNorm * eDC.dot(eCB.cross(eBA)), DCxCB.dot(CBxBA));
188  }
189 
190  public:
197  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
198  const std::string& label = "", int A = -1);
199  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
200  const std::string& label, int A, const std::map<std::string, std::string>& basis,
201  const std::map<std::string, std::string>& shells);
202  virtual ~CoordEntry();
203 
205  virtual const Vector3& compute() = 0;
208  virtual void set_coordinates(double x, double y, double z) = 0;
210  virtual CoordEntryType type() = 0;
212  virtual void print_in_input_format() = 0;
214  virtual std::string string_in_input_format() = 0;
216  bool is_computed() const { return computed_; }
218  bool is_equivalent_to(const std::shared_ptr<CoordEntry>& other) const;
220  virtual void invalidate() = 0;
222  virtual std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& atoms,
223  std::map<std::string, double>& map) = 0;
224 
226  const bool& is_ghosted() const { return ghosted_; }
228  void set_ghosted(bool ghosted) { ghosted_ = ghosted; }
229 
231  const double& Z() const;
233  const double& charge() const { return charge_; }
235  const double& mass() const { return mass_; }
237  const int& A() const { return A_; }
239  const std::string& symbol() const { return symbol_; }
241  const std::string& label() const { return label_; }
243  const int& entry_number() const { return entry_number_; }
244 
246  void set_nuclear_charge(double newZ) { Z_ = newZ; }
247 
252  void set_basisset(const std::string& name, const std::string& type = "BASIS");
253 
258  const std::string& basisset(const std::string& type = "BASIS") const;
259  const std::map<std::string, std::string>& basissets() const { return basissets_; }
260 
265  void set_shell(const std::string& name, const std::string& type = "BASIS");
266 
271  const std::string& shell(const std::string& type = "BASIS") const;
272  const std::map<std::string, std::string>& shells() const { return shells_; }
273 
274  // Assign the mass of the atom (useful for isotopic substitutions)
275  void set_mass(double mass) { mass_ = mass; }
276 
277  // Assign the mass number of the atom
278  void set_A(int A) { A_ = A; }
279 };
280 
281 class CartesianEntry : public CoordEntry {
282  std::shared_ptr<CoordValue> x_;
283  std::shared_ptr<CoordValue> y_;
284  std::shared_ptr<CoordValue> z_;
285 
286  public:
287  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
288  const std::string& label, int A, std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y,
289  std::shared_ptr<CoordValue> z);
290  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
291  const std::string& label, int A, std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y,
292  std::shared_ptr<CoordValue> z, const std::map<std::string, std::string>& basis,
293  const std::map<std::string, std::string>& shells);
294 
295  const Vector3& compute();
296  void set_coordinates(double x, double y, double z);
298  void print_in_input_format();
299  std::string string_in_input_format();
300  void invalidate() {
301  computed_ = false;
302  x_->invalidate();
303  y_->invalidate();
304  z_->invalidate();
305  }
306  std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& /*atoms*/,
307  std::map<std::string, double>& map) {
308  std::shared_ptr<CoordEntry> temp =
309  std::make_shared<CartesianEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, x_->clone(map),
310  y_->clone(map), z_->clone(map), basissets_, shells_);
311  return temp;
312  }
313 };
314 
315 class ZMatrixEntry : public CoordEntry {
316  std::shared_ptr<CoordEntry> rto_;
317  std::shared_ptr<CoordValue> rval_;
318  std::shared_ptr<CoordEntry> ato_;
319  std::shared_ptr<CoordValue> aval_;
320  std::shared_ptr<CoordEntry> dto_;
321  std::shared_ptr<CoordValue> dval_;
322 
323  public:
324  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
325  const std::string& label, int A, std::shared_ptr<CoordEntry> rto = std::shared_ptr<CoordEntry>(),
326  std::shared_ptr<CoordValue> rval = std::shared_ptr<CoordValue>(),
327  std::shared_ptr<CoordEntry> ato = std::shared_ptr<CoordEntry>(),
328  std::shared_ptr<CoordValue> aval = std::shared_ptr<CoordValue>(),
329  std::shared_ptr<CoordEntry> dto = std::shared_ptr<CoordEntry>(),
330  std::shared_ptr<CoordValue> dval = std::shared_ptr<CoordValue>());
331  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
332  const std::string& label, int A, const std::map<std::string, std::string>& basis,
333  const std::map<std::string, std::string>& shells,
334  std::shared_ptr<CoordEntry> rto = std::shared_ptr<CoordEntry>(),
335  std::shared_ptr<CoordValue> rval = std::shared_ptr<CoordValue>(),
336  std::shared_ptr<CoordEntry> ato = std::shared_ptr<CoordEntry>(),
337  std::shared_ptr<CoordValue> aval = std::shared_ptr<CoordValue>(),
338  std::shared_ptr<CoordEntry> dto = std::shared_ptr<CoordEntry>(),
339  std::shared_ptr<CoordValue> dval = std::shared_ptr<CoordValue>());
340 
341  virtual ~ZMatrixEntry();
342  void invalidate() {
343  computed_ = false;
344  if (rval_ != 0) rval_->invalidate();
345  if (aval_ != 0) aval_->invalidate();
346  if (dval_ != 0) dval_->invalidate();
347  }
348  const Vector3& compute();
349  void print_in_input_format();
350  std::string string_in_input_format();
351  void set_coordinates(double x, double y, double z);
353  std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& atoms,
354  std::map<std::string, double>& map) {
355  std::shared_ptr<CoordEntry> temp;
356  if (rto_ == 0 && ato_ == 0 && dto_ == 0) {
357  temp =
358  std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_, shells_);
359  } else if (ato_ == 0 && dto_ == 0) {
360  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
361  shells_, atoms[rto_->entry_number()], rval_->clone(map));
362  } else if (dto_ == 0) {
363  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
364  shells_, atoms[rto_->entry_number()], rval_->clone(map),
365  atoms[ato_->entry_number()], aval_->clone(map));
366  } else {
367  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, A_, basissets_,
368  shells_, atoms[rto_->entry_number()], rval_->clone(map),
369  atoms[ato_->entry_number()], aval_->clone(map),
370  atoms[dto_->entry_number()], dval_->clone(map));
371  }
372  if (computed_)
373  temp->set_coordinates(coordinates_[0], coordinates_[1], coordinates_[2]);
374  return temp;
375  }
376 };
377 }
378 
379 #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:156
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:300
bool fixed() const
Definition: coordentry.h:71
virtual void set(double val)=0
Sets the current value.
virtual void print_in_input_format()=0
Prints the updated geometry, in the format provided by the user.
const double & Z() const
The nuclear charge of the current atom (0 if ghosted).
Definition: coordentry.cc:94
const std::map< std::string, std::string > & basissets() const
Definition: coordentry.h:259
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:172
CoordValueType
Definition: coordentry.h:78
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< CoordEntry > clone(std::vector< std::shared_ptr< CoordEntry > > &atoms, std::map< std::string, double > &map)
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:353
std::shared_ptr< BasisSet > basis
Definition: dx_write.cc:59
double value_
Definition: coordentry.h:95
const std::string & name() const
Definition: coordentry.h:124
Vector3 cross(const Vector3 &) const
Definition: vector3.h:75
virtual double compute()=0
Computes the current value, and returns it.
Definition: coordentry.h:315
std::shared_ptr< CoordValue > z_
Definition: coordentry.h:284
virtual CoordValueType type()=0
The type of variable representation.
void set(double val)
Sets the current value.
Definition: coordentry.h:100
virtual ~CoordValue()
Definition: coordentry.h:68
Definition: coordentry.h:196
void print_in_input_format()
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc:282
void set_A(int A)
Definition: coordentry.h:278
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:108
bool fixed_
Fixed coordinate?
Definition: coordentry.h:57
std::shared_ptr< CoordValue > rval_
Definition: coordentry.h:317
std::string string_in_input_format()
String of the updated geometry, in the format provided by the user (analog of print_in_input_format) ...
Definition: coordentry.cc:321
const std::string & symbol() const
The atomic symbol.
Definition: coordentry.h:239
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:283
std::map< std::string, std::string > shells_
Short string representation of the numerical contents of basis.
Definition: coordentry.h:167
Definition: vector3.h:37
int A_
Definition: coordentry.h:151
const double & charge() const
The &quot;atomic charge&quot; of the current atom (for SAD purposes).
Definition: coordentry.h:233
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:130
std::map< std::string, double > & geometryVariables_
Definition: coordentry.h:115
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:156
Definition: coordentry.h:196
void set_coordinates(double x, double y, double z)
Definition: coordentry.cc:249
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) ...
virtual void invalidate()=0
Flags the current coordinates as being outdated.
std::shared_ptr< CoordEntry > clone(std::vector< std::shared_ptr< CoordEntry > > &, std::map< std::string, double > &map)
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:306
std::shared_ptr< CoordValue > aval_
Definition: coordentry.h:319
virtual ~ZMatrixEntry()
Definition: coordentry.cc:243
NumberValue(double value, bool fixed=false)
Definition: coordentry.h:98
const double & mass() const
The atomic mass of the current atom.
Definition: coordentry.h:235
virtual const Vector3 & compute()=0
Computes the values of the coordinates (in whichever units were inputted), returning them in a Vector...
friend void load(Archive &ar, psi::Vector3 &t, size_t)
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:182
std::shared_ptr< CoordEntry > dto_
Definition: coordentry.h:320
void invalidate()
Flag the current value as outdated.
Definition: coordentry.h:86
std::shared_ptr< CoordValue > x_
Definition: coordentry.h:282
friend void save(Archive &ar, const psi::Vector3 &t, size_t)
const bool & is_ghosted() const
Whether the current atom is ghosted or not.
Definition: coordentry.h:226
const int & entry_number() const
The order in which this appears in the full atom list.
Definition: coordentry.h:243
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:297
const std::string & shell(const std::string &type="BASIS") const
Definition: coordentry.cc:145
int entry_number_
Definition: coordentry.h:143
#define CLEANUP_THRESH
Definition: coordentry.h:42
std::shared_ptr< CoordValue > clone(std::map< std::string, double > &map)
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:131
const std::string & basisset(const std::string &type="BASIS") const
Definition: coordentry.cc:129
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:43
Definition: coordentry.h:78
const Vector3 & compute()
Definition: coordentry.cc:371
CoordValue()
Definition: coordentry.h:62
CoordValue(bool fixed)
Definition: coordentry.h:64
const int & A() const
The mass number of the current atom, if known, else -1.
Definition: coordentry.h:237
VariableValue(const std::string name, std::map< std::string, double > &geometryVariables, bool negate=false, bool fixed=false)
Definition: coordentry.h:119
void set_nuclear_charge(double newZ)
Set the nuclear charge for this atom (primarily used in ECP calculations to modify Z)...
Definition: coordentry.h:246
bool ghosted_
Is this a ghost atom?
Definition: coordentry.h:158
Definition: coordentry.h:113
const std::string name_
Definition: coordentry.h:114
Definition: coordentry.h:136
void set_ghosted(bool ghosted)
Flag the atom as either ghost or real.
Definition: coordentry.h:228
static double r(const Vector3 &a1, const Vector3 &a2)
Computes the distance between two sets of coordinates.
Definition: coordentry.h:170
Definition: coordentry.h:94
Definition: coordentry.h:54
const std::map< std::string, std::string > & shells() const
Definition: coordentry.h:272
void normalize()
Definition: vector3.h:63
void set_mass(double mass)
Definition: coordentry.h:275
bool computed_
Definition: coordentry.h:144
bool computed_
Whether the current value is up to date or not.
Definition: coordentry.h:59
const Vector3 & compute()
Computes the values of the coordinates (in whichever units were inputted), returning them in a Vector...
Definition: coordentry.cc:191
virtual ~CoordEntry()
Definition: coordentry.cc:90
void set_fixed(bool fixed)
Definition: coordentry.h:70
bool is_computed() const
Whether the current atom&#39;s coordinates are up-to-date.
Definition: coordentry.h:216
CoordEntryType
Definition: coordentry.h:196
double compute()
Computes the current value, and returns it.
Definition: coordentry.h:99
double compute()
Computes the current value, and returns it.
Definition: coordentry.cc:68
const std::string & label() const
The atom label.
Definition: coordentry.h:241
void set(double val)
Sets the current value.
Definition: coordentry.h:125
CoordValue(bool fixed, bool computed)
Definition: coordentry.h:66
double charge_
Definition: coordentry.h:149
std::string symbol_
Label of the atom minus any extra info (H1 =&gt; H)
Definition: coordentry.h:154
bool negate_
Definition: coordentry.h:116
std::shared_ptr< CoordEntry > ato_
Definition: coordentry.h:318
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:352
double distance(const Vector3 &) const
Definition: vector3.h:55
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:342
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:75
void print_in_input_format()
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc:170
void set_basisset(const std::string &name, const std::string &type="BASIS")
Definition: coordentry.cc:124
Vector3 coordinates_
Definition: coordentry.h:145
std::shared_ptr< CoordValue > dval_
Definition: coordentry.h:321
void set_coordinates(double x, double y, double z)
Definition: coordentry.cc:203
std::shared_ptr< CoordValue > clone(std::map< std::string, double > &)
Clones the current object, using a user-provided variable array, for deep copying.
Definition: coordentry.h:104
std::map< std::string, std::string > basissets_
Different types of basis sets that can be assigned to this atom.
Definition: coordentry.h:162
std::shared_ptr< CoordEntry > rto_
Definition: coordentry.h:316
double mass_
Definition: coordentry.h:150
Definition: coordentry.h:281
double norm() const
Definition: vector3.h:148
Definition: coordentry.h:78
bool negated() const
Definition: coordentry.h:123
std::string string_in_input_format()
String of the updated geometry, in the format provided by the user (analog of print_in_input_format) ...
Definition: coordentry.cc:178
double Z_
Atomic number of the atom.
Definition: coordentry.h:148
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:216
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:103