ergo
molecule.h
Go to the documentation of this file.
1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 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 */
template_blas_sqrt
Treal template_blas_sqrt(Treal x)
Molecule::setFromMoleculeFile
int setFromMoleculeFile(const char *fileName, int netCharge, char **basissetFile)
Loads molecule from a given file name, assuming given net charge.
Definition: molecule.cc:409
Vector3D
A representation of Vector or point in cartesian space.
Definition: molecule.h:60
realtype.h
Definition of the main floating-point datatype used; the ergo_real type.
xyz_file_parser.h
Functionality for parsing a file in xyz file format, storing the result as a molecule object.
readMoleculeFileInXyzFormat
int readMoleculeFileInXyzFormat(Molecule &result, const char *fileName, int netCharge, bool expectPlainCharges)
Definition: xyz_file_parser.cc:53
memorymanag.h
Memory allocation/deallocation routines.
UNIT_one_Angstrom
#define UNIT_one_Angstrom
Definition: units.h:43
LOG_CAT_ERROR
#define LOG_CAT_ERROR
Definition: output.h:47
Molecule::getNuclearRepulsionEnergyQuadratic
ergo_real getNuclearRepulsionEnergyQuadratic() const
Compute nuclear repulsion energy.
Definition: molecule.cc:87
ergo_real
double ergo_real
Definition: realtype.h:69
Molecule::clear
void clear()
Definition: molecule.h:108
ergo_malloc
void * ergo_malloc(size_t noOfBytes)
Definition: memorymanag.cc:49
Molecule::getNuclearElectricFieldEnergy
ergo_real getNuclearElectricFieldEnergy(const Vector3D &electricField) const
Compute nuclear energy in given electric field.
Definition: molecule.cc:138
Molecule::getNoOfAtoms
int getNoOfAtoms() const
Definition: molecule.h:114
Atom
Simple atom representation by its charge and cartesian coordinates.
Definition: molecule.h:51
mat_gblas.h
charge
int charge
Definition: grid_test.cc:51
B
#define B
Vector3D::dist
ergo_real dist(const ergo_real b[]) const
Definition: molecule.h:79
Molecule::setNetCharge
void setNetCharge(ergo_real netCharge_)
Definition: molecule.h:109
mat::get_file_size
static long int get_file_size(const char *fileName)
Definition: FileWritable.cc:402
Vector3D::dist
ergo_real dist(const Vector3D &b) const
compute distance between two points.
Definition: molecule.h:77
Vector3D::Vector3D
Vector3D()
Definition: molecule.h:62
Vector3D::operator[]
ergo_real operator[](unsigned i) const
Definition: molecule.h:67
Molecule::setAtomList
void setAtomList(const std::vector< Atom > atomList)
Definition: molecule.h:111
readMoleculeFileInMolFormat
static int readMoleculeFileInMolFormat(Molecule *result, const char *fileName, int netCharge, char **basisfilename)
Definition: molecule.cc:171
Molecule::getNuclearRepulsionEnergyGradientContribQuadratic
void getNuclearRepulsionEnergyGradientContribQuadratic(ergo_real *resultGradient) const
Compute gradient of nuclear repulsion energy w.r.t.
Definition: molecule.cc:111
Vector3D::v
ergo_real v[3]
Definition: molecule.h:61
Molecule::getAtom
const Atom & getAtom(int i) const
Definition: molecule.h:113
utilities.h
Basic OS access utilities.
A
#define A
LOG_CAT_INFO
#define LOG_CAT_INFO
Definition: output.h:49
Molecule::netCharge
ergo_real netCharge
Definition: molecule.h:90
LOG_AREA_MAIN
#define LOG_AREA_MAIN
Definition: output.h:57
units.h
Constants for conversion between units for some common units like Angstrom, electron-volt (eV),...
get_distance_between_atoms
static ergo_real get_distance_between_atoms(const Atom &atomA, const Atom &atomB)
Definition: molecule.cc:53
Atom::charge
ergo_real charge
Definition: molecule.h:52
molecule.h
Class representing a molecule as a set of atoms with assiciated coordinates and charges of the atomic...
Vector3D::Vector3D
Vector3D(ergo_real x, ergo_real y, ergo_real z)
Definition: molecule.h:63
Molecule::atoms
std::vector< Atom > atoms
Definition: molecule.h:89
Molecule
Representation of a molecule as a set of nuclei and total charge.
Definition: molecule.h:87
Molecule::getExtremeInternuclearDistancesQuadratic
void getExtremeInternuclearDistancesQuadratic(ergo_real &minDist, ergo_real &maxDist) const
Compute smallest and largest internuclear distances.
Definition: molecule.cc:66
Molecule::getAtomListPtr
const Atom * getAtomListPtr() const
Definition: molecule.h:112
Vector3D::dist2
ergo_real dist2(const ergo_real b[]) const
compute square of distance between two points.
Definition: molecule.h:69
Molecule::getNetCharge
ergo_real getNetCharge() const
Definition: molecule.h:115
Molecule::Molecule
Molecule()
Definition: molecule.h:95
Atom::coords
ergo_real coords[3]
Definition: molecule.h:53
Molecule::addAtom
void addAtom(ergo_real c, ergo_real x, ergo_real y, ergo_real z)
Definition: molecule.h:97
Vector3D::operator[]
ergo_real & operator[](unsigned i)
Definition: molecule.h:66
do_output
void do_output(int logCategory, int logArea, const char *format,...)
Definition: output.cc:53
Molecule::getNumberOfElectrons
int getNumberOfElectrons() const
Compute total number of electrons.
Definition: molecule.cc:158
Molecule::noOfAtoms
int noOfAtoms
Definition: molecule.h:91
output.h
Functionality for writing output messages to a text file.
Molecule::replaceAtom
void replaceAtom(int i, const Atom &atom)
Definition: molecule.h:110