33 #ifndef MOLECULAR_BASIS_H
34 #define MOLECULAR_BASIS_H
53 std::vector<double> coeff;
54 std::vector<double> expnt;
61 int np = coeff.size();
62 if (np == 1) coeff[0] = 1.0e0;
65 int l_lim = 2*type - 1;
67 for (
int n=l_lim; n>1; n-=2) f *= n;
69 for (
int n=0; n<
np; n++)
73 for (
int n1=0; n1<
np; n1++) {
74 for (
int n2=0; n2<
np; n2++) {
75 double S =pi32/
pow(expnt[n1]+expnt[n2],1.5e0+type)/
pow(2e0,type);
76 sum = sum + coeff[n1]*coeff[n2]*S;
82 for (
int n=0; n<
np; n++) coeff[n] *= f;
87 : type(-1), coeff(), expnt(), rsqmax(0.0), numbf(0) {};
90 const std::vector<double>& coeff,
91 const std::vector<double>& expnt,
93 : type(type), coeff(coeff), expnt(expnt), numbf((type+1)*(type+2)/2) {
94 if (donorm) normalize();
95 double minexpnt = expnt[0];
96 for (
unsigned int i=1; i<expnt.size(); i++)
97 minexpnt =
std::min(minexpnt,expnt[i]);
98 rsqmax = 18.4/minexpnt;
110 if (rsq > rsqmax)
return 0.0;
112 for (
unsigned int i=0; i<coeff.size(); i++) {
113 double ersq = expnt[i]*rsq;
114 if (ersq < 18.4) sum += coeff[i]*
exp(-ersq);
121 double*
eval(
double rsq,
double x,
double y,
double z,
double* bf)
const {
123 if (
fabs(R) < 1e-8) {
124 for (
int i=0; i<numbf; i++) bf[i] = 0.0;
159 throw "UNKNOWN ANGULAR MOMENTUM";
193 static const char* tags[4][10] = {
194 {
"s" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" } ,
195 {
"px" ,
"py" ,
"pz" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" ,
"" } ,
196 {
"dxx" ,
"dxy" ,
"dxz" ,
"dyy" ,
"dyz" ,
"dzz" ,
"" ,
"" ,
"" ,
"" } ,
197 {
"fxxx",
"fxxy",
"fxxz",
"fxyy",
"fxyz",
"fxzz",
"fxzz",
"fyyy",
"fyzz",
"fzzz"}
199 MADNESS_ASSERT(ibf<numbf && ibf >= 0);
200 return tags[type][ibf];
203 template <
typename Archive>
205 ar & type & coeff & expnt & rsqmax & numbf;
211 static const char* tag[] = {
"s",
"p",
"d",
"f",
"g"};
214 const std::vector<double>& coeff = c.
get_coeff();
215 const std::vector<double>& expnt = c.
get_expnt();
218 for (
int i=0; i<c.
nprim(); i++) {
219 p += sprintf(p,
"%.6f(%.6f)",coeff[i],expnt[i]);
220 if (i != (c.
nprim()-1)) p += sprintf(p,
", ");
222 p += sprintf(p,
"]");
230 std::vector<ContractedGaussianShell> g;
233 Tensor<double> dmat, avec, bvec;
242 for (
unsigned int i=0; i<g.size(); i++) {
243 rmaxsq =
std::max(rmaxsq, g[i].rangesq());
249 const Tensor<double>& avec,
const Tensor<double>& bvec) {
250 this->dmat =
copy(dmat);
251 this->avec =
copy(avec);
252 this->bvec =
copy(bvec);
266 const std::vector<ContractedGaussianShell>&
get_shells()
const {
275 double*
eval(
double x,
double y,
double z,
double* bf)
const {
276 double rsq = x*x + y*y + z*z;
278 for (
int i=0; i<numbf; i++) bf[i] = 0.0;
282 double* bfstart = bf;
283 for (
unsigned int i=0; i<g.size(); i++) {
284 bf = g[i].eval(rsq, x, y, z, bf);
287 MADNESS_ASSERT(bf-bfstart == numbf);
294 double rsq = x*x + y*y + z*z;
295 if (rsq > rmaxsq)
return 0.0;
299 const double* p = dmat.ptr();
301 for (
int i=0; i<numbf; i++, p+=numbf) {
303 for (
int j=0; j<numbf; ++j)
313 for (
unsigned int i=0; i<g.size(); i++) {
314 int nbf_in_shell = g[i].
nbf();
315 if (ibf>=n && ibf<(n+nbf_in_shell)) {
316 ibf_in_shell = ibf-n;
327 return dmat.size()>0;
342 template <
typename Archive>
344 ar & g & rmaxsq & numbf & dmat & avec & bvec;
350 const std::vector<ContractedGaussianShell>& shells = c.
get_shells();
351 for (
int i=0; i<c.
nshell(); i++) {
352 s <<
" " << shells[i] << std::endl;
355 s <<
" " <<
"Guess density matrix" << std::endl;
365 const double xx, yy, zz;
373 : xx(x), yy(y), zz(z), shell(shell), ibf(ibf), nbf(shell.nbf()) {}
380 , shell(aofunc.shell)
389 double rsq = x*x + y*y + z*z;
390 shell.
eval(rsq, x, y, z, bf);
395 s <<
"atomic basis function: center " << xx <<
" " << yy <<
" " << zz <<
" : ibf " << ibf <<
" nbf " << nbf <<
" : shell " << shell << std::endl;
428 std::vector<AtomicBasis> ag;
430 template <
typename T>
431 std::vector<T> load_tixml_vector(
TiXmlElement* node,
int n,
const char* name) {
433 MADNESS_ASSERT(child);
434 std::istringstream s(child->
GetText());
436 for (
int i=0; i<n; i++) {
437 MADNESS_ASSERT(s >> r[i]);
442 template <
typename T>
443 Tensor<T> load_tixml_matrix(
TiXmlElement* node,
int n,
int m,
const char* name) {
445 MADNESS_ASSERT(child);
446 std::istringstream s(child->
GetText());
448 for (
int i=0; i<n; i++) {
449 for (
int j=0; j<
m; j++) {
450 MADNESS_ASSERT(s >> r(i,j));
465 static const bool debug =
false;
468 std::cout <<
"AtomicBasisSet: Failed loading from file " << filename
471 <<
" : Col " << doc.
ErrorCol() << std::endl;
475 if (strcmp(node->
Value(),
"name") == 0) {
477 if (debug) std::cout <<
"Loading basis set " << name << std::endl;
479 else if (strcmp(node->
Value(),
"basis") == 0) {
480 const char* symbol = node->
Attribute(
"symbol");
481 if (debug) std::cout <<
" found basis set for " << symbol << std::endl;
483 std::vector<ContractedGaussianShell>
g;
485 const char* type = shell->Attribute(
"type");
487 shell->Attribute(
"nprim",&nprim);
488 if (debug) std::cout <<
" found shell " << type <<
" " << nprim << std::endl;
489 std::vector<double> expnt = load_tixml_vector<double>(shell, nprim,
"exponents");
490 if (strcmp(type,
"L") == 0) {
491 std::vector<double> scoeff = load_tixml_vector<double>(shell, nprim,
"scoefficients");
492 std::vector<double> pcoeff = load_tixml_vector<double>(shell, nprim,
"pcoefficients");
497 static const char* tag[] = {
"S",
"P",
"D",
"F",
"G"};
499 for (i=0; i<5; i++) {
500 if (strcmp(type,tag[i]) == 0)
goto foundit;
504 std::vector<double> coeff = load_tixml_vector<double>(shell, nprim,
"coefficients");
510 else if (strcmp(node->
Value(),
"atomicguess") == 0) {
511 const char* symbol = node->
Attribute(
"symbol");
512 if (debug) std::cout <<
" atomic guess info for " << symbol << std::endl;
515 int nbf = ag[atn].nbf();
516 Tensor<double> dmat = load_tixml_matrix<double>(node,
nbf,
nbf,
"guessdensitymatrix");
517 Tensor<double> avec = load_tixml_matrix<double>(node,
nbf,
nbf,
"alphavectors");
518 Tensor<double> bvec = load_tixml_matrix<double>(node,
nbf,
nbf,
"betavectors");
519 ag[atn].set_guess_info(dmat, avec, bvec);
531 at_to_bf = std::vector<int>(mentity.
natom());
532 at_nbf = std::vector<int>(mentity.
natom());
535 for (
int i=0; i<mentity.
natom(); i++) {
540 at_nbf[i] = ag[atn].nbf();
548 MADNESS_ASSERT(ibf >= 0);
550 for (
int i=0; i<mentity.
natom(); i++) {
555 const int nbf_on_atom = ag[atn].nbf();
556 if (ibf >= n && (n+nbf_on_atom) > ibf) {
568 MADNESS_ASSERT(ibf >= 0);
570 for (
int i=0; i<mentity.
natom(); i++) {
575 const int nbf_on_atom = ag[atn].nbf();
576 if (ibf >= n && (n+nbf_on_atom) > ibf) {
579 ag[atn].get_shell_from_basis_function(ibf-n, index);
593 for (
int i=0; i<mentity.
natom(); i++) {
604 for (
int i=0; i<mentity.
natom(); i++) {
607 bf = ag[atn].eval(x-atom.
x, y-atom.
y, z-atom.
z, bf);
615 for (
int i=0; i<mentity.
natom(); i++) {
618 sum += ag[atn].eval_guess_density(x-atom.
x, y-atom.
y, z-atom.
z);
624 return ag[atomic_number].nbf() > 0;
629 std::cout <<
"\n " << name <<
" atomic basis set" << std::endl;
630 for (
int i=0; i<mentity.
natom(); i++) {
633 for (
int j=0; j<i; j++) {
637 std::cout << std::endl;
639 std::cout << ag[atn];
645 template <
typename T>
646 class AnalysisSorter {
651 return std::abs(v[i]) > std::abs(v[j]);
663 template <
typename T>
665 const double thresh = 0.2*v.normf();
667 printf(
" zero vector\n");
670 long nbf = int(v.dim[0]);
673 for (
long i=0; i<
nbf; i++) {
674 if (std::abs(v(i)) > thresh) {
681 if (mentity.
natom() < 10) {
682 format =
" %2s(%1d)%4s(%2ld)%6.3f ";
684 else if (mentity.
natom() < 100) {
685 format =
" %2s(%2d)%4s(%3ld)%6.3f ";
687 else if (mentity.
natom() < 1000) {
688 format =
" %2s(%3d)%4s(%4ld)%6.3f ";
691 format =
" %2s(%4d)%4s(%5ld)%6.3f ";
693 for (
long ii=0; ii<ngot; ii++) {
703 printf(format, element, iat, desc, ibf, v[ibf]);
710 std::cout <<
"\n " << name <<
" atomic basis set" << std::endl;
711 for (
unsigned int i=0; i<ag.size(); i++) {
712 if (ag[i].
nbf() > 0) {
719 template <
typename Archive>
int np
Definition: tdse1d.cc:166
int nbf() const
Returns the number of basis functions on the center.
Definition: hf/molecularbasis.h:256
double eval_radial(double rsq) const
Evaluates the radial part of the contracted function.
Definition: hf/molecularbasis.h:109
const double thresh
Definition: dielectric.cc:185
const Tensor< double > & get_dmat() const
Definition: hf/molecularbasis.h:330
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
bool is_supported(int atomic_number) const
Definition: hf/molecularbasis.h:623
const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2234
const double pi
Mathematical constant pi.
Definition: constants.h:44
int angular_momentum() const
Returns the shell angular momentum.
Definition: hf/molecularbasis.h:167
void atoms_to_bfn(const MolecularEntity &mentity, std::vector< int > &at_to_bf, std::vector< int > &at_nbf)
Makes map from atoms to first basis function on atom and number of basis functions on atom...
Definition: hf/molecularbasis.h:530
const double R
Definition: dielectric.cc:191
void serialize(Archive &ar)
Definition: hf/molecularbasis.h:204
double rangesq() const
Returns square of the distance beyond which function is less than 1e-8.
Definition: hf/molecularbasis.h:103
double operator()(double x, double y, double z) const
Definition: hf/molecularbasis.h:384
ContractedGaussianShell()
Definition: hf/molecularbasis.h:86
int basisfn_to_atom(const MolecularEntity &mentity, int ibf) const
Returns the number of the atom the ibf'th basis function is on.
Definition: hf/molecularbasis.h:547
const mpreal pow(const mpreal &a, const unsigned int b, mp_rnd_t rnd_mode=mpreal::default_rnd)
Definition: mpreal.h:2788
void serialize(Archive &ar)
Definition: hf/molecularbasis.h:720
double eval_guess_density(double x, double y, double z) const
Evaluates the guess atomic density at point x, y, z relative to atomic center.
Definition: hf/molecularbasis.h:292
const bool debug
Definition: tdse1.cc:45
const ContractedGaussianShell & get_shell_from_basis_function(int ibf, int &ibf_in_shell) const
Return shell that contains basis function ibf and also return index of function in the shell...
Definition: hf/molecularbasis.h:311
const char *const symbol
Definition: chem/atomutil.h:54
void print(const MolecularEntity &mentity) const
Print basis info for atoms in the molecule (once for each unique atom type)
Definition: hf/molecularbasis.h:628
double z
Definition: chem/molecule.h:57
double rangesq() const
Returns square of the distance beyond which function is less than 1e-8.
Definition: chem/molecularbasis.h:104
::std::string string
Definition: gtest-port.h:872
Defines common mathematical and physical constants.
void print_me(std::ostream &s) const
Definition: chem/molecularbasis.cc:73
double eval_radial(double rsq) const
Evaluates the radial part of the contracted function.
Definition: chem/molecularbasis.h:110
int nprim() const
Returns the number of primitives in the contraction.
Definition: hf/molecularbasis.h:177
int nprim() const
Returns the number of primitives in the contraction.
Definition: chem/molecularbasis.h:181
NDIM & f
Definition: mra.h:2179
bool operator()(long i, long j) const
Definition: hf/molecularbasis.h:650
int nbf() const
Returns the number of basis functions in the shell.
Definition: hf/molecularbasis.h:172
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cc:924
AtomicBasisFunction get_atomic_basis_function(const Molecule &molecule, int ibf) const
Returns the ibf'th atomic basis function.
Definition: chem/molecularbasis.h:474
AtomicBasis(const std::vector< ContractedGaussianShell > &g)
Definition: hf/molecularbasis.h:238
int ErrorCol() const
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1475
void print_me(std::ostream &s) const
Definition: hf/molecularbasis.h:394
AtomicBasis()
Definition: hf/molecularbasis.h:236
Represents multiple shells of contracted gaussians on a single center.
Definition: chem/molecularbasis.h:214
double rangesq() const
Definition: hf/molecularbasis.h:415
const char * get_desc(int ibf) const
Returns a string description of the basis function type.
Definition: hf/molecularbasis.h:192
void print_anal(const MolecularEntity &mentity, const Tensor< T > &v)
Given a vector of AO coefficients prints an analysis.
Definition: hf/molecularbasis.h:664
Defines and implements most of Tensor.
Represents a single shell of contracted, Cartesian, Gaussian primitives.
Definition: chem/molecularbasis.h:52
int ErrorRow() const
Definition: tinyxml.h:1474
const AtomicData & get_atomic_data(unsigned int atomic_number)
Definition: chem/atomutil.cc:160
int nshell() const
Returns the number of shells on the center.
Definition: chem/molecularbasis.h:246
const std::vector< double > & get_expnt() const
Returns a const reference to the exponents.
Definition: chem/molecularbasis.h:191
int nbf(const Molecule &molecule) const
Given a molecule count the number of basis functions.
Definition: chem/molecularbasis.h:498
double * eval(double rsq, double x, double y, double z, double *bf) const
Evaluates the entire shell returning the incremented result pointer.
Definition: hf/molecularbasis.h:121
#define max(a, b)
Definition: lda.h:53
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1460
void set_guess_info(const Tensor< double > &dmat, const Tensor< double > &avec, const Tensor< double > &bvec)
Definition: hf/molecularbasis.h:248
double * eval(double x, double y, double z, double *bf) const
Evaluates the basis functions at point x, y, z relative to atomic center.
Definition: hf/molecularbasis.h:275
int get_index() const
Definition: hf/molecularbasis.h:402
const std::vector< double > & get_expnt() const
Returns a const reference to the exponents.
Definition: hf/molecularbasis.h:187
const std::vector< double > & get_coeff() const
Returns a const reference to the coefficients.
Definition: hf/molecularbasis.h:182
const char * get_desc(int ibf) const
Returns a string description of the basis function type.
Definition: chem/molecularbasis.h:196
Used to represent one basis function from a shell on a specific center.
Definition: chem/molecularbasis.h:335
int nbf(const MolecularEntity &mentity) const
Given a molecule count the number of basis functions.
Definition: hf/molecularbasis.h:591
void read_file(std::string filename)
read the atomic basis set from file
Definition: chem/molecularbasis.cc:107
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
const mpreal min(const mpreal &x, const mpreal &y)
Definition: mpreal.h:2675
Definition: tinyxml.h:1386
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cc:431
AtomicBasisSet()
Definition: hf/molecularbasis.h:457
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
unsigned int atomic_number
Atomic number.
Definition: chem/molecule.h:58
const char * get_desc() const
Definition: chem/molecularbasis.h:376
void get_coords(double &x, double &y, double &z) const
Definition: hf/molecularbasis.h:410
const Tensor< double > & get_bvec() const
Definition: hf/molecularbasis.h:338
int basisfn_to_atom(const Molecule &molecule, int ibf) const
Returns the number of the atom the ibf'th basis function is on.
Definition: chem/molecularbasis.h:454
bool is_supported(int atomic_number) const
Definition: chem/molecularbasis.h:530
double eval_guess_density(const MolecularEntity &mentity, double x, double y, double z) const
Evaluates the guess density.
Definition: hf/molecularbasis.h:613
const char * get_desc() const
Definition: hf/molecularbasis.h:406
void eval(const MolecularEntity &mentity, double x, double y, double z, double *bf) const
Evaluates the basis functions.
Definition: hf/molecularbasis.h:603
AtomicBasisFunction(double x, double y, double z, const ContractedGaussianShell &shell, int ibf)
Definition: hf/molecularbasis.h:371
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
bool has_guess_info() const
Definition: chem/molecularbasis.h:311
const Atom & get_atom(unsigned int i) const
Definition: mentity.cc:369
void read_file(std::string filename)
Definition: hf/molecularbasis.h:464
const std::vector< ContractedGaussianShell > & get_shells() const
Returns a const reference to the shells.
Definition: hf/molecularbasis.h:266
double x
Definition: chem/molecule.h:57
Definition: chem/molecule.h:55
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cc:461
double * eval(double rsq, double x, double y, double z, double *bf) const
Evaluates the entire shell returning the incremented result pointer.
Definition: chem/molecularbasis.h:122
double y
Definition: chem/molecule.h:57
const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode)
Definition: mpreal.cc:241
AtomicBasisFunction(const AtomicBasisFunction &aofunc)
Definition: hf/molecularbasis.h:376
const double m
Definition: gfit.cc:199
unsigned int symbol_to_atomic_number(const std::string &symbol)
Definition: chem/atomutil.cc:166
void print_all() const
Print basis info for all supported atoms.
Definition: hf/molecularbasis.h:709
std::ostream & operator<<(std::ostream &s, const ContractedGaussianShell &c)
Definition: chem/molecularbasis.cc:38
Definition: DFcode/molecularbasis.h:597
const Tensor< double > & get_avec() const
Definition: hf/molecularbasis.h:334
const char * Value() const
Definition: tinyxml.h:489
int nbf() const
Returns the number of basis functions on the center.
Definition: chem/molecularbasis.h:241
void serialize(Archive &ar)
Definition: hf/molecularbasis.h:343
AnalysisSorter(const Tensor< T > &v)
Definition: hf/molecularbasis.h:649
Contracted Gaussian basis.
Definition: chem/molecularbasis.h:391
const Tensor< double > & get_dmat() const
Definition: chem/molecularbasis.h:315
double E0(double p)
Definition: gfit.cc:203
const std::vector< double > & get_coeff() const
Returns a const reference to the coefficients.
Definition: chem/molecularbasis.h:186
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
int nshell() const
Returns the number of shells on the center.
Definition: hf/molecularbasis.h:261
const char * GetText() const
Definition: tinyxml.cc:871
AtomicBasisFunction get_atomic_basis_function(const MolecularEntity &mentity, int ibf) const
Returns the ibf'th atomic basis function.
Definition: hf/molecularbasis.h:567
const std::vector< ContractedGaussianShell > & get_shells() const
Returns a const reference to the shells.
Definition: chem/molecularbasis.h:251
const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2187
AtomicBasisSet(std::string filename)
Definition: hf/molecularbasis.h:460
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
const char * Attribute(const char *name) const
Definition: tinyxml.cc:555
int angular_momentum() const
Returns the shell angular momentum.
Definition: chem/molecularbasis.h:171
const ContractedGaussianShell & get_shell() const
Definition: hf/molecularbasis.h:398
double * eval(double x, double y, double z, double *bf) const
Evaluates the basis functions at point x, y, z relative to atomic center.
Definition: chem/molecularbasis.h:260
bool has_guess_info() const
Definition: hf/molecularbasis.h:326
int natom() const
Definition: mentity.h:112
ContractedGaussianShell(int type, const std::vector< double > &coeff, const std::vector< double > &expnt, bool donorm=true)
Definition: hf/molecularbasis.h:89
Definition: tinyxml.h:945
int nbf() const
Returns the number of basis functions in the shell.
Definition: chem/molecularbasis.h:176