Changeset a0064e for src/Helpers
- Timestamp:
- Dec 23, 2010, 5:40:04 PM (14 years ago)
- 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:
- ad011c
- Parents:
- f28a26
- git-author:
- Frederik Heber <heber@…> (12/22/10 09:18:48)
- git-committer:
- Frederik Heber <heber@…> (12/23/10 17:40:04)
- Location:
- src/Helpers
- Files:
-
- 22 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Helpers/fast_functions.hpp
rf28a26 ra0064e 51 51 }; 52 52 53 /** Returns the power of \a n with respect to \a base.54 * \param base basis55 * \param n power56 * \return \f$base^n\f$57 */58 inline int pot(int base, int n)59 {60 int res = 1;61 int j;62 for (j=n;j--;)63 res *= base;64 return res;65 };66 67 /*************************** Templatized functions ************************************/68 69 /** Flips two values.70 * \param x first value71 * \param y second value72 */73 template <typename T>74 inline void flip(T &x, T &y)75 {76 T tmp;77 tmp = x;78 x = y;79 y = tmp;80 };81 53 82 54 #endif /* FAST_FUNCTIONS_HPP_ */ -
src/Helpers/helpers.cpp
-
Property mode
changed from
100755
to100644
rf28a26 ra0064e 28 28 29 29 30 /** Asks for a double value and checks input31 * \param *text question32 */33 double ask_value(const char *text)34 {35 double test = 0.1439851348959832147598734598273456723948652983045928346598365;36 do {37 DoLog(0) && (Log() << Verbose(0) << text);38 cin >> test;39 } while (test == 0.1439851348959832147598734598273456723948652983045928346598365);40 return test;41 };42 43 30 /** Output of a debug message to stderr. 44 31 * \param *P Problem at hand, points to ParallelSimulationData#me … … 53 40 #endif 54 41 55 /** modulo operator for doubles.56 * \param *b pointer to double57 * \param lower_bound lower bound58 * \param upper_bound upper bound59 */60 void bound(double *b, double lower_bound, double upper_bound)61 {62 double step = (upper_bound - lower_bound);63 while (*b >= upper_bound)64 *b -= step;65 while (*b < lower_bound)66 *b += step;67 };68 69 /** Counts lines in file.70 * Note we are scanning lines from current position, not from beginning.71 * \param InputFile file to be scanned.72 */73 int CountLinesinFile(ifstream &InputFile)74 {75 char *buffer = new char[MAXSTRINGSIZE];76 int lines=0;77 78 int PositionMarker = InputFile.tellg(); // not needed as Inputfile is copied, given by value, not by ref79 // count the number of lines, i.e. the number of fragments80 InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines81 InputFile.getline(buffer, MAXSTRINGSIZE);82 while(!InputFile.eof()) {83 InputFile.getline(buffer, MAXSTRINGSIZE);84 lines++;85 }86 InputFile.seekg(PositionMarker, ios::beg);87 delete[](buffer);88 return lines;89 };90 42 91 43 /** Returns a string with \a i prefixed with 0s to match order of total number of molecules in digits. … … 117 69 }; 118 70 119 /** Tests whether a given string contains a valid number or not.120 * \param *string121 * \return true - is a number, false - is not a valid number122 */123 bool IsValidNumber( const char *string)124 {125 int ptr = 0;126 if ((string[ptr] == '.') || (string[ptr] == '-')) // number may be negative or start with dot127 ptr++;128 if ((string[ptr] >= '0') && (string[ptr] <= '9'))129 return true;130 return false;131 };132 133 /** Comparison function for GSL heapsort on distances in two molecules.134 * \param *a135 * \param *b136 * \return <0, \a *a less than \a *b, ==0 if equal, >0 \a *a greater than \a *b137 */138 int CompareDoubles (const void * a, const void * b)139 {140 if (*(double *)a > *(double *)b)141 return -1;142 else if (*(double *)a < *(double *)b)143 return 1;144 else145 return 0;146 };147 148 149 71 /** 150 72 * Calls exit(255). -
Property mode
changed from
-
src/Helpers/helpers.hpp
rf28a26 ra0064e 50 50 } sign_t; 51 51 52 double ask_value(const char *text);53 bool check_bounds(double *x, double *cell_size);54 void bound(double *b, double lower_bound, double upper_bound);55 int CountLinesinFile(ifstream &InputFile);56 52 char *FixedDigitNumber(const int FragmentNumber, const int digits); 57 bool IsValidNumber( const char *string);58 int CompareDoubles (const void * a, const void * b);59 53 void performCriticalExit(); 60 54 sign_t sign(double value); … … 62 56 /********************************************** helpful template functions *********************************/ 63 57 64 65 /** returns greater of the two values.66 * \param x first value67 * \param y second value68 * \return greater of the two (by operator>())69 */70 template <typename T> T Max(T x, T y)71 {72 if (x > y)73 return x;74 else return y;75 };76 77 /** returns smaller of the two values.78 * \param x first value79 * \param y second value80 * \return smaller of the two (by operator<())81 */82 template <typename T> T Min(T x, T y)83 {84 if (x < y)85 return x;86 else return y;87 };88 58 89 59 /** Creates a lookup table for true father's Atom::Nr -> atom ptr. … … 144 114 145 115 146 /** Frees a two-dimensional array.147 * \param *ptr pointer to array148 * \param dim first dim of array149 */150 template <typename X> void Free2DArray(X **ptr, int dim)151 {152 int i;153 if (ptr != NULL) {154 for(i=dim;i--;)155 if (ptr[i] != NULL)156 free(ptr[i]);157 free(ptr);158 }159 };160 161 template <typename T> void Increment(T *value, T *inc)162 {163 *value += *inc;164 };165 166 template <typename T> void AbsoluteValue(T *value, T *abs)167 {168 *value = *abs;169 };170 171 template <typename T> void IncrementalAbsoluteValue(T *value, T *abs)172 {173 *value = *abs;174 (*abs) += 1;175 };176 177 116 #define PLURAL_S(v) (((v)==1)?"":"s") 178 117 … … 201 140 }; 202 141 203 /************ struct to contain simple enumerations ***************/204 template <class C>205 struct enumeration{206 enumeration() : max(0) {}207 enumeration(unsigned int i) : max(i) {}208 enumeration(const enumeration &src) :209 there(src.there),210 back(src.back),211 max(src.max)212 {}213 enumeration &operator=(const enumeration &src){214 /* no self-assignment check needed */215 there = src.there;216 back = src.back;217 max = src.max;218 return *this;219 }220 void add(const C &value){221 if(!there.count(value)){222 there[value]=max;223 back[max++]=value;224 }225 }226 unsigned int getMax() const{227 return max;228 }229 230 map<C,unsigned int> there;231 map<unsigned int,C> back;232 private:233 unsigned int max;234 };235 236 /***** A counter to generate sequential numbers *******************/237 struct counter{238 inline counter() : count(0){};239 inline counter(int i) : count(i){};240 inline unsigned int operator()(){241 return count++;242 }243 private:244 unsigned int count;245 };246 247 template <class C,class ForwardIterator>248 enumeration<C> enumerate(ForwardIterator first,ForwardIterator last){249 enumeration<C> res;250 for_each(first,last,bind1st(mem_fun(&enumeration<C>::add),&res));251 return res;252 }253 254 142 #endif /*HELPERS_HPP_*/
Note:
See TracChangeset
for help on using the changeset viewer.