| 1 | /* | 
|---|
| 2 | * IndexedPartialCharges.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Jun 12, 2016 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef INDEXEDPARTIALCHARGES_HPP_ | 
|---|
| 10 | #define INDEXEDPARTIALCHARGES_HPP_ | 
|---|
| 11 |  | 
|---|
| 12 | // include config.h | 
|---|
| 13 | #ifdef HAVE_CONFIG_H | 
|---|
| 14 | #include <config.h> | 
|---|
| 15 | #endif | 
|---|
| 16 |  | 
|---|
| 17 | #include <iosfwd> | 
|---|
| 18 |  | 
|---|
| 19 | #include "Fragmentation/Summation/SetValues/IndexedValue.hpp" | 
|---|
| 20 | #include "Fragmentation/Summation/ZeroInstance.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | struct partial_charge_t | 
|---|
| 23 | { | 
|---|
| 24 | //!> typedef for a single charge | 
|---|
| 25 | typedef double charge_t; | 
|---|
| 26 | charge_t charge; | 
|---|
| 27 |  | 
|---|
| 28 | /** Default constructor for a partial charge. | 
|---|
| 29 | */ | 
|---|
| 30 | partial_charge_t() : | 
|---|
| 31 | charge(0.) | 
|---|
| 32 | {} | 
|---|
| 33 |  | 
|---|
| 34 | /** Constructor for a partial charge. | 
|---|
| 35 | * | 
|---|
| 36 | * \param _charge new partial charge | 
|---|
| 37 | */ | 
|---|
| 38 | partial_charge_t(const double &_charge) : | 
|---|
| 39 | charge(_charge) | 
|---|
| 40 | {} | 
|---|
| 41 |  | 
|---|
| 42 | /** Assignment operator for the charge. | 
|---|
| 43 | * | 
|---|
| 44 | * \param _charge new partial charge | 
|---|
| 45 | */ | 
|---|
| 46 | partial_charge_t& operator()(const double &_charge) | 
|---|
| 47 | { | 
|---|
| 48 | charge = _charge; | 
|---|
| 49 | return *this; | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | /** Sum operator. | 
|---|
| 53 | * | 
|---|
| 54 | * \param _charge new partial charge | 
|---|
| 55 | */ | 
|---|
| 56 | partial_charge_t& operator+=(const double &_charge) | 
|---|
| 57 | { charge += _charge; return *this; } | 
|---|
| 58 |  | 
|---|
| 59 | /** Subtraction operator. | 
|---|
| 60 | * | 
|---|
| 61 | * \param _charge new partial charge | 
|---|
| 62 | */ | 
|---|
| 63 | partial_charge_t& operator-=(const double &_charge) | 
|---|
| 64 | { charge -= _charge; return *this; } | 
|---|
| 65 |  | 
|---|
| 66 | /** Comparator for partial charge. | 
|---|
| 67 | * | 
|---|
| 68 | * \param other other charge instance | 
|---|
| 69 | */ | 
|---|
| 70 | bool operator==(const partial_charge_t &other) const | 
|---|
| 71 | { return charge == other.charge; } | 
|---|
| 72 |  | 
|---|
| 73 | bool operator!=(const partial_charge_t &other) const | 
|---|
| 74 | { return !operator==(other); } | 
|---|
| 75 |  | 
|---|
| 76 | bool operator<(const partial_charge_t &other) const | 
|---|
| 77 | { return charge < other.charge; } | 
|---|
| 78 |  | 
|---|
| 79 | /** Summation operator for two force vectors. | 
|---|
| 80 | * | 
|---|
| 81 | * \param other other charge | 
|---|
| 82 | * \param prefactor prefactor to use in summation (e.g. -1 gives a subtraction) | 
|---|
| 83 | */ | 
|---|
| 84 | void superposeOtherIndexedVectors(const partial_charge_t &other, const double prefactor) | 
|---|
| 85 | { charge = charge + prefactor * other.charge; } | 
|---|
| 86 |  | 
|---|
| 87 | // make output operator friend | 
|---|
| 88 | friend std::ostream & operator<<(std::ostream &ost, const partial_charge_t &other); | 
|---|
| 89 | }; | 
|---|
| 90 |  | 
|---|
| 91 | std::ostream & operator<<(std::ostream &ost, const partial_charge_t &other); | 
|---|
| 92 |  | 
|---|
| 93 | struct IndexedPartialCharges  : public IndexedValue<partial_charge_t> | 
|---|
| 94 | { | 
|---|
| 95 | public: | 
|---|
| 96 | IndexedPartialCharges( | 
|---|
| 97 | const typename IndexedValue<partial_charge_t>::indices_t &_indices, | 
|---|
| 98 | const typename IndexedValue<partial_charge_t>::values_t &_charges) : | 
|---|
| 99 | IndexedValue<partial_charge_t>(_indices, _charges) | 
|---|
| 100 | {} | 
|---|
| 101 |  | 
|---|
| 102 | IndexedPartialCharges() | 
|---|
| 103 | {} | 
|---|
| 104 | }; | 
|---|
| 105 |  | 
|---|
| 106 | template<typename T> T ZeroInstance(); | 
|---|
| 107 | template<> IndexedPartialCharges ZeroInstance< IndexedPartialCharges >(); | 
|---|
| 108 | template<> partial_charge_t ZeroInstance< partial_charge_t >(); | 
|---|
| 109 |  | 
|---|
| 110 | #endif /* INDEXEDPARTIALCHARGES_HPP_ */ | 
|---|