Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

coor.h

00001 //
00002 // coor.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_molecule_coor_h
00029 #define _chemistry_molecule_coor_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <iostream>
00036 #include <vector>
00037 
00038 #include <math/scmat/matrix.h>
00039 #include <math/optimize/transform.h>
00040 #include <chemistry/molecule/molecule.h>
00041 
00044 class IntCoor: public SavableState {
00045   protected:
00046     // conversion factors from radians, bohr to the preferred units
00047     static double bohr_conv;
00048     static double radian_conv;
00049     char *label_;
00050     double value_;
00051   public:
00052     IntCoor(StateIn&);
00053     IntCoor(const IntCoor&);
00056     IntCoor(const char* label = 0);
00073     IntCoor(const Ref<KeyVal>&);
00074     
00075     virtual ~IntCoor();
00076     void save_data_state(StateOut&);
00077 
00079     virtual const char* label() const;
00081     virtual double value() const;
00083     virtual void set_value(double);
00085     virtual double preferred_value() const;
00087     virtual const char* ctype() const = 0;
00089     virtual void print(std::ostream & o=ExEnv::out()) const;
00090     virtual void print_details(const Ref<Molecule> &, std::ostream& =ExEnv::out()) const;
00093     virtual double force_constant(Ref<Molecule>&) = 0;
00095     virtual void update_value(const Ref<Molecule>&) = 0;
00097     virtual void bmat(const Ref<Molecule>&,RefSCVector&bmat,double coef=1.0) = 0;
00101     virtual int equivalent(Ref<IntCoor>&) = 0;
00102 };
00103 
00118 class SumIntCoor: public IntCoor {
00119   private:
00120     std::vector<double> coef_;
00121     std::vector<Ref<IntCoor> > coor_;
00122   public:
00123     SumIntCoor(StateIn&);
00126     SumIntCoor(const char *);
00137     SumIntCoor(const Ref<KeyVal>&);
00138 
00139     ~SumIntCoor();
00140     void save_data_state(StateOut&);
00141 
00143     int n();
00146     void add(Ref<IntCoor>&,double coef);
00148     void normalize();
00149 
00150     // IntCoor overrides
00152     double preferred_value() const;
00154     const char* ctype() const;
00156     void print_details(const Ref<Molecule> &, std::ostream& =ExEnv::out()) const;
00158     double force_constant(Ref<Molecule>&);
00160     void update_value(const Ref<Molecule>&);
00162     void bmat(const Ref<Molecule>&,RefSCVector&bmat,double coef = 1.0);
00164     int equivalent(Ref<IntCoor>&);
00165 };
00166 
00187 class SetIntCoor: public SavableState {
00188   private:
00189     std::vector<Ref<IntCoor> > coor_;
00190   public:
00191     SetIntCoor();
00192     SetIntCoor(StateIn&);
00203     SetIntCoor(const Ref<KeyVal>&);
00204 
00205     virtual ~SetIntCoor();
00206     void save_data_state(StateOut&);
00207 
00209     void add(const Ref<IntCoor>&);
00211     void add(const Ref<SetIntCoor>&);
00213     void pop();
00215     void clear();
00217     int n() const;
00219     Ref<IntCoor> coor(int i) const;
00221     virtual void fd_bmat(const Ref<Molecule>&,RefSCMatrix&);
00223     virtual void bmat(const Ref<Molecule>&, RefSCMatrix&);
00227     virtual void guess_hessian(Ref<Molecule>&,RefSymmSCMatrix&);
00229     virtual void print_details(const Ref<Molecule> &,std::ostream& =ExEnv::out()) const;
00231     virtual void update_values(const Ref<Molecule>&);
00233     virtual void values_to_vector(const RefSCVector&);
00234 };
00235 
00236 
00237 // ////////////////////////////////////////////////////////////////////////
00238 
00239 class BitArrayLTri;
00240 
00243 class IntCoorGen: public SavableState
00244 {
00245   protected:
00246     Ref<Molecule> molecule_;
00247     
00248     int linear_bends_;
00249     int linear_lbends_;
00250     int linear_tors_;
00251     int linear_stors_;
00252     int nextra_bonds_;
00253     int *extra_bonds_;
00254     double linear_bend_thres_;
00255     double linear_tors_thres_;
00256     double radius_scale_factor_;
00257 
00258     void init_constants();
00259 
00260     double cos_ijk(Molecule& m, int i, int j, int k);
00261     int hterminal(Molecule& m, BitArrayLTri& bonds, int i);
00262     int nearest_contact(int i, Molecule& m);
00263 
00264     void add_bonds(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
00265     void add_bends(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
00266     void add_tors(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
00267     void add_out(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
00268   public:
00272     IntCoorGen(const Ref<Molecule>&, int nextra=0, int *extra=0);
00314     IntCoorGen(const Ref<KeyVal>&);
00315     IntCoorGen(StateIn&);
00316 
00317     ~IntCoorGen();
00318 
00320     void save_data_state(StateOut&);
00321 
00323     virtual void generate(const Ref<SetIntCoor>&);
00324 
00326     virtual void print(std::ostream& out=ExEnv::out()) const;
00327 };
00328 
00329 
00330 // ////////////////////////////////////////////////////////////////////////
00331 
00332 
00336 class MolecularCoor: public SavableState
00337 {
00338   protected:
00339     Ref<Molecule> molecule_;
00340     RefSCDimension dnatom3_; // the number of atoms x 3
00341     Ref<SCMatrixKit> matrixkit_; // used to construct matrices
00342 
00343     int debug_;
00344   public:
00345     MolecularCoor(Ref<Molecule>&);
00346     MolecularCoor(StateIn&);
00363     MolecularCoor(const Ref<KeyVal>&);
00364 
00365     virtual ~MolecularCoor();
00366 
00367     void save_data_state(StateOut&);
00368 
00371     RefSCDimension dim_natom3() { return dnatom3_; }
00372 
00374     Ref<Molecule> molecule() const { return molecule_; }
00375 
00377     virtual void print(std::ostream& =ExEnv::out()) const = 0;
00378     virtual void print_simples(std::ostream& =ExEnv::out()) const = 0;
00379 
00383     virtual RefSCDimension dim() = 0;
00384     
00388     int to_cartesian(const RefSCVector&internal);
00389     virtual int to_cartesian(const Ref<Molecule>&mol,
00390                              const RefSCVector&internal) = 0;
00391 
00395     virtual int to_internal(RefSCVector&internal) = 0;
00396 
00401     virtual int to_cartesian(RefSCVector&cartesian,RefSCVector&internal) = 0;
00402 
00407     virtual int to_internal(RefSCVector&internal,RefSCVector&cartesian) = 0;
00408 
00412     virtual int to_cartesian(RefSymmSCMatrix&cartesian,
00413                               RefSymmSCMatrix&internal) =0;
00414 
00418     virtual int to_internal(RefSymmSCMatrix&internal,
00419                              RefSymmSCMatrix&cartesian) = 0;
00420 
00423     virtual void guess_hessian(RefSymmSCMatrix&hessian) = 0;
00424 
00427     virtual RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&) = 0;
00428 
00430     virtual int nconstrained();
00431 
00435     virtual Ref<NonlinearTransform> change_coordinates();
00436 
00437     Ref<SCMatrixKit> matrixkit() const { return matrixkit_; }
00438 };
00439 
00440 
00443 class IntMolecularCoor: public MolecularCoor
00444 {
00445   protected:
00446     Ref<IntCoorGen> generator_;
00447 
00448     void form_K_matrix(RefSCDimension& dredundant,
00449                        RefSCDimension& dfixed,
00450                        RefSCMatrix& K,
00451                        int*& is_totally_symmetric);
00452 
00453     RefSCDimension dim_; // corresponds to the number of variable coordinates
00454     RefSCDimension dvc_; // the number of variable + constant coordinates
00455 
00456     Ref<SetIntCoor> variable_; // the variable internal coordinates
00457     Ref<SetIntCoor> constant_; // the constant internal coordinates
00458     
00459     Ref<SetIntCoor> fixed_;
00460     Ref<SetIntCoor> watched_;
00461     Ref<IntCoor> followed_;
00462 
00463     // these are all of the basic coordinates
00464     Ref<SetIntCoor> bonds_;
00465     Ref<SetIntCoor> bends_;
00466     Ref<SetIntCoor> tors_;
00467     Ref<SetIntCoor> outs_;
00468     // these are provided by the user or generated coordinates that
00469     // could not be assigned to any of the above catagories
00470     Ref<SetIntCoor> extras_;
00471 
00472     Ref<SetIntCoor> all_;
00473 
00474     // Useful relationships
00475     // variable_->n() + constant_->n() = 3N-6(5)
00476     // symm_->n() + asymm_->n() = 3N-6(5)
00477 
00478     int update_bmat_;  // if 1 recompute the b matrix during to_cartesian
00479     int only_totally_symmetric_; // only coors with tot. symm comp. are varied
00480     double symmetry_tolerance_; // tol used to find coors with tot. sym. comp.
00481     double simple_tolerance_; // tol used to see if a simple is included
00482     double coordinate_tolerance_; // tol used to see if a coor is included
00483     double cartesian_tolerance_;  // tol used in intco->cart transformation
00484     double scale_bonds_; // scale factor for bonds
00485     double scale_bends_; // scale factor for bends
00486     double scale_tors_;  // scale factor for tors
00487     double scale_outs_;  // scale factor for outs
00488 
00489     int nextra_bonds_;
00490     int* extra_bonds_;
00491 
00492     int given_fixed_values_; // if true make molecule have given fixed values
00493 
00494     int decouple_bonds_;
00495     int decouple_bends_;
00496 
00497     int max_update_steps_;
00498     double max_update_disp_;
00499 
00503     virtual void init();
00506     virtual void new_coords();
00508     virtual void read_keyval(const Ref<KeyVal>&);
00509 
00510     // control whether or not to print coordinates when they are formed
00511     int form_print_simples_;
00512     int form_print_variable_;
00513     int form_print_constant_;
00514     int form_print_molecule_;
00515   public:
00516     IntMolecularCoor(StateIn&);
00517     IntMolecularCoor(Ref<Molecule>&mol);
00622     IntMolecularCoor(const Ref<KeyVal>&);
00623 
00624     virtual ~IntMolecularCoor();
00625     void save_data_state(StateOut&);
00626   
00629     virtual void form_coordinates(int keep_variable=0) =0;
00630     
00633     virtual int all_to_cartesian(const Ref<Molecule> &,RefSCVector&internal);
00636     virtual int all_to_internal(const Ref<Molecule> &,RefSCVector&internal);
00637 
00640     virtual RefSCDimension dim();
00641     virtual int to_cartesian(const Ref<Molecule> &,const RefSCVector&internal);
00642     virtual int to_internal(RefSCVector&internal);
00643     virtual int to_cartesian(RefSCVector&cartesian,RefSCVector&internal);
00644     virtual int to_internal(RefSCVector&internal,RefSCVector&cartesian);
00645     virtual int to_cartesian(RefSymmSCMatrix&cart,RefSymmSCMatrix&internal);
00646     virtual int to_internal(RefSymmSCMatrix&internal,RefSymmSCMatrix&cart);
00647     virtual void print(std::ostream& =ExEnv::out()) const;
00648     virtual void print_simples(std::ostream& =ExEnv::out()) const;
00649     virtual void print_variable(std::ostream& =ExEnv::out()) const;
00650     virtual void print_constant(std::ostream& =ExEnv::out()) const;
00651     int nconstrained();
00652 };
00653 
00654 // ///////////////////////////////////////////////////////////////////////
00655 
00665 class SymmMolecularCoor: public IntMolecularCoor
00666 {
00667   protected:
00668     // true if coordinates should be changed during optimization
00669     int change_coordinates_;
00670     // true if hessian should be transformed too (should always be true)
00671     int transform_hessian_;
00672     // max value for the condition number if coordinates can be changed
00673     double max_kappa2_;
00674 
00675     void init();
00676   public:
00677     SymmMolecularCoor(Ref<Molecule>&mol);
00678     SymmMolecularCoor(StateIn&);
00697     SymmMolecularCoor(const Ref<KeyVal>&);
00698 
00699     virtual ~SymmMolecularCoor();
00700     void save_data_state(StateOut&);
00701 
00704     void form_coordinates(int keep_variable=0);
00705 
00707     void guess_hessian(RefSymmSCMatrix&hessian);
00709     RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
00710 
00713     Ref<NonlinearTransform> change_coordinates();
00714 
00715     void print(std::ostream& =ExEnv::out()) const;
00716 };
00717 
00718 // ///////////////////////////////////////////////////////////////////////
00719 
00722 class RedundMolecularCoor: public IntMolecularCoor
00723 {
00724 
00725   public:
00726     RedundMolecularCoor(Ref<Molecule>&mol);
00727     RedundMolecularCoor(StateIn&);
00729     RedundMolecularCoor(const Ref<KeyVal>&);
00730 
00731     virtual ~RedundMolecularCoor();
00732     void save_data_state(StateOut&);
00733 
00736     void form_coordinates(int keep_variable=0);
00738     void guess_hessian(RefSymmSCMatrix&hessian);
00740     RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
00741 };
00742 
00743 // ///////////////////////////////////////////////////////////////////////
00744 
00749 class CartMolecularCoor: public MolecularCoor
00750 {
00751   private:
00752   protected:
00753     RefSCDimension dim_; // the number of atoms x 3
00754 
00756     virtual void init();
00757   public:
00758     CartMolecularCoor(Ref<Molecule>&mol);
00759     CartMolecularCoor(StateIn&);
00761     CartMolecularCoor(const Ref<KeyVal>&);
00762 
00763     virtual ~CartMolecularCoor();
00764   
00765     void save_data_state(StateOut&);
00766 
00768     virtual RefSCDimension dim();
00769     virtual int to_cartesian(const Ref<Molecule>&,const RefSCVector&internal);
00770     virtual int to_internal(RefSCVector&internal);
00771     virtual int to_cartesian(RefSCVector&cartesian,RefSCVector&internal);
00772     virtual int to_internal(RefSCVector&internal,RefSCVector&cartesian);
00773     virtual int to_cartesian(RefSymmSCMatrix&cart,RefSymmSCMatrix&internal);
00774     virtual int to_internal(RefSymmSCMatrix&internal,RefSymmSCMatrix&cart);
00775     virtual void print(std::ostream& =ExEnv::out()) const;
00776     virtual void print_simples(std::ostream& =ExEnv::out()) const;
00777     void guess_hessian(RefSymmSCMatrix&hessian);
00778     RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
00779 };
00780 
00781 #endif
00782 
00783 // Local Variables:
00784 // mode: c++
00785 // c-file-style: "CLJ"
00786 // End:

Generated at Thu Oct 4 18:08:43 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.