Changeset 3d0892


Ignore:
Timestamp:
Apr 5, 2012, 3:55:47 PM (13 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:
2034f3
Parents:
d2596b
git-author:
Frederik Heber <heber@…> (03/26/12 09:59:32)
git-committer:
Frederik Heber <heber@…> (04/05/12 15:55:47)
Message:

Added an additionalAtomInfo container to XmlParser.

  • this stores the parser-specific information such as charge, ...
Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParserStorage.cpp

    rd2596b r3d0892  
    3737#include "Psi3Parser.hpp"
    3838#include "TremoloParser.hpp"
     39#include "XmlParser.hpp"
    3940#include "XyzParser.hpp"
    4041
  • src/Parser/XmlParser.cpp

    rd2596b r3d0892  
    3737
    3838#include "Parser/pugixml/pugixml.hpp"
     39
     40// static instances
     41FormatParser< xml >::additionalAtomInfo FormatParser< xml >::defaultAtomInfo;
    3942
    4043// declare specialized static variables
     
    162165    newAtom->setPosition(p.position);
    163166    newmol->AddAtom(newAtom);
     167    additionalAtomInfo atomInfo(p.q, p.potential, p.field);
     168#ifndef NDEBUG
     169    std::pair<AtomInfoMap_t::iterator, bool> inserter =
     170#endif
     171    additionalAtomData.insert( std::make_pair(newAtom->getId(), atomInfo) );
     172    ASSERT( inserter.second,
     173        "FormatParser< xml >::load() - atomInfo entry for atom "+toString(newAtom->getId())
     174        +" already present.");
    164175  }
    165176
     
    188199  for(std::vector<atom*>::const_iterator it = atoms.begin(); it != atoms.end(); it++) {
    189200    struct scafacos::configuration::particle p;
     201    const additionalAtomInfo &atomInfo = getAtomData(*(*it));
    190202    p.position = (*it)->getPosition();
    191     p.q = 0.;
    192     p.potential = 0.;
    193     p.field = zeroVec;
     203    p.q = atomInfo.charge;
     204    p.potential = atomInfo.potential;
     205    p.field = atomInfo.field;
    194206    data.config.p.push_back(p);
    195207  }
     
    234246}
    235247
     248/** Observer callback when new atom is added to World.
     249 *
     250 * @param id of atom
     251 */
     252void FormatParser< xml >::AtomInserted(atomId_t id)
     253{
     254  std::map<const atomId_t, additionalAtomInfo>::iterator iter = additionalAtomData.find(id);
     255  ASSERT(iter == additionalAtomData.end(),
     256      "FormatParser< xml >::AtomInserted() - additionalAtomData already present for newly added atom "
     257      +toString(id)+".");
     258  // additionalAtomData.insert( std::make_pair(id, additionalAtomInfo()) );
     259}
     260
     261/** Remove additional AtomData info, when atom has been removed from World.
     262 *
     263 * @param id of atom
     264 */
     265void FormatParser< xml >::AtomRemoved(atomId_t id)
     266{
     267  std::map<const atomId_t, additionalAtomInfo>::iterator iter = additionalAtomData.find(id);
     268  // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
     269//  ASSERT(iter != additionalAtomData.end(),
     270//      "FormatParser< tremolo >::AtomRemoved() - additionalAtomData is not present for atom "
     271//      +toString(id)+" to remove.");
     272  if (iter != additionalAtomData.end())
     273    additionalAtomData.erase(iter);
     274}
     275
     276const FormatParser< xml >::additionalAtomInfo& FormatParser< xml >::getAtomData(const atom &_atom) const
     277{
     278  {
     279    // has its own entry?
     280    AtomInfoMap_t::const_iterator iter = additionalAtomData.find(_atom.getId());
     281    if (iter != additionalAtomData.end()) {
     282      return iter->second;
     283    }
     284  }
     285  {
     286    // father has an entry?
     287    AtomInfoMap_t::const_iterator iter = additionalAtomData.find(_atom.GetTrueFather()->getId());
     288    if (iter != additionalAtomData.end()) {
     289      return iter->second;
     290    }
     291  }
     292  return defaultAtomInfo;
     293}
     294
     295
    236296#define comparator(x,y) if (x != y) { LOG(2, "DEBUG: Mismatch in " << #x << ": " << x << " != " << y); return false; }
    237297#define num_comparator(x,y) if (fabs(x - y) > MYEPSILON) { LOG(2, "DEBUG: Numeric mismatch in " << #x << ": " << x << " != " << y << " by " << fabs(x - y) << "."); return false; }
     
    265325}
    266326
     327
    267328bool FormatParser< xml >::scafacos::operator==(const scafacos &s) const {
    268329  comparator(name, s.name)
  • src/Parser/XmlParser.hpp

    rd2596b r3d0892  
    1414#endif
    1515
     16#include <map>
    1617#include <string>
    1718
     
    5354  void save(std::ostream* file, const std::vector<atom *> &atoms);
    5455
     56protected:
     57  void AtomInserted(atomId_t);
     58  void AtomRemoved(atomId_t);
     59
    5560private:
    5661  //!> structure that contains all information from the xml file
     
    9196    }
    9297  } data;
     98
     99  //!> additional parser-specific information for an atom.
     100  struct additionalAtomInfo {
     101    /** Default constructor for additionalAtomInfo.
     102     *
     103     * Sets all parser-specific values to zero.
     104     */
     105    additionalAtomInfo() :
     106      charge(0.),
     107      potential(0),
     108      field(zeroVec)
     109    {}
     110
     111    /** Default constructor for additionalAtomInfo.
     112     *
     113     */
     114    additionalAtomInfo(double _charge, double _potential, const Vector& _field) :
     115      charge(_charge),
     116      potential(_potential),
     117      field(_field)
     118    {}
     119
     120    //!> charge of the atom
     121    double charge;
     122    //!> potential at position of atom
     123    double potential;
     124    //!> field at position of atom
     125    Vector field;
     126  };
     127
     128  //!> typedef for map to associate additional parser-specific information to each atom.
     129  typedef std::map< atomId_t, additionalAtomInfo> AtomInfoMap_t;
     130
     131  //!> map to associate additional parser-specific information to each atom.
     132  AtomInfoMap_t additionalAtomData;
     133
     134  //!> static instance with default additional atom information
     135  static additionalAtomInfo defaultAtomInfo;
     136
     137  /** Getter for additionalAtomInfo.
     138   *
     139   * @param _atom constant ref to atom
     140   * @return constant reference to additional atom info container,
     141   *         otherwise to default atom info
     142   */
     143  const additionalAtomInfo& getAtomData(const atom &_atom) const;
    93144};
    94145
Note: See TracChangeset for help on using the changeset viewer.