~ubuntu-branches/ubuntu/oneiric/mpqc/oneiric

« back to all changes in this revision

Viewing changes to src/lib/chemistry/qc/wfn/density.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2005-11-27 11:41:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127114149-zgz9r3gk50w8ww2q
Tags: 2.3.0-1
* New upstream release.
* debian/rules (SONAME): Activate awk snippet for automatic so-name
  detection again, resulting in a bump to `7' and making a `c2a' for
  the C++ allocator change unnecessary; closes: #339232.
* debian/patches/00list (08_gcc-4.0_fixes): Removed, no longer needed.
* debian/rules (test): Remove workarounds, do not abort build if tests
  fail.
* debian/ref: Removed.
* debian/control.in (libsc): Added Conflict against libsc6c2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include <math/isosurf/volume.h>
36
36
#include <chemistry/qc/wfn/wfn.h>
 
37
#include <chemistry/qc/basis/extent.h>
37
38
#include <chemistry/molecule/molrender.h>
38
39
 
39
40
namespace sc {
40
41
 
 
42
/** This is a Volume that computer the electron density.  It
 
43
    can be used to generate isodensity surfaces. */
41
44
class ElectronDensity: public Volume {
42
45
  protected:
43
46
    Ref<Wavefunction> wfn_;
51
54
                             SCVector3& p1, SCVector3& p2);
52
55
};
53
56
 
 
57
/** This a more highly optimized than ElectronDensity since
 
58
    everything is precomputed.  However, it cannot be used
 
59
    if the density and/or geometry might change between
 
60
    computations of the density or bounding box, unless the
 
61
    obsolete member is called. */
 
