~ubuntu-branches/ubuntu/oneiric/mpqc/oneiric

« back to all changes in this revision

Viewing changes to src/lib/chemistry/cca/MPQC_Chemistry_QC_Model_Impl.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2005-11-27 11:41:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127114149-zgz9r3gk50w8ww2q
Tags: 2.3.0-1
* New upstream release.
* debian/rules (SONAME): Activate awk snippet for automatic so-name
  detection again, resulting in a bump to `7' and making a `c2a' for
  the C++ allocator change unnecessary; closes: #339232.
* debian/patches/00list (08_gcc-4.0_fixes): Removed, no longer needed.
* debian/rules (test): Remove workarounds, do not abort build if tests
  fail.
* debian/ref: Removed.
* debian/control.in (libsc): Added Conflict against libsc6c2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// File:          MPQC_Chemistry_QC_Model_Impl.cc
 
3
// Symbol:        MPQC.Chemistry_QC_Model-v0.2
 
4
// Symbol Type:   class
 
5
// Babel Version: 0.10.2
 
6
// Description:   Server-side implementation for MPQC.Chemistry_QC_Model
 
7
// 
 
8
// WARNING: Automatically generated; only changes within splicers preserved
 
9
// 
 
10
// babel-version = 0.10.2
 
11
// 
 
12
#include "MPQC_Chemistry_QC_Model_Impl.hh"
 
13
 
 
14
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._includes)
 
15
 
 
16
static int ex_counter = 0;
 
17
 
 
18
#include "Chemistry_Chemistry_Molecule.hh"
 
19
//#include <util/class/class.h>
 
20
#include <iostream>
 
21
using namespace std;
 
22
 
 
23
sidl::array<double>
 
24
vector_to_array(const sc::RefSCVector &v);
 
25
 
 
26
sc::RefSCVector
 
27
array_to_vector(sidl::array<double>, const sc::RefSCVector &v);
 
28
 
 
29
sc::RefSCVector
 
30
array_to_vector(sidl::array<double>, const sc::RefSCVector &v, double conv);
 
31
 
 
32
sidl::array<double>
 
33
matrix_to_array(const sc::RefSymmSCMatrix &v);
 
34
 
 
35
sc::RefSymmSCMatrix
 
36
array_to_matrix(sidl::array<double>, const sc::RefSymmSCMatrix &v);
 
37
 
 
38
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._includes)
 
39
 
 
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)
 
45
}
 
46
 
 
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)
 
52
}
 
53
 
 
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)
 
59
}
 
60
 
 
61
// user-defined static methods: (none)
 
62
 
 
63
// user-defined non-static methods:
 
64
/**
 
65
 * Method:  initialize_parsedkeyval[]
 
66
 */
 
67
void
 
68
MPQC::Chemistry_QC_Model_impl::initialize_parsedkeyval (
 
69
  /* in */ const ::std::string& keyword,
 
70
  /* in */ const ::std::string& input ) 
 
71
throw () 
 
72
{
 
73
  // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.initialize_parsedkeyval)
 
74
 
 
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;
 
79
  try {
 
80
    dc = kv->describedclassvalue(keyword.c_str());
 
81
  }
 
82
  catch (std::exception &e) {
 
83
    e.what();
 
84
  }
 
85
  wfn_ = dynamic_cast<sc::Wavefunction*>(dc.pointer());
 
86
 
 
87
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.initialize_parsedkeyval)
 
88
}
 
89
 
 
90
/**
 
91
 * Method:  initialize_parsedkeyval_file[]
 
92
 */
 
93
void
 
94
MPQC::Chemistry_QC_Model_impl::initialize_parsedkeyval_file (
 
95
  /* in */ const ::std::string& keyword,
 
96
  /* in */ const ::std::string& filename ) 
 
97
throw () 
 
98
{
 
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());
 
103
  if (dc.null()) {
 
104
      std::cout << "WARNING: dc is null" << std::endl;
 
105
    }
 
106
  wfn_ = dynamic_cast<sc::Wavefunction*>(dc.pointer());
 
107
  if (wfn_.null()) {
 
108
      std::cout << "WARNING: wfn is null" << std::endl;
 
109
    }
 
110
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.initialize_parsedkeyval_file)
 
111
}
 
112
 
 
113
/**
 
114
 * Method:  initialize_aggregatekeyval[]
 
115
 */
 
116
void
 
117
MPQC::Chemistry_QC_Model_impl::initialize_aggregatekeyval (
 
118
  /* in */ const ::std::string& keyword,
 
119
  /* in */ const ::std::string& input,
 
120
  /* in */ void* describedclass ) 
 
