Changeset 274d45 for src


Ignore:
Timestamp:
Jun 19, 2010, 3:54:47 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:
bf0edf
Parents:
ad2b411
git-author:
Frederik Heber <heber@…> (06/19/10 12:35:01)
git-committer:
Frederik Heber <heber@…> (06/19/10 15:54:47)
Message:

FIX: Atoms were stored not in the sequence they were loaded.

  1. The main problem is molecule::atomSet which is a set<atom *>, i.e. atoms are sorted by their appearance in memory. As memory need not be allocated sequentially, this gives rise to extreme arbitririty which is not desired. Instead the atoms should be stored in the sequence they were loaded/created. The solution is as follows:
  • config::SaveAll()
  • molecule::atomSet is now a list<atom *>
  • molecule::atomIds is a new set<atomId_t> (atomIdSet) which controls that (global) ids remain unique in the no more Atomset's set (but list)
  • molecule::erase() erases also in atomIds
  • molecule::insert() checks whether id is present by atomIds
  • molecule::find() as std::list does not have a find, we just go through the list until the object is found (or not), this may be speeded up by another internal list.
  • molecule::InternalPointer made lots of confusion as virtual function GoToFirst() is const, hence begin() (needed therein) returns const_iterator, which then cannot be simply re-cast into an iterator: We make it a pointer, reinterpret_cast the pointer and reference it back. Although InternalPointer is mutable, the compiler cannot use the non-const function begin() (it cannot be made const, as overloading is not allowed). (this is noted in the code also extensively.)
  • molecule::containsAtom() does not use count but the new find, as it returns only boolean anyway.
  • rewrote MoleculeListClass::SimpleMerge() to get rid of the extra iterator, as we remove all atoms in the end anyway.
  • FIX: MoleculeListClass::SimpleMultiMerge() - the created mol was not inserted into the moleculelist in the end, although it is the only one to remain.
  1. All other databases had missing headers with respect to those stored in elements_db.cpp. Hence, valence of hydrogen was not parsed and this caused several failures in CalculateOrbitals() (Psi numbers and MaxMinSetp in pcp conf file).
  1. Subsequenytly, various test cases (12, 21, 30, 31, 36-38, 39) were broken. This had two reasons:
  • Seemingly, CalculateOrbitals() was broken before hence MaxMinStep (pcp config) and MaxPsiDouble/PsiMaxNn[Up|Down] were always 0. (10-21,30-31,39)
  • As the order is now correct, fixes from commits c9217161ec2a5d5db508557fe98a32068461f45b and 22a6da8380911571debebd69444d2615450bbbd8 were obselete and have been reverted (order of the Ion?_Type...): Molecules/6 (30), Molecules/7 (31), Filling/1 (39)
  • Due to different ordering, Tesselation/3 (38) had completely different .dat file (though same tesselation)
  • r3d had small differences, mostly order or epsilon (0 not being 0 but ..-e16), hence diffing was deactivated, as r3d is deprecated anyway (since vmd can render triangles as well and better).

