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;
51 
52 const std::string RotorTypeList[] = {"ASYMMETRIC_TOP", "SYMMETRIC_TOP",
53  "SPHERICAL_TOP", "LINEAR", "ATOM"};
54 
55 const std::string FullPointGroupList[] = {"ATOM", "C_inf_v", "D_inf_h", "C1", "Cs", "Ci", "Cn", "Cnv",
56  "Cnh", "Sn", "Dn", "Dnd", "Dnh", "Td", "Oh", "Ih"};
57 
63 {
64 public:
71  };
75  enum GeometryUnits {Angstrom, Bohr};
79  enum FragmentType {
81  Real,
82  Ghost
83  };
84 
86  QMatom = 1,
87  EFPatom = 2,
88  ALLatom = 3
89  };
90 
91  typedef std::vector<std::shared_ptr<CoordEntry> > EntryVector;
92  typedef EntryVector::iterator EntryVectorIter;
93 
94 protected:
96  std::string name_;
102  std::vector<int> fragment_charges_;
104  std::vector<int> fragment_multiplicities_;
105 
110 
124  std::vector<std::string> all_variables_;
126  void clear();
127 
134  CoordValue* get_coord_value(const std::string &str);
135 
143  int get_anchor_atom(const std::string &str, const std::string &line);
144 
146  std::shared_ptr<PointGroup> pg_;
151 
153  int nunique_;
155  int *nequiv_;
157  int **equiv_;
160 
162  std::map<std::string, double> geometry_variables_;
164  std::vector<FragmentType> fragment_types_;
166  std::vector<std::pair<int, int> > fragments_;
168  std::string symmetry_from_input_;
175  bool zmat_;
177  bool cart_;
178 
179 public:
180 
181  Molecule();
183  Molecule(const Molecule& other);
184  virtual ~Molecule();
185 
186  Molecule clone(void) {
187  Molecule new_obj(*this);
188  return new_obj;
189  }
190 
194  Molecule& operator=(const Molecule& other);
196 
197 
202  void init_with_xyz(const std::string& xyzfilename);
203 
216  void add_atom(double Z, double x, double y, double z, std::string sym = "", double mass = 0.0,
217  double charge = 0.0, std::string lbl = "", int A = -1);
218  void add_unsettled_atom(double Z, std::vector<std::string> anchor, std::string sym = "", double mass = 0.0,
219  double charge = 0.0, std::string lbl = "", int A = -1);
220 
222  bool multiplicity_specified() const { return multiplicity_specified_; } // TODO remove
224  bool charge_specified() const { return charge_specified_; } // TODO remove
226  int nfragments() const { return fragments_.size();}
228  int nactive_fragments();
230  // Needed for EFP interface
231  std::pair<int, int> fragment_atom_pair(int f) { return fragments_[f]; } // TODO remove?
233  void set_lock_frame(bool tf) { lock_frame_ = tf; }
234 
236  const std::string name() const {return name_; }
238  const std::string& basis_on_atom(int atom) const;
240  void set_name(const std::string &_name) { name_ = _name; }
242  int natom() const;
244  int nallatom() const { return full_atoms_.size(); }
246  const double& Z(int atom) const;
248  double fZ(int atom) const;
250  double x(int atom) const;
252  double y(int atom) const;
254  double z(int atom) const;
256  double fx(int atom) const;
258  double fy(int atom) const;
260  double fz(int atom) const;
262  Vector3 xyz(int atom) const;
263  Vector3 fxyz(int atom) const;
265  double xyz(int atom, int _xyz) const;
267  double mass(int atom) const;
268 
270  void set_mass(int atom, double mass);
272  void set_nuclear_charge(int atom, double newZ);
273 
275  std::string symbol(int atom) const;
277  std::string fsymbol(int atom) const;
279  std::string label(int atom) const;
281  double charge(int atom) const;
283  int mass_number(int atom) const;
285  int true_atomic_number(int atom) const;
286  int ftrue_atomic_number(int atom) const;
288  double fmass(int atom) const;
290  std::string flabel(int atom) const;
292  double fcharge(int atom) const;
294  int fmass_number(int atom) const;
296  const std::shared_ptr<CoordEntry>& atom_entry(int atom) const;
297 
298  void set_basis_all_atoms(const std::string& name, const std::string& type="BASIS");
299  void set_basis_by_symbol(const std::string& symbol, const std::string& name, const std::string& type="BASIS");
300  void set_basis_by_number(int number, const std::string& name, const std::string& type="BASIS");
301  void set_basis_by_label(const std::string& label, const std::string& name, const std::string& type="BASIS");
302  void set_shell_by_label(const std::string& label, const std::string& name, const std::string& type="BASIS");
303 
306  int atom_at_position1(double *, double tol = 0.05) const;
307  int atom_at_position2(Vector3&, double tol = 0.05) const;
309 
311  void set_reinterpret_coordentry(bool rc);
312 
314  Matrix geometry() const;
316  Matrix full_geometry() const;
317 
322  void set_geometry(double** geom);
323 
327  void set_geometry(const Matrix& geom);
328 
332  void set_full_geometry(double** geom);
333 
337  void set_full_geometry(const Matrix& geom);
338 
342  void rotate(const Matrix& R);
343  void rotate_full(const Matrix& R);
344 
348  void reinterpret_coordentries();
349 
353  void reinterpret_fragments();
354 
359  void symmetrize_to_abelian_group(double tol);
360 
362  Vector3 center_of_mass() const;
365  double nuclear_repulsion_energy(const std::array<double,3> &dipole_field) const;
367  Vector3 nuclear_dipole() const;
369  Vector3 nuclear_dipole(const Vector3 &origin) const;
372  Matrix nuclear_repulsion_energy_deriv1(const std::array<double, 3> &dipole_field) const;
374  Matrix nuclear_repulsion_energy_deriv2() const;
375 
377  double pairwise_nuclear_repulsion_energy(std::shared_ptr<Molecule> other) const;
378 
380  void translate(const Vector3& r);
382  void move_to_com();
388 // void reorient();
389 
391  Matrix distance_matrix() const;
392 
394  Matrix* inertia_tensor() const;
395 
397  Vector rotational_constants(double tol = FULL_PG_TOL) const;
398 
400  void print_rotational_constants(void) const;
402  RotorType rotor_type(double tol = FULL_PG_TOL) const;
403 
405  void print() const;
406 
408  void print_cluster() const;
409 
411  void print_full() const;
412 
414  void print_in_input_format() const;
415 
417  void print_in_bohr() const;
418 
420  void print_in_angstrom() const;
421 
423  void print_distances() const;
424  void print_bond_angles() const;
425  void print_dihedrals() const;
426  void print_out_of_planes() const;
427 
429  void save_xyz_file(const std::string & filename, bool save_ghosts = true) const;
431  std::string save_string_xyz_file() const;
432 
434  std::string save_string_xyz() const;
435 
441  int nunique() const { return nunique_; }
443  int unique(int iuniq) const { return equiv_[iuniq][0]; }
445  int nequivalent(int iuniq) const { return nequiv_[iuniq]; }
447  int equivalent(int iuniq, int j) const { return equiv_[iuniq][j]; }
450  int atom_to_unique(int iatom) const { return atom_to_unique_[iatom]; }
453  int atom_to_unique_offset(int iatom) const;
455  int max_nequivalent() const;
457 
461  bool has_symmetry_element(Vector3& op, double tol = DEFAULT_SYM_TOL) const;
462  std::shared_ptr<PointGroup> point_group() const;
463  void set_point_group(std::shared_ptr<PointGroup> pg);
465  void set_full_point_group(double tol = FULL_PG_TOL);
467  bool has_inversion(Vector3& origin, double tol = DEFAULT_SYM_TOL) const;
469  bool is_plane(Vector3& origin, Vector3& uperp, double tol = DEFAULT_SYM_TOL) const;
471  bool is_axis(Vector3& origin, Vector3& axis, int order, double tol = DEFAULT_SYM_TOL) const;
473  void is_linear_planar(bool& linear, bool& planar, double tol = DEFAULT_SYM_TOL) const;
475  std::shared_ptr<PointGroup> find_point_group(double tol = DEFAULT_SYM_TOL) const;
477  void reset_point_group(const std::string& pgname);
479  std::shared_ptr<PointGroup> find_highest_point_group(double tol = DEFAULT_SYM_TOL) const;
482  std::shared_ptr<Matrix> symmetry_frame(double tol = DEFAULT_SYM_TOL);
484  void release_symmetry_information();
487  void form_symmetry_information(double tol = DEFAULT_SYM_TOL);
489  std::string sym_label();
491  std::vector<std::string> irrep_labels();
492  const std::string& symmetry_from_input() const { return symmetry_from_input_; }
493 
498  void symmetrize(double tol=0.05, bool suppress_mol_print_in_exc=false);
500 
507  static std::shared_ptr<Molecule> create_molecule_from_string(const std::string &geom);
508 
515  std::string create_psi4_string_from_molecule() const;
516 
520  void activate_all_fragments();
521 
525  void deactivate_all_fragments();
526 
531  void set_active_fragments(std::vector<int> reals);
532 
537  void set_active_fragment(int fragment);
538 
543  void set_ghost_fragments(std::vector<int> ghosts);
544 
549  void set_ghost_fragment(int fragment);
550 
558  std::shared_ptr<Molecule> extract_subsets(const std::vector<int>& real_list,
559  const std::vector<int>& ghost_list) const;
560 
567  std::shared_ptr<Molecule> py_extract_subsets_1(std::vector<int> reals, std::vector<int> ghost);
568 
575  std::shared_ptr<Molecule> py_extract_subsets_2(std::vector<int> reals, int ghost = -1);
576 
583  std::shared_ptr<Molecule> py_extract_subsets_3(int reals, std::vector<int> ghost);
584 
591  std::shared_ptr<Molecule> py_extract_subsets_4(int reals, int ghost = -1);
592 
598  std::shared_ptr<Molecule> py_extract_subsets_5(std::vector<int> reals);
599 
605  std::shared_ptr<Molecule> py_extract_subsets_6(int reals);
606 
607  // => Fragment Composition <= //
608 
611  const std::vector<std::pair<int, int> >& get_fragments() const { return fragments_; }
613  const std::vector<FragmentType>& get_fragment_types() const { return fragment_types_; }
615  const std::vector<int>& get_fragment_charges() const { return fragment_charges_; }
617  const std::vector<int>& get_fragment_multiplicities() const { return fragment_multiplicities_; }
619  void set_fragment_pattern(const std::vector<std::pair<int, int>>,
620  const std::vector<FragmentType>,
621  const std::vector<int>,
622  const std::vector<int>);
623 
625  void set_has_cartesian(bool tf) { cart_ = tf; }
627  void set_has_zmatrix(bool tf) { zmat_ = tf; }
629  bool has_zmatrix() const { return zmat_; }
632  void set_variable(const std::string& str, double val);
634  void set_geometry_variable(const std::string &str, double val) { geometry_variables_[str] = val; }
637  double get_variable(const std::string& str);
640  bool is_variable(const std::string& str) const;
641 
643  void set_molecular_charge(int charge) {
644  charge_specified_ = true;
645  molecular_charge_ = charge;
646  }
648  int molecular_charge() const { return molecular_charge_; }
650  void set_multiplicity(int mult) {
651  multiplicity_specified_ = true;
652  multiplicity_ = mult;
653  }
655  int multiplicity() const { return multiplicity_; }
656 
658  void set_units(GeometryUnits units);
660  GeometryUnits units() const { return units_; }
663  void set_input_units_to_au(double conv);
665  double input_units_to_au() const { return input_units_to_au_; }
667  bool orientation_fixed() const { return fix_orientation_; }
669  void set_orientation_fixed(bool fix = true) { fix_orientation_ = fix; }
671  bool com_fixed() const { return !move_to_com_; }
673  void set_com_fixed(bool fix = true) { move_to_com_ = !fix; }
675  std::string schoenflies_symbol() const;
677  bool valid_atom_map(double tol = 0.05) const;
679  std::string full_point_group() const;
681  std::string full_point_group_with_n() const { return FullPointGroupList[full_pg_]; }
683  int full_pg_n() { return full_pg_n_; }
686  int rotational_symmetry_number() const;
687 
692  void update_geometry();
693 };
694 
695 }
696 
697 #endif
int multiplicity() const
Get the multiplicity (defined as 2Ms + 1)
Definition: libmints/molecule.h:655
Definition: libmints/molecule.h:50
int ** equiv_
Equivalent atom mapping array.
Definition: libmints/molecule.h:157
Molecule clone(void)
Definition: libmints/molecule.h:186
bool reinterpret_coordentries_
Definition: libmints/molecule.h:171
Definition: libmints/molecule.h:49
Definition: libmints/molecule.h:49
const std::string & symmetry_from_input() const
Definition: libmints/molecule.h:492
Definition: libmints/molecule.h:50
Definition: libmints/molecule.h:50
const std::vector< std::pair< int, int > > & get_fragments() const
Definition: libmints/molecule.h:611
Definition: libmints/molecule.h:48
std::string symmetry_from_input_
Symmetry string from geometry specification.
Definition: libmints/molecule.h:168
int molecular_charge() const
Gets the molecular charge.
Definition: libmints/molecule.h:648
Definition: manybody.h:66
bool fix_orientation_
Reorient or not?
Definition: libmints/molecule.h:107
const std::vector< FragmentType > & get_fragment_types() const
A list describing how to handle each fragment.
Definition: libmints/molecule.h:613
Definition: libmints/molecule.h:69
#define FULL_PG_TOL
Definition: libmints/molecule.h:40
FragmentType
Definition: libmints/molecule.h:79
void set_has_cartesian(bool tf)
Sets whether this molecule contains at least one cartesian entry.
Definition: libmints/molecule.h:625
void set_name(const std::string &_name)
Set molecule name.
Definition: libmints/molecule.h:240
std::vector< std::shared_ptr< CoordEntry > > EntryVector
Definition: libmints/molecule.h:91
Definition: libmints/molecule.h:50
Definition: libmints/molecule.h:49
EntryVector::iterator EntryVectorIter
Definition: libmints/molecule.h:92
FragmentLevel
Definition: libmints/molecule.h:85
double input_units_to_au() const
Gets the geometry unit conversion.
Definition: libmints/molecule.h:665
Definition: libmints/molecule.h:48
const std::vector< int > & get_fragment_charges() const
The charge of each fragment.
Definition: libmints/molecule.h:615
int molecular_charge_
The molecular charge.
Definition: libmints/molecule.h:116
int nunique_
Number of unique atoms.
Definition: libmints/molecule.h:153
Definition: vector3.h:37
RotorType
Definition: libmints/molecule.h:48
const std::string RotorTypeList[]
Definition: libmints/molecule.h:52
GeometryUnits units_
The units used to define the geometry.
Definition: libmints/molecule.h:120
std::vector< FragmentType > fragment_types_
A list describing how to handle each fragment.
Definition: libmints/molecule.h:164
Definition: libmints/molecule.h:49
std::vector< std::pair< int, int > > fragments_
The list of atom ranges defining each fragment from parent molecule.
Definition: libmints/molecule.h:166
std::map< std::string, double > geometry_variables_
A listing of the variables used to define the geometries.
Definition: libmints/molecule.h:162
Definition: libmints/molecule.h:49
int nequivalent(int iuniq) const
Returns the number of atoms equivalent to iuniq.
Definition: libmints/molecule.h:445
int equivalent(int iuniq, int j) const
Returns the j&#39;th atom equivalent to iuniq.
Definition: libmints/molecule.h:447
std::shared_ptr< PointGroup > pg_
Point group to use with this molecule.
Definition: libmints/molecule.h:146
void set_lock_frame(bool tf)
Set whether to leave the geometry alone upon update_geometry()
Definition: libmints/molecule.h:233
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:683
std::vector< int > fragment_multiplicities_
The multiplicity of each fragment.
Definition: libmints/molecule.h:104
Definition: libmints/molecule.h:49
Definition: gshell.h:46
bool charge_specified_
Whether the charge was given by the user.
Definition: libmints/molecule.h:112
GeometryFormat
Definition: libmints/molecule.h:68
bool charge_specified() const
Whether the charge was given by the user.
Definition: libmints/molecule.h:224
const std::string name() const
Get molecule name.
Definition: libmints/molecule.h:236
int multiplicity_
The multiplicity (defined as 2Ms + 1)
Definition: libmints/molecule.h:118
const std::string FullPointGroupList[]
Definition: libmints/molecule.h:55
std::string full_point_group_with_n() const
Return point group name such as Cnv or Sn.
Definition: libmints/molecule.h:681
bool lock_frame_
Nilpotence boolean (flagged upon first determination of symmetry frame, reset each time a substantiat...
Definition: libmints/molecule.h:173
Definition: libmints/molecule.h:50
int nfragments() const
The number of fragments in the molecule.
Definition: libmints/molecule.h:226
bool has_zmatrix() const
Whether this molecule has at least one zmatrix entry.
Definition: libmints/molecule.h:629
bool com_fixed() const
Get whether or not COM is fixed.
Definition: libmints/molecule.h:671
int full_pg_n_
n of the highest rotational axis Cn
Definition: libmints/molecule.h:150
Definition: libmints/molecule.h:50
EntryVector full_atoms_
Atom info vector (includes dummy atoms)
Definition: libmints/molecule.h:100
Definition: libmints/molecule.h:48
int nunique() const
Definition: libmints/molecule.h:441
Makes using matrices just a little easier.
Definition: libmints/matrix.h:65
FullPointGroup full_pg_
Full point group.
Definition: libmints/molecule.h:148
int atom_to_unique(int iatom) const
Definition: libmints/molecule.h:450
bool orientation_fixed() const
Get whether or not orientation is fixed.
Definition: libmints/molecule.h:667
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:634
Definition: coordentry.h:54
Definition: libmints/molecule.h:48
bool multiplicity_specified() const
Whether the multiplicity was given by the user.
Definition: libmints/molecule.h:222
int * nequiv_
Number of equivalent atoms per unique atom (length nunique_)
Definition: libmints/molecule.h:155
#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:673
Definition: libmints/molecule.h:80
FullPointGroup
Definition: libmints/molecule.h:49
void set_orientation_fixed(bool fix=true)
Fix the orientation at its current frame.
Definition: libmints/molecule.h:669
#define PSI_API
Definition: pragma.h:128
bool zmat_
Whether this molecule has at least one zmatrix entry.
Definition: libmints/molecule.h:175
const std::vector< int > & get_fragment_multiplicities() const
The multiplicity of each fragment.
Definition: libmints/molecule.h:617
bool cart_
Whether this molecule has at least one cartesian entry.
Definition: libmints/molecule.h:177
std::vector< int > fragment_charges_
The charge of each fragment.
Definition: libmints/molecule.h:102
std::pair< int, int > fragment_atom_pair(int f)
Returns the list of atoms belonging to a fragment.
Definition: libmints/molecule.h:231
bool multiplicity_specified_
Whether the multiplicity was specified by the user.
Definition: libmints/molecule.h:114
std::string name_
Molecule (or fragment) name.
Definition: libmints/molecule.h:96
void set_molecular_charge(int charge)
Sets the molecular charge.
Definition: libmints/molecule.h:643
EntryVector atoms_
Atom info vector (no knowledge of dummy atoms)
Definition: libmints/molecule.h:98
Definition: libmints/molecule.h:49
int unique(int iuniq) const
Returns the overall number of the iuniq&#39;th unique atom.
Definition: libmints/molecule.h:443
Molecule information class.
Definition: libmints/molecule.h:62
double input_units_to_au_
The conversion factor to take input units to Bohr.
Definition: libmints/molecule.h:122
Definition: libmints/molecule.h:50
Definition: libmints/molecule.h:81
void set_multiplicity(int mult)
Sets the multiplicity (defined as 2Ms + 1)
Definition: libmints/molecule.h:650
GeometryUnits units() const
Gets the geometry units.
Definition: libmints/molecule.h:660
Definition: libmints/molecule.h:50
int nallatom() const
Number of all atoms (includes dummies)
Definition: libmints/molecule.h:244
std::vector< std::string > all_variables_
A list of all variables known, whether they have been set or not.
Definition: libmints/molecule.h:124
Definition: vector.h:48
void set_has_zmatrix(bool tf)
Sets whether this molecule contains at least one zmatrix entry.
Definition: libmints/molecule.h:627
GeometryUnits
Definition: libmints/molecule.h:75
int * atom_to_unique_
Atom to unique atom mapping array (length natom)
Definition: libmints/molecule.h:159
Definition: libmints/molecule.h:49
bool move_to_com_
Move to center of mass or not?
Definition: libmints/molecule.h:109