Changeset 560bbe for src


Ignore:
Timestamp:
Feb 17, 2012, 3:24:18 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:
cdaae6
Parents:
ac5c36
git-author:
Frederik Heber <heber@…> (01/06/12 16:49:11)
git-committer:
Frederik Heber <heber@…> (02/17/12 15:24:18)
Message:

AtomicInfo now also (re)stores ParticleInfo::Nr, molecule has own IdPool.

  • molecule now also has an internal IdPool to be able to hand out unique ids, according to uniqueId policy.
  • new functions: molecule::changeAtomNr(), molecule::setAtomName()
  • molecule::erase() and ::insert() release and set the id (and the name).
  • molecule::setAtomName() uses getNr() with id increased by one.
  • AtomicInfo stores and sets ParticleInfo::Nr.
  • atom::changeNr() is similar to changeId() only for the molecule.
  • molecule::AddAtom() does not set the name anymore, is done by ::insert().
  • simplified molecule::doCountAtoms() a lot, no more naming of atoms.
  • SPEEDUP: This speeds up the GUI already a lot.
  • TESTFIX: changed regression test Tesselation/BigNonConvex due to different ordering of node ids (due to above), surface is still the same (checked).
Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Atom/AtomicInfo.cpp

    rac5c36 r560bbe  
    3535    FatherId(0),
    3636    MolId(0),
    37     Id(0)
     37    Id(0),
     38    Nr(0)
    3839{}
    3940AtomicInfo::AtomicInfo(const atom &_atom) :
     
    4344    FatherId(_atom.father->getId()),
    4445    MolId(_atom.getMolecule()->getId()),
    45     Id(_atom.getId())
     46    Id(_atom.getId()),
     47    Nr(_atom.getNr())
    4648{}
    4749
     
    7274  if (_mol != NULL)
    7375    _atom.setMolecule(_mol); // this is ok, mol is const within AtomicInfo, but not outside (atoms need to register)
     76  _atom.changeNr(Nr);
    7477
    7578  return status;
     
    9093  Velocity = AI.Velocity;
    9194  Id = AI.Id;
     95  Nr = AI.Nr;
    9296  return *this;
    9397}
  • src/Atom/AtomicInfo.hpp

    rac5c36 r560bbe  
    4141  moleculeId_t MolId;
    4242  atomId_t Id;
     43  int Nr;
    4344};
    4445
  • src/Atom/atom.cpp

    rac5c36 r560bbe  
    322322}
    323323
     324bool atom::changeNr(const int newNr)
     325{
     326  if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
     327    return true;
     328  } else{
     329    return false;
     330  }
     331}
     332
    324333int atom::getNr() const{
    325334  return ParticleInfo::getNr();
  • src/Atom/atom.hpp

    rac5c36 r560bbe  
    211211    */
    212212   void removeFromMolecule();
     213
     214   /** Changes the molecule internal ParticleInfo::Nr of this atom.
     215    *
     216    * @param newNr new ParticleInfo::Nr to set
     217    * @return true - change successful, false - changed not successful, id remains the old one
     218    */
     219   bool changeNr(int newNr);
    213220
    214221   /** Getter for ParticleInfo::Nr of the atom.
  • src/documentation/constructs/molecules.dox

    rac5c36 r560bbe  
    2929 * as well.
    3030 *
     31 * \section molecules-atoms Atoms
     32 *
     33 * Atoms are added to the molecule via molecule::AddAtom() and removed via
     34 * molecule::RemoveAtom(). Therein, the atom receives a unique ParticleInfo::Nr
     35 * that is useful only within the molecule and is displayed in the atoms name,
     36 * i.e. atom names only vary within the molecule.
     37 *
     38 * The molecule only stores the atoms global id and uses a boost::transform_iterator
     39 * to map the ids to the true refs obtained from the World.
     40 *
    3141 * \section molecules-formula Formula
    3242 *
  • src/molecule.cpp

    rac5c36 r560bbe  
    2525#include <gsl/gsl_inline.h>
    2626#include <gsl/gsl_heapsort.h>
     27
     28#include "molecule.hpp"
    2729
    2830#include "Atom/atom.hpp"
     
    3234#include "CodePatterns/Log.hpp"
    3335#include "config.hpp"
     36#include "Descriptors/AtomIdDescriptor.hpp"
    3437#include "Element/element.hpp"
    3538#include "Element/periodentafel.hpp"
     
    4144#include "LinearAlgebra/Vector.hpp"
    4245#include "LinkedCell/linkedcell.hpp"
    43 #include "molecule.hpp"
     46#include "IdPool_impl.hpp"
    4447#include "Tesselation/tesselation.hpp"
    4548#include "World.hpp"
     
    6366  AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"),
    6467  BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"),
     68  atomIdPool(0, 20, 100),
    6569  last_atom(0)
    6670{
     
    103107  cout << "Set name of molecule " << getId() << " to " << _name << endl;
    104108  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
     109}
     110
     111bool molecule::changeAtomNr(int oldNr, int newNr, atom* target){
     112  OBSERVE;
     113  if(atomIdPool.reserveId(newNr)){
     114    if (oldNr != -1)  // -1 is reserved and indicates no number
     115      atomIdPool.releaseId(oldNr);
     116    ASSERT (target,
     117        "molecule::changeAtomNr() - given target is NULL, cannot set Nr or name.");
     118    target->setNr(newNr);
     119    setAtomName(target);
     120    return true;
     121  } else{
     122    return false;
     123  }
    105124}
    106125
     
    197216    ++iter;
    198217    atomIds.erase( key->getId() );
     218    atomIdPool.releaseId(key->getNr());
     219    key->setNr(-1);
    199220    formula-=key->getType();
    200221    key->removeFromMolecule();
     
    213234  pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
    214235  if (res.second) { // push atom if went well
     236    key->setNr(atomIdPool.getNextId());
     237    setAtomName(key);
    215238    formula+=key->getType();
    216239    return pair<iterator,bool>(iterator(res.first, FromIdToAtom()),res.second);
     
    219242  }
    220243}
     244
     245void molecule::setAtomName(atom *_atom) const
     246{
     247  std::stringstream sstr;
     248  sstr << _atom->getType()->getSymbol() << _atom->getNr()+1;
     249  _atom->setName(sstr.str());
     250}
     251
    221252
    222253bool molecule::containsAtom(atom* key){
     
    247278  OBSERVE;
    248279  if (pointer != NULL) {
    249     if (pointer->getType() != NULL) {
    250       if (pointer->getType()->getAtomicNumber() != 1)
    251         NoNonHydrogen++;
    252       if(pointer->getName() == "Unknown"){
    253         stringstream sstr;
    254         sstr << pointer->getType()->getSymbol() << pointer->getNr()+1;
    255         pointer->setName(sstr.str());
    256       }
    257     }
     280    if (pointer->getType()->getAtomicNumber() != 1)
     281      NoNonHydrogen++;
    258282    insert(pointer);
    259283    pointer->setMolecule(this);
     
    10291053{
    10301054  int res = size();
    1031   int i = 0;
    10321055  NoNonHydrogen = 0;
    1033   for (molecule::iterator iter = begin(); iter != end(); ++iter) {
    1034     (*iter)->setNr(i);   // update number in molecule (for easier referencing in FragmentMolecule lateron)
     1056  // go through atoms and look for new ones
     1057  for (molecule::const_iterator iter = begin(); iter != end(); ++iter)
    10351058    if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it
    10361059      NoNonHydrogen++;
    1037     stringstream sstr;
    1038     sstr << (*iter)->getType()->getSymbol() << (*iter)->getNr()+1;
    1039     (*iter)->setName(sstr.str());
    1040     LOG(3, "Naming atom nr. " << (*iter)->getNr() << " " << (*iter)->getName() << ".");
    1041     i++;
    1042   }
    10431060  return res;
    10441061};
     
    11061123  ActiveFlag = !ActiveFlag;
    11071124}
     1125
     1126// construct idpool
     1127CONSTRUCT_IDPOOL(atomId_t, continuousId)
  • src/molecule.hpp

    rac5c36 r560bbe  
    3333#include "Formula.hpp"
    3434#include "Helpers/defs.hpp"
     35#include "IdPool_policy.hpp"
     36#include "IdPool.hpp"
    3537#include "types.hpp"
    3638
     
    9799  moleculeId_t id;
    98100  atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
     101  IdPool<atomId_t, uniqueId> atomIdPool;  //!< pool of internal ids such that way may guarantee uniqueness
     102
    99103protected:
    100104
     
    150154   */
    151155  const_iterator erase(atom * key);
     156
     157private:
     158  friend bool atom::changeNr(int newId);
     159  /**
     160   * used when changing an ParticleInfo::Nr.
     161   * Note that this number is local with this molecule.
     162   * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
     163   *
     164   * @param oldNr old Nr
     165   * @param newNr new Nr to set
     166   * @param *target ref to atom
     167   * @return indicates wether the change could be done or not.
     168   */
     169  bool changeAtomNr(int oldNr, int newNr, atom* target=0);
     170
     171  /** Sets the name of the atom.
     172   *
     173   * The name is set via its element symbol and its internal ParticleInfo::Nr.
     174   *
     175   * @param _atom atom whose name to set
     176   */
     177  void setAtomName(atom *_atom) const;
    152178
    153179public:
Note: See TracChangeset for help on using the changeset viewer.