EMAN2
Public Types | Public Member Functions | Private Attributes
EMAN::PDBReader Class Reference

PointArray defines a double array of points with values in a 3D space. More...

#include <pdbreader.h>

Collaboration diagram for EMAN::PDBReader:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Density2PointsArrayAlgorithm { PEAKS_SUB, PEAKS_DIV, KMEANS }

Public Member Functions

 PDBReader ()
 PDBReader (int nn)
 ~PDBReader ()
void zero ()
PDBReadercopy ()
PDBReaderoperator= (PDBReader &pa)
size_t get_number_points () const
void set_number_points (size_t nn)
bool read_from_pdb (const char *file)
 Reads and parses all information from file.
void save_to_pdb (const char *file) const
 Saves all atom information into a pdb in the official format.
double * get_points_array ()
 Returns the double array of points.
void set_points_array (double *p)
 Allows the user to set the double array of points.
vector< float > get_points ()
 Returns all x,y,z triplets packed into a vector<float>
void right_transform (const Transform &transform)
 Does Transform*v as opposed to v*Transform (as in the transform function)
PointArraymakePointArray (const PDBReader &p)
vector< float > get_x ()
vector< float > get_y ()
vector< float > get_z ()
vector< string > get_atomName ()
vector< string > get_resName ()
vector< int > get_resNum ()

Private Attributes

double * points
vector< int > pointInfo
vector< string > pWords
vector< string > atomName
vector< string > residueName
vector< string > chainId
vector< string > elementSym
vector< string > tail
vector< string > head
vector< string > lines
size_t n
int ter_stop
int count_stop
vector< float > x
vector< float > y
vector< float > z
vector< int > resNum

Detailed Description

PointArray defines a double array of points with values in a 3D space.

Definition at line 58 of file pdbreader.h.


Member Enumeration Documentation

Enumerator:
PEAKS_SUB 
PEAKS_DIV 
KMEANS 

Definition at line 61 of file pdbreader.h.


Constructor & Destructor Documentation

PDBReader::PDBReader ( )

Definition at line 46 of file pdbreader.cpp.

References n, and points.

Referenced by copy().

{
        points = 0;
        n = 0;
}
PDBReader::PDBReader ( int  nn) [explicit]

Definition at line 52 of file pdbreader.cpp.

References n, nn(), points, and ter_stop.

{
        n = nn;
        points = (double *) calloc(4 * n, sizeof(double));
        ter_stop = 0;
}
PDBReader::~PDBReader ( )

Definition at line 59 of file pdbreader.cpp.

References points.

{
        if( points )
        {
                free(points);
                points = 0;
        }
}

Member Function Documentation

PDBReader * PDBReader::copy ( )

Definition at line 75 of file pdbreader.cpp.

References atomName, chainId, elementSym, get_number_points(), get_points_array(), head, lines, PDBReader(), pointInfo, pWords, residueName, set_number_points(), and tail.

{
        PDBReader *pa2 = new PDBReader();
        pa2->set_number_points(get_number_points());
        double *pa2data = pa2->get_points_array();
        memcpy(pa2data, get_points_array(), sizeof(double) * 4 * get_number_points());
        pa2->pWords = pWords;
        pa2->atomName = atomName;
        pa2->residueName = residueName;
        pa2->chainId = chainId;
        pa2->elementSym = elementSym;
        pa2->tail = tail;
        pa2->head = head;
        pa2->pointInfo = pointInfo;
        pa2->lines = lines;
        return pa2;
}
vector< string > PDBReader::get_atomName ( )

Definition at line 153 of file pdbreader.cpp.

References atomName.

                                       {
        return atomName;
}
size_t PDBReader::get_number_points ( ) const

Definition at line 103 of file pdbreader.cpp.

References n.

Referenced by copy(), operator=(), and read_from_pdb().

{
        return n;
}
vector< float > PDBReader::get_points ( )

Returns all x,y,z triplets packed into a vector<float>

Returns:
All points packed into a vector<float>

Definition at line 309 of file pdbreader.cpp.

References n, and points.

                                    {
vector<float> ret;
for (unsigned int i=0; i<n; i++) {
        ret.push_back((float)points[i*4]);
        ret.push_back((float)points[i*4+1]);
        ret.push_back((float)points[i*4+2]);
}

return ret;
}
double * PDBReader::get_points_array ( )

Returns the double array of points.

Returns:
A double array of points

Definition at line 117 of file pdbreader.cpp.

References points.

Referenced by copy(), and operator=().

{
        return points;
}
vector< string > PDBReader::get_resName ( )

Definition at line 157 of file pdbreader.cpp.

References residueName.

                                      {
        return residueName;
}
vector< int > PDBReader::get_resNum ( )

