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-2017 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 
153  std::string symbol_;
155  std::string label_;
157  bool ghosted_;
158 
160  // option name, basis name
161  std::map<std::string, std::string> basissets_;
162 
164  // set assigned to this atom.
165  // option name, hash string
166  std::map<std::string, std::string> shells_;
167 
169  static double r(const Vector3& a1, const Vector3& a2) { return a1.distance(a2); }
171  static double a(const Vector3& a1, const Vector3& a2, const Vector3& a3) {
172  Vector3 eBA(a2 - a1), eBC(a2 - a3);
173  eBA.normalize();
174  eBC.normalize();
175  double costheta = eBA.dot(eBC);
176  if (costheta > 1.0 - CLEANUP_THRESH) costheta = 1.0;
177  if (costheta < CLEANUP_THRESH - 1.0) costheta = -1.0;
178  return acos(costheta);
179  }
181  static double d(const Vector3& a1, const Vector3& a2, const Vector3& a3, const Vector3& a4) {
182  Vector3 eBA(a2 - a1), eDC(a4 - a3), eCB(a3 - a2);
183  double CBNorm = eCB.norm();
184  Vector3 DCxCB(eDC.cross(eCB));
185  Vector3 CBxBA(eCB.cross(eBA));
186  return -atan2(CBNorm * eDC.dot(eCB.cross(eBA)), DCxCB.dot(CBxBA));
187  }
188 
189  public:
196  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
197  const std::string& label = "");
198  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
199  const std::string& label, const std::map<std::string, std::string>& basis,
200  const std::map<std::string, std::string>& shells);
201  virtual ~CoordEntry();
202 
204  virtual const Vector3& compute() = 0;
207  virtual void set_coordinates(double x, double y, double z) = 0;
209  virtual CoordEntryType type() = 0;
211  virtual void print_in_input_format() = 0;
213  virtual std::string string_in_input_format() = 0;
215  bool is_computed() const { return computed_; }
217  bool is_equivalent_to(const std::shared_ptr<CoordEntry>& other) const;
219  virtual void invalidate() = 0;
221  virtual std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& atoms,
222  std::map<std::string, double>& map) = 0;
223 
225  const bool& is_ghosted() const { return ghosted_; }
227  void set_ghosted(bool ghosted) { ghosted_ = ghosted; }
228 
230  const double& Z() const;
232  const double& charge() const { return charge_; }
234  const double& mass() const { return mass_; }
236  const std::string& symbol() const { return symbol_; }
238  const std::string& label() const { return label_; }
240  const int& entry_number() const { return entry_number_; }
241 
243  void set_nuclear_charge(double newZ) { Z_ = newZ; }
244 
249  void set_basisset(const std::string& name, const std::string& type = "BASIS");
250 
255  const std::string& basisset(const std::string& type = "BASIS") const;
256  const std::map<std::string, std::string>& basissets() const { return basissets_; }
257 
262  void set_shell(const std::string& name, const std::string& type = "BASIS");
263 
268  const std::string& shell(const std::string& type = "BASIS") const;
269  const std::map<std::string, std::string>& shells() const { return shells_; }
270 
271  // Assign the mass of the atom (useful for isotopic substitutions)
272  void set_mass(double mass) { mass_ = mass; }
273 };
274 
275 class CartesianEntry : public CoordEntry {
276  std::shared_ptr<CoordValue> x_;
277  std::shared_ptr<CoordValue> y_;
278  std::shared_ptr<CoordValue> z_;
279 
280  public:
281  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
282  const std::string& label, std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y,
283  std::shared_ptr<CoordValue> z);
284  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
285  const std::string& label, std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y,
286  std::shared_ptr<CoordValue> z, const std::map<std::string, std::string>& basis,
287  const std::map<std::string, std::string>& shells);
288 
289  const Vector3& compute();
290  void set_coordinates(double x, double y, double z);
292  void print_in_input_format();
293  std::string string_in_input_format();
294  void invalidate() {
295  computed_ = false;
296  x_->invalidate();
297  y_->invalidate();
298  z_->invalidate();
299  }
300  std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& /*atoms*/,
301  std::map<std::string, double>& map) {
302  std::shared_ptr<CoordEntry> temp =
303  std::make_shared<CartesianEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, x_->clone(map),
304  y_->clone(map), z_->clone(map), basissets_, shells_);
305  return temp;
306  }
307 };
308 
309 class ZMatrixEntry : public CoordEntry {
310  std::shared_ptr<CoordEntry> rto_;
311  std::shared_ptr<CoordValue> rval_;
312  std::shared_ptr<CoordEntry> ato_;
313  std::shared_ptr<CoordValue> aval_;
314  std::shared_ptr<CoordEntry> dto_;
315  std::shared_ptr<CoordValue> dval_;
316 
317  public:
318  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
319  const std::string& label, std::shared_ptr<CoordEntry> rto = std::shared_ptr<CoordEntry>(),
320  std::shared_ptr<CoordValue> rval = std::shared_ptr<CoordValue>(),
321  std::shared_ptr<CoordEntry> ato = std::shared_ptr<CoordEntry>(),
322  std::shared_ptr<CoordValue> aval = std::shared_ptr<CoordValue>(),
323  std::shared_ptr<CoordEntry> dto = std::shared_ptr<CoordEntry>(),
324  std::shared_ptr<CoordValue> dval = std::shared_ptr<CoordValue>());
325  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol,
326  const std::string& label, const std::map<std::string, std::string>& basis,
327  const std::map<std::string, std::string>& shells,
328  std::shared_ptr<CoordEntry> rto = std::shared_ptr<CoordEntry>(),
329  std::shared_ptr<CoordValue> rval = std::shared_ptr<CoordValue>(),
330  std::shared_ptr<CoordEntry> ato = std::shared_ptr<CoordEntry>(),
331  std::shared_ptr<CoordValue> aval = std::shared_ptr<CoordValue>(),
332  std::shared_ptr<CoordEntry> dto = std::shared_ptr<CoordEntry>(),
333  std::shared_ptr<CoordValue> dval = std::shared_ptr<CoordValue>());
334 
335  virtual ~ZMatrixEntry();
336  void invalidate() {
337  computed_ = false;
338  if (rval_ != 0) rval_->invalidate();
339  if (aval_ != 0) aval_->invalidate();
340  if (dval_ != 0) dval_->invalidate();
341  }
342  const Vector3& compute();
343  void print_in_input_format();
344  std::string string_in_input_format();
345  void set_coordinates(double x, double y, double z);
347  std::shared_ptr<CoordEntry> clone(std::vector<std::shared_ptr<CoordEntry> >& atoms,
348  std::map<std::string, double>& map) {
349  std::shared_ptr<CoordEntry> temp;
350  if (rto_ == 0 && ato_ == 0 && dto_ == 0) {
351  temp =
352  std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_);
353  } else if (ato_ == 0 && dto_ == 0) {
354  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_,
355  shells_, atoms[rto_->entry_number()], rval_->clone(map));
356  } else if (dto_ == 0) {
357  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_,
358  shells_, atoms[rto_->entry_number()], rval_->clone(map),
359  atoms[ato_->entry_number()], aval_->clone(map));
360  } else {
361  temp = std::make_shared<ZMatrixEntry>(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_,
362  shells_, atoms[rto_->entry_number()], rval_->clone(map),
363  atoms[ato_->entry_number()], aval_->clone(map),
364  atoms[dto_->entry_number()], dval_->clone(map));
365  }
366  return temp;
367  }
368 };
369 }
370 
371 #endif // COORDENTRY_H
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:294
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:256
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:171
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:347
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:309
std::shared_ptr< CoordValue > z_
Definition: coordentry.h:278
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:195
void print_in_input_format()
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc:282
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:311
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:236
CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label, std::shared_ptr< CoordValue > x, std::shared_ptr< CoordValue > y, std::shared_ptr< CoordValue > z)
Definition: coordentry.cc:156
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:277
std::map< std::string, std::string > shells_
Short string representation of the numerical contents of basis.
Definition: coordentry.h:166
Definition: vector3.h:37
const double & charge() const
The &quot;atomic charge&quot; of the current atom (for SAD purposes).
Definition: coordentry.h:232
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:155
Definition: coordentry.h:195
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:300
std::shared_ptr< CoordValue > aval_
Definition: coordentry.h:313
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:234
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:181
std::shared_ptr< CoordEntry > dto_
Definition: coordentry.h:314
void invalidate()
Flag the current value as outdated.
Definition: coordentry.h:86
std::shared_ptr< CoordValue > x_
Definition: coordentry.h:276
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:225
const int & entry_number() const
The order in which this appears in the full atom list.
Definition: coordentry.h:240
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:291
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
ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label, 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
CoordValue()
Definition: coordentry.h:62
CoordValue(bool fixed)
Definition: coordentry.h:64
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:243
bool ghosted_
Is this a ghost atom?
Definition: coordentry.h:157
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:227
static double r(const Vector3 &a1, const Vector3 &a2)
Computes the distance between two sets of coordinates.
Definition: coordentry.h:169
Definition: coordentry.h:94
Definition: coordentry.h:54
const std::map< std::string, std::string > & shells() const
Definition: coordentry.h:269
void normalize()
Definition: vector3.h:63
void set_mass(double mass)
Definition: coordentry.h:272
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:215
CoordEntryType
Definition: coordentry.h:195
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:238
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:153
bool negate_
Definition: coordentry.h:116
std::shared_ptr< CoordEntry > ato_
Definition: coordentry.h:312
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:346
double distance(const Vector3 &) const
Definition: vector3.h:55
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:336
virtual void set_coordinates(double x, double y, double z)=0
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:315
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:161
std::shared_ptr< CoordEntry > rto_
Definition: coordentry.h:310
double mass_
Definition: coordentry.h:150
Definition: coordentry.h:275
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
CoordEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label="")
Definition: coordentry.cc:75
double Z_
Atomic number of the atom.
Definition: coordentry.h:148
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:103