cutoff.hpp 2.63 KB
Newer Older
Carl Poelking's avatar
Carl Poelking committed
1
2
3
4
5
6
#ifndef _SOAP_CUTOFF_HPP
#define _SOAP_CUTOFF_HPP

#include <string>
#include <math.h>
#include <vector>
Carl Poelking's avatar
Carl Poelking committed
7
8
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
Carl Poelking's avatar
Carl Poelking committed
9

10
11
12
13
#include "soap/base/exceptions.hpp"
#include "soap/base/objectfactory.hpp"
#include "soap/globals.hpp"
#include "soap/options.hpp"
Carl Poelking's avatar
Carl Poelking committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

namespace soap {

namespace ub = boost::numeric::ublas;

class CutoffFunction
{
public:
	std::string &identify() { return _type; }
	const double &getCutoff() { return _Rc; }
    const double &getCutoffWidth() { return _Rc_width; }
    const double &getCenterWeight() { return _center_weight; }
    CutoffFunction() : 
        _type("shifted-cosine"), 
        _Rc(-1), 
        _Rc_width(-1.),
        _center_weight(-1.) {;}
    virtual ~CutoffFunction() {;}
    virtual void configure(Options &options);
Carl Poelking's avatar
Carl Poelking committed
33
34
35
    virtual bool isWithinCutoff(double r);
    virtual double calculateWeight(double r);
    virtual vec calculateGradientWeight(double r, vec d);
Carl Poelking's avatar
Carl Poelking committed
36

Carl Poelking's avatar
Carl Poelking committed
37
38
39
40
41
42
43
44
    template<class Archive>
    void serialize(Archive &arch, const unsigned int version) {
    	arch & _type;
    	arch & _Rc;
    	arch & _Rc_width;
    	arch & _center_weight;
    }

Carl Poelking's avatar
Carl Poelking committed
45
46
47
48
49
protected:
    std::string _type;
    double _Rc;
    double _Rc_width;
    double _center_weight;
Carl Poelking's avatar
Carl Poelking committed
50
51
52

public:
    static constexpr double WEIGHT_ZERO = 1e-10;
Carl Poelking's avatar
Carl Poelking committed
53
54
};

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class CutoffFunctionHeaviside : public CutoffFunction
{
public:
    CutoffFunctionHeaviside() { _type = "heaviside"; _Rc = -1; }
    void configure(Options &options);
    bool isWithinCutoff(double r);
    double calculateWeight(double r);
    virtual vec calculateGradientWeight(double r, vec d);

    template<class Archive>
    void serialize(Archive &arch, const unsigned int version) {
        arch & boost::serialization::base_object<CutoffFunction>(*this);
    }
};

Carl Poelking's avatar
Carl Poelking committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

class CutoffFunctionFactory
    : public soap::base::ObjectFactory<std::string, CutoffFunction>
{
private:
    CutoffFunctionFactory() {}
public:
    static void registerAll(void);
    CutoffFunction *create(const std::string &key);
    friend CutoffFunctionFactory &CutoffFunctionOutlet();
};

inline CutoffFunctionFactory &CutoffFunctionOutlet() {
    static CutoffFunctionFactory _instance;
    return _instance;
}

inline CutoffFunction *CutoffFunctionFactory::create(const std::string &key) {
    assoc_map::const_iterator it(getObjects().find(key));
    if (it != getObjects().end()) {
        CutoffFunction *basis = (it->second)();
        return basis;
    }
    else {
        throw std::runtime_error("Factory key " + key + " not found.");
    }
}

Carl Poelking's avatar
Carl Poelking committed
98
99
100
101
} /* CLOSE NAMESPACE */

BOOST_CLASS_EXPORT_KEY(soap::CutoffFunction);
BOOST_CLASS_EXPORT_KEY(soap::CutoffFunctionHeaviside);
Carl Poelking's avatar
Carl Poelking committed
102
103

#endif