Definition at line 161 of file pdbreader.cpp.

References resNum.

                                  {
        return resNum;
}
vector< float > PDBReader::get_x ( )

Definition at line 130 of file pdbreader.cpp.

References atomName, count_stop, pointInfo, points, resNum, x, y, and z.

                               {
        if (count_stop == 0) {count_stop = atomName.size();}
        for (int i=0; i<count_stop; i++) {
                x.push_back((float)points[4*i]);
                y.push_back((float)points[4*i + 1]);
                z.push_back((float)points[4*i + 2]);
                resNum.push_back(pointInfo[2*i+1]);
        }

        return x;
}
vector< float > PDBReader::get_y ( )

Definition at line 143 of file pdbreader.cpp.

References y.

                               {
        //cout << y.size() << endl;
        return y;
}
vector< float > PDBReader::get_z ( )

Definition at line 149 of file pdbreader.cpp.

References z.

                               {
        return z;
}
PointArray * PDBReader::makePointArray ( const PDBReader p)

Definition at line 332 of file pdbreader.cpp.

References EMAN::PointArray::read_from_pdb(), and save_to_pdb().

                                                         {
        PointArray* pArray  = new PointArray;
        p.save_to_pdb("thisFile3.txt");
        pArray->read_from_pdb("thisFile3.txt");
        remove("thisFile3.txt");
        
        return pArray;
}
PDBReader & PDBReader::operator= ( PDBReader pa)

Definition at line 94 of file pdbreader.cpp.

References get_number_points(), get_points_array(), and set_number_points().

{
        if (this != &pa) {
                set_number_points(pa.get_number_points());
                memcpy(get_points_array(), pa.get_points_array(), sizeof(double) * 4 * get_number_points());
        }
        return *this;
}
bool PDBReader::read_from_pdb ( const char *  file)

Reads and parses all information from file.

Parameters:
The.pdb file that you want to read from

Definition at line 167 of file pdbreader.cpp.

References atomName, chainId, count_stop, elementSym, get_number_points(), head, lines, pointInfo, points, pWords, residueName, set_number_points(), tail, ter_stop, tf(), x, y, and z.

{

        pWords.clear();
        atomName.clear();
        residueName.clear();
        chainId.clear();
        elementSym.clear();
        tail.clear();
        head.clear();
        lines.clear();
        pointInfo.clear();
        ter_stop = 0;
        count_stop = 0;

        struct stat filestat;
        stat(file, &filestat);
        set_number_points(( int)(filestat.st_size / 80 + 1)); //80 bytes per line
#ifdef DEBUG
        printf("PDBReader::read_pdb(): try %4lu atoms first\n", get_number_points());
#endif

        FILE *fp = fopen(file, "r");
        if(!fp) {
                fprintf(stderr,"ERROR in PDBReader::read_pdb(): cannot open file %s\n",file);
                throw;
        }
        char s[200];
        size_t count = 0;

        while ((fgets(s, 200, fp) != NULL)) {
                lines.push_back(s);
                if ((strncmp(s, "ENDMDL", 6) == 0) && (ter_stop==0)){
                        ter_stop =1;
                        count_stop = count;
                }
                if (strncmp(s, "END", 6) == 0){
                        break;
                }
                //if ((strncmp(s, "TER", 3) == 0) && (ter_stop ==0)){
                        //if (count !=0) {ter_stop = 1;}
                        //count_stop = count;
                //}
                if (strncmp(s, "ATOM", 4) != 0) {
                        if (count == 0) {head.push_back(s);}
                        else {tail.push_back(s);}
                }
                else {
                        pWords.push_back(s);
                        atomName.push_back(pWords[count].substr(12,4));
                        residueName.push_back(pWords[count].substr(17,3));
                        chainId.push_back(pWords[count].substr(21,1));
                        elementSym.push_back(pWords[count].substr(76,2));

                        float x, y, z, tf;
                        int an, sn;
                        sscanf(&s[6], "%d", &an);
                        sscanf(&s[23], "%d %f %f %f %*f %f", &sn, &x, &y, &z, &tf);

                        if (count + 1 > get_number_points()) {
                                set_number_points(2 * (count + 1)); 
                        }   //makes sure point array is big enough

                        points[4 * count] = x;
                        points[4 * count + 1] = y;
                        points[4 * count + 2] = z;
                        points[4 * count + 3] = tf;
                        pointInfo.push_back(an);
                        pointInfo.push_back(sn);
                        count++;
                }
        }

        fclose(fp);
        set_number_points(count);
        return true;
}
void PDBReader::right_transform ( const Transform transform)

Does Transform*v as opposed to v*Transform (as in the transform function)

