Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/moleculelist.cpp

    r29812d rf66195  
    55 */
    66
     7#include "atom.hpp"
     8#include "bond.hpp"
     9#include "boundary.hpp"
    710#include "config.hpp"
    8 #include "molecules.hpp"
     11#include "element.hpp"
     12#include "helpers.hpp"
     13#include "linkedcell.hpp"
     14#include "molecule.hpp"
    915#include "memoryallocator.hpp"
     16#include "periodentafel.hpp"
    1017
    1118/*********************************** Functions for class MoleculeListClass *************************/
     
    292299/** Embedding merge of a given set of molecules into one.
    293300 * Embedding merge inserts one molecule into the other.
    294  * \param *mol destination molecule
    295  * \param *srcmol source molecule
    296  * \return true - merge successful, false - merge failed (probably due to non-existant indices
    297  * \TODO find embedding center
     301 * \param *mol destination molecule (fixed one)
     302 * \param *srcmol source molecule (variable one, where atoms are taken from)
     303 * \return true - merge successful, false - merge failed (probably due to non-existant indices)
     304 * \TODO linked cell dimensions for boundary points has to be as big as inner diameter!
    298305 */
    299306bool MoleculeListClass::EmbedMerge(molecule *mol, molecule *srcmol)
    300307{
    301   if (srcmol == NULL)
     308  if ((srcmol == NULL) || (mol == NULL)) {
     309    cout << Verbose(1) << "ERROR: Either fixed or variable molecule is given as NULL." << endl;
    302310    return false;
    303 
    304   // calculate center for merge
    305   srcmol->Center.CopyVector(mol->FindEmbeddingHole((ofstream *)&cout, srcmol));
    306   srcmol->Center.Zero();
    307 
    308   // perform simple merge
    309   SimpleMerge(mol, srcmol);
     311  }
     312
     313  // calculate envelope for *mol
     314  LinkedCell *LCList = new LinkedCell(mol, 8.);
     315  FindNonConvexBorder((ofstream *)&cout, mol, LCList, 4., NULL);
     316  if (mol->TesselStruct == NULL) {
     317    cout << Verbose(1) << "ERROR: Could not tesselate the fixed molecule." << endl;
     318    return false;
     319  }
     320  delete(LCList);
     321  LCList = new LinkedCell(mol->TesselStruct, 8.);  // re-create with boundary points only!
     322
     323  // prepare index list for bonds
     324  srcmol->CountAtoms((ofstream *)&cout);
     325  atom ** CopyAtoms = new atom*[srcmol->AtomCount];
     326  for(int i=0;i<srcmol->AtomCount;i++)
     327    CopyAtoms[i] = NULL;
     328
     329  // for each of the source atoms check whether we are in- or outside and add copy atom
     330  atom *Walker = srcmol->start;
     331  int nr=0;
     332  while (Walker->next != srcmol->end) {
     333    Walker = Walker->next;
     334    cout << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl;
     335    if (!mol->TesselStruct->IsInnerPoint((ofstream *)&cout, Walker->x, LCList)) {
     336      CopyAtoms[Walker->nr] = new atom(Walker);
     337      mol->AddAtom(CopyAtoms[Walker->nr]);
     338      nr++;
     339    } else {
     340      // do nothing
     341    }
     342  }
     343  cout << Verbose(1) << nr << " of " << srcmol->AtomCount << " atoms have been merged.";
     344
     345  // go through all bonds and add as well
     346  bond *Binder = srcmol->first;
     347  while(Binder->next != srcmol->last) {
     348    Binder = Binder->next;
     349    cout << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
     350    mol->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
     351  }
     352  delete(LCList);
    310353  return true;
    311354};
Note: See TracChangeset for help on using the changeset viewer.