ergo
molecule.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
38 #ifndef MOLECULE_HEADER
39 #define MOLECULE_HEADER
40 
41 #include <cmath>
42 #include <vector>
43 #include <cassert>
44 
45 #include "realtype.h"
46 #include "mat_gblas.h"
47 
51 struct Atom {
54 };
55 
60 struct Vector3D {
62  Vector3D() {}
64  v[0] = x; v[1] = y; v[2] = z;
65  }
66  ergo_real& operator[](unsigned i) { return v[i]; }
67  ergo_real operator[](unsigned i) const { return v[i]; }
69  ergo_real dist2(const ergo_real b[]) const {
70  ergo_real d, r;
71  d = v[0]-b[0]; r = d*d;
72  d = v[1]-b[1]; r += d*d;
73  d = v[2]-b[2]; r += d*d;
74  return r;
75  }
77  ergo_real dist(const Vector3D& b) const
78  { return template_blas_sqrt(dist2(b.v)); }
79  ergo_real dist(const ergo_real b[]) const
80  { return template_blas_sqrt(dist2(b)); }
81 };
82 
87 class Molecule {
88  private:
89  std::vector<Atom> atoms;
91  int noOfAtoms;
92 
93  public:
94 
95  Molecule() : atoms(10), netCharge(0), noOfAtoms(0) {}
96 
98  int currListSize = atoms.size();
99  if(noOfAtoms >= currListSize)
100  atoms.resize(currListSize*2);
101  atoms[noOfAtoms].charge = c;
102  atoms[noOfAtoms].coords[0] = x;
103  atoms[noOfAtoms].coords[1] = y;
104  atoms[noOfAtoms].coords[2] = z;
105  noOfAtoms++;
106  }
107 
108  void clear() { noOfAtoms = 0; netCharge = 0; }
109  void setNetCharge(ergo_real netCharge_) { netCharge = netCharge_; }
110  void replaceAtom(int i, const Atom & atom) { assert(i >= 0 && i < noOfAtoms); atoms[i] = atom; }
111  void setAtomList(const std::vector<Atom> atomList) { atoms = atomList; noOfAtoms = atomList.size(); }
112  const Atom* getAtomListPtr() const { return &atoms[0]; }
113  const Atom & getAtom(int i) const { return atoms[i]; }
114  int getNoOfAtoms() const { return noOfAtoms; }
115  ergo_real getNetCharge() const { return netCharge; }
116 
118  void getExtremeInternuclearDistancesQuadratic(ergo_real & minDist, ergo_real & maxDist) const;
122  ergo_real getNuclearElectricFieldEnergy(const Vector3D& electricField) const;
125  int getNumberOfElectrons() const;
128 
132  int setFromMoleculeFile(const char* fileName,
133  int netCharge,
134  char **basissetFile);
135 
136 };
137 
138 
139 #endif /* MOLECULE_HEADER */
const Atom * getAtomListPtr() const
Definition: molecule.h:112
double ergo_real
Definition: realtype.h:69
int getNoOfAtoms() const
Definition: molecule.h:114
ergo_real getNuclearRepulsionEnergyQuadratic() const
Compute nuclear repulsion energy.
Definition: molecule.cc:87
int getNumberOfElectrons() const
Compute total number of electrons.
Definition: molecule.cc:158
A representation of Vector or point in cartesian space.
Definition: molecule.h:60
ergo_real & operator[](unsigned i)
Definition: molecule.h:66
ergo_real getNuclearElectricFieldEnergy(const Vector3D &electricField) const
Compute nuclear energy in given electric field.
Definition: molecule.cc:138
ergo_real dist(const ergo_real b[]) const
Definition: molecule.h:79
Representation of a molecule as a set of nuclei and total charge.
Definition: molecule.h:87
void setNetCharge(ergo_real netCharge_)
Definition: molecule.h:109
ergo_real dist2(const ergo_real b[]) const
compute square of distance between two points.
Definition: molecule.h:69
ergo_real netCharge
Definition: molecule.h:90
Simple atom representation by its charge and cartesian coordinates.
Definition: molecule.h:51
Definition of the main floating-point datatype used; the ergo_real type.
void clear()
Definition: molecule.h:108
C++ interface to a subset of BLAS and LAPACK.
ergo_real v[3]
Definition: molecule.h:61
Vector3D()
Definition: molecule.h:62
const Atom & getAtom(int i) const
Definition: molecule.h:113
Molecule()
Definition: molecule.h:95
Vector3D(ergo_real x, ergo_real y, ergo_real z)
Definition: molecule.h:63
std::vector< Atom > atoms
Definition: molecule.h:89
void getExtremeInternuclearDistancesQuadratic(ergo_real &minDist, ergo_real &maxDist) const
Compute smallest and largest internuclear distances.
Definition: molecule.cc:66
ergo_real coords[3]
Definition: molecule.h:53
int noOfAtoms
Definition: molecule.h:91
void setAtomList(const std::vector< Atom > atomList)
Definition: molecule.h:111
void getNuclearRepulsionEnergyGradientContribQuadratic(ergo_real *resultGradient) const
Compute gradient of nuclear repulsion energy w.r.t.
Definition: molecule.cc:111
void addAtom(ergo_real c, ergo_real x, ergo_real y, ergo_real z)
Definition: molecule.h:97
ergo_real charge
Definition: molecule.h:52
void replaceAtom(int i, const Atom &atom)
Definition: molecule.h:110
ergo_real dist(const Vector3D &b) const
compute distance between two points.
Definition: molecule.h:77
ergo_real getNetCharge() const
Definition: molecule.h:115
Treal template_blas_sqrt(Treal x)
int setFromMoleculeFile(const char *fileName, int netCharge, char **basissetFile)
Loads molecule from a given file name, assuming given net charge.
Definition: molecule.cc:409
ergo_real operator[](unsigned i) const
Definition: molecule.h:67