Parameters:
transforman EMAN2 Transform object

Definition at line 321 of file pdbreader.cpp.

References n, points, EMAN::Transform::transpose(), and v.

                                                          {
        for ( unsigned int i = 0; i < 4 * n; i += 4) {
                Transform s = transform.transpose();
                Vec3f v((float)points[i],(float)points[i+1],(float)points[i+2]);
                v= s*v;
                points[i]  =v[0];
                points[i+1]=v[1];
                points[i+2]=v[2];
        }
}
void PDBReader::save_to_pdb ( const char *  file) const

Saves all atom information into a pdb in the official format.

Parameters:
Thefile that you want the pdb info written to

Definition at line 281 of file pdbreader.cpp.

References lines, pointInfo, points, and pWords.

Referenced by makePointArray().

                                                  {
        FILE *fp = fopen(file, "w");
        int m = 0;
        for (size_t i =0; i< lines.size(); i++) {
                char liner [200];
                strcpy (liner, lines[i].c_str());
                if (strncmp(liner, "ATOM", 4) != 0) {
                        fprintf (fp, "%s", liner);
                }
                else {
                        string curr = pWords[m];
                        string mid, final;
                        mid = curr.substr(12, 10);
                        final = curr.substr(76,2);
                        char mid2 [12];
                        strcpy(mid2, mid.c_str());
                        char final2 [4];
                        strcpy(final2, final.c_str());
                        fprintf(fp, "ATOM  %5d %10s%4d    %8.3f%8.3f%8.3f  1.00%6.2f          %2s\n", pointInfo[2*m], mid2, pointInfo[2*m +1], points[4 * m], points[4 * m + 1], points[4 * m + 2], points[4*m + 3], final2);
                        m++;
                }
        }       
        fclose(fp);

}
void PDBReader::set_number_points ( size_t  nn)

Definition at line 109 of file pdbreader.cpp.

References n, nn(), and points.

Referenced by copy(), operator=(), and read_from_pdb().

{
        if (n != nn) {
                n = nn;
                points = (double *) realloc(points, 4 * n * sizeof(double));
        }
}
void PDBReader::set_points_array ( double *  p)

Allows the user to set the double array of points.

Parameters:
Adouble array of points

Definition at line 122 of file pdbreader.cpp.

References points.

{
        points = p;
}
void PDBReader::zero ( )

Definition at line 68 of file pdbreader.cpp.

References n, and points.

{
        memset((void *) points, 0, 4 * n * sizeof(double));
}

Member Data Documentation

vector<string> EMAN::PDBReader::atomName [private]

Definition at line 124 of file pdbreader.h.

Referenced by copy(), get_atomName(), get_x(), and read_from_pdb().

vector<string> EMAN::PDBReader::chainId [private]

Definition at line 126 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

Definition at line 133 of file pdbreader.h.

Referenced by get_x(), and read_from_pdb().

vector<string> EMAN::PDBReader::elementSym [private]

Definition at line 127 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

vector<string> EMAN::PDBReader::head [private]

Definition at line 129 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

vector<string> EMAN::PDBReader::lines [private]

Definition at line 130 of file pdbreader.h.

Referenced by copy(), read_from_pdb(), and save_to_pdb().

size_t EMAN::PDBReader::n [private]
vector<int> EMAN::PDBReader::pointInfo [private]

Definition at line 122 of file pdbreader.h.

Referenced by copy(), get_x(), read_from_pdb(), and save_to_pdb().

double* EMAN::PDBReader::points [private]
vector<string> EMAN::PDBReader::pWords [private]

Definition at line 123 of file pdbreader.h.

Referenced by copy(), read_from_pdb(), and save_to_pdb().

vector<string> EMAN::PDBReader::residueName [private]

Definition at line 125 of file pdbreader.h.

Referenced by copy(), get_resName(), and read_from_pdb().

vector<int> EMAN::PDBReader::resNum [private]

Definition at line 138 of file pdbreader.h.

Referenced by get_resNum(), and get_x().

vector<string> EMAN::PDBReader::tail [private]

Definition at line 128 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

Definition at line 132 of file pdbreader.h.

Referenced by PDBReader(), and read_from_pdb().

vector<float> EMAN::PDBReader::x [private]

Definition at line 135 of file pdbreader.h.

Referenced by get_x(), and read_from_pdb().

vector<float> EMAN::PDBReader::y [private]

Definition at line 136 of file pdbreader.h.

Referenced by get_x(), get_y(), and read_from_pdb().

vector<float> EMAN::PDBReader::z [private]

Definition at line 137 of file pdbreader.h.

Referenced by get_x(), get_z(), and read_from_pdb().


The documentation for this class was generated from the following files: