Changeset 9106c6 for src/molecule.cpp


Ignore:
Timestamp:
Jul 28, 2010, 1:48:50 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:
0bb05a
Parents:
b1a39b (diff), a7b777c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'StructureRefactoring' into stable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    rb1a39b r9106c6  
    4949molecule::molecule(const periodentafel * const teil) :
    5050  Observable("molecule"),
    51   elemente(teil),  MDSteps(0),  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0),
     51  elemente(teil),  MDSteps(0),  BondCount(0), NoNonHydrogen(0), NoNonBonds(0),
    5252  NoCyclicBonds(0), BondDistance(0.),  ActiveFlag(false), IndexNr(-1),
    53   formula(this,boost::bind(&molecule::calcFormula,this),"formula"),
    5453  AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0),  InternalPointer(atoms.begin())
    5554{
    5655
    57   // other stuff
    58   for(int i=MAX_ELEMENTS;i--;)
    59     ElementsInMolecule[i] = 0;
    6056  strcpy(name,World::getInstance().getDefaultName().c_str());
    6157};
     
    10197}
    10298
    103 const std::string molecule::getFormula(){
    104   return *formula;
    105 }
    106 
    107 std::string molecule::calcFormula(){
    108   std::map<atomicNumber_t,unsigned int> counts;
    109   stringstream sstr;
    110   periodentafel *periode = World::getInstance().getPeriode();
    111   for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    112     counts[(*iter)->type->getNumber()]++;
    113   }
    114   std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
    115   for(iter = counts.rbegin(); iter != counts.rend(); ++iter) {
    116     atomicNumber_t Z = (*iter).first;
    117     sstr << periode->FindElement(Z)->symbol << (*iter).second;
    118   }
    119   return sstr.str();
     99const Formula &molecule::getFormula(){
     100  return formula;
     101}
     102
     103unsigned int molecule::getElementCount(){
     104  return formula.getElementCount();
     105}
     106
     107bool molecule::hasElement(const element *element) const{
     108  return formula.hasElement(element);
     109}
     110
     111bool molecule::hasElement(atomicNumber_t Z) const{
     112  return formula.hasElement(Z);
     113}
     114
     115bool molecule::hasElement(const string &shorthand) const{
     116  return formula.hasElement(shorthand);
    120117}
    121118
     
    210207    pointer->sort = &pointer->nr;
    211208    if (pointer->type != NULL) {
    212       if (ElementsInMolecule[pointer->type->Z] == 0)
    213         ElementCount++;
    214       ElementsInMolecule[pointer->type->Z]++; // increase number of elements
     209      formula += pointer->type;
    215210      if (pointer->type->Z != 1)
    216211        NoNonHydrogen++;
     
    651646
    652647  // copy values
    653   copy->CountElements();
    654648  if (hasBondStructure()) {  // if adjaceny list is present
    655649    copy->BondDistance = BondDistance;
     
    774768  ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom().");
    775769  OBSERVE;
    776   if (ElementsInMolecule[pointer->type->Z] != 0)  { // this would indicate an error
    777     ElementsInMolecule[pointer->type->Z]--;  // decrease number of atom of this element
    778   } else
    779     DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->getName() << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    780   if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    781     ElementCount--;
     770  formula-=pointer->type;
    782771  RemoveBonds(pointer);
    783772  erase(pointer);
     
    793782  if (pointer == NULL)
    794783    return false;
    795   if (ElementsInMolecule[pointer->type->Z] != 0)  // this would indicate an error
    796     ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element
    797   else
    798     DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->getName() << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    799   if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    800     ElementCount--;
     784  formula-=pointer->type;
    801785  erase(pointer);
    802786  return true;
     
    871855{
    872856  int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS];
    873   CountElements();
    874857
    875858  for (int i=0;i<MAX_ELEMENTS;++i) {
     
    898881{
    899882  int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS];
    900   CountElements();
    901883
    902884  if (output == NULL) {
     
    940922bool molecule::Checkout(ofstream * const output)  const
    941923{
    942   return elemente->Checkout(output, ElementsInMolecule);
     924  return formula.checkOut(output);
    943925};
    944926
     
    998980};
    999981
    1000 /** Brings molecule::ElementCount and molecule::ElementsInMolecule up-to-date.
    1001  */
    1002 void molecule::CountElements()
    1003 {
    1004   for(int i=MAX_ELEMENTS;i--;)
    1005     ElementsInMolecule[i] = 0;
    1006   ElementCount = 0;
    1007 
    1008   SetIndexedArrayForEachAtomTo ( ElementsInMolecule, &element::Z, &Increment, 1);
    1009 
    1010   for(int i=MAX_ELEMENTS;i--;)
    1011     ElementCount += (ElementsInMolecule[i] != 0 ? 1 : 0);
    1012 };
    1013 
    1014982/** Determines whether two molecules actually contain the same atoms and coordination.
    1015983 * \param *out output stream for debugging
     
    1030998  /// first count both their atoms and elements and update lists thereby ...
    1031999  //Log() << Verbose(0) << "Counting atoms, updating list" << endl;
    1032   CountElements();
    1033   OtherMolecule->CountElements();
    10341000
    10351001  /// ... and compare:
     
    10411007    } else Log() << Verbose(4) << "AtomCounts match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl;
    10421008  }
    1043   /// -# ElementCount
     1009  /// -# Formula
    10441010  if (result) {
    1045     if (ElementCount != OtherMolecule->ElementCount) {
    1046       DoLog(4) && (Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl);
     1011    if (formula != OtherMolecule->formula) {
     1012      DoLog(4) && (Log() << Verbose(4) << "Formulas don't match: " << formula << " == " << OtherMolecule->formula << endl);
    10471013      result = false;
    1048     } else Log() << Verbose(4) << "ElementCount match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;
    1049   }
    1050   /// -# ElementsInMolecule
    1051   if (result) {
    1052     for (flag=MAX_ELEMENTS;flag--;) {
    1053       //Log() << Verbose(5) << "Element " <<  flag << ": " << ElementsInMolecule[flag] << " <-> " << OtherMolecule->ElementsInMolecule[flag] << "." << endl;
    1054       if (ElementsInMolecule[flag] != OtherMolecule->ElementsInMolecule[flag])
    1055         break;
    1056     }
    1057     if (flag < MAX_ELEMENTS) {
    1058       DoLog(4) && (Log() << Verbose(4) << "ElementsInMolecule don't match." << endl);
    1059       result = false;
    1060     } else Log() << Verbose(4) << "ElementsInMolecule match." << endl;
     1014    } else Log() << Verbose(4) << "Formulas match: " << formula << " == " << OtherMolecule->formula << endl;
    10611015  }
    10621016  /// then determine and compare center of gravity for each molecule ...
Note: See TracChangeset for help on using the changeset viewer.