Psi4
libmints/molecule.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-2018 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 _psi_src_lib_libmints_molecule_h_
30 #define _psi_src_lib_libmints_molecule_h_
31 
32 #include <vector>
33 #include <string>
34 #include <cstdio>
35 #include <map>
36 #include <memory>
37 
38 #define LINEAR_A_TOL 1.0E-2 // When sin(a) is below this, we consider the angle to be linear
39 #define DEFAULT_SYM_TOL 1.0E-8
40 #define FULL_PG_TOL 1.0e-8 // default
41 
42 #include "typedefs.h"
43 #include "coordentry.h"
44 
45 namespace psi {
46 class PointGroup;
47 class BasisSet;
66 };
67 
68 const std::string RotorTypeList[] = {"ASYMMETRIC_TOP", "SYMMETRIC_TOP", "SPHERICAL_TOP", "LINEAR", "ATOM"};
69 
70 const std::string FullPointGroupList[] = {"ATOM", "C_inf_v", "D_inf_h", "C1", "Cs", "Ci", "Cn", "Cnv",
71  "Cnh", "Sn", "Dn", "Dnd", "Dnh", "Td", "Oh", "Ih"};
72 
78  public:
85  };
89  enum GeometryUnits { Angstrom, Bohr };
93  enum FragmentType {
95  Real,
96  Ghost
97  };
98 
99  typedef std::vector<std::shared_ptr<CoordEntry>> EntryVector;
100  typedef EntryVector::iterator EntryVectorIter;
101 
102  protected:
104  std::string name_;
110  std::vector<int> fragment_charges_;
112  std::vector<int> fragment_multiplicities_;
113 
118 
128  std::vector<std::string> all_variables_;
130  void clear();
131 
138  CoordValue* get_coord_value(const std::string& str);
139 
147  int get_anchor_atom(const std::string& str, const std::string& line);
148 
150  std::shared_ptr<PointGroup> pg_;
155 
157  int nunique_;
159  int* nequiv_;
161  int** equiv_;
164 
166  std::map<std::string, double> geometry_variables_;
168  std::vector<FragmentType> fragment_types_;
170  std::vector<std::pair<int, int>> fragments_;
172  std::string symmetry_from_input_;
180  bool zmat_;
182  bool cart_;
183 
184  public:
185  Molecule();
187  Molecule(const Molecule& other);
188  virtual ~Molecule();
189 
190  Molecule clone(void) {
191  Molecule new_obj(*this);
192  return new_obj;
193  }
194 
198  Molecule& operator=(const Molecule& other);
200 
213  void add_atom(double Z, double x, double y, double z, std::string sym = "", double mass = 0.0, double charge = 0.0,
214  std::string lbl = "", int A = -1);
215  void add_unsettled_atom(double Z, std::vector<std::string> anchor, std::string sym = "", double mass = 0.0,
216  double charge = 0.0, std::string lbl = "", int A = -1);
217 
219  int nfragments() const { return fragments_.size(); }
221  int nactive_fragments();
223  void set_lock_frame(bool tf) { lock_frame_ = tf; }
224 
226  const std::string name() const { return name_; }
228  const std::string& basis_on_atom(int atom) const;
230  void set_name(const std::string& _name) { name_ = _name; }
232  int natom() const;
234  int nallatom() const { return full_atoms_.size(); }
236  const double& Z(int atom) const;
238  double fZ(int atom) const;
240  double x(int atom) const;
242  double y(int atom) const;
244  double z(int atom) const;
246  double fx(int atom) const;
248  double fy(int atom) const;
250  double fz(int atom) const;
252  Vector3 xyz(int atom) const;
253  Vector3 fxyz(int atom) const;
255  double xyz(int atom, int _xyz) const;
257  double mass(int atom) const;
258 
260  void set_mass(int atom, double mass);
262  void set_nuclear_charge(int atom, double newZ);
263 
265  std::string symbol(int atom) const;
267  std::string fsymbol(int atom) const;
269  std::string label(int atom) const;
271  double charge(int atom) const;
273  int mass_number(int atom) const;
275  int true_atomic_number(int atom) const;
276  int ftrue_atomic_number(int atom) const;
278  double fmass(int atom) const;
280  std::string flabel(int atom) const;
282  double fcharge(int atom) const;
284  int fmass_number(int atom) const;
286  const std::shared_ptr<CoordEntry>& atom_entry(int atom) const;
287 
288  void set_basis_all_atoms(const std::string& name, const std::string& type = "BASIS");
289  void set_basis_by_symbol(const std::string& symbol, const std::string& name, const std::string& type = "BASIS");
290  void set_basis_by_number(int number, const std::string& name, const std::string& type = "BASIS");
291  void set_basis_by_label(const std::string& label, const std::string& name, const std::string& type = "BASIS");
292  void set_shell_by_label(const std::string& label, const std::string& name, const std::string& type = "BASIS");
293 
296  int atom_at_position1(double*, double tol = 0.05) const;
297  int atom_at_position2(Vector3&, double tol = 0.05) const;
298  int atom_at_position3(const std::array<double, 3>&, const double tol = 0.05) const;
300 
302  void set_reinterpret_coordentry(bool rc);
303 
305  Matrix geometry() const;
307  Matrix full_geometry() const;
308 
313  void set_geometry(double** geom);
314 
318  void set_geometry(const Matrix& geom);
319 
323  void set_full_geometry(double** geom);
324 
328  void set_full_geometry(const Matrix& geom);
329 
333  void rotate(const Matrix& R);
334  void rotate_full(const Matrix& R);
335 
339  void reinterpret_coordentries();
340 
344  void reinterpret_fragments();
345 
350  void symmetrize_to_abelian_group(double tol);
351 
353  Vector3 center_of_mass() const;
356  double nuclear_repulsion_energy(const std::array<double, 3>& dipole_field) const;
358  Vector3 nuclear_dipole() const;
360  Vector3 nuclear_dipole(const Vector3& origin) const;
363  Matrix nuclear_repulsion_energy_deriv1(const std::array<double, 3>& dipole_field) const;
365  Matrix nuclear_repulsion_energy_deriv2() const;
366 
368  double pairwise_nuclear_repulsion_energy(std::shared_ptr<Molecule> other) const;
369 
371  void translate(const Vector3& r);
373  void move_to_com();
379  // void reorient();
380 
382  Matrix distance_matrix() const;
383 
385  Matrix* inertia_tensor() const;
386 
388  Vector rotational_constants(double tol = FULL_PG_TOL) const;
389 
391  void print_rotational_constants(void) const;
393  RotorType rotor_type(double tol = FULL_PG_TOL) const;
394 
396  void print() const;
397 
399  void print_cluster() const;
400 
402  void print_full() const;
403 
405  void print_in_input_format() const;
406 
408  void print_in_bohr() const;
409 
411  void print_in_angstrom() const;
412 
414  void print_distances() const;
415  void print_bond_angles() const;
416  void print_dihedrals() const;
417  void print_out_of_planes() const;
418 
420  void save_xyz_file(const std::string& filename, bool save_ghosts = true) const;
422  std::string save_string_xyz_file() const;
423 
425  std::string save_string_xyz() const;
426 
432  int nunique() const { return nunique_; }
434  int unique(int iuniq) const { return equiv_[iuniq][0]; }
436  int nequivalent(int iuniq) const { return nequiv_[iuniq]; }
438  int equivalent(int iuniq, int j) const { return equiv_[iuniq][j]; }
441  int atom_to_unique(int iatom) const { return atom_to_unique_[iatom]; }
444  int atom_to_unique_offset(int iatom) const;
446  int max_nequivalent() const;
448 
452  bool has_symmetry_element(Vector3& op, double tol = DEFAULT_SYM_TOL) const;
453  std::shared_ptr<PointGroup> point_group() const;
454  void set_point_group(std::shared_ptr<PointGroup> pg);
456  void set_full_point_group(double tol = FULL_PG_TOL);
458  bool has_inversion(Vector3& origin, double tol = DEFAULT_SYM_TOL) const;
460  bool is_plane(Vector3& origin, Vector3& uperp, double tol = DEFAULT_SYM_TOL) const;
462  bool is_axis(Vector3& origin, Vector3& axis, int order, double tol = DEFAULT_SYM_TOL) const;
464  void is_linear_planar(bool& linear, bool& planar, double tol = DEFAULT_SYM_TOL) const;
466  std::shared_ptr<PointGroup> find_point_group(double tol = DEFAULT_SYM_TOL) const;
468  void reset_point_group(const std::string& pgname);
470  std::shared_ptr<PointGroup> find_highest_point_group(double tol = DEFAULT_SYM_TOL) const;
473  std::shared_ptr<Matrix> symmetry_frame(double tol = DEFAULT_SYM_TOL);
475  void release_symmetry_information();
478  void form_symmetry_information(double tol = DEFAULT_SYM_TOL);
480  std::string sym_label();
482  std::vector<std::string> irrep_labels();
483  const std::string& symmetry_from_input() const { return symmetry_from_input_; }
484 
489  void symmetrize(double tol = 0.05, bool suppress_mol_print_in_exc = false);
491 
498  std::string create_psi4_string_from_molecule() const;
499 
503  void activate_all_fragments();
504 
508  void deactivate_all_fragments();
509 
514  void set_active_fragments(std::vector<int> reals);
515 
520  void set_active_fragment(int fragment);
521 
526  void set_ghost_fragments(std::vector<int> ghosts);
527 
532  void set_ghost_fragment(int fragment);
533 
541  std::shared_ptr<Molecule> extract_subsets(const std::vector<int>& real_list,
542  const std::vector<int>& ghost_list) const;
543 
550  std::shared_ptr<Molecule> py_extract_subsets_1(std::vector<int> reals, std::vector<int> ghost);
551 
558  std::shared_ptr<Molecule> py_extract_subsets_2(std::vector<int> reals, int ghost = -1);
559 
566  std::shared_ptr<Molecule> py_extract_subsets_3(int reals, std::vector<int> ghost);
567 
574  std::shared_ptr<Molecule> py_extract_subsets_4(int reals, int ghost = -1);
575 
581  std::shared_ptr<Molecule> py_extract_subsets_5(std::vector<int> reals);
582 
588  std::shared_ptr<Molecule> py_extract_subsets_6(int reals);
589 
590  // => Fragment Composition <= //
591 
594  const std::vector<std::pair<int, int>>& get_fragments() const { return fragments_; }
596  const std::vector<FragmentType>& get_fragment_types() const { return fragment_types_; }
598  const std::vector<int>& get_fragment_charges() const { return fragment_charges_; }
600  const std::vector<int>& get_fragment_multiplicities() const { return fragment_multiplicities_; }
602  void set_fragment_pattern(const std::vector<std::pair<int, int>>, const std::vector<FragmentType>,
603  const std::vector<int>, const std::vector<int>);
604 
606  void set_has_cartesian(bool tf) { cart_ = tf; }
608  void set_has_zmatrix(bool tf) { zmat_ = tf; }
610  bool has_zmatrix() const { return zmat_; }
613  void set_variable(const std::string& str, double val);
615  void set_geometry_variable(const std::string& str, double val) { geometry_variables_[str] = val; }
618  double get_variable(const std::string& str);
621  bool is_variable(const std::string& str) const;
622 
624  void set_molecular_charge(int charge) { molecular_charge_ = charge; }
626  int molecular_charge() const { return molecular_charge_; }
628  void set_multiplicity(int mult) { multiplicity_ = mult; }
630  int multiplicity() const { return multiplicity_; }
631 
633  void set_units(GeometryUnits units);
635  GeometryUnits units() const { return units_; }
638  void set_input_units_to_au(double conv);
640  double input_units_to_au() const { return input_units_to_au_; }
642  bool orientation_fixed() const { return fix_orientation_; }
644  void set_orientation_fixed(bool fix = true) { fix_orientation_ = fix; }
646  bool com_fixed() const { return !move_to_com_; }
648  void set_com_fixed(bool fix = true) { move_to_com_ = !fix; }
650  std::string schoenflies_symbol() const;
652  bool valid_atom_map(double tol = 0.05) const;
654  std::string full_point_group() const;
656  std::string full_point_group_with_n() const { return FullPointGroupList[full_pg_]; }
658  int full_pg_n() { return full_pg_n_; }
661  int rotational_symmetry_number() const;
662 
667  void update_geometry();
668 };
669 
670 } // namespace psi
671 
672 #endif
int multiplicity() const
Get the multiplicity (defined as 2Ms + 1)
Definition: libmints/molecule.h:630
Definition: libmints/molecule.h:59
int ** equiv_
Equivalent atom mapping array.
Definition: libmints/molecule.h:161
Molecule clone(void)
Definition: libmints/molecule.h:190
bool reinterpret_coordentries_
Definition: libmints/molecule.h:175
Definition: libmints/molecule.h:53
Definition: libmints/molecule.h:55
const std::string & symmetry_from_input() const
Definition: libmints/molecule.h:483
Definition: libmints/molecule.h:64
Definition: libmints/molecule.h:63
const std::vector< std::pair< int, int > > & get_fragments() const
Definition: libmints/molecule.h:594
Definition: libmints/molecule.h:48
std::string symmetry_from_input_
Symmetry string from geometry specification.
Definition: libmints/molecule.h:172
int molecular_charge() const
Gets the molecular charge.
Definition: libmints/molecule.h:626
Definition: manybody.h:66
bool fix_orientation_
Reorient or not?
Definition: libmints/molecule.h:115
const std::vector< FragmentType > & get_fragment_types() const
A list describing how to handle each fragment.
Definition: libmints/molecule.h:596
Definition: libmints/molecule.h:83
#define FULL_PG_TOL
Definition: libmints/molecule.h:40
FragmentType
Definition: libmints/molecule.h:93
void set_has_cartesian(bool tf)
Sets whether this molecule contains at least one cartesian entry.
Definition: libmints/molecule.h:606
void set_name(const std::string &_name)
Set molecule name.
Definition: libmints/molecule.h:230
std::vector< std::shared_ptr< CoordEntry > > EntryVector
Definition: libmints/molecule.h:99
Definition: libmints/molecule.h:60
Definition: libmints/molecule.h:54
EntryVector::iterator EntryVectorIter
Definition: libmints/molecule.h:100
double input_units_to_au() const
Gets the geometry unit conversion.
Definition: libmints/molecule.h:640
Definition: libmints/molecule.h:48
const std::vector< int > & get_fragment_charges() const
The charge of each fragment.
Definition: libmints/molecule.h:598
int molecular_charge_
The molecular charge.
Definition: libmints/molecule.h:120
int nunique_
Number of unique atoms.
Definition: libmints/molecule.h:157
Definition: vector3.h:38
RotorType
Definition: libmints/molecule.h:48
const std::string RotorTypeList[]
Definition: libmints/molecule.h:68
GeometryUnits units_
The units used to define the geometry.
Definition: libmints/molecule.h:124
std::vector< FragmentType > fragment_types_
A list describing how to handle each fragment.
Definition: libmints/molecule.h:168
Definition: libmints/molecule.h:51
std::vector< std::pair< int, int > > fragments_
The list of atom ranges defining each fragment from parent molecule.
Definition: libmints/molecule.h:170
std::map< std::string, double > geometry_variables_
A listing of the variables used to define the geometries.
Definition: libmints/molecule.h:166
Definition: libmints/molecule.h:57
int nequivalent(int iuniq) const
Returns the number of atoms equivalent to iuniq.
Definition: libmints/molecule.h:436
int equivalent(int iuniq, int j) const
Returns the j&#39;th atom equivalent to iuniq.
Definition: libmints/molecule.h:438
std::shared_ptr< PointGroup > pg_
Point group to use with this molecule.
Definition: libmints/molecule.h:150
void set_lock_frame(bool tf)
Set whether to leave the geometry alone upon update_geometry()
Definition: libmints/molecule.h:223
int full_pg_n()
Return n in Cnv, etc.; If there is no n (e.g. Td) it&#39;s the highest-order rotation axis...
Definition: libmints/molecule.h:658
std::vector< int > fragment_multiplicities_
The multiplicity of each fragment.
Definition: libmints/molecule.h:112
Definition: libmints/molecule.h:50
Definition: gshell.h:42
GeometryFormat
Definition: libmints/molecule.h:82
const std::string name() const
Get molecule name.
Definition: libmints/molecule.h:226
int multiplicity_
The multiplicity (defined as 2Ms + 1)
Definition: libmints/molecule.h:122
const std::string FullPointGroupList[]
Definition: libmints/molecule.h:70
std::string full_point_group_with_n() const
Return point group name such as Cnv or Sn.
Definition: libmints/molecule.h:656
bool lock_frame_
Definition: libmints/molecule.h:178
Definition: libmints/molecule.h:62
int nfragments() const
The number of fragments in the molecule.
Definition: libmints/molecule.h:219
bool has_zmatrix() const
Whether this molecule has at least one zmatrix entry.
Definition: libmints/molecule.h:610
bool com_fixed() const
Get whether or not COM is fixed.
Definition: libmints/molecule.h:646
int full_pg_n_
n of the highest rotational axis Cn
Definition: libmints/molecule.h:154
Definition: libmints/molecule.h:58
EntryVector full_atoms_
Atom info vector (includes dummy atoms)
Definition: libmints/molecule.h:108
Definition: libmints/molecule.h:48
int nunique() const
Definition: libmints/molecule.h:432
Makes using matrices just a little easier.
Definition: libmints/matrix.h:59
FullPointGroup full_pg_
Full point group.
Definition: libmints/molecule.h:152
int atom_to_unique(int iatom) const
Definition: libmints/molecule.h:441
bool orientation_fixed() const
Get whether or not orientation is fixed.
Definition: libmints/molecule.h:642
void set_geometry_variable(const std::string &str, double val)
Plain assigns the vlue val to the variable labeled string in the list of geometry variables...
Definition: libmints/molecule.h:615
Definition: coordentry.h:54
Definition: libmints/molecule.h:48
int * nequiv_
Number of equivalent atoms per unique atom (length nunique_)
Definition: libmints/molecule.h:159
#define DEFAULT_SYM_TOL
Definition: libmints/molecule.h:39
Definition: libmints/molecule.h:48
void set_com_fixed(bool fix=true)
Fix the center of mass at its current frame.
Definition: libmints/molecule.h:648
Definition: libmints/molecule.h:94
FullPointGroup
Definition: libmints/molecule.h:49
void set_orientation_fixed(bool fix=true)
Fix the orientation at its current frame.
Definition: libmints/molecule.h:644
#define PSI_API
Definition: pragma.h:155
bool zmat_
Whether this molecule has at least one zmatrix entry.
Definition: libmints/molecule.h:180
const std::vector< int > & get_fragment_multiplicities() const
The multiplicity of each fragment.
Definition: libmints/molecule.h:600
bool cart_
Whether this molecule has at least one cartesian entry.
Definition: libmints/molecule.h:182
std::vector< int > fragment_charges_
The charge of each fragment.
Definition: libmints/molecule.h:110
std::string name_
Molecule (or fragment) name.
Definition: libmints/molecule.h:104
void set_molecular_charge(int charge)
Sets the molecular charge.
Definition: libmints/molecule.h:624
EntryVector atoms_
Atom info vector (no knowledge of dummy atoms)
Definition: libmints/molecule.h:106
Definition: libmints/molecule.h:52
int unique(int iuniq) const
Returns the overall number of the iuniq&#39;th unique atom.
Definition: libmints/molecule.h:434
Molecule information class.
Definition: libmints/molecule.h:77
double input_units_to_au_
The conversion factor to take input units to Bohr.
Definition: libmints/molecule.h:126
Definition: libmints/molecule.h:65
Definition: libmints/molecule.h:95
void set_multiplicity(int mult)
Sets the multiplicity (defined as 2Ms + 1)
Definition: libmints/molecule.h:628
GeometryUnits units() const
Gets the geometry units.
Definition: libmints/molecule.h:635
Definition: libmints/molecule.h:61
int nallatom() const
Number of all atoms (includes dummies)
Definition: libmints/molecule.h:234
std::vector< std::string > all_variables_
A list of all variables known, whether they have been set or not.
Definition: libmints/molecule.h:128
Definition: vector.h:48
void set_has_zmatrix(bool tf)
Sets whether this molecule contains at least one zmatrix entry.
Definition: libmints/molecule.h:608
GeometryUnits
Definition: libmints/molecule.h:89
int * atom_to_unique_
Atom to unique atom mapping array (length natom)
Definition: libmints/molecule.h:163
Definition: libmints/molecule.h:56
bool move_to_com_
Move to center of mass or not?
Definition: libmints/molecule.h:117