MSpin-JCoupling  2.1
couplingconstant.h
1 /***************************************************************************
2  couplingconstant.h - description
3  -------------------
4  author : Armando Navarro-Vazquez
5  email : armando.deus@gmail.com
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef MAGNES_COUPLINGCONSTANT_H
18 #define MAGNES_COUPLINGCONSTANT_H
19 
20 #include "coreexport.h"
21 #include "mathtools.h"
22 #include <vector>
24 namespace magnes
25 {
26 
31  class MAGNES_CORE_API Error
32  {
33  public:
35  Error() : m_value(0) {};
37  ~Error() { delete m_value; }
38  double Value() const { return *m_value; }
39 
41  explicit Error(double v)
42  {
43  m_value =new double(v);
44  }
46  Error(const Error& e)
47  {
48 
49  if ( e )
50  {
51  m_value = new double(e.Value());
52 
53  }
54  else m_value=0;
55  // if (!m_value && !e) //Do nothing
56 
57 
58  }
60  Error& operator = (const Error& e)
61  {
62  if ( &e != this)
63  {
64  if ( m_value && e )
65  {
66  *m_value=e.Value();
67 
68  }
69  if ( m_value && !e)
70  {
71  delete m_value;
72  m_value=0;
73  }
74  if ( !m_value && e)
75  {
76  m_value = new double(e.Value());
77 
78  }
79  // if (!m_value && !e) //Do nothing
80 
81  }
82  return *this;
83  }
84 
85 
87  Error& operator = (double v)
88  {
89  {
90  if ( m_value ) *m_value=v;
91  else
92  m_value = new double(v);
93  }
94  return *this;
95  }
96  private:
97  typedef void (Error::*bool_type) () const;
98  void helperfunction() const {};
99  private:
100  //static unity m_unity;
101  double* m_value;
102 public:
104  operator bool_type () const
105  {
106  if ( m_value != 0 ) return &Error::helperfunction;
107  else return 0;
108  }
109 
110  };
111 
112 
113 
114 
115 
119 class MAGNES_CORE_API CouplingConstant
120  {
121  public:
123  CouplingConstant(size_t i, size_t j);
125  CouplingConstant(size_t i, size_t j, double ev);
127  CouplingConstant(size_t i, size_t j, double ev,double err);
129  double AverageValue() const { return _averagevalue; }
131  double ExperimentalValue() const { return _experimentalvalue; }
133  void SetExperimentalValue(double ev);
135  bool HasExperimentalValue() const { return _hasexperimentalvalue; }
137  void SetAverageValue(double v) { _averagevalue=v; }
139  const std::vector<double>& ComputedValues() const { return _computedvalues; }
141  std::vector<double>& ComputedValues() { return _computedvalues; }
143  const size_t& I() const { return _first; }
145  const size_t& J() const { return _second; }
147  size_t& I() { return _first; }
149  size_t& J() { return _second; }
151  const magnes::Error& StandardDeviation() const { return _standarddeviation; }
153  void SetStandardDeviation(double err) { _standarddeviation=err; }
154  const std::vector<magnes::Error>& ComputedStandardDeviations() const { return _computederrors; }
155  std::vector<magnes::Error>& ComputedStandardDeviations() { return _computederrors; }
157  const magnes::Error& AveragedStandardDeviation() const { return _averagedstandarddeviation; }
159  void SetAveragedStandardDeviation(double err) { _averagedstandarddeviation=err; }
161  const std::vector< magnes::D1Array<double> >& Distribution() const { return _distribution; }
163  std::vector< magnes::D1Array<double> >& Distribution() { return _distribution; }
165  const magnes::D1Array<double>& AveragedDistribution() const { return _averageddistribution; }
167  magnes::D1Array<double>& AveragedDistribution() { return _averageddistribution; }
169  void ComputeStatistics();
170 
171 
172 private:
173  size_t _first;
174  size_t _second;
175  std::vector<double> _computedvalues;
176  double _averagevalue;
177  double _experimentalvalue;
178  bool _hasexperimentalvalue;
179  magnes::Error _standarddeviation;
180  magnes::Error _averagedstandarddeviation;
181  std::vector<magnes::Error> _computederrors;
182  std::vector< D1Array<double> > _distribution;
183  D1Array<double> _averageddistribution;
184  };
186  MAGNES_CORE_API bool operator==(const CouplingConstant &, const CouplingConstant &);
188  MAGNES_CORE_API std::ostream& operator << ( std::ostream& s,const CouplingConstant& c );
189 }
190 
191 #endif
size_t & J()
Definition: couplingconstant.h:149
Error()
Definition: couplingconstant.h:35
double AverageValue() const
Definition: couplingconstant.h:129
size_t & I()
Definition: couplingconstant.h:147
const size_t & I() const
Definition: couplingconstant.h:143
void SetAverageValue(double v)
Definition: couplingconstant.h:137
MAGNES_CORE_API std::ostream & operator<<(std::ostream &s, const Coordinate &c)
Definition: coordinate.h:269
Error(double v)
Definition: couplingconstant.h:41
the global magnes namespace
Definition: ccchequation.h:38
std::vector< magnes::D1Array< double > > & Distribution()
Definition: couplingconstant.h:163
const magnes::Error & AveragedStandardDeviation() const
Definition: couplingconstant.h:157
void SetAveragedStandardDeviation(double err)
Definition: couplingconstant.h:159
const magnes::Error & StandardDeviation() const
Definition: couplingconstant.h:151
MAGNES_CORE_API bool operator==(const ChemicalShift &, const ChemicalShift &)
representation of a coupling constant between nuclei
Definition: couplingconstant.h:119
void SetStandardDeviation(double err)
Definition: couplingconstant.h:153
A general class for storing experimental errors.
Definition: couplingconstant.h:31
const magnes::D1Array< double > & AveragedDistribution() const
Definition: couplingconstant.h:165
magnes::D1Array< double > & AveragedDistribution()
Definition: couplingconstant.h:167
const std::vector< double > & ComputedValues() const
Definition: couplingconstant.h:139
double ExperimentalValue() const
Definition: couplingconstant.h:131
std::vector< double > & ComputedValues()
Definition: couplingconstant.h:141
bool HasExperimentalValue() const
Definition: couplingconstant.h:135
const size_t & J() const
Definition: couplingconstant.h:145
const std::vector< magnes::D1Array< double > > & Distribution() const
Definition: couplingconstant.h:161
Error(const Error &e)
Definition: couplingconstant.h:46