Signed-off-by: Frederik Heber <heber@…>

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Hbondangle.db

    rad2b411 r274d45  
     1# atomicnumber angles for single, double and triple bond (-1 no angle)
    121       180     -1      -1
    235       180     131.0   109.2
  • src/Hbonddistance.db

    rad2b411 r274d45  
     1#atomic number bond distances for single, double and triple bond (-1 no bond)
    121       0.74    -1      -1
    232       0.77429209      -1      -1
  • src/config.cpp

    rad2b411 r274d45  
    17841784  char filename[MAXSTRINGSIZE];
    17851785  ofstream output;
    1786   molecule *mol = World::getInstance().createMolecule();
    1787   mol->SetNameFromFilename(ConfigFileName);
     1786  molecule *mol = NULL;
    17881787
    17891788  if (!strcmp(configpath, GetDefaultPath())) {
     
    18161815  // translate each to its center and merge all molecules in MoleculeListClass into this molecule
    18171816  int N = molecules->ListOfMolecules.size();
    1818   int *src = new int[N];
    1819   N=0;
    1820   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
    1821     src[N++] = (*ListRunner)->IndexNr;
    1822     (*ListRunner)->Translate(&(*ListRunner)->Center);
    1823   }
    1824   molecules->SimpleMultiAdd(mol, src, N);
    1825   delete[](src);
    1826 
    1827   // ... and translate back
    1828   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
    1829     (*ListRunner)->Center.Scale(-1.);
    1830     (*ListRunner)->Translate(&(*ListRunner)->Center);
    1831     (*ListRunner)->Center.Scale(-1.);
     1817  if (N != 1) { // don't do anything in case of only one molecule (shifts mol ids otherwise)
     1818    int *src = new int[N];
     1819    N=0;
     1820    for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
     1821      src[N++] = (*ListRunner)->IndexNr;
     1822      (*ListRunner)->Translate(&(*ListRunner)->Center);
     1823    }
     1824    mol = World::getInstance().createMolecule();
     1825    mol->SetNameFromFilename(ConfigFileName);
     1826    molecules->SimpleMultiMerge(mol, src, N);
     1827    mol->doCountAtoms();
     1828    mol->CountElements();
     1829    mol->CalculateOrbitals(*this);
     1830    delete[](src);
     1831  } else {
     1832    if (!molecules->ListOfMolecules.empty()) {
     1833      mol = *(molecules->ListOfMolecules.begin());
     1834      mol->doCountAtoms();
     1835      mol->CalculateOrbitals(*this);
     1836    } else {
     1837      DoeLog(1) && (eLog() << Verbose(1) << "There are no molecules to save!" << endl);
     1838    }
    18321839  }
    18331840
    18341841  Log() << Verbose(0) << "Storing configuration ... " << endl;
    18351842  // get correct valence orbitals
    1836   mol->CalculateOrbitals(*this);
    1837   InitMaxMinStopStep = MaxMinStopStep = MaxPsiDouble;
    18381843  if (ConfigFileName != NULL) { // test the file name
    18391844    strcpy(filename, ConfigFileName);
     
    18951900  }
    18961901
    1897   World::getInstance().destroyMolecule(mol);
     1902  // don't destroy molecule as it contains all our atoms
     1903  //World::getInstance().destroyMolecule(mol);
    18981904};
    18991905
  • src/molecule.cpp

    rad2b411 r274d45  
    4242  NoCyclicBonds(0), BondDistance(0.),  ActiveFlag(false), IndexNr(-1),
    4343  formula(this,boost::bind(&molecule::calcFormula,this),"formula"),
    44   AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0),  InternalPointer(begin())
     44  AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0),  InternalPointer(atoms.begin())
    4545{
    4646
     
    146146  iter--;
    147147  atom* atom = *loc;
    148   atoms.erase( loc );
     148  atomIds.erase( atom->getId() );
     149  atoms.remove( atom );
    149150  atom->removeFromMolecule();
    150151  return iter;
     
    156157  molecule::const_iterator iter = find(key);
    157158  if (iter != end()){
    158     atoms.erase( iter++ );
     159    atomIds.erase( key->getId() );
     160    atoms.remove( key );
    159161    key->removeFromMolecule();
    160162  }
     
    164166molecule::const_iterator molecule::find ( atom * key ) const
    165167{
    166   return atoms.find( key );
     168  molecule::const_iterator iter;
     169  for (molecule::const_iterator Runner = begin(); Runner != end(); ++Runner) {
     170    if (*Runner == key)
     171      return molecule::const_iterator(Runner);
     172  }
     173  return molecule::const_iterator(atoms.end());
    167174}
    168175
    169176pair<molecule::iterator,bool> molecule::insert ( atom * const key )
    170177{
    171   pair<atomSet::iterator,bool> res = atoms.insert(key);
    172   return pair<iterator,bool>(iterator(res.first,this),res.second);
     178  pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
     179  if (res.second) { // push atom if went well
     180    atoms.push_back(key);
     181    return pair<iterator,bool>(molecule::iterator(--end()),res.second);
     182  } else {
     183    return pair<iterator,bool>(molecule::iterator(end()),res.second);
     184  }
    173185}
    174186
    175187bool molecule::containsAtom(atom* key){
    176   return atoms.count(key);
     188  return (find(key) != end());
    177189}
    178190
     
    790802  for (molecule::iterator iter = begin(); !empty(); iter = begin())
    791803      erase(iter);
     804  return empty();
    792805};
    793806
     
    10101023  configuration.MaxPsiDouble /= 2;
    10111024  configuration.PsiType = (configuration.PsiMaxNoDown == configuration.PsiMaxNoUp) ? 0 : 1;
    1012   if ((configuration.PsiType == 1) && (configuration.ProcPEPsi < 2)) {
     1025  if ((configuration.PsiType == 1) && (configuration.ProcPEPsi < 2) && ((configuration.PsiMaxNoDown != 1) || (configuration.PsiMaxNoUp != 0))) {
    10131026    configuration.ProcPEGamma /= 2;
    10141027    configuration.ProcPEPsi *= 2;
     
    10171030    configuration.ProcPEPsi = 1;
    10181031  }
    1019   configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.MaxPsiDouble;
     1032  cout << configuration.PsiMaxNoDown << ">" << configuration.PsiMaxNoUp << endl;
     1033  if (configuration.PsiMaxNoDown > configuration.PsiMaxNoUp) {
     1034    configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.PsiMaxNoDown;
     1035    cout << configuration.PsiMaxNoDown << " " << configuration.InitMaxMinStopStep << endl;
     1036  } else {
     1037    configuration.InitMaxMinStopStep = configuration.MaxMinStopStep = configuration.PsiMaxNoUp;
     1038    cout << configuration.PsiMaxNoUp << " " << configuration.InitMaxMinStopStep << endl;
     1039  }
    10201040};
    10211041
  • src/molecule.hpp

    rad2b411 r274d45  
    9393
    9494  public:
    95     typedef std::set<atom*> atomSet;
     95    typedef std::list<atom*> atomSet;
     96    typedef std::set<atomId_t> atomIdSet;
    9697    typedef ObservedIterator<atomSet> iterator;
    9798    typedef atomSet::const_iterator const_iterator;
     
    121122    Cacheable<int>    AtomCount;
    122123    moleculeId_t id;
    123     atomSet atoms; //<!set of atoms
     124    atomSet atoms; //<!list of atoms
     125    atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
    124126  protected:
    125127    //void CountAtoms();
  • src/molecule_pointcloud.cpp

    rad2b411 r274d45  
    5757void molecule::GoToFirst() const
    5858{
    59   InternalPointer = atoms.begin();
     59  // evil hack necessary because
     60  // -# although InternalPointer is mutable
     61  // -# only const_iterator begin() is called due to const in the function declaration above
     62  // -# and there is no cast from const_iterator to const iterator
     63  atomSet::const_iterator test = begin();
     64  InternalPointer = *(reinterpret_cast<atomSet::iterator *>(&test));
    6065};
    6166
  • src/moleculelist.cpp

    rad2b411 r274d45  
    212212
    213213  // put all molecules of src into mol
    214   molecule::iterator runner;
    215   for (molecule::iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) {
    216     runner = iter++;
    217     srcmol->UnlinkAtom((*runner));
    218     mol->AddAtom((*runner));
     214  for (molecule::iterator iter = srcmol->begin(); !srcmol->empty(); iter=srcmol->begin()) {
     215    atom * const Walker = *iter;
     216    srcmol->UnlinkAtom(Walker);
     217    mol->AddAtom(Walker);
    219218  }
    220219
     
    259258    status = status && SimpleMerge(mol, srcmol);
    260259  }
     260  insert(mol);
    261261  return status;
    262262};
  • src/orbitals.db

    rad2b411 r274d45  
     1# atomicnumber numberoforbitals
    121       1
    232       0
  • src/periodentafel.cpp

    rad2b411 r274d45  
    373373      (*input) >> elements[Z]->Valence;
    374374      (*input) >> ws;
    375       //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
     375      //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->Valence << " valence electrons." << endl;
    376376    }
    377377    return true;
     
    396396      (*input) >> elements[Z]->NoValenceOrbitals;
    397397      (*input) >> ws;
    398       //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     398      //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
    399399    }
    400400    return true;
  • src/valence.db

    rad2b411 r274d45  
     1#atomicnumber numberofvalenceorbitals
    121       0.10000000000000E+01
    232       0.20000000000000E+01
Note: See TracChangeset for help on using the changeset viewer.