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
    00042 namespace sc {
    00043
    00046 class IntCoor: public SavableState {
    00047   protected:
    00048     // conversion factors from radians, bohr to the preferred units
    00049     static double bohr_conv;
    00050     static double radian_conv;
    00051     char *label_;
    00052     double value_;
    00053   public:
    00054     IntCoor(StateIn&);
    00055     IntCoor(const IntCoor&);
    00058     IntCoor(const char* label = 0);
    00075     IntCoor(const Ref<KeyVal>&);
    00076
    00077     virtual ~IntCoor();
    00078     void save_data_state(StateOut&);
    00079
    00081     virtual const char* label() const;
    00083     virtual double value() const;
    00085     virtual void set_value(double);
    00087     virtual double preferred_value() const;
    00089     virtual const char* ctype() const = 0;
    00091     virtual void print(std::ostream & o=ExEnv::out0()) const;
    00092     virtual void print_details(const Ref<Molecule> &, std::ostream& =ExEnv::out0()) const;
    00095     virtual double force_constant(Ref<Molecule>&) = 0;
    00097     virtual void update_value(const Ref<Molecule>&) = 0;
    00099     virtual void bmat(const Ref<Molecule>&,RefSCVector&bmat,double coef=1.0) = 0;
    00103     virtual int equivalent(Ref<IntCoor>&) = 0;
    00104 };
    00105
    00120 class SumIntCoor: public IntCoor {
    00121   private:
    00122     std::vector<double> coef_;
    00123     std::vector<Ref<IntCoor> > coor_;
    00124   public:
    00125     SumIntCoor(StateIn&);
    00128     SumIntCoor(const char *);
    00139     SumIntCoor(const Ref<KeyVal>&);
    00140
    00141     ~SumIntCoor();
    00142     void save_data_state(StateOut&);
    00143
    00145     int n();
    00148     void add(Ref<IntCoor>&,double coef);
    00150     void normalize();
    00151
    00152     // IntCoor overrides
    00154     double preferred_value() const;
    00156     const char* ctype() const;
    00158     void print_details(const Ref<Molecule> &, std::ostream& =ExEnv::out0()) const;
    00160     double force_constant(Ref<Molecule>&);
    00162     void update_value(const Ref<Molecule>&);
    00164     void bmat(const Ref<Molecule>&,RefSCVector&bmat,double coef = 1.0);
    00166     int equivalent(Ref<IntCoor>&);
    00167 };
    00168
    00189 class SetIntCoor: public SavableState {
    00190   private:
    00191     std::vector<Ref<IntCoor> > coor_;
    00192   public:
    00193     SetIntCoor();
    00194     SetIntCoor(StateIn&);
    00205     SetIntCoor(const Ref<KeyVal>&);
    00206
    00207     virtual ~SetIntCoor();
    00208     void save_data_state(StateOut&);
    00209
    00211     void add(const Ref<IntCoor>&);
    00213     void add(const Ref<SetIntCoor>&);
    00215     void pop();
    00217     void clear();
    00219     int n() const;
    00221     Ref<IntCoor> coor(int i) const;
    00223     virtual void fd_bmat(const Ref<Molecule>&,RefSCMatrix&);
    00225     virtual void bmat(const Ref<Molecule>&, RefSCMatrix&);
    00229     virtual void guess_hessian(Ref<Molecule>&,RefSymmSCMatrix&);
    00231     virtual void print_details(const Ref<Molecule> &,std::ostream& =ExEnv::out0()) const;
    00233     virtual void update_values(const Ref<Molecule>&);
    00235     virtual void values_to_vector(const RefSCVector&);
    00236 };
    00237
    00238
    00239 // ////////////////////////////////////////////////////////////////////////
    00240
    00241 class BitArrayLTri;
    00242
    00245 class IntCoorGen: public SavableState
    00246 {
    00247   protected:
    00248     Ref<Molecule> molecule_;
    00249
    00250     int linear_bends_;
    00251     int linear_lbends_;
    00252     int linear_tors_;
    00253     int linear_stors_;
    00254     int nextra_bonds_;
    00255     int *extra_bonds_;
    00256     double linear_bend_thres_;
    00257     double linear_tors_thres_;
    00258     double radius_scale_factor_;
    00259
    00260     void init_constants();
    00261
    00262     double cos_ijk(Molecule& m, int i, int j, int k);
    00263     int hterminal(Molecule& m, BitArrayLTri& bonds, int i);
    00264     int nearest_contact(int i, Molecule& m);
    00265
    00266     void add_bonds(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
    00267     void add_bends(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
    00268     void add_tors(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
    00269     void add_out(const Ref<SetIntCoor>& list, BitArrayLTri& bonds, Molecule& m);
    00270   public:
    00274     IntCoorGen(const Ref<Molecule>&, int nextra=0, int *extra=0);
    00316     IntCoorGen(const Ref<KeyVal>&);
    00317     IntCoorGen(StateIn&);
    00318
    00319     ~IntCoorGen();
    00320
    00322     void save_data_state(StateOut&);
    00323
    00325     virtual void generate(const Ref<SetIntCoor>&);
    00326
    00328     virtual void print(std::ostream& out=ExEnv::out0()) const;
    00329 };
    00330
    00331
    00332 // ////////////////////////////////////////////////////////////////////////
    00333
    00334
    00338 class MolecularCoor: public SavableState
    00339 {
    00340   protected:
    00341     Ref<Molecule> molecule_;
    00342     RefSCDimension dnatom3_; // the number of atoms x 3
    00343     Ref<SCMatrixKit> matrixkit_; // used to construct matrices
    00344
    00345     int debug_;
    00346   public:
    00347     MolecularCoor(Ref<Molecule>&);
    00348     MolecularCoor(StateIn&);
    00365     MolecularCoor(const Ref<KeyVal>&);
    00366
    00367     virtual ~MolecularCoor();
    00368
    00369     void save_data_state(StateOut&);
    00370
    00373     RefSCDimension dim_natom3() { return dnatom3_; }
    00374
    00376     Ref<Molecule> molecule() const { return molecule_; }
    00377
    00379     virtual void print(std::ostream& =ExEnv::out0()) const = 0;
    00380     virtual void print_simples(std::ostream& =ExEnv::out0()) const = 0;
    00381
    00385     virtual RefSCDimension dim() = 0;
    00386
    00390     int to_cartesian(const RefSCVector&internal);
    00391     virtual int to_cartesian(const Ref<Molecule>&mol,
    00392                              const RefSCVector&internal) = 0;
    00393
    00397     virtual int to_internal(RefSCVector&internal) = 0;
    00398
    00403     virtual int to_cartesian(RefSCVector&cartesian,RefSCVector&internal) = 0;
    00404
    00409     virtual int to_internal(RefSCVector&internal,RefSCVector&cartesian) = 0;
    00410
    00414     virtual int to_cartesian(RefSymmSCMatrix&cartesian,
    00415                               RefSymmSCMatrix&internal) =0;
    00416
    00420     virtual int to_internal(RefSymmSCMatrix&internal,
    00421                              RefSymmSCMatrix&cartesian) = 0;
    00422
    00425     virtual void guess_hessian(RefSymmSCMatrix&hessian) = 0;
    00426
    00429     virtual RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&) = 0;
    00430
    00432     virtual int nconstrained();
    00433
    00437     virtual Ref<NonlinearTransform> change_coordinates();
    00438
    00439     Ref<SCMatrixKit> matrixkit() const { return matrixkit_; }
    00440 };
    00441
    00442
    00445 class IntMolecularCoor: public MolecularCoor
    00446 {
    00447   protected:
    00448     Ref<IntCoorGen> generator_;
    00449
    00450     void form_K_matrix(RefSCDimension& dredundant,
    00451                        RefSCDimension& dfixed,
    00452                        RefSCMatrix& K,
    00453                        int*& is_totally_symmetric);
    00454
    00455     RefSCDimension dim_; // corresponds to the number of variable coordinates
    00456     RefSCDimension dvc_; // the number of variable + constant coordinates
    00457
    00458     Ref<SetIntCoor> variable_; // the variable internal coordinates
    00459     Ref<SetIntCoor> constant_; // the constant internal coordinates
    00460
    00461     Ref<SetIntCoor> fixed_;
    00462     Ref<SetIntCoor> watched_;
    00463     Ref<IntCoor> followed_;
    00464
    00465     // these are all of the basic coordinates
    00466     Ref<SetIntCoor> bonds_;
    00467     Ref<SetIntCoor> bends_;
    00468     Ref<SetIntCoor> tors_;
    00469     Ref<SetIntCoor> outs_;
    00470     // these are provided by the user or generated coordinates that
    00471     // could not be assigned to any of the above catagories
    00472     Ref<SetIntCoor> extras_;
    00473
    00474     Ref<SetIntCoor> all_;
    00475
    00476     // Useful relationships
    00477     // variable_->n() + constant_->n() = 3N-6(5)
    00478     // symm_->n() + asymm_->n() = 3N-6(5)
    00479
    00480     int update_bmat_;  // if 1 recompute the b matrix during to_cartesian
    00481     int only_totally_symmetric_; // only coors with tot. symm comp. are varied
    00482     double symmetry_tolerance_; // tol used to find coors with tot. sym. comp.
    00483     double simple_tolerance_; // tol used to see if a simple is included
    00484     double coordinate_tolerance_; // tol used to see if a coor is included
    00485     double cartesian_tolerance_;  // tol used in intco->cart transformation
    00486     double scale_bonds_; // scale factor for bonds
    00487     double scale_bends_; // scale factor for bends
    00488     double scale_tors_;  // scale factor for tors
    00489     double scale_outs_;  // scale factor for outs
    00490
    00491     int nextra_bonds_;
    00492     int* extra_bonds_;
    00493
    00494     int given_fixed_values_; // if true make molecule have given fixed values
    00495
    00496     int decouple_bonds_;
    00497     int decouple_bends_;
    00498
    00499     int max_update_steps_;
    00500     double max_update_disp_;
    00501
    00505     virtual void init();
    00508     virtual void new_coords();
    00510     virtual void read_keyval(const Ref<KeyVal>&);
    00511
    00512     // control whether or not to print coordinates when they are formed
    00513     int form_print_simples_;
    00514     int form_print_variable_;
    00515     int form_print_constant_;
    00516     int form_print_molecule_;
    00517   public:
    00518     IntMolecularCoor(StateIn&);
    00519     IntMolecularCoor(Ref<Molecule>&mol);
    00624     IntMolecularCoor(const Ref<KeyVal>&);
    00625
    00626     virtual ~IntMolecularCoor();
    00627     void save_data_state(StateOut&);
    00628
    00631     virtual void form_coordinates(int keep_variable=0) =0;
    00632
    00635     virtual int all_to_cartesian(const Ref<Molecule> &,RefSCVector&internal);
    00638     virtual int all_to_internal(const Ref<Molecule> &,RefSCVector&internal);
    00639
    00642     virtual RefSCDimension dim();
    00643     virtual int to_cartesian(const Ref<Molecule> &,const RefSCVector&internal);
    00644     virtual int to_internal(RefSCVector&internal);
    00645     virtual int to_cartesian(RefSCVector&cartesian,RefSCVector&internal);
    00646     virtual int to_internal(RefSCVector&internal,RefSCVector&cartesian);
    00647     virtual int to_cartesian(RefSymmSCMatrix&cart,RefSymmSCMatrix&internal);
    00648     virtual int to_internal(RefSymmSCMatrix&internal,RefSymmSCMatrix&cart);
    00649     virtual void print(std::ostream& =ExEnv::out0()) const;
    00650     virtual void print_simples(std::ostream& =ExEnv::out0()) const;
    00651     virtual void print_variable(std::ostream& =ExEnv::out0()) const;
    00652     virtual void print_constant(std::ostream& =ExEnv::out0()) const;
    00653     int nconstrained();
    00654 };
    00655
    00656 // ///////////////////////////////////////////////////////////////////////
    00657
    00667 class SymmMolecularCoor: public IntMolecularCoor
    00668 {
    00669   protected:
    00670     // true if coordinates should be changed during optimization
    00671     int change_coordinates_;
    00672     // true if hessian should be transformed too (should always be true)
    00673     int transform_hessian_;
    00674     // max value for the condition number if coordinates can be changed
    00675     double max_kappa2_;
    00676
    00677     void init();
    00678   public:
    00679     SymmMolecularCoor(Ref<Molecule>&mol);
    00680     SymmMolecularCoor(StateIn&);
    00699     SymmMolecularCoor(const Ref<KeyVal>&);
    00700
    00701     virtual ~SymmMolecularCoor();
    00702     void save_data_state(StateOut&);
    00703
    00706     void form_coordinates(int keep_variable=0);
    00707
    00709     void guess_hessian(RefSymmSCMatrix&hessian);
    00711     RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
    00712
    00715     Ref<NonlinearTransform> change_coordinates();
    00716
    00717     void print(std::ostream& =ExEnv::out0()) const;
    00718 };
    00719
    00720 // ///////////////////////////////////////////////////////////////////////
    00721
    00724 class RedundMolecularCoor: public IntMolecularCoor
    00725 {
    00726
    00727   public:
    00728     RedundMolecularCoor(Ref<Molecule>&mol);
    00729     RedundMolecularCoor(StateIn&);
    00731     RedundMolecularCoor(const Ref<KeyVal>&);
    00732
    00733     virtual ~RedundMolecularCoor();
    00734     void save_data_state(StateOut&);
    00735
    00738     void form_coordinates(int keep_variable=0);
    00740     void guess_hessian(RefSymmSCMatrix&hessian);
    00742     RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
    00743 };
    00744
    00745 // ///////////////////////////////////////////////////////////////////////
    00746
    00751 class CartMolecularCoor: public MolecularCoor
    00752 {
    00753   private:
    00754   protected:
    00755     RefSCDimension dim_; // the number of atoms x 3
    00756
    00758     virtual void init();
    00759   public:
    00760     CartMolecularCoor(Ref<Molecule>&mol);
    00761     CartMolecularCoor(StateIn&);
    00763     CartMolecularCoor(const Ref<KeyVal>&);
    00764
    00765     virtual ~CartMolecularCoor();
    00766
    00767     void save_data_state(StateOut&);
    00768
    00770     virtual RefSCDimension dim();
    00771     virtual int to_cartesian(const Ref<Molecule>&,const RefSCVector&internal);
    00772     virtual int to_internal(RefSCVector&internal);
    00773     virtual int to_cartesian(RefSCVector&cartesian,RefSCVector&internal);
    00774     virtual int to_internal(RefSCVector&internal,RefSCVector&cartesian);
    00775     virtual int to_cartesian(RefSymmSCMatrix&cart,RefSymmSCMatrix&internal);
    00776     virtual int to_internal(RefSymmSCMatrix&internal,RefSymmSCMatrix&cart);
    00777     virtual void print(std::ostream& =ExEnv::out0()) const;
    00778     virtual void print_simples(std::ostream& =ExEnv::out0()) const;
    00779     void guess_hessian(RefSymmSCMatrix&hessian);
    00780     RefSymmSCMatrix inverse_hessian(RefSymmSCMatrix&);
    00781 };
    00782
    00783 }
    00784
    00785 #endif
    00786
    00787 // Local Variables:
    00788 // mode: c++
    00789 // c-file-style: "CLJ"
    00790 // End: