Changeset ac9b56


Ignore:
Timestamp:
Feb 2, 2010, 3:53:04 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
f721c6
Parents:
e3c8b4
Message:

Added simple way to retrieve formula of a molecule using caching

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    re3c8b4 rac9b56  
    66
    77#include <cstring>
     8#include <boost/bind.hpp>
    89
    910#include "atom.hpp"
     
    3233  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3334  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
    34   ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start)
     35  ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start),
     36  formula(this,boost::bind(&molecule::calcFormula,this))
    3537{
    3638  // init atom chain list
     
    7274  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
    7375  FINISH_OBSERVER;
     76}
     77
     78const std::string molecule::getFormula(){
     79  return *formula;
     80}
     81
     82std::string molecule::calcFormula(){
     83  int Counts[MAX_ELEMENTS];
     84  stringstream sstr;
     85  for (int j = 0; j<MAX_ELEMENTS;j++)
     86    Counts[j] = 0;
     87  for(atom *Walker = start; Walker != end; Walker = Walker->next) {
     88    Counts[Walker->type->Z]++;
     89  }
     90  for(element* Elemental = elemente->end; Elemental != elemente->start; Elemental = Elemental->previous) {
     91    if (Counts[Elemental->Z] != 0)
     92      sstr << Elemental->symbol << Counts[Elemental->Z];
     93  }
     94  return sstr.str();
    7495}
    7596
  • src/molecule.hpp

    re3c8b4 rac9b56  
    3333#include "tesselation.hpp"
    3434#include "Patterns/Observer.hpp"
     35#include "Patterns/Cacheable.hpp"
    3536
    3637/****************************************** forward declarations *****************************/
     
    105106    char name[MAXSTRINGSIZE];         //!< arbitrary name
    106107
     108  private:
     109    Cacheable<string> formula;
     110
    107111public:
    108112  molecule(const periodentafel * const teil);
     
    112116  const std::string getName();
    113117  void setName(const std::string);
     118  const std::string getFormula();
     119  std::string calcFormula();
    114120
    115121  // re-definition of virtual functions from PointCloud
Note: See TracChangeset for help on using the changeset viewer.