Changes in / [8a3e45:d250b2]


Ignore:
Location:
src
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r8a3e45 rd250b2  
    1 SOURCE = atom.cpp bond.cpp boundary.cpp builder.cpp config.cpp element.cpp helpers.cpp molecules.cpp moleculelist.cpp periodentafel.cpp vector.cpp verbose.cpp
    2 HEADER = boundary.hpp defs.hpp helpers.hpp molecules.hpp stackclass.hpp vector.hpp
     1SOURCE = atom.cpp bond.cpp builder.cpp config.cpp element.cpp helpers.cpp molecules.cpp moleculelist.cpp periodentafel.cpp vector.cpp verbose.cpp
     2HEADER = defs.hpp helpers.hpp molecules.hpp stackclass.hpp vector.hpp
    33
    44bin_PROGRAMS = molecuilder joiner analyzer
  • src/builder.cpp

    r8a3e45 rd250b2  
    5252#include "helpers.hpp"
    5353#include "molecules.hpp"
    54 #include "boundary.hpp"
    5554
    5655/********************************************** Submenu routine **************************************/
     
    485484 * \param *mol the molecule with all the atoms
    486485 */
    487 static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
     486static void MeasureAtoms(periodentafel *periode, molecule *mol)
    488487{
    489488  atom *first, *second, *third;
     
    497496  cout << Verbose(0) << " b - calculate bond length between two atoms" << endl;
    498497  cout << Verbose(0) << " c - calculate bond angle" << endl;
    499   cout << Verbose(0) << " d - calculate principal axis of the system" << endl;
    500   cout << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
    501498  cout << Verbose(0) << "all else - go back" << endl;
    502499  cout << Verbose(0) << "===============================================" << endl;
     
    556553      cout << Verbose(0) << (acos(x.ScalarProduct((const vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;         
    557554      break;
    558     case 'd':
    559         cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
    560         cout << Verbose(0) << "Shall we rotate? [0/1]: ";
    561         cin >> Z;
    562         if ((Z >=0) && (Z <=1))
    563           mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
    564         else
    565           mol->PrincipalAxisSystem((ofstream *)&cout, false);
    566         break;
    567     case 'e':
    568         cout << Verbose(0) << "Evaluating volume of the convex envelope.";
    569         VolumeOfConvexEnvelope((ofstream *)&cout, configuration, NULL, mol);
    570         break;
    571555  }
    572556};
     
    736720  int ExitFlag = 0;
    737721  int j;
    738   double volume = 0.;
    739722  enum ConfigStatus config_present = absent;
    740723  clock_t start,end;
     
    759742            cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
    760743            cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
    761             cout << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
    762744            cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
    763745            cout << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner and stores config files in same dir as config." << endl;
    764746            cout << "\t-h/-H/-?\tGive this help screen." << endl;
    765             cout << "\t-m\tAlign in PAS with greatest EV along z axis." << endl;
    766             cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
    767             cout << "\t-o\tGet volume of the convex envelope (and store to tecplot file)." << endl;
    768747            cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
    769748            cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
    770749            cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
    771750            cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
    772             cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
    773751            cout << "\t-v/-V\t\tGives version information." << endl;
    774752            cout << "Note: config files must not begin with '-' !" << endl;
     
    790768            argptr+=1;
    791769            break;
    792           case 'n':
    793             cout << "I won't parse trajectories." << endl;
    794             configuration.FastParsing = true;
    795770          default:   // no match? Step on
    796771            argptr++;
     
    805780      cout << Verbose(0) << "Element list loaded successfully." << endl;
    806781      periode->Output((ofstream *)&cout);
    807     } else {
     782    } else
    808783      cout << Verbose(0) << "Element list loading failed." << endl;
    809       return 1;
    810     }
    811784   
    812785    // 3. Find config file name and parse if possible
     
    972945              }
    973946              break;
    974             case 'm':
    975               ExitFlag = 1;
    976               j = atoi(argv[argptr++]);
    977               if ((j<0) || (j>1)) {
    978                 cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
    979                 j = 0;
    980               }
    981               if (j)
    982                 cout << Verbose(0) << "Converting to prinicipal axis system." << endl;
    983               else
    984                 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
    985               mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);
    986               break;
    987             case 'o':
    988               ExitFlag = 1;
    989               cout << Verbose(0) << "Evaluating volume of the convex envelope.";
    990               VolumeOfConvexEnvelope((ofstream *)&cout, &configuration, NULL, mol);
    991               break;
    992             case 'U':
    993               volume = atof(argv[argptr++]);
    994               cout << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl; 
    995             case 'u':
    996               {
    997                 double density;
    998                 ExitFlag = 1;
    999                 cout << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
    1000                 density = atof(argv[argptr++]);
    1001                 if (density < 1.0) {
    1002                   cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
    1003                   density = 1.3;
    1004                 }
    1005 //                for(int i=0;i<NDIM;i++) {
    1006 //                  repetition[i] = atoi(argv[argptr++]);
    1007 //                  if (repetition[i] < 1)
    1008 //                    cerr << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;
    1009 //                  repetition[i] = 1;
    1010 //                }
    1011                 PrepareClustersinWater((ofstream *)&cout, &configuration, mol, volume, density);
    1012               }
    1013               break;
    1014             case 'd':
    1015               for (int axis = 1; axis <= NDIM; axis++) {
    1016                 int faktor = atoi(argv[argptr++]);
    1017                 int count;
    1018                 element ** Elements;
    1019                 vector ** Vectors;
    1020                 if (faktor < 1) {
    1021                   cerr << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;
    1022                   faktor = 1;
    1023                 }
    1024                 mol->CountAtoms((ofstream *)&cout);  // recount atoms
    1025                 if (mol->AtomCount != 0) {  // if there is more than none
    1026                   count = mol->AtomCount;   // is changed becausing of adding, thus has to be stored away beforehand
    1027                   Elements = new element *[count];
    1028                   Vectors = new vector *[count];
    1029                   j = 0;
    1030                   first = mol->start;
    1031                   while (first->next != mol->end) {  // make a list of all atoms with coordinates and element
    1032                     first = first->next;
    1033                     Elements[j] = first->type;
    1034                     Vectors[j] = &first->x;
    1035                     j++;
    1036                   }
    1037                   if (count != j)
    1038                     cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
    1039                   x.Zero();
    1040                   y.Zero();
    1041                   y.x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    1042                   for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    1043                     x.AddVector(&y); // per factor one cell width further
    1044                     for (int k=count;k--;) { // go through every atom of the original cell
    1045                       first = new atom(); // create a new body
    1046                       first->x.CopyVector(Vectors[k]);  // use coordinate of original atom
    1047                       first->x.AddVector(&x);      // translate the coordinates
    1048                       first->type = Elements[k];  // insert original element
    1049                       mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
    1050                     }
    1051                   }
    1052                   // free memory
    1053                   delete[](Elements);
    1054                   delete[](Vectors);
    1055                   // correct cell size
    1056                   if (axis < 0) { // if sign was negative, we have to translate everything
    1057                     x.Zero();
    1058                     x.AddVector(&y);
    1059                     x.Scale(-(faktor-1));
    1060                     mol->Translate(&x);
    1061                   }
    1062                   mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
    1063                 }
    1064               }
    1065               break;
    1066947            default:   // no match? Step on
    1067               if (argv[argptr][0] != '-') // if it started with a '-' we've already made a step!
    1068                 argptr++;
     948              argptr++;
    1069949              break;
    1070950          }
     
    12711151
    12721152      case 'l': // measure distances or angles
    1273         MeasureAtoms(periode, mol, &configuration);
     1153        MeasureAtoms(periode, mol);
    12741154        break;
    12751155
     
    12841164        mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
    12851165        //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
    1286         Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
     1166        Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, false, MinimumRingSize);
    12871167        while (Subgraphs->next != NULL) {
    12881168          Subgraphs = Subgraphs->next;
     
    13401220 
    13411221  // save element data base
    1342   if (periode->StorePeriodentafel(ElementsFileName)) //ElementsFileName
     1222  if (periode->StorePeriodentafel()) //ElementsFileName
    13431223    cout << Verbose(0) << "Saving of elements.db successful." << endl;
    13441224  else
  • src/config.cpp

    r8a3e45 rd250b2  
    2424  configname[0]='\0';
    2525 
    26   FastParsing = false;
    2726  ProcPEGamma=8;
    2827  ProcPEPsi=1;
     
    456455  string zeile;
    457456  string dummy;
    458   element *elementhash[MAX_ELEMENTS];
    459   char name[MAX_ELEMENTS];
    460   char keyword[MAX_ELEMENTS];
    461   int Z, No[MAX_ELEMENTS];
     457  element *elementhash[128];
     458  char name[128];
     459  char keyword[128];
     460  int Z, No;
    462461  int verbose = 0;
    463462 
     
    633632  if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
    634633    config::StructOpt = 0;
    635   // prescan number of ions per type
    636   cout << Verbose(0) << "Prescanning ions per type: " << endl;
    637634  for (int i=0; i < config::MaxTypes; i++) {
    638635    sprintf(name,"Ion_Type%i",i+1);
    639     ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
     636    ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No, 1, critical);
    640637    ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
    641638    elementhash[i] = periode->FindElement(Z);
    642     cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
    643   }
    644   for (int i=0; i < config::MaxTypes; i++) {
    645     sprintf(name,"Ion_Type%i",i+1);
    646     for(int j=0;j<No[i];j++) {
     639    for(int j=0;j<No;j++) {
    647640      int repetition = 1; // which repeated keyword shall be read
    648641      sprintf(keyword,"%s_%i",name, j+1);
    649642      atom *neues = new atom();
    650643      // then parse for each atom the coordinates as often as present
    651       if (!FastParsing) {
    652         while (ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition, (repetition == 1) ? critical : optional) &&
    653           ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition, (repetition == 1) ? critical : optional) &&
    654           ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition, (repetition == 1) ? critical : optional))
    655           repetition++;
    656         repetition--;
    657         //cout << "Found " << repetition << " times of the keyword " << keyword << "." << endl;
    658       }
     644      while (ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition, (repetition == 1) ? critical : optional) &&
     645        ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition, (repetition == 1) ? critical : optional) &&
     646        ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition, (repetition == 1) ? critical : optional))
     647        repetition++;
     648      repetition--;
     649      //cout << "Found " << repetition << " times of the keyword " << keyword << "." << endl;
    659650      ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
    660651      ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
     
    665656      if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
    666657        neues->v.x[1] = 0.;
    667       if(!ParseForParameter(verbose,file, keyword, (int)FastParsing, 7, 1, double_type, &neues->v.x[2], repetition,optional))
     658      if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
    668659        neues->v.x[2] = 0.;
    669660      neues->type = elementhash[i]; // find element type
  • src/defs.hpp

    r8a3e45 rd250b2  
    4343
    4444// various standard filenames
    45 #define DEFAULTCONFIG "main_pcp_linux"    //!< default filename of config file
    46 #define CONVEXENVELOPE "ConvexEnvelope.dat"    //!< default filename of convex envelope tecplot data file
    47 #define KEYSETFILE "KeySets.dat"    //!< default filename of BOSSANOVA key sets file
    48 #define ADJACENCYFILE "Adjacency.dat"    //!< default filename of BOSSANOVA adjacancy file
    49 #define TEFACTORSFILE "TE-Factors.dat"    //!< default filename of BOSSANOVA total energy factors file
    50 #define FORCESFILE "Forces-Factors.dat"    //!< default filename of BOSSANOVA force factors file
    51 #define ORDERATSITEFILE "OrderAtSite.dat"    //!< default filename of BOSSANOVA Bond Order at each atom file
    52 #define ENERGYPERFRAGMENT "EnergyPerFragment"    //!< default filename of BOSSANOVA Energy contribution Per Fragment file
    53 #define FRAGMENTPREFIX "BondFragment"    //!< default filename prefix of BOSSANOVA fragment config and directories
    54 #define STANDARDCONFIG "unknown.conf"    //!< default filename of standard config file
    55 #define STANDARDELEMENTSDB "elements.db"    //!< default filename of elements data base with masses, Z, VanDerWaals radii, ...
    56 #define STANDARDVALENCEDB "valence.db"    //!< default filename of valence number per element database
    57 #define STANDARDORBITALDB "orbitals.db"    //!< default filename of orbitals per element database
    58 #define STANDARDHBONDDISTANCEDB "Hbonddistance.db"    //!< default filename of typial bond distance to hydrogen database
    59 #define STANDARDHBONDANGLEDB "Hbondangle.db"    //!< default filename of typial bond angle to hydrogen database
    60 
    61 // some values
    62 #define SOLVENTDENSITY_A 0.6022142
    63 #define SOLVENTDENSITY_a0 0.089238936
    64 
     45#define DEFAULTCONFIG "main_pcp_linux"
     46#define KEYSETFILE "KeySets.dat"
     47#define ADJACENCYFILE "Adjacency.dat"
     48#define TEFACTORSFILE "TE-Factors.dat"
     49#define FORCESFILE "Forces-Factors.dat"
     50#define ORDERATSITEFILE "OrderAtSite.dat"
     51#define ENERGYPERFRAGMENT "EnergyPerFragment"
     52#define FRAGMENTPREFIX "BondFragment"
     53#define STANDARDCONFIG "unknown.conf"
     54#define STANDARDELEMENTSDB "elements.db"
     55#define STANDARDVALENCEDB "valence.db"
     56#define STANDARDORBITALDB "orbitals.db"
     57#define STANDARDHBONDDISTANCEDB "Hbonddistance.db"
     58#define STANDARDHBONDANGLEDB "Hbondangle.db"
    6559
    6660#define UPDATECOUNT 10  //!< update ten sites per BOSSANOVA interval
  • src/helpers.hpp

    r8a3e45 rd250b2  
    118118};
    119119
     120
     121
    120122/******************************** Some templates for list management ***********************************/
    121123
  • src/moleculelist.cpp

    r8a3e45 rd250b2  
    240240    *out << endl;
    241241    // prepare output of config file
    242     sprintf(FragmentName, "%s/%s%s.conf", PathBackup, FRAGMENTPREFIX, FragmentNumber);
     242    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    243243    outputFragment.open(FragmentName, ios::out);
    244     //strcpy(PathBackup, configuration->configpath);
    245     sprintf(FragmentName, "%s/%s%s/", PathBackup, FRAGMENTPREFIX, FragmentNumber);
     244    strcpy(PathBackup, configuration->configpath);
     245    sprintf(FragmentName, "%s/%s%s/", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    246246   
    247247    // center on edge
     
    251251    for (int k=0;k<NDIM;k++) {
    252252      j += k+1;
    253       BoxDimension.x[k] = 2.5* (configuration->GetIsAngstroem() ? 1. : 1./AtomicLengthToAngstroem);
     253      BoxDimension.x[k] = 5.;
    254254      ListOfMolecules[i]->cell_size[j] += BoxDimension.x[k]*2.;
    255255    }
  • src/molecules.cpp

    r8a3e45 rd250b2  
    179179  bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane
    180180  atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
     181  int i;  // loop variable
    181182  double b,l,d,f,g, alpha, factors[NDIM];    // hold temporary values in triple bond case for coordination determination
    182183  vector OrthoVector1, OrthoVector2;  // temporary vectors in coordination construction
     
    252253    case 2:
    253254      // determine two other bonds (warning if there are more than two other) plus valence sanity check
    254       for (int i=0;i<NumBond;i++) {
     255      for (i=0;i<NumBond;i++) {
    255256        if (BondList[i] != TopBond) {
    256257          if (FirstBond == NULL) {
     
    311312      FirstOtherAtom->x.Zero();
    312313      SecondOtherAtom->x.Zero();
    313       for(int 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)
    314315        FirstOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (sin(bondangle));
    315316        SecondOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (-sin(bondangle));
     
    318319      SecondOtherAtom->x.Scale(&BondRescale);
    319320      //*out << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
    320       for(int i=NDIM;i--;) { // and make relative to origin atom
     321      for(i=NDIM;i--;) { // and make relative to origin atom
    321322        FirstOtherAtom->x.x[i] += TopOrigin->x.x[i];
    322323        SecondOtherAtom->x.x[i] += TopOrigin->x.x[i];
     
    438439  int NumberOfAtoms = 0; // atom number in xyz read
    439440  int i, j; // loop variables
    440   atom *Walker = NULL;  // pointer to added atom
     441  atom *first = NULL;  // pointer to added atom
    441442  char shorthand[3];  // shorthand for atom name
    442443  ifstream xyzfile;   // xyz file
     
    456457
    457458  for(i=0;i<NumberOfAtoms;i++){
    458     Walker = new atom;
     459    first = new atom;
    459460    getline(xyzfile,line,'\n');
    460461    istringstream *item = new istringstream(line);
     
    465466    *item >> x[1];
    466467    *item >> x[2];
    467     Walker->type = elemente->FindElement(shorthand);
    468     if (Walker->type == NULL) {
     468    first->type = elemente->FindElement(shorthand);
     469    if (first->type == NULL) {
    469470      cerr << "Could not parse the element at line: '" << line << "', setting to H.";
    470       Walker->type = elemente->FindElement(1);
     471      first->type = elemente->FindElement(1);
    471472    }
    472473    for(j=NDIM;j--;)
    473       Walker->x.x[j] = x[j];
    474      AddAtom(Walker);  // add to molecule
     474      first->x.x[j] = x[j];
     475     AddAtom(first);  // add to molecule
    475476    delete(item);
    476477  }
     
    709710};
    710711
    711 /** Returns vector pointing to center of gravity.
     712/** Centers the center of gravity of the atoms at (0,0,0).
    712713 * \param *out output stream for debugging
    713  * \return pointer to center of gravity vector
    714  */
    715 vector * molecule::DetermineCenterOfGravity(ofstream *out)
    716 {
    717         atom *ptr = start->next;  // start at first in list
    718         vector *a = new vector();
    719         vector tmp;
     714 * \param *center return vector for translation vector
     715 */
     716void molecule::CenterGravity(ofstream *out, vector *center)
     717{
    720718  double Num = 0;
    721        
    722         a->Zero();
    723 
     719  atom *ptr = start->next;  // start at first in list
     720  vector tmp;
     721 
     722  for(int i=NDIM;i--;) // zero center vector
     723    center->x[i] = 0.;
     724   
    724725  if (ptr != end) {   //list not empty?
    725726    while (ptr->next != end) {  // continue with second if present
     
    728729      tmp.CopyVector(&ptr->x);
    729730      tmp.Scale(ptr->type->mass);  // scale by mass
    730       a->AddVector(&tmp);       
    731     }
    732     a->Scale(-1./Num); // divide through total mass (and sign for direction)
    733   }
    734   *out << Verbose(1) << "Resulting center of gravity: ";
    735   a->Output(out);
    736   *out << endl;
    737   return a;
    738 };
    739 
    740 /** Centers the center of gravity of the atoms at (0,0,0).
    741  * \param *out output stream for debugging
    742  * \param *center return vector for translation vector
    743  */
    744 void molecule::CenterGravity(ofstream *out, vector *center)
    745 {
    746   if (center == NULL) {
    747     DetermineCenter(*center);
    748     Translate(center);
    749     delete(center);
    750   } else {
     731      center->AddVector(&tmp);       
     732    }
     733    center->Scale(-1./Num); // divide through total mass (and sign for direction)
    751734    Translate(center);
    752735  }
     
    792775};
    793776
    794 /** Determines center of molecule (yet not considering atom masses).
    795  * \param Center reference to return vector
    796  */
    797 void molecule::DetermineCenter(vector &Center)
     777/** Determines center of gravity (yet not considering atom masses).
     778 * \param CenterOfGravity reference to return vector
     779 */
     780void molecule::DetermineCenterOfGravity(vector &CenterOfGravity)
    798781{
    799782  atom *Walker = start;
     
    805788 
    806789  do {
    807     Center.Zero();
     790    CenterOfGravity.Zero();
    808791    flag = true;
    809792    while (Walker->next != end) {
     
    832815        TestVector.AddVector(&TranslationVector);
    833816        TestVector.MatrixMultiplication(matrix);
    834         Center.AddVector(&TestVector);
     817        CenterOfGravity.AddVector(&TestVector);
    835818        cout << Verbose(1) << "Vector is: ";
    836819        TestVector.Output((ofstream *)&cout);
     
    845828            TestVector.AddVector(&TranslationVector);
    846829            TestVector.MatrixMultiplication(matrix);
    847             Center.AddVector(&TestVector);
     830            CenterOfGravity.AddVector(&TestVector);
    848831            cout << Verbose(1) << "Hydrogen Vector is: ";
    849832            TestVector.Output((ofstream *)&cout);
     
    855838    }
    856839  } while (!flag);
    857   Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
    858   Center.Scale(1./(double)AtomCount);
    859 };
    860 
    861 /** Transforms/Rotates the given molecule into its principal axis system.
    862  * \param *out output stream for debugging
    863  * \param DoRotate whether to rotate (true) or only to determine the PAS.
    864  */
    865 void molecule::PrincipalAxisSystem(ofstream *out, bool DoRotate)
    866 {
    867         atom *ptr = start;  // start at first in list
    868         double InertiaTensor[NDIM*NDIM];
    869         vector *CenterOfGravity = DetermineCenterOfGravity(out);
    870 
    871         CenterGravity(out, CenterOfGravity);
    872        
    873         // reset inertia tensor
    874         for(int i=0;i<NDIM*NDIM;i++)
    875                 InertiaTensor[i] = 0.;
    876        
    877         // sum up inertia tensor
    878         while (ptr->next != end) {
    879                 ptr = ptr->next;
    880                 vector x;
    881                 x.CopyVector(&ptr->x);
    882                 //x.SubtractVector(CenterOfGravity);
    883                 InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
    884                 InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
    885                 InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
    886                 InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
    887                 InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
    888                 InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
    889                 InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
    890                 InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
    891                 InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
    892         }
    893         // print InertiaTensor for debugging
    894         *out << "The inertia tensor is:" << endl;
    895         for(int i=0;i<NDIM;i++) {
    896           for(int j=0;j<NDIM;j++)
    897             *out << InertiaTensor[i*NDIM+j] << " ";
    898           *out << endl;
    899         }
    900         *out << endl;
    901        
    902         // diagonalize to determine principal axis system
    903         gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM);
    904         gsl_matrix_view m = gsl_matrix_view_array(InertiaTensor, NDIM, NDIM);
    905         gsl_vector *eval = gsl_vector_alloc(NDIM);
    906         gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM);
    907         gsl_eigen_symmv(&m.matrix, eval, evec, T);
    908         gsl_eigen_symmv_free(T);
    909         gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);
    910        
    911         for(int i=0;i<NDIM;i++) {
    912                 *out << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i);
    913                 *out << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl;
    914         }
    915        
    916         // check whether we rotate or not
    917         if (DoRotate) {
    918           *out << Verbose(1) << "Transforming molecule into PAS ... ";
    919           // the eigenvectors specify the transformation matrix
    920           ptr = start;
    921           while (ptr->next != end) {
    922             ptr = ptr->next;
    923             ptr->x.MatrixMultiplication(evec->data);
    924           }
    925           *out << "done." << endl;
    926 
    927           // summing anew for debugging (resulting matrix has to be diagonal!)
    928           // reset inertia tensor
    929     for(int i=0;i<NDIM*NDIM;i++)
    930       InertiaTensor[i] = 0.;
    931    
    932     // sum up inertia tensor
    933     ptr = start;
    934     while (ptr->next != end) {
    935       ptr = ptr->next;
    936       vector x;
    937       x.CopyVector(&ptr->x);
    938       //x.SubtractVector(CenterOfGravity);
    939       InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
    940       InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
    941       InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
    942       InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
    943       InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
    944       InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
    945       InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
    946       InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
    947       InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
    948     }
    949     // print InertiaTensor for debugging
    950     *out << "The inertia tensor is:" << endl;
    951     for(int i=0;i<NDIM;i++) {
    952       for(int j=0;j<NDIM;j++)
    953         *out << InertiaTensor[i*NDIM+j] << " ";
    954       *out << endl;
    955     }
    956     *out << endl;
    957         }
    958        
    959         // free everything
    960         delete(CenterOfGravity);
    961         gsl_vector_free(eval);
    962         gsl_matrix_free(evec);
     840  Free((void **)&matrix, "molecule::DetermineCenterOfGravity: *matrix");
     841  CenterOfGravity.Scale(1./(double)AtomCount);
    963842};
    964843
     
    13551234  if ((Binder->next != last) && (Binder->next->Type == Undetermined)) {
    13561235    *out << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl;
    1357     Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);
     1236    Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize);
    13581237    while (Subgraphs->next != NULL) {
    13591238      Subgraphs = Subgraphs->next;
     
    13701249  return No;
    13711250};
     1251
    13721252/** Returns Shading as a char string.
    13731253 * \param color the Shading
     
    15731453            for(j=0;j<NumberOfBondsPerAtom[Walker->nr];j++)
    15741454              NoBonds += ListOfBondsPerAtom[Walker->nr][j]->BondDegree;
    1575                   *out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     1455                  //*out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    15761456                  if ((int)(Walker->type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check NoBonds of other atom
    15771457                    // count valence of second partner
     
    15791459              for(j=0;j<NumberOfBondsPerAtom[OtherWalker->nr];j++)
    15801460                NoBonds += ListOfBondsPerAtom[OtherWalker->nr][j]->BondDegree;
    1581               *out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     1461              //*out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    15821462                    if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) // increase bond degree by one
    15831463                ListOfBondsPerAtom[Walker->nr][i]->BondDegree++;
     
    15911471          *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << "." << endl;
    15921472               
    1593           // output bonds for debugging (if bond chain list was correctly installed)
    1594           *out << Verbose(1) << endl << "From contents of bond chain list:";
    1595           bond *Binder = first;
    1596     while(Binder->next != last) {
    1597       Binder = Binder->next;
    1598                         *out << *Binder << "\t" << endl;
    1599     }
    1600     *out << endl;
     1473//        // output bonds for debugging (if bond chain list was correctly installed)
     1474//        *out << Verbose(1) << endl << "From contents of bond chain list:";
     1475//        bond *Binder = first;
     1476//    while(Binder->next != last) {
     1477//      Binder = Binder->next;
     1478//                      *out << *Binder << "\t" << endl;
     1479//    }
     1480//    *out << endl;
    16011481  } else
    16021482        *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
     
    16101490 * We use the algorithm from [Even, Graph Algorithms, p.62].
    16111491 * \param *out output stream for debugging
     1492 * \param ReturnStack true - return pointer to atom stack of separable components, false - return NULL
    16121493 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found
    16131494 * \return list of each disconnected subgraph as an individual molecule class structure
    16141495 */
    1615 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize)
     1496MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int *&MinimumRingSize)
    16161497{
    16171498  class StackClass<atom *> *AtomStack;
     
    21252006 * \param *path path to file
    21262007 * \param *FragmentList empty, filled on return
     2008 * \param IsAngstroem whether we have Ansgtroem or bohrradius
    21272009 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
    21282010 */
    2129 bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList)
     2011bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList, bool IsAngstroem)
    21302012{
    21312013  bool status = true;
     
    23042186{
    23052187  ifstream File;
    2306   stringstream filename;
     2188  stringstream line;
    23072189  bool status = true;
    23082190  char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    23092191 
    2310   filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
    2311   File.open(filename.str().c_str(), ios::out);
     2192  line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     2193  File.open(line.str().c_str(), ios::out);
    23122194  *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ";
    23132195  if (File != NULL) {
     
    26112493
    26122494  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
    2613   Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);
     2495  Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize);
    26142496  // fill the bond structure of the individually stored subgraphs
    26152497  Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    26162498
    26172499  // ===== 3. if structure still valid, parse key set file and others =====
    2618   FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList);
     2500  FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList, configuration->GetIsAngstroem());
    26192501
    26202502  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
     
    31313013//          *out << ", who has no son in this fragment molecule." << endl;
    31323014#ifdef ADDHYDROGEN
    3133           //*out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
     3015//          *out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
    31343016          Leaf->AddHydrogenReplacementAtom(out, ListOfBondsPerAtom[FatherOfRunner->nr][i], Runner, FatherOfRunner, OtherFather, ListOfBondsPerAtom[FatherOfRunner->nr],NumberOfBondsPerAtom[FatherOfRunner->nr], IsAngstroem);
    31353017#endif
     
    35393421  KeyStack AtomStack;
    35403422  atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::PowerSetGenerator: **PredecessorList");
     3423  KeySet::iterator runner;
    35413424  int RootKeyNr = FragmentSearch.Root->nr;
    35423425  int Counter = FragmentSearch.FragmentCounter;
     
    39333816{
    39343817  Graph ***FragmentLowerOrdersList = NULL;
    3935   int NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL;
    3936   int counter = 0, Order;
     3818  int Order, NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL;
     3819  int counter = 0;
    39373820  int UpgradeCount = RootStack.size();
    39383821  KeyStack FragmentRootStack;
     
    39483831
    39493832  // initialise the fragments structure
     3833  FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     3834  FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    39503835  FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    39513836  FragmentSearch.Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *Labels");
     
    41744059  if (result) {
    41754060    *out << Verbose(5) << "Calculating Centers of Gravity" << endl;
    4176     DetermineCenter(CenterOfGravity);
    4177     OtherMolecule->DetermineCenter(OtherCenterOfGravity);
     4061    DetermineCenterOfGravity(CenterOfGravity);
     4062    OtherMolecule->DetermineCenterOfGravity(OtherCenterOfGravity);
    41784063    *out << Verbose(5) << "Center of Gravity: ";
    41794064    CenterOfGravity.Output(out);
  • src/molecules.hpp

    r8a3e45 rd250b2  
    1313#include <gsl/gsl_vector.h>
    1414#include <gsl/gsl_matrix.h>
    15 #include <gsl/gsl_eigen.h>
    1615#include <gsl/gsl_heapsort.h>
    1716
     
    4039#define KeySet set<int>
    4140#define NumberValuePair pair<int, double>
    42 #define Graph map <KeySet, NumberValuePair, KeyCompare >
    43 #define GraphPair pair <KeySet, NumberValuePair >
     41#define Graph map<KeySet, NumberValuePair, KeyCompare >
     42#define GraphPair pair<KeySet, NumberValuePair >
    4443#define KeySetTestPair pair<KeySet::iterator, bool>
    4544#define GraphTestPair pair<Graph::iterator, bool>
     
    266265  void CenterEdge(ofstream *out, vector *max);
    267266  void CenterOrigin(ofstream *out, vector *max);
    268   void CenterGravity(ofstream *out, vector *max);
     267  void CenterGravity(ofstream *out, vector *max); 
    269268  void Translate(const vector *x);
    270269  void Mirror(const vector *x);
    271270  void Align(vector *n);
    272271  void Scale(double **factor);
    273   void DetermineCenter(vector &center);
    274   vector * DetermineCenterOfGravity(ofstream *out);
     272  void DetermineCenterOfGravity(vector &CenterOfGravity);
    275273  void SetBoxDimension(vector *dim);
    276274  double * ReturnFullMatrixforSymmetric(double *cell_size);
    277275  void ScanForPeriodicCorrection(ofstream *out);
    278         void PrincipalAxisSystem(ofstream *out, bool DoRotate);
    279         double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
    280        
     276
    281277  bool CheckBounds(const vector *x) const;
    282278  void GetAlignVector(struct lsq_params * par) const;
     
    287283 
    288284  // Graph analysis
    289   MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize);
     285  MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int *&MinimumRingSize);
    290286  void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
    291287  bond * FindNextUnused(atom *vertex);
     
    307303  bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
    308304  bool StoreOrderAtSiteFile(ofstream *out, char *path);
    309   bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
     305  bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList, bool IsAngstroem);
    310306  bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
    311307  bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
     
    396392    char *configpath;
    397393    char *configname;
    398     bool FastParsing;
    399394   
    400395    private:
  • src/periodentafel.cpp

    r8a3e45 rd250b2  
    217217
    218218  // fill valence DB per element
    219   strncpy(filename, path, MAXSTRINGSIZE);
    220   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
    221   strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
     219  strncat(filename, path, MAXSTRINGSIZE);
     220  strncpy(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
    222221  infile.open(filename);
    223222  if (infile != NULL) {
     
    227226        infile >> FindElement((int)tmp)->Valence;
    228227        infile >> ws;
    229         //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
     228        //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->Valence << " valence electrons." << endl;
    230229    }
    231230    infile.close();
     
    235234
    236235  // fill valence DB per element
    237   strncpy(filename, path, MAXSTRINGSIZE);
    238   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
    239   strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
     236  strncat(filename, path, MAXSTRINGSIZE);
     237  strncpy(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
    240238  infile.open(filename);
    241239  if (infile != NULL) {
     
    245243      infile >> FindElement((int)tmp)->NoValenceOrbitals;
    246244      infile >> ws;
    247       //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     245      //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
    248246    }
    249247    infile.close();
     
    253251 
    254252  // fill H-BondDistance DB per element
    255   strncpy(filename, path, MAXSTRINGSIZE);
    256   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
    257   strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
     253  strncat(filename, path, MAXSTRINGSIZE);
     254  strncpy(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
    258255  infile.open(filename);
    259256  if (infile != NULL) {
     
    266263      infile >> ptr->HBondDistance[2];
    267264        infile >> ws;
    268       //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
     265      //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
    269266    }
    270267    infile.close();
     
    274271 
    275272  // fill H-BondAngle DB per element
    276   strncpy(filename, path, MAXSTRINGSIZE);
    277   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
    278   strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
     273  strncat(filename, path, MAXSTRINGSIZE);
     274  strncpy(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
    279275  infile.open(filename);
    280276  if (infile != NULL) {
     
    293289    otherstatus = false;
    294290 
    295   if (!otherstatus)
    296     cerr << "ERROR: Something went wrong while parsing the databases!" << endl;
    297  
    298291  return status;
    299292};
     
    305298  bool result = true;
    306299  ofstream f;
    307   char file[MAXSTRINGSIZE];
    308  
    309   if (filename == STANDARDELEMENTSDB)
    310     f.open(file);
     300 
     301  if (filename == NULL)
     302    f.open("elements.db");
    311303  else
    312304    f.open(filename);
  • src/vector.cpp

    r8a3e45 rd250b2  
    1313 */
    1414vector::vector() { x[0] = x[1] = x[2] = 0.; };
    15 
    16 /** Constructor of class vector.
    17  */
    18 vector::vector(double x1, double x2, double x3) { x[0] = x1; x[1] = x2; x[2] = x3; };
    1915
    2016/** Desctructor of class vector.
     
    115111};
    116112
    117 /** projects this vector onto plane defined by \a *y.
    118  * \param *y array to normal vector of plane
    119  * \return \f$\langle x, y \rangle\f$
    120  */
    121 void vector::ProjectOntoPlane(const vector *y)
    122 {
    123   vector tmp;
    124   tmp.CopyVector(y);
    125   tmp.Scale(Projection(y));
    126   this->SubtractVector(&tmp);
    127 };
    128 
    129113/** Calculates the projection of a vector onto another \a *y.
    130114 * \param *y array to second vector
     
    133117double vector::Projection(const vector *y) const
    134118{
    135   return (ScalarProduct(y));
     119  return (ScalarProduct(y)/Norm()/y->Norm());
    136120};
    137121
     
    166150};
    167151
    168 /** Zeros all components of this vector.
    169  */
    170 void vector::One(double one)
    171 {
    172   for (int i=NDIM;i--;)
    173     this->x[i] = one;
    174 };
    175 
    176 /** Initialises all components of this vector.
    177  */
    178 void vector::Init(double x1, double x2, double x3)
    179 {
    180   x[0] = x1;
    181   x[1] = x2;
    182   x[2] = x3;
    183 };
    184 
    185152/** Calculates the angle between this and another vector.
    186153 * \param *y array to second vector
    187  * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$
     154 * \return \f$\frac{\langle x, y \rangle}{|x||y|}\f$
    188155 */
    189156double vector::Angle(vector *y) const
    190157{
    191   return acos(this->ScalarProduct(y)/Norm()/y->Norm());
     158  return (this->ScalarProduct(y)/(this->Norm()*y->Norm()));
    192159};
    193160
     
    387354{
    388355  double projection;
    389   projection = ScalarProduct(n)/n->ScalarProduct(n);    // remove constancy from n (keep as logical one)
     356  projection = ScalarProduct(n)/((vector *)n)->ScalarProduct(n);    // remove constancy from n (keep as logical one)
    390357  // withdraw projected vector twice from original one
    391358  cout << Verbose(1) << "Vector: ";
     
    418385    return false;
    419386  }
    420 //  cout << Verbose(4) << "relative, first plane coordinates:";
    421 //  x1.Output((ofstream *)&cout);
    422 //  cout << endl;
    423 //  cout << Verbose(4) << "second plane coordinates:";
    424 //  x2.Output((ofstream *)&cout);
    425 //  cout << endl;
     387  cout << Verbose(4) << "relative, first plane coordinates:";
     388  x1.Output((ofstream *)&cout);
     389  cout << endl;
     390  cout << Verbose(4) << "second plane coordinates:";
     391  x2.Output((ofstream *)&cout);
     392  cout << endl;
    426393
    427394  this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]);
     
    452419    return false;
    453420  }
    454 //  cout << Verbose(4) << "relative, first plane coordinates:";
    455 //  x1.Output((ofstream *)&cout);
    456 //  cout << endl;
    457 //  cout << Verbose(4) << "second plane coordinates:";
    458 //  x2.Output((ofstream *)&cout);
    459 //  cout << endl;
     421  cout << Verbose(4) << "relative, first plane coordinates:";
     422  x1.Output((ofstream *)&cout);
     423  cout << endl;
     424  cout << Verbose(4) << "second plane coordinates:";
     425  x2.Output((ofstream *)&cout);
     426  cout << endl;
    460427
    461428  this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]);
     
    491458 * \return true - success, false - failure (null vector given)
    492459 */
    493 bool vector::GetOneNormalVector(const vector *GivenVector)
     460bool vector::GetOneNormalVector(const vector *vector)
    494461{
    495462  int Components[NDIM]; // contains indices of non-zero components
     
    499466
    500467  cout << Verbose(4);
    501   GivenVector->Output((ofstream *)&cout);
     468  vector->Output((ofstream *)&cout);
    502469  cout << endl;
    503470  for (j=NDIM;j--;)
     
    505472  // find two components != 0
    506473  for (j=0;j<NDIM;j++)
    507     if (fabs(GivenVector->x[j]) > MYEPSILON)
     474    if (fabs(vector->x[j]) > MYEPSILON)
    508475      Components[Last++] = j;
    509476  cout << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl;
     
    512479    case 3:  // threecomponent system
    513480    case 2:  // two component system
    514       norm = sqrt(1./(GivenVector->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]]));
     481      norm = sqrt(1./(vector->x[Components[1]]*vector->x[Components[1]]) + 1./(vector->x[Components[0]]*vector->x[Components[0]]));
    515482      x[Components[2]] = 0.;
    516483      // in skp both remaining parts shall become zero but with opposite sign and third is zero
    517       x[Components[1]] = -1./GivenVector->x[Components[1]] / norm;
    518       x[Components[0]] = 1./GivenVector->x[Components[0]] / norm;
     484      x[Components[1]] = -1./vector->x[Components[1]] / norm;
     485      x[Components[0]] = 1./vector->x[Components[0]] / norm;
    519486      return true;
    520487      break;
     
    531498};
    532499
    533 /** Determines paramter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
    534  * \param *A first plane vector
    535  * \param *B second plane vector
    536  * \param *C third plane vector
    537  * \return scaling parameter for this vector
    538  */
    539 double vector::CutsPlaneAt(vector *A, vector *B, vector *C)
    540 {
    541 //  cout << Verbose(3) << "For comparison: ";
    542 //  cout << "A " << A->Projection(this) << "\t";
    543 //  cout << "B " << B->Projection(this) << "\t";
    544 //  cout << "C " << C->Projection(this) << "\t";
    545 //  cout << endl;
    546   return A->Projection(this);
    547 };
    548 
    549500/** Creates a new vector as the one with least square distance to a given set of \a vectors.
    550501 * \param *vectors set of vectors
     
    568519     gsl_multimin_fminimizer_nmsimplex;
    569520   gsl_multimin_fminimizer *s = NULL;
    570    gsl_vector *ss, *y;
     521   gsl_vector *ss, *x;
    571522   gsl_multimin_function minex_func;
    572523 
     
    577528   /* Initial vertex size vector */
    578529   ss = gsl_vector_alloc (np);
    579    y = gsl_vector_alloc (np);
     530   x = gsl_vector_alloc (np);
    580531 
    581532   /* Set all step sizes to 1 */
     
    587538       
    588539         for (i=NDIM;i--;)
    589                 gsl_vector_set(y, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);
     540                gsl_vector_set(x, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);
    590541         
    591542   /* Initialize method and iterate */
     
    595546 
    596547   s = gsl_multimin_fminimizer_alloc (T, np);
    597    gsl_multimin_fminimizer_set (s, &minex_func, y, ss);
     548   gsl_multimin_fminimizer_set (s, &minex_func, x, ss);
    598549 
    599550   do
     
    624575  for (i=(size_t)np;i--;)
    625576    this->x[i] = gsl_vector_get(s->x, i);
    626    gsl_vector_free(y);
     577   gsl_vector_free(x);
    627578   gsl_vector_free(ss);
    628579   gsl_multimin_fminimizer_free (s);
  • src/vector.hpp

    r8a3e45 rd250b2  
    1010
    1111  vector();
    12   vector(double x1, double x2, double x3);
    1312  ~vector();
    1413
     
    2423  void CopyVector(const vector *y);
    2524  void RotateVector(const vector *y, const double alpha);
    26   void ProjectOntoPlane(const vector *y);
    2725  void Zero();
    28   void One(double one);
    29   void Init(double x1, double x2, double x3);
    3026  void Normalize();
    3127  void Translate(const vector *x);
     
    3935  void LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors);
    4036 
    41   double CutsPlaneAt(vector *A, vector *B, vector *C);
    4237  bool GetOneNormalVector(const vector *x1);
    4338  bool MakeNormalVector(const vector *y1);
Note: See TracChangeset for help on using the changeset viewer.