Changeset 61745cc


Ignore:
Timestamp:
Jun 10, 2010, 4:17:22 PM (15 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:
198494
Parents:
7e6b00
Message:

BUGFIX: LoadPeriodentafel() did not close files and elements have to be replaced in-place.

  • LoadPeriodentafel() - input file was never closed or cleared.
  • LoadPeriodentafel() - new element in case of presence of same-Z, deleted the old one and installed a new one. However, atoms::type knows nothing about this change! Has to be done in-place.
  • LoadPeriodentafel() - insertion is now tested with ASSERT
  • periodentafel::RemoveElement() now return number of removed elements (good for ASSERT checks)
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/periodentafel.cpp

    r7e6b00 r61745cc  
    7070 * \param *pointer element to be removed
    7171 */
    72 void periodentafel::RemoveElement(element * const pointer)
    73 {
    74   RemoveElement(pointer->getNumber());
     72size_t periodentafel::RemoveElement(element * const pointer)
     73{
     74  return RemoveElement(pointer->getNumber());
    7575};
    7676
     
    7878 * \param Z element to be removed
    7979 */
    80 void periodentafel::RemoveElement(atomicNumber_t Z)
    81 {
    82   elements.erase(Z);
     80size_t periodentafel::RemoveElement(atomicNumber_t Z)
     81{
     82  return elements.erase(Z);
    8383};
    8484
     
    233233  strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
    234234  input.open(filename);
     235  if (!input.fail())
     236    DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as elements database." << endl);
    235237  status = status && LoadElementsDatabase(&input);
     238  input.close();
     239  input.clear();
    236240
    237241  // fill valence DB per element
     
    240244  strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
    241245  input.open(filename);
     246  if (!input.fail())
     247    DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as valence database." << endl);
    242248  otherstatus = otherstatus && LoadValenceDatabase(&input);
     249  input.close();
     250  input.clear();
    243251
    244252  // fill orbitals DB per element
     
    247255  strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
    248256  input.open(filename);
     257  if (!input.fail())
     258    DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as orbitals database." << endl);
    249259  otherstatus = otherstatus && LoadOrbitalsDatabase(&input);
     260  input.close();
     261  input.clear();
    250262
    251263  // fill H-BondAngle DB per element
     
    254266  strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
    255267  input.open(filename);
     268  if (!input.fail())
     269    DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond angle database." << endl);
    256270  otherstatus = otherstatus && LoadHBondAngleDatabase(&input);
     271  input.close();
     272  input.clear();
    257273
    258274  // fill H-BondDistance DB per element
     
    261277  strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
    262278  input.open(filename);
     279  if (!input.fail())
     280    DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond length database." << endl);
    263281  otherstatus = otherstatus && LoadHBondLengthsDatabase(&input);
     282  input.close();
     283  input.clear();
    264284
    265285  if (!otherstatus){
     
    278298  bool status = true;
    279299  int counter = 0;
     300  pair< std::map<atomicNumber_t,element*>::iterator, bool > InserterTest;
    280301  if (!(*input).fail()) {
    281302    (*input).getline(header1, MAXSTRINGSIZE);
     
    303324      //(*input) >> ws;
    304325      (*input) >> ws;
    305       if (elements.count(neues->Z)) {// if element already present, remove and delete it
    306         element * const Elemental = FindElement(neues->Z);
    307         ASSERT(Elemental != NULL, "element should be present but is not??");
    308         RemoveElement(Elemental);
    309         delete(Elemental);
    310       }
    311326      //neues->Output((ofstream *)&cout);
    312       if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) {
    313         DoLog(0) && (Log() << Verbose(0) << " " << neues->symbol);
    314         elements[neues->getNumber()] = neues;
     327      if ((neues->getNumber() > 0) && (neues->getNumber() < MAX_ELEMENTS)) {
     328        if (elements.count(neues->getNumber())) {// if element already present, remove and delete old one (i.e. replace it)
     329          //cout << neues->symbol << " is present already." << endl;
     330          element * const Elemental = FindElement(neues->getNumber());
     331          ASSERT(Elemental != NULL, "element should be present but is not??");
     332          *Elemental = *neues;
     333        } else {
     334          InserterTest = elements.insert(pair <atomicNumber_t,element*> (neues->getNumber(), neues));
     335          ASSERT(InserterTest.second, "Could not insert new element into periodentafel on LoadElementsDatabase().");
     336        }
     337        DoLog(0) && (Log() << Verbose(0) << " " << elements[neues->getNumber()]->symbol);
    315338        counter++;
    316339      } else {
     
    321344    }
    322345    DoLog(0) && (Log() << Verbose(0) << endl);
    323   } else
     346  } else {
     347    DoeLog(1) && (eLog() << Verbose(1) << "Could not open the database." << endl);
    324348    status = false;
     349  }
    325350
    326351  if (counter == 0)
  • src/periodentafel.hpp

    r7e6b00 r61745cc  
    4444
    4545  iterator AddElement(element * const pointer);
    46   void RemoveElement(element * const pointer);
    47   void RemoveElement(atomicNumber_t);
     46  size_t RemoveElement(element * const pointer);
     47  size_t RemoveElement(atomicNumber_t);
    4848  void CleanupPeriodtable();
    4949  element * const FindElement(atomicNumber_t) const;
Note: See TracChangeset for help on using the changeset viewer.