MPQC  3.0.0-alpha
molecule.h
1 //
2 // molecule.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit 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 Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _chemistry_molecule_molecule_h
29 #define _chemistry_molecule_molecule_h
30 
31 #undef HAVE_OPENBABEL2 // Won't link on my machine. Remove this before committing to main branch
32 
33 #include <stdio.h>
34 #include <iostream>
35 #include <mpqc_config.h>
36 #include <util/class/class.h>
37 #include <util/state/state.h>
38 #include <util/keyval/keyval.h>
39 #include <util/misc/units.h>
40 #include <math/symmetry/pointgrp.h>
41 #include <math/scmat/vector3.h>
42 #include <math/scmat/matrix.h>
43 #include <chemistry/molecule/atominfo.h>
44 #include <chemistry/molecule/atom.h>
45 
46 #ifdef MPQC_NEW_FEATURES
47 #include <util/misc/xml.h>
48 #endif // MPQC_NEW_FEATURES
49 
50 namespace sc {
51 
54 
149 class Molecule: public SavableState
150 #ifdef MPQC_NEW_FEATURES
151 , virtual public DescribedXMLWritable
152 #endif
153 {
154  protected:
155  std::vector<Atom> atoms_;
156  Ref<AtomInfo> atominfo_;
157  Ref<PointGroup> pg_;
158  Ref<Units> geometry_units_;
159  double ref_origin_[3]; //< position of the origin of the reference coordinate system
160 
161  // symmetry equiv info
162  int nuniq_;
163  int *nequiv_;
164  int **equiv_;
165  int *atom_to_uniq_;
166  void init_symmetry_info(double tol=0.5);
167  void clear_symmetry_info();
168 
169  // The Z that represents a "Q" type atom.
170  int q_Z_;
171 
172  // If true, include the q terms in the charge and efield routines
173  bool include_q_;
174 
175  // If true, include the coupling between q-q pairs when
176  // computing nuclear repulsion energy and gradients.
177  bool include_qq_;
178 
179  // These vectors contain the atom indices of atoms that are not type
180  // "Q" and those that are.
181  std::vector<int> q_atoms_;
182  std::vector<int> non_q_atoms_;
183 
184  void clear();
185 
186  // Throw an exception if an atom is duplicated. The
187  // atoms in the range [begin, natom_) are checked.
188  void throw_if_atom_duplicated(int begin=0, double tol = 1e-3);
189  public:
190  Molecule();
191  Molecule(const Molecule&);
192  Molecule(StateIn&);
301  Molecule(const Ref<KeyVal>&input);
302 
303  virtual ~Molecule();
304 
305  Molecule& operator=(const Molecule&);
306 
308  void add_atom(int Z,double x,double y,double z,
309  const std::string & label = "", double mass = 0.0,
310  int have_charge = 0, double charge = 0.0,
311  int have_fragment = 0, int fragment = 0);
312 
313  const Atom& atom(size_t i) const { return atoms_[i]; }
314  const std::vector<Atom>& atoms() const { return atoms_; }
315 
317  virtual void print(std::ostream& =ExEnv::out0()) const;
318  virtual void print_parsedkeyval(std::ostream& =ExEnv::out0(),
319  int print_pg = 1,
320  int print_unit = 1,
321  int number_atoms = 1) const;
322 
324  Ref<Units> geometry_units() const { return geometry_units_; }
325 
327  size_t natom() const { return atoms_.size(); }
328 
329  int Z(int atom) const { return atoms_[atom].Z(); }
330  double &r(int atom, int xyz) { return atoms_[atom].r(xyz); }
331  const double &r(int atom, int xyz) const { return atoms_[atom].r(xyz); }
332  const double *r(int atom) const { return atoms_[atom].r(); }
333  double mass(int atom) const;
336  const char *label(int atom) const;
338  int fragment(int atom) const;
339 
342  int atom_at_position(double *, double tol = 0.05) const;
343 
346  int atom_label_to_index(const std::string &label) const;
347 
350  std::vector<double> charges() const;
351 
353  double charge(int iatom) const;
354 
356  bool is_Q(int iatom) const;
357 
360  double total_charge() const;
361 
363  int total_Z() const;
364 
366  void set_point_group(const Ref<PointGroup>&, double tol=1.0e-7);
368  const Ref<PointGroup>& point_group() const;
369 
373  Ref<PointGroup> highest_point_group(double tol = 1.0e-8) const;
374 
377  int is_axis(SCVector3 &origin,
378  SCVector3 &udirection, int order, double tol=1.0e-8) const;
379 
382  int is_plane(SCVector3 &origin, SCVector3 &uperp, double tol=1.0e-8) const;
383 
385  int has_inversion(SCVector3 &origin, double tol = 1.0e-8) const;
386 
388  int is_linear(double tolerance = 1.0e-5) const;
390  int is_planar(double tolerance = 1.0e-5) const;
393  void is_linear_planar(int&linear,int&planar,double tol = 1.0e-5) const;
394 
397  SCVector3 center_of_mass() const;
398 
400  double nuclear_repulsion_energy();
401 
404  void nuclear_repulsion_1der(int center, double xyz[3]);
405 
407  void nuclear_efield(const double *position, double* efield);
408 
411  void nuclear_charge_efield(const double *charges,
412  const double *position, double* efield);
413 
419  void symmetrize(double tol = 0.5);
420 
422  void symmetrize(const Ref<PointGroup> &pg, double tol = 0.5);
423 
429  void cleanup_molecule(double tol = 0.1);
430 
431  void translate(const double *r);
432  void move_to_com();
433  void transform_to_principal_axes(int trans_frame=1);
434  void transform_to_symmetry_frame();
435  void print_xyz(std::ostream& =ExEnv::out0(), const char *title =0) const;
436 
439  void principal_moments_of_inertia(double *evals, double **evecs=0) const;
440 
445  int nunique() const { return nuniq_; }
448  int unique(int iuniq) const { return equiv_[iuniq][0]; }
450  int nequivalent(int iuniq) const { return nequiv_[iuniq]; }
452  int equivalent(int iuniq, int j) const { return equiv_[iuniq][j]; }
455  int atom_to_unique(int iatom) const { return atom_to_uniq_[iatom]; }
458  int atom_to_unique_offset(int iatom) const;
460 
462  int n_core_electrons();
463 
465  int max_z();
466 
468  Ref<AtomInfo> atominfo() const { return atominfo_; }
469 
471  std::string atom_name(int iatom) const;
472 
474  std::string atom_symbol(int iatom) const;
475 
478  void set_include_q(bool iq) { include_q_ = iq; }
480  bool include_q() const { return include_q_; }
481 
484  void set_include_qq(bool iqq) { include_qq_ = iqq; }
486  bool include_qq() const { return include_qq_; }
487 
489  int n_q_atom() const { return q_atoms_.size(); }
491  int q_atom(int i) const { return q_atoms_[i]; }
492 
494  int n_non_q_atom() const { return non_q_atoms_.size(); }
496  int non_q_atom(int i) const { return non_q_atoms_[i]; }
497 
499  bool any_atom_has_charge() const;
501  bool any_atom_has_fragment() const;
503  bool any_atom_has_label() const;
504 
507  SCVector3 ref_origin() const { return ref_origin_; }
508 
509  void save_data_state(StateOut&);
510 
511 #ifdef MPQC_NEW_FEATURES
512  virtual boost::property_tree::ptree& write_xml(boost::property_tree::ptree& parent, const XMLWriter& writer);
513 #endif
514 
515  private:
517  void read_xyz(const char *filename);
518 #ifdef HAVE_OPENBABEL2
519  void read_openbabel2(const char *filename);
521 #endif // HAVE_OPENBABEL2
522 };
523 
525 bool operator==(const Molecule& mol1, const Molecule& mol2);
526 
528 // end of addtogroup ChemistryMolecule
529 
530 } // namespace sc
531 
532 #endif
533 
534 // Local Variables:
535 // mode: c++
536 // c-file-style: "CLJ"
537 // End:
sc::Molecule::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::Molecule::atom_at_position
int atom_at_position(double *, double tol=0.05) const
Takes an (x, y, z) postion and finds an atom within the given tolerance distance.
sc::Molecule::nequivalent
int nequivalent(int iuniq) const
Returns the number of atoms equivalent to iuniq.
Definition: molecule.h:450
sc::Molecule::has_inversion
int has_inversion(SCVector3 &origin, double tol=1.0e-8) const
Return 1 if the molecule has an inversion center.
sc::Molecule::max_z
int max_z()
Return the maximum atomic number.
sc::Molecule::is_linear_planar
void is_linear_planar(int &linear, int &planar, double tol=1.0e-5) const
Sets linear to 1 if the molecular is linear, 0 otherwise.
sc::Molecule::total_charge
double total_charge() const
Returns the total nuclear charge.
sc::Molecule::any_atom_has_fragment
bool any_atom_has_fragment() const
Determine if any of the atoms have a fragment label.
sc::Molecule
The Molecule class contains information about molecules.
Definition: molecule.h:149
sc::Molecule::point_group
const Ref< PointGroup > & point_group() const
Returns the PointGroup of the molecule.
sc::Molecule::atom_label_to_index
int atom_label_to_index(const std::string &label) const
Returns the index of the atom with the given label.
sc::Molecule::geometry_units
Ref< Units > geometry_units() const
in which units Molecule was specified and in which units it will be reported
Definition: molecule.h:324
sc::Molecule::atom_symbol
std::string atom_symbol(int iatom) const
Returns the element symbol of the atom.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::Atom
Atom represents an atom in a Molecule.
Definition: atom.h:47
sc::Molecule::total_Z
int total_Z() const
Returns the sum of atomic numbers of nuclei.
sc::Molecule::n_q_atom
int n_q_atom() const
Retrieve the number of "Q" atoms.
Definition: molecule.h:489
sc::Molecule::atom_to_unique
int atom_to_unique(int iatom) const
Converts an atom number to the number of its generating unique atom.
Definition: molecule.h:455
sc::Molecule::is_linear
int is_linear(double tolerance=1.0e-5) const
Returns 1 if the molecule is linear, 0 otherwise.
sc::Molecule::center_of_mass
SCVector3 center_of_mass() const
Returns a SCVector3 containing the cartesian coordinates of the center of mass for the molecule.
sc::Molecule::add_atom
void add_atom(int Z, double x, double y, double z, const std::string &label="", double mass=0.0, int have_charge=0, double charge=0.0, int have_fragment=0, int fragment=0)
Add an AtomicCenter to the Molecule.
sc::Molecule::charges
std::vector< double > charges() const
Returns a vector of the nuclear charges of the atoms.
sc::Molecule::is_planar
int is_planar(double tolerance=1.0e-5) const
Returns 1 if the molecule is planar, 0 otherwise.
sc::Molecule::is_axis
int is_axis(SCVector3 &origin, SCVector3 &udirection, int order, double tol=1.0e-8) const
Return 1 if this given axis is a symmetry element for the molecule.
sc::Molecule::nuclear_repulsion_energy
double nuclear_repulsion_energy()
Returns the nuclear repulsion energy for the molecule.
sc::Molecule::non_q_atom
int non_q_atom(int i) const
Retrieve the of non-"Q" atoms.
Definition: molecule.h:496
sc::Molecule::any_atom_has_label
bool any_atom_has_label() const
Determine if any of the atoms have a user defined label.
sc::Molecule::include_q
bool include_q() const
Returns include_q. See set_include_q.
Definition: molecule.h:480
sc::StateIn
Definition: statein.h:79
sc::Molecule::set_include_q
void set_include_q(bool iq)
If include_q is true, then include the "Q" atoms in the charge and efield routines.
Definition: molecule.h:478
sc::Molecule::n_non_q_atom
int n_non_q_atom() const
Retrieve the number of non-"Q" atoms.
Definition: molecule.h:494
sc::Molecule::nuclear_charge_efield
void nuclear_charge_efield(const double *charges, const double *position, double *efield)
Compute the electric field due to the given charges at the positions of the nuclei at the given point...
sc::Molecule::fragment
int fragment(int atom) const
returns the fragment to which atom belongs to
sc::Molecule::principal_moments_of_inertia
void principal_moments_of_inertia(double *evals, double **evecs=0) const
Compute the principal moments of inertia and, possibly, the principal axes.
sc::Molecule::atom_name
std::string atom_name(int iatom) const
Returns the element name of the atom.
sc::DescribedXMLWritable
Definition: xml.h:50
sc::Molecule::atom_to_unique_offset
int atom_to_unique_offset(int iatom) const
Converts an atom number to the offset of this atom in the list of generated atoms.
sc::Molecule::cleanup_molecule
void cleanup_molecule(double tol=0.1)
This will try to carefully correct symmetry errors in molecules.
sc::Molecule::include_qq
bool include_qq() const
Returns include_qq. See set_include_qq.
Definition: molecule.h:486
sc::Molecule::symmetrize
void symmetrize(double tol=0.5)
If the molecule contains only symmetry unique atoms, this function will generate the other,...
sc::Molecule::nunique
int nunique() const
Return information about symmetry unique and equivalent atoms.
Definition: molecule.h:446
sc::Molecule::print
virtual void print(std::ostream &=ExEnv::out0()) const
Print information about the molecule.
sc::StateOut
Definition: stateout.h:71
sc::Molecule::is_Q
bool is_Q(int iatom) const
Return true if iatom is a simple point charge.
sc::Molecule::charge
double charge(int iatom) const
Return the charge of the atom.
sc::XMLWriter
Definition: xmlwriter.h:215
sc::Molecule::atominfo
Ref< AtomInfo > atominfo() const
Return the molecule's AtomInfo object.
Definition: molecule.h:468
sc::Molecule::n_core_electrons
int n_core_electrons()
Return the number of core electrons.
sc::Molecule::set_include_qq
void set_include_qq(bool iqq)
If include_qq is true, include the coupling between pairs of "Q" atoms when computing nuclear repulsi...
Definition: molecule.h:484
sc::Molecule::label
const char * label(int atom) const
Returns the label explicitly assigned to atom.
sc::Molecule::q_atom
int q_atom(int i) const
Retrieve the "Q" atoms.
Definition: molecule.h:491
sc::SCVector3
a 3-element version of SCVector
Definition: vector3.h:43
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::Molecule::nuclear_repulsion_1der
void nuclear_repulsion_1der(int center, double xyz[3])
Compute the nuclear repulsion energy first derivative with respect to the given center.
sc::Molecule::natom
size_t natom() const
Returns the number of atoms in the molecule.
Definition: molecule.h:327
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::Molecule::highest_point_group
Ref< PointGroup > highest_point_group(double tol=1.0e-8) const
Find this molecules true point group (limited to abelian groups).
sc::Molecule::nuclear_efield
void nuclear_efield(const double *position, double *efield)
Compute the electric field due to the nuclei at the given point.
sc::operator==
bool operator==(const Atom &a, const Atom &b)
sc::Molecule::is_plane
int is_plane(SCVector3 &origin, SCVector3 &uperp, double tol=1.0e-8) const
Return 1 if the given plane is a symmetry element for the molecule.
sc::Molecule::equivalent
int equivalent(int iuniq, int j) const
Returns the j'th atom equivalent to iuniq.
Definition: molecule.h:452
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::Molecule::ref_origin
SCVector3 ref_origin() const
returns the origin of the reference coordinate system (the system in which atoms were specified befor...
Definition: molecule.h:507
sc::Molecule::unique
int unique(int iuniq) const
Returns the overall number of the iuniq'th unique atom.
Definition: molecule.h:448
sc::Molecule::any_atom_has_charge
bool any_atom_has_charge() const
Determine if any of the atoms have non-standard charge.
sc::Molecule::set_point_group
void set_point_group(const Ref< PointGroup > &, double tol=1.0e-7)
Sets the PointGroup of the molecule.

Generated at Sun Jan 26 2020 23:23:57 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.