EMAN2
Public Types | Public Member Functions | Private Attributes | List of all members
EMAN::PDBReader Class Reference

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

#include <pdbreader.h>

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. More...
 
void save_to_pdb (const char *file) const
 Saves all atom information into a pdb in the official format. More...
 
double * get_points_array ()
 Returns the double array of points. More...
 
void set_points_array (double *p)
 Allows the user to set the double array of points. More...
 
vector< float > get_points ()
 Returns all x,y,z triplets packed into a vector<float> More...
 
void right_transform (const Transform &transform)
 Does Transform*v as opposed to v*Transform (as in the transform function) More...
 
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 54 of file pdbreader.h.

Member Enumeration Documentation

◆ Density2PointsArrayAlgorithm

Enumerator
PEAKS_SUB 
PEAKS_DIV 
KMEANS 

Definition at line 57 of file pdbreader.h.

Constructor & Destructor Documentation

◆ PDBReader() [1/2]

PDBReader::PDBReader ( )

Definition at line 42 of file pdbreader.cpp.

43{
44 points = 0;
45 n = 0;
46}
double * points
Definition: pdbreader.h:117

References n, and points.

Referenced by copy().

◆ PDBReader() [2/2]

PDBReader::PDBReader ( int  nn)
explicit

Definition at line 48 of file pdbreader.cpp.

49{
50 n = nn;
51 points = (double *) calloc(4 * n, sizeof(double));
52 ter_stop = 0;
53}

References n, points, and ter_stop.

◆ ~PDBReader()

PDBReader::~PDBReader ( )

Definition at line 55 of file pdbreader.cpp.

56{
57 if( points )
58 {
59 free(points);
60 points = 0;
61 }
62}

References points.

Member Function Documentation

◆ copy()

PDBReader * PDBReader::copy ( )

Definition at line 71 of file pdbreader.cpp.

72{
73 PDBReader *pa2 = new PDBReader();
75 double *pa2data = pa2->get_points_array();
76 memcpy(pa2data, get_points_array(), sizeof(double) * 4 * get_number_points());
77 pa2->pWords = pWords;
78 pa2->atomName = atomName;
80 pa2->chainId = chainId;
82 pa2->tail = tail;
83 pa2->head = head;
84 pa2->pointInfo = pointInfo;
85 pa2->lines = lines;
86 return pa2;
87}
PointArray defines a double array of points with values in a 3D space.
Definition: pdbreader.h:55
vector< string > elementSym
Definition: pdbreader.h:123
vector< string > chainId
Definition: pdbreader.h:122
vector< string > head
Definition: pdbreader.h:125
vector< string > lines
Definition: pdbreader.h:126
vector< string > pWords
Definition: pdbreader.h:119
vector< string > atomName
Definition: pdbreader.h:120
void set_number_points(size_t nn)
Definition: pdbreader.cpp:105
vector< string > tail
Definition: pdbreader.h:124
double * get_points_array()
Returns the double array of points.
Definition: pdbreader.cpp:113
vector< string > residueName
Definition: pdbreader.h:121
vector< int > pointInfo
Definition: pdbreader.h:118
size_t get_number_points() const
Definition: pdbreader.cpp:99

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

◆ get_atomName()

vector< string > PDBReader::get_atomName ( )

Definition at line 149 of file pdbreader.cpp.

149 {
150 return atomName;
151}

References atomName.

◆ get_number_points()

size_t PDBReader::get_number_points ( ) const

Definition at line 99 of file pdbreader.cpp.

100{
101 return n;
102}

References n.

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

◆ get_points()

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 308 of file pdbreader.cpp.

308 {
309vector<float> ret;
310for (unsigned int i=0; i<n; i++) {
311 ret.push_back((float)points[i*4]);
312 ret.push_back((float)points[i*4+1]);
313 ret.push_back((float)points[i*4+2]);
314}
315
316return ret;
317}

References n, and points.

◆ get_points_array()

double * PDBReader::get_points_array ( )

Returns the double array of points.

Returns
A double array of points

Definition at line 113 of file pdbreader.cpp.

114{
115 return points;
116}

References points.

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

◆ get_resName()

vector< string > PDBReader::get_resName ( )

Definition at line 153 of file pdbreader.cpp.

153 {
154 return residueName;
155}

