Changeset 49f802c


Ignore:
Timestamp:
Oct 9, 2009, 11:57:41 AM (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:
c111db
Parents:
f66195
Message:

Implementing templated iterators done for molecule.cpp

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/atom.cpp

    rf66195 r49f802c  
    222222{
    223223  if (out != NULL) {
    224     *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << NumberOfBondsPerAtom[nr] << " bonds: ";
    225     int TotalDegree = 0;
    226     for (int j=0;j<NumberOfBondsPerAtom[nr];j++) {
    227       *out << *ListOfBondsPerAtom[nr][j] << "\t";
    228       TotalDegree += ListOfBondsPerAtom[nr][j]->BondDegree;
     224#ifdef ADDHYDROGEN
     225    if (type->Z != 1) {   // regard only non-hydrogen
     226#endif
     227      *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << NumberOfBondsPerAtom[nr] << " bonds: ";
     228      int TotalDegree = 0;
     229      for (int j=0;j<NumberOfBondsPerAtom[nr];j++) {
     230        *out << *ListOfBondsPerAtom[nr][j] << "\t";
     231        TotalDegree += ListOfBondsPerAtom[nr][j]->BondDegree;
     232      }
     233      *out << " -- TotalDegree: " << TotalDegree << endl;
     234#ifdef ADDHYDROGEN
    229235    }
    230     *out << " -- TotalDegree: " << TotalDegree << endl;
     236#endif
    231237    return true;
    232238  } else
     
    258264};
    259265
     266/** Returns squared distance to a given vector.
     267 * \param origin vector to calculate distance to
     268 * \return distance squared
     269 */
     270double atom::DistanceSquaredToVector(Vector &origin)
     271{
     272  return origin.DistanceSquared(&x);
     273};
     274
     275/** Adds kinetic energy of this atom to given temperature value.
     276 * \param *temperature add on this value
     277 * \param step given step of trajectory to add
     278 */
     279void atom::AddKineticToTemperature(double *temperature, int step) const
     280{
     281  for (int i=NDIM;i--;)
     282    *temperature += type->mass * Trajectory.U.at(step).x[i]* Trajectory.U.at(step).x[i];
     283};
     284
     285/** Returns distance to a given vector.
     286 * \param origin vector to calculate distance to
     287 * \return distance
     288 */
     289double atom::DistanceToVector(Vector &origin)
     290{
     291  return origin.Distance(&x);
     292};
     293
    260294bool operator < (atom &a, atom &b)
    261295{
  • src/atom.hpp

    rf66195 r49f802c  
    7979  bool Compare(const atom &ptr);
    8080
     81  double DistanceToVector(Vector &origin);
     82  double DistanceSquaredToVector(Vector &origin);
     83
     84  void AddKineticToTemperature(double *temperature, int step) const;
     85
    8186  bool IsInParallelepiped(Vector offset, double *parallelepiped);
    8287
  • src/molecule.cpp

    rf66195 r49f802c  
    779779{
    780780  *out << Verbose(2) << endl << "From Contents of ListOfBondsPerAtom, all non-hydrogen atoms:" << endl;
    781   atom *Walker = start;
    782   while (Walker->next != end) {
    783     Walker = Walker->next;
    784 #ifdef ADDHYDROGEN
    785     if (Walker->type->Z != 1) {   // regard only non-hydrogen
    786 #endif
    787       *out << Verbose(2) << "Atom " << Walker->Name << " has Bonds: "<<endl;
    788       for(int j=0;j<NumberOfBondsPerAtom[Walker->nr];j++) {
    789         *out << Verbose(3) << *(ListOfBondsPerAtom)[Walker->nr][j] << endl;
    790       }
    791 #ifdef ADDHYDROGEN
    792     }
    793 #endif
    794   }
     781  ActOnAllAtoms (&atom::OutputBondOfAtom, out, NumberOfBondsPerAtom, ListOfBondsPerAtom);
    795782  *out << endl;
    796783};
     
    983970  size_t *PermMap = NULL, *OtherPermMap = NULL;
    984971  int *PermutationMap = NULL;
    985   atom *Walker = NULL;
    986972  bool result = true; // status of comparison
    987973
     
    10421028    Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    10431029    OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
    1044     Walker = start;
    1045     while (Walker->next != end) {
    1046       Walker = Walker->next;
    1047       Distances[Walker->nr] = CenterOfGravity.DistanceSquared(&Walker->x);
    1048     }
    1049     Walker = OtherMolecule->start;
    1050     while (Walker->next != OtherMolecule->end) {
    1051       Walker = Walker->next;
    1052       OtherDistances[Walker->nr] = OtherCenterOfGravity.DistanceSquared(&Walker->x);
    1053     }
     1030    SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, CenterOfGravity);
     1031    SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, CenterOfGravity);
    10541032
    10551033    /// ... sort each list (using heapsort (o(N log N)) from GSL)
     
    11501128{
    11511129  double temperature;
    1152   atom *Walker = NULL;
    11531130  // test stream
    11541131  if (output == NULL)
     
    11581135  for (int step=startstep;step < endstep; step++) { // loop over all time steps
    11591136    temperature = 0.;
    1160     Walker = start;
    1161     while (Walker->next != end) {
    1162       Walker = Walker->next;
    1163       for (int i=NDIM;i--;)
    1164         temperature += Walker->type->mass * Walker->Trajectory.U.at(step).x[i]* Walker->Trajectory.U.at(step).x[i];
    1165     }
     1137    ActOnAllAtoms( &atom::AddKineticToTemperature, &temperature, step);
    11661138    *output << step << "\t" << temperature*AtomicEnergyToKelvin << "\t" << temperature << endl;
    11671139  }
  • src/molecule.hpp

    rf66195 r49f802c  
    108108  template <typename res> void ActOnAllVectors( res (Vector::*f)() const);
    109109  template <typename res> void ActOnAllVectors( res (Vector::*f)() ) const;
     110  template <typename res> void ActOnAllVectors( res (Vector::*f)() const) const;
    110111  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t );
    111112  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t );
    112113  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t ) const;
     114  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t ) const;
    113115  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u );
    114116  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u );
    115117  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const;
     118  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const;
    116119  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v);
    117120  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v);
    118121  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const;
     122  template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const;
    119123
    120124  // templates for allowing global manipulation of molecule with each atom as single argument
     
    122126  template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) const);
    123127  template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) ) const;
     128  template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) const) const;
    124129
    125130  // templates for allowing global copying of molecule with each atom as single argument
     
    127132  template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const , molecule *copy);
    128133  template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const;
     134  template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const;
    129135
    130136  // templates for allowing global manipulation of all atoms
     
    132138  template <typename res> void ActOnAllAtoms( res (atom::*f)() const );
    133139  template <typename res> void ActOnAllAtoms( res (atom::*f)() ) const;
     140  template <typename res> void ActOnAllAtoms( res (atom::*f)() const) const;
    134141  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T), T t );
    135142  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T) const, T t );
     143  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T), T t ) const;
    136144  template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T) const, T t ) const;
    137145  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U), T t, U u );
    138146  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U) const, T t, U u );
    139147  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U), T t, U u ) const;
     148  template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U) const, T t, U u ) const;
    140149  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v);
    141150  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V) const, T t, U u, V v);
    142151  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v) const;
     152  template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V) const, T t, U u, V v) const;
    143153  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);
    144154  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);
    145155  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;
     156  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) const;
    146157
    147158  // templates for allowing conditional global copying of molecule with each atom as single argument
     
    152163
    153164  // templates for allowing global manipulation of an array with one entry per atom
    154   template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int atom::* index, void (*Setor)(T *, T));
    155   template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int atom::* index, void (*Setor)(T *, T), T);
     165  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, void (*Setor)(T *, T));
     166  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, void (*Setor)(T *, T), T t);
    156167  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T));
    157   template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T), T);
     168  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T), T t);
     169  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, T (atom::*Setor)(Vector &), Vector atom::*value);
     170  template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::*index, T (atom::*Setor)(Vector &), Vector &vect );
    158171
    159172  /// remove atoms from molecule.
  • src/molecule_template.hpp

    rf66195 r49f802c  
    4545  }
    4646};
     47template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() const ) const
     48    {
     49  atom *Walker = start;
     50  while (Walker->next != end) {
     51    Walker = Walker->next;
     52    ((Walker->node)->*f)();
     53  }
     54};
    4755// one argument
    4856template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t )
     
    7078  }
    7179};
     80template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T) const, T t ) const
     81{
     82  atom *Walker = start;
     83  while (Walker->next != end) {
     84    Walker = Walker->next;
     85    ((Walker->node)->*f)(t);
     86  }
     87};
    7288// two arguments
    7389template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u )
     
    95111  }
    96112};
     113template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const
     114{
     115  atom *Walker = start;
     116  while (Walker->next != end) {
     117    Walker = Walker->next;
     118    ((Walker->node)->*f)(t, u);
     119  }
     120};
    97121// three arguments
    98122template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v)
     
    120144  }
    121145};
     146template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const
     147{
     148  atom *Walker = start;
     149  while (Walker->next != end) {
     150    Walker = Walker->next;
     151    ((Walker->node)->*f)(t, u, v);
     152  }
     153};
    122154
    123155// ================== Acting with each Atoms on same molecule ========================== //
     
    148180  }
    149181};
     182template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const
     183{
     184  atom *Walker = start;
     185  while (Walker->next != end) {
     186    Walker = Walker->next;
     187    (*f)(Walker);
     188  }
     189};
    150190
    151191// ================== Acting with each Atoms on copy molecule ========================== //
     
    176216  }
    177217};
     218template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const
     219{
     220  atom *Walker = start;
     221  while (Walker->next != end) {
     222    Walker = Walker->next;
     223    (copy->*f)(Walker);
     224  }
     225};
    178226
    179227// ================== Acting with each Atoms on copy molecule if true ========================== //
     
    247295  }
    248296};
     297template <typename res> void molecule::ActOnAllAtoms( res (atom::*f)() const) const
     298{
     299  atom *Walker = start;
     300  while (Walker->next != end) {
     301    Walker = Walker->next;
     302    (Walker->*f)();
     303  }
     304};
    249305// one argument
    250306template <typename res, typename T> void molecule::ActOnAllAtoms( res (atom::*f)(T), T t )
     
    264320  }
    265321};
     322template <typename res, typename T> void molecule::ActOnAllAtoms( res (atom::*f)(T), T t ) const
     323{
     324  atom *Walker = start;
     325  while (Walker->next != end) {
     326    Walker = Walker->next;
     327    (Walker->*f)(t);
     328  }
     329};
    266330template <typename res, typename T> void molecule::ActOnAllAtoms( res (atom::*f)(T) const, T t ) const
    267331{
     
    297361  }
    298362};
     363template <typename res, typename T, typename U> void molecule::ActOnAllAtoms( res (atom::*f)(T, U) const, T t, U u ) const
     364{
     365  atom *Walker = start;
     366  while (Walker->next != end) {
     367    Walker = Walker->next;
     368    (Walker->*f)(t, u);
     369  }
     370};
    299371// three argument
    300372template <typename res, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v)
     
    322394  }
    323395};
     396template <typename res, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (atom::*f)(T, U, V) const, T t, U u, V v) const
     397{
     398  atom *Walker = start;
     399  while (Walker->next != end) {
     400    Walker = Walker->next;
     401    (Walker->*f)(t, u, v);
     402  }
     403};
    324404// four arguments
    325405template <typename res, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (atom::*f)(T, U, V, W), T t, U u, V v, W w)
     
    347427  }
    348428};
     429template <typename res, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (atom::*f)(T, U, V, W) const, T t, U u, V v, W w) const
     430{
     431  atom *Walker = start;
     432  while (Walker->next != end) {
     433    Walker = Walker->next;
     434    (Walker->*f)(t, u, v, w);
     435  }
     436};
    349437
    350438// ===================== Accesssing arrays indexed by some integer for each atom ======================
    351439
    352440// for atom ints
    353 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int atom::*index, void (*Setor)(T *, T) )
     441template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::*index, void (*Setor)(T *, T) )
    354442{
    355443  atom *Walker = start;
     
    359447  }
    360448};
    361 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int atom::*index, void (*Setor)(T *, T), T value )
     449template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::*index, void (*Setor)(T *, T), T value )
    362450{
    363451  atom *Walker = start;
     
    384472  }
    385473};
     474template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::*index, T (atom::*Setor)(Vector &), Vector atom::*value )
     475{
     476  atom *Walker = start;
     477  while (Walker->next != end) {
     478    Walker = Walker->next;
     479    array[(Walker->*index)] = (Walker->*Setor) (Walker->*value);
     480  }
     481};
     482template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::*index, T (atom::*Setor)(Vector &), Vector &vect )
     483{
     484  atom *Walker = start;
     485  while (Walker->next != end) {
     486    Walker = Walker->next;
     487    array[(Walker->*index)] = (Walker->*Setor) (vect);
     488  }
     489};
    386490
    387491#endif /* MOLECULE_TEMPLATE_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.