00001 #ifndef KNNR_H
00002 #define KNNR_H
00003 
00004 #include <iostream>
00005 #include <iomanip>
00006 #include <fstream>
00007 #include <cstdio>
00008 #include <vector>
00009 #include <cstring>
00010 #include <math.h>
00011 
00012 #include "stringtools.h"
00013 #include "pTable.h"
00014 #include "constants.h"
00015 #include "utils.h"
00016 
00017 class ICoord;
00018 
00019 class KNNR {
00020   
00021   private:
00022   
00023    string file0;
00024    int runnum;
00025    string* filesxyz;
00026    string* filesgrad;
00027    string* fileshess;
00028 
00029    int natoms;
00030    double** xyz;
00031    int* anumbers;
00032    string* anames;
00033 
00034    int* id;
00035    double* distances;
00036    double* distancesu;
00037    double* energies;
00038    double** grads;
00039    double** hess;
00040    int* useH;
00041 
00042    int nic;
00043    int nbonds; int nangles; int ntor;
00044 
00045 
00046    int read_ics(int& nbonds, int** bonds, int& nangles, int** angles, int& ntor, int** torsions, string filename);
00047    int read_xyzs(double* energies, double** xyz, string* filenames);
00048    double read_one_xyz(int n, string filename, double* coords);
00049 
00050    void xyz_read(string* anames, double* coords, string xyzfile);
00051 
00052    int read_hess(int nic, string* filenames);
00053    void read_one_hess(int n, int nic, string filename);
00054    int get_files(string fileprefix, string filesuffix, string* files);
00055 
00056    void get_distances(int npts, double** xyz, ICoord& ic1, ICoord& ic2);
00057    double get_distance(double* xyz1, double* xyz2, ICoord& ic1, ICoord& ic2);
00058    void get_distances_u(int npts, int pt, ICoord& ic1, ICoord& ic2);
00059    double get_distance_u(double* xyz1, double* xyz2, ICoord& ic1, ICoord& ic2);
00060    void get_dqpic(double* dq1, ICoord& ic1, ICoord& ic2);
00061 
00062    void setup_ic(ICoord& ic1, ICoord& ic2);
00063    void release_ic(ICoord& ic1, ICoord& ic2);
00064 
00065   
00066    int find_knn(int pt, int k, int* knn, double* knnd, int type);
00067    double predict_point(int pt, int k, ICoord& ic1, ICoord& ic2);
00068 
00069   
00070    int find_knn_xyz(double* coords, int k, int* knn, double* knnd, ICoord& ic1, ICoord& ic2);
00071 
00072    int compare_add_files(int npts1, string* filesxyz1, string* filesgrad1, string* fileshess1, string* newfilesxyz, string* newfilesgrad, string* newfileshess);
00073    void reassign_mem(int npts1);
00074 
00075   public:
00076 
00077    int npts;
00078    int printl;
00079 
00080    int begin(int runnum, int natoms0);
00081    double test_points(int k0);
00082    double grad_knnr(double* coords, double &E1, double* grads, double* Ut, int k);
00083    int add_extra_points();
00084    void add_point(double energy, double* xyz, double* grad, double* hess);
00085    void freemem();
00086 
00087 
00088 };
00089 
00090 #endif