2
// File: MPQC_Chemistry_QC_Model_Impl.cc
3
// Symbol: MPQC.Chemistry_QC_Model-v0.2
5
// Babel Version: 0.10.2
6
// Description: Server-side implementation for MPQC.Chemistry_QC_Model
8
// WARNING: Automatically generated; only changes within splicers preserved
10
// babel-version = 0.10.2
12
#include "MPQC_Chemistry_QC_Model_Impl.hh"
14
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._includes)
16
static int ex_counter = 0;
18
#include "Chemistry_Chemistry_Molecule.hh"
19
//#include <util/class/class.h>
24
vector_to_array(const sc::RefSCVector &v);
27
array_to_vector(sidl::array<double>, const sc::RefSCVector &v);
30
array_to_vector(sidl::array<double>, const sc::RefSCVector &v, double conv);
33
matrix_to_array(const sc::RefSymmSCMatrix &v);
36
array_to_matrix(sidl::array<double>, const sc::RefSymmSCMatrix &v);
38
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._includes)
40
// user-defined constructor.
41
void MPQC::Chemistry_QC_Model_impl::_ctor() {
42
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._ctor)
43
// add construction details here
44
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._ctor)
47
// user-defined destructor.
48
void MPQC::Chemistry_QC_Model_impl::_dtor() {
49
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._dtor)
50
// add destruction details here
51
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._dtor)
54
// static class initializer.
55
void MPQC::Chemistry_QC_Model_impl::_load() {
56
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._load)
57
// guaranteed to be called at most once before any other method in this class
58
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._load)
61
// user-defined static methods: (none)
63
// user-defined non-static methods:
65
* Method: initialize_parsedkeyval[]
68
MPQC::Chemistry_QC_Model_impl::initialize_parsedkeyval (
69
/* in */ const ::std::string& keyword,
70
/* in */ const ::std::string& input )
73
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.initialize_parsedkeyval)
75
sc::Ref<sc::ParsedKeyVal> kv = new sc::ParsedKeyVal();
76
//sc::ClassDesc::list_all_classes();
77
kv->parse_string(input.c_str());
78
sc::Ref<sc::DescribedClass> dc;
80
dc = kv->describedclassvalue(keyword.c_str());
82
catch (std::exception &e) {
85
wfn_ = dynamic_cast<sc::Wavefunction*>(dc.pointer());
87
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.initialize_parsedkeyval)
91
* Method: initialize_parsedkeyval_file[]
94
MPQC::Chemistry_QC_Model_impl::initialize_parsedkeyval_file (
95
/* in */ const ::std::string& keyword,
96
/* in */ const ::std::string& filename )
99
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.initialize_parsedkeyval_file)
100
std::cout << "reading " << keyword << " from " << filename << std::endl;
101
sc::Ref<sc::ParsedKeyVal> kv = new sc::ParsedKeyVal(filename.c_str());
102
sc::Ref<sc::DescribedClass> dc = kv->describedclassvalue(keyword.c_str());
104
std::cout << "WARNING: dc is null" << std::endl;
106
wfn_ = dynamic_cast<sc::Wavefunction*>(dc.pointer());
108
std::cout << "WARNING: wfn is null" << std::endl;
110
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.initialize_parsedkeyval_file)
114
* Method: initialize_aggregatekeyval[]
117
MPQC::Chemistry_QC_Model_impl::initialize_aggregatekeyval (
118
/* in */ const ::std::string& keyword,
119
/* in */ const ::std::string& input,
120
/* in */ void* describedclass )
123
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.initialize_aggregatekeyval)
125
// this doesn't seem to work, though JPK and CLJ both think it should
127
std::cout << "Initializing MPQC model using aggregate keyval\n";
129
sc::Ref<sc::ParsedKeyVal> kv = new sc::ParsedKeyVal;
130
kv->parse_string(input.c_str());
132
sc::Ref<sc::DescribedClass>* dc_ptr =
133
static_cast<sc::Ref<sc::DescribedClass>*>(describedclass);
134
sc::Ref<sc::DescribedClass> dc = *dc_ptr;
135
sc::Ref<sc::AssignedKeyVal> akv = new sc::AssignedKeyVal;
136
akv->assign("model:integrals",dc);
138
sc::Ref<sc::AggregateKeyVal> aggkv = new sc::AggregateKeyVal(kv,akv);
140
sc::Ref<sc::DescribedClass> dc2 = aggkv->describedclassvalue(keyword.c_str());
141
wfn_ = dynamic_cast<sc::Wavefunction*>(dc2.pointer());
142
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.initialize_aggregatekeyval)
146
* Method: initialize_pointer[]
149
MPQC::Chemistry_QC_Model_impl::initialize_pointer (
153
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.initialize_pointer)
154
wfn_ = reinterpret_cast<sc::Wavefunction*>(ptr);
155
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.initialize_pointer)
159
* Set the molecule. @param molecule The new molecule.
162
MPQC::Chemistry_QC_Model_impl::set_molecule (
163
/* in */ ::Chemistry::Molecule molecule )
166
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_molecule)
167
molecule_ = molecule;
168
double conv = molecule_.get_units().convert_to("bohr");
169
wfn_->molecule()->print();
170
sc::Molecule* scMol = wfn_->molecule().pointer();
171
for( int i=0; i<molecule_.get_n_atom(); ++i)
172
for( int j=0; j<3; ++j)
173
scMol->r(i)[j] = molecule_.get_cart_coor(i,j)*conv;
174
wfn_->set_x(array_to_vector(molecule_.get_coor(),
175
wfn_->matrixkit()->vector(wfn_->dimension()),conv));
177
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_molecule)
181
* Returns the molecule. @return The Molecule object.
183
::Chemistry::Molecule
184
MPQC::Chemistry_QC_Model_impl::get_molecule ()
188
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_molecule)
190
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_molecule)
194
* Method: get_energy[]
197
MPQC::Chemistry_QC_Model_impl::get_energy ()
199
::sidl::BaseException
202
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_energy)
203
// if ((++ex_counter)%3 == 0) {
204
// sidl::BaseException e = sidl::BaseException::_create();
205
// e.setNote("Simulated Numerical Error");
208
return wfn_->energy();
209
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_energy)
213
* Sets the accuracy for subsequent energy calculations.
214
* @param acc The new accuracy.
217
MPQC::Chemistry_QC_Model_impl::set_energy_accuracy (
218
/* in */ double acc )
221
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_energy_accuracy)
222
wfn_->set_desired_value_accuracy(acc);
223
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_energy_accuracy)
227
* Returns the accuracy to which the energy is already computed.
228
* The result is undefined if the energy has not already been computed.
229
* @return The energy accuracy.
232
MPQC::Chemistry_QC_Model_impl::get_energy_accuracy ()
236
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_energy_accuracy)
237
return wfn_->actual_value_accuracy();
238
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_energy_accuracy)
242
* This allows a programmer to request that if any result is computed,
243
* then the energy is computed too. This allows, say, for a request
244
* for a gradient to cause the energy to be computed. This computed
245
* energy is cached and returned when the get_energy() member is called.
246
* @param doit Whether or not to compute the energy.
249
MPQC::Chemistry_QC_Model_impl::set_do_energy (
253
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_do_energy)
255
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_do_energy)
259
* Returns the Cartesian gradient.
261
::sidl::array<double>
262
MPQC::Chemistry_QC_Model_impl::get_gradient ()
264
::sidl::BaseException
267
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_gradient)
268
return vector_to_array(wfn_->gradient());
269
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_gradient)
273
* Sets the accuracy for subsequent gradient calculations
274
* @param acc The new accuracy for gradients.
277
MPQC::Chemistry_QC_Model_impl::set_gradient_accuracy (
278
/* in */ double acc )
281
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_gradient_accuracy)
282
wfn_->set_desired_gradient_accuracy(acc);
283
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_gradient_accuracy)
287
* Returns the accuracy to which the gradient is already computed.
288
* The result is undefined if the gradient has not already been computed.
289
* @return The current gradient accuracy.
292
MPQC::Chemistry_QC_Model_impl::get_gradient_accuracy ()
296
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_gradient_accuracy)
297
return wfn_->actual_gradient_accuracy();
298
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_gradient_accuracy)
302
* Returns the Cartesian Hessian. @return The Hessian.
304
::sidl::array<double>
305
MPQC::Chemistry_QC_Model_impl::get_hessian ()
307
::sidl::BaseException
310
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_hessian)
311
return matrix_to_array(wfn_->hessian());
312
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_hessian)
316
* Sets the accuracy for subsequent Hessian calculations.
317
* @param acc The new accuracy for Hessians.
320
MPQC::Chemistry_QC_Model_impl::set_hessian_accuracy (
321
/* in */ double acc )
324
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_hessian_accuracy)
325
wfn_->set_desired_hessian_accuracy(acc);
326
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_hessian_accuracy)
330
* Returns the accuracy to which the Hessian is already computed.
331
* The result is undefined if the Hessian has not already been computed.
334
MPQC::Chemistry_QC_Model_impl::get_hessian_accuracy ()
338
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_hessian_accuracy)
339
return wfn_->actual_hessian_accuracy();
340
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_hessian_accuracy)
344
* Returns a Cartesian guess Hessian.
346
::sidl::array<double>
347
MPQC::Chemistry_QC_Model_impl::get_guess_hessian ()
349
::sidl::BaseException
352
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_guess_hessian)
353
sc::RefSymmSCMatrix hess(wfn_->dimension(), wfn_->matrixkit());
354
wfn_->guess_hessian(hess);
355
return matrix_to_array(hess);
356
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_guess_hessian)
360
* Sets the accuracy for subsequent guess Hessian calculations.
361
* @param acc The new accuracy for guess Hessians.
364
MPQC::Chemistry_QC_Model_impl::set_guess_hessian_accuracy (
365
/* in */ double acc )
368
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_guess_hessian_accuracy)
370
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_guess_hessian_accuracy)
374
* Returns the accuracy to which the guess Hessian is already computed.
375
* The result is undefined if the guess Hessian has not already been computed.
376
* @return The guess hessian accuracy.
379
MPQC::Chemistry_QC_Model_impl::get_guess_hessian_accuracy ()
383
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_guess_hessian_accuracy)
385
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_guess_hessian_accuracy)
389
* This can be called when this Model object is no longer needed. No other
390
* members may be called after finalize.
393
MPQC::Chemistry_QC_Model_impl::finalize ()
397
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.finalize)
398
// insert implementation here
399
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.finalize)
403
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._misc)
406
vector_to_array(const sc::RefSCVector &v)
408
sidl::array<double> a = sidl::array<double>::create1d(v.dim().n());
410
for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++)
417
array_to_vector(sidl::array<double> a, const sc::RefSCVector &v)
419
for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++) {
427
array_to_vector(sidl::array<double> a, const sc::RefSCVector &v, double conv)
429
for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++) {
430
v(i) = a.get(ai) * conv;
437
matrix_to_array(const sc::RefSymmSCMatrix &v)
439
sidl::array<double> a = sidl::array<double>::create2dCol(v.dim().n(), v.dim().n());
441
for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++) {
442
for (int j=0,aj=a.lower(1); j<v.dim().n(); j++,aj++) {
443
a.set(ai, aj, v(i,j));
451
array_to_matrix(sidl::array<double> a, const sc::RefSymmSCMatrix &v)
453
for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++) {
454
for (int j=0,aj=a.lower(1); j<v.dim().n(); j++,aj++) {
455
v(i,j) = a.get(ai,aj);
462
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._misc)