Changeset 927aba for molecuilder/src


Ignore:
Timestamp:
May 21, 2008, 11:14:06 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
3ce105
Parents:
06feff
Message:

new function CenterInBox, some char* converted to string

CenterInBox centers the given geometry in a rectangular box of given edge lengths
new g++ that came with ubuntu hardy complained about deprecated use of char* instead of string (for constant char arrays such: "test")

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified molecuilder/src/molecules.cpp

    r06feff r927aba  
    461461    istringstream *item = new istringstream(line);
    462462    //istringstream input(line);
    463     cout << Verbose(1) << "Reading: " << line << endl;
     463    //cout << Verbose(1) << "Reading: " << line << endl;
    464464    *item >> shorthand;
    465465    *item >> x[0];
     
    596596  cell_size[4] = 0.;
    597597  cell_size[5] = dim->x[2];
     598};
     599
     600/** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths.
     601 * \param *out output stream for debugging
     602 * \param *BoxLengths box lengths
     603 */
     604bool molecule::CenterInBox(ofstream *out, vector *BoxLengths)
     605{
     606  bool status = true;
     607  atom *ptr = NULL;
     608  vector *min = new vector;
     609  vector *max = new vector;
     610 
     611  // gather min and max for each axis
     612  ptr = start->next;  // start at first in list
     613  if (ptr != end) {   //list not empty?
     614    for (int i=0;i<NDIM;i++) {
     615      max->x[i] = ptr->x.x[i];
     616      min->x[i] = ptr->x.x[i];
     617    }
     618    while (ptr->next != end) {  // continue with second if present
     619      ptr = ptr->next;
     620      //ptr->Output(1,1,out);
     621      for (int i=0;i<NDIM;i++) {
     622        max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
     623        min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
     624      }
     625    }
     626  }
     627  // sanity check
     628  for(int i=0;i<NDIM;i++) {
     629    if (max->x[i] - min->x[i] > BoxLengths->x[i])
     630      status = false;
     631  }
     632  // warn if check failed
     633  if (!status)
     634    *out << "WARNING: molecule is bigger than defined box!" << endl;
     635  else {  // else center in box
     636    ptr = start;
     637    while (ptr->next != end) {
     638      ptr = ptr->next;
     639      for (int i=0;i<NDIM;i++)
     640        ptr->x.x[i] += -(max->x[i] + min->x[i])/2. + BoxLengths->x[i]/2.; // first term centers molecule at (0,0,0), second shifts to center of new box
     641    }
     642  }
     643
     644  // free and exit
     645  delete(min);
     646  delete(max);
     647  return status;
    598648};
    599649
     
    884934 * \param *text question before entering
    885935 */
    886 atom * molecule::AskAtom(char *text)
     936atom * molecule::AskAtom(string text)
    887937{
    888938  int No;
     
    12041254 * \return string of the flag
    12051255 */
    1206 char * molecule::GetColor(enum Shading color)
     1256string molecule::GetColor(enum Shading color)
    12071257{
    12081258  switch(color) {
     
    32403290 
    32413291  // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen
    3242   // von Endstuecken (aus den Bonds) hinzugefÃŒgt werden und fÃŒr verbleibende ANOVAOrder
    3243   // rekursiv GraphCrawler in der nÀchsten Ebene aufgerufen werden
     3292  // von Endstuecken (aus den Bonds) hinzugefᅵᅵgt werden und fᅵᅵr verbleibende ANOVAOrder
     3293  // rekursiv GraphCrawler in der nᅵᅵchsten Ebene aufgerufen werden
    32443294 
    32453295  *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
Note: See TracChangeset for help on using the changeset viewer.