Changes in / [d250b2:8a3e45]


Ignore:
Location:
src
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Makefile.am

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

    rd250b2 r8a3e45  
    5252#include "helpers.hpp"
    5353#include "molecules.hpp"
     54#include "boundary.hpp"
    5455
    5556/********************************************** Submenu routine **************************************/
     
    484485 * \param *mol the molecule with all the atoms
    485486 */
    486 static void MeasureAtoms(periodentafel *periode, molecule *mol)
     487static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
    487488{
    488489  atom *first, *second, *third;
     
    496497  cout << Verbose(0) << " b - calculate bond length between two atoms" << endl;
    497498  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;
    498501  cout << Verbose(0) << "all else - go back" << endl;
    499502  cout << Verbose(0) << "===============================================" << endl;
     
    553556      cout << Verbose(0) << (acos(x.ScalarProduct((const vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;         
    554557      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;
    555571  }
    556572};
     
    720736  int ExitFlag = 0;
    721737  int j;
     738  double volume = 0.;
    722739  enum ConfigStatus config_present = absent;
    723740  clock_t start,end;
     
    742759            cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
    743760            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;
    744762            cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
    745763            cout << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner and stores config files in same dir as config." << endl;
    746764            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;
    747768            cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
    748769            cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
    749770            cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
    750771            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;
    751773            cout << "\t-v/-V\t\tGives version information." << endl;
    752774            cout << "Note: config files must not begin with '-' !" << endl;
     
    768790            argptr+=1;
    769791            break;
     792          case 'n':
     793            cout << "I won't parse trajectories." << endl;
     794            configuration.FastParsing = true;
    770795          default:   // no match? Step on
    771796            argptr++;
     
    780805      cout << Verbose(0) << "Element list loaded successfully." << endl;
    781806      periode->Output((ofstream *)&cout);
    782     } else
     807    } else {
    783808      cout << Verbose(0) << "Element list loading failed." << endl;
     809      return 1;
     810    }
    784811   
    785812    // 3. Find config file name and parse if possible
     
    945972              }
    946973              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;
    9471066            default:   // no match? Step on
    948               argptr++;
     1067              if (argv[argptr][0] != '-') // if it started with a '-' we've already made a step!
     1068                argptr++;
    9491069              break;
    9501070          }
     
    11511271
    11521272      case 'l': // measure distances or angles
    1153         MeasureAtoms(periode, mol);
     1273        MeasureAtoms(periode, mol, &configuration);
    11541274        break;
    11551275
     
    11641284        mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
    11651285        //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
    1166         Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, false, MinimumRingSize);
     1286        Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
    11671287        while (Subgraphs->next != NULL) {
    11681288          Subgraphs = Subgraphs->next;
     
    12201340 
    12211341  // save element data base
    1222   if (periode->StorePeriodentafel()) //ElementsFileName
     1342  if (periode->StorePeriodentafel(ElementsFileName)) //ElementsFileName
    12231343    cout << Verbose(0) << "Saving of elements.db successful." << endl;
    12241344  else
  • TabularUnified src/config.cpp

    rd250b2 r8a3e45  
    2424  configname[0]='\0';
    2525 
     26  FastParsing = false;
    2627  ProcPEGamma=8;
    2728  ProcPEPsi=1;
     
    455456  string zeile;
    456457  string dummy;
    457   element *elementhash[128];
    458   char name[128];
    459   char keyword[128];
    460   int Z, No;
     458  element *elementhash[MAX_ELEMENTS];
     459  char name[MAX_ELEMENTS];
     460  char keyword[MAX_ELEMENTS];
     461  int Z, No[MAX_ELEMENTS];
    461462  int verbose = 0;
    462463 
     
    632633  if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
    633634    config::StructOpt = 0;
     635  // prescan number of ions per type
     636  cout << Verbose(0) << "Prescanning ions per type: " << endl;
    634637  for (int i=0; i < config::MaxTypes; i++) {
    635638    sprintf(name,"Ion_Type%i",i+1);
    636     ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No, 1, critical);
     639    ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
    637640    ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
    638641    elementhash[i] = periode->FindElement(Z);
    639     for(int j=0;j<No;j++) {
     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++) {
    640647      int repetition = 1; // which repeated keyword shall be read
    641648      sprintf(keyword,"%s_%i",name, j+1);
    642649      atom *neues = new atom();
    643650      // then parse for each atom the coordinates as often as present
    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;
     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      }
    650659      ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
    651660      ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
     
    656665      if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
    657666        neues->v.x[1] = 0.;
    658       if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
     667      if(!ParseForParameter(verbose,file, keyword, (int)FastParsing, 7, 1, double_type, &neues->v.x[2], repetition,optional))
    659668        neues->v.x[2] = 0.;
    660669      neues->type = elementhash[i]; // find element type
  • TabularUnified src/defs.hpp

    rd250b2 r8a3e45  
    4343
    4444// various standard filenames
    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"
     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
    5965
    6066#define UPDATECOUNT 10  //!< update ten sites per BOSSANOVA interval
  • TabularUnified src/helpers.hpp

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

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

    rd250b2 r8a3e45  
    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
    182181  double b,l,d,f,g, alpha, factors[NDIM];    // hold temporary values in triple bond case for coordination determination
    183182  vector OrthoVector1, OrthoVector2;  // temporary vectors in coordination construction
     
    253252    case 2:
    254253      // determine two other bonds (warning if there are more than two other) plus valence sanity check
    255       for (i=0;i<NumBond;i++) {
     254      for (int i=0;i<NumBond;i++) {
    256255        if (BondList[i] != TopBond) {
    257256          if (FirstBond == NULL) {
     
    312311      FirstOtherAtom->x.Zero();
    313312      SecondOtherAtom->x.Zero();
    314       for(i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction)
     313      for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction)
    315314        FirstOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (sin(bondangle));
    316315        SecondOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (-sin(bondangle));
     
    319318      SecondOtherAtom->x.Scale(&BondRescale);
    320319      //*out << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
    321       for(i=NDIM;i--;) { // and make relative to origin atom
     320      for(int i=NDIM;i--;) { // and make relative to origin atom
    322321        FirstOtherAtom->x.x[i] += TopOrigin->x.x[i];
    323322        SecondOtherAtom->x.x[i] += TopOrigin->x.x[i];
     
    439438  int NumberOfAtoms = 0; // atom number in xyz read
    440439  int i, j; // loop variables
    441   atom *first = NULL;  // pointer to added atom
     440  atom *Walker = NULL;  // pointer to added atom
    442441  char shorthand[3];  // shorthand for atom name
    443442  ifstream xyzfile;   // xyz file
     
    457456
    458457  for(i=0;i<NumberOfAtoms;i++){
    459     first = new atom;
     458    Walker = new atom;
    460459    getline(xyzfile,line,'\n');
    461460    istringstream *item = new istringstream(line);
     
    466465    *item >> x[1];
    467466    *item >> x[2];
    468     first->type = elemente->FindElement(shorthand);
    469     if (first->type == NULL) {
     467    Walker->type = elemente->FindElement(shorthand);
     468    if (Walker->type == NULL) {
    470469      cerr << "Could not parse the element at line: '" << line << "', setting to H.";
    471       first->type = elemente->FindElement(1);
     470      Walker->type = elemente->FindElement(1);
    472471    }
    473472    for(j=NDIM;j--;)
    474       first->x.x[j] = x[j];
    475      AddAtom(first);  // add to molecule
     473      Walker->x.x[j] = x[j];
     474     AddAtom(Walker);  // add to molecule
    476475    delete(item);
    477476  }
     
    710709};
    711710
    712 /** Centers the center of gravity of the atoms at (0,0,0).
     711/** Returns vector pointing to center of gravity.
    713712 * \param *out output stream for debugging
    714  * \param *center return vector for translation vector
    715  */
    716 void molecule::CenterGravity(ofstream *out, vector *center)
    717 {
     713 * \return pointer to center of gravity vector
     714 */
     715vector * molecule::DetermineCenterOfGravity(ofstream *out)
     716{
     717        atom *ptr = start->next;  // start at first in list
     718        vector *a = new vector();
     719        vector tmp;
    718720  double Num = 0;
    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    
     721       
     722        a->Zero();
     723
    725724  if (ptr != end) {   //list not empty?
    726725    while (ptr->next != end) {  // continue with second if present
     
    729728      tmp.CopyVector(&ptr->x);
    730729      tmp.Scale(ptr->type->mass);  // scale by mass
    731       center->AddVector(&tmp);       
    732     }
    733     center->Scale(-1./Num); // divide through total mass (and sign for direction)
     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 */
     744void molecule::CenterGravity(ofstream *out, vector *center)
     745{
     746  if (center == NULL) {
     747    DetermineCenter(*center);
     748    Translate(center);
     749    delete(center);
     750  } else {
    734751    Translate(center);
    735752  }
     
    775792};
    776793
    777 /** Determines center of gravity (yet not considering atom masses).
    778  * \param CenterOfGravity reference to return vector
    779  */
    780 void molecule::DetermineCenterOfGravity(vector &CenterOfGravity)
     794/** Determines center of molecule (yet not considering atom masses).
     795 * \param Center reference to return vector
     796 */
     797void molecule::DetermineCenter(vector &Center)
    781798{
    782799  atom *Walker = start;
     
    788805 
    789806  do {
    790     CenterOfGravity.Zero();
     807    Center.Zero();
    791808    flag = true;
    792809    while (Walker->next != end) {
     
    815832        TestVector.AddVector(&TranslationVector);
    816833        TestVector.MatrixMultiplication(matrix);
    817         CenterOfGravity.AddVector(&TestVector);
     834        Center.AddVector(&TestVector);
    818835        cout << Verbose(1) << "Vector is: ";
    819836        TestVector.Output((ofstream *)&cout);
     
    828845            TestVector.AddVector(&TranslationVector);
    829846            TestVector.MatrixMultiplication(matrix);
    830             CenterOfGravity.AddVector(&TestVector);
     847            Center.AddVector(&TestVector);
    831848            cout << Verbose(1) << "Hydrogen Vector is: ";
    832849            TestVector.Output((ofstream *)&cout);
     
    838855    }
    839856  } while (!flag);
    840   Free((void **)&matrix, "molecule::DetermineCenterOfGravity: *matrix");
    841   CenterOfGravity.Scale(1./(double)AtomCount);
     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 */
     865void 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);
    842963};
    843964
     
    12341355  if ((Binder->next != last) && (Binder->next->Type == Undetermined)) {
    12351356    *out << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl;
    1236     Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize);
     1357    Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);
    12371358    while (Subgraphs->next != NULL) {
    12381359      Subgraphs = Subgraphs->next;
     
    12491370  return No;
    12501371};
    1251 
    12521372/** Returns Shading as a char string.
    12531373 * \param color the Shading
     
    14531573            for(j=0;j<NumberOfBondsPerAtom[Walker->nr];j++)
    14541574              NoBonds += ListOfBondsPerAtom[Walker->nr][j]->BondDegree;
    1455                   //*out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     1575                  *out << Verbose(3) << "Walker: " << (int)Walker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    14561576                  if ((int)(Walker->type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check NoBonds of other atom
    14571577                    // count valence of second partner
     
    14591579              for(j=0;j<NumberOfBondsPerAtom[OtherWalker->nr];j++)
    14601580                NoBonds += ListOfBondsPerAtom[OtherWalker->nr][j]->BondDegree;
    1461               //*out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
     1581              *out << Verbose(3) << "OtherWalker: " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    14621582                    if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) // increase bond degree by one
    14631583                ListOfBondsPerAtom[Walker->nr][i]->BondDegree++;
     
    14711591          *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << "." << endl;
    14721592               
    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;
     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;
    14811601  } else
    14821602        *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
     
    14901610 * We use the algorithm from [Even, Graph Algorithms, p.62].
    14911611 * \param *out output stream for debugging
    1492  * \param ReturnStack true - return pointer to atom stack of separable components, false - return NULL
    14931612 * \param *&MinimumRingSize contains smallest ring size in molecular structure on return or -1 if no rings were found
    14941613 * \return list of each disconnected subgraph as an individual molecule class structure
    14951614 */
    1496 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int *&MinimumRingSize)
     1615MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize)
    14971616{
    14981617  class StackClass<atom *> *AtomStack;
     
    20062125 * \param *path path to file
    20072126 * \param *FragmentList empty, filled on return
    2008  * \param IsAngstroem whether we have Ansgtroem or bohrradius
    20092127 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
    20102128 */
    2011 bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList, bool IsAngstroem)
     2129bool molecule::ParseKeySetFile(ofstream *out, char *path, Graph *&FragmentList)
    20122130{
    20132131  bool status = true;
     
    21862304{
    21872305  ifstream File;
    2188   stringstream line;
     2306  stringstream filename;
    21892307  bool status = true;
    21902308  char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    21912309 
    2192   line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
    2193   File.open(line.str().c_str(), ios::out);
     2310  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     2311  File.open(filename.str().c_str(), ios::out);
    21942312  *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ";
    21952313  if (File != NULL) {
     
    24932611
    24942612  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
    2495   Subgraphs = DepthFirstSearchAnalysis(out, false, MinimumRingSize);
     2613  Subgraphs = DepthFirstSearchAnalysis(out, MinimumRingSize);
    24962614  // fill the bond structure of the individually stored subgraphs
    24972615  Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    24982616
    24992617  // ===== 3. if structure still valid, parse key set file and others =====
    2500   FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList, configuration->GetIsAngstroem());
     2618  FragmentationToDo = FragmentationToDo && ParseKeySetFile(out, configuration->configpath, ParsedFragmentList);
    25012619
    25022620  // ===== 4. check globally whether there's something to do actually (first adaptivity check)
     
    30133131//          *out << ", who has no son in this fragment molecule." << endl;
    30143132#ifdef ADDHYDROGEN
    3015 //          *out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
     3133          //*out << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
    30163134          Leaf->AddHydrogenReplacementAtom(out, ListOfBondsPerAtom[FatherOfRunner->nr][i], Runner, FatherOfRunner, OtherFather, ListOfBondsPerAtom[FatherOfRunner->nr],NumberOfBondsPerAtom[FatherOfRunner->nr], IsAngstroem);
    30173135#endif
     
    34213539  KeyStack AtomStack;
    34223540  atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::PowerSetGenerator: **PredecessorList");
    3423   KeySet::iterator runner;
    34243541  int RootKeyNr = FragmentSearch.Root->nr;
    34253542  int Counter = FragmentSearch.FragmentCounter;
     
    38163933{
    38173934  Graph ***FragmentLowerOrdersList = NULL;
    3818   int Order, NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL;
    3819   int counter = 0;
     3935  int NumLevels, NumMolecules, TotalNumMolecules = 0, *NumMoleculesOfOrder = NULL;
     3936  int counter = 0, Order;
    38203937  int UpgradeCount = RootStack.size();
    38213938  KeyStack FragmentRootStack;
     
    38313948
    38323949  // 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");
    38353950  FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    38363951  FragmentSearch.Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *Labels");
     
    40594174  if (result) {
    40604175    *out << Verbose(5) << "Calculating Centers of Gravity" << endl;
    4061     DetermineCenterOfGravity(CenterOfGravity);
    4062     OtherMolecule->DetermineCenterOfGravity(OtherCenterOfGravity);
     4176    DetermineCenter(CenterOfGravity);
     4177    OtherMolecule->DetermineCenter(OtherCenterOfGravity);
    40634178    *out << Verbose(5) << "Center of Gravity: ";
    40644179    CenterOfGravity.Output(out);
  • TabularUnified src/molecules.hpp

    rd250b2 r8a3e45  
    1313#include <gsl/gsl_vector.h>
    1414#include <gsl/gsl_matrix.h>
     15#include <gsl/gsl_eigen.h>
    1516#include <gsl/gsl_heapsort.h>
    1617
     
    3940#define KeySet set<int>
    4041#define NumberValuePair pair<int, double>
    41 #define Graph map<KeySet, NumberValuePair, KeyCompare >
    42 #define GraphPair pair<KeySet, NumberValuePair >
     42#define Graph map <KeySet, NumberValuePair, KeyCompare >
     43#define GraphPair pair <KeySet, NumberValuePair >
    4344#define KeySetTestPair pair<KeySet::iterator, bool>
    4445#define GraphTestPair pair<Graph::iterator, bool>
     
    265266  void CenterEdge(ofstream *out, vector *max);
    266267  void CenterOrigin(ofstream *out, vector *max);
    267   void CenterGravity(ofstream *out, vector *max); 
     268  void CenterGravity(ofstream *out, vector *max);
    268269  void Translate(const vector *x);
    269270  void Mirror(const vector *x);
    270271  void Align(vector *n);
    271272  void Scale(double **factor);
    272   void DetermineCenterOfGravity(vector &CenterOfGravity);
     273  void DetermineCenter(vector &center);
     274  vector * DetermineCenterOfGravity(ofstream *out);
    273275  void SetBoxDimension(vector *dim);
    274276  double * ReturnFullMatrixforSymmetric(double *cell_size);
    275277  void ScanForPeriodicCorrection(ofstream *out);
    276 
     278        void PrincipalAxisSystem(ofstream *out, bool DoRotate);
     279        double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
     280       
    277281  bool CheckBounds(const vector *x) const;
    278282  void GetAlignVector(struct lsq_params * par) const;
     
    283287 
    284288  // Graph analysis
    285   MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int *&MinimumRingSize);
     289  MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize);
    286290  void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
    287291  bond * FindNextUnused(atom *vertex);
     
    303307  bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
    304308  bool StoreOrderAtSiteFile(ofstream *out, char *path);
    305   bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList, bool IsAngstroem);
     309  bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
    306310  bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
    307311  bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
     
    392396    char *configpath;
    393397    char *configname;
     398    bool FastParsing;
    394399   
    395400    private:
  • TabularUnified src/periodentafel.cpp

    rd250b2 r8a3e45  
    217217
    218218  // fill valence DB per element
    219   strncat(filename, path, MAXSTRINGSIZE);
    220   strncpy(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
     219  strncpy(filename, path, MAXSTRINGSIZE);
     220  strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
     221  strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
    221222  infile.open(filename);
    222223  if (infile != NULL) {
     
    226227        infile >> FindElement((int)tmp)->Valence;
    227228        infile >> ws;
    228         //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->Valence << " valence electrons." << endl;
     229        //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
    229230    }
    230231    infile.close();
     
    234235
    235236  // fill valence DB per element
    236   strncat(filename, path, MAXSTRINGSIZE);
    237   strncpy(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
     237  strncpy(filename, path, MAXSTRINGSIZE);
     238  strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
     239  strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
    238240  infile.open(filename);
    239241  if (infile != NULL) {
     
    243245      infile >> FindElement((int)tmp)->NoValenceOrbitals;
    244246      infile >> ws;
    245       //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     247      //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
    246248    }
    247249    infile.close();
     
    251253 
    252254  // fill H-BondDistance DB per element
    253   strncat(filename, path, MAXSTRINGSIZE);
    254   strncpy(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
     255  strncpy(filename, path, MAXSTRINGSIZE);
     256  strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
     257  strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
    255258  infile.open(filename);
    256259  if (infile != NULL) {
     
    263266      infile >> ptr->HBondDistance[2];
    264267        infile >> ws;
    265       //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
     268      //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
    266269    }
    267270    infile.close();
     
    271274 
    272275  // fill H-BondAngle DB per element
    273   strncat(filename, path, MAXSTRINGSIZE);
    274   strncpy(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
     276  strncpy(filename, path, MAXSTRINGSIZE);
     277  strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
     278  strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
    275279  infile.open(filename);
    276280  if (infile != NULL) {
     
    289293    otherstatus = false;
    290294 
     295  if (!otherstatus)
     296    cerr << "ERROR: Something went wrong while parsing the databases!" << endl;
     297 
    291298  return status;
    292299};
     
    298305  bool result = true;
    299306  ofstream f;
    300  
    301   if (filename == NULL)
    302     f.open("elements.db");
     307  char file[MAXSTRINGSIZE];
     308 
     309  if (filename == STANDARDELEMENTSDB)
     310    f.open(file);
    303311  else
    304312    f.open(filename);
  • TabularUnified src/vector.cpp

    rd250b2 r8a3e45  
    1313 */
    1414vector::vector() { x[0] = x[1] = x[2] = 0.; };
     15
     16/** Constructor of class vector.
     17 */
     18vector::vector(double x1, double x2, double x3) { x[0] = x1; x[1] = x2; x[2] = x3; };
    1519
    1620/** Desctructor of class vector.
     
    111115};
    112116
     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 */
     121void vector::ProjectOntoPlane(const vector *y)
     122{
     123  vector tmp;
     124  tmp.CopyVector(y);
     125  tmp.Scale(Projection(y));
     126  this->SubtractVector(&tmp);
     127};
     128
    113129/** Calculates the projection of a vector onto another \a *y.
    114130 * \param *y array to second vector
     
    117133double vector::Projection(const vector *y) const
    118134{
    119   return (ScalarProduct(y)/Norm()/y->Norm());
     135  return (ScalarProduct(y));
    120136};
    121137
     
    150166};
    151167
     168/** Zeros all components of this vector.
     169 */
     170void 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 */
     178void vector::Init(double x1, double x2, double x3)
     179{
     180  x[0] = x1;
     181  x[1] = x2;
     182  x[2] = x3;
     183};
     184
    152185/** Calculates the angle between this and another vector.
    153186 * \param *y array to second vector
    154  * \return \f$\frac{\langle x, y \rangle}{|x||y|}\f$
     187 * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$
    155188 */
    156189double vector::Angle(vector *y) const
    157190{
    158   return (this->ScalarProduct(y)/(this->Norm()*y->Norm()));
     191  return acos(this->ScalarProduct(y)/Norm()/y->Norm());
    159192};
    160193
     
    354387{
    355388  double projection;
    356   projection = ScalarProduct(n)/((vector *)n)->ScalarProduct(n);    // remove constancy from n (keep as logical one)
     389  projection = ScalarProduct(n)/n->ScalarProduct(n);    // remove constancy from n (keep as logical one)
    357390  // withdraw projected vector twice from original one
    358391  cout << Verbose(1) << "Vector: ";
     
    385418    return false;
    386419  }
    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;
     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;
    393426
    394427  this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]);
     
    419452    return false;
    420453  }
    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;
     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;
    427460
    428461  this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]);
     
    458491 * \return true - success, false - failure (null vector given)
    459492 */
    460 bool vector::GetOneNormalVector(const vector *vector)
     493bool vector::GetOneNormalVector(const vector *GivenVector)
    461494{
    462495  int Components[NDIM]; // contains indices of non-zero components
     
    466499
    467500  cout << Verbose(4);
    468   vector->Output((ofstream *)&cout);
     501  GivenVector->Output((ofstream *)&cout);
    469502  cout << endl;
    470503  for (j=NDIM;j--;)
     
    472505  // find two components != 0
    473506  for (j=0;j<NDIM;j++)
    474     if (fabs(vector->x[j]) > MYEPSILON)
     507    if (fabs(GivenVector->x[j]) > MYEPSILON)
    475508      Components[Last++] = j;
    476509  cout << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl;
     
    479512    case 3:  // threecomponent system
    480513    case 2:  // two component system
    481       norm = sqrt(1./(vector->x[Components[1]]*vector->x[Components[1]]) + 1./(vector->x[Components[0]]*vector->x[Components[0]]));
     514      norm = sqrt(1./(GivenVector->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]]));
    482515      x[Components[2]] = 0.;
    483516      // in skp both remaining parts shall become zero but with opposite sign and third is zero
    484       x[Components[1]] = -1./vector->x[Components[1]] / norm;
    485       x[Components[0]] = 1./vector->x[Components[0]] / norm;
     517      x[Components[1]] = -1./GivenVector->x[Components[1]] / norm;
     518      x[Components[0]] = 1./GivenVector->x[Components[0]] / norm;
    486519      return true;
    487520      break;
     
    498531};
    499532
     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 */
     539double 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
    500549/** Creates a new vector as the one with least square distance to a given set of \a vectors.
    501550 * \param *vectors set of vectors
     
    519568     gsl_multimin_fminimizer_nmsimplex;
    520569   gsl_multimin_fminimizer *s = NULL;
    521    gsl_vector *ss, *x;
     570   gsl_vector *ss, *y;
    522571   gsl_multimin_function minex_func;
    523572 
     
    528577   /* Initial vertex size vector */
    529578   ss = gsl_vector_alloc (np);
    530    x = gsl_vector_alloc (np);
     579   y = gsl_vector_alloc (np);
    531580 
    532581   /* Set all step sizes to 1 */
     
    538587       
    539588         for (i=NDIM;i--;)
    540                 gsl_vector_set(x, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);
     589                gsl_vector_set(y, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);
    541590         
    542591   /* Initialize method and iterate */
     
    546595 
    547596   s = gsl_multimin_fminimizer_alloc (T, np);
    548    gsl_multimin_fminimizer_set (s, &minex_func, x, ss);
     597   gsl_multimin_fminimizer_set (s, &minex_func, y, ss);
    549598 
    550599   do
     
    575624  for (i=(size_t)np;i--;)
    576625    this->x[i] = gsl_vector_get(s->x, i);
    577    gsl_vector_free(x);
     626   gsl_vector_free(y);
    578627   gsl_vector_free(ss);
    579628   gsl_multimin_fminimizer_free (s);
  • TabularUnified src/vector.hpp

    rd250b2 r8a3e45  
    1010
    1111  vector();
     12  vector(double x1, double x2, double x3);
    1213  ~vector();
    1314
     
    2324  void CopyVector(const vector *y);
    2425  void RotateVector(const vector *y, const double alpha);
     26  void ProjectOntoPlane(const vector *y);
    2527  void Zero();
     28  void One(double one);
     29  void Init(double x1, double x2, double x3);
    2630  void Normalize();
    2731  void Translate(const vector *x);
     
    3539  void LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors);
    3640 
     41  double CutsPlaneAt(vector *A, vector *B, vector *C);
    3742  bool GetOneNormalVector(const vector *x1);
    3843  bool MakeNormalVector(const vector *y1);
Note: See TracChangeset for help on using the changeset viewer.