density.h

00001 //
00002 // density.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _chemistry_qc_wfn_density_h
00029 #define _chemistry_qc_wfn_density_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <math/isosurf/volume.h>
00036 #include <chemistry/qc/wfn/wfn.h>
00037 #include <chemistry/qc/basis/extent.h>
00038 #include <chemistry/molecule/molrender.h>
00039 #include <chemistry/molecule/molecule.h>
00040 #include <math/mmisc/grid.h>
00041 
00042 namespace sc {
00043 
00046 class ElectronDensity: public Volume {
00047   protected:
00048     Ref<Wavefunction> wfn_;
00049     virtual void compute();
00050   public:
00051     ElectronDensity(const Ref<KeyVal>&);
00052     ElectronDensity(const Ref<Wavefunction>&);
00053     ~ElectronDensity();
00054     virtual void boundingbox(double valuemin,
00055                              double valuemax,
00056                              SCVector3& p1, SCVector3& p2);
00057 };
00058 
00064 class BatchElectronDensity: public Volume {
00065     void zero_pointers();
00066   protected:
00067     Ref<Wavefunction> wfn_;
00068 
00069     Ref<GaussianBasisSet> basis_;
00070 
00071     // shared between threads
00072     double *alpha_dmat_;
00073     double *beta_dmat_;
00074     double *dmat_bound_;
00075     ShellExtent *extent_;
00076 
00077     // private data
00078     GaussianBasisSet::ValueData *valdat_;
00079     int ncontrib_;
00080     int *contrib_;
00081     int ncontrib_bf_;
00082     int *contrib_bf_;
00083     double *bs_values_;
00084     double *bsg_values_;
00085     double *bsh_values_;
00086 
00087     int nshell_;
00088     int nbasis_;
00089     int spin_polarized_;
00090     int linear_scaling_;
00091     int use_dmat_bound_;
00092 
00093     bool need_hessian_, need_gradient_;
00094     bool need_basis_hessian_, need_basis_gradient_;
00095 
00096     bool using_shared_data_;
00097 
00098     double accuracy_;
00099     virtual void init_common_data(bool initialize_density_matrices);
00100     // this must be called after common data is initialized,
00101     // either with init_common_data or by copying
00102     virtual void init_scratch_data();
00103     void compute_basis_values(const SCVector3&r);
00104     void compute_spin_density(const double *restrictxx dmat,
00105                               double *restrictxx rho,
00106                               double *restrictxx grad,
00107                               double *restrictxx hess);
00108 
00109     virtual void compute();
00110   public:
00111 
00113     enum {X=0, Y=1, Z=2};
00115     enum {XX=0, YX=1, YY=2, ZX=3, ZY=4, ZZ=5};
00116 
00117     BatchElectronDensity(const Ref<KeyVal>&);
00118     BatchElectronDensity(const Ref<Wavefunction>&, double accuracy=DBL_EPSILON);
00129     BatchElectronDensity(const Ref<BatchElectronDensity>& d,
00130                          bool reference_parent_data=false);
00131     ~BatchElectronDensity();
00133     virtual void boundingbox(double valuemin,
00134                              double valuemax,
00135                              SCVector3& p1, SCVector3& p2);
00136 
00138     void clear();
00139 
00142     void compute_density(const SCVector3 &r,
00143                          double *alpha_density,
00144                          double *alpha_density_grad,
00145                          double *alpha_density_hessian,
00146                          double *beta_density,
00147                          double *beta_density_grad,
00148                          double *beta_density_hessian);
00149 
00159     virtual void init(bool initialize_density_matrices = true);
00160 
00165     virtual void set_densities(const RefSymmSCMatrix &aden,
00166                                const RefSymmSCMatrix &bden);
00167 
00170     void set_linear_scaling(bool b) { linear_scaling_ = b; }
00171 
00173     void set_accuracy(double a) { accuracy_ = a; }
00174 
00176     void set_use_dmat_bound(bool b) { use_dmat_bound_ = b; }
00177 
00184     double *alpha_density_matrix() { return alpha_dmat_; }
00186     double *beta_density_matrix()
00187         { return (spin_polarized_?beta_dmat_:alpha_dmat_); }
00188     int ncontrib() { return ncontrib_; }
00189     int *contrib() { return contrib_; }
00190     int ncontrib_bf() { return ncontrib_bf_; }
00191     int *contrib_bf() { return contrib_bf_; }
00192     double *bs_values() { return bs_values_; }
00193     double *bsg_values() { return bsg_values_; }
00194     double *bsh_values() { return bsh_values_; }
00197     void set_need_basis_gradient(bool b) { need_basis_gradient_ = b; }
00198     void set_need_basis_hessian(bool b) { need_basis_hessian_ = b; }
00200 };
00201 
00204 class WriteElectronDensity: public WriteGrid {
00205   private:
00206     double df_alpha(double alpha, double beta);
00207     double df_beta(double alpha, double beta);
00208     double df_sum(double alpha, double beta);
00209     double df_spin(double alpha, double beta);
00210   protected:
00211     Ref<Wavefunction> wfn_;
00212     Ref<BatchElectronDensity> bed_;
00213     double accuracy_;
00214     char *type_;
00215     double (WriteElectronDensity::*density_function_)(double, double);
00216     
00217     void initialize();
00218     void label(char* buffer);
00219     Ref<Molecule> get_molecule();
00220     double calculate_value(SCVector3 point);
00221   public:
00236     WriteElectronDensity(const Ref<KeyVal> &);
00237 };
00238 
00239 class DensityColorizer: public MoleculeColorizer {
00240   protected:
00241     Ref<Wavefunction> wfn_;
00242     double scale_;
00243     double reference_;
00244     int have_scale_;
00245     int have_reference_;
00246   public:
00247     DensityColorizer(const Ref<KeyVal>&);
00248     ~DensityColorizer();
00249 
00250     void colorize(const Ref<RenderedPolygons> &);
00251 };
00252 
00253 class GradDensityColorizer: public MoleculeColorizer {
00254   protected:
00255     Ref<Wavefunction> wfn_;
00256     double scale_;
00257     double reference_;
00258     int have_scale_;
00259     int have_reference_;
00260   public:
00261     GradDensityColorizer(const Ref<KeyVal>&);
00262     ~GradDensityColorizer();
00263 
00264     void colorize(const Ref<RenderedPolygons> &);
00265 };
00266 
00267 }
00268 
00269 #endif
00270 
00271 // Local Variables:
00272 // mode: c++
00273 // c-file-style: "CLJ"
00274 // End:

Generated at Wed Sep 5 14:02:29 2007 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.5.2.
These pages are hosted on SourceForge.net