[0b990d] | 1 | //
|
---|
| 2 | // wfntest.cc
|
---|
| 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 | #include <util/misc/formio.h>
|
---|
| 29 | #include <util/state/stateio.h>
|
---|
| 30 | #include <util/state/state_text.h>
|
---|
| 31 | #include <util/state/state_bin.h>
|
---|
| 32 |
|
---|
| 33 | #include <chemistry/qc/wfn/density.h>
|
---|
| 34 | #include <chemistry/qc/wfn/obwfn.h>
|
---|
| 35 |
|
---|
| 36 | using namespace std;
|
---|
| 37 | using namespace sc;
|
---|
| 38 |
|
---|
| 39 | // Force linkages:
|
---|
| 40 | static ForceLink<HCoreWfn> fl0;
|
---|
| 41 |
|
---|
| 42 | #include <chemistry/molecule/linkage.h>
|
---|
| 43 |
|
---|
| 44 | void
|
---|
| 45 | density_test(const Ref<Wavefunction> &wfn, double resolution)
|
---|
| 46 | {
|
---|
| 47 | wfn->ao_density()->print("AO Density Matrix");
|
---|
| 48 | wfn->overlap()->print("SO Overlap Matrix");
|
---|
| 49 | wfn->natural_density()->print("Natural Density");
|
---|
| 50 | wfn->natural_orbitals()->print("Natural Orbitals");
|
---|
| 51 |
|
---|
| 52 | Ref<ElectronDensity> ed = new ElectronDensity(wfn);
|
---|
| 53 | Ref<BatchElectronDensity> bed = new BatchElectronDensity(wfn);
|
---|
| 54 |
|
---|
| 55 | SCVector3 r(0,0,0);
|
---|
| 56 | for (double x = 0.0; x < 2.1; x += 0.25) {
|
---|
| 57 | r[0] = x;
|
---|
| 58 | ed->set_x(x);
|
---|
| 59 | bed->set_x(x);
|
---|
| 60 | SCVector3 edg;
|
---|
| 61 | ed->get_gradient(edg);
|
---|
| 62 | ExEnv::out0() << scprintf(" ED: %12.8f; ", ed->value())
|
---|
| 63 | << edg
|
---|
| 64 | << std::endl;
|
---|
| 65 | SCVector3 bedg;
|
---|
| 66 | bed->get_gradient(bedg);
|
---|
| 67 | ExEnv::out0() << scprintf("BED: %12.8f; ", bed->value())
|
---|
| 68 | << bedg
|
---|
| 69 | << std::endl;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | SCVector3 upper, lower;
|
---|
| 73 | bed->boundingbox(DBL_EPSILON,DBL_MAX,lower,upper);
|
---|
| 74 | ExEnv::out0() << "BED BB: " << lower << ", " << upper << std::endl;
|
---|
| 75 | ed->boundingbox(DBL_EPSILON,DBL_MAX,lower,upper);
|
---|
| 76 | ExEnv::out0() << " ED BB: " << lower << ", " << upper << std::endl;
|
---|
| 77 |
|
---|
| 78 | SCVector3 boxsize = upper - lower;
|
---|
| 79 | ExEnv::out0() << "boxsize = " << boxsize << std::endl;
|
---|
| 80 | int nx = int(boxsize[0]/resolution);
|
---|
| 81 | int ny = int(boxsize[1]/resolution);
|
---|
| 82 | int nz = int(boxsize[2]/resolution);
|
---|
| 83 | ExEnv::out0() << "evaluating " << nx*ny*nz << " points" << std::endl;
|
---|
| 84 |
|
---|
| 85 | double nele_bed = 0.0;
|
---|
| 86 | for (int i=0; i<nx; i++) {
|
---|
| 87 | SCVector3 r(i*resolution + lower[0],0.,0.);
|
---|
| 88 | for (int j=0; j<ny; j++) {
|
---|
| 89 | r[1] = j*resolution + lower[1];
|
---|
| 90 | for (int k=0; k<nz; k++) {
|
---|
| 91 | r[2] = k*resolution + lower[2];
|
---|
| 92 | bed->set_x(r);
|
---|
| 93 | nele_bed += bed->value();
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | nele_bed *= resolution*resolution*resolution;
|
---|
| 98 | ExEnv::out0() << scprintf("BED Nele = %12.8f",nele_bed) << std::endl;
|
---|
| 99 |
|
---|
| 100 | double nele_ed = 0.0;
|
---|
| 101 | for (int i=0; i<nx; i++) {
|
---|
| 102 | SCVector3 r(i*resolution + lower[0],0.,0.);
|
---|
| 103 | for (int j=0; j<ny; j++) {
|
---|
| 104 | r[1] = j*resolution + lower[1];
|
---|
| 105 | for (int k=0; k<nz; k++) {
|
---|
| 106 | r[2] = k*resolution + lower[2];
|
---|
| 107 | ed->set_x(r);
|
---|
| 108 | nele_ed += ed->value();
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | nele_ed *= resolution*resolution*resolution;
|
---|
| 113 | ExEnv::out0() << scprintf(" ED Nele = %12.8f",nele_ed) << std::endl;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | main(int argc, char *argv[])
|
---|
| 117 | {
|
---|
| 118 | const char *input = (argc > 1) ? argv[1] : SRCDIR "/wfntest.kv";
|
---|
| 119 |
|
---|
| 120 | Ref<KeyVal> rpkv(new ParsedKeyVal(input));
|
---|
| 121 |
|
---|
| 122 | // the output stream is standard out
|
---|
| 123 | ostream &o = cout;
|
---|
| 124 |
|
---|
| 125 | Ref<OneBodyWavefunction> wfn;
|
---|
| 126 | wfn << rpkv->describedclassvalue("wavefunction");
|
---|
| 127 | if (wfn.null()) {
|
---|
| 128 | ExEnv::err0() << "wfn is null\n";
|
---|
| 129 | exit(1);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | double resolution = rpkv->doublevalue("resolution");
|
---|
| 133 | density_test(wfn,resolution);
|
---|
| 134 |
|
---|
| 135 | wfn->overlap()->print("overlap");
|
---|
| 136 | wfn->core_hamiltonian()->print("Hcore");
|
---|
| 137 | wfn->hcore_guess()->print("guess vector");
|
---|
| 138 | wfn->density()->print("density");
|
---|
| 139 | wfn->natural_orbitals()->print("natural orbitals");
|
---|
| 140 | wfn->natural_density()->print("natural density");
|
---|
| 141 |
|
---|
| 142 | //wfn->print(o);
|
---|
| 143 | //o << endl;
|
---|
| 144 |
|
---|
| 145 | Ref<OneBodyWavefunction> oldwfn;
|
---|
| 146 | oldwfn << rpkv->describedclassvalue("pwavefunction");
|
---|
| 147 |
|
---|
| 148 | RefSCMatrix evecs = wfn->projected_eigenvectors(oldwfn);
|
---|
| 149 |
|
---|
| 150 | evecs.print("projected wavefunction");
|
---|
| 151 |
|
---|
| 152 | StateOutBin so("wfn.ckpt");
|
---|
| 153 | SavableState::save_state(wfn.pointer(),so);
|
---|
| 154 | so.close();
|
---|
| 155 |
|
---|
| 156 | Ref<MolecularEnergy> me;
|
---|
| 157 | StateInBin si("wfn.ckpt");
|
---|
| 158 | me << SavableState::restore_state(si);
|
---|
| 159 |
|
---|
| 160 | me->print(o);
|
---|
| 161 | o << me->value();
|
---|
| 162 |
|
---|
| 163 | return 0;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 167 |
|
---|
| 168 | // Local Variables:
|
---|
| 169 | // mode: c++
|
---|
| 170 | // c-file-style: "ETS"
|
---|
| 171 | // End:
|
---|