Changeset d067d45 for src/molecules.cpp
- Timestamp:
- Jul 23, 2009, 1:45:24 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:
- 51c910
- Parents:
- ce5ac3 (diff), 437922 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Frederik Heber <heber@…> (07/23/09 12:34:47)
- git-committer:
- Frederik Heber <heber@…> (07/23/09 13:45:24)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
rce5ac3 rd067d45 62 62 cell_size[0] = cell_size[2] = cell_size[5]= 20.; 63 63 cell_size[1] = cell_size[3] = cell_size[4]= 0.; 64 strcpy(name,"none"); 65 IndexNr = -1; 66 ActiveFlag = false; 64 67 }; 65 68 … … 598 601 }; 599 602 603 /** Set molecule::name from the basename without suffix in the given \a *filename. 604 * \param *filename filename 605 */ 606 void molecule::SetNameFromFilename(const char *filename) 607 { 608 int length = 0; 609 char *molname = strrchr(filename, '/')+sizeof(char); // search for filename without dirs 610 char *endname = strchr(molname, '.'); 611 if ((endname == NULL) || (endname < molname)) 612 length = strlen(molname); 613 else 614 length = strlen(molname) - strlen(endname); 615 strncpy(name, molname, length); 616 name[length]='\0'; 617 }; 618 600 619 /** Sets the molecule::cell_size to the components of \a *dim (rectangular box) 601 620 * \param *dim vector class … … 652 671 max->Scale(0.5); 653 672 Translate(max); 673 Center.Zero(); 654 674 } 655 675 … … 691 711 max->AddVector(min); 692 712 Translate(min); 713 Center.Zero(); 693 714 } 694 715 delete(min); … … 700 721 * \param *center return vector for translation vector 701 722 */ 702 void molecule::CenterOrigin(ofstream *out , Vector *center)723 void molecule::CenterOrigin(ofstream *out) 703 724 { 704 725 int Num = 0; 705 726 atom *ptr = start->next; // start at first in list 706 727 707 for(int i=NDIM;i--;) // zero center vector 708 center->x[i] = 0.; 728 Center.Zero(); 709 729 710 730 if (ptr != end) { //list not empty? … … 712 732 ptr = ptr->next; 713 733 Num++; 714 center->AddVector(&ptr->x); 715 } 716 center->Scale(-1./Num); // divide through total number (and sign for direction) 717 Translate(center); 734 Center.AddVector(&ptr->x); 735 } 736 Center.Scale(-1./Num); // divide through total number (and sign for direction) 737 Translate(&Center); 738 Center.Zero(); 718 739 } 719 740 }; … … 780 801 * \param *center return vector for translation vector 781 802 */ 782 void molecule::CenterGravity(ofstream *out, Vector *center) 783 { 784 if (center == NULL) { 785 DetermineCenter(*center); 786 Translate(center); 787 delete(center); 788 } else { 789 Translate(center); 790 } 803 void molecule::CenterPeriodic(ofstream *out) 804 { 805 DeterminePeriodicCenter(Center); 806 }; 807 808 /** Centers the center of gravity of the atoms at (0,0,0). 809 * \param *out output stream for debugging 810 * \param *center return vector for translation vector 811 */ 812 void molecule::CenterAtVector(ofstream *out, Vector *newcenter) 813 { 814 Center.CopyVector(newcenter); 791 815 }; 792 816 … … 837 861 838 862 /** Determines center of molecule (yet not considering atom masses). 839 * \param Center reference to return vector840 */ 841 void molecule::Determine Center(Vector &Center)863 * \param center reference to return vector 864 */ 865 void molecule::DeterminePeriodicCenter(Vector ¢er) 842 866 { 843 867 atom *Walker = start; … … 849 873 850 874 do { 851 Center.Zero();875 center.Zero(); 852 876 flag = true; 853 877 while (Walker->next != end) { … … 876 900 Testvector.AddVector(&Translationvector); 877 901 Testvector.MatrixMultiplication(matrix); 878 Center.AddVector(&Testvector);902 center.AddVector(&Testvector); 879 903 cout << Verbose(1) << "vector is: "; 880 904 Testvector.Output((ofstream *)&cout); … … 889 913 Testvector.AddVector(&Translationvector); 890 914 Testvector.MatrixMultiplication(matrix); 891 Center.AddVector(&Testvector);915 center.AddVector(&Testvector); 892 916 cout << Verbose(1) << "Hydrogen vector is: "; 893 917 Testvector.Output((ofstream *)&cout); … … 900 924 } while (!flag); 901 925 Free((void **)&matrix, "molecule::DetermineCenter: *matrix"); 902 Center.Scale(1./(double)AtomCount);926 center.Scale(1./(double)AtomCount); 903 927 }; 904 928 … … 913 937 Vector *CenterOfGravity = DetermineCenterOfGravity(out); 914 938 915 Center Gravity(out, CenterOfGravity);939 CenterAtVector(out, CenterOfGravity); 916 940 917 941 // reset inertia tensor … … 1409 1433 bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration) 1410 1434 { 1435 molecule *mol = NULL; 1411 1436 bool status = true; 1412 1437 int MaxSteps = configuration.MaxOuterStep; 1413 MoleculeListClass *MoleculePerStep = new MoleculeListClass( MaxSteps+1, AtomCount);1438 MoleculeListClass *MoleculePerStep = new MoleculeListClass(); 1414 1439 // Get the Permutation Map by MinimiseConstrainedPotential 1415 1440 atom **PermutationMap = NULL; … … 1443 1468 *out << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl; 1444 1469 for (int step = 0; step <= MaxSteps; step++) { 1445 MoleculePerStep->ListOfMolecules[step] = new molecule(elemente); 1470 mol = new molecule(elemente); 1471 MoleculePerStep->insert(mol); 1446 1472 Walker = start; 1447 1473 while (Walker->next != end) { 1448 1474 Walker = Walker->next; 1449 1475 // add to molecule list 1450 Sprinter = MoleculePerStep->ListOfMolecules[step]->AddCopyAtom(Walker);1476 Sprinter = mol->AddCopyAtom(Walker); 1451 1477 for (int n=NDIM;n--;) { 1452 1478 Sprinter->x.x[n] = Trajectories[Walker].R.at(startstep).x[n] + (Trajectories[PermutationMap[Walker->nr]].R.at(endstep).x[n] - Trajectories[Walker].R.at(startstep).x[n])*((double)step/(double)MaxSteps); … … 1467 1493 for (int i=AtomCount; i--; ) 1468 1494 SortIndex[i] = i; 1469 status = MoleculePerStep->OutputConfigForListOfFragments(out, "ConstrainedStep", &configuration, SortIndex, false, false);1495 status = MoleculePerStep->OutputConfigForListOfFragments(out, &configuration, SortIndex); 1470 1496 1471 1497 // free and return … … 1828 1854 }; 1829 1855 1830 /** Removes atom from molecule list .1856 /** Removes atom from molecule list and deletes it. 1831 1857 * \param *pointer atom to be removed 1832 1858 * \return true - succeeded, false - atom not found in list … … 1842 1868 Trajectories.erase(pointer); 1843 1869 return remove(pointer, start, end); 1870 }; 1871 1872 /** Removes atom from molecule list, but does not delete it. 1873 * \param *pointer atom to be removed 1874 * \return true - succeeded, false - atom not found in list 1875 */ 1876 bool molecule::UnlinkAtom(atom *pointer) 1877 { 1878 if (pointer == NULL) 1879 return false; 1880 if (ElementsInMolecule[pointer->type->Z] != 0) // this would indicate an error 1881 ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element 1882 else 1883 cerr << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl; 1884 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 1885 ElementCount--; 1886 Trajectories.erase(pointer); 1887 unlink(pointer); 1888 return true; 1844 1889 }; 1845 1890 … … 2368 2413 }; 2369 2414 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices. 2370 2415 2371 2416 } 2372 2417 … … 2484 2529 //*out << Verbose(0) << "Current comparison atom is " << *OtherWalker << "." << endl; 2485 2530 /// \todo periodic check is missing here! 2486 //*out << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistance (&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;2531 //*out << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 2487 2532 MinDistance = OtherWalker->type->CovalentRadius + Walker->type->CovalentRadius; 2488 2533 MinDistance *= (IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem; 2489 2534 MaxDistance = MinDistance + BONDTHRESHOLD; 2490 2535 MinDistance -= BONDTHRESHOLD; 2491 distance = OtherWalker->x.PeriodicDistance(&(Walker->x), cell_size);2536 distance = OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size); 2492 2537 if ((OtherWalker->father->nr > Walker->father->nr) && (distance <= MaxDistance*MaxDistance) && (distance >= MinDistance*MinDistance)) { // create bond if distance is smaller 2493 //*out << Verbose( 0) << "Adding Bond between " << *Walker << " and " << *OtherWalker<< "." << endl;2538 //*out << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl; 2494 2539 AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount 2495 BondCount++;2496 2540 } else { 2497 2541 //*out << Verbose(1) << "Not Adding: Wrong label order or distance too great." << endl; … … 2564 2608 *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl; 2565 2609 *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl; 2566 2610 2567 2611 // output bonds for debugging (if bond chain list was correctly installed) 2568 2612 *out << Verbose(1) << endl << "From contents of bond chain list:"; … … 3171 3215 cerr << "KeySet file must be corrupt as there are two equal key sets therein!" << endl; 3172 3216 } 3173 //FragmentList->ListOfMolecules[NumberOfFragments++] = StoreFragmentFromKeySet(out, CurrentSet, IsAngstroem);3174 3217 } 3175 3218 } … … 3731 3774 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure 3732 3775 // allocate memory for the pointer array and transmorph graphs into full molecular fragments 3733 BondFragments = new MoleculeListClass( TotalGraph.size(), AtomCount);3776 BondFragments = new MoleculeListClass(); 3734 3777 int k=0; 3735 3778 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { 3736 3779 KeySet test = (*runner).first; 3737 3780 *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl; 3738 BondFragments-> ListOfMolecules[k] = StoreFragmentFromKeySet(out, test, configuration);3781 BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration)); 3739 3782 k++; 3740 3783 } 3741 *out << k << "/" << BondFragments-> NumberOfMolecules<< " fragments generated from the keysets." << endl;3784 *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl; 3742 3785 3743 3786 // ===== 9. Save fragments' configuration and keyset files et al to disk === 3744 if (BondFragments-> NumberOfMolecules!= 0) {3787 if (BondFragments->ListOfMolecules.size() != 0) { 3745 3788 // create the SortIndex from BFS labels to order in the config file 3746 3789 CreateMappingLabelsToConfigSequence(out, SortIndex); 3747 3790 3748 *out << Verbose(1) << "Writing " << BondFragments-> NumberOfMolecules<< " possible bond fragmentation configs" << endl;3749 if (BondFragments->OutputConfigForListOfFragments(out, FRAGMENTPREFIX, configuration, SortIndex, true, true))3791 *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl; 3792 if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex)) 3750 3793 *out << Verbose(1) << "All configs written." << endl; 3751 3794 else … … 5318 5361 if (result) { 5319 5362 *out << Verbose(5) << "Calculating Centers of Gravity" << endl; 5320 Determine Center(CenterOfGravity);5321 OtherMolecule->Determine Center(OtherCenterOfGravity);5363 DeterminePeriodicCenter(CenterOfGravity); 5364 OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity); 5322 5365 *out << Verbose(5) << "Center of Gravity: "; 5323 5366 CenterOfGravity.Output(out); … … 5325 5368 OtherCenterOfGravity.Output(out); 5326 5369 *out << endl; 5327 if (CenterOfGravity.Distance (&OtherCenterOfGravity) >threshold) {5370 if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) { 5328 5371 *out << Verbose(4) << "Centers of gravity don't match." << endl; 5329 5372 result = false; … … 5339 5382 while (Walker->next != end) { 5340 5383 Walker = Walker->next; 5341 Distances[Walker->nr] = CenterOfGravity.Distance (&Walker->x);5384 Distances[Walker->nr] = CenterOfGravity.DistanceSquared(&Walker->x); 5342 5385 } 5343 5386 Walker = OtherMolecule->start; 5344 5387 while (Walker->next != OtherMolecule->end) { 5345 5388 Walker = Walker->next; 5346 OtherDistances[Walker->nr] = OtherCenterOfGravity.Distance (&Walker->x);5389 OtherDistances[Walker->nr] = OtherCenterOfGravity.DistanceSquared(&Walker->x); 5347 5390 } 5348 5391 … … 5362 5405 flag = 0; 5363 5406 for (int i=0;i<AtomCount;i++) { 5364 *out << Verbose(5) << "Distances : |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl;5365 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold )5407 *out << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl; 5408 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold) 5366 5409 flag = 1; 5367 5410 }
Note:
See TracChangeset
for help on using the changeset viewer.