Psi4
frag.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 
33 #ifndef _opt_frag_h_
34 #define _opt_frag_h_
35 
36 #include <cstdio>
37 #include <vector>
38 #include <string>
40 #include "print.h"
41 #include "coordinates.h"
42 #include "psi4/psi4-dec.h"
43 
44 namespace opt {
45 
46 class INTERFRAG;
47 using std::vector;
48 
54 class FRAG {
55 
56  protected: // private, except the EFP derived class can access
57  int natom;
58  double *Z;
59  double **geom;
60  double **grad;
61  double *mass;
62  bool **connectivity;
63  bool frozen;
65 
66  public:
67  friend class INTERFRAG;
68 
77  FRAG(int natom_in, double *Z_in, double **geom_in); // use if Z and geom are known
78  FRAG(int natom_in);
79 
80  ~FRAG(); // free memory
81 
85  int g_natom(void) const { return natom; };
86 
87  void set_masses(void);
88 
89  void print_geom(std::string psi_fp, FILE *qc_fp, const int id, bool print_mass = false);
90  void print_geom_grad(std::string psi_fp, FILE *qc_fp, const int id, bool print_mass = false);
91  void print_simples(std::string psi_fp, FILE *qc_fp, int atom_offset=0) const;
92  void print_coords(std::string psi_fp, FILE *qc_fp, int atom_offset=0) const;
93  void print_combinations(std::string psi_fp, FILE *qc_fp) const;
94  void print_intco_dat(std::string psi_fp, FILE *qc_fp, int atom_offset=0) const;
95 
96  std::string get_coord_definition(int coord_index, int atom_offset=0);
97  std::string get_simple_definition(int simple_index, int atom_offset=0);
98 
99  INTCO_TYPE get_simple_type(int simple_index);
100 
102  void update_connectivity_by_bonds(void);
103 
104  void print_connectivity(std::string psi_fp, FILE *qc_fp, const int id, const int offset = 0) const ;
105 
106  // add simple internals based on connectivity; return number added
107  int add_stre_by_connectivity(void);
108  int add_bend_by_connectivity(void);
109  int add_tors_by_connectivity(void);
110  int add_cartesians(void);
111 
113  void add_trivial_coord_combination(int simple_id);
116 
118  int n;
121  n += add_tors_by_connectivity(); // but check bond angles
122  return n;
123  }
124 
125  int add_auxiliary_bonds(void);
126 
127  // add connectivity between two atoms; atom numbers are for fragment
128  void connect(int i, int j) {
129  connectivity[i][j] = connectivity[j][i] = true;
130  }
131 
132  // Compute B matrix for only this fragment
133  double ** compute_B(void) const ;
134 
135  // Compute B matrix. Use prevously allocated memory. Offsets are ideal for molecule.
136  void compute_B(double **B_in, int coord_offset, int atom_offset) const ;
137 
138  // Compute B only for the simple coordinates.
139  //void compute_B_simples(double **B, int coord_offset, int atom_offset) const;
140 
141  void compute_G(double **, bool use_masses=false) const;
142 
143  // Compute B' matrix for one coordinate in given memory with given geometry.
144  void compute_derivative_B(GeomType g, int coord_index, double **Bprime, int atom_offset) const;
145 
146  // Compute B' matrix for one coordinate in given memory with present geometry.
147  void compute_derivative_B(int coord_index, double **Bprime, int atom_offset) const;
148 
149  // Compute B' matrix for one coordinate for fragment.
150  double ** compute_derivative_B(int coord_index) const;
151 
152  // compute and print B matrix (for debugging)
153  void print_B(std::string psi_fp, FILE *qc_fp) const ;
154 
155  // check nearness to 180 and save value
156  void fix_tors_near_180(void);
157 
158  // check nearness to 180 and save value
159  void fix_oofp_near_180(void);
160 
161  // Fix bend axes for consistency during displacments
162  void fix_bend_axes(void);
163  void unfix_bend_axes(void);
164 
165  // check if interior angles of torsion are near 0 or linear
166  //bool check_tors_for_bad_angles(void) const;
167 
168  // return number of intrafragment coordinates
169  int Ncoord(void) const { return coords.index.size(); };
170 
171  // The following 2 functions are only used by the B matrix testing routines.
172  // return natom in definition of coord # coord_index
173  int g_simple_natom(const int coord_index) const {
174  return coords.simples.at(coord_index)->g_natom();
175  }
176 
177  // return atom i in definition of coord # coord_index
178  int g_simple_atom(const int coord_index, const int atom) const {
179  return coords.simples.at(coord_index)->g_atom(atom);
180  }
181 
182  // return array of atomic numbers
183  double *g_Z(void) const;
184  double *g_Z_pointer(void) { return Z; }
185 
186  //print s vectors to output file
187  void print_s(std::string psi_fp, FILE *qc_fp, GeomType geom) const {
188  coords.print_s(psi_fp, qc_fp, geom);
189  return;
190  }
191 
192  // Get all values.
193  double *coord_values(void) const;
194  double *coord_values(GeomType geom) const;
195 
196  // Get one value.
197  double coord_value(int lookup) const;
198  double coord_value(GeomType geom, int lookup) const;
199 
200  // Identify wayward angles
201  std::vector<int> validate_angles(double const * const dq, int atom_offset);
202 
203  // is simple one already present?
204  bool present(const SIMPLE_COORDINATE *one) const;
205 
206  int find(const SIMPLE_COORDINATE *one) const;
207 
208  // displace fragment by dq ; forces and offset are provided for printing
209  void displace(double *dq, double *fq, int atom_offset=0);
210  // utility used by displace
211  bool displace_util(double *dq, bool focus_on_constraints);
212 
213  double ** g_geom_pointer(void) { return geom; }; // returns pointer
214  double ** g_geom(void) const; // returns a copy
215  GeomType g_geom_const_pointer(void) const { return geom;}; // returns const pointer
216 
217  double ** g_grad(void);
218  double ** g_grad_pointer(void) {return grad;};
219 
220  double * g_geom_array(void);
221  double * g_grad_array(void);
222  void set_geom_array(double * geom_array_in);
223  void set_geom(double ** geom_in);
224  void set_grad(double **grad_in);
225 
226  void print_geom(std::string psi_fp, FILE *qc_fp); // write cartesian geometry out for next step
227  void print_geom_irc(std::string psi_fp, FILE *qc_fp); // write cartesian geometry out for next step
228 
229  double ** H_guess(void);
230  // function to help with Lindh guess hessian
231  double Lindh_rho(int A, int B, double RAB) const;
232  // function to help with Lindh guess hessian - original constants
233  double **Lindh_guess(void);
234  bool **g_connectivity(void) const;
235  const bool * const * g_connectivity_pointer(void) const;
236 
237  bool read_coord(std::vector<std::string> & tokens, int first_atom_offset);
238 
239  // return matrix of constraints on coordinates
240  double ** compute_constraints(void) const;
241 
242  // add any missing hydrogen bonds within the fragment
243  // return number added
244  int add_hbonds(void);
245 
247  coords.simples.push_back(i);
248  }
249 
250  double g_mass(int i) { return mass[i]; }
251 
252  // relating to frozen fragments
253  bool is_frozen(void) const { return frozen; }
254  void freeze(void) { frozen = true; }
255  void unfreeze(void) { frozen = false; }
256 
257  // freeze coords within fragments
258  void freeze_coords(void);
259 
263  double *com(GeomType in_geom);
267  double *com(void) { return (com(geom)); }
271  double **inertia_tensor (GeomType in_geom);
275  double **inertia_tensor(void) { return (inertia_tensor(geom)); }
279  int principal_axes(GeomType geom, double **axes, double *evals);
288  int principal_axes(double **axes, double *evals) {
289  return (principal_axes(geom, axes, evals));
290  }
291 
292  // These functions are needed for the forces() function
293  // to apply user-defined equilibrium extra forces.
294  bool coord_has_fixed_eq_val(int coord_index) const {
295  return coords.simples[coord_index]->has_fixed_eq_val();
296  }
297  double coord_fixed_eq_val(int coord_index) const {
298  return coords.simples[coord_index]->fixed_eq_val();
299  }
300  void add_combination_coord(vector<int> ids, vector<double> coeffs); // for molecule_read_coord
301 
309  bool apply_frozen_constraints(std::string R_string, std::string B_string, std::string D_string, std::string C_string);
310 
317  bool apply_fixed_constraints(std::string R_string, std::string B_string, std::string D_string);
318 
319  void erase_combo_coord(int index) { coords.erase_combo(index); } ;
320 
321  /* Are any coordinates present that are not cartesians? */
322  bool is_noncart_present(void) const;
323 
324 };
325 
326 }
327 
328 #endif
void displace(double *dq, double *fq, int atom_offset=0)
Definition: frag_disp.cc:54
double ** Lindh_guess(void)
Definition: lindh_guess.cc:99
void compute_derivative_B(GeomType g, int coord_index, double **Bprime, int atom_offset) const
Definition: frag.cc:685
void print_geom_irc(std::string psi_fp, FILE *qc_fp)
Definition: frag_print.cc:113
int principal_axes(double **axes, double *evals)
Definition: frag.h:288
void fix_tors_near_180(void)
Definition: frag.cc:736
const double *const *const GeomType
Definition: simple_base.h:45
~FRAG()
Definition: frag.cc:84
double ** grad
cartesian coordinates
Definition: frag.h:60
void freeze_coords(void)
Definition: frag.cc:715
std::vector< int > validate_angles(double const *const dq, int atom_offset)
Definition: frag.cc:830
void set_grad(double **grad_in)
Definition: frag.cc:785
int principal_axes(GeomType geom, double **axes, double *evals)
Definition: frag.cc:922
std::string get_coord_definition(int coord_index, int atom_offset=0)
Definition: frag_print.cc:154
int form_natural_coord_combinations(void)
Definition: frag_natural.cc:63
void fix_bend_axes(void)
Definition: frag.cc:743
void add_combination_coord(vector< int > ids, vector< double > coeffs)
Definition: frag.cc:500
INTCO_TYPE
Definition: simple_base.h:43
void print_s(std::string psi_fp, FILE *qc_fp, GeomType geom) const
Definition: combo_coordinates.cc:136
void set_masses(void)
Definition: frag.cc:97
int add_auxiliary_bonds(void)
Definition: frag.cc:226
double ** g_grad(void)
Definition: frag.cc:816
void print_coords(std::string psi_fp, FILE *qc_fp, int atom_offset=0) const
Definition: frag_print.cc:129
int g_simple_atom(const int coord_index, const int atom) const
Definition: frag.h:178
void freeze(void)
Definition: frag.h:254
void add_trivial_coord_combination(int simple_id)
Definition: frag.cc:505
int g_simple_natom(const int coord_index) const
Definition: frag.h:173
double * g_geom_array(void)
Definition: frag.cc:798
void unfix_bend_axes(void)
Definition: frag.cc:757
double ** compute_B(void) const
Definition: frag.cc:678
void set_geom_array(double *geom_array_in)
Definition: frag.cc:772
bool coord_has_fixed_eq_val(int coord_index) const
Definition: frag.h:294
INTCO_TYPE get_simple_type(int simple_index)
Definition: frag.cc:947
int natom
number of atoms in fragment
Definition: frag.h:57
double * g_Z_pointer(void)
Definition: frag.h:184
double ** g_geom(void) const
Definition: frag.cc:793
Definition: pointgrp.h:106
double * g_Z(void) const
Definition: frag.cc:821
void compute_G(double **, bool use_masses=false) const
Definition: frag.cc:721
Definition: simple_base.h:47
double ** inertia_tensor(void)
Definition: frag.h:275
void print_combinations(std::string psi_fp, FILE *qc_fp) const
Definition: frag_print.cc:136
double ** g_grad_pointer(void)
Definition: frag.h:218
A group of atoms, its geometry, and its internal coordinates.
Definition: frag.h:54
bool ** connectivity
connectivity matrix
Definition: frag.h:62
Definition: combo_coordinates.h:45
void fix_oofp_near_180(void)
Definition: frag.cc:766
int form_trivial_coord_combinations(void)
Definition: frag.cc:515
void simple_add(SIMPLE_COORDINATE *i)
Definition: frag.h:246
double coord_fixed_eq_val(int coord_index) const
Definition: frag.h:297
void print_connectivity(std::string psi_fp, FILE *qc_fp, const int id, const int offset=0) const
Definition: frag_print.cc:178
bool ** g_connectivity(void) const
Definition: frag.cc:873
bool is_noncart_present(void) const
Definition: frag.cc:610
void set_geom(double **geom_in)
Definition: frag.cc:779
int form_delocalized_coord_combinations(void)
Definition: frag.cc:523
void update_connectivity_by_bonds(void)
Definition: frag.cc:133
vector< SIMPLE_COORDINATE * > simples
Definition: combo_coordinates.h:49
void print_intco_dat(std::string psi_fp, FILE *qc_fp, int atom_offset=0) const
Definition: frag_print.cc:168
double ** g_geom_pointer(void)
Definition: frag.h:213
int add_simples_by_connectivity(void)
Definition: frag.h:117
int add_cartesians(void)
Definition: frag.cc:590
int add_hbonds(void)
Definition: frag.cc:171
double coord_value(int lookup) const
Definition: frag.cc:639
double * com(void)
Definition: frag.h:267
void print_simples(std::string psi_fp, FILE *qc_fp, int atom_offset=0) const
Definition: frag_print.cc:121
void update_connectivity_by_distances(void)
Definition: frag.cc:106
int add_tors_by_connectivity(void)
Definition: frag.cc:360
std::string get_simple_definition(int simple_index, int atom_offset=0)
Definition: frag_print.cc:163
double ** H_guess(void)
Definition: frag_H_guess.cc:119
int Ncoord(void) const
Definition: frag.h:169
bool present(const SIMPLE_COORDINATE *one) const
Definition: frag.cc:492
COMBO_COORDINATES coords
simple or linear combinations of simple coordinates
Definition: frag.h:64
int find(const SIMPLE_COORDINATE *one) const
Definition: frag.cc:622
void print_geom_grad(std::string psi_fp, FILE *qc_fp, const int id, bool print_mass=false)
Definition: frag_print.cc:73
void print_B(std::string psi_fp, FILE *qc_fp) const
Definition: frag_print.cc:191
bool apply_frozen_constraints(std::string R_string, std::string B_string, std::string D_string, std::string C_string)
Definition: frag_apply_frozen_constraints.cc:81
double * Z
atomic numbers
Definition: frag.h:58
bool is_frozen(void) const
Definition: frag.h:253
double g_mass(int i)
Definition: frag.h:250
GeomType g_geom_const_pointer(void) const
Definition: frag.h:215
void connect(int i, int j)
Definition: frag.h:128
double * g_grad_array(void)
Definition: frag.cc:807
int g_natom(void) const
Definition: frag.h:85
void erase_combo(int cc)
Definition: combo_coordinates.cc:128
double ** geom
cartesian coordinates
Definition: frag.h:59
bool apply_fixed_constraints(std::string R_string, std::string B_string, std::string D_string)
Definition: frag_apply_frozen_constraints.cc:215
void print_s(std::string psi_fp, FILE *qc_fp, GeomType geom) const
Definition: frag.h:187
void print_geom(std::string psi_fp, FILE *qc_fp, const int id, bool print_mass=false)
Definition: frag_print.cc:57
double * coord_values(void) const
Definition: frag.cc:631
Header for coordinate classes (simple and combination).
vector< vector< int > > index
Definition: combo_coordinates.h:50
int add_stre_by_connectivity(void)
Definition: frag.cc:149
double ** compute_constraints(void) const
Definition: frag.cc:704
Definition: interfrag.h:69
FRAG(int natom_in, double *Z_in, double **geom_in)
Definition: frag.cc:60
bool frozen
whether to optimize
Definition: frag.h:63
bool displace_util(double *dq, bool focus_on_constraints)
Definition: frag_disp.cc:213
bool read_coord(std::vector< std::string > &tokens, int first_atom_offset)
Definition: molecule_read_coords.cc:417
int add_bend_by_connectivity(void)
Definition: frag.cc:280
double * mass
nuclear masses
Definition: frag.h:61
void erase_combo_coord(int index)
Definition: frag.h:319
void unfreeze(void)
Definition: frag.h:255
const bool *const * g_connectivity_pointer(void) const
Definition: frag.cc:881
double Lindh_rho(int A, int B, double RAB) const
Definition: frag_H_guess.cc:102