Accept xyz with extra info

Add fixed atoms option
Fix atomic bonds
parent 9b6a6fcd
......@@ -19,6 +19,8 @@ float userpos[3];
float BACKGROUND[3];
int* numAtoms; //[timesteps]
float **atoms; //[timesteps][numAtoms[i]*4] //xyzu, u=atom number
bool fixedAtoms;
float atomScaling;
std::vector<float> *clonedAtoms;
std::vector<int> bonds;
......@@ -129,6 +131,7 @@ int loadConfigFile(const char * f)
numAtoms=0;
atomScaling=1;
clonedAtoms=0;
fixedAtoms=false;
bonds.clear();
showTrajectories = false;
basisvectorreps=0;
......@@ -262,7 +265,7 @@ int loadConfigFile(const char * f)
r=readString(F, s);
if (r!=0)
return -14;
int timesteps;
int timesteps=TIMESTEPS;
char file[256];
sprintf(file, "%s%s", PATH, s);
fixFile(file);
......@@ -360,6 +363,8 @@ int loadConfigFile(const char * f)
r=readString (F, token);
if (r!=0)
return -16;
} else if (!strcmp (s, "fixedatoms")) {
fixedAtoms=true;
} else if (!strcmp (s, "\x0d")) { //discard windows newline (problem in Sebastian Kokott's phone (?!)
continue;
} else {
......
......@@ -15,6 +15,7 @@ extern float userpos[3];
extern float BACKGROUND[3];
extern int* numAtoms; //[timesteps]
extern float **atoms; //[timesteps][numAtoms[i]*4] //xyzu, u=atom number
extern bool fixedAtoms; //all timesteps use the atoms for timestep 0. Used for excitons etc.
extern float atomScaling;
extern std::vector<float> *clonedAtoms;
extern std::vector<int> bonds;
......
......@@ -43,11 +43,14 @@ bool grid::compare (float *a, float *b)
{
if (a<=b) //already returned when searching a beforehand
return false;
float sqd=atomRadius(a[3])+atomRadius(b[3]);
sqd*=sqd;
float d=0;
for (int i=0;i<3;i++)
d+=(a[i]-b[i])*(a[i]-b[i]);
if (d*scale < (a[3]+b[3]))
if (d*scale < sqd)
return true;
return false;
}
std::vector<float*> grid::find (float *p)
......@@ -66,9 +69,10 @@ std::vector<float*> grid::find (float *p)
}
coordinates(mp, mc);
coordinates(Mp, Mc);
for (int x=mc[0];x<Mc[0];x++)
for (int y=mc[1];y<Mc[1];y++)
for (int z=mc[2];z<Mc[2];z++) {
for (int x=mc[0];x<=Mc[0];x++)
for (int y=mc[1];y<=Mc[1];y++)
for (int z=mc[2];z<=Mc[2];z++) {
const int c=x*dims*dims + y*dims+z;
for (int i=0;i<content[c].size();i++) {
if (compare (content[c][i], p))
......
......@@ -176,7 +176,10 @@ GLenum PrepareGLiso (GLuint vao, GLuint vertbuffer, const std::vector<float> &ve
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vertbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertdata.size(), &vertdata[0], GL_STATIC_DRAW);
if (vertdata.size() !=0)
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertdata.size(), &vertdata[0], GL_STATIC_DRAW);
else
eprintf("Warning: Iso has no data");
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__);
......
......@@ -10,6 +10,7 @@
#include "eprintf.h"
#include "atoms.hpp"
#include "ConfigFile.h"
#include "rapidjson/document.h"
#include "rapidjson/filereadstream.h"
#include "happyhttp/happyhttp.h"
......@@ -226,7 +227,8 @@ int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float *
mynum.push_back(mynumatoms);
discardline (f); //comment
for (int i=0;i<mynumatoms;i++) {
r=fscanf (f, "%s %f %f %f", s, mypos.back()+4*i+0, mypos.back()+4*i+1,mypos.back()+4*i+2);
float unused;
r=fscanf (f, "%s %f %f %f %f", s, mypos.back()+4*i+0, mypos.back()+4*i+1,mypos.back()+4*i+2, &unused);
if (r<4)
return -2;
int a=findAtom(s);
......@@ -270,9 +272,14 @@ int readAtomsCube(const char *const file, int **numatoms, int *timesteps, float
eprintf ("Error opening file %s", file);
return -1;
}
*timesteps = 1;
*pos = new float*[*timesteps];
*numatoms = new int[*timesteps];
if (!fixedAtoms) {
*timesteps = 1;
*pos = new float*[*timesteps];
*numatoms = new int[*timesteps];
} else {
*pos = new float*[1];
*numatoms = new int[1];
}
discardline(f); //two comments
discardline(f);
......
......@@ -10,6 +10,14 @@
#include "polyhedron.h"
#include "Grid.h"
int getAtomTimesteps()
{
if (fixedAtoms)
return 1;
else
return TIMESTEPS;
}
GLenum atomTexture(GLuint t)
{
GLenum e;
......@@ -59,7 +67,7 @@ if (!solid) {
//xyz nxnynz u=atom type ; 7 floats
int e;
int totalatoms=numAtoms[TIMESTEPS-1];
int totalatoms=numAtoms[getAtomTimesteps() -1];
//eprintf ("SetupAtomsNoTess 2");
*AtomVAO = new GLuint[3]; //atoms, cloned atoms, bonds
......@@ -93,7 +101,7 @@ if (!solid) {
float *current=tmp;
//eprintf ("Before For 1");
for (int p=0;p<TIMESTEPS;p++) {
for (int p=0;p<getAtomTimesteps() ;p++) {
for (int a = 0; a < numAtoms[p]-(p==0?0:numAtoms[p-1]); a++) {
const int atomNumber = static_cast<int>(atoms[p][4 * a + 3]);
const float radius = atomRadius(atomNumber)*atomScaling;
......@@ -220,7 +228,7 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
int e;
int totalatoms=0;
for (int i=0;i<TIMESTEPS;i++) {
for (int i=0;i<getAtomTimesteps() ;i++) {
totalatoms += numAtoms[i];
}
eprintf("SetupAtoms: totalatoms=%d", totalatoms);
......@@ -248,8 +256,8 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
const int atomlimit=30;
numBonds=new int[TIMESTEPS];
for (int p=0;p<TIMESTEPS;p++) {
numBonds=new int[getAtomTimesteps() ];
for (int p=0;p<getAtomTimesteps() ;p++) {
for (int a = 0; a < numAtoms[p]; a++) {
for (int k = 0; k < 4; k++) {
......@@ -281,26 +289,26 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
float m[3];
float M[3];
for (int k=0; k<3;k++) {
m[k]=M[k]=tmp[k];
m[k]=M[k]=atoms[p][k];
}
for (int a = 1; a < numAtoms[p]; a++) {
for (int k=0; k<3;k++) {
if (m[k]>tmp[4*a+k])
m[k]=tmp[4*a+k];
if (M[k]<tmp[4*a+k])
M[k]=tmp[4*a+k];
if (m[k]>atoms[p][4*a+k])
m[k]=atoms[p][4*a+k];
if (M[k]<atoms[p][4*a+k])
M[k]=atoms[p][4*a+k];
}
}
grid g(m, M, pow(numAtoms[p], 1.0/3), 0.9f);
for (int a = 1; a < numAtoms[p]; a++)
g.add(tmp+4*a);
g.add(atoms[p]+4*a);
for (int a = 0; a < numAtoms[p]; a++) {
std::vector<float*> found=g.find(tmp+4*a);
std::vector<float*> found=g.find(atoms[p]+4*a);
for (int b=0;b<found.size();b++) {
//if (found[b] < tmp+4*a) // already got this bound
// continue;
bonds.push_back(a+(p==0?0:numAtoms[p-1]));
bonds.push_back(((found[b]-tmp)/4)+(p==0?0:numAtoms[p-1]));
bonds.push_back(((found[b]-atoms[p])/4)+(p==0?0:numAtoms[p-1]));
}
}
}
......@@ -335,7 +343,7 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
for (unsigned int t=0;t<atomtrajectories.size();t++) {
atomtrajectoryrestarts.push_back(std::vector<int>());
atomtrajectoryrestarts[t].push_back(0);
for (int p=1;p<TIMESTEPS;p++) {
for (int p=1;p<getAtomTimesteps() ;p++) {
int a=atomtrajectories[t];
if (has_abc)
if (fabs(atoms[p][a*4+0]-atoms[p-1][a*4+0])+
......@@ -343,7 +351,7 @@ GLenum SetupAtoms(GLuint **AtomVAO /*[3]*/, GLuint **AtomVertBuffer /*[2]*/, GLu
fabs(atoms[p][a*4+2]-atoms[p-1][a*4+2])>max)
atomtrajectoryrestarts[t].push_back(p);
}
atomtrajectoryrestarts[t].push_back(TIMESTEPS);
atomtrajectoryrestarts[t].push_back(getAtomTimesteps() );
}
}
delete[] tmp;
......
......@@ -14,5 +14,7 @@ bool PrepareAtomShaderNoTess (GLuint *AtomP, GLint *AtomMatrixLocation);
bool PrepareUnitCellShader (GLuint *cellP, GLint *UnitCellMatrixLocation, GLint *UnitCellColourLocation);
void GetDisplacement(int p[3], float f[3]);
int getAtomTimesteps();
#endif //__ATOMSGL_H
......@@ -839,7 +839,7 @@ void CMainApplication::Shutdown()
}
if (numAtoms!=0) {
for (int i=0;i<TIMESTEPS;i++) {
for (int i=0;i<getAtomTimesteps();i++) {
delete[] atoms[i];
}
delete[] atoms;
......@@ -2026,7 +2026,7 @@ glUniformMatrix4fv(m_nAtomMatrixLocation, 1, GL_FALSE, transform.get());
//glUniformMatrix4fv(m_nAtomMVLocation, 1, GL_FALSE, mv.get());
if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error 4 timestep =%d: %d, %s\n", currentset, e, gluErrorString(e));
if (currentset==0)
if (currentset==0 ||fixedAtoms)
glDrawArrays(GL_PATCHES, 0, numAtoms[0]);
else
glDrawArrays(GL_PATCHES, numAtoms[currentset-1], numAtoms[currentset]-numAtoms[currentset-1]);
......@@ -2035,7 +2035,7 @@ if ((e = glGetError()) != GL_NO_ERROR)
dprintf("Gl error after RenderAtoms timestep =%d: %d, %s\n", currentset, e, gluErrorString(e));
//now cloned atoms
if (numClonedAtoms!=0 && currentset==0) {
if (numClonedAtoms!=0 && (currentset==0||fixedAtoms)) {
glBindVertexArray(m_unAtomVAO[1]);
glDrawArrays(GL_PATCHES, 0, numClonedAtoms);
if ((e = glGetError()) != GL_NO_ERROR)
......@@ -2049,7 +2049,7 @@ if (numBonds) {
glUniformMatrix4fv(m_nUnitCellMatrixLocation, 1, GL_FALSE, transform.get());
float color[4]={0.5,0.5,1,1};
glUniform4fv(m_nUnitCellColourLocation, 1, color);
if (currentset==0)
if (currentset==0||fixedAtoms)
glDrawElements(GL_LINES, numBonds[0], GL_UNSIGNED_INT, (void*)0);
else
glDrawElements(GL_LINES, numBonds[currentset]-numBonds[currentset-1], GL_UNSIGNED_INT,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment