Changeset f75030 for molecuilder/src/molecules.cpp
- Timestamp:
- May 23, 2008, 9:17:19 AM (17 years ago)
- Children:
- 6145aa7
- Parents:
- 6c96f4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified molecuilder/src/molecules.cpp ¶
r6c96f4 rf75030 21 21 int num = par->num; 22 22 23 for (int i= 0;i<num;i++) {24 for(int j= 0;j<NDIM;j++)23 for (int i=num;i--;) { 24 for(int j=NDIM;j--;) 25 25 sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]); 26 26 } … … 57 57 NumberOfBondsPerAtom = NULL; 58 58 ElementCount = 0; 59 for(int i= 0;i<MAX_ELEMENTS;i++)59 for(int i=MAX_ELEMENTS;i--;) 60 60 ElementsInMolecule[i] = 0; 61 61 cell_size[0] = cell_size[2] = cell_size[5]= 20.; … … 69 69 { 70 70 if (ListOfBondsPerAtom != NULL) 71 for(int i= 0;i<AtomCount;i++)71 for(int i=AtomCount;i--;) 72 72 Free((void **)&ListOfBondsPerAtom[i], "molecule::~molecule: ListOfBondsPerAtom[i]"); 73 73 Free((void **)&ListOfBondsPerAtom, "molecule::~molecule: ListOfBondsPerAtom"); … … 200 200 // *out << endl; 201 201 OrthoVector1.Zero(); 202 for (int i= 0;i<NDIM;i++) {202 for (int i=NDIM;i--;) { 203 203 l = TopReplacement->x.x[i] - TopOrigin->x.x[i]; 204 204 if (fabs(l) > BondDistance) { // is component greater than bond distance … … 312 312 FirstOtherAtom->x.Zero(); 313 313 SecondOtherAtom->x.Zero(); 314 for(i= 0;i<NDIM;i++) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction)314 for(i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction) 315 315 FirstOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (sin(bondangle)); 316 316 SecondOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (-sin(bondangle)); … … 319 319 SecondOtherAtom->x.Scale(&BondRescale); 320 320 //*out << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl; 321 for(i= 0;i<NDIM;i++) { // and make relative to origin atom321 for(i=NDIM;i--;) { // and make relative to origin atom 322 322 FirstOtherAtom->x.x[i] += TopOrigin->x.x[i]; 323 323 SecondOtherAtom->x.x[i] += TopOrigin->x.x[i]; … … 471 471 first->type = elemente->FindElement(1); 472 472 } 473 for(j= 0;j<NDIM;j++)473 for(j=NDIM;j--;) 474 474 first->x.x[j] = x[j]; 475 475 AddAtom(first); // add to molecule … … 612 612 ptr = start->next; // start at first in list 613 613 if (ptr != end) { //list not empty? 614 for (int i= 0;i<NDIM;i++) {614 for (int i=NDIM;i--;) { 615 615 max->x[i] = ptr->x.x[i]; 616 616 min->x[i] = ptr->x.x[i]; … … 619 619 ptr = ptr->next; 620 620 //ptr->Output(1,1,out); 621 for (int i= 0;i<NDIM;i++) {621 for (int i=NDIM;i--;) { 622 622 max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i]; 623 623 min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i]; … … 626 626 } 627 627 // sanity check 628 for(int i= 0;i<NDIM;i++) {628 for(int i=NDIM;i--;) { 629 629 if (max->x[i] - min->x[i] > BoxLengths->x[i]) 630 630 status = false; … … 637 637 while (ptr->next != end) { 638 638 ptr = ptr->next; 639 for (int i= 0;i<NDIM;i++)639 for (int i=NDIM;i--;) 640 640 ptr->x.x[i] += -(max->x[i] + min->x[i])/2. + BoxLengths->x[i]/2.; // first term centers molecule at (0,0,0), second shifts to center of new box 641 641 } … … 659 659 atom *ptr = start->next; // start at first in list 660 660 if (ptr != end) { //list not empty? 661 for (int i= 0;i<NDIM;i++) {661 for (int i=NDIM;i--;) { 662 662 max->x[i] = ptr->x.x[i]; 663 663 min->x[i] = ptr->x.x[i]; … … 666 666 ptr = ptr->next; 667 667 //ptr->Output(1,1,out); 668 for (int i= 0;i<NDIM;i++) {668 for (int i=NDIM;i--;) { 669 669 max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i]; 670 670 min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i]; … … 677 677 // *out << endl; 678 678 679 for (int i= 0;i<NDIM;i++) {679 for (int i=NDIM;i--;) { 680 680 min->x[i] *= -1.; 681 681 max->x[i] += min->x[i]; … … 696 696 atom *ptr = start->next; // start at first in list 697 697 698 for(int i= 0;i<NDIM;i++) // zero center vector698 for(int i=NDIM;i--;) // zero center vector 699 699 center->x[i] = 0.; 700 700 … … 720 720 vector tmp; 721 721 722 for(int i= 0;i<NDIM;i++) // zero center vector722 for(int i=NDIM;i--;) // zero center vector 723 723 center->x[i] = 0.; 724 724 … … 957 957 bool result = true; 958 958 int j =-1; 959 for (int i=0;i< 3;i++) {959 for (int i=0;i<NDIM;i++) { 960 960 j += i+1; 961 961 result = result && ((x->x[i] >= 0) && (x->x[i] < cell_size[j])); … … 1207 1207 { 1208 1208 int i = 0; 1209 for(i= 0;i<MAX_ELEMENTS;i++)1209 for(i=MAX_ELEMENTS;i--;) 1210 1210 ElementsInMolecule[i] = 0; 1211 1211 ElementCount = 0; … … 1217 1217 i++; 1218 1218 } 1219 for(i= 0;i<MAX_ELEMENTS;i++)1219 for(i=MAX_ELEMENTS;i--;) 1220 1220 ElementCount += (ElementsInMolecule[i] != 0 ? 1 : 0); 1221 1221 }; … … 1282 1282 { 1283 1283 configuration.MaxPsiDouble = configuration.PsiMaxNoDown = configuration.PsiMaxNoUp = configuration.PsiType = 0; 1284 for(int i= 0;i<MAX_ELEMENTS;i++) {1284 for(int i=MAX_ELEMENTS;i--;) { 1285 1285 if (ElementsInMolecule[i] != 0) { 1286 1286 //cout << "CalculateOrbitals: " << elemente->FindElement(i)->name << " has a valence of " << (int)elemente->FindElement(i)->Valence << " and there are " << ElementsInMolecule[i] << " of it." << endl; … … 1352 1352 *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl; 1353 1353 CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList"); 1354 for (int i= 0;i<NumberCells;i++)1354 for (int i=NumberCells;i--;) 1355 1355 CellList[i] = NULL; 1356 1356 … … 1382 1382 1383 1383 // 3a. go through every cell 1384 for (N[0]= 0;N[0]<divisor[0];N[0]++)1385 for (N[1]= 0;N[1]<divisor[1];N[1]++)1386 for (N[2]= 0;N[2]<divisor[2];N[2]++) {1384 for (N[0]=divisor[0];N[0]--;) 1385 for (N[1]=divisor[1];N[1]--;) 1386 for (N[2]=divisor[2];N[2]--;) { 1387 1387 Index = N[2] + (N[1] + N[0] * divisor[1]) * divisor[2]; 1388 1388 if (CellList[Index] != NULL) { // if there atoms in this cell … … 1424 1424 } 1425 1425 // 4. free the cell again 1426 for (int i= 0;i<NumberCells;i++)1426 for (int i=NumberCells;i--;) 1427 1427 if (CellList[i] != NULL) { 1428 1428 delete(CellList[i]); … … 1696 1696 1697 1697 // initialise each vertex as white with no predecessor, empty queue, color Root lightgray 1698 for (int i= 0;i<AtomCount;i++) {1698 for (int i=AtomCount;i--;) { 1699 1699 PredecessorList[i] = NULL; 1700 1700 ShortestPathList[i] = -1; … … 1702 1702 } 1703 1703 MinimumRingSize = new int[AtomCount]; 1704 for(int i= 0;i<AtomCount;i++)1704 for(int i=AtomCount;i--;) 1705 1705 MinimumRingSize[i] = AtomCount; 1706 1706 … … 1891 1891 Free((void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr"); 1892 1892 Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr"); 1893 for (int i= 0;i<NumberOfBondsPerAtom[Walker->nr];i++)1893 for (int i=NumberOfBondsPerAtom[Walker->nr];i--;) 1894 1894 Walker->ComponentNr[i] = -1; 1895 1895 } … … 2261 2261 2262 2262 // initialize mask list 2263 for(int i= 0;i<AtomCount;i++)2263 for(int i=AtomCount;i--;) 2264 2264 AtomMask[i] = false; 2265 2265 … … 2414 2414 } 2415 2415 SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex"); 2416 for(int i= 0;i<AtomCount;i++)2416 for(int i=AtomCount;i--;) 2417 2417 SortIndex[i] = -1; 2418 2418 while (runner->next != elemente->end) { // go through every element … … 2533 2533 2534 2534 // free the index lookup list 2535 for (int i= 0;i<FragmentCounter;i++)2535 for (int i=FragmentCounter;i--;) 2536 2536 Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]"); 2537 2537 Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms"); … … 2649 2649 2650 2650 *out << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl; 2651 for(int i= 0;i<AtomCount;i++)2651 for(int i=AtomCount;i--;) 2652 2652 OrderArray[i] = 0; 2653 2653 line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE; 2654 2654 file.open(line.str().c_str()); 2655 2655 if (file != NULL) { 2656 for (int i= 0;i<AtomCount;i++) // initialise with 02656 for (int i=AtomCount;i--;) // initialise with 0 2657 2657 OrderArray[i] = 0; 2658 2658 while (!file.eof()) { // parse from file … … 2697 2697 *out << Verbose(2) << "(Re-)Allocating memory." << endl; 2698 2698 if (ListOfBondsPerAtom != NULL) { 2699 for(int i= 0;i<AtomCount;i++)2699 for(int i=AtomCount;i--;) 2700 2700 Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]"); 2701 2701 Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom"); … … 2707 2707 2708 2708 // reset bond counts per atom 2709 for(int i= 0;i<AtomCount;i++)2709 for(int i=AtomCount;i--;) 2710 2710 NumberOfBondsPerAtom[i] = 0; 2711 2711 // count bonds per atom … … 2716 2716 NumberOfBondsPerAtom[Binder->rightatom->nr]++; 2717 2717 } 2718 // allocate list of bonds per atom2719 for(int i=0;i<AtomCount;i++)2718 for(int i=AtomCount;i--;) { 2719 // allocate list of bonds per atom 2720 2720 ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]"); 2721 // clear the list again, now each NumberOfBondsPerAtom marks current free field 2722 for(int i=0;i<AtomCount;i++) 2721 // clear the list again, now each NumberOfBondsPerAtom marks current free field 2723 2722 NumberOfBondsPerAtom[i] = 0; 2723 } 2724 2724 // fill the list 2725 2725 Binder = first; … … 2774 2774 2775 2775 // initialise each vertex as white with no predecessor, empty queue, color Root lightgray 2776 for (int i= 0;i<AtomCount;i++) {2776 for (int i=AtomCount;i--;) { 2777 2777 PredecessorList[i] = NULL; 2778 2778 ShortestPathList[i] = -1; … … 2890 2890 // reset parent list 2891 2891 *out << Verbose(3) << "Resetting ParentList." << endl; 2892 for (int i= 0;i<Father->AtomCount;i++)2892 for (int i=Father->AtomCount;i--;) 2893 2893 ParentList[i] = NULL; 2894 2894 … … 2972 2972 2973 2973 Leaf->BondDistance = BondDistance; 2974 for(int i= 0;i<NDIM*2;i++)2974 for(int i=NDIM*2;i--;) 2975 2975 Leaf->cell_size[i] = cell_size[i]; 2976 2976 2977 2977 // initialise SonList (indicates when we need to replace a bond with hydrogen instead) 2978 for(int i= 0;i<AtomCount;i++)2978 for(int i=AtomCount;i--;) 2979 2979 SonList[i] = NULL; 2980 2980 … … 3298 3298 // initialised touched list (stores added atoms on this level) 3299 3299 *out << Verbose(1+verbosity) << "Clearing touched list." << endl; 3300 for (TouchedIndex= 0;TouchedIndex<=SubOrder;TouchedIndex++) // empty touched list3300 for (TouchedIndex=SubOrder+1;TouchedIndex--;) // empty touched list 3301 3301 TouchedList[TouchedIndex] = -1; 3302 3302 TouchedIndex = 0; … … 3307 3307 // count the set bit of i 3308 3308 bits = 0; 3309 for (int j= 0;j<SetDimension;j++)3309 for (int j=SetDimension;j--;) 3310 3310 bits += (i & (1 << j)) >> j; 3311 3311 … … 3339 3339 while (Binder->next != FragmentSearch->BondsPerSPList[2*SP+1]) { // compare to end node of this level 3340 3340 Binder = Binder->next; 3341 for (int k= 0;k<TouchedIndex;k++) {3341 for (int k=TouchedIndex;k--;) { 3342 3342 if (Binder->Contains(TouchedList[k])) // if we added this very endpiece 3343 3343 SubSetDimension++; … … 3419 3419 int Counter = FragmentSearch.FragmentCounter; 3420 3420 3421 for (int i= 0;i<AtomCount;i++) {3421 for (int i=AtomCount;i--;) { 3422 3422 PredecessorList[i] = NULL; 3423 3423 } … … 3431 3431 FragmentSearch.ShortestPathList[RootKeyNr] = 0; 3432 3432 // prepare the atom stack counters (number of atoms with certain SP on stack) 3433 for (int i= 0;i<Order;i++)3433 for (int i=Order;i--;) 3434 3434 NumberOfAtomsSPLevel[i] = 0; 3435 3435 NumberOfAtomsSPLevel[0] = 1; // for root … … 3528 3528 } 3529 3529 3530 // creating fragments with the found edge sets 3530 // creating fragments with the found edge sets (may be done in reverse order, faster) 3531 3531 SP = 0; 3532 for(int i= 0;i<Order;i++) { // sum up all found edges3532 for(int i=Order;i--;) { // sum up all found edges 3533 3533 Binder = FragmentSearch.BondsPerSPList[2*i]; 3534 3534 while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) { … … 3576 3576 // free'ing the bonds lists 3577 3577 *out << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl; 3578 for(int i= 0;i<Order;i++) {3578 for(int i=Order;i--;) { 3579 3579 *out << Verbose(1) << "Current SP level is " << i << ": "; 3580 3580 Binder = FragmentSearch.BondsPerSPList[2*i]; … … 3625 3625 while (flag) { 3626 3626 // remove bonds that are beyond bonddistance 3627 for(int i= 0;i<NDIM;i++)3627 for(int i=NDIM;i--;) 3628 3628 TranslationVector.x[i] = 0.; 3629 3629 // scan all bonds … … 3632 3632 while ((!flag) && (Binder->next != last)) { 3633 3633 Binder = Binder->next; 3634 for (int i= 0;i<NDIM;i++) {3634 for (int i=NDIM;i--;) { 3635 3635 tmp = fabs(Binder->leftatom->x.x[i] - Binder->rightatom->x.x[i]); 3636 3636 //*out << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl; … … 3646 3646 if (flag) { 3647 3647 // create translation vector from their periodically modified distance 3648 for (int i= 0;i<NDIM;i++) {3648 for (int i=NDIM;i--;) { 3649 3649 tmp = Binder->leftatom->x.x[i] - Binder->rightatom->x.x[i]; 3650 3650 if (fabs(tmp) > BondDistance) … … 3656 3656 //*out << endl; 3657 3657 // apply to all atoms of first component via BFS 3658 for (int i= 0;i<AtomCount;i++)3658 for (int i=AtomCount;i--;) 3659 3659 ColorList[i] = white; 3660 3660 AtomStack->Push(Binder->leftatom); … … 3832 3832 FragmentSearch.FragmentSet = new KeySet; 3833 3833 FragmentSearch.Root = FindAtom(RootKeyNr); 3834 for (int i= 0;i<AtomCount;i++) {3834 for (int i=AtomCount;i--;) { 3835 3835 FragmentSearch.Labels[i] = -1; 3836 3836 FragmentSearch.ShortestPathList[i] = -1; … … 3865 3865 FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList"); 3866 3866 FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount"); 3867 for (int i= 0;i<Order;i++) {3867 for (int i=Order;i--;) { 3868 3868 FragmentSearch.BondsPerSPList[2*i] = new bond(); // start node 3869 3869 FragmentSearch.BondsPerSPList[2*i+1] = new bond(); // end node … … 3933 3933 // free Order-dependent entries of UniqueFragments structure for next loop cycle 3934 3934 Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount"); 3935 for (int i= 0;i<Order;i++) {3935 for (int i=Order;i--;) { 3936 3936 delete(FragmentSearch.BondsPerSPList[2*i]); 3937 3937 delete(FragmentSearch.BondsPerSPList[2*i+1]); … … 3989 3989 * \return <0, \a *a less than \a *b, ==0 if equal, >0 \a *a greater than \a *b 3990 3990 */ 3991 in t CompareDoubles (const void * a, const void * b)3991 inline int CompareDoubles (const void * a, const void * b) 3992 3992 { 3993 3993 if (*(double *)a > *(double *)b) … … 4040 4040 /// -# ElementsInMolecule 4041 4041 if (result) { 4042 for (flag= 0;flag<MAX_ELEMENTS;flag++) {4042 for (flag=MAX_ELEMENTS;flag--;) { 4043 4043 //*out << Verbose(5) << "Element " << flag << ": " << ElementsInMolecule[flag] << " <-> " << OtherMolecule->ElementsInMolecule[flag] << "." << endl; 4044 4044 if (ElementsInMolecule[flag] != OtherMolecule->ElementsInMolecule[flag]) … … 4074 4074 while (Walker->next != end) { 4075 4075 Walker = Walker->next; 4076 //for (i=0;i<AtomCount;i++) {4077 4076 Distances[Walker->nr] = CenterOfGravity.Distance(&Walker->x); 4078 4077 } … … 4091 4090 PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap"); 4092 4091 *out << Verbose(5) << "Combining Permutation Maps" << endl; 4093 for(int i= 0;i<AtomCount;i++)4092 for(int i=AtomCount;i--;) 4094 4093 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 4095 4094 … … 4136 4135 *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl; 4137 4136 int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap"); //Calloc 4138 for (int i= 0;i<AtomCount;i++)4137 for (int i=AtomCount;i--;) 4139 4138 AtomicMap[i] = -1; 4140 4139 if (OtherMolecule == this) { // same molecule 4141 for (int i= 0;i<AtomCount;i++) // no need as -1 means already that there is trivial correspondence4140 for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence 4142 4141 AtomicMap[i] = i; 4143 4142 *out << Verbose(4) << "Map is trivial." << endl;
Note:
See TracChangeset
for help on using the changeset viewer.