Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
VR-demos
Commits
99c5d0b0
Commit
99c5d0b0
authored
Apr 03, 2017
by
Ruben Jesus Garcia Hernandez
Browse files
Removed files which are now in the nomad vr lib
parent
15f4da94
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
OculusMobile/readme.md
0 → 100644
View file @
99c5d0b0
This repository contains the demos for GearVR using Oculus Mobile version 1.0.0.0
https://developer3.oculus.com/documentation/mobilesdk/latest/
Clone that repository and add the content of this one inside the VrSamples
\N
ative directory.
Copy the content of the ../libs directory (rply, happyhttp, rapidjson) into NOMADGearvrT
\S
rc
List of directories
NOMADGearvrT:
This program can load prepared molecular dynamics simulations, and is
compatible with the TimestepData OpenVR demo.
Ply support is not yet implemented
\ No newline at end of file
OpenVR/TimestepData/TessShaders.cpp
deleted
100644 → 0
View file @
15f4da94
#include "TessShaders.h"
/*rgh: for now default tesselation control, using
glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, {3,3,3,3});
glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL, {3,3});
*/
const
char
*
const
AtomShaders
[]
=
{
"Atom Renderer"
,
// vertex shader
"#version 410
\n
"
"uniform sampler2D atomData;
\n
"
"layout(location = 0) in vec3 center;
\n
"
"layout(location = 1) in float atomIn;
\n
"
"out vec4 vcolor;
\n
"
//color , radius
"out vec3 vcen;"
"void main()
\n
"
"{
\n
"
//"gl_Position = matrix * vec4(position+center, 1);\n"
"float coord=atomIn/118.0+0.5/118.0;
\n
"
"vcolor=vec4(texture(atomData, vec2(coord, 0)));
\n
"
"vcen=center;
\n
"
//"color.a=1;\n"
"}
\n
"
,
//fragment shader
"#version 410 core
\n
"
"in vec4 color;
\n
"
"in vec3 vertex;"
"in vec3 normal;"
"out vec4 outputColor;
\n
"
"void main()
\n
"
"{
\n
"
//"vec3 U = dFdx(vertex); "
//"vec3 V = dFdy(vertex); "
"vec3 nn = normalize(normal);"
//"vec3 nn = normalize(cross(U,V));"
"lowp float a=abs(dot(nn, vec3(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0)));
\n
"
"lowp float b=max(0.0, dot(nn, vec3(0,0,1)));
\n
"
"highp vec4 res=color;
\n
"
" outputColor = vec4 ((res.rgb) * (0.1 + 0.2*a), color.a);
\n
"
"}
\n
"
,
//tess eval
"#version 400
\n
"
//"layout(triangles, equal_spacing, cw) in;\n"
"layout(quads, equal_spacing, cw) in;
\n
"
"#define pi 3.1415926535897932384626433832795
\n
"
"uniform mat4 matrix;
\n
"
//"uniform mat4 mv;\n"
"in vec4 vcolor[];
\n
"
//color , radius
"in vec3 vcen[];"
"out vec4 color;
\n
"
//color
"out vec3 normal;
\n
"
"out vec3 vertex;"
"uniform mat4 Projection;
\n
"
"uniform mat4 Modelview;
\n
"
"void main()
\n
"
"{
\n
"
"normal=vec3(sin(gl_TessCoord.x*2*pi)*cos((gl_TessCoord.y-0.5)*pi), "
"cos(gl_TessCoord.x*2*pi)*cos((gl_TessCoord.y-0.5)*pi), "
"sin((gl_TessCoord.y-0.5)*pi));"
" vertex = normal * vcolor[0].w + vcen[0];
\n
"
"color=vec4(vcolor[0].xyz, 1);"
"gl_Position = matrix * vec4(vertex, 1);
\n
"
"}
\n
"
};
\ No newline at end of file
OpenVR/TimestepData/TessShaders.h
deleted
100644 → 0
View file @
15f4da94
#define SHADERNAME 0
#define SHADERVERTEX 1
#define SHADERFRAGMENT 2
#define SHADERTESSEVAL 3
extern
const
char
*
const
AtomShaders
[];
\ No newline at end of file
OpenVR/TimestepData/UnitCellShaders.cpp
deleted
100644 → 0
View file @
15f4da94
#include "UnitCellShaders.h"
const
char
*
const
UnitCellShaders
[]
=
{
"Unit Cell Renderer"
,
//vertex
"#version 410
\n
"
"uniform mat4 matrix;
\n
"
"layout(location = 0) in vec3 pos;
\n
"
"void main()
\n
"
"{
\n
"
"gl_Position = matrix * vec4(pos, 1);
\n
"
"}
\n
"
,
//fragment
"#version 410 core
\n
"
"uniform vec4 color;
\n
"
"out vec4 outputColor;
\n
"
"void main()
\n
"
"{
\n
"
" outputColor = color;
\n
"
"}
\n
"
,
//tess
nullptr
};
OpenVR/TimestepData/UnitCellShaders.h
deleted
100644 → 0
View file @
15f4da94
extern
const
char
*
const
UnitCellShaders
[];
\ No newline at end of file
OpenVR/TimestepData/atoms.cpp
deleted
100644 → 0
View file @
15f4da94
#define NOMINMAX
#include <stdio.h>
#include <string.h>
#include <vector>
#include <winsock2.h>
#include "atoms.hpp"
#include "rapidjson/document.h"
#include "rapidjson/filereadstream.h"
#include "happyhttp.h"
const
char
*
const
atomNames
[]
=
{
"H"
,
"He"
,
"Li"
,
"Be"
,
"B"
,
"C"
,
"N"
,
"O"
,
"F"
,
"Ne"
,
"Na"
,
"Mg"
,
"Al"
,
"Si"
,
"P"
,
"S"
,
"Cl"
,
"Ar"
,
"K"
,
"Ca"
,
"Sc"
,
"Ti"
,
"V"
,
"Cr"
,
"Mn"
,
"Fe"
,
"Co"
,
"Ni"
,
"Cu"
,
"Zn"
,
"Ga"
,
"Ge"
,
"As"
,
"Se"
,
"Br"
,
"Kr"
,
"Rb"
,
"Sr"
,
"Y"
,
"Zr"
,
"Nb"
,
"Mo"
,
"Tc"
,
"Ru"
,
"Rh"
,
"Pd"
,
"Ag"
,
"Cd"
,
"In"
,
"Sn"
,
"Sb"
,
"Te"
,
"I"
,
"Xe"
,
"Cs"
,
"Ba"
,
"La"
,
"Ce"
,
"Pr"
,
"Nd"
,
"Pm"
,
"Sm"
,
"Eu"
,
"Gd"
,
"Tb"
,
"Dy"
,
"Ho"
,
"Er"
,
"Tm"
,
"Yb"
,
"Lu"
,
"Hf"
,
"Ta"
,
"W"
,
"Re"
,
"Os"
,
"Ir"
,
"Pt"
,
"Au"
,
"Hg"
,
"Tl"
,
"Pb"
,
"Bi"
,
"Po"
,
"At"
,
"Rn"
,
"Fr"
,
"Ra"
,
"Ac"
,
"Th"
,
"Pa"
,
"U"
,
"Np"
,
"Pu"
,
"Am"
,
"Cm"
,
"Bk"
,
"Cf"
,
"Es"
,
"Fm"
,
"Md"
,
"No"
,
"Lr"
,
"Rf"
,
"Ha"
,
"Sg"
,
"Ns"
,
"Hs"
,
"Mt"
,
"Ds"
,
"Rg"
,
"Cn"
,
"Nh"
,
"Fl"
,
"Mc"
,
"Lv"
,
"Ts"
,
"Og"
};
//rgb radius for easy transfer to texture. In AAngstrom
//not const as users may want to scale the radius
float
atomColours
[][
4
]
=
{
{
1.000000
f
,
1.000000
f
,
1.000000
f
,
0.310000
f
},
//H
{
0.851000
f
,
1.000000
f
,
1.000000
f
,
0.280000
f
},
//He
{
0.800000
f
,
0.502000
f
,
1.000000
f
,
1.280000
f
},
//Li
{
0.761000
f
,
1.000000
f
,
0.000000
f
,
0.960000
f
},
//Be
{
1.000000
f
,
0.710000
f
,
0.710000
f
,
0.840000
f
},
//B
{
0.565000
f
,
0.565000
f
,
0.565000
f
,
0.760000
f
},
//C
{
0.188000
f
,
0.314000
f
,
0.973000
f
,
0.710000
f
},
//N
{
1.000000
f
,
0.051000
f
,
0.051000
f
,
0.660000
f
},
//O
{
0.565000
f
,
0.878000
f
,
0.314000
f
,
0.570000
f
},
//F
{
0.702000
f
,
0.890000
f
,
0.961000
f
,
0.580000
f
},
//Ne
{
0.671000
f
,
0.361000
f
,
0.949000
f
,
1.660000
f
},
//Na
{
0.541000
f
,
1.000000
f
,
0.000000
f
,
1.410000
f
},
//Mg
{
0.749000
f
,
0.651000
f
,
0.651000
f
,
1.210000
f
},
//Al
{
0.941000
f
,
0.784000
f
,
0.627000
f
,
1.110000
f
},
//Si
{
1.000000
f
,
0.502000
f
,
0.000000
f
,
1.070000
f
},
//P
{
1.000000
f
,
1.000000
f
,
0.188000
f
,
1.050000
f
},
//S
{
0.122000
f
,
0.941000
f
,
0.122000
f
,
1.020000
f
},
//Cl
{
0.502000
f
,
0.820000
f
,
0.890000
f
,
1.060000
f
},
//Ar
{
0.561000
f
,
0.251000
f
,
0.831000
f
,
2.030000
f
},
//K
{
0.239000
f
,
1.000000
f
,
0.000000
f
,
1.760000
f
},
//Ca
{
0.902000
f
,
0.902000
f
,
0.902000
f
,
1.700000
f
},
//Sc
{
0.749000
f
,
0.761000
f
,
0.780000
f
,
1.600000
f
},
//Ti
{
0.651000
f
,
0.651000
f
,
0.671000
f
,
1.530000
f
},
//V
{
0.541000
f
,
0.600000
f
,
0.780000
f
,
1.390000
f
},
//Cr
{
0.612000
f
,
0.478000
f
,
0.780000
f
,
1.390000
f
},
//Mn
{
0.878000
f
,
0.400000
f
,
0.200000
f
,
1.320000
f
},
//Fe
{
0.941000
f
,
0.565000
f
,
0.627000
f
,
1.260000
f
},
//Co
{
0.314000
f
,
0.816000
f
,
0.314000
f
,
1.240000
f
},
//Ni
{
0.784000
f
,
0.502000
f
,
0.200000
f
,
1.320000
f
},
//Cu
{
0.490000
f
,
0.502000
f
,
0.690000
f
,
1.220000
f
},
//Zn
{
0.761000
f
,
0.561000
f
,
0.561000
f
,
1.220000
f
},
//Ga
{
0.400000
f
,
0.561000
f
,
0.561000
f
,
1.200000
f
},
//Ge
{
0.741000
f
,
0.502000
f
,
0.890000
f
,
1.190000
f
},
//As
{
1.000000
f
,
0.631000
f
,
0.000000
f
,
1.200000
f
},
//Se
{
0.651000
f
,
0.161000
f
,
0.161000
f
,
1.200000
f
},
//Br
{
0.361000
f
,
0.722000
f
,
0.820000
f
,
1.160000
f
},
//Kr
{
0.439000
f
,
0.180000
f
,
0.690000
f
,
2.200000
f
},
//Rb
{
0.000000
f
,
1.000000
f
,
0.000000
f
,
1.950000
f
},
//Sr
{
0.580000
f
,
1.000000
f
,
1.000000
f
,
1.900000
f
},
//Y
{
0.580000
f
,
0.878000
f
,
0.878000
f
,
1.750000
f
},
//Zr
{
0.451000
f
,
0.761000
f
,
0.788000
f
,
1.640000
f
},
//Nb
{
0.329000
f
,
0.710000
f
,
0.710000
f
,
1.540000
f
},
//Mo
{
0.231000
f
,
0.620000
f
,
0.620000
f
,
1.470000
f
},
//Tc
{
0.141000
f
,
0.561000
f
,
0.561000
f
,
1.460000
f
},
//Ru
{
0.039000
f
,
0.490000
f
,
0.549000
f
,
1.420000
f
},
//Rh
{
0.000000
f
,
0.412000
f
,
0.522000
f
,
1.390000
f
},
//Pd
{
0.753000
f
,
0.753000
f
,
0.753000
f
,
1.450000
f
},
//Ag
{
1.000000
f
,
0.851000
f
,
0.561000
f
,
1.440000
f
},
//Cd
{
0.651000
f
,
0.459000
f
,
0.451000
f
,
1.420000
f
},
//In
{
0.400000
f
,
0.502000
f
,
0.502000
f
,
1.390000
f
},
//Sn
{
0.620000
f
,
0.388000
f
,
0.710000
f
,
1.390000
f
},
//Sb
{
0.831000
f
,
0.478000
f
,
0.000000
f
,
1.380000
f
},
//Te
{
0.580000
f
,
0.000000
f
,
0.580000
f
,
1.390000
f
},
//I
{
0.259000
f
,
0.620000
f
,
0.690000
f
,
1.400000
f
},
//Xe
{
0.341000
f
,
0.090000
f
,
0.561000
f
,
2.440000
f
},
//Cs
{
0.000000
f
,
0.788000
f
,
0.000000
f
,
2.150000
f
},
//Ba
{
0.439000
f
,
0.831000
f
,
1.000000
f
,
2.070000
f
},
//La
{
1.000000
f
,
1.000000
f
,
0.780000
f
,
2.040000
f
},
//Ce
{
0.851000
f
,
1.000000
f
,
0.780000
f
,
2.030000
f
},
//Pr
{
0.780000
f
,
1.000000
f
,
0.780000
f
,
2.010000
f
},
//Nd
{
0.639000
f
,
1.000000
f
,
0.780000
f
,
1.990000
f
},
//Pm
{
0.561000
f
,
1.000000
f
,
0.780000
f
,
1.980000
f
},
//Sm
{
0.380000
f
,
1.000000
f
,
0.780000
f
,
1.980000
f
},
//Eu
{
0.271000
f
,
1.000000
f
,
0.780000
f
,
1.960000
f
},
//Gd
{
0.188000
f
,
1.000000
f
,
0.780000
f
,
1.940000
f
},
//Tb
{
0.122000
f
,
1.000000
f
,
0.780000
f
,
1.920000
f
},
//Dy
{
0.000000
f
,
1.000000
f
,
0.612000
f
,
1.920000
f
},
//Ho
{
0.000000
f
,
0.902000
f
,
0.459000
f
,
1.890000
f
},
//Er
{
0.000000
f
,
0.831000
f
,
0.322000
f
,
1.900000
f
},
//Tm
{
0.000000
f
,
0.749000
f
,
0.220000
f
,
1.870000
f
},
//Yb
{
0.000000
f
,
0.671000
f
,
0.141000
f
,
1.870000
f
},
//Lu
{
0.302000
f
,
0.761000
f
,
1.000000
f
,
1.750000
f
},
//Hf
{
0.302000
f
,
0.651000
f
,
1.000000
f
,
1.700000
f
},
//Ta
{
0.129000
f
,
0.580000
f
,
0.839000
f
,
1.620000
f
},
//W
{
0.149000
f
,
0.490000
f
,
0.671000
f
,
1.510000
f
},
//Re
{
0.149000
f
,
0.400000
f
,
0.588000
f
,
1.440000
f
},
//Os
{
0.090000
f
,
0.329000
f
,
0.529000
f
,
1.410000
f
},
//Ir
{
0.816000
f
,
0.816000
f
,
0.878000
f
,
1.360000
f
},
//Pt
{
1.000000
f
,
0.820000
f
,
0.137000
f
,
1.360000
f
},
//Au
{
0.722000
f
,
0.722000
f
,
0.816000
f
,
1.320000
f
},
//Hg
{
0.651000
f
,
0.329000
f
,
0.302000
f
,
1.450000
f
},
//Tl
{
0.341000
f
,
0.349000
f
,
0.380000
f
,
1.460000
f
},
//Pb
{
0.620000
f
,
0.310000
f
,
0.710000
f
,
1.480000
f
},
//Bi
{
0.671000
f
,
0.361000
f
,
0.000000
f
,
1.400000
f
},
//Po
{
0.459000
f
,
0.310000
f
,
0.271000
f
,
1.500000
f
},
//At
{
0.259000
f
,
0.510000
f
,
0.588000
f
,
1.500000
f
},
//Rn
{
0.259000
f
,
0.000000
f
,
0.400000
f
,
2.600000
f
},
//Fr
{
0.000000
f
,
0.490000
f
,
0.000000
f
,
2.210000
f
},
//Ra
{
0.439000
f
,
0.671000
f
,
0.980000
f
,
2.150000
f
},
//Ac
{
0.000000
f
,
0.729000
f
,
1.000000
f
,
2.060000
f
},
//Th
{
0.000000
f
,
0.631000
f
,
1.000000
f
,
2.000000
f
},
//Pa
{
0.000000
f
,
0.561000
f
,
1.000000
f
,
1.960000
f
},
//U
{
0.000000
f
,
0.502000
f
,
1.000000
f
,
1.900000
f
},
//Np
{
0.000000
f
,
0.420000
f
,
1.000000
f
,
1.870000
f
},
//Pu
{
0.329000
f
,
0.361000
f
,
0.949000
f
,
1.800000
f
},
//Am
{
0.471000
f
,
0.361000
f
,
0.890000
f
,
1.690000
f
},
//Cm
{
0.541000
f
,
0.310000
f
,
0.890000
f
,
MISSINGRADIUS
},
//Bk
{
0.631000
f
,
0.212000
f
,
0.831000
f
,
MISSINGRADIUS
},
//Cf
{
0.702000
f
,
0.122000
f
,
0.831000
f
,
MISSINGRADIUS
},
//Es
{
0.702000
f
,
0.122000
f
,
0.729000
f
,
MISSINGRADIUS
},
//Fm
{
0.702000
f
,
0.051000
f
,
0.651000
f
,
MISSINGRADIUS
},
//Md
{
0.741000
f
,
0.051000
f
,
0.529000
f
,
MISSINGRADIUS
},
//No
{
0.780000
f
,
0.000000
f
,
0.400000
f
,
MISSINGRADIUS
},
//Lr
{
0.800000
f
,
0.000000
f
,
0.349000
f
,
MISSINGRADIUS
},
//Rf
{
0.820000
f
,
0.000000
f
,
0.310000
f
,
MISSINGRADIUS
},
//Ha
{
0.851000
f
,
0.000000
f
,
0.271000
f
,
MISSINGRADIUS
},
//Sg
{
0.878000
f
,
0.000000
f
,
0.220000
f
,
MISSINGRADIUS
},
//Ns
{
0.902000
f
,
0.000000
f
,
0.180000
f
,
MISSINGRADIUS
},
//Hs
{
0.922000
f
,
0.000000
f
,
0.149000
f
,
MISSINGRADIUS
},
//Mt
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Ds
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Rg
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Cn
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Nh
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Fl
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Mc
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Lv
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Ts
{
MISSINGR
,
MISSINGG
,
MISSINGB
,
MISSINGRADIUS
},
//Og
};
void
discardline
(
FILE
*
F
)
{
int
c
;
do
{
c
=
fgetc
(
F
);
}
while
(
c
!=
EOF
&&
c
!=
'\n'
);
}
int
findAtom
(
const
char
*
const
s
)
{
//rgh FIXME, add caching
for
(
int
i
=
0
;
i
<
sizeof
(
atomNames
)
/
sizeof
(
const
char
*
);
i
++
)
if
(
!
strcmp
(
s
,
atomNames
[
i
]))
return
i
;
return
-
1
;
}
char
*
readAtomsXYZErrors
[]
=
{
"All Ok"
,
//0
"could not open file"
,
//-1
"error loading atom type and position line"
,
//-2
"atom type unknown"
,
//-3
};
int
readAtomsXYZ
(
const
char
*
const
file
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
)
{
int
mynumatoms
;
std
::
vector
<
float
*>
mypos
;
std
::
vector
<
int
>
mynum
;
FILE
*
f
=
fopen
(
file
,
"r"
);
int
r
;
char
s
[
100
];
if
(
f
==
0
)
return
-
1
;
*
timesteps
=
0
;
while
(
!
feof
(
f
))
{
r
=
fscanf
(
f
,
"%d"
,
&
mynumatoms
);
if
(
r
<
1
)
continue
;
//there may be a blank line at the end of the file
(
*
timesteps
)
++
;
discardline
(
f
);
mypos
.
push_back
(
new
float
[
mynumatoms
*
4
]);
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
);
if
(
r
<
4
)
return
-
2
;
int
a
=
findAtom
(
s
);
if
(
a
==-
1
)
return
-
3
;
(
mypos
.
back
())[
4
*
i
+
3
]
=
a
;
}
}
*
pos
=
new
float
*
[
*
timesteps
];
*
numatoms
=
new
int
[
*
timesteps
];
for
(
int
i
=
0
;
i
<*
timesteps
;
i
++
)
{
(
*
pos
)[
i
]
=
mypos
[
i
];
(
*
numatoms
)[
i
]
=
mynum
[
i
];
}
return
0
;
}
char
*
readAtomsCubeErrors
[]
=
{
"All Ok"
,
//0
"could not open file"
,
//-1
"could not read number of atoms or translation"
,
//-2
"could not read voxel size or unit cell"
,
//-3
"error loading atom type and position line"
,
//-4
};
//We will use Angstrom, convert from bohr if needed
//rgh FIXME, untested code
int
readAtomsCube
(
const
char
*
const
file
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
)
{
float
isoTrans
[
3
];
int
voxelSize
[
3
];
float
abc
[
9
];
FILE
*
f
=
fopen
(
file
,
"r"
);
int
r
;
if
(
f
==
0
)
return
-
1
;
*
timesteps
=
1
;
*
pos
=
new
float
*
[
*
timesteps
];
*
numatoms
=
new
int
[
*
timesteps
];
discardline
(
f
);
//two comments
discardline
(
f
);
r
=
fscanf
(
f
,
"%d %f %f %f"
,
*
numatoms
,
isoTrans
+
0
,
isoTrans
+
1
,
isoTrans
+
2
);
if
(
r
<
4
)
return
-
2
;
**
pos
=
new
float
[
4
*
**
numatoms
];
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
r
=
fscanf
(
f
,
"%d %f %f %f"
,
voxelSize
+
i
,
abc
+
0
+
3
*
i
,
abc
+
1
+
3
*
i
,
abc
+
2
+
3
*
i
);
if
(
r
<
4
)
return
-
3
;
//positive then the units are Bohr, if negative then Angstroms.
if
(
voxelSize
[
i
]
<
0
)
voxelSize
[
i
]
=
-
voxelSize
[
i
];
else
{
for
(
int
j
=
0
;
j
<
3
;
j
++
)
abc
[
j
+
3
*
i
]
*=
0.52918
;
}
}
for
(
int
i
=
0
;
i
<
**
numatoms
;
i
++
)
{
int
a
;
float
unused
;
r
=
fscanf
(
f
,
"%d %f %f %f %f"
,
&
a
,
&
unused
,
&
((
**
pos
)[
4
*
i
+
0
]),
&
((
**
pos
)[
4
*
i
+
1
]),
&
((
**
pos
)[
4
*
i
+
2
]));
if
(
r
<
5
)
return
-
4
;
(
**
pos
)[
4
*
i
+
3
]
=
a
-
1
;
}
//rgh FIXME, discard the volumetric data for now
fclose
(
f
);
return
0
;
}
FILE
*
out
;
void
OnData
(
const
happyhttp
::
Response
*
r
,
void
*
userdata
,
const
unsigned
char
*
data
,
int
n
)
{
fwrite
(
data
,
1
,
n
,
out
);
}
char
*
readAtomsJsonErrors
[]
=
{
"All Ok"
,
//0
"could not open file"
,
//-1
"error parsing json"
,
//-2
"error downloading json"
,
//-3
};
int
readAtomsJsonURL
(
const
char
*
const
f
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
,
float
abc
[
3
][
3
],
std
::
vector
<
float
>**
clonedAtoms
)
{
try
{
char
host
[
2048
],
page
[
2048
],
url
[
2048
];
int
port
=
80
;
int
r
;
//http://stackoverflow.com/questions/726122/best-ways-of-parsing-a-url-using-c
r
=
sscanf
(
f
,
"http://%2047[^/:]:%d%2047[^
\n
]"
,
host
,
&
port
,
page
);
if
(
r
==
1
)
r
=
sscanf
(
f
,
"http://%2047[^/]%2047[^
\n
]"
,
host
,
page
);
if
(
r
<
2
)
{
//possibly https or other unsupported protocol, fall back to wget
return
readAtomsJsonURLwget
(
f
,
numatoms
,
timesteps
,
pos
,
abc
,
clonedAtoms
);
}
sprintf
(
url
,
"%s%s"
,
page
,
"/cells"
);
out
=
fopen
(
"material_cells.json"
,
"w"
);
happyhttp
::
Connection
conn
(
host
,
port
);
conn
.
setcallbacks
(
nullptr
,
OnData
,
nullptr
,
0
);
conn
.
request
(
"GET"
,
url
,
0
,
0
,
0
);
while
(
conn
.
outstanding
()
)
conn
.
pump
();
fclose
(
out
);
conn
.
close
();
sprintf
(
url
,
"%s%s"
,
page
,
"/elements"
);
out
=
fopen
(
"material_elements.json"
,
"w"
);
conn
.
request
(
"GET"
,
url
,
0
,
0
,
0
);
while
(
conn
.
outstanding
()
)
conn
.
pump
();
fclose
(
out
);
}
catch
(
const
happyhttp
::
Wobbly
&
w
)
{
int
e
=
WSAGetLastError
();
fprintf
(
stderr
,
"error %d
\n
"
,
e
);
return
-
3
;
}
fclose
(
out
);
//sprintf (cmd, "wget %s/cells -O material_cells.json", f);
//system(cmd);
//sprintf (cmd, "wget %s/elements -O material_elements.json", f);
//system(cmd);
return
readAtomsJson
(
"material"
,
numatoms
,
timesteps
,
pos
,
abc
,
clonedAtoms
);
}
int
readAtomsJsonURLwget
(
const
char
*
const
f
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
,
float
abc
[
3
][
3
],
std
::
vector
<
float
>**
clonedAtoms
)
{
char
cmd
[
2048
];
int
ret
;
sprintf
(
cmd
,
"wget %s/cells -O material_cells.json"
,
f
);
ret
=
system
(
cmd
);
if
(
ret
!=
0
)
return
(
-
3
);
sprintf
(
cmd
,
"wget %s/elements -O material_elements.json"
,
f
);
ret
=
system
(
cmd
);
return
(
-
3
);
return
readAtomsJson
(
"material"
,
numatoms
,
timesteps
,
pos
,
abc
,
clonedAtoms
);
}
bool
isAlmostZero
(
float
coordinate
)
{
return
(
coordinate
<
1E-5
);
}
void
add
(
std
::
vector
<
float
>
*
v
,
float
x
,
float
y
,
float
z
,
float
a
)
{
v
->
push_back
(
x
);
v
->
push_back
(
y
);
v
->
push_back
(
z
);
v
->
push_back
(
a
);
}
int
readAtomsJson
(
const
char
*
const
f
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
,
float
abc
[
3
][
3
],
std
::
vector
<
float
>**
clonedAtoms
)
{
char
file
[
512
];
int
r
;
sprintf
(
file
,
"%s_cells.json"
,
f
);
FILE
*
fcells
=
fopen
(
file
,
"r"
);
if
(
fcells
==
0
)
return
-
1
;
char
readBuffer
[
65536
];
rapidjson
::
FileReadStream
is
(
fcells
,
readBuffer
,
sizeof
(
readBuffer
));
rapidjson
::
Document
json
;
json
.
ParseStream
(
is
);
fclose
(
fcells
);
int
total_results
=
json
[
"total_results"
].
GetInt
();
const
rapidjson
::
GenericValue
<
rapidjson
::
UTF8
<>
>
&
results
=
json
[
"results"
];
for
(
int
i
=
0
;
i
<
total_results
;
i
++
)
{
const
rapidjson
::
GenericValue
<
rapidjson
::
UTF8
<>
>
&
result
=
results
[
i
];
if
(
result
[
"is_primitive"
].
GetBool
()
==
false
)
continue
;
const
char
*
myabc
[
3
]
=
{
result
[
"a"
].
GetString
(),
result
[
"b"
].
GetString
(),
result
[
"c"
].
GetString
()};
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
r
=
sscanf
(
myabc
[
j
],
"(%f,%f,%f)"
,
&
(
abc
[
j
][
0
]),
&
(
abc
[
j
][
1
]),
&
(
abc
[
j
][
2
]));
for
(
int
k
=
0
;
k
<
3
;
k
++
)
abc
[
j
][
k
]
*=
1e10
;
//using angstrom internally
}
}
sprintf
(
file
,
"%s_elements.json"
,
f
);
FILE
*
felements
=
fopen
(
file
,
"r"
);
if
(
felements
==
0
)
return
-
1
;
rapidjson
::
FileReadStream
is2
(
felements
,
readBuffer
,
sizeof
(
readBuffer
));
json
.
ParseStream
(
is2
);
fclose
(
felements
);
*
timesteps
=
1
;
*
pos
=
new
float
*
[
*
timesteps
];
*
numatoms
=
new
int
[
*
timesteps
];
**
numatoms
=
json
[
"total_results"
].
GetInt
();
**
pos
=
new
float
[
4
*
**
numatoms
];
*
clonedAtoms
=
new
std
::
vector
<
float
>
[
*
timesteps
];
const
rapidjson
::
GenericValue
<
rapidjson
::
UTF8
<>
>&
a
=
json
[
"results"
];
float
tmppos
[
3
];
for
(
int
i
=
0
;
i
<
**
numatoms
;
i
++
)
{
const
rapidjson
::
GenericValue
<
rapidjson
::
UTF8
<>
>
&
result
=
a
[
i
];
const
rapidjson
::
GenericValue
<
rapidjson
::
UTF8
<>
>
&
label
=
result
[
"label"
];
if
(
!
label
.
IsInt
())
return
-
2
;
int
k
=
label
.
GetInt
();
(
**
pos
)[
4
*
i
+
3
]
=
k
;
const
char
*
stringpos
=
result
[
"position"
].
GetString
();
r
=
sscanf
(
stringpos
,
"(%f,%f,%f)"
,
tmppos
+
0
,
tmppos
+
1
,
tmppos
+
2
);
//clone
//https://gitlab.mpcdf.mpg.de/nomad-lab/encyclopedia-gui/blob/lauri_viz/viztools/structure/src/typescript/structureviewer.ts
Clone
(
tmppos
,
k
,
*
clonedAtoms
);
//atom positions in the abc domain, must multiply.
for
(
int
s
=
0
;
s
<
3
;
s
++
)
(
**
pos
)[
4
*
i
+
s
]
=
tmppos
[
0
]
*
abc
[
0
][
s
]
+
tmppos
[
1
]
*
abc
[
1
][
s
]
+
tmppos
[
2
]
*
abc
[
2
][
s
];
}
TransformAtoms
(
*
clonedAtoms
,
abc
);
return
0
;
}
void
TransformAtoms
(
std
::
vector
<
float
>*
clonedAtoms
,
const
float
abc
[
3
][
3
])
{
float
tmppos
[
3
];
for
(
int
o
=
0
;
o
<
clonedAtoms
->
size
()
/
4
;
o
++
)
{
for
(
int
s
=
0
;
s
<
3
;
s
++
)
tmppos
[
s
]
=
(
*
clonedAtoms
)[
o
*
4
+
s
];
for
(
int
s
=
0
;
s
<
3
;
s
++
)
(
*
clonedAtoms
)[
o
*
4
+
s
]
=
tmppos
[
0
]
*
abc
[
0
][
s
]
+
tmppos
[
1
]
*
abc
[
1
][
s
]
+
tmppos
[
2
]
*
abc
[
2
][
s
];
}
}
void
Clone
(
float
tmppos
[
3
],
float
k
,
std
::
vector
<
float
>*
clonedAtoms
)
{
bool
iaz
[
3
];
for
(
int
q
=
0
;
q
<
3
;
q
++
)
iaz
[
q
]
=
isAlmostZero
(
tmppos
[
q
]);
if
(
iaz
[
0
]
&&
iaz
[
1
]
&&
iaz
[
2
]){
add
(
clonedAtoms
,
0
,
0
,
1
,
k
);
add
(
clonedAtoms
,
0
,
1
,
0
,
k
);
add
(
clonedAtoms
,
0
,
1
,
1
,
k
);
add
(