Changeset e138de for src/ellipsoid.cpp
- Timestamp:
- Nov 4, 2009, 7:56:04 PM (16 years ago)
- Branches:
- 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
- Children:
- 1614174, e5ad5c
- Parents:
- 7326b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ellipsoid.cpp
r7326b2 re138de 16 16 #include "ellipsoid.hpp" 17 17 #include "linkedcell.hpp" 18 #include "log.hpp" 18 19 #include "tesselation.hpp" 19 20 #include "vector.hpp" … … 35 36 double psi,theta,phi; // euler angles in ZX'Z'' convention 36 37 37 // cout<< Verbose(3) << "Begin of SquaredDistanceToEllipsoid" << endl;38 //Log() << Verbose(3) << "Begin of SquaredDistanceToEllipsoid" << endl; 38 39 39 40 for(int i=0;i<3;i++) … … 44 45 helper.SubtractVector(&EllipsoidCenter); 45 46 RefPoint.CopyVector(&helper); 46 // cout<< Verbose(4) << "Translated given point is at " << RefPoint << "." << endl;47 //Log() << Verbose(4) << "Translated given point is at " << RefPoint << "." << endl; 47 48 48 49 // 2. transform coordinate system by inverse of rotation matrix and of diagonal matrix … … 61 62 helper.MatrixMultiplication(Matrix); 62 63 helper.Scale(InverseLength); 63 // cout<< Verbose(4) << "Transformed RefPoint is at " << helper << "." << endl;64 //Log() << Verbose(4) << "Transformed RefPoint is at " << helper << "." << endl; 64 65 65 66 // 3. construct intersection point with unit sphere and ray between origin and x 66 67 helper.Normalize(); // is simply normalizes vector in distance direction 67 // cout<< Verbose(4) << "Transformed intersection is at " << helper << "." << endl;68 //Log() << Verbose(4) << "Transformed intersection is at " << helper << "." << endl; 68 69 69 70 // 4. transform back the constructed intersection point … … 82 83 Matrix[8] = cos(theta); 83 84 helper.MatrixMultiplication(Matrix); 84 // cout<< Verbose(4) << "Intersection is at " << helper << "." << endl;85 //Log() << Verbose(4) << "Intersection is at " << helper << "." << endl; 85 86 86 87 // 5. determine distance between backtransformed point and x 87 88 distance = RefPoint.DistanceSquared(&helper); 88 // cout<< Verbose(4) << "Squared distance between intersection and RefPoint is " << distance << "." << endl;89 //Log() << Verbose(4) << "Squared distance between intersection and RefPoint is " << distance << "." << endl; 89 90 90 91 return distance; 91 // cout<< Verbose(3) << "End of SquaredDistanceToEllipsoid" << endl;92 //Log() << Verbose(3) << "End of SquaredDistanceToEllipsoid" << endl; 92 93 }; 93 94 … … 131 132 } 132 133 133 // cout<< "Current summed distance is " << SumDistance << "." << endl;134 //Log() << Verbose(0) << "Current summed distance is " << SumDistance << "." << endl; 134 135 return SumDistance; 135 136 }; … … 142 143 * \return true - fit successful, false - fit impossible 143 144 */ 144 bool FitPointSetToEllipsoid( ofstream *out,Vector *set, int N, Vector *EllipsoidCenter, double *EllipsoidLength, double *EllipsoidAngle)145 bool FitPointSetToEllipsoid(Vector *set, int N, Vector *EllipsoidCenter, double *EllipsoidLength, double *EllipsoidAngle) 145 146 { 146 147 int status = GSL_SUCCESS; 147 *out<< Verbose(2) << "Begin of FitPointSetToEllipsoid " << endl;148 Log() << Verbose(2) << "Begin of FitPointSetToEllipsoid " << endl; 148 149 if (N >= 3) { // check that enough points are given (9 d.o.f.) 149 150 struct EllipsoidMinimisation par; … … 198 199 EllipsoidAngle[i] = gsl_vector_get (s->x, i+6); 199 200 } 200 *out << setprecision(3) << Verbose(4) << "Converged fit at: " << *EllipsoidCenter << ", lengths " << EllipsoidLength[0] << ", " << EllipsoidLength[1] << ", " << EllipsoidLength[2] << ", angles " << EllipsoidAngle[0] << ", " << EllipsoidAngle[1] << ", " << EllipsoidAngle[2] << " with summed distance " << s->fval << "." << endl;201 Log() << Verbose(4) << setprecision(3) << "Converged fit at: " << *EllipsoidCenter << ", lengths " << EllipsoidLength[0] << ", " << EllipsoidLength[1] << ", " << EllipsoidLength[2] << ", angles " << EllipsoidAngle[0] << ", " << EllipsoidAngle[1] << ", " << EllipsoidAngle[2] << " with summed distance " << s->fval << "." << endl; 201 202 } 202 203 … … 208 209 209 210 } else { 210 *out<< Verbose(3) << "Not enough points provided for fit to ellipsoid." << endl;211 Log() << Verbose(3) << "Not enough points provided for fit to ellipsoid." << endl; 211 212 return false; 212 213 } 213 *out<< Verbose(2) << "End of FitPointSetToEllipsoid" << endl;214 Log() << Verbose(2) << "End of FitPointSetToEllipsoid" << endl; 214 215 if (status == GSL_SUCCESS) 215 216 return true; … … 225 226 * \param PointsToPick number of points in set to pick 226 227 */ 227 void PickRandomNeighbouredPointSet( ofstream *out,class Tesselation *T, class LinkedCell *LC, Vector *&x, size_t PointsToPick)228 void PickRandomNeighbouredPointSet(class Tesselation *T, class LinkedCell *LC, Vector *&x, size_t PointsToPick) 228 229 { 229 230 size_t PointsLeft = 0; … … 234 235 int index; 235 236 TesselPoint *Candidate = NULL; 236 *out<< Verbose(2) << "Begin of PickRandomPointSet" << endl;237 Log() << Verbose(2) << "Begin of PickRandomPointSet" << endl; 237 238 238 239 // allocate array … … 240 241 x = new Vector[PointsToPick]; 241 242 } else { 242 *out<< "WARNING: Given pointer to vector array seems already allocated." << endl;243 eLog() << Verbose(2) << "WARNING: Given pointer to vector array seems already allocated." << endl; 243 244 } 244 245 … … 246 247 for(int i=0;i<NDIM;i++) // pick three random indices 247 248 LC->n[i] = (rand() % LC->N[i]); 248 *out<< Verbose(2) << "INFO: Center cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " ... ";249 Log() << Verbose(2) << "INFO: Center cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " ... "; 249 250 // get random cell 250 251 const LinkedNodes *List = LC->GetCurrentCell(); … … 252 253 continue; 253 254 } 254 *out<< "with No. " << LC->index << "." << endl;255 256 *out<< Verbose(2) << "LC Intervals:";255 Log() << Verbose(2) << "with No. " << LC->index << "." << endl; 256 257 Log() << Verbose(2) << "LC Intervals:"; 257 258 for (int i=0;i<NDIM;i++) { 258 259 Nlower[i] = ((LC->n[i]-1) >= 0) ? LC->n[i]-1 : 0; 259 260 Nupper[i] = ((LC->n[i]+1) < LC->N[i]) ? LC->n[i]+1 : LC->N[i]-1; 260 *out<< " [" << Nlower[i] << "," << Nupper[i] << "] ";261 } 262 *out<< endl;261 Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] "; 262 } 263 Log() << Verbose(0) << endl; 263 264 264 265 // count whether there are sufficient atoms in this cell+neighbors … … 270 271 PointsLeft += List->size(); 271 272 } 272 *out<< Verbose(2) << "There are " << PointsLeft << " atoms in this neighbourhood." << endl;273 Log() << Verbose(2) << "There are " << PointsLeft << " atoms in this neighbourhood." << endl; 273 274 if (PointsLeft < PointsToPick) { // ensure that we can pick enough points in its neighbourhood at all. 274 275 continue; … … 281 282 current = PickedAtomNrs.find(index); // not present? 282 283 if (current == PickedAtomNrs.end()) { 283 // *out<< Verbose(2) << "Picking atom nr. " << index << "." << endl;284 //Log() << Verbose(2) << "Picking atom nr. " << index << "." << endl; 284 285 PickedAtomNrs.insert(index); 285 286 } … … 293 294 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) { 294 295 const LinkedNodes *List = LC->GetCurrentCell(); 295 // *out<< Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;296 // Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl; 296 297 if (List != NULL) { 297 298 // if (List->begin() != List->end()) 298 // *out<< Verbose(2) << "Going through candidates ... " << endl;299 // Log() << Verbose(2) << "Going through candidates ... " << endl; 299 300 // else 300 // *out<< Verbose(2) << "Cell is empty ... " << endl;301 // Log() << Verbose(2) << "Cell is empty ... " << endl; 301 302 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 302 303 if ((current != PickedAtomNrs.end()) && (*current == index)) { 303 304 Candidate = (*Runner); 304 *out<< Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl;305 Log() << Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl; 305 306 x[PointsPicked++].CopyVector(Candidate->node); // we have one more atom picked 306 307 current++; // next pre-picked atom … … 309 310 } 310 311 // } else { 311 // *out<< Verbose(2) << "List for this index not allocated!" << endl;312 // Log() << Verbose(2) << "List for this index not allocated!" << endl; 312 313 } 313 314 } 314 *out<< Verbose(2) << "The following points were picked: " << endl;315 Log() << Verbose(2) << "The following points were picked: " << endl; 315 316 for (size_t i=0;i<PointsPicked;i++) 316 *out<< Verbose(2) << x[i] << endl;317 Log() << Verbose(2) << x[i] << endl; 317 318 if (PointsPicked == PointsToPick) // break out of loop if we have all 318 319 break; 319 320 } while(1); 320 321 321 *out<< Verbose(2) << "End of PickRandomPointSet" << endl;322 Log() << Verbose(2) << "End of PickRandomPointSet" << endl; 322 323 }; 323 324 … … 328 329 * \param PointsToPick number of points in set to pick 329 330 */ 330 void PickRandomPointSet( ofstream *out,class Tesselation *T, Vector *&x, size_t PointsToPick)331 void PickRandomPointSet(class Tesselation *T, Vector *&x, size_t PointsToPick) 331 332 { 332 333 size_t PointsLeft = (size_t) T->PointsOnBoundaryCount; … … 334 335 double value, threshold; 335 336 PointMap *List = &T->PointsOnBoundary; 336 *out<< Verbose(2) << "Begin of PickRandomPointSet" << endl;337 Log() << Verbose(2) << "Begin of PickRandomPointSet" << endl; 337 338 338 339 // allocate array … … 340 341 x = new Vector[PointsToPick]; 341 342 } else { 342 *out<< "WARNING: Given pointer to vector array seems already allocated." << endl;343 eLog() << Verbose(2) << "WARNING: Given pointer to vector array seems already allocated." << endl; 343 344 } 344 345 … … 347 348 threshold = 1. - (double)(PointsToPick - PointsPicked)/(double)PointsLeft; 348 349 value = (double)rand()/(double)RAND_MAX; 349 // *out<< Verbose(3) << "Current node is " << *Runner->second->node << " with " << value << " ... " << threshold << ": ";350 //Log() << Verbose(3) << "Current node is " << *Runner->second->node << " with " << value << " ... " << threshold << ": "; 350 351 if (value > threshold) { 351 352 x[PointsPicked].CopyVector(Runner->second->node->node); 352 353 PointsPicked++; 353 // *out<< "IN." << endl;354 //Log() << Verbose(0) << "IN." << endl; 354 355 } else { 355 // *out<< "OUT." << endl;356 //Log() << Verbose(0) << "OUT." << endl; 356 357 } 357 358 PointsLeft--; 358 359 } 359 *out<< Verbose(2) << "The following points were picked: " << endl;360 Log() << Verbose(2) << "The following points were picked: " << endl; 360 361 for (size_t i=0;i<PointsPicked;i++) 361 *out<< Verbose(3) << x[i] << endl;362 363 *out<< Verbose(2) << "End of PickRandomPointSet" << endl;362 Log() << Verbose(3) << x[i] << endl; 363 364 Log() << Verbose(2) << "End of PickRandomPointSet" << endl; 364 365 }; 365 366 … … 372 373 * \param *filename name for output file 373 374 */ 374 void FindDistributionOfEllipsoids( ofstream *out,class Tesselation *T, class LinkedCell *LCList, int N, int number, const char *filename)375 void FindDistributionOfEllipsoids(class Tesselation *T, class LinkedCell *LCList, int N, int number, const char *filename) 375 376 { 376 377 ofstream output; … … 381 382 double EllipsoidAngle[3]; 382 383 double distance, MaxDistance, MinDistance; 383 *out<< Verbose(0) << "Begin of FindDistributionOfEllipsoids" << endl;384 Log() << Verbose(0) << "Begin of FindDistributionOfEllipsoids" << endl; 384 385 385 386 // construct center of gravity of boundary point set for initial ellipsoid center … … 388 389 Center.AddVector(Runner->second->node->node); 389 390 Center.Scale(1./T->PointsOnBoundaryCount); 390 *out<< Verbose(1) << "Center is at " << Center << "." << endl;391 Log() << Verbose(1) << "Center is at " << Center << "." << endl; 391 392 392 393 // Output header … … 396 397 // loop over desired number of parameter sets 397 398 for (;number >0;number--) { 398 *out<< Verbose(1) << "Determining data set " << number << " ... " << endl;399 Log() << Verbose(1) << "Determining data set " << number << " ... " << endl; 399 400 // pick the point set 400 401 x = NULL; 401 //PickRandomPointSet( out,T, LCList, x, N);402 PickRandomNeighbouredPointSet( out,T, LCList, x, N);402 //PickRandomPointSet(T, LCList, x, N); 403 PickRandomNeighbouredPointSet(T, LCList, x, N); 403 404 404 405 // calculate some sensible starting values for parameter fit … … 412 413 MinDistance = distance; 413 414 } 414 // *out<< Verbose(2) << "MinDistance " << MinDistance << ", MaxDistance " << MaxDistance << "." << endl;415 //Log() << Verbose(2) << "MinDistance " << MinDistance << ", MaxDistance " << MaxDistance << "." << endl; 415 416 EllipsoidCenter.CopyVector(&Center); // use Center of Gravity as initial center of ellipsoid 416 417 for (int i=0;i<3;i++) … … 421 422 422 423 // fit the parameters 423 if (FitPointSetToEllipsoid( out,x, N, &EllipsoidCenter, &EllipsoidLength[0], &EllipsoidAngle[0])) {424 *out<< Verbose(1) << "Picking succeeded!" << endl;424 if (FitPointSetToEllipsoid(x, N, &EllipsoidCenter, &EllipsoidLength[0], &EllipsoidAngle[0])) { 425 Log() << Verbose(1) << "Picking succeeded!" << endl; 425 426 // output obtained parameter set 426 427 output << number << "\t"; … … 433 434 output << endl; 434 435 } else { // increase N to pick one more 435 *out<< Verbose(1) << "Picking failed!" << endl;436 Log() << Verbose(1) << "Picking failed!" << endl; 436 437 number++; 437 438 } … … 441 442 output.close(); 442 443 443 *out<< Verbose(0) << "End of FindDistributionOfEllipsoids" << endl;444 }; 444 Log() << Verbose(0) << "End of FindDistributionOfEllipsoids" << endl; 445 };
Note:
See TracChangeset
for help on using the changeset viewer.