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 program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef COORDENTRY_H
29 #define COORDENTRY_H
30 
31 #include <map>
32 #include <string>
33 #include <cmath>
34 #include "vector3.h"
35  #include "psi4/pragma.h"
36  PRAGMA_WARNING_PUSH
37  PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS
38  #include <memory>
40 
41 #define CLEANUP_THRESH 1.0E-14
42 
43 namespace psi {
44 
47 
48 class Vector3;
49 
50 
57 {
58 protected:
60  bool fixed_;
62  bool computed_;
63 public:
64 
65  CoordValue() : fixed_(false), computed_(false)
66  { }
67 
68  CoordValue(bool fixed) : fixed_(fixed), computed_(false)
69  { }
70 
71  CoordValue(bool fixed, bool computed) : fixed_(fixed), computed_(computed)
72  { }
73 
74  virtual ~CoordValue() {}
75 
76  void set_fixed(bool fixed) { fixed_ = fixed; }
77  bool fixed() const { return fixed_; }
78 
86  virtual double compute() =0;
88  virtual void set(double val) =0;
90  virtual CoordValueType type() =0;
92  void invalidate() { computed_ = false; }
94  virtual std::shared_ptr<CoordValue> clone( std::map<std::string, double>& map) =0;
95 };
96 
100 class NumberValue : public CoordValue
101 {
102  double value_;
103 public:
104  NumberValue(double value, bool fixed = false) : CoordValue(fixed, true), value_(value) {}
105  double compute() { return value_; }
106  void set(double val) { if (!fixed_) value_ = val; }
108  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& /*map*/) {
109  return std::shared_ptr<CoordValue>(new NumberValue(value_, fixed_));
110  }
111 };
112 
117 class VariableValue : public CoordValue
118 {
119  const std::string name_;
120  std::map<std::string, double>& geometryVariables_;
121  bool negate_;
122 public:
123  VariableValue(const std::string name, std::map<std::string, double>& geometryVariables, bool negate=false, bool fixed = false)
124  : CoordValue(fixed, true), name_(name), geometryVariables_(geometryVariables), negate_(negate) {}
125  double compute();
126  bool negated() const { return negate_; }
127  const std::string & name() const { return name_; }
128  void set(double val) { if (!fixed_) { geometryVariables_[name_] = negate_ ? -val : val; } }
130  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& map) {
131  return std::shared_ptr<CoordValue>(new VariableValue(name_, map, negate_, fixed_));
132  }
133 };
134 
135 
137 {
138  template<class Archive>
139  friend void save(Archive & ar, const psi::Vector3 & t, unsigned int /*version*/);
140  template<class Archive>
141  friend void load(Archive & ar, psi::Vector3 & t, unsigned int /*version*/);
142 
143 protected:
145  bool computed_;
147 
149  double Z_;
150  double charge_;
151  double mass_;
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); eBA.normalize(); eBC.normalize();
174  double costheta = eBA.dot(eBC);
175  if(costheta > 1.0 - CLEANUP_THRESH) costheta = 1.0;
176  if(costheta < CLEANUP_THRESH - 1.0) costheta = -1.0;
177  return acos(costheta); }
179  static double d(const Vector3 &a1, const Vector3 &a2, const Vector3 &a3, const Vector3 &a4)
180  { Vector3 eBA(a2-a1), eDC(a4-a3), eCB(a3-a2);
181  double CBNorm = eCB.norm();
182  Vector3 DCxCB(eDC.cross(eCB));
183  Vector3 CBxBA(eCB.cross(eBA));
184  return -atan2(CBNorm * eDC.dot(eCB.cross(eBA)), DCxCB.dot(CBxBA));}
185 public:
192  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label="");
193  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label, const std::map<std::string, std::string>& basis, const std::map<std::string, std::string>& shells);
194  virtual ~CoordEntry();
195 
197  virtual const Vector3& compute() =0;
200  virtual void set_coordinates(double x, double y, double z) = 0;
202  virtual CoordEntryType type() =0;
204  virtual void print_in_input_format() = 0;
206  virtual std::string string_in_input_format() = 0;
208  bool is_computed() const { return computed_; }
210  bool is_equivalent_to(const std::shared_ptr<CoordEntry> &other) const;
212  virtual void invalidate() =0;
214  virtual std::shared_ptr<CoordEntry> clone( std::vector<std::shared_ptr<CoordEntry> > &atoms, std::map<std::string, double>& map) =0;
215 
217  const bool& is_ghosted() const { return ghosted_; }
219  void set_ghosted(bool ghosted) { ghosted_ = ghosted; }
220 
222  const double& Z() const;
224  const double& charge() const { return charge_; }
226  const double& mass() const { return mass_; }
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 
238  void set_basisset(const std::string& name, const std::string& type="BASIS");
239 
244  const std::string& basisset(const std::string& type="BASIS") const;
245  const std::map<std::string, std::string>& basissets() const { return basissets_;}
246 
251  void set_shell(const std::string& name, const std::string& type="BASIS");
252 
257  const std::string& shell(const std::string& type="BASIS") const;
258  const std::map<std::string, std::string>& shells() const { return shells_;}
259 
260  // Assign the mass of the atom (useful for isotopic substitutions)
261  void set_mass(double mass) { mass_ = mass; }
262 };
263 
264 class CartesianEntry : public CoordEntry{
265  std::shared_ptr<CoordValue> x_;
266  std::shared_ptr<CoordValue> y_;
267  std::shared_ptr<CoordValue> z_;
268 public:
269  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
270  std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y, std::shared_ptr<CoordValue> z);
271  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
272  std::shared_ptr<CoordValue> x, std::shared_ptr<CoordValue> y, std::shared_ptr<CoordValue> z, const std::map<std::string, std::string>& basis, const std::map<std::string, std::string>& shells);
273 
274  const Vector3& compute();
275  void set_coordinates(double x, double y, double z);
277  void print_in_input_format();
278  std::string string_in_input_format();
279  void invalidate () { computed_ = false; x_->invalidate(); y_->invalidate(); z_->invalidate(); }
280  std::shared_ptr<CoordEntry> clone( std::vector<std::shared_ptr<CoordEntry> >& /*atoms*/, std::map<std::string, double>& map){
281  std::shared_ptr<CoordEntry> temp(new CartesianEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, x_->clone(map), y_->clone(map), z_->clone(map), basissets_, shells_));
282  return temp;
283  }
284 };
285 
286 class ZMatrixEntry : public CoordEntry
287 {
288  std::shared_ptr<CoordEntry> rto_;
289  std::shared_ptr<CoordValue> rval_;
290  std::shared_ptr<CoordEntry> ato_;
291  std::shared_ptr<CoordValue> aval_;
292  std::shared_ptr<CoordEntry> dto_;
293  std::shared_ptr<CoordValue> dval_;
294 
295 public:
296  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
297  std::shared_ptr<CoordEntry> rto=std::shared_ptr<CoordEntry>(),
298  std::shared_ptr<CoordValue> rval=std::shared_ptr<CoordValue>(),
299  std::shared_ptr<CoordEntry> ato=std::shared_ptr<CoordEntry>(),
300  std::shared_ptr<CoordValue> aval=std::shared_ptr<CoordValue>(),
301  std::shared_ptr<CoordEntry> dto=std::shared_ptr<CoordEntry>(),
302  std::shared_ptr<CoordValue> dval=std::shared_ptr<CoordValue>());
303  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
304  const std::map<std::string, std::string>& basis,
305  const std::map<std::string, std::string>& shells,
306  std::shared_ptr<CoordEntry> rto=std::shared_ptr<CoordEntry>(),
307  std::shared_ptr<CoordValue> rval=std::shared_ptr<CoordValue>(),
308  std::shared_ptr<CoordEntry> ato=std::shared_ptr<CoordEntry>(),
309  std::shared_ptr<CoordValue> aval=std::shared_ptr<CoordValue>(),
310  std::shared_ptr<CoordEntry> dto=std::shared_ptr<CoordEntry>(),
311  std::shared_ptr<CoordValue> dval=std::shared_ptr<CoordValue>());
312 
313  virtual ~ZMatrixEntry();
314  void invalidate () { computed_ = false; if(rval_ != 0) rval_->invalidate();
315  if(aval_ != 0) aval_->invalidate();
316  if(dval_ != 0) dval_->invalidate(); }
317  const Vector3& compute();
318  void print_in_input_format();
319  std::string string_in_input_format();
320  void set_coordinates(double x, double y, double z);
322  std::shared_ptr<CoordEntry> clone( std::vector<std::shared_ptr<CoordEntry> > &atoms, std::map<std::string, double>& map){
323  std::shared_ptr<CoordEntry> temp;
324  if(rto_ == 0 && ato_ == 0 && dto_ == 0){
325  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_));
326  }else if(ato_ == 0 && dto_ == 0){
327  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_,
328  atoms[rto_->entry_number()], rval_->clone(map)));
329  }else if(dto_ == 0){
330  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_,
331  atoms[rto_->entry_number()], rval_->clone(map),
332  atoms[ato_->entry_number()], aval_->clone(map)));
333  }
334  else {
335  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_,
336  atoms[rto_->entry_number()], rval_->clone(map),
337  atoms[ato_->entry_number()], aval_->clone(map),
338  atoms[dto_->entry_number()], dval_->clone(map)));
339  }
340  return temp;
341  }
342 };
343 
344 }
345 
346 #endif // COORDENTRY_H
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:279
bool fixed() const
Definition: coordentry.h:77
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:90
const std::map< std::string, std::string > & basissets() const
Definition: coordentry.h:245
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:84
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:322
std::shared_ptr< BasisSet > basis
Definition: dx_write.cc:58
double value_
Definition: coordentry.h:102
const std::string & name() const
Definition: coordentry.h:127
Vector3 cross(const Vector3 &) const
Definition: vector3.h:74
virtual double compute()=0
Computes the current value, and returns it.
Definition: coordentry.h:286
std::shared_ptr< CoordValue > z_
Definition: coordentry.h:267
virtual CoordValueType type()=0
The type of variable representation.
void set(double val)
Sets the current value.
Definition: coordentry.h:106
virtual ~CoordValue()
Definition: coordentry.h:74
Definition: coordentry.h:191
void print_in_input_format()
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc: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:104
bool fixed_
Fixed coordinate?
Definition: coordentry.h:60
std::shared_ptr< CoordValue > rval_
Definition: coordentry.h:289
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:317
const std::string & symbol() const
The atomic symbol.
Definition: coordentry.h:228
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:152
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.
friend void save(Archive &ar, const psi::Vector3 &t, unsigned int)
void set_shell(const std::string &name, const std::string &type="BASIS")
Definition: coordentry.cc:136
std::shared_ptr< CoordValue > y_
Definition: coordentry.h:266
std::map< std::string, std::string > shells_
Short string representation of the numerical contents of basis.
Definition: coordentry.h:167
friend void load(Archive &ar, psi::Vector3 &t, unsigned int)
Definition: vector3.h:36
const double & charge() const
The &quot;atomic charge&quot; of the current atom (for SAD purposes).
Definition: coordentry.h:224
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:129
std::map< std::string, double > & geometryVariables_
Definition: coordentry.h:120
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:191
void set_coordinates(double x, double y, double z)
Definition: coordentry.cc:245
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:280
std::shared_ptr< CoordValue > aval_
Definition: coordentry.h:291
virtual ~ZMatrixEntry()
Definition: coordentry.cc:239
NumberValue(double value, bool fixed=false)
Definition: coordentry.h:104
const double & mass() const
The atomic mass of the current atom.
Definition: coordentry.h:226
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:179
std::shared_ptr< CoordEntry > dto_
Definition: coordentry.h:292
void invalidate()
Flag the current value as outdated.
Definition: coordentry.h:92
std::shared_ptr< CoordValue > x_
Definition: coordentry.h:265
const bool & is_ghosted() const
Whether the current atom is ghosted or not.
Definition: coordentry.h:217
const int & entry_number() const
The order in which this appears in the full atom list.
Definition: coordentry.h:232
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:276
const std::string & shell(const std::string &type="BASIS") const
Definition: coordentry.cc:141
int entry_number_
Definition: coordentry.h:144
#define CLEANUP_THRESH
Definition: coordentry.h:41
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:130
const std::string & basisset(const std::string &type="BASIS") const
Definition: coordentry.cc:125
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:42
Definition: coordentry.h:84
const Vector3 & compute()
Definition: coordentry.cc:367
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:212
CoordValue()
Definition: coordentry.h:65
CoordValue(bool fixed)
Definition: coordentry.h:68
VariableValue(const std::string name, std::map< std::string, double > &geometryVariables, bool negate=false, bool fixed=false)
Definition: coordentry.h:123
bool ghosted_
Is this a ghost atom?
Definition: coordentry.h:158
Definition: coordentry.h:117
const std::string name_
Definition: coordentry.h:119
Definition: coordentry.h:136
void set_ghosted(bool ghosted)
Flag the atom as either ghost or real.
Definition: coordentry.h:219
static double r(const Vector3 &a1, const Vector3 &a2)
Computes the distance between two sets of coordinates.
Definition: coordentry.h:170
Definition: coordentry.h:100
Definition: coordentry.h:56
const std::map< std::string, std::string > & shells() const
Definition: coordentry.h:258
void normalize()
Definition: vector3.h:62
void set_mass(double mass)
Definition: coordentry.h:261
bool computed_
Definition: coordentry.h:145
bool computed_
Whether the current value is up to date or not.
Definition: coordentry.h:62
const Vector3 & compute()
Computes the values of the coordinates (in whichever units were inputted), returning them in a Vector...
Definition: coordentry.cc:187
virtual ~CoordEntry()
Definition: coordentry.cc:86
void set_fixed(bool fixed)
Definition: coordentry.h:76
bool is_computed() const
Whether the current atom&#39;s coordinates are up-to-date.
Definition: coordentry.h:208
CoordEntryType
Definition: coordentry.h:191
double compute()
Computes the current value, and returns it.
Definition: coordentry.h:105
double compute()
Computes the current value, and returns it.
Definition: coordentry.cc:64
const std::string & label() const
The atom label.
Definition: coordentry.h:230
void set(double val)
Sets the current value.
Definition: coordentry.h:128
CoordValue(bool fixed, bool computed)
Definition: coordentry.h:71
double charge_
Definition: coordentry.h:150
std::string symbol_
Label of the atom minus any extra info (H1 =&gt; H)
Definition: coordentry.h:154
bool negate_
Definition: coordentry.h:121
std::shared_ptr< CoordEntry > ato_
Definition: coordentry.h:290
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:321
double distance(const Vector3 &) const
Definition: vector3.h:54
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:314
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:166
void set_basisset(const std::string &name, const std::string &type="BASIS")
Definition: coordentry.cc:120
Vector3 coordinates_
Definition: coordentry.h:146
std::shared_ptr< CoordValue > dval_
Definition: coordentry.h:293
void set_coordinates(double x, double y, double z)
Definition: coordentry.cc:199
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:108
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:288
double mass_
Definition: coordentry.h:151
Definition: coordentry.h:264
double norm() const
Definition: vector3.h:143
Definition: coordentry.h:84
bool negated() const
Definition: coordentry.h:126
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:174
CoordEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label="")
Definition: coordentry.cc:71
double Z_
Atomic number of the atom.
Definition: coordentry.h:149
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:107