References residueName.

◆ get_resNum()

vector< int > PDBReader::get_resNum ( )

Definition at line 157 of file pdbreader.cpp.

157 {
158 return resNum;
159}
vector< int > resNum
Definition: pdbreader.h:134

References resNum.

◆ get_x()

vector< float > PDBReader::get_x ( )

Definition at line 126 of file pdbreader.cpp.

126 {
127 if (count_stop == 0) {count_stop = atomName.size();}
128 for (int i=0; i<count_stop; i++) {
129 x.push_back((float)points[4*i]);
130 y.push_back((float)points[4*i + 1]);
131 z.push_back((float)points[4*i + 2]);
132 resNum.push_back(pointInfo[2*i+1]);
133 }
134
135 return x;
136}
vector< float > z
Definition: pdbreader.h:133
vector< float > x
Definition: pdbreader.h:131
vector< float > y
Definition: pdbreader.h:132

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

◆ get_y()

vector< float > PDBReader::get_y ( )

Definition at line 139 of file pdbreader.cpp.

139 {
140 //cout << y.size() << endl;
141 return y;
142}

References y.

◆ get_z()

vector< float > PDBReader::get_z ( )

Definition at line 145 of file pdbreader.cpp.

145 {
146 return z;
147}

References z.

◆ makePointArray()

PointArray * PDBReader::makePointArray ( const PDBReader p)

Definition at line 331 of file pdbreader.cpp.

331 {
332 PointArray* pArray = new PointArray;
333 p.save_to_pdb("thisFile3.txt");
334 pArray->read_from_pdb("thisFile3.txt");
335 remove("thisFile3.txt");
336
337 return pArray;
338}
void save_to_pdb(const char *file) const
Saves all atom information into a pdb in the official format.
Definition: pdbreader.cpp:280
PointArray defines a double array of points with values in a 3D space.
Definition: pointarray.h:52
bool read_from_pdb(const char *file, const vector< int > &lines=vector< int >())
Definition: pointarray.cpp:329

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

◆ operator=()

PDBReader & PDBReader::operator= ( PDBReader pa)

Definition at line 90 of file pdbreader.cpp.

91{
92 if (this != &pa) {
94 memcpy(get_points_array(), pa.get_points_array(), sizeof(double) * 4 * get_number_points());
95 }
96 return *this;
97}

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

◆ read_from_pdb()

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 163 of file pdbreader.cpp.

164{
165
166 pWords.clear();
167 atomName.clear();
168 residueName.clear();
169 chainId.clear();
170 elementSym.clear();
171 tail.clear();
172 head.clear();
173 lines.clear();
174 pointInfo.clear();
175 ter_stop = 0;
176 count_stop = 0;
177
178 struct stat filestat;
179 stat(file, &filestat);
180 set_number_points(( int)(filestat.st_size / 80 + 1)); //80 bytes per line
181#ifdef DEBUG
182 printf("PDBReader::read_pdb(): try %4lu atoms first\n", get_number_points());
183#endif
184
185 FILE *fp = fopen(file, "r");
186 if(!fp) {
187 fprintf(stderr,"ERROR in PDBReader::read_pdb(): cannot open file %s\n",file);
188 throw;
189 }
190 char s[200];
191 size_t count = 0;
192
193 while ((fgets(s, 200, fp) != NULL)) {
194 lines.push_back(s);
195 if ((strncmp(s, "ENDMDL", 6) == 0) && (ter_stop==0)){
196 ter_stop =1;
197 count_stop = count;
198 }
199 if (strncmp(s, "END", 6) == 0){
200 break;
201 }
202 //if ((strncmp(s, "TER", 3) == 0) && (ter_stop ==0)){
203 //if (count !=0) {ter_stop = 1;}
204 //count_stop = count;
205 //}
206 if (strncmp(s, "ATOM", 4) != 0) {
207 if (count == 0) {head.push_back(s);}
208 else {tail.push_back(s);}
209 }
210 else {
211 pWords.push_back(s);
212 atomName.push_back(pWords[count].substr(12,4));
213 residueName.push_back(pWords[count].substr(17,3));
214 chainId.push_back(pWords[count].substr(21,1));
215 if (pWords[count].size()>78)
216 elementSym.push_back(pWords[count].substr(76,2));
217 else
218 elementSym.push_back(string("Null"));
219
220 float x, y, z, tf;
221 int an, sn;
222 sscanf(&s[6], "%d", &an);
223 sscanf(&s[23], "%d %f %f %f %*f %f", &sn, &x, &y, &z, &tf);
224
225 if (count + 1 > get_number_points()) {
226 set_number_points(2 * (count + 1));
227 } //makes sure point array is big enough
228
229 points[4 * count] = x;
230 points[4 * count + 1] = y;
231 points[4 * count + 2] = z;
232 points[4 * count + 3] = tf;
233 pointInfo.push_back(an);
234 pointInfo.push_back(sn);
235 count++;
236 }
237 }
238
239 fclose(fp);
240 set_number_points(count);
241 return true;
242}

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

