Changeset cf959d


Ignore:
Timestamp:
Apr 27, 2008, 12:53:53 PM (17 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:
73f80e
Parents:
dbe929
Message:

Load/StorePeriodentafel(): filename as parameter, if NULL default name in pwd is used

Filename is NULL by default or parsed on command line (new -e switch). It was necessary because of command line test (make check), as elements.db is not in the same dir. Also, opening of files is checked and a related status returned for both functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/periodentafel.cpp

    rdbe929 rcf959d  
    161161/** Loads element list from file.
    162162 */
    163 bool periodentafel::LoadPeriodentafel()
     163bool periodentafel::LoadPeriodentafel(char *filename)
    164164{
    165165  ifstream infile;
    166166  double tmp;
    167167  element *ptr;
     168  bool status = true;
     169  bool otherstatus = true;
    168170 
    169171  // fill elements DB
    170   infile.open("elements.db");
    171   infile.getline(header1, 255);
    172   infile.getline(header2, 255); // skip first two header lines
    173   while (!infile.eof()) {
    174     element *neues = new element;
    175     infile >> neues->name;
    176     //infile >> ws;
    177     infile >> neues->symbol;
    178     //infile >> ws;
    179     infile >> neues->period;
    180     //infile >> ws;
    181     infile >> neues->group;
    182     //infile >> ws;
    183     infile >> neues->block;
    184     //infile >> ws;
    185     infile >> neues->Z;
    186     //infile >> ws;
    187     infile >> neues->mass;
    188     //infile >> ws;
    189     infile >> neues->CovalentRadius;
    190     //infile >> ws;
    191     infile >> neues->VanDerWaalsRadius;
    192     //infile >> ws;
    193     periodentafel::AddElement(neues);
    194     infile >> ws;
    195     //neues->Output((ofstream *)&cout);
    196   }
    197   infile.close();
    198   infile.clear();
     172  if (filename == NULL)
     173    infile.open("elements.db");
     174  else
     175    infile.open(filename);
     176  if (infile != NULL) {
     177    infile.getline(header1, 255);
     178    infile.getline(header2, 255); // skip first two header lines
     179    cout <<  "Parsed elements:";
     180    while (!infile.eof()) {
     181      element *neues = new element;
     182      infile >> neues->name;
     183      //infile >> ws;
     184      infile >> neues->symbol;
     185      //infile >> ws;
     186      infile >> neues->period;
     187      //infile >> ws;
     188      infile >> neues->group;
     189      //infile >> ws;
     190      infile >> neues->block;
     191      //infile >> ws;
     192      infile >> neues->Z;
     193      //infile >> ws;
     194      infile >> neues->mass;
     195      //infile >> ws;
     196      infile >> neues->CovalentRadius;
     197      //infile >> ws;
     198      infile >> neues->VanDerWaalsRadius;
     199      //infile >> ws;
     200      periodentafel::AddElement(neues);
     201      infile >> ws;
     202      cout << " " << neues->symbol;
     203      //neues->Output((ofstream *)&cout);
     204    }
     205    cout << endl;
     206    infile.close();
     207    infile.clear();
     208  } else
     209    status = false;
    199210
    200211  // fill valence DB per element
    201212  infile.open("valence.db");
    202   while (!infile.eof()) {
    203         infile >> tmp;
    204         infile >> ws;
    205         infile >> FindElement((int)tmp)->Valence;
    206         infile >> ws;
    207         //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->Valence << " valence electrons." << endl;
    208   }
    209   infile.close();
    210   infile.clear();
     213  if (infile != NULL) {
     214    while (!infile.eof()) {
     215        infile >> tmp;
     216        infile >> ws;
     217        infile >> FindElement((int)tmp)->Valence;
     218        infile >> ws;
     219        //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->Valence << " valence electrons." << endl;
     220    }
     221    infile.close();
     222    infile.clear();
     223  } else
     224    otherstatus = false;
    211225
    212226  // fill valence DB per element
    213227  infile.open("orbitals.db");
    214   while (!infile.eof()) {
    215     infile >> tmp;
    216     infile >> ws;
    217     infile >> FindElement((int)tmp)->NoValenceOrbitals;
    218     infile >> ws;
    219     //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
    220   }
    221   infile.close();
    222   infile.clear();
     228  if (infile != NULL) {
     229    while (!infile.eof()) {
     230      infile >> tmp;
     231      infile >> ws;
     232      infile >> FindElement((int)tmp)->NoValenceOrbitals;
     233      infile >> ws;
     234      //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     235    }
     236    infile.close();
     237    infile.clear();
     238  } else
     239    otherstatus = false;
    223240 
    224241  // fill H-BondDistance DB per element
    225242  infile.open("Hbonddistance.db");
    226   while (!infile.eof()) {
    227         infile >> tmp;
    228     ptr = FindElement((int)tmp);
    229         infile >> ws;
    230     infile >> ptr->HBondDistance[0];
    231     infile >> ptr->HBondDistance[1];
    232     infile >> ptr->HBondDistance[2];
    233         infile >> ws;
    234     //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
    235   }
    236   infile.close();
    237   infile.clear();
     243  if (infile != NULL) {
     244    while (!infile.eof()) {
     245        infile >> tmp;
     246      ptr = FindElement((int)tmp);
     247        infile >> ws;
     248      infile >> ptr->HBondDistance[0];
     249      infile >> ptr->HBondDistance[1];
     250      infile >> ptr->HBondDistance[2];
     251        infile >> ws;
     252      //cout << Verbose(3) << "Element " << (int)tmp << " has " << find_element((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
     253    }
     254    infile.close();
     255    infile.clear();
     256  } else
     257    otherstatus = false;
    238258 
    239259  // fill H-BondAngle DB per element
    240260  infile.open("Hbondangle.db");
    241   while (!infile.eof()) {
    242     infile >> tmp;
    243     ptr = FindElement((int)tmp);
    244     infile >> ws;
    245     infile >> ptr->HBondAngle[0];
    246     infile >> ptr->HBondAngle[1];
    247     infile >> ptr->HBondAngle[2];
    248     infile >> ws;
    249     //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondAngle[0] << ", " << FindElement((int)tmp)->HBondAngle[1] << ", " << FindElement((int)tmp)->HBondAngle[2] << " degrees bond angle for one, two, three connected hydrogens." << endl;
    250   }
    251   infile.close();
    252  
    253   return true;
     261  if (infile != NULL) {
     262    while (!infile.eof()) {
     263      infile >> tmp;
     264      ptr = FindElement((int)tmp);
     265      infile >> ws;
     266      infile >> ptr->HBondAngle[0];
     267      infile >> ptr->HBondAngle[1];
     268      infile >> ptr->HBondAngle[2];
     269      infile >> ws;
     270      //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondAngle[0] << ", " << FindElement((int)tmp)->HBondAngle[1] << ", " << FindElement((int)tmp)->HBondAngle[2] << " degrees bond angle for one, two, three connected hydrogens." << endl;
     271    }
     272    infile.close();
     273  } else
     274    otherstatus = false;
     275 
     276  return status;
    254277};
    255278
    256279/** Stores element list to file.
    257280 */
    258 bool periodentafel::StorePeriodentafel() const
     281bool periodentafel::StorePeriodentafel(char *filename) const
    259282{
    260283  bool result = true;
    261   ofstream f("elements.db");
    262   f << header1 << endl;
    263   f << header2 << endl;
    264   element *walker = periodentafel::start;
    265   while (walker->next != periodentafel::end) {
    266     walker = walker->next;
    267     result = result && walker->Output(&f);
    268   }
    269   f.close();
     284  ofstream f;
     285 
     286  if (filename == NULL)
     287    f.open("elements.db");
     288  else
     289    f.open(filename);
     290  if (f != NULL) {
     291    f << header1 << endl;
     292    f << header2 << endl;
     293    element *walker = periodentafel::start;
     294    while (walker->next != periodentafel::end) {
     295      walker = walker->next;
     296      result = result && walker->Output(&f);
     297    }
     298    f.close();
     299  } else
     300    result = false;
    270301  return result;
    271302};
Note: See TracChangeset for help on using the changeset viewer.