Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/moleculelist.cpp

    r477bb2 r244a84  
    44 *
    55 */
     6
     7#include <cstring>
    68
    79#include "atom.hpp"
     
    142144
    143145  // header
    144   (*out) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
    145   (*out) << "-----------------------------------------------" << endl;
     146  Log() << Verbose(0) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
     147  Log() << Verbose(0) << "-----------------------------------------------" << endl;
    146148  if (ListOfMolecules.size() == 0)
    147     (*out) << "\tNone" << endl;
     149    Log() << Verbose(0) << "\tNone" << endl;
    148150  else {
    149151    Origin.Zero();
     
    162164      }
    163165      // output Index, Name, number of atoms, chemical formula
    164       (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
     166      Log() << Verbose(0) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
    165167      Elemental = (*ListRunner)->elemente->end;
    166168      while(Elemental->previous != (*ListRunner)->elemente->start) {
    167169        Elemental = Elemental->previous;
    168170        if (Counts[Elemental->Z] != 0)
    169           (*out) << Elemental->symbol << Counts[Elemental->Z];
     171          Log() << Verbose(0) << Elemental->symbol << Counts[Elemental->Z];
    170172      }
    171173      // Center and size
    172       (*out) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
     174      Log() << Verbose(0) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
    173175    }
    174176  }
     
    402404  input.open(line.c_str());
    403405  if (input == NULL) {
    404     eLog() << Verbose(0) << endl << "Unable to open " << line << ", is the directory correct?" << endl;
    405     performCriticalExit();
     406    Log() << Verbose(1) << endl << "Unable to open " << line << ", is the directory correct?" << endl;
    406407    return false;
    407408  }
     
    740741/** Dissects given \a *mol into connected subgraphs and inserts them as new molecules but with old atoms into \a this.
    741742 * \param *out output stream for debugging
    742  * \param *mol molecule with atoms to dissect
     743 * \param *periode periodentafel
    743744 * \param *configuration config with BondGraph
    744745 */
    745 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(molecule * const mol, config * const configuration)
    746 {
     746void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
     747{
     748  molecule *mol = new molecule(periode);
     749  atom *Walker = NULL;
     750  atom *Advancer = NULL;
     751  bond *Binder = NULL;
     752  bond *Stepper = NULL;
     753  // 0. gather all atoms into single molecule
     754  for (MoleculeList::iterator MolRunner = ListOfMolecules.begin(); !ListOfMolecules.empty(); MolRunner = ListOfMolecules.begin()) {
     755    // shift all atoms to new molecule
     756    Advancer = (*MolRunner)->start->next;
     757    while (Advancer != (*MolRunner)->end) {
     758      Walker = Advancer;
     759      Advancer = Advancer->next;
     760      Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl;
     761      unlink(Walker);
     762      Walker->father = Walker;
     763      mol->AddAtom(Walker);    // counting starts at 1
     764    }
     765    // remove all bonds
     766    Stepper = (*MolRunner)->first->next;
     767    while (Stepper != (*MolRunner)->last) {
     768      Binder = Stepper;
     769      Stepper = Stepper->next;
     770      delete(Binder);
     771    }
     772    // remove the molecule
     773    delete(*MolRunner);
     774    ListOfMolecules.erase(MolRunner);
     775  }
     776
    747777  // 1. dissect the molecule into connected subgraphs
    748778  configuration->BG->ConstructBondGraph(mol);
     
    760790  // 4a. create array of molecules to fill
    761791  const int MolCount = Subgraphs->next->Count();
     792  char number[MAXSTRINGSIZE];
    762793  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    763794  for (int i=0;i<MolCount;i++) {
    764795    molecules[i] = (molecule*) new molecule(mol->elemente);
    765796    molecules[i]->ActiveFlag = true;
     797    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     798    if (MolCount > 1) {
     799      sprintf(number, "-%d", i+1);
     800      strncat(molecules[i]->name, number, MAXSTRINGSIZE - strlen(mol->name) - 1);
     801    }
     802    cout << "MolName is " << molecules[i]->name << endl;
    766803    insert(molecules[i]);
    767804  }
     
    771808  int *MolMap = Calloc<int>(mol->AtomCount, "config::Load() - *MolMap");
    772809  MoleculeLeafClass *MolecularWalker = Subgraphs;
    773   atom *Walker = NULL;
     810  Walker = NULL;
    774811  while (MolecularWalker->next != NULL) {
    775812    MolecularWalker = MolecularWalker->next;
     
    800837    }
    801838  }
    802   // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintained their ListOfBonds, but we have to remove them from first..last list
    803   bond *Binder = mol->first;
     839  // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list
     840  Binder = mol->first;
    804841  while (mol->first->next != mol->last) {
    805842    Binder = mol->first->next;
     
    837874  return AtomNo;
    838875}
    839 
    840 /***********
    841  * Methods Moved here from the menus
    842  */
    843 
    844 void MoleculeListClass::flipChosen() {
    845   int j;
    846   Log() << Verbose(0) << "Enter index of molecule: ";
    847   cin >> j;
    848   for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
    849     if ((*ListRunner)->IndexNr == j)
    850       (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
    851 }
    852 
    853 void MoleculeListClass::createNewMolecule(periodentafel *periode) {
    854   molecule *mol = NULL;
    855   mol = new molecule(periode);
    856   insert(mol);
    857 };
    858 
    859 void MoleculeListClass::loadFromXYZ(periodentafel *periode){
    860   molecule *mol = NULL;
    861   Vector center;
    862   char filename[MAXSTRINGSIZE];
    863   Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
    864   mol = new molecule(periode);
    865   do {
    866     Log() << Verbose(0) << "Enter file name: ";
    867     cin >> filename;
    868   } while (!mol->AddXYZFile(filename));
    869   mol->SetNameFromFilename(filename);
    870   // center at set box dimensions
    871   mol->CenterEdge(&center);
    872   mol->cell_size[0] = center.x[0];
    873   mol->cell_size[1] = 0;
    874   mol->cell_size[2] = center.x[1];
    875   mol->cell_size[3] = 0;
    876   mol->cell_size[4] = 0;
    877   mol->cell_size[5] = center.x[2];
    878   insert(mol);
    879 }
    880 
    881 void MoleculeListClass::changeName(){
    882   char filename[MAXSTRINGSIZE];
    883   molecule *mol = NULL;
    884   int nr;
    885   do {
    886     Log() << Verbose(0) << "Enter index of molecule: ";
    887     cin >> nr;
    888     mol = ReturnIndex(nr);
    889   } while (mol == NULL);
    890   Log() << Verbose(0) << "Enter name: ";
    891   cin >> filename;
    892   strcpy(mol->name, filename);
    893 }
    894 
    895 void MoleculeListClass::setMoleculeFilename() {
    896   char filename[MAXSTRINGSIZE];
    897   int nr;
    898   molecule *mol = NULL;
    899   do {
    900     Log() << Verbose(0) << "Enter index of molecule: ";
    901     cin >> nr;
    902     mol = ReturnIndex(nr);
    903   } while (mol == NULL);
    904   Log() << Verbose(0) << "Enter name: ";
    905   cin >> filename;
    906   mol->SetNameFromFilename(filename);
    907 }
    908 
    909 void MoleculeListClass::parseXYZIntoMolecule(){
    910   char filename[MAXSTRINGSIZE];
    911   int nr;
    912   molecule *mol = NULL;
    913   mol = NULL;
    914   do {
    915    Log() << Verbose(0) << "Enter index of molecule: ";
    916    cin >> nr;
    917    mol = ReturnIndex(nr);
    918   } while (mol == NULL);
    919   Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
    920   do {
    921    Log() << Verbose(0) << "Enter file name: ";
    922    cin >> filename;
    923   } while (!mol->AddXYZFile(filename));
    924   mol->SetNameFromFilename(filename);
    925 };
    926 
    927 void MoleculeListClass::eraseMolecule(){
    928   int nr;
    929   molecule *mol = NULL;
    930   Log() << Verbose(0) << "Enter index of molecule: ";
    931   cin >> nr;
    932   for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
    933     if (nr == (*ListRunner)->IndexNr) {
    934       mol = *ListRunner;
    935       ListOfMolecules.erase(ListRunner);
    936       delete(mol);
    937       break;
    938     }
    939 };
    940876
    941877
Note: See TracChangeset for help on using the changeset viewer.