source: src/molecule_geometry.cpp@ 1bd79e

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 Candidate_v1.7.0 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 1bd79e was 1bd79e, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Changed implementation of Vector to forward operations to contained objects

  • Property mode set to 100644
File size: 17.1 KB
Line 
1/*
2 * molecule_geometry.cpp
3 *
4 * Created on: Oct 5, 2009
5 * Author: heber
6 */
7
8#include "atom.hpp"
9#include "bond.hpp"
10#include "config.hpp"
11#include "element.hpp"
12#include "helpers.hpp"
13#include "leastsquaremin.hpp"
14#include "log.hpp"
15#include "memoryallocator.hpp"
16#include "molecule.hpp"
17
18/************************************* Functions for class molecule *********************************/
19
20
21/** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths.
22 * \param *out output stream for debugging
23 */
24bool molecule::CenterInBox()
25{
26 bool status = true;
27 const Vector *Center = DetermineCenterOfAll();
28 double *M = ReturnFullMatrixforSymmetric(cell_size);
29 double *Minv = InverseMatrix(M);
30
31 // go through all atoms
32 ActOnAllVectors( &Vector::SubtractVector, *Center);
33 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
34
35 Free(&M);
36 Free(&Minv);
37 delete(Center);
38 return status;
39};
40
41
42/** Bounds the molecule in the box whose lengths are defined by vector \a *BoxLengths.
43 * \param *out output stream for debugging
44 */
45bool molecule::BoundInBox()
46{
47 bool status = true;
48 double *M = ReturnFullMatrixforSymmetric(cell_size);
49 double *Minv = InverseMatrix(M);
50
51 // go through all atoms
52 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
53
54 Free(&M);
55 Free(&Minv);
56 return status;
57};
58
59/** Centers the edge of the atoms at (0,0,0).
60 * \param *out output stream for debugging
61 * \param *max coordinates of other edge, specifying box dimensions.
62 */
63void molecule::CenterEdge(Vector *max)
64{
65 Vector *min = new Vector;
66
67// Log() << Verbose(3) << "Begin of CenterEdge." << endl;
68 atom *ptr = start->next; // start at first in list
69 if (ptr != end) { //list not empty?
70 for (int i=NDIM;i--;) {
71 max->at(i) = ptr->x[i];
72 min->at(i) = ptr->x[i];
73 }
74 while (ptr->next != end) { // continue with second if present
75 ptr = ptr->next;
76 //ptr->Output(1,1,out);
77 for (int i=NDIM;i--;) {
78 max->at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i);
79 min->at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i);
80 }
81 }
82// Log() << Verbose(4) << "Maximum is ";
83// max->Output(out);
84// Log() << Verbose(0) << ", Minimum is ";
85// min->Output(out);
86// Log() << Verbose(0) << endl;
87 min->Scale(-1.);
88 (*max) += (*min);
89 Translate(min);
90 Center.Zero();
91 }
92 delete(min);
93// Log() << Verbose(3) << "End of CenterEdge." << endl;
94};
95
96/** Centers the center of the atoms at (0,0,0).
97 * \param *out output stream for debugging
98 * \param *center return vector for translation vector
99 */
100void molecule::CenterOrigin()
101{
102 int Num = 0;
103 atom *ptr = start; // start at first in list
104
105 Center.Zero();
106
107 if (ptr->next != end) { //list not empty?
108 while (ptr->next != end) { // continue with second if present
109 ptr = ptr->next;
110 Num++;
111 Center += ptr->x;
112 }
113 Center.Scale(-1./Num); // divide through total number (and sign for direction)
114 Translate(&Center);
115 Center.Zero();
116 }
117};
118
119/** Returns vector pointing to center of all atoms.
120 * \return pointer to center of all vector
121 */
122Vector * molecule::DetermineCenterOfAll() const
123{
124 atom *ptr = start->next; // start at first in list
125 Vector *a = new Vector();
126 Vector tmp;
127 double Num = 0;
128
129 a->Zero();
130
131 if (ptr != end) { //list not empty?
132 while (ptr->next != end) { // continue with second if present
133 ptr = ptr->next;
134 Num += 1.;
135 tmp = ptr->x;
136 (*a) += tmp;
137 }
138 a->Scale(1./Num); // divide through total mass (and sign for direction)
139 }
140 return a;
141};
142
143/** Returns vector pointing to center of gravity.
144 * \param *out output stream for debugging
145 * \return pointer to center of gravity vector
146 */
147Vector * molecule::DetermineCenterOfGravity()
148{
149 atom *ptr = start->next; // start at first in list
150 Vector *a = new Vector();
151 Vector tmp;
152 double Num = 0;
153
154 a->Zero();
155
156 if (ptr != end) { //list not empty?
157 while (ptr->next != end) { // continue with second if present
158 ptr = ptr->next;
159 Num += ptr->type->mass;
160 tmp = ptr->type->mass * ptr->x;
161 (*a) += tmp;
162 }
163 a->Scale(-1./Num); // divide through total mass (and sign for direction)
164 }
165// Log() << Verbose(1) << "Resulting center of gravity: ";
166// a->Output(out);
167// Log() << Verbose(0) << endl;
168 return a;
169};
170
171/** Centers the center of gravity of the atoms at (0,0,0).
172 * \param *out output stream for debugging
173 * \param *center return vector for translation vector
174 */
175void molecule::CenterPeriodic()
176{
177 DeterminePeriodicCenter(Center);
178};
179
180
181/** Centers the center of gravity of the atoms at (0,0,0).
182 * \param *out output stream for debugging
183 * \param *center return vector for translation vector
184 */
185void molecule::CenterAtVector(Vector *newcenter)
186{
187 Center = *newcenter;
188};
189
190
191/** Scales all atoms by \a *factor.
192 * \param *factor pointer to scaling factor
193 *
194 * TODO: Is this realy what is meant, i.e.
195 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl)
196 * or rather
197 * x=(**factor) * x (as suggested by comment)
198 */
199void molecule::Scale(const double ** const factor)
200{
201 atom *ptr = start;
202
203 while (ptr->next != end) {
204 ptr = ptr->next;
205 for (int j=0;j<MDSteps;j++)
206 ptr->Trajectory.R.at(j).ScaleAll(*factor);
207 ptr->x.ScaleAll(*factor);
208 }
209};
210
211/** Translate all atoms by given vector.
212 * \param trans[] translation vector.
213 */
214void molecule::Translate(const Vector *trans)
215{
216 atom *ptr = start;
217
218 while (ptr->next != end) {
219 ptr = ptr->next;
220 for (int j=0;j<MDSteps;j++)
221 ptr->Trajectory.R.at(j) += (*trans);
222 ptr->x += (*trans);
223 }
224};
225
226/** Translate the molecule periodically in the box.
227 * \param trans[] translation vector.
228 * TODO treatment of trajetories missing
229 */
230void molecule::TranslatePeriodically(const Vector *trans)
231{
232 double *M = ReturnFullMatrixforSymmetric(cell_size);
233 double *Minv = InverseMatrix(M);
234
235 // go through all atoms
236 ActOnAllVectors( &Vector::SubtractVector, *trans);
237 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
238
239 Free(&M);
240 Free(&Minv);
241};
242
243
244/** Mirrors all atoms against a given plane.
245 * \param n[] normal vector of mirror plane.
246 */
247void molecule::Mirror(const Vector *n)
248{
249 ActOnAllVectors( &Vector::Mirror, *n );
250};
251
252/** Determines center of molecule (yet not considering atom masses).
253 * \param center reference to return vector
254 */
255void molecule::DeterminePeriodicCenter(Vector &center)
256{
257 atom *Walker = start;
258 double *matrix = ReturnFullMatrixforSymmetric(cell_size);
259 double *inversematrix = InverseMatrix(cell_size);
260 double tmp;
261 bool flag;
262 Vector Testvector, Translationvector;
263
264 do {
265 Center.Zero();
266 flag = true;
267 while (Walker->next != end) {
268 Walker = Walker->next;
269#ifdef ADDHYDROGEN
270 if (Walker->type->Z != 1) {
271#endif
272 Testvector = Walker->x;
273 Testvector.MatrixMultiplication(inversematrix);
274 Translationvector.Zero();
275 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
276 if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing
277 for (int j=0;j<NDIM;j++) {
278 tmp = Walker->x[j] - (*Runner)->GetOtherAtom(Walker)->x[j];
279 if ((fabs(tmp)) > BondDistance) {
280 flag = false;
281 Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl;
282 if (tmp > 0)
283 Translationvector[j] -= 1.;
284 else
285 Translationvector[j] += 1.;
286 }
287 }
288 }
289 Testvector += Translationvector;
290 Testvector.MatrixMultiplication(matrix);
291 Center += Testvector;
292 Log() << Verbose(1) << "vector is: " << Testvector << endl;
293#ifdef ADDHYDROGEN
294 // now also change all hydrogens
295 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
296 if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) {
297 Testvector = (*Runner)->GetOtherAtom(Walker)->x;
298 Testvector.MatrixMultiplication(inversematrix);
299 Testvector += Translationvector;
300 Testvector.MatrixMultiplication(matrix);
301 Center += Testvector;
302 Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl;
303 }
304 }
305 }
306#endif
307 }
308 } while (!flag);
309 Free(&matrix);
310 Free(&inversematrix);
311
312 Center.Scale(1./(double)AtomCount);
313};
314
315/** Transforms/Rotates the given molecule into its principal axis system.
316 * \param *out output stream for debugging
317 * \param DoRotate whether to rotate (true) or only to determine the PAS.
318 * TODO treatment of trajetories missing
319 */
320void molecule::PrincipalAxisSystem(bool DoRotate)
321{
322 atom *ptr = start; // start at first in list
323 double InertiaTensor[NDIM*NDIM];
324 Vector *CenterOfGravity = DetermineCenterOfGravity();
325
326 CenterPeriodic();
327
328 // reset inertia tensor
329 for(int i=0;i<NDIM*NDIM;i++)
330 InertiaTensor[i] = 0.;
331
332 // sum up inertia tensor
333 while (ptr->next != end) {
334 ptr = ptr->next;
335 Vector x = ptr->x;
336 //x.SubtractVector(CenterOfGravity);
337 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
338 InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
339 InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
340 InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
341 InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
342 InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
343 InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
344 InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
345 InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
346 }
347 // print InertiaTensor for debugging
348 Log() << Verbose(0) << "The inertia tensor is:" << endl;
349 for(int i=0;i<NDIM;i++) {
350 for(int j=0;j<NDIM;j++)
351 Log() << Verbose(0) << InertiaTensor[i*NDIM+j] << " ";
352 Log() << Verbose(0) << endl;
353 }
354 Log() << Verbose(0) << endl;
355
356 // diagonalize to determine principal axis system
357 gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM);
358 gsl_matrix_view m = gsl_matrix_view_array(InertiaTensor, NDIM, NDIM);
359 gsl_vector *eval = gsl_vector_alloc(NDIM);
360 gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM);
361 gsl_eigen_symmv(&m.matrix, eval, evec, T);
362 gsl_eigen_symmv_free(T);
363 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);
364
365 for(int i=0;i<NDIM;i++) {
366 Log() << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i);
367 Log() << Verbose(0) << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl;
368 }
369
370 // check whether we rotate or not
371 if (DoRotate) {
372 Log() << Verbose(1) << "Transforming molecule into PAS ... ";
373 // the eigenvectors specify the transformation matrix
374 ActOnAllVectors( &Vector::MatrixMultiplication, (const double *) evec->data );
375 Log() << Verbose(0) << "done." << endl;
376
377 // summing anew for debugging (resulting matrix has to be diagonal!)
378 // reset inertia tensor
379 for(int i=0;i<NDIM*NDIM;i++)
380 InertiaTensor[i] = 0.;
381
382 // sum up inertia tensor
383 ptr = start;
384 while (ptr->next != end) {
385 ptr = ptr->next;
386 Vector x = ptr->x;
387 //x.SubtractVector(CenterOfGravity);
388 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
389 InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
390 InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
391 InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
392 InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
393 InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
394 InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
395 InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
396 InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
397 }
398 // print InertiaTensor for debugging
399 Log() << Verbose(0) << "The inertia tensor is:" << endl;
400 for(int i=0;i<NDIM;i++) {
401 for(int j=0;j<NDIM;j++)
402 Log() << Verbose(0) << InertiaTensor[i*NDIM+j] << " ";
403 Log() << Verbose(0) << endl;
404 }
405 Log() << Verbose(0) << endl;
406 }
407
408 // free everything
409 delete(CenterOfGravity);
410 gsl_vector_free(eval);
411 gsl_matrix_free(evec);
412};
413
414
415/** Align all atoms in such a manner that given vector \a *n is along z axis.
416 * \param n[] alignment vector.
417 */
418void molecule::Align(Vector *n)
419{
420 atom *ptr = start;
421 double alpha, tmp;
422 Vector z_axis;
423 z_axis[0] = 0.;
424 z_axis[1] = 0.;
425 z_axis[2] = 1.;
426
427 // rotate on z-x plane
428 Log() << Verbose(0) << "Begin of Aligning all atoms." << endl;
429 alpha = atan(-n->at(0)/n->at(2));
430 Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ";
431 while (ptr->next != end) {
432 ptr = ptr->next;
433 tmp = ptr->x[0];
434 ptr->x[0] = cos(alpha) * tmp + sin(alpha) * ptr->x[2];
435 ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
436 for (int j=0;j<MDSteps;j++) {
437 tmp = ptr->Trajectory.R.at(j)[0];
438 ptr->Trajectory.R.at(j)[0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
439 ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
440 }
441 }
442 // rotate n vector
443 tmp = n->at(0);
444 n->at(0) = cos(alpha) * tmp + sin(alpha) * n->at(2);
445 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2);
446 Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl;
447
448 // rotate on z-y plane
449 ptr = start;
450 alpha = atan(-n->at(1)/n->at(2));
451 Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ";
452 while (ptr->next != end) {
453 ptr = ptr->next;
454 tmp = ptr->x[1];
455 ptr->x[1] = cos(alpha) * tmp + sin(alpha) * ptr->x[2];
456 ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
457 for (int j=0;j<MDSteps;j++) {
458 tmp = ptr->Trajectory.R.at(j)[1];
459 ptr->Trajectory.R.at(j)[1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
460 ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
461 }
462 }
463 // rotate n vector (for consistency check)
464 tmp = n->at(1);
465 n->at(1) = cos(alpha) * tmp + sin(alpha) * n->at(2);
466 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2);
467
468 Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl;
469 Log() << Verbose(0) << "End of Aligning all atoms." << endl;
470};
471
472
473/** Calculates sum over least square distance to line hidden in \a *x.
474 * \param *x offset and direction vector
475 * \param *params pointer to lsq_params structure
476 * \return \f$ sum_i^N | y_i - (a + t_i b)|^2\f$
477 */
478double LeastSquareDistance (const gsl_vector * x, void * params)
479{
480 double res = 0, t;
481 Vector a,b,c,d;
482 struct lsq_params *par = (struct lsq_params *)params;
483 atom *ptr = par->mol->start;
484
485 // initialize vectors
486 a[0] = gsl_vector_get(x,0);
487 a[1] = gsl_vector_get(x,1);
488 a[2] = gsl_vector_get(x,2);
489 b[0] = gsl_vector_get(x,3);
490 b[1] = gsl_vector_get(x,4);
491 b[2] = gsl_vector_get(x,5);
492 // go through all atoms
493 while (ptr != par->mol->end) {
494 ptr = ptr->next;
495 if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type
496 c = ptr->x - a;
497 t = c.ScalarProduct(b); // get direction parameter
498 d = t*b; // and create vector
499 c -= d; // ... yielding distance vector
500 res += d.ScalarProduct(d); // add squared distance
501 }
502 }
503 return res;
504};
505
506/** By minimizing the least square distance gains alignment vector.
507 * \bug this is not yet working properly it seems
508 */
509void molecule::GetAlignvector(struct lsq_params * par) const
510{
511 int np = 6;
512
513 const gsl_multimin_fminimizer_type *T =
514 gsl_multimin_fminimizer_nmsimplex;
515 gsl_multimin_fminimizer *s = NULL;
516 gsl_vector *ss;
517 gsl_multimin_function minex_func;
518
519 size_t iter = 0, i;
520 int status;
521 double size;
522
523 /* Initial vertex size vector */
524 ss = gsl_vector_alloc (np);
525
526 /* Set all step sizes to 1 */
527 gsl_vector_set_all (ss, 1.0);
528
529 /* Starting point */
530 par->x = gsl_vector_alloc (np);
531 par->mol = this;
532
533 gsl_vector_set (par->x, 0, 0.0); // offset
534 gsl_vector_set (par->x, 1, 0.0);
535 gsl_vector_set (par->x, 2, 0.0);
536 gsl_vector_set (par->x, 3, 0.0); // direction
537 gsl_vector_set (par->x, 4, 0.0);
538 gsl_vector_set (par->x, 5, 1.0);
539
540 /* Initialize method and iterate */
541 minex_func.f = &LeastSquareDistance;
542 minex_func.n = np;
543 minex_func.params = (void *)par;
544
545 s = gsl_multimin_fminimizer_alloc (T, np);
546 gsl_multimin_fminimizer_set (s, &minex_func, par->x, ss);
547
548 do
549 {
550 iter++;
551 status = gsl_multimin_fminimizer_iterate(s);
552
553 if (status)
554 break;
555
556 size = gsl_multimin_fminimizer_size (s);
557 status = gsl_multimin_test_size (size, 1e-2);
558
559 if (status == GSL_SUCCESS)
560 {
561 printf ("converged to minimum at\n");
562 }
563
564 printf ("%5d ", (int)iter);
565 for (i = 0; i < (size_t)np; i++)
566 {
567 printf ("%10.3e ", gsl_vector_get (s->x, i));
568 }
569 printf ("f() = %7.3f size = %.3f\n", s->fval, size);
570 }
571 while (status == GSL_CONTINUE && iter < 100);
572
573 for (i=0;i<(size_t)np;i++)
574 gsl_vector_set(par->x, i, gsl_vector_get(s->x, i));
575 //gsl_vector_free(par->x);
576 gsl_vector_free(ss);
577 gsl_multimin_fminimizer_free (s);
578};
Note: See TracBrowser for help on using the repository browser.