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