62
class BatchElectronDensity: public Volume {
 
63
    void zero_pointers();
 
64
  protected:
 
65
    Ref<Wavefunction> wfn_;
 
66
 
 
67
    Ref<GaussianBasisSet> basis_;
 
68
 
 
69
    // shared between threads
 
70
    double *alpha_dmat_;
 
71
    double *beta_dmat_;
 
72
    double *dmat_bound_;
 
73
    ShellExtent *extent_;
 
74
 
 
75
    // private data
 
76
    GaussianBasisSet::ValueData *valdat_;
 
77
    int ncontrib_;
 
78
    int *contrib_;
 
79
    int ncontrib_bf_;
 
80
    int *contrib_bf_;
 
81
    double *bs_values_;
 
82
    double *bsg_values_;
 
83
    double *bsh_values_;
 
84
 
 
85
    int nshell_;
 
86
    int nbasis_;
 
87
    int spin_polarized_;
 
88
    int linear_scaling_;
 
89
    int use_dmat_bound_;
 
90
 
 
91
    bool need_hessian_, need_gradient_;
 
92
    bool need_basis_hessian_, need_basis_gradient_;
 
93
 
 
94
    bool using_shared_data_;
 
95
 
 
96
    double accuracy_;
 
97
    virtual void init_common_data(bool initialize_density_matrices);
 
98
    // this must be called after common data is initialized,
 
99
    // either with init_common_data or by copying
 
100
    virtual void init_scratch_data();
 
101
    void compute_basis_values(const SCVector3&r);
 
102
    void compute_spin_density(const double *dmat,
 
103
                              double *rho, double *grad, double *hess);
 
104
 
 
105
    virtual void compute();
 
106
  public:
 
107
 
 
108
    /** This gives the elements of gradient arrays. */
 
109
    enum {X=0, Y=1, Z=2};
 
110
    /** This gives the elements of hessian arrays. */
 
111
    enum {XX=0, YX=1, YY=2, ZX=3, ZY=4, ZZ=5};
 
112
 
 
113
    BatchElectronDensity(const Ref<KeyVal>&);
 
114
    BatchElectronDensity(const Ref<Wavefunction>&, double accuracy=DBL_EPSILON);
 
115
    /** This will construct copies of this.  If reference_parent_data is
 
116
        true, then data that do not change, such as the density matrices
 
117
        and shell extent, are referenced rather than copied.  In this case,
 
118
        the original object that allocated this items must be valid while
 
119
        copied objects are used to compute densities.  Also d must have
 
120
        already been intialized and the resulting copy is already initialized
 
121
        (and cannot be reinitialized).
 
122
 
 
123
        If reference_parent_data is false, then init must be called on this
 
124
        object before it is used.  */
 
125
    BatchElectronDensity(const Ref<BatchElectronDensity>& d,
 
126
                         bool reference_parent_data=false);
 
127
    ~BatchElectronDensity();
 
128
    /** Returns the bounding box. */
 
129
    virtual void boundingbox(double valuemin,
 
130
                             double valuemax,
 
131
                             SCVector3& p1, SCVector3& p2);
 
132
 
 
133
    /** This will cause all stratch storage to be released. */
 
134
    void clear();
 
135
 
 
136
    /** This is a alternate to the Volume interface that avoids some of the
 
137
        overhead of that interface. */
 
138
    void compute_density(const SCVector3 &r,
 
139
                         double *alpha_density,
 
140
                         double *alpha_density_grad,
 
141
                         double *alpha_density_hessian,
 
142
                         double *beta_density,
 
143
                         double *beta_density_grad,
 
144
                         double *beta_density_hessian);
 
145
 
 
146
    /** This is called to finish initialization of the object.  It must not
 
147
        be called with objects that created in a way that they share parent
 
148
        data, those objects are initialized when they are constructed. This
 
149
        member is usually called automatically, however, if it will be used
 
150
        to initial other objects that share parent data, then it must be
 
151
        initialized first and this return is the way to do that.  If
 
152
        initialize_density_matrices is false, then the density matrices
 
153
        will be allocated, but not filled in.  They must be later filled in
 
154
        with set_densities. */
 
155
    virtual void init(bool initialize_density_matrices = true);
 
156
 
 
157
    /** This will fill in the internel copies of the density matrices with
 
158
        new values.  aden is the alpha density matrix and bden is the beta
 
159
        density matrix.  bden is ignored if the wavefunction is not spin
 
160
        polarized. */
 
161
    virtual void set_densities(const RefSymmSCMatrix &aden,
 
162
                               const RefSymmSCMatrix &bden);
 
163
 
 
164
    /** Turn linear scaling algorithm on/off. The effect of this will be
 
165
        delayed until the next time init() is called. */
 
166
    void set_linear_scaling(bool b) { linear_scaling_ = b; }
 
167
 
 
168
    /** Sets the accuracy.  */
 
169
    void set_accuracy(double a) { accuracy_ = a; }
 
170
 
 
171
    /** Turn use of density matrix bounds on/off. */
 
172
    void set_use_dmat_bound(bool b) { use_dmat_bound_ = b; }
 
173
 
 
174
    /** @name DFT Support Members.
 
175
        These return some of the internal data, some of which is
 
176
        only value after a density has been computed.  This data
 
177
        is needed by the density functional theory code. */
 
178
    //@{
 
179
    /** Return the alpha density matrix. */
 
180
    double *alpha_density_matrix() { return alpha_dmat_; }
 
181
    /** Return the beta density matrix. */
 
182
    double *beta_density_matrix()
 
183
        { return (spin_polarized_?beta_dmat_:alpha_dmat_); }
 
184
    int ncontrib() { return ncontrib_; }
 
185
    int *contrib() { return contrib_; }
 
186
    int ncontrib_bf() { return ncontrib_bf_; }
 
187
    int *contrib_bf() { return contrib_bf_; }
 
188
    double *bs_values() { return bs_values_; }
 
189
    double *bsg_values() { return bsg_values_; }
 
190
    double *bsh_values() { return bsh_values_; }
 
191
    /** To ensure that that the basis functions gradients are computed,
 
192
        use this. */
 
193
    void set_need_basis_gradient(bool b) { need_basis_gradient_ = b; }
 
194
    void set_need_basis_hessian(bool b) { need_basis_hessian_ = b; }
 
195
    //@}
 
196
};
 
197
 
54
198
class DensityColorizer: public MoleculeColorizer {
55
199
  protected:
56
200
    Ref<Wavefunction> wfn_;