19 glDeleteVertexArrays(1, &_vao);
20 glDeleteBuffers(4, _vbo);
25 _textureSize = aoTextureSize;
33 void Loader::GenerateVAO() {
36 glDeleteVertexArrays(1, &_vao);
37 glDeleteBuffers(4, _vbo);
40 std::vector<glm::vec4> vertexPos = std::vector<glm::vec4>();
41 std::vector<glm::vec3> atomColors = std::vector<glm::vec3>();
42 std::vector<glm::vec3> atomChainColors = std::vector<glm::vec3>();
43 std::vector<glm::vec4> textureQuads = std::vector<glm::vec4>();
44 std::vector<GLfloat> atomRadius = std::vector<GLfloat>();
46 int numberOfAtoms = _atoms->size();
47 int numPatches = numberOfAtoms;
48 double patch_size = glm::floor(_textureSize / glm::ceil(glm::sqrt(
double(numPatches))));
49 double patch_min_x = 0;
50 double patch_min_y = 0;
54 for (
int i=0;i<numberOfAtoms;i++) {
59 atomChainColors.push_back(a->GetChainColor());
63 if ((patch_min_x+patch_size)>_textureSize) {
65 patch_min_y += patch_size;
67 textureQuads.push_back(glm::vec4(patch_min_x/_textureSize, patch_min_y/_textureSize, (patch_min_x+patch_size)/_textureSize, (patch_min_y+patch_size)/_textureSize));
68 patch_min_x += patch_size;
77 glGenVertexArrays(1, &_vao);
78 glGenBuffers(4, _vbo);
79 glBindVertexArray(_vao);
84 glBindBuffer(GL_ARRAY_BUFFER, _vbo[0]);
85 glBufferData(GL_ARRAY_BUFFER, numberOfAtoms*
sizeof(glm::vec4), &vertexPos[0], GL_STATIC_DRAW);
87 glEnableVertexAttribArray(0);
88 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
93 glBindBuffer(GL_ARRAY_BUFFER, _vbo[1]);
94 glBufferData(GL_ARRAY_BUFFER, numberOfAtoms*
sizeof(GLfloat), &atomRadius[0], GL_STATIC_DRAW);
96 glEnableVertexAttribArray(1);
97 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL);
103 glEnableVertexAttribArray(2);
104 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);
108 glBindBuffer(GL_ARRAY_BUFFER, _vbo[3]);
109 glBufferData(GL_ARRAY_BUFFER, numberOfAtoms*
sizeof(glm::vec4), &textureQuads[0], GL_STATIC_DRAW);
112 glEnableVertexAttribArray(3);
113 glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 0, NULL);
116 glBindBuffer(GL_ARRAY_BUFFER, 0);
117 glBindVertexArray(0);
127 return _atoms->size();
136 if ((colorMode < 0) || (colorMode > 3))
139 _colorMode = colorMode;
144 std::vector<glm::vec3> colors = std::vector<glm::vec3>();
147 for (
int i=0;i<_atoms->size();i++) {
148 colors.push_back(_atoms->at(i)->GetColor());
150 }
else if (colorMode==1) {
151 for (
int i=0;i<_atoms->size();i++) {
152 colors.push_back(_atoms->at(i)->GetChainColor());
155 for (
int i=0;i<_atoms->size();i++) {
156 colors.push_back(glm::vec3(1.0f,1.0f,1.0f));
161 if (!_loadingMolecule)
162 glBindVertexArray(_vao);
164 glBindBuffer(GL_ARRAY_BUFFER, _vbo[2]);
165 glBufferData(GL_ARRAY_BUFFER, _atoms->size()*
sizeof(glm::vec3), &colors[0], GL_STATIC_DRAW);
167 if (!_loadingMolecule)
168 glBindVertexArray(0);
177 in.open(absolutePathToFile);
183 _atoms =
new std::vector<Atom *>();
192 std::stringstream stream;
198 std::getline(in, line);
203 std::string type = line.substr(0, 6);
205 if ((type.compare(
"ATOM ")==0) || (type.compare(
"HETATM")==0))
210 stream.str(line.substr(30, 8));
215 stream.str(line.substr(38, 8));
220 stream.str(line.substr(46, 8));
225 stream.str(line.substr(12, 4));
229 if (name.compare(
"")==0)
232 stream.str(line.substr(21, 1));
237 glm::vec3 chainColor;
239 if ( _chainColors.find(chainID) == _chainColors.end() ) {
241 if (_numChains>=_availableChainColors.size()) {
242 tempColor = glm::vec3(rand() % 255,rand() % 255, rand() % 255);
244 tempColor = _availableChainColors.at(_numChains);
246 _chainColors[chainID] = tempColor;
250 chainColor = _chainColors[chainID];
252 glm::vec3 color = _colors[name];
254 if (color.x == 0 && color.y == 0 && color.z == 0) {
255 color = glm::vec3(255.0f,255.0,255.0f);
257 color.x = color.x/255.0f;
258 color.y = color.y/255.0f;
259 color.z = color.z/255.0f;
260 chainColor.x = chainColor.x/255.0f;
261 chainColor.y = chainColor.y/255.0f;
262 chainColor.z = chainColor.z/255.0f;
265 float radius = _radius[name];
277 Atom * atom =
new Atom(x,y,z,color,chainColor,radius);
278 _atoms->push_back(atom);
289 float x_extent = (max_x + min_x)/2;
290 float y_extent = (max_y + min_y)/2;
291 float z_extent = (max_z + min_z)/2;
293 for (
int i=0;i<_atoms->size();i++) {
294 _atoms->at(i)->MovePosition(-x_extent,-y_extent,-z_extent);
296 x_extent = max_x - x_extent;
297 y_extent = max_y - y_extent;
298 z_extent = max_z - z_extent;
301 float max_radius = 2;
302 _bounding_sphere = sqrt(pow(x_extent,2) + pow(y_extent,2) + pow(z_extent,2)) + 2*max_radius;
318 void Loader::initParams() {
320 _availableChainColors.push_back(glm::vec3(0.0f,128.0f,255.0f));
321 _availableChainColors.push_back(glm::vec3(255.0f,128.0f,128.0f));
322 _availableChainColors.push_back(glm::vec3(0.0f,128.0f,0.0f));
323 _availableChainColors.push_back(glm::vec3(255.0f,255.0f,0.0f));
324 _availableChainColors.push_back(glm::vec3(128.0f,0.0f,128.0f));
325 _availableChainColors.push_back(glm::vec3(255.0f,0.0f,0.0f));
326 _availableChainColors.push_back(glm::vec3(255.0f,128.0f,0.0f));
327 _availableChainColors.push_back(glm::vec3(128.0f,255.0f,0.0f));
328 _availableChainColors.push_back(glm::vec3(0.0f,255.0f,255.0f));
330 _availableChainColors.push_back(glm::vec3(0.0f,0.0f,128.0f));
331 _availableChainColors.push_back(glm::vec3(255.0f,128.0f,128.0f));
332 _availableChainColors.push_back(glm::vec3(64.0f,128.0f,255.0f));
333 _availableChainColors.push_back(glm::vec3(255.0f,128.0f,64.0f));
334 _availableChainColors.push_back(glm::vec3(64.0f,0.0f,64.0f));
335 _availableChainColors.push_back(glm::vec3(32.0f,255.0f,32.0f));
346 _radius[
"CL"]= 1.89f;
348 _radius[
"H"]= 1.100f;
349 _radius[
"C"]= 1.548f;
350 _radius[
"N"]= 1.400f;
351 _radius[
"O"]= 1.348f;
352 _radius[
"P"]= 1.880f;
353 _radius[
"S"]= 1.808f;
354 _radius[
"CA"]= 1.948f;
355 _radius[
"FE"]= 1.948f;
356 _radius[
"ZN"]= 1.148f;
357 _radius[
"CD"]= 1.748f;
358 _radius[
"I"]= 1.748f;
360 _colors[
"H"] = glm::vec3(255.0f,255.0f,255.0f);
361 _colors[
"HE"]= glm::vec3(217.0f,255.0f,255.0f);
362 _colors[
"LI"]= glm::vec3(204.0f,128.0f,255.0f);
363 _colors[
"BE"]= glm::vec3(194.0f,255.0f, 0.0f);
364 _colors[
"B"] = glm::vec3(255.0f,181.0f,181.0f);
365 _colors[
"C"] = glm::vec3(144.0f,144.0f,144.0f);
366 _colors[
"N"] = glm::vec3( 48.0f, 80.0f,248.0f);
367 _colors[
"O"] = glm::vec3(255.0f, 13.0f, 13.0f);
368 _colors[
"F"] = glm::vec3(144.0f,224.0f, 80.0f);
369 _colors[
"NE"]= glm::vec3(179.0f,227.0f,245.0f);
370 _colors[
"NA"]= glm::vec3(171.0f, 92.0f,242.0f);
371 _colors[
"MG"]= glm::vec3(138.0f,255.0f, 0.0f);
372 _colors[
"AL"]= glm::vec3(191.0f,166.0f,166.0f);
373 _colors[
"SI"]= glm::vec3(240.0f,200.0f,160.0f);
374 _colors[
"P"] = glm::vec3(255.0f,128.0f, 0.0f);
375 _colors[
"S"] = glm::vec3(255.0f,255.0f, 48.0f);
376 _colors[
"CL"]= glm::vec3( 31.0f,240.0f, 31.0f);
377 _colors[
"AR"]= glm::vec3(128.0f,209.0f,227.0f);
378 _colors[
"K"] = glm::vec3(143.0f, 64.0f,212.0f);
379 _colors[
"CA"]= glm::vec3( 61.0f,255.0f, 0.0f);
380 _colors[
"SC"]= glm::vec3(230.0f,230.0f,230.0f);
381 _colors[
"TI"]= glm::vec3(191.0f,194.0f,199.0f);
382 _colors[
"V"] = glm::vec3(166.0f,166.0f,171.0f);
383 _colors[
"CR"]= glm::vec3(138.0f,153.0f,199.0f);
384 _colors[
"MN"]= glm::vec3(156.0f,122.0f,199.0f);
385 _colors[
"FE"]= glm::vec3(224.0f,102.0f, 51.0f);
386 _colors[
"CO"]= glm::vec3(240.0f,144.0f,160.0f);
387 _colors[
"NI"]= glm::vec3( 80.0f,208.0f, 80.0f);
388 _colors[
"CU"]= glm::vec3(200.0f,128.0f, 51.0f);
389 _colors[
"ZN"]= glm::vec3(125.0f,128.0f,176.0f);
390 _colors[
"GA"]= glm::vec3(194.0f,143.0f,143.0f);
391 _colors[
"GE"]= glm::vec3(102.0f,143.0f,143.0f);
392 _colors[
"AS"]= glm::vec3(189.0f,128.0f,227.0f);
393 _colors[
"SE"]= glm::vec3(255.0f,161.0f, 0.0f);
394 _colors[
"BR"]= glm::vec3(166.0f, 41.0f, 41.0f);
395 _colors[
"KR"]= glm::vec3( 92.0f,184.0f,209.0f);
396 _colors[
"RB"]= glm::vec3(112.0f, 46.0f,176.0f);
397 _colors[
"SR"]= glm::vec3( 0.0f,255.0f, 0.0f);
398 _colors[
"Y"] = glm::vec3(148.0f,255.0f,255.0f);
399 _colors[
"ZR"]= glm::vec3(148.0f,224.0f,224.0f);
400 _colors[
"NB"]= glm::vec3(115.0f,194.0f,201.0f);
401 _colors[
"MO"]= glm::vec3( 84.0f,181.0f,181.0f);
402 _colors[
"TC"]= glm::vec3( 59.0f,158.0f,158.0f);
403 _colors[
"RU"]= glm::vec3( 36.0f,143.0f,143.0f);
404 _colors[
"RH"]= glm::vec3( 10.0f,125.0f,140.0f);
405 _colors[
"PD"]= glm::vec3( 0.0f,105.0f,133.0f);
406 _colors[
"AG"]= glm::vec3(192.0f,192.0f,192.0f);
407 _colors[
"CD"]= glm::vec3(255.0f,217.0f,143.0f);
408 _colors[
"IN"]= glm::vec3(166.0f,117.0f,115.0f);
409 _colors[
"SN"]= glm::vec3(102.0f,128.0f,128.0f);
410 _colors[
"SB"]= glm::vec3(158.0f, 99.0f,181.0f);
411 _colors[
"TE"]= glm::vec3(212.0f,122.0f, 0.0f);
412 _colors[
"I"] = glm::vec3(148.0f, 0.0f,148.0f);
413 _colors[
"XE"]= glm::vec3( 66.0f,158.0f,176.0f);
414 _colors[
"CS"]= glm::vec3( 87.0f, 23.0f,143.0f);
415 _colors[
"BA"]= glm::vec3( 0.0f,201.0f, 0.0f);
416 _colors[
"LA"]= glm::vec3(112.0f,212.0f,255.0f);
417 _colors[
"CE"]= glm::vec3(255.0f,255.0f,199.0f);
418 _colors[
"PR"]= glm::vec3(217.0f,255.0f,199.0f);
419 _colors[
"ND"]= glm::vec3(199.0f,255.0f,199.0f);
420 _colors[
"PM"]= glm::vec3(163.0f,255.0f,199.0f);
421 _colors[
"SM"]= glm::vec3(143.0f,255.0f,199.0f);
422 _colors[
"EU"]= glm::vec3( 97.0f,255.0f,199.0f);
423 _colors[
"GD"]= glm::vec3( 69.0f,255.0f,199.0f);
424 _colors[
"TB"]= glm::vec3( 48.0f,255.0f,199.0f);
425 _colors[
"DY"]= glm::vec3( 31.0f,255.0f,199.0f);
426 _colors[
"HO"]= glm::vec3( 0.0f,255.0f,156.0f);
427 _colors[
"ER"]= glm::vec3( 0.0f,230.0f,117.0f);
428 _colors[
"TM"]= glm::vec3( 0.0f,212.0f, 82.0f);
429 _colors[
"YB"]= glm::vec3( 0.0f,191.0f, 56.0f);
430 _colors[
"LU"]= glm::vec3( 0.0f,171.0f, 36.0f);
431 _colors[
"HF"]= glm::vec3( 77.0f,194.0f,255.0f);
432 _colors[
"TA"]= glm::vec3( 77.0f,166.0f,255.0f);
433 _colors[
"W"] = glm::vec3( 33.0f,148.0f,214.0f);
434 _colors[
"RE"]= glm::vec3( 38.0f,125.0f,171.0f);
435 _colors[
"OS"]= glm::vec3( 38.0f,102.0f,150.0f);
436 _colors[
"IR"]= glm::vec3( 23.0f, 84.0f,135.0f);
437 _colors[
"PT"]= glm::vec3(208.0f,208.0f,224.0f);
438 _colors[
"AU"]= glm::vec3(255.0f,209.0f, 35.0f);
439 _colors[
"HG"]= glm::vec3(184.0f,184.0f,208.0f);
440 _colors[
"TL"]= glm::vec3(166.0f, 84.0f, 77.0f);
441 _colors[
"PB"]= glm::vec3( 87.0f, 89.0f, 97.0f);
442 _colors[
"BI"]= glm::vec3(158.0f, 79.0f,181.0f);
443 _colors[
"PO"]= glm::vec3(171.0f, 92.0f, 0.0f);
444 _colors[
"AT"]= glm::vec3(117.0f, 79.0f, 69.0f);
445 _colors[
"RN"]= glm::vec3( 66.0f,130.0f,150.0f);
446 _colors[
"FR"]= glm::vec3( 66.0f, 0.0f,102.0f);
447 _colors[
"RA"]= glm::vec3( 0.0f,125.0f, 0.0f);
448 _colors[
"AC"]= glm::vec3(112.0f,171.0f,250.0f);
449 _colors[
"TH"]= glm::vec3( 0.0f,186.0f,255.0f);
450 _colors[
"PA"]= glm::vec3( 0.0f,161.0f,255.0f);
451 _colors[
"U"] = glm::vec3( 0.0f,143.0f,255.0f);
452 _colors[
"NP"]= glm::vec3( 0.0f,128.0f,255.0f);
453 _colors[
"PU"]= glm::vec3( 0.0f,107.0f,255.0f);
454 _colors[
"AM"]= glm::vec3( 84.0f, 92.0f,242.0f);
455 _colors[
"CM"]= glm::vec3(120.0f, 92.0f,227.0f);
456 _colors[
"BK"]= glm::vec3(138.0f, 79.0f,227.0f);
457 _colors[
"CF"]= glm::vec3(161.0f, 54.0f,212.0f);
458 _colors[
"ES"]= glm::vec3(179.0f, 31.0f,212.0f);
459 _colors[
"FM"]= glm::vec3(179.0f, 31.0f,186.0f);
460 _colors[
"MD"]= glm::vec3(179.0f, 13.0f,166.0f);
461 _colors[
"NO"]= glm::vec3(189.0f, 13.0f,135.0f);
462 _colors[
"LR"]= glm::vec3(199.0f, 0.0f,102.0f);
463 _colors[
"RF"]= glm::vec3(204.0f, 0.0f, 89.0f);
464 _colors[
"DB"]= glm::vec3(209.0f, 0.0f, 79.0f);
465 _colors[
"SG"]= glm::vec3(217.0f, 0.0f, 69.0f);
466 _colors[
"BH"]= glm::vec3(224.0f, 0.0f, 56.0f);
467 _colors[
"HS"]= glm::vec3(230.0f, 0.0f, 46.0f);
468 _colors[
"MT"]= glm::vec3(235.0f, 0.0f, 38.0f);
473 return _bounding_sphere;