From 7145c220b79cf74d2375635af4410875e8ceb7ab Mon Sep 17 00:00:00 2001 From: "Garcia-Hernandez, Ruben Jesus (rgarcia)" <garcia@lrz.de> Date: Mon, 5 Mar 2018 15:42:01 +0100 Subject: [PATCH] Added NOMAD2XYZ app (used for preprocessing json into remote visualization ready datasets). --- NOMADVRLib/ConfigFile.cpp | 9 +---- NOMADVRLib/ConfigFile.h | 11 ++---- NOMADVRLib/ConfigFileAtoms.cpp | 11 ++++++ NOMADVRLib/ConfigFileAtoms.h | 16 ++++++++ NOMADVRLib/atoms.cpp | 2 +- NOMADVRLib/atoms.hpp | 1 + README.md | 7 ++++ RemoteVisualization/Makefile | 8 ++++ RemoteVisualization/Readme.txt | 8 ++++ RemoteVisualization/eprintf.cpp | 32 ++++++++++++++++ RemoteVisualization/main.cpp | 68 +++++++++++++++++++++++++++++++++ 11 files changed, 156 insertions(+), 17 deletions(-) create mode 100644 NOMADVRLib/ConfigFileAtoms.cpp create mode 100644 NOMADVRLib/ConfigFileAtoms.h create mode 100644 RemoteVisualization/Makefile create mode 100644 RemoteVisualization/Readme.txt create mode 100644 RemoteVisualization/eprintf.cpp create mode 100644 RemoteVisualization/main.cpp diff --git a/NOMADVRLib/ConfigFile.cpp b/NOMADVRLib/ConfigFile.cpp index 57919e9..832317f 100644 --- a/NOMADVRLib/ConfigFile.cpp +++ b/NOMADVRLib/ConfigFile.cpp @@ -36,9 +36,6 @@ float scaling; float markerscaling; float BACKGROUND[3]; -int* numAtoms; //[timesteps] -float **atoms; //[timesteps][numAtoms[i]*4] //xyzu, u=atom number -bool fixedAtoms; float atomScaling; std::vector<float> *clonedAtoms; @@ -55,11 +52,8 @@ bool showTrajectories; std::vector<int> atomtrajectories; std::vector<std::vector<int>> atomtrajectoryrestarts; -float abc[3][3]; //basis vectors -bool has_abc = false; bool displayunitcell; -float supercell[3]; -int voxelSize[3]; + float unitcellcolour[4]; float supercellcolour[4]; @@ -79,7 +73,6 @@ float nearclip, farclip; //markers such as hole positions and electron positions float ** markers; float ** markercolours; -float cubetrans[3]; float animationspeed; float movementspeed; diff --git a/NOMADVRLib/ConfigFile.h b/NOMADVRLib/ConfigFile.h index 186ad84..e6910f4 100644 --- a/NOMADVRLib/ConfigFile.h +++ b/NOMADVRLib/ConfigFile.h @@ -19,6 +19,7 @@ #include <vector> #include "MyGL.h" #include "polyhedron.h" +#include "ConfigFileAtoms.h" extern const char * PATH; extern const char * SCREENSHOT; @@ -31,9 +32,7 @@ extern float userpos[3]; extern float scaling; 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; @@ -49,10 +48,8 @@ extern bool showTrajectories; extern std::vector<int> atomtrajectories; extern std::vector<std::vector<int>> atomtrajectoryrestarts; -extern float abc[3][3]; //basis vectors -extern bool has_abc; extern bool displayunitcell; -extern float supercell[3]; + extern float markerscaling; extern float unitcellcolour[4]; extern float supercellcolour[4]; @@ -79,8 +76,6 @@ extern float movementspeed; //how fast to move the user //markers such as hole positions and electron positions extern float ** markers; extern float ** markercolours; -extern float cubetrans[3]; -extern int voxelSize[3]; extern const char * loadConfigFileErrors[]; diff --git a/NOMADVRLib/ConfigFileAtoms.cpp b/NOMADVRLib/ConfigFileAtoms.cpp new file mode 100644 index 0000000..7f0ad0a --- /dev/null +++ b/NOMADVRLib/ConfigFileAtoms.cpp @@ -0,0 +1,11 @@ +float abc[3][3]; //basis vectors +bool has_abc = false; + +int* numAtoms; //[timesteps] +float **atoms; //[timesteps][numAtoms[i]*4] //xyzu, u=atom number +bool fixedAtoms; + +float cubetrans[3]; + +float supercell[3]; +int voxelSize[3]; \ No newline at end of file diff --git a/NOMADVRLib/ConfigFileAtoms.h b/NOMADVRLib/ConfigFileAtoms.h new file mode 100644 index 0000000..67e0dce --- /dev/null +++ b/NOMADVRLib/ConfigFileAtoms.h @@ -0,0 +1,16 @@ +#ifndef CONFIGFILEATOMS_H +#define CONFIGFILEATOMS_H + +extern float abc[3][3]; //basis vectors +extern bool has_abc; + +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 cubetrans[3]; +extern int voxelSize[3]; + +extern float supercell[3]; + +#endif //CONFIGFILEATOMS_H diff --git a/NOMADVRLib/atoms.cpp b/NOMADVRLib/atoms.cpp index f80fce6..aa4b69f 100644 --- a/NOMADVRLib/atoms.cpp +++ b/NOMADVRLib/atoms.cpp @@ -28,7 +28,7 @@ #include "eprintf.h" #include "atoms.hpp" -#include "ConfigFile.h" +#include "ConfigFileAtoms.h" #include "rapidjson/document.h" #include "rapidjson/filereadstream.h" #include "happyhttp/happyhttp.h" diff --git a/NOMADVRLib/atoms.hpp b/NOMADVRLib/atoms.hpp index 347ef27..589574c 100644 --- a/NOMADVRLib/atoms.hpp +++ b/NOMADVRLib/atoms.hpp @@ -62,6 +62,7 @@ void TransformAtoms(std::vector<float>* clonedAtoms, const float abc[3][3]); extern bool inv_abc_init; extern float inv_abc[3][3]; +extern const char * const atomNames[]; extern std::vector<const char*> extraAtomNames; extern std::vector<float*> extraAtomData; diff --git a/README.md b/README.md index 4aefbe4..288b4fb 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ Subdirectories: OculusMobile: Demos for GearVR. GoogleCardboardAndroid: Demos for Google Cardboard (android) CAVE: Demos for LRZ CAVE-like environment (linux) + + NOMADGearVRChooser: Android app to select the dataset for GearVR, which + calls the OculusMobile app as a subroutine. NOMADVRLib: Shared code between HTC Vive, GearVR and Google Cardboard demos related to NOMAD. libs: Other (external) supporting libs shared by HTC Vive, GearVR, Cardboard and CAVE demos @@ -11,6 +14,10 @@ Subdirectories: htdocs: Web pages containing the VR software and documentation. cgi-bin: cgi scripts to create suitable config files from a material number. + RemoteVisualization: NOMAD2xyz app + Transforms a json from encyclopedia or archive into an XYZ file + Useful for the remote visualization infrastructure + More platforms will be added in the future. The code is distributed under the Apache 2.0 License (See LICENSE file). diff --git a/RemoteVisualization/Makefile b/RemoteVisualization/Makefile new file mode 100644 index 0000000..360f85c --- /dev/null +++ b/RemoteVisualization/Makefile @@ -0,0 +1,8 @@ +all: NOMADVRLib/atoms.o eprintf.o happyhttp/happyhttp.o NOMADVRLib/ConfigFileAtoms.o main.o + g++ $^ -o nomad2xyz + +.cpp.o: + g++ -I. -std=c++11 $< -c -o $*.o + +clean: + rm -f *.o nomad2xyz diff --git a/RemoteVisualization/Readme.txt b/RemoteVisualization/Readme.txt new file mode 100644 index 0000000..eb11894 --- /dev/null +++ b/RemoteVisualization/Readme.txt @@ -0,0 +1,8 @@ +NOMAD2xyz app + Transforms a json from encyclopedia or archive into an XYZ file + Useful for the remote visualization infrastructure + +Depends on the following libraries: + NOMADVRLib + happyhttp + rapidjson \ No newline at end of file diff --git a/RemoteVisualization/eprintf.cpp b/RemoteVisualization/eprintf.cpp new file mode 100644 index 0000000..0920c90 --- /dev/null +++ b/RemoteVisualization/eprintf.cpp @@ -0,0 +1,32 @@ +/* +# Copyright 2016-2018 The NOMAD Developers Group +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include <stdarg.h> +#include <stdio.h> + +#include "NOMADVRLib/eprintf.h" + +void eprintf( const char *fmt, ... ) +{ + va_list args; + char buffer[ 2048 ]; + + va_start( args, fmt ); + vsprintf( buffer, fmt, args ); + va_end( args ); + + fprintf(stderr, "%s\n", buffer ); +} diff --git a/RemoteVisualization/main.cpp b/RemoteVisualization/main.cpp new file mode 100644 index 0000000..6763954 --- /dev/null +++ b/RemoteVisualization/main.cpp @@ -0,0 +1,68 @@ +/* +# Copyright 2016-2018 The NOMAD Developers Group +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include "NOMADVRLib/eprintf.h" +#include "NOMADVRLib/ConfigFileAtoms.h" +#include "NOMADVRLib/atoms.hpp" + + int timesteps; + +void exportXYZ(const char * file, const char *mat) +{ + +FILE * f=fopen (file, "w"); +for (int i=0;i<timesteps;i++) { + fprintf (f, "%d\n", numAtoms[i]); + fprintf (f, "Comment: Material=%s\n", mat); + + for (int j=0;j<numAtoms[i];j++) { + fprintf (f, "%s\t%f\t%f\t%f\n", atomNames[(int)(atoms[i][j*4+3])], + atoms[i][j*4+0], atoms[i][j*4+1], atoms[i][j*4+2]); + + + } +} +} + +void usage (const char * argv0) +{ + eprintf ("Usage: \n%s e <basename for encyclopedia json> xyz", argv0); + eprintf ("%s a <archive json> xyz", argv0); + +} + +int main (int argc, char **argv) { + + if (argc < 3) { + usage(argv[0]); + return 1; + } + + std::vector<float> *clonedAtoms; + if (argv[1][0]=='e') { + readAtomsJson (argv[2], &numAtoms, ×teps, &atoms, abc, &clonedAtoms); + + //now export xyz + exportXYZ(argv[3], argv[2]); + } else if (argv[1][0]=='a') { + readAtomsAnalyticsJson (argv[2], &numAtoms, ×teps, &atoms, abc, &clonedAtoms); + exportXYZ (argv[3], argv[2]); + } else { + usage(argv[0]); + return 2; + } + return 0; +} -- GitLab