◆ right_transform()

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 320 of file pdbreader.cpp.

320 {
321 for ( unsigned int i = 0; i < 4 * n; i += 4) {
322 Transform s = transform.transpose();
323 Vec3f v((float)points[i],(float)points[i+1],(float)points[i+2]);
324 v= s*v;
325 points[i] =v[0];
326 points[i+1]=v[1];
327 points[i+2]=v[2];
328 }
329}
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
Transform transpose() const
Get the transpose of this transformation matrix.
Definition: transform.cpp:1346

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

◆ save_to_pdb()

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 280 of file pdbreader.cpp.

280 {
281 FILE *fp = fopen(file, "w");
282 int m = 0;
283 for (size_t i =0; i< lines.size(); i++) {
284 char liner [200];
285 strcpy (liner, lines[i].c_str());
286 if (strncmp(liner, "ATOM", 4) != 0) {
287 fprintf (fp, "%s", liner);
288 }
289 else {
290 string curr = pWords[m];
291 string mid, final;
292 mid = curr.substr(12, 10);
293 final = curr.substr(76,2);
294 char mid2 [12];
295 strcpy(mid2, mid.c_str());
296 char final2 [4];
297 strcpy(final2, final.c_str());
298 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);
299 m++;
300 }
301 }
302 fclose(fp);
303
304}

References lines, pointInfo, points, and pWords.

Referenced by makePointArray().

◆ set_number_points()

void PDBReader::set_number_points ( size_t  nn)

Definition at line 105 of file pdbreader.cpp.

106{
107 if (n != nn) {
108 n = nn;
109 points = (double *) realloc(points, 4 * n * sizeof(double));
110 }
111}

References n, and points.

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

◆ set_points_array()

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 118 of file pdbreader.cpp.

119{
120 points = p;
121}

References points.

◆ zero()

void PDBReader::zero ( )

Definition at line 64 of file pdbreader.cpp.

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

References n, and points.

Member Data Documentation

◆ atomName

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

Definition at line 120 of file pdbreader.h.

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

◆ chainId

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

Definition at line 122 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

◆ count_stop

int EMAN::PDBReader::count_stop
private

Definition at line 129 of file pdbreader.h.

Referenced by get_x(), and read_from_pdb().

◆ elementSym

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

Definition at line 123 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

◆ head

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

Definition at line 125 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

◆ lines

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

Definition at line 126 of file pdbreader.h.

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

◆ n

size_t EMAN::PDBReader::n
private

◆ pointInfo

vector<int> EMAN::PDBReader::pointInfo
private

Definition at line 118 of file pdbreader.h.

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

◆ points

double* EMAN::PDBReader::points
private

◆ pWords

vector<string> EMAN::PDBReader::pWords
private

Definition at line 119 of file pdbreader.h.

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

◆ residueName

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

Definition at line 121 of file pdbreader.h.

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

◆ resNum

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

Definition at line 134 of file pdbreader.h.

Referenced by get_resNum(), and get_x().

◆ tail

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

Definition at line 124 of file pdbreader.h.

Referenced by copy(), and read_from_pdb().

◆ ter_stop

int EMAN::PDBReader::ter_stop
private

Definition at line 128 of file pdbreader.h.

Referenced by PDBReader(), and read_from_pdb().

◆ x

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

Definition at line 131 of file pdbreader.h.

Referenced by get_x(), and read_from_pdb().

◆ y

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

Definition at line 132 of file pdbreader.h.

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

◆ z

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

Definition at line 133 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: