EMAN2
pointarray.h
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Wen Jiang, 08/11/2004 (jiang12@purdue.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  *
00034  * */
00035 
00036 #ifndef eman_pointarray_h_
00037 #define eman_pointarray_h_
00038 
00039 #include "emdata.h"
00040 #include "transform.h"
00041 
00042 #if defined NFFT || NFFT2
00043 extern "C"
00044 {
00045         #include "nfft.h"
00046         #include "utils.h"
00047 }
00048 #endif
00049 
00050 #include <sys/stat.h>
00051 
00052 namespace EMAN
00053 {
00055         class PointArray
00056         {
00057                 public:
00058                 enum Density2PointsArrayAlgorithm
00059                 {
00060                         PEAKS_SUB, PEAKS_DIV, KMEANS
00061                 };
00062 
00063                 public:
00064                 PointArray();
00065                 explicit PointArray(int nn);
00066                 ~PointArray();
00067                 void zero();
00068                 PointArray *copy();
00069                 PointArray & operator=(PointArray & pa);
00070                 size_t get_number_points() const;
00071                 void set_number_points(size_t nn);
00072                 bool read_from_pdb(const char *file);
00073                 void save_to_pdb(const char *file);
00074                 FloatPoint get_center();
00075                 void center_to_zero();  // shift center to zero
00076                 Region get_bounding_box();
00077                 double *get_points_array();
00078                 Vec3f get_vector_at(int i);     // get the ith vector in the list
00079                 double get_value_at(int i);  // get the amplitude of the ith vector
00080                 void set_vector_at(int i,Vec3f vec,double value);
00081                 void set_vector_at(int i,vector<double>);
00082                 void set_points_array(double *p);
00087                 vector<float> get_points();
00088 
00094                 EMData *distmx(int sortrows=0); // computes a distance matrix
00095 
00104                 vector<int> match_points(PointArray *to,float max_miss=-1.0);
00105 
00106 
00113                 Transform *align_2d(PointArray *to,float max_dist);     // computes the optimal alignment between two (non-identical) sets of points
00114 
00123                 vector<float> align_trans_2d(PointArray *to,int flags=0,float dxhint=0,float dyhint=0 );                // translational alignment of point sets in 2-D
00124 
00125                 void mask(double rmax, double rmin = 0.0);
00126                 void mask_asymmetric_unit(const string & sym);
00127                 void transform(const Transform& transform);
00128 
00132                 void right_transform(const Transform& transform);
00133 
00134                 void set_from(vector<float>);
00135                 void set_from(PointArray * source, const string & sym = "", Transform *transform=0);
00136                 void set_from(double *source, int num, const string & sym = "", Transform *transform=0);
00137                 void set_from_density_map(EMData * map, int num, float thresh, float apix,
00138                                                                   Density2PointsArrayAlgorithm mode = PEAKS_DIV);
00139                 void sort_by_axis(int axis = 1);        // x,y,z axes = 0, 1, 2
00140                 EMData *pdb2mrc_by_nfft(int map_size, float apix, float res);   // return real space 3-D map
00141                 EMData *pdb2mrc_by_summation(int map_size, float apix, float res, int addpdbbfactor);   // return real space 3-D map
00142                 EMData *projection_by_nfft(int image_size, float apix, float res = 0);  // return 2-D Fourier Transform
00143                 EMData *projection_by_summation(int image_size, float apix, float res); // return 2-D real space image
00144                 void replace_by_summation(EMData *image, int i, Vec3f vec, float amp, float apix, float res); // changes a single Gaussian from the projection
00145 
00153                 void opt_from_proj(const vector<EMData*> & proj,float pixres);
00154 
00156                 inline double sim_pointpotential(double dist, double ang, double dihed) {
00157                         return pow(dist-dist0,2.0)*distc+ang*ang*angc+pow(dihed-dihed0,2.0)*dihedc;
00158                 }
00159 
00161                 double sim_potential();
00162                 
00164                 double sim_potentiald(int i);
00165 
00167                 double sim_potentialdxyz(int i,double dx, double dy, double dz);
00168                 
00170                 void sim_updategeom();
00171 
00173                 Vec3f sim_descent(int i);
00174                 
00176                 void sim_minstep(double maxshift);
00177 
00179                 void sim_minstep_seq(double meanshift);
00180 
00182                 void sim_rescale();
00183                 
00185                 void sim_printstat();
00186                 
00188                 void sim_set_pot_parms(double pdist0,double pdistc,double pangc, double pdihed0, double pdihedc, double pmapc, EMData *pmap,double pmindistc,double pdistpenc);
00189                 
00191                 void sim_add_point_double();
00192                 void sim_add_point_one();
00193                 
00195                 double calc_total_length();
00196                 
00198                 vector<double> fit_helix(EMData *pmap,int minlength,float mindensity,vector<int> edge,int twodir);
00199                 
00201                 vector<float> do_pca(int start, int end);
00202                 
00203                 vector<float> do_filter(vector<float> pts, float *ft, int num);
00204                 
00205                 vector<double> construct_helix(int start,int end,float phs, float &score,bool &dir);
00206                 void reverse_chain();
00207 
00208                 void save_pdb_with_helix(const char *file, vector<float> hlxid);
00209                 
00210                 void remove_helix_from_map(EMData *m, vector<float> hlxid);
00211                 private:
00212                 double *points;
00213                 size_t n;
00214                 double *bfactor;
00215                 
00216                 // These are used internally for the simple dynamics/minimization code, and are otherwise unallocated
00217                 // Note that this is NOT for PDB MD, just for simplified point-chains, and mapping points into density
00218                 double *adist;  // distance squared between the numbered point and the previous point with wrap-around
00219                 double *aang;   // angle at the numbered point using the point before and the point after
00220                 double *adihed; // dihedral using 2 points before and one point after
00221                 
00235                 double dist0, distc, angc, dihed0, dihedc, mapc,apix, mindistc,distpenc;
00236                 EMData *map;
00237                 EMData *gradx,*grady,*gradz;
00238                 vector<Vec3f> oldshifts;
00239         };
00240 }
00241 
00242 #endif