Changeset e9f8f9 for src


Ignore:
Timestamp:
Oct 6, 2009, 5:57:01 PM (16 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:
fcd7b6
Parents:
ebcade
Message:

More functions of molecule now use templated iterators.

Location:
src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    rebcade re9f8f9  
    11SOURCE = atom.cpp bond.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    2 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp memoryallocator.hpp memoryusageobserver.cpp memoryusageobserver.hpp molecule.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     2HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp memoryallocator.hpp memoryusageobserver.cpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
    33
    44noinst_PROGRAMS =  ActOnAllTest VectorUnitTest MemoryAllocatorUnitTest MemoryUsageObserverUnitTest TesselationUnitTest
  • src/atom.cpp

    rebcade re9f8f9  
    102102};
    103103
     104/** Checks whether atom is within the given box.
     105 * \param offset offset to box origin
     106 * \param *parallelepiped box matrix
     107 * \return true - is inside, false - is not
     108 */
     109bool atom::IsInParallelepiped(Vector offset, double *parallelepiped)
     110{
     111  return (node->IsInParallelepiped(offset, parallelepiped));
     112};
     113
    104114/** Output of a single atom.
    105115 * \param ElementNo cardinal number of the element
     
    112122  if (out != NULL) {
    113123    *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint;
     124    *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
     125    *out << "\t" << FixedIon;
     126    if (v.Norm() > MYEPSILON)
     127      *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
     128    if (comment != NULL)
     129      *out << " # " << comment << endl;
     130    else
     131      *out << " # molecule nr " << nr << endl;
     132    return true;
     133  } else
     134    return false;
     135};
     136bool atom::Output(int *ElementNo, int *AtomNo, ofstream *out, const char *comment)
     137{
     138  AtomNo[type->Z]++;  // increment number
     139  if (out != NULL) {
     140    *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t"  << fixed << setprecision(9) << showpoint;
    114141    *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
    115142    *out << "\t" << FixedIon;
  • src/atom.hpp

    rebcade re9f8f9  
    5252
    5353  bool Output(int ElementNo, int AtomNo, ofstream *out, const char *comment = NULL) const;
     54  bool Output(int *ElementNo, int *AtomNo, ofstream *out, const char *comment = NULL);
    5455  bool OutputXYZLine(ofstream *out) const;
    5556  void EqualsFather ( atom *ptr, atom **res );
     
    5758  atom *GetTrueFather();
    5859  bool Compare(const atom &ptr);
     60
     61  bool IsInParallelepiped(Vector offset, double *parallelepiped);
    5962
    6063  ostream & operator << (ostream &ost);
  • src/helpers.cpp

    rebcade re9f8f9  
    144144};
    145145
    146 
  • src/helpers.hpp

    rebcade re9f8f9  
    273273};
    274274
     275template <typename T> void Increment(T *value, T inc)
     276{
     277  *value += inc;
     278};
     279
     280template <typename T> void AbsoluteValue(T *value, T abs)
     281{
     282  *value = abs;
     283};
     284
    275285
    276286
  • src/molecule.cpp

    rebcade re9f8f9  
    66
    77#include "config.hpp"
     8#include "helpers.hpp"
    89#include "memoryallocator.hpp"
    910#include "molecule.hpp"
     
    482483{
    483484  molecule *copy = new molecule(elemente);
    484   atom *CurrentAtom = NULL;
    485485  atom *LeftAtom = NULL, *RightAtom = NULL;
    486   atom *Walker = NULL;
    487486
    488487  // copy all atoms
    489   Walker = start;
    490   while(Walker->next != end) {
    491     Walker = Walker->next;
    492     CurrentAtom = copy->AddCopyAtom(Walker);
    493   }
     488  ActOnCopyWithEachAtom ( &molecule::AddCopyAtom, copy );
    494489
    495490  // copy all bonds
     
    532527molecule* molecule::CopyMoleculeFromSubRegion(Vector offset, double *parallelepiped) {
    533528  molecule *copy = new molecule(elemente);
    534   atom *Walker = start;
    535 
    536   while(Walker->next != end) {
    537     Walker = Walker->next;
    538     if (Walker->x.IsInParallelepiped(offset, parallelepiped)) {
    539       cout << "Adding atom " << *Walker << endl;
    540       copy->AddCopyAtom(Walker);
    541     }
    542   }
     529
     530  ActOnCopyWithEachAtomIfTrue ( &molecule::AddCopyAtom, copy, &atom::IsInParallelepiped, offset, parallelepiped );
    543531
    544532  //TODO: copy->BuildInducedSubgraph((ofstream *)&cout, this);
     
    721709bool molecule::Output(ofstream *out)
    722710{
    723   atom *walker = NULL;
    724711  int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS];
    725712  CountElements();
     
    733720  } else {
    734721    *out << "#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)" << endl;
    735     walker = start;
    736     while (walker->next != end) { // go through every atom of this element
    737       walker = walker->next;
    738       ElementNo[walker->type->Z] = 1;
    739     }
     722    SetIndexedArrayForEachAtomTo ( ElementNo, &element::Z, &AbsoluteValue, 1);
    740723    int current=1;
    741724    for (int i=0;i<MAX_ELEMENTS;++i) {
     
    743726        ElementNo[i] = current++;
    744727    }
    745     walker = start;
    746     while (walker->next != end) { // go through every atom of this element
    747       walker = walker->next;
    748       AtomNo[walker->type->Z]++;
    749       walker->Output(ElementNo[walker->type->Z], AtomNo[walker->type->Z], out); // removed due to trajectories
    750     }
     728    ActOnAllAtoms( &atom::Output, ElementNo, AtomNo, out, (const char *) NULL ); // (bool (atom::*)(int *, int *, ofstream *, const char *))
    751729    return true;
    752730  }
     
    775753        ElementNo[i] = 0;
    776754      }
    777     walker = start;
    778     while (walker->next != end) { // go through every atom of this element
    779       walker = walker->next;
    780       ElementNo[walker->type->Z] = 1;
    781     }
    782     int current=1;
    783     for (int i=0;i<MAX_ELEMENTS;++i) {
    784       if (ElementNo[i] == 1)
    785         ElementNo[i] = current++;
    786     }
    787     walker = start;
     755      SetIndexedArrayForEachAtomTo ( ElementNo, &element::Z, &AbsoluteValue, 1);
     756      int current=1;
     757      for (int i=0;i<MAX_ELEMENTS;++i) {
     758        if (ElementNo[i] == 1)
     759          ElementNo[i] = current++;
     760      }
     761      walker = start;
    788762      while (walker->next != end) { // go through every atom of this element
    789763        walker = walker->next;
     
    880854  if (out != NULL) {
    881855    *out << AtomNo << "\n\tCreated by molecuilder on " << ctime(&now);
    882     walker = start;
    883     while (walker->next != end) { // go through every atom of this element
    884       walker = walker->next;
    885       walker->OutputXYZLine(out);
    886     }
     856    ActOnAllAtoms( &atom::OutputXYZLine, out );
    887857    return true;
    888858  } else
  • src/molecule.hpp

    rebcade re9f8f9  
    134134  // templates for allowing global manipulation of all vectors
    135135  template <typename res> void ActOnAllVectors( res (Vector::*f)() );
     136  template <typename res> void ActOnAllVectors( res (Vector::*f)() const);
     137  template <typename res> void ActOnAllVectors( res (Vector::*f)() ) const;
    136138  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t );
     139  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t );
     140  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t ) const;
    137141  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u );
     142  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u );
     143  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const;
    138144  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v);
     145  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v);
     146  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const;
     147
     148  // templates for allowing global manipulation of molecule with each atom as single argument
     149  template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) );
     150  template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) const);
     151  template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) ) const;
     152
     153  // templates for allowing global copying of molecule with each atom as single argument
     154  template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy);
     155  template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const , molecule *copy);
     156  template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const;
    139157
    140158  // templates for allowing global manipulation of all atoms
    141   template <typename res> void ActOnAllAtoms( res (molecule::*f)(atom *) );
    142159  template <typename res> void ActOnAllAtoms( res (atom::*f)() );
     160  template <typename res> void ActOnAllAtoms( res (atom::*f)() const );
     161  template <typename res> void ActOnAllAtoms( res (atom::*f)() ) const;
    143162  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T), T t );
     163  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T) const, T t );
     164  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T) const, T t ) const;
    144165  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U), T t, U u );
     166  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U) const, T t, U u );
     167  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U), T t, U u ) const;
    145168  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v);
     169  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V) const, T t, U u, V v);
     170  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v) const;
     171  template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W), T t, U u, V v, W w);
     172  template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W) const, T t, U u, V v, W w);
     173  template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W), T t, U u, V v, W w) const;
     174
     175  // templates for allowing conditional global copying of molecule with each atom as single argument
     176  template <typename res> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () );
     177  template <typename res, typename T> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t );
     178  template <typename res, typename T, typename U> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u );
     179  template <typename res, typename T, typename U, typename V> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v );
     180
     181  // templates for allowing global manipulation of an array with one entry per atom
     182  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int atom::* index, void (*Setor)(T *, T));
     183  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int atom::* index, void (*Setor)(T *, T), T);
     184  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T));
     185  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T), T);
    146186
    147187  /// remove atoms from molecule.
     
    262302};
    263303
    264 
    265 template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() ) {
    266   atom *Walker = start;
    267   while (Walker->next != end) {
    268     Walker = Walker->next;
    269     ((Walker->node)->*f)();
    270   }
    271 };
    272 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t )
    273 {
    274   atom *Walker = start;
    275   while (Walker->next != end) {
    276     Walker = Walker->next;
    277     ((Walker->node)->*f)(t);
    278   }
    279 };
    280 template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u )
    281 {
    282   atom *Walker = start;
    283   while (Walker->next != end) {
    284     Walker = Walker->next;
    285     ((Walker->node)->*f)(t, u);
    286   }
    287 };
    288 template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v)
    289 {
    290   atom *Walker = start;
    291   while (Walker->next != end) {
    292     Walker = Walker->next;
    293     ((Walker->node)->*f)(t, u, v);
    294   }
    295 };
    296 
    297 template <typename res> void molecule::ActOnAllAtoms( res (molecule::*f)(atom *)) {
    298   atom *Walker = start;
    299   while (Walker->next != end) {
    300     Walker = Walker->next;
    301     (*f)(Walker);
    302   }
    303 };
    304 
    305 template <typename res> void molecule::ActOnAllAtoms( res (atom::*f)()) {
    306   atom *Walker = start;
    307   while (Walker->next != end) {
    308     Walker = Walker->next;
    309     (Walker->*f)();
    310   }
    311 };
    312 template <typename res, typename T> void molecule::ActOnAllAtoms( res (atom::*f)(T), T t )
    313 {
    314   atom *Walker = start;
    315   while (Walker->next != end) {
    316     Walker = Walker->next;
    317     (Walker->*f)(t);
    318   }
    319 };
    320 template <typename res, typename T, typename U> void molecule::ActOnAllAtoms( res (atom::*f)(T, U), T t, U u )
    321 {
    322   atom *Walker = start;
    323   while (Walker->next != end) {
    324     Walker = Walker->next;
    325     (Walker->*f)(t, u);
    326   }
    327 };
    328 template <typename res, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v)
    329 {
    330   atom *Walker = start;
    331   while (Walker->next != end) {
    332     Walker = Walker->next;
    333     (Walker->*f)(t, u, v);
    334   }
    335 };
     304#include "molecule_template.hpp"
    336305
    337306/** A list of \a molecule classes.
Note: See TracChangeset for help on using the changeset viewer.