source: src/molecule_geometry.cpp@ e2373df

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 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 e2373df was 056e70, checked in by Frederik Heber <heber@…>, 14 years ago

Suffixed getters and setters for AtomInfo trajecories with AtStep.

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