121
throw () 
 
122
{
 
123
  // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.initialize_aggregatekeyval)
 
124
 
 
125
  // this doesn't seem to work, though JPK and CLJ both think it should
 
126
 
 
127
  std::cout << "Initializing MPQC model using aggregate keyval\n";
 
128
  
 
129
  sc::Ref<sc::ParsedKeyVal> kv = new sc::ParsedKeyVal;
 
130
  kv->parse_string(input.c_str());
 
131
  
 
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);
 
137
 
 
138
  sc::Ref<sc::AggregateKeyVal> aggkv = new sc::AggregateKeyVal(kv,akv);
 
139
 
 
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)
 
143
}
 
144
 
 
145
/**
 
146
 * Method:  initialize_pointer[]
 
147
 */
 
148
void
 
149
MPQC::Chemistry_QC_Model_impl::initialize_pointer (
 
150
  /* in */ void* ptr ) 
 
151
throw () 
 
152
{
 
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)
 
156
}
 
157
 
 
158
/**
 
159
 * Set the molecule. @param molecule The new molecule. 
 
160
 */
 
161
void
 
162
MPQC::Chemistry_QC_Model_impl::set_molecule (
 
163
  /* in */ ::Chemistry::Molecule molecule ) 
 
164
throw () 
 
165
{
 
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));
 
176
  return;
 
177
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_molecule)
 
178
}
 
179
 
 
180
/**
 
181
 * Returns the molecule.  @return The Molecule object. 
 
182
 */
 
183
::Chemistry::Molecule
 
184
MPQC::Chemistry_QC_Model_impl::get_molecule ()
 
185
throw () 
 
186
 
 
187
{
 
188
  // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_molecule)
 
189
  return molecule_;
 
190
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_molecule)
 
191
}
 
192
 
 
193
/**
 
194
 * Method:  get_energy[]
 
195
 */
 
196
double
 
197
MPQC::Chemistry_QC_Model_impl::get_energy ()
 
198
throw ( 
 
199
  ::sidl::BaseException
 
200
)
 
201
{
 
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");
 
206
 //     throw e;
 
207
 //   }
 
208
  return wfn_->energy();
 
209
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_energy)
 
210
}
 
211
 
 
212
/**
 
213
 * Sets the accuracy for subsequent energy calculations.
 
214
 * @param acc The new accuracy. 
 
215
 */
 
216
void
 
217
MPQC::Chemistry_QC_Model_impl::set_energy_accuracy (
 
218
  /* in */ double acc ) 
 
219
throw () 
 
220
{
 
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)
 
224
}
 
225
 
 
226
/**
 
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. 
 
230
 */
 
231
double
 
232
MPQC::Chemistry_QC_Model_impl::get_energy_accuracy ()
 
233
throw () 
 
234
 
 
235
{
 
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)
 
239
}
 
240
 
 
241
/**
 
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.
 
247
 */
 
248
void
 
249
MPQC::Chemistry_QC_Model_impl::set_do_energy (
 
250
  /* in */ bool doit ) 
 
251
throw () 
 
252
{
 
253
  // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_do_energy)
 
254
  wfn_->do_value(1);
 
255
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_do_energy)
 
256
}
 
257
 
 
258
/**
 
259
 * Returns the Cartesian gradient.  
 
260
 */
 
261
::sidl::array<double>
 
262
MPQC::Chemistry_QC_Model_impl::get_gradient ()
 
263
throw ( 
 
264
  ::sidl::BaseException
 
265
)
 
266
{
 
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)
 
270
}
 
271
 
 
272
/**
 
273
 * Sets the accuracy for subsequent gradient calculations
 
274
 * @param acc The new accuracy for gradients. 
 
275
 */
 
276
void
 
277
MPQC::Chemistry_QC_Model_impl::set_gradient_accuracy (
 
278
  /* in */ double acc ) 
 
279
throw () 
 
280
{
 
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)
 
284
}
 
285
 
 
286
/**
 
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. 
 
290
 */
 
291
double
 
292
MPQC::Chemistry_QC_Model_impl::get_gradient_accuracy ()
 
293
throw () 
 
294
 
 
295
{
 
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)
 
299
}
 
300
 
 
301
/**
 
302
 * Returns the Cartesian Hessian. @return The Hessian. 
 
303
 */
 
304
::sidl::array<double>
 
305
MPQC::Chemistry_QC_Model_impl::get_hessian ()
 
