Changeset 833b15 for src


Ignore:
Timestamp:
Sep 9, 2014, 7:42:32 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
a090e3
Parents:
2d701e
git-author:
Frederik Heber <heber@…> (09/01/14 15:54:02)
git-committer:
Frederik Heber <heber@…> (09/09/14 19:42:32)
Message:

FIX: Changes to function signatures in molecule_geometry.

  • no more returning allocated pointer (Vector *)
  • no more Pointers as parameters.
  • removed functions that are only convenience and have nothing to do with the molecule.
  • changes elsewhere due to signature changes.
Location:
src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FillAction/FillSurfaceAction.cpp

    r2d701e r833b15  
    8181
    8282  // center filler's tip at origin
    83   Vector max;
    84   filler->CenterEdge(&max);
     83  filler->CenterEdge();
    8584
    8685  // determine center with respect to alignment axis
     
    9695  {
    9796    Vector translater = -1.*sum;
    98     filler->Translate(&translater);
     97    filler->Translate(translater);
    9998  }
    10099
  • src/Actions/MoleculeAction/CopyAction.cpp

    r2d701e r833b15  
    6363      iter != World::getInstance().endMoleculeSelection(); ++iter) {
    6464    molecule * const copy = (iter->second)->CopyMolecule();
    65     Vector *Center = (iter->second)->DetermineCenterOfAll();
    66     *Center *= -1.;
    67     *Center += params.position.get();
     65    Vector Center = (iter->second)->DetermineCenterOfAll();
     66    Center *= -1.;
     67    Center += params.position.get();
    6868    copy->Translate(Center);
    69     delete(Center);
    7069    molecules.push_back(copy->getId());
    7170  }
  • src/Actions/MoleculeAction/RotateAroundSelfByAngleAction.cpp

    r2d701e r833b15  
    7474
    7575    // Creation Line that is the rotation axis
    76     Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
    77     LOG(0,  "Center of gravity is " << *CenterOfGravity << ".");
    78     Line RotationAxis(*CenterOfGravity, params.Axis.get());
    79     delete(CenterOfGravity);
     76    const Vector CenterOfGravity = mol->DetermineCenterOfGravity();
     77    LOG(0,  "Center of gravity is " << CenterOfGravity << ".");
     78    Line RotationAxis(CenterOfGravity, params.Axis.get());
    8079    LOG(0, "Rotate " << mol->getName() << " around self by " << params.angle.get() << " radian around axis " << RotationAxis << ".");
    8180
     
    9392
    9493  BOOST_FOREACH(molecule *mol, state->selectedMolecules) {
    95     Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
    96     LOG(0,  "Center of gravity is " << *CenterOfGravity << ".");
    97     Line RotationAxis(*CenterOfGravity, state->params.Axis.get());
    98     delete(CenterOfGravity);
     94    const Vector CenterOfGravity = mol->DetermineCenterOfGravity();
     95    LOG(0,  "Center of gravity is " <<CenterOfGravity << ".");
     96    Line RotationAxis(CenterOfGravity, state->params.Axis.get());
    9997    LOG(0, "Rotate " << mol->getName() << " around self by " << -state->params.angle.get() << " radian around axis " << RotationAxis << ".");
    10098
     
    111109
    112110  BOOST_FOREACH(molecule *mol, state->selectedMolecules) {
    113     Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
    114     LOG(0,  "Center of gravity is " << *CenterOfGravity << ".");
    115     Line RotationAxis(*CenterOfGravity, state->params.Axis.get());
    116     delete(CenterOfGravity);
     111    const Vector CenterOfGravity = mol->DetermineCenterOfGravity();
     112    LOG(0,  "Center of gravity is " << CenterOfGravity << ".");
     113    Line RotationAxis(CenterOfGravity, state->params.Axis.get());
    117114    LOG(0, "Rotate " << mol->getName() << " around self by " << state->params.angle.get() << " radian around axis " << RotationAxis << ".");
    118115
  • src/Analysis/unittests/CountBondsUnitTest.cpp

    r2d701e r833b15  
    148148void CountBondsTest::HydrogenBridgeBondsTest()
    149149{
    150   double *mirror = new double[3];
     150  double mirror[3];
    151151  CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
    152152  for (int i=0;i<3;i++)
     
    161161  cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
    162162  Translator  = Vector(3,0,0);
    163   TestMolecule1->Translate(&Translator);
     163  TestMolecule1->Translate(Translator);
    164164  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    165165  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen, NULL) );
    166166  Translator = Vector(-3,0,0);
    167   TestMolecule1->Translate(&Translator);
     167  TestMolecule1->Translate(Translator);
    168168
    169169  cout << "Case 2: offset of (0,3,0), hence angle are (14.5, 165.5, 90) < 30 (only three, because other 90 is missing due to first H01 only fulfilling H-bond criteria)." << endl;
    170170  Translator = Vector(0,3,0);
    171   TestMolecule1->Translate(&Translator);
     171  TestMolecule1->Translate(Translator);
    172172  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    173173  Translator = Vector(0,-3,0);
    174   TestMolecule1->Translate(&Translator);
     174  TestMolecule1->Translate(Translator);
    175175
    176176  cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
    177177  Translator = Vector(0,-3,0);
    178   TestMolecule1->Scale((const double ** const)&mirror);
    179   TestMolecule1->Translate(&Translator);
     178  TestMolecule1->Scale(&mirror[0]);
     179  TestMolecule1->Translate(Translator);
    180180  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    181181  Translator = Vector(0,3,0);
    182   TestMolecule1->Translate(&Translator);
    183   TestMolecule1->Scale((const double ** const)&mirror);
     182  TestMolecule1->Translate(Translator);
     183  TestMolecule1->Scale(&mirror[0]);
    184184
    185185  cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
    186186  Translator = Vector(2,1,0);
    187   TestMolecule1->Translate(&Translator);
     187  TestMolecule1->Translate(Translator);
    188188  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    189189  Translator = Vector(-2,-1,0);
    190   TestMolecule1->Translate(&Translator);
     190  TestMolecule1->Translate(Translator);
    191191
    192192  cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
    193193  Translator = Vector(0,0,3);
    194   TestMolecule1->Translate(&Translator);
     194  TestMolecule1->Translate(Translator);
    195195  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    196196  Translator = Vector(0,0,-3);
    197   TestMolecule1->Translate(&Translator);
     197  TestMolecule1->Translate(Translator);
    198198
    199199  cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
    200200  Translator = Vector(-3,0,0);
    201   TestMolecule1->Scale((const double ** const)&mirror);
    202   TestMolecule1->Translate(&Translator);
     201  TestMolecule1->Scale(&mirror[0]);
     202  TestMolecule1->Translate(Translator);
    203203  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    204204  Translator = Vector(3,0,0);
    205   TestMolecule1->Translate(&Translator);
    206   TestMolecule1->Scale((const double ** const)&mirror);
     205  TestMolecule1->Translate(Translator);
     206  TestMolecule1->Scale(&mirror[0]);
    207207
    208208  cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
    209209  Translator = Vector(3,0,0);
    210   TestMolecule1->Scale((const double ** const)&mirror);
    211   TestMolecule1->Translate(&Translator);
     210  TestMolecule1->Scale(&mirror[0]);
     211  TestMolecule1->Translate(Translator);
    212212  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    213213  Translator = Vector(-3,0,0);
    214   TestMolecule1->Translate(&Translator);
    215   TestMolecule1->Scale((const double ** const)&mirror);
     214  TestMolecule1->Translate(Translator);
     215  TestMolecule1->Scale(&mirror[0]);
    216216
    217217  cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
    218218  Translator = Vector(0,3,0);
    219   TestMolecule1->Scale((const double ** const)&mirror);
    220   TestMolecule1->Translate(&Translator);
     219  TestMolecule1->Scale(&mirror[0]);
     220  TestMolecule1->Translate(Translator);
    221221  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL, NULL) );
    222222  Translator = Vector(0,-3,0);
    223   TestMolecule1->Translate(&Translator);
    224   TestMolecule1->Scale((const double ** const)&mirror);
    225 
    226   delete[](mirror);
    227 };
     223  TestMolecule1->Translate(Translator);
     224  TestMolecule1->Scale(&mirror[0]);
     225};
  • src/Tesselation/boundary.cpp

    r2d701e r833b15  
    183183  LineMap LinesOnBoundary;
    184184  TriangleMap TrianglesOnBoundary;
    185   Vector *MolCenter = mol->DetermineCenterOfAll();
     185  Vector MolCenter = mol->DetermineCenterOfAll();
    186186  Vector helper;
    187187  BoundariesTestPair BoundaryTestPair;
     
    207207    // Boundaries stores non-const TesselPoint ref, hence we need iterator here
    208208    for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    209       ProjectedVector = (*iter)->getPosition() - (*MolCenter);
     209      ProjectedVector = (*iter)->getPosition() - (MolCenter);
    210210      ProjectedVector.ProjectOntoPlane(AxisVector);
    211211
     
    233233          LOG(2, "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << ".");
    234234        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    235           helper = (*iter)->getPosition() - (*MolCenter);
     235          helper = (*iter)->getPosition() - (MolCenter);
    236236          const double oldhelperNorm = helper.NormSquared();
    237           helper = BoundaryTestPair.first->second.second->getPosition() - (*MolCenter);
     237          helper = BoundaryTestPair.first->second.second->getPosition() - (MolCenter);
    238238          if (helper.NormSquared() < oldhelperNorm) {
    239239            BoundaryTestPair.first->second.second = (*iter);
     
    289289        {
    290290          Vector SideA, SideB, SideC, SideH;
    291           SideA = left->second.second->getPosition() - (*MolCenter);
     291          SideA = left->second.second->getPosition() - (MolCenter);
    292292          SideA.ProjectOntoPlane(AxisVector);
    293293          //          LOG(1, "SideA: " << SideA);
    294294
    295           SideB = right->second.second->getPosition() -(*MolCenter);
     295          SideB = right->second.second->getPosition() -(MolCenter);
    296296          SideB.ProjectOntoPlane(AxisVector);
    297297          //          LOG(1, "SideB: " << SideB);
     
    301301          //          LOG(1, "SideC: " << SideC);
    302302
    303           SideH = runner->second.second->getPosition() -(*MolCenter);
     303          SideH = runner->second.second->getPosition() -(MolCenter);
    304304          SideH.ProjectOntoPlane(AxisVector);
    305305          //          LOG(1, "SideH: " << SideH);
     
    329329    } while (flag);
    330330  }
    331   delete(MolCenter);
    332331  return BoundaryPoints;
    333332};
     
    726725    for (int i = 0; i < NDIM; i++)
    727726      BoxLengths[i] = GreatestDiameter[i];
    728     mol->CenterEdge(&BoxLengths);
     727    mol->CenterEdge();
    729728  } else {
    730729    BoxLengths[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);
     
    749748    // set new box dimensions
    750749    LOG(0, "Translating to box with these boundaries.");
    751     mol->SetBoxDimension(&BoxLengths);
     750    {
     751      RealSpaceMatrix domain;
     752      for(int i =0; i<NDIM;++i)
     753        domain.at(i,i) = BoxLengths[i];
     754      World::getInstance().setDomain(domain);
     755    }
    752756    mol->CenterInBox();
    753757  }
    754758  delete[] GreatestDiameter;
    755759  // update Box of atoms by boundary
    756   mol->SetBoxDimension(&BoxLengths);
     760  {
     761    RealSpaceMatrix domain;
     762    for(int i =0; i<NDIM;++i)
     763      domain.at(i,i) = BoxLengths[i];
     764    World::getInstance().setDomain(domain);
     765  }
    757766  LOG(0, "RESULT: The resulting cell dimensions are: " << BoxLengths[0] << " and " << BoxLengths[1] << " and " << BoxLengths[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3.");
    758767};
     
    804813
    805814  // Center filler at origin
    806   filler->CenterEdge(&Inserter);
     815  filler->CenterEdge();
    807816  const int FillerCount = filler->getAtomCount();
    808817  LOG(2, "INFO: Filler molecule has the following bonds:");
     
    10991108
    11001109  // Center filler at its center of gravity
    1101   Vector *gravity = filler->DetermineCenterOfGravity();
     1110  const Vector gravity = filler->DetermineCenterOfGravity();
    11021111  filler->CenterAtVector(gravity);
    1103   delete gravity;
    11041112  //const int FillerCount = filler->getAtomCount();
    11051113  LOG(2, "INFO: Filler molecule has the following bonds:");
     
    11651173          RandomizeMoleculePositions(Filling, RandomAtomDisplacement, Rotations, random);
    11661174          // translation
    1167           Filling->Translate(&Inserter);
     1175          Filling->Translate(Inserter);
    11681176          // remove out-of-bounds atoms
    11691177          const bool status = RemoveAtomsOutsideDomain(Filling);
     
    12031211    RandomizeMoleculePositions(filler, RandomAtomDisplacement, Rotations, random);
    12041212    // translation
    1205     filler->Translate(&firstInserter);
     1213    filler->Translate(firstInserter);
    12061214    // remove out-of-bounds atoms
    12071215    RemoveAtomsOutsideDomain(filler);
     
    12771285
    12781286  // Center filler at origin
    1279   filler->CenterEdge(&Inserter);
     1287  filler->CenterEdge();
    12801288//  const int FillerCount = filler->getAtomCount();
    12811289  LOG(2, "INFO: Filler molecule has the following bonds:");
     
    13781386          RandomizeMoleculePositions(Filling, RandomAtomDisplacement, Rotations, random);
    13791387          // translation
    1380           Filling->Translate(&Inserter);
     1388          Filling->Translate(Inserter);
    13811389          // remove out-of-bounds atoms
    13821390          const bool status = RemoveAtomsOutsideDomain(Filling);
     
    14161424    RandomizeMoleculePositions(filler, RandomAtomDisplacement, Rotations, random);
    14171425    // translation
    1418     filler->Translate(&firstInserter);
     1426    filler->Translate(firstInserter);
    14191427    // remove out-of-bounds atoms
    14201428    RemoveAtomsOutsideDomain(filler);
  • src/molecule.cpp

    r2d701e r833b15  
    751751};
    752752
    753 /** Sets the molecule::cell_size to the components of \a *dim (rectangular box)
    754  * \param *dim vector class
    755  */
    756 void molecule::SetBoxDimension(Vector *dim)
    757 {
    758   RealSpaceMatrix domain;
    759   for(int i =0; i<NDIM;++i)
    760     domain.at(i,i) = dim->at(i);
    761   World::getInstance().setDomain(domain);
    762 };
    763 
    764753/** Removes atom from molecule list, but does not delete it.
    765754 * \param *pointer atom to be removed
  • src/molecule.hpp

    r2d701e r833b15  
    273273  bool CenterInBox();
    274274  bool BoundInBox();
    275   void CenterEdge(Vector *max);
     275  void CenterEdge();
    276276  void CenterOrigin();
    277277  void CenterPeriodic();
    278   void CenterAtVector(Vector *newcenter);
    279   void Translate(const Vector *x);
    280   void TranslatePeriodically(const Vector *trans);
    281   void Mirror(const Vector *x);
    282   void Align(Vector *n);
    283   void Scale(const double ** const factor);
     278  void CenterAtVector(const Vector &newcenter);
     279  void Translate(const Vector &x);
     280  void TranslatePeriodically(const Vector &trans);
     281  void Mirror(const Vector &x);
     282  void Align(const Vector &n);
     283  void Scale(const double *factor);
    284284  void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
    285   Vector * DetermineCenterOfGravity() const;
    286   Vector * DetermineCenterOfAll() const;
    287   Vector * DetermineCenterOfBox() const;
     285  const Vector DetermineCenterOfGravity() const;
     286  const Vector DetermineCenterOfAll() const;
    288287  void SetNameFromFilename(const char *filename);
    289   void SetBoxDimension(Vector *dim);
    290288  bool ScanForPeriodicCorrection();
    291289  double VolumeOfConvexEnvelope(bool IsAngstroem);
  • src/molecule_geometry.cpp

    r2d701e r833b15  
    5858/************************************* Functions for class molecule *********************************/
    5959
     60/** Returns vector pointing to center of the domain.
     61 * \return pointer to center of the domain
     62 */
     63#ifdef HAVE_INLINE
     64inline
     65#else
     66static
     67#endif
     68const Vector DetermineCenterOfBox()
     69{
     70  Vector a(0.5,0.5,0.5);
     71  const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
     72  a *= M;
     73  return a;
     74}
    6075
    6176/** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths.
     
    6580{
    6681  bool status = true;
    67   const Vector *Center = DetermineCenterOfAll();
    68   const Vector *CenterBox = DetermineCenterOfBox();
     82  const Vector Center = DetermineCenterOfAll();
     83  const Vector CenterBox = DetermineCenterOfBox();
    6984  Box &domain = World::getInstance().getDomain();
    7085
    7186  // go through all atoms
    72   const Vector difference = *CenterBox - *Center;
    73   Translate(&difference);
     87  Translate(CenterBox - Center);
    7488  getAtomSet().transformNodes(boost::bind(&Box::enforceBoundaryConditions,domain,_1));
    7589
    76   delete(Center);
    77   delete(CenterBox);
    7890  return status;
    79 };
     91}
    8092
    8193
     
    92104
    93105  return status;
    94 };
     106}
    95107
    96108/** Centers the edge of the atoms at (0,0,0).
    97  * \param *out output stream for debugging
    98  * \param *max coordinates of other edge, specifying box dimensions.
    99  */
    100 void molecule::CenterEdge(Vector *max)
     109 */
     110void molecule::CenterEdge()
    101111{
    102112  const_iterator iter = begin();
    103113  if (iter != end()) {   //list not empty?
    104114    Vector min = (*begin())->getPosition();
    105     *max = min;
    106115    for (;iter != end(); ++iter) { // continue with second if present
    107116      const Vector &currentPos = (*iter)->getPosition();
    108       for (size_t i=0;i<NDIM;++i) {
     117      for (size_t i=0;i<NDIM;++i)
    109118        if (min[i] > currentPos[i])
    110119          min[i] = currentPos[i];
    111         if ((*max)[i] < currentPos[i])
    112           (*max)[i] = currentPos[i];
    113       }
    114     }
    115     LOG(1, "INFO: Maximum is " << *max << ", Minimum is " << min << ".");
    116     const Vector temp = -1.*min;
    117     Translate(&temp);
    118   }
    119 };
     120    }
     121    Translate(-1.*min);
     122  }
     123}
    120124
    121125/** Centers the center of the atoms at (0,0,0).
     
    136140    }
    137141    Center.Scale(-1./(double)Num); // divide through total number (and sign for direction)
    138     Translate(&Center);
    139   }
    140 };
     142    Translate(Center);
     143  }
     144}
    141145
    142146/** Returns vector pointing to center of all atoms.
    143147 * \return pointer to center of all vector
    144148 */
    145 Vector * molecule::DetermineCenterOfAll() const
     149const Vector molecule::DetermineCenterOfAll() const
    146150{
    147151  const_iterator iter = begin();  // start at first in list
    148   Vector *a = new Vector();
     152  Vector a;
    149153  double Num = 0;
    150154
    151   a->Zero();
     155  a.Zero();
    152156
    153157  if (iter != end()) {   //list not empty?
    154158    for (; iter != end(); ++iter) {  // continue with second if present
    155159      Num++;
    156       (*a) += (*iter)->getPosition();
    157     }
    158     a->Scale(1./(double)Num); // divide through total mass (and sign for direction)
     160      a += (*iter)->getPosition();
     161    }
     162    a.Scale(1./(double)Num); // divide through total mass (and sign for direction)
    159163  }
    160164  return a;
    161 };
    162 
    163 /** Returns vector pointing to center of the domain.
    164  * \return pointer to center of the domain
    165  */
    166 Vector * molecule::DetermineCenterOfBox() const
    167 {
    168   Vector *a = new Vector(0.5,0.5,0.5);
    169   const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
    170   (*a) *= M;
    171   return a;
    172 };
     165}
     166
    173167
    174168/** Returns vector pointing to center of gravity.
     
    176170 * \return pointer to center of gravity vector
    177171 */
    178 Vector * molecule::DetermineCenterOfGravity() const
     172const Vector molecule::DetermineCenterOfGravity() const
    179173{
    180174  const_iterator iter = begin();  // start at first in list
    181   Vector *a = new Vector();
     175  Vector a;
    182176  Vector tmp;
    183177  double Num = 0;
    184178
    185   a->Zero();
     179  a.Zero();
    186180
    187181  if (iter != end()) {   //list not empty?
     
    189183      Num += (*iter)->getType()->getMass();
    190184      tmp = (*iter)->getType()->getMass() * (*iter)->getPosition();
    191       (*a) += tmp;
    192     }
    193     a->Scale(1./Num); // divide through total mass
    194   }
    195   LOG(1, "INFO: Resulting center of gravity: " << *a << ".");
     185      a += tmp;
     186    }
     187    a.Scale(1./Num); // divide through total mass
     188  }
     189  LOG(1, "INFO: Resulting center of gravity: " << a << ".");
    196190  return a;
    197 };
     191}
    198192
    199193/** Centers the center of gravity of the atoms at (0,0,0).
     
    205199  Vector NewCenter;
    206200  DeterminePeriodicCenter(NewCenter);
    207   NewCenter *= -1.;
    208   Translate(&NewCenter);
    209 };
     201  Translate(-1.*NewCenter);
     202}
    210203
    211204
     
    214207 * \param *center return vector for translation vector
    215208 */
    216 void molecule::CenterAtVector(Vector *newcenter)
    217 {
    218   const Vector temp = -1.**newcenter;
    219   Translate(&temp);
    220 };
     209void molecule::CenterAtVector(const Vector &newcenter)
     210{
     211  Translate(-1.*newcenter);
     212}
    221213
    222214/** Calculate the inertia tensor of a the molecule.
     
    227219{
    228220  RealSpaceMatrix InertiaTensor;
    229   Vector *CenterOfGravity = DetermineCenterOfGravity();
     221  const Vector CenterOfGravity = DetermineCenterOfGravity();
    230222
    231223  // reset inertia tensor
     
    235227  for (const_iterator iter = begin(); iter != end(); ++iter) {
    236228    Vector x = (*iter)->getPosition();
    237     x -= *CenterOfGravity;
     229    x -= CenterOfGravity;
    238230    const double mass = (*iter)->getType()->getMass();
    239231    InertiaTensor.at(0,0) += mass*(x[1]*x[1] + x[2]*x[2]);
     
    250242  LOG(1, "INFO: The inertia tensor of molecule " << getName() <<  " is:" << InertiaTensor);
    251243
    252   delete CenterOfGravity;
    253244  return InertiaTensor;
    254245}
     
    261252void molecule::RotateToPrincipalAxisSystem(const Vector &Axis)
    262253{
    263   Vector *CenterOfGravity = DetermineCenterOfGravity();
     254  const Vector CenterOfGravity = DetermineCenterOfGravity();
    264255  RealSpaceMatrix InertiaTensor = getInertiaTensor();
    265256
     
    273264
    274265  // obtain first column, eigenvector to biggest eigenvalue
    275   Vector BiggestEigenvector(InertiaTensor.column(Eigenvalues.SmallestComponent()));
     266  const Vector BiggestEigenvector(InertiaTensor.column(Eigenvalues.SmallestComponent()));
    276267  Vector DesiredAxis(Axis.getNormalized());
    277268
     
    287278  // and rotate
    288279  for (iterator iter = begin(); iter != end(); ++iter) {
    289     *(*iter) -= *CenterOfGravity;
     280    *(*iter) -= CenterOfGravity;
    290281    (*iter)->setPosition(RotationAxis.rotateVector((*iter)->getPosition(), alpha));
    291     *(*iter) += *CenterOfGravity;
     282    *(*iter) += CenterOfGravity;
    292283  }
    293284  LOG(0, "STATUS: done.");
    294 
    295   delete CenterOfGravity;
    296285}
    297286
     
    304293 * x=(**factor) * x (as suggested by comment)
    305294 */
    306 void molecule::Scale(const double ** const factor)
     295void molecule::Scale(const double *factor)
    307296{
    308297  for (iterator iter = begin(); iter != end(); ++iter) {
    309298    for (size_t j=0;j<(*iter)->getTrajectorySize();j++) {
    310299      Vector temp = (*iter)->getPositionAtStep(j);
    311       temp.ScaleAll(*factor);
     300      temp.ScaleAll(factor);
    312301      (*iter)->setPositionAtStep(j,temp);
    313302    }
     
    318307 * \param trans[] translation vector.
    319308 */
    320 void molecule::Translate(const Vector *trans)
    321 {
    322   getAtomSet().translate(*trans);
     309void molecule::Translate(const Vector &trans)
     310{
     311  getAtomSet().translate(trans);
    323312};
    324313
     
    327316 * TODO treatment of trajectories missing
    328317 */
    329 void molecule::TranslatePeriodically(const Vector *trans)
     318void molecule::TranslatePeriodically(const Vector &trans)
    330319{
    331320  Translate(trans);
     
    338327 * \param n[] normal vector of mirror plane.
    339328 */
    340 void molecule::Mirror(const Vector *n)
    341 {
    342   Plane p(*n,0);
     329void molecule::Mirror(const Vector &n)
     330{
     331  Plane p(n,0);
    343332  getAtomSet().transformNodes(boost::bind(&Plane::mirrorVector,p,_1));
    344333};
     
    356345  Vector Testvector, Translationvector;
    357346  Vector Center;
    358   BondGraph *BG = World::getInstance().getBondGraph();
     347  const BondGraph * const BG = World::getInstance().getBondGraph();
    359348
    360349  do {
     
    407396
    408397  Center.Scale(1./static_cast<double>(getAtomCount()));
    409   CenterAtVector(&Center);
     398  CenterAtVector(Center);
    410399};
    411400
     
    413402 * \param n[] alignment vector.
    414403 */
    415 void molecule::Align(Vector *n)
     404void molecule::Align(const Vector &n)
    416405{
    417406  double alpha, tmp;
    418407  Vector z_axis;
     408  Vector alignment(n);
    419409  z_axis[0] = 0.;
    420410  z_axis[1] = 0.;
     
    423413  // rotate on z-x plane
    424414  LOG(0, "Begin of Aligning all atoms.");
    425   alpha = atan(-n->at(0)/n->at(2));
     415  alpha = atan(-alignment.at(0)/alignment.at(2));
    426416  LOG(1, "INFO: Z-X-angle: " << alpha << " ... ");
    427417  for (iterator iter = begin(); iter != end(); ++iter) {
     
    437427  }
    438428  // rotate n vector
    439   tmp = n->at(0);
    440   n->at(0) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
    441   n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
    442   LOG(1, "alignment vector after first rotation: " << n);
     429  tmp = alignment.at(0);
     430  alignment.at(0) =  cos(alpha) * tmp +  sin(alpha) * alignment.at(2);
     431  alignment.at(2) = -sin(alpha) * tmp +  cos(alpha) * alignment.at(2);
     432  LOG(1, "alignment vector after first rotation: " << alignment);
    443433
    444434  // rotate on z-y plane
    445   alpha = atan(-n->at(1)/n->at(2));
     435  alpha = atan(-alignment.at(1)/alignment.at(2));
    446436  LOG(1, "INFO: Z-Y-angle: " << alpha << " ... ");
    447437  for (iterator iter = begin(); iter != end(); ++iter) {
     
    457447  }
    458448  // rotate n vector (for consistency check)
    459   tmp = n->at(1);
    460   n->at(1) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
    461   n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
    462 
    463 
    464   LOG(1, "alignment vector after second rotation: " << n);
     449  tmp = alignment.at(1);
     450  alignment.at(1) =  cos(alpha) * tmp +  sin(alpha) * alignment.at(2);
     451  alignment.at(2) = -sin(alpha) * tmp +  cos(alpha) * alignment.at(2);
     452
     453  LOG(1, "alignment vector after second rotation: " << alignment);
    465454  LOG(0, "End of Aligning all atoms.");
    466455};
  • src/moleculelist.cpp

    r2d701e r833b15  
    229229      }
    230230      // Center and size
    231       Vector *Center = (*ListRunner)->DetermineCenterOfAll();
    232       (*out) << "\t" << *Center << "\t" << sqrt(size) << endl;
    233       delete(Center);
     231      Vector Center = (*ListRunner)->DetermineCenterOfAll();
     232      (*out) << "\t" << Center << "\t" << sqrt(size) << endl;
    234233    }
    235234  }
     
    578577//        if (BoxDimension[k] < 1.)
    579578//          BoxDimension[k] += 1.;
    580 //      (*ListRunner)->SetBoxDimension(&BoxDimension); // update Box of atoms by boundary
     579//      {
     580//        RealSpaceMatrix domain;
     581//        for(int i =0; i<NDIM;++i)
     582//          domain.at(i,i) = BoxDimension[i];
     583//        World::getInstance().setDomain(domain);
     584//      }
    581585//      for (int k = 0; k < NDIM; k++) {
    582586//        BoxDimension[k] = 2.5 * (World::getInstance().getConfig()->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
Note: See TracChangeset for help on using the changeset viewer.