source: ThirdParty/mpqc_open/src/lib/chemistry/cca/MPQC_Chemistry_QC_Model_Impl.cc

Candidate_v1.6.1
Last change on this file was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 13.0 KB
Line 
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
16static int ex_counter = 0;
17
18#include "Chemistry_Chemistry_Molecule.hh"
19//#include <util/class/class.h>
20#include <iostream>
21using namespace std;
22
23sidl::array<double>
24vector_to_array(const sc::RefSCVector &v);
25
26sc::RefSCVector
27array_to_vector(sidl::array<double>, const sc::RefSCVector &v);
28
29sc::RefSCVector
30array_to_vector(sidl::array<double>, const sc::RefSCVector &v, double conv);
31
32sidl::array<double>
33matrix_to_array(const sc::RefSymmSCMatrix &v);
34
35sc::RefSymmSCMatrix
36array_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.
41void 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.
48void 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.
55void 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 */
67void
68MPQC::Chemistry_QC_Model_impl::initialize_parsedkeyval (
69 /* in */ const ::std::string& keyword,
70 /* in */ const ::std::string& input )
71throw ()
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 */
93void
94MPQC::Chemistry_QC_Model_impl::initialize_parsedkeyval_file (
95 /* in */ const ::std::string& keyword,
96 /* in */ const ::std::string& filename )
97throw ()
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 */
116void
117MPQC::Chemistry_QC_Model_impl::initialize_aggregatekeyval (
118 /* in */ const ::std::string& keyword,
119 /* in */ const ::std::string& input,
120 /* in */ void* describedclass )
121throw ()
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 */
148void
149MPQC::Chemistry_QC_Model_impl::initialize_pointer (
150 /* in */ void* ptr )
151throw ()
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 */
161void
162MPQC::Chemistry_QC_Model_impl::set_molecule (
163 /* in */ ::Chemistry::Molecule molecule )
164throw ()
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
184MPQC::Chemistry_QC_Model_impl::get_molecule ()
185throw ()
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 */
196double
197MPQC::Chemistry_QC_Model_impl::get_energy ()
198throw (
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 */
216void
217MPQC::Chemistry_QC_Model_impl::set_energy_accuracy (
218 /* in */ double acc )
219throw ()
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 */
231double
232MPQC::Chemistry_QC_Model_impl::get_energy_accuracy ()
233throw ()
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 */
248void
249MPQC::Chemistry_QC_Model_impl::set_do_energy (
250 /* in */ bool doit )
251throw ()
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>
262MPQC::Chemistry_QC_Model_impl::get_gradient ()
263throw (
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 */
276void
277MPQC::Chemistry_QC_Model_impl::set_gradient_accuracy (
278 /* in */ double acc )
279throw ()
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 */
291double
292MPQC::Chemistry_QC_Model_impl::get_gradient_accuracy ()
293throw ()
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>
305MPQC::Chemistry_QC_Model_impl::get_hessian ()
306throw (
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 */
319void
320MPQC::Chemistry_QC_Model_impl::set_hessian_accuracy (
321 /* in */ double acc )
322throw ()
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 */
333double
334MPQC::Chemistry_QC_Model_impl::get_hessian_accuracy ()
335throw ()
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>
347MPQC::Chemistry_QC_Model_impl::get_guess_hessian ()
348throw (
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 */
363void
364MPQC::Chemistry_QC_Model_impl::set_guess_hessian_accuracy (
365 /* in */ double acc )
366throw ()
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 */
378double
379MPQC::Chemistry_QC_Model_impl::get_guess_hessian_accuracy ()
380throw ()
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 */
392int32_t
393MPQC::Chemistry_QC_Model_impl::finalize ()
394throw ()
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
405sidl::array<double>
406vector_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
416sc::RefSCVector
417array_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
426sc::RefSCVector
427array_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
436sidl::array<double>
437matrix_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
450sc::RefSymmSCMatrix
451array_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
Note: See TracBrowser for help on using the repository browser.