306
throw ( 
 
307
  ::sidl::BaseException
 
308
)
 
309
{
 
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)
 
313
}
 
314
 
 
315
/**
 
316
 * Sets the accuracy for subsequent Hessian calculations.
 
317
 * @param acc The new accuracy for Hessians. 
 
318
 */
 
319
void
 
320
MPQC::Chemistry_QC_Model_impl::set_hessian_accuracy (
 
321
  /* in */ double acc ) 
 
322
throw () 
 
323
{
 
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)
 
327
}
 
328
 
 
329
/**
 
330
 * Returns the accuracy to which the Hessian is already computed.
 
331
 * The result is undefined if the Hessian has not already been computed. 
 
332
 */
 
333
double
 
334
MPQC::Chemistry_QC_Model_impl::get_hessian_accuracy ()
 
335
throw () 
 
336
 
 
337
{
 
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)
 
341
}
 
342
 
 
343
/**
 
344
 * Returns a Cartesian guess Hessian. 
 
345
 */
 
346
::sidl::array<double>
 
347
MPQC::Chemistry_QC_Model_impl::get_guess_hessian ()
 
348
throw ( 
 
349
  ::sidl::BaseException
 
350
)
 
351
{
 
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)
 
357
}
 
358
 
 
359
/**
 
360
 * Sets the accuracy for subsequent guess Hessian calculations.
 
361
 * @param acc The new accuracy for guess Hessians. 
 
362
 */
 
363
void
 
364
MPQC::Chemistry_QC_Model_impl::set_guess_hessian_accuracy (
 
365
  /* in */ double acc ) 
 
366
throw () 
 
367
{
 
368
  // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.set_guess_hessian_accuracy)
 
369
  // noop
 
370
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.set_guess_hessian_accuracy)
 
371
}
 
372
 
 
373
/**
 
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.  
 
377
 */
 
378
double
 
379
MPQC::Chemistry_QC_Model_impl::get_guess_hessian_accuracy ()
 
380
throw () 
 
381
 
 
382
{
 
383
  // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model.get_guess_hessian_accuracy)
 
384
  return DBL_EPSILON;
 
385
  // DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model.get_guess_hessian_accuracy)
 
386
}
 
387
 
 
388
/**
 
389
 * This can be called when this Model object is no longer needed.  No other
 
390
 * members may be called after finalize. 
 
391
 */
 
392
int32_t
 
393
MPQC::Chemistry_QC_Model_impl::finalize ()
 
394
throw () 
 
395
 
 
396
{
 
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)
 
400
}
 
401
 
 
402
 
 
403
// DO-NOT-DELETE splicer.begin(MPQC.Chemistry_QC_Model._misc)
 
404
 
 
405
sidl::array<double>
 
406
vector_to_array(const sc::RefSCVector &v)
 
407
{
 
408
  sidl::array<double> a = sidl::array<double>::create1d(v.dim().n());
 
409
 
 
410
  for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++)
 
411
      a.set(ai, v(i));
 
412
 
 
413
  return a;
 
414
}
 
415
 
 
416
sc::RefSCVector
 
417
array_to_vector(sidl::array<double> a, const sc::RefSCVector &v)
 
418
{
 
419
  for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++) {
 
420
      v(i) = a.get(ai);
 
421
    }
 
422
 
 
423
  return v;
 
424
}
 
425
 
 
426
sc::RefSCVector
 
427
array_to_vector(sidl::array<double> a, const sc::RefSCVector &v, double conv)
 
428
{
 
429
  for (int i=0,ai=a.lower(0); i<v.dim().n(); i++,ai++) {
 
430
      v(i) = a.get(ai) * conv;
 
431
    }
 
432
 
 
433
  return v;
 
434
}
 
435
 
 
436
sidl::array<double>
 
437
matrix_to_array(const sc::RefSymmSCMatrix &v)
 
438
{
 
439
  sidl::array<double> a = sidl::array<double>::create2dCol(v.dim().n(), v.dim().n());
 
440
 
 
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));
 
444
        }
 
445
    }
 
446
 
 
447
  return a;
 
448
}
 
449
 
 
450
sc::RefSymmSCMatrix
 
451
array_to_matrix(sidl::array<double> a, const sc::RefSymmSCMatrix &v)
 
452
{
 
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);
 
456
        }
 
457
    }
 
458
 
 
459
  return v;
 
460
}
 
461
 
 
462
// DO-NOT-DELETE splicer.end(MPQC.Chemistry_QC_Model._misc)
 
463