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 
49 
56 {
57 protected:
59  bool fixed_;
61  bool computed_;
62 public:
63 
64  CoordValue() : fixed_(false), computed_(false)
65  { }
66 
67  CoordValue(bool fixed) : fixed_(fixed), computed_(false)
68  { }
69 
70  CoordValue(bool fixed, bool computed) : fixed_(fixed), computed_(computed)
71  { }
72 
73  virtual ~CoordValue() {}
74 
75  void set_fixed(bool fixed) { fixed_ = fixed; }
76  bool fixed() const { return fixed_; }
77 
85  virtual double compute() =0;
87  virtual void set(double val) =0;
89  virtual CoordValueType type() =0;
91  void invalidate() { computed_ = false; }
93  virtual std::shared_ptr<CoordValue> clone( std::map<std::string, double>& map) =0;
94 };
95 
99 class NumberValue : public CoordValue
100 {
101  double value_;
102 public:
103  NumberValue(double value, bool fixed = false) : CoordValue(fixed, true), value_(value) {}
104  double compute() { return value_; }
105  void set(double val) { if (!fixed_) value_ = val; }
107  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& /*map*/) {
108  return std::shared_ptr<CoordValue>(new NumberValue(value_, fixed_));
109  }
110 };
111 
116 class VariableValue : public CoordValue
117 {
118  const std::string name_;
119  std::map<std::string, double>& geometryVariables_;
120  bool negate_;
121 public:
122  VariableValue(const std::string name, std::map<std::string, double>& geometryVariables, bool negate=false, bool fixed = false)
123  : CoordValue(fixed, true), name_(name), geometryVariables_(geometryVariables), negate_(negate) {}
124  double compute();
125  bool negated() const { return negate_; }
126  const std::string & name() const { return name_; }
127  void set(double val) { if (!fixed_) { geometryVariables_[name_] = negate_ ? -val : val; } }
129  std::shared_ptr<CoordValue> clone(std::map<std::string, double>& map) {
130  return std::shared_ptr<CoordValue>(new VariableValue(name_, map, negate_, fixed_));
131  }
132 };
133 
134 
136 {
137  template<class Archive>
138  friend void save(Archive & ar, const psi::Vector3 & t, unsigned int /*version*/);
139  template<class Archive>
140  friend void load(Archive & ar, psi::Vector3 & t, unsigned int /*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); eBA.normalize(); eBC.normalize();
173  double costheta = eBA.dot(eBC);
174  if(costheta > 1.0 - CLEANUP_THRESH) costheta = 1.0;
175  if(costheta < CLEANUP_THRESH - 1.0) costheta = -1.0;
176  return acos(costheta); }
178  static double d(const Vector3 &a1, const Vector3 &a2, const Vector3 &a3, const Vector3 &a4)
179  { Vector3 eBA(a2-a1), eDC(a4-a3), eCB(a3-a2);
180  double CBNorm = eCB.norm();
181  Vector3 DCxCB(eDC.cross(eCB));
182  Vector3 CBxBA(eCB.cross(eBA));
183  return -atan2(CBNorm * eDC.dot(eCB.cross(eBA)), DCxCB.dot(CBxBA));}
184 public:
191  CoordEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label="");
192  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);
193  virtual ~CoordEntry();
194 
196  virtual const Vector3& compute() =0;
199  virtual void set_coordinates(double x, double y, double z) = 0;
201  virtual CoordEntryType type() =0;
203  virtual void print_in_input_format() = 0;
205  virtual std::string string_in_input_format() = 0;
207  bool is_computed() const { return computed_; }
209  bool is_equivalent_to(const std::shared_ptr<CoordEntry> &other) const;
211  virtual void invalidate() =0;
213  virtual std::shared_ptr<CoordEntry> clone( std::vector<std::shared_ptr<CoordEntry> > &atoms, std::map<std::string, double>& map) =0;
214 
216  const bool& is_ghosted() const { return ghosted_; }
218  void set_ghosted(bool ghosted) { ghosted_ = ghosted; }
219 
221  const double& Z() const;
223  const double& charge() const { return charge_; }
225  const double& mass() const { return mass_; }
227  const std::string& symbol() const { return symbol_; }
229  const std::string& label() const { return label_; }
231  const int& entry_number() const { return entry_number_; }
232 
234  void set_nuclear_charge(double newZ) { Z_ = newZ; }
235 
240  void set_basisset(const std::string& name, const std::string& type="BASIS");
241 
246  const std::string& basisset(const std::string& type="BASIS") const;
247  const std::map<std::string, std::string>& basissets() const { return basissets_;}
248 
253  void set_shell(const std::string& name, const std::string& type="BASIS");
254 
259  const std::string& shell(const std::string& type="BASIS") const;
260  const std::map<std::string, std::string>& shells() const { return shells_;}
261 
262  // Assign the mass of the atom (useful for isotopic substitutions)
263  void set_mass(double mass) { mass_ = mass; }
264 };
265 
266 class CartesianEntry : public CoordEntry{
267  std::shared_ptr<CoordValue> x_;
268  std::shared_ptr<CoordValue> y_;
269  std::shared_ptr<CoordValue> z_;
270 public:
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);
273  CartesianEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
274  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);
275 
276  const Vector3& compute();
277  void set_coordinates(double x, double y, double z);
279  void print_in_input_format();
280  std::string string_in_input_format();
281  void invalidate () { computed_ = false; x_->invalidate(); y_->invalidate(); z_->invalidate(); }
282  std::shared_ptr<CoordEntry> clone( std::vector<std::shared_ptr<CoordEntry> >& /*atoms*/, std::map<std::string, double>& map){
283  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_));
284  return temp;
285  }
286 };
287 
288 class ZMatrixEntry : public CoordEntry
289 {
290  std::shared_ptr<CoordEntry> rto_;
291  std::shared_ptr<CoordValue> rval_;
292  std::shared_ptr<CoordEntry> ato_;
293  std::shared_ptr<CoordValue> aval_;
294  std::shared_ptr<CoordEntry> dto_;
295  std::shared_ptr<CoordValue> dval_;
296 
297 public:
298  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
299  std::shared_ptr<CoordEntry> rto=std::shared_ptr<CoordEntry>(),
300  std::shared_ptr<CoordValue> rval=std::shared_ptr<CoordValue>(),
301  std::shared_ptr<CoordEntry> ato=std::shared_ptr<CoordEntry>(),
302  std::shared_ptr<CoordValue> aval=std::shared_ptr<CoordValue>(),
303  std::shared_ptr<CoordEntry> dto=std::shared_ptr<CoordEntry>(),
304  std::shared_ptr<CoordValue> dval=std::shared_ptr<CoordValue>());
305  ZMatrixEntry(int entry_number, double Z, double charge, double mass, const std::string& symbol, const std::string& label,
306  const std::map<std::string, std::string>& basis,
307  const std::map<std::string, std::string>& shells,
308  std::shared_ptr<CoordEntry> rto=std::shared_ptr<CoordEntry>(),
309  std::shared_ptr<CoordValue> rval=std::shared_ptr<CoordValue>(),
310  std::shared_ptr<CoordEntry> ato=std::shared_ptr<CoordEntry>(),
311  std::shared_ptr<CoordValue> aval=std::shared_ptr<CoordValue>(),
312  std::shared_ptr<CoordEntry> dto=std::shared_ptr<CoordEntry>(),
313  std::shared_ptr<CoordValue> dval=std::shared_ptr<CoordValue>());
314 
315  virtual ~ZMatrixEntry();
316  void invalidate () { computed_ = false; if(rval_ != 0) rval_->invalidate();
317  if(aval_ != 0) aval_->invalidate();
318  if(dval_ != 0) dval_->invalidate(); }
319  const Vector3& compute();
320  void print_in_input_format();
321  std::string string_in_input_format();
322  void set_coordinates(double x, double y, double z);
324  std::shared_ptr<CoordEntry> clone( std::vector<std::shared_ptr<CoordEntry> > &atoms, std::map<std::string, double>& map){
325  std::shared_ptr<CoordEntry> temp;
326  if(rto_ == 0 && ato_ == 0 && dto_ == 0){
327  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_));
328  }else if(ato_ == 0 && dto_ == 0){
329  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_,
330  atoms[rto_->entry_number()], rval_->clone(map)));
331  }else if(dto_ == 0){
332  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_,
333  atoms[rto_->entry_number()], rval_->clone(map),
334  atoms[ato_->entry_number()], aval_->clone(map)));
335  }
336  else {
337  temp = std::shared_ptr<CoordEntry>(new ZMatrixEntry(entry_number_, Z_, charge_, mass_, symbol_, label_, basissets_, shells_,
338  atoms[rto_->entry_number()], rval_->clone(map),
339  atoms[ato_->entry_number()], aval_->clone(map),
340  atoms[dto_->entry_number()], dval_->clone(map)));
341  }
342  return temp;
343  }
344 };
345 
346 }
347 
348 #endif // COORDENTRY_H
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:281
bool fixed() const
Definition: coordentry.h:76
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:91
const std::map< std::string, std::string > & basissets() const
Definition: coordentry.h:247
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:83
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:324
std::shared_ptr< BasisSet > basis
Definition: dx_write.cc:59
double value_
Definition: coordentry.h:101
const std::string & name() const
Definition: coordentry.h:126
Vector3 cross(const Vector3 &) const
Definition: vector3.h:75
virtual double compute()=0
Computes the current value, and returns it.
Definition: coordentry.h:288
std::shared_ptr< CoordValue > z_
Definition: coordentry.h:269
virtual CoordValueType type()=0
The type of variable representation.
void set(double val)
Sets the current value.
Definition: coordentry.h:105
virtual ~CoordValue()
Definition: coordentry.h:73
Definition: coordentry.h:190
void print_in_input_format()
Prints the updated geometry, in the format provided by the user.
Definition: coordentry.cc:279
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:105
bool fixed_
Fixed coordinate?
Definition: coordentry.h:59
std::shared_ptr< CoordValue > rval_
Definition: coordentry.h:291
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:318
const std::string & symbol() const
The atomic symbol.
Definition: coordentry.h:227
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:153
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:137
std::shared_ptr< CoordValue > y_
Definition: coordentry.h:268
std::map< std::string, std::string > shells_
Short string representation of the numerical contents of basis.
Definition: coordentry.h:166
friend void load(Archive &ar, psi::Vector3 &t, unsigned int)
Definition: vector3.h:37
const double & charge() const
The &quot;atomic charge&quot; of the current atom (for SAD purposes).
Definition: coordentry.h:223
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:128
std::map< std::string, double > & geometryVariables_
Definition: coordentry.h:119
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:190
void set_coordinates(double x, double y, double z)
Definition: coordentry.cc:246
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:282
std::shared_ptr< CoordValue > aval_
Definition: coordentry.h:293
virtual ~ZMatrixEntry()
Definition: coordentry.cc:240
NumberValue(double value, bool fixed=false)
Definition: coordentry.h:103
const double & mass() const
The atomic mass of the current atom.
Definition: coordentry.h:225
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:178
std::shared_ptr< CoordEntry > dto_
Definition: coordentry.h:294
void invalidate()
Flag the current value as outdated.
Definition: coordentry.h:91
std::shared_ptr< CoordValue > x_
Definition: coordentry.h:267
const bool & is_ghosted() const
Whether the current atom is ghosted or not.
Definition: coordentry.h:216
const int & entry_number() const
The order in which this appears in the full atom list.
Definition: coordentry.h:231
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:278
const std::string & shell(const std::string &type="BASIS") const
Definition: coordentry.cc:142
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:129
const std::string & basisset(const std::string &type="BASIS") const
Definition: coordentry.cc:126
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:43
Definition: coordentry.h:83
const Vector3 & compute()
Definition: coordentry.cc:368
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:213
CoordValue()
Definition: coordentry.h:64
CoordValue(bool fixed)
Definition: coordentry.h:67
VariableValue(const std::string name, std::map< std::string, double > &geometryVariables, bool negate=false, bool fixed=false)
Definition: coordentry.h:122
void set_nuclear_charge(double newZ)
Set the nuclear charge for this atom (primarily used in ECP calculations to modify Z)...
Definition: coordentry.h:234
bool ghosted_
Is this a ghost atom?
Definition: coordentry.h:157
Definition: coordentry.h:116
const std::string name_
Definition: coordentry.h:118
Definition: coordentry.h:135
void set_ghosted(bool ghosted)
Flag the atom as either ghost or real.
Definition: coordentry.h:218
static double r(const Vector3 &a1, const Vector3 &a2)
Computes the distance between two sets of coordinates.
Definition: coordentry.h:169
Definition: coordentry.h:99
Definition: coordentry.h:55
const std::map< std::string, std::string > & shells() const
Definition: coordentry.h:260
void normalize()
Definition: vector3.h:63
void set_mass(double mass)
Definition: coordentry.h:263
bool computed_
Definition: coordentry.h:144
bool computed_
Whether the current value is up to date or not.
Definition: coordentry.h:61
const Vector3 & compute()
Computes the values of the coordinates (in whichever units were inputted), returning them in a Vector...
Definition: coordentry.cc:188
virtual ~CoordEntry()
Definition: coordentry.cc:87
void set_fixed(bool fixed)
Definition: coordentry.h:75
bool is_computed() const
Whether the current atom&#39;s coordinates are up-to-date.
Definition: coordentry.h:207
CoordEntryType
Definition: coordentry.h:190
double compute()
Computes the current value, and returns it.
Definition: coordentry.h:104
double compute()
Computes the current value, and returns it.
Definition: coordentry.cc:65
const std::string & label() const
The atom label.
Definition: coordentry.h:229
void set(double val)
Sets the current value.
Definition: coordentry.h:127
CoordValue(bool fixed, bool computed)
Definition: coordentry.h:70
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:120
std::shared_ptr< CoordEntry > ato_
Definition: coordentry.h:292
CoordEntryType type()
The type of CoordEntry Specialization.
Definition: coordentry.h:323
double distance(const Vector3 &) const
Definition: vector3.h:55
void invalidate()
Flags the current coordinates as being outdated.
Definition: coordentry.h:316
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:167
void set_basisset(const std::string &name, const std::string &type="BASIS")
Definition: coordentry.cc:121
Vector3 coordinates_
Definition: coordentry.h:145
std::shared_ptr< CoordValue > dval_
Definition: coordentry.h:295
void set_coordinates(double x, double y, double z)
Definition: coordentry.cc:200
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:107
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:290
double mass_
Definition: coordentry.h:150
Definition: coordentry.h:266
double norm() const
Definition: vector3.h:148
Definition: coordentry.h:83
bool negated() const
Definition: coordentry.h:125
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:175
CoordEntry(int entry_number, double Z, double charge, double mass, const std::string &symbol, const std::string &label="")
Definition: coordentry.cc:72
double Z_
Atomic number of the atom.
Definition: coordentry.h:148
CoordValueType type()
The type of variable representation.
Definition: coordentry.h:106