├── .gitignore ├── docs └── jcc25344-toc-0001-m.jpg ├── ChangeLog.md ├── topoms-cli ├── CMakeLists.txt ├── LICENSE └── src │ └── main.cpp ├── scripts ├── CAR2vti.py ├── plot_bondStats.py ├── VASPutils.py └── compute_chgCOM.py ├── topoms ├── CMakeLists.txt ├── README.md ├── LICENSE ├── include │ ├── MSCBond.h │ ├── Vec3.h │ ├── Mat3.h │ ├── MultilinearInterpolator.h │ ├── ConfigParser.h │ ├── Material.h │ └── Utils.h └── src │ ├── Utils.cpp │ └── MSCBond.cpp ├── configs └── example.conf ├── msc ├── LICENSE ├── src │ ├── regular_grid.cpp │ └── regular_grid_trilinear_function.cpp └── include │ ├── advection_events.h │ ├── topological_regular_masked_restricted_grid.h │ ├── basic_types.h │ ├── array_index_partition.h │ ├── topological_regular_grid_restricted.h │ ├── timing.h │ ├── labeling.h │ ├── msc_iterators.h │ ├── isolated_region_remover.h │ ├── strictly_numeric_integrator.h │ ├── discrete_gradient_labeling.h │ ├── isolated_region_remover2.h │ ├── labeling_to_bounary_labeling.h │ └── topological_explicit_mesh_function.h ├── topoms-ui ├── README.md └── CMakeLists.txt ├── CMakeLists.txt ├── README.md └── install.topoms.sh /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.DS_Store 3 | 4 | build* 5 | *user 6 | 7 | -------------------------------------------------------------------------------- /docs/jcc25344-toc-0001-m.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llnl/TopoMS/HEAD/docs/jcc25344-toc-0001-m.jpg -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | ### Summary of changes 2 | 3 | ##### v1.0.2 (Aug 19, 2018) 4 | 5 | * Support for non-orthgonal lattice. Properly handles lattice vectors. 6 | * Bug fix in VASP file parsing. Handles carriage return correctly. (commit e595f59) 7 | * Several improvements in build process. 8 | * Starting maintaining the change log. 9 | 10 | ##### v1.0.1 (Apr 17, 2018) 11 | 12 | * Bug fix in numerical integrator. Uses the correct seed point. (commit f85266d) 13 | 14 | ##### v1.0 (Feb 20, 2018) 15 | 16 | * Initial release. (commit bc424b0) 17 | -------------------------------------------------------------------------------- /topoms-cli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # CMake file for topoms-cli 3 | # ------------------------------------------------------------------------------ 4 | 5 | cmake_minimum_required(VERSION 3.9) 6 | 7 | include_directories(${PATH_MSC}/include ${PATH_TOPOMS}/include) 8 | 9 | add_executable(${TRG_CLI} ${PATH_CLI}/src/main.cpp) 10 | target_link_libraries(${TRG_CLI} LINK_PUBLIC ${TRG_LIB}) 11 | 12 | install(TARGETS ${TRG_CLI} DESTINATION bin) 13 | 14 | # ------------------------------------------------------------------------------ 15 | -------------------------------------------------------------------------------- /scripts/CAR2vti.py: -------------------------------------------------------------------------------- 1 | # Read VASP CAR format (CHGCAR, AECCAR, LOCPOT) and write the field as a vti file! 2 | import numpy 3 | import argparse 4 | 5 | from VASPutils import readCAR 6 | from pyevtk.hl import imageToVTK 7 | 8 | # --------------------------------------------- 9 | parser = argparse.ArgumentParser(description='Read a CAR file and write as vti') 10 | parser.add_argument('--infile', metavar='(infile)', required=True, nargs=1, help='Input CAR file') 11 | 12 | args = parser.parse_args() 13 | infilename = args.infile[0] 14 | 15 | # --------------------------------------------- 16 | (sysname, scalingfactor, lattice, species, pos, grid, data) = readCAR(infilename, True) 17 | spacings = (scalingfactor*lattice[0][0]/(grid[0]-1), 18 | scalingfactor*lattice[1][1]/(grid[1]-1), 19 | scalingfactor*lattice[2][2]/(grid[2]-1)) 20 | 21 | # --------------------------------------------- 22 | # now, write the data 23 | print 'Writing', infilename+'.vti' 24 | imageToVTK(infilename, spacing = spacings, pointData = {"charge" : data} ) 25 | -------------------------------------------------------------------------------- /topoms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # CMake file for topoms (shared library) 3 | # ------------------------------------------------------------------------------ 4 | 5 | cmake_minimum_required(VERSION 3.9) 6 | 7 | # ------------------------------------------------------------------------------ 8 | # TopoMS source 9 | 10 | include_directories(${PATH_MSC}/include ${PATH_TOPOMS}/include) 11 | 12 | file(GLOB HDRS_MSC ${PATH_MSC}/include/*.h) 13 | file(GLOB SRCS_MSC ${PATH_MSC}/src/*.cpp) 14 | 15 | file(GLOB HDRS_TOPOMS ${PATH_TOPOMS}/include/*.h) 16 | file(GLOB SRCS_TOPOMS ${PATH_TOPOMS}/src/*.cpp) 17 | 18 | # ------------------------------------------------------------------------------ 19 | # create and install target 20 | 21 | add_library(${TRG_LIB} STATIC 22 | ${HDRS_MSC} ${HDRS_TOPOMS} ${SRCS_MSC} ${SRCS_TOPOMS}) 23 | 24 | if(VTK_FOUND) 25 | target_link_libraries(${TRG_LIB} LINK_PUBLIC ${VTK_LIBRARIES}) 26 | endif(VTK_FOUND) 27 | 28 | install(TARGETS ${TRG_LIB} DESTINATION lib ) 29 | 30 | # ------------------------------------------------------------------------------ 31 | -------------------------------------------------------------------------------- /configs/example.conf: -------------------------------------------------------------------------------- 1 | 2 | # type of input file (currently VASP CHGCAR and Cube files are supported) 3 | INFILETYPE = VASP 4 | 5 | # field type, CHG or POT 6 | FIELDTYPE = CHG 7 | 8 | # path to input file 9 | INFILE = ./AECCAR 10 | 11 | # flags for periodicity in all three spatial dimensions 12 | PERIODIC_DOMAIN = 1 1 1 13 | 14 | # enable computation of Bader volumes 15 | BADER_VOLUMES = true 16 | 17 | # threshold to define vacuum regions. (use 0.0 for no thresholding) 18 | # in units of function value (electron charge density) 19 | THRESHOLD_VACUUM = 0.01 20 | 21 | # enable computation of complete molecular graph 22 | # if this is true, the Bader volumes will be computed irrespective of BADER_VOLUMES flag 23 | MOLECULAR_GRAPH = true 24 | 25 | # simplification threshold 26 | # in units of function value (electron charge density) 27 | # if used in command line mode, TopoMS will output the molecular graph at the given threshold 28 | # is UI app is used, this threshold defines the initial view, but is editable through UI 29 | THRESHOLD_SIMPL = 1.0 30 | 31 | # other internal parameters for TopoMS algorithm 32 | THRESHOLD_GRAD = 0.0001 33 | THRESHOLD_ERROR = 0.0001 34 | NUM_ITER = 10000 35 | -------------------------------------------------------------------------------- /topoms/README.md: -------------------------------------------------------------------------------- 1 | ## TopoMS, Version 1.0 2 | ##### Author: Harsh Bhatia, hbhatia@llnl.gov 3 | 4 | TopoMS is a computational tool for detailed topological analysis of molecular 5 | and condensed matter systems, including the computation of atomic volumes and 6 | charges through the quantum theory of atoms in molecules (also known as Bader 7 | analysis), as well as the complete molecular graph. With roots in techniques 8 | from computational topology, and using a shared-memory parallel approach, 9 | TopoMS provides scalable, numerically robust, and topologically consistent 10 | analysis. 11 | 12 | ### Installation 13 | 14 | Update: Please see the script `TopoMS/install.topoms.sh`, which automates the 15 | following steps. 16 | 17 | The only external dependency of `TopoMS` is VTK (https://www.vtk.org/); recommended 18 | version `VTK 7.1`. Once VTK has been installed, `TopoMS` can be installed using 19 | the `cmake` system. `TopoMS` requires a C++ compiler supporting OpenMP. 20 | 21 | ``` 22 | $ pwd 23 | TopoMS/topoms 24 | $ mkdir build 25 | $ cd build 26 | $ cmake -DCMAKE_CXX_COMPILER= .. # path needed for Mac 27 | $ make 28 | ``` 29 | 30 | Note: If you're using the install scripts, the external dependencies will be installed 31 | in `TopoMS/external`, and the executables will be installed in `TopoMS/build`. 32 | 33 | ### Execution 34 | 35 | The application can be executed by passing a configuration file from command line. 36 | 37 | ``` 38 | $ TopoMS configuration_file.conf 39 | ``` 40 | -------------------------------------------------------------------------------- /msc/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 University of Utah 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the copyright holder nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /topoms-ui/README.md: -------------------------------------------------------------------------------- 1 | ## TopoMS-UI, Version 1.0 2 | ##### Author: Harsh Bhatia, hbhatia@llnl.gov 3 | 4 | TopoMS is a computational tool for detailed topological analysis of molecular 5 | and condensed matter systems, including the computation of atomic volumes and 6 | charges through the quantum theory of atoms in molecules (also known as Bader 7 | analysis), as well as the complete molecular graph. With roots in techniques 8 | from computational topology, and using a shared-memory parallel approach, 9 | TopoMS provides scalable, numerically robust, and topologically consistent 10 | analysis. 11 | 12 | ### Installation 13 | 14 | In addition to `TopoMS`, `TopoMS-UI` depends upon `Qt 5.7`, `QGLViewer 2.7.1` 15 | (http://libqglviewer.com/), and `GLEW 2.1.0`. 16 | Once these depenencies are installed, you may use `cmake` or Qt's `qmake` 17 | system to build the tool. 18 | 19 | ``` 20 | $ pwd 21 | TopoMS/topoms-ui 22 | $ mkdir build 23 | $ cmake -DCMAKE_CXX_COMPILER= .. # compiler path needed only for Mac 24 | $ make 25 | ``` 26 | If you are more comfortable using `qmake`, you may proceed as follows 27 | 28 | ``` 29 | $ pwd 30 | TopoMS/topoms-ui 31 | $ mkdir build 32 | $ qmake -spec macx-g++ QMAKE_CXX= \ # this line needed only for Mac 33 | QGLPATH=/Users/bhatia4/usr \ 34 | VTKPATH=/Users/bhatia4/usr VTKVERSION=7.1 \ 35 | .. 36 | $ make 37 | ``` 38 | 39 | Note: If you're using the install scripts, the external dependencies will be installed 40 | in `TopoMS/external`, and the executables will be installed in `TopoMS/build`. 41 | 42 | ### Execution 43 | 44 | The application can be executed by passing a configuration file from command line. 45 | 46 | ``` 47 | $ TopoMS-UI configuration_file.conf 48 | ``` 49 | -------------------------------------------------------------------------------- /msc/src/regular_grid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "regular_grid.h" 31 | 32 | using namespace MSC; 33 | const Vec3l RegularGrid::kNeighborOffsets6[6] = { 34 | Vec3l(1, 0, 0), Vec3l(-1, 0, 0), 35 | Vec3l(0, 1, 0), Vec3l(0, -1, 0), 36 | Vec3l(0, 0, 1), Vec3l(0, 0, -1) 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /msc/include/advection_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef ADVECTION_EVENTS_H 31 | #define ADVECTION_EVENTS_H 32 | 33 | namespace MSC { 34 | enum ADVECTION_EVENT { 35 | NONE, 36 | OUT_OF_VOXEL, 37 | OVER_MAX_ITERATIONS, 38 | LOW_GRADIENT, 39 | HIT_EXTREMUM, 40 | HIT_PREASSIGNED, 41 | OTHER 42 | }; 43 | } 44 | #endif -------------------------------------------------------------------------------- /msc/src/regular_grid_trilinear_function.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "regular_grid_trilinear_function.h" 31 | 32 | using namespace MSC; 33 | 34 | const FLOATTYPE RegularGridTrilinearFunction::kRKCoefficients[5][9] = { 35 | { 1, 0, 0, 0, 0, 0, 0, 0, 0 }, 36 | { -1.0 / 2.0, 0, 1.0 / 2.0, 0, 0, 0, 0, 0, 0 }, 37 | { 1.0 / 12.0, -2.0 / 3.0, 0, 2.0 / 3.0, -1.0 / 12.0, 0, 0, 0, 0 }, 38 | { -1.0 / 60.0, 3.0 / 20.0, -3.0 / 4.0, 0, 3.0 / 4.0, -3.0 / 20.0, 1.0 / 60.0, 0, 0 }, 39 | { 1.0 / 280.0, -4.0 / 105.0, 1.0 / 5.0, -4.0 / 5.0, 0, 4.0 / 5.0, -1.0 / 5.0, 4.0 / 105.0, -1.0 / 280.0 } 40 | }; 41 | -------------------------------------------------------------------------------- /msc/include/topological_regular_masked_restricted_grid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef TOPOLOGICAL_REGULAR_MASKED_RESTRICTED_GRID_H 31 | #define TOPOLOGICAL_REGULAR_MASKED_RESTRICTED_GRID_H 32 | 33 | 34 | #include "regular_grid.h" 35 | #include "topological_regular_grid.h" 36 | #include "topological_regular_masked_grid.h" 37 | #include "topological_regular_grid_restricted.h" 38 | 39 | namespace MSC { 40 | 41 | class TopologicalRegularMaskedRestrictedGrid : 42 | public TopologicalRegularMaskedGrid, 43 | public TopologicalRegularGridRestricted { 44 | public: 45 | TopologicalRegularMaskedRestrictedGrid(RegularGrid* base_grid) : 46 | TopologicalRegularMaskedGrid(base_grid), 47 | TopologicalRegularGridRestricted(base_grid), 48 | TopologicalRegularGrid(base_grid) {} 49 | }; 50 | } // end of namespace 51 | #endif 52 | -------------------------------------------------------------------------------- /msc/include/basic_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef BASIC_TYPES_H 31 | #define BASIC_TYPES_H 32 | 33 | #define INDEX_TYPE long long // type to index elements of a mesh - need to support big meshes! - keep this signed to make arithmetic consistent 34 | //#define FLOATTYPE float // type used for computing numerical integration 35 | #define FLOATTYPE double // type used for computing numerical integration 36 | #define INT_TYPE int // regular old ints 37 | #define DIM_TYPE unsigned char // used to query the dimension of a cell - we usually have values between 0-3 38 | #define BYTE_TYPE unsigned char // just a regular old byte 39 | #define BOUNDARY_TYPE unsigned char // used to query the boundary classification of a cell - usually a small integer 40 | #define ASSIGNED_TYPE unsigned char // used to query if a cell has been assigned - usually 0, 1 values 41 | 42 | enum DestType { 43 | BACKGROUND, 44 | UNASSIGNED, 45 | ASSIGNED, 46 | CERTAIN_TERMINAL, 47 | CERTAIN_NONTERMINAL 48 | }; 49 | #endif 50 | -------------------------------------------------------------------------------- /msc/include/array_index_partition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef ARRAY_INDEX_PARTITION_H 31 | #define ARRAY_INDEX_PARTITION_H 32 | 33 | 34 | #include 35 | #include 36 | 37 | namespace MSC { 38 | 39 | class ArrayIndexPartitioner { 40 | protected: 41 | 42 | public: 43 | 44 | // fills the partition array with numbers such that the 0th element is 0, and last element 45 | // is the number of elements total. A task with index i should do work between 46 | // the interval from index >= partition[i] to index < partition[i+1] 47 | // equalizes the amount of work between the numthreads indices 48 | static void EvenChunkSplit(INDEX_TYPE num_elements, int numThreads, std::vector& partition) { 49 | partition.clear(); 50 | partition.reserve(numThreads + 1); 51 | INDEX_TYPE chunksize = num_elements / numThreads; 52 | INDEX_TYPE remainder = num_elements % numThreads; 53 | INDEX_TYPE start = 0; 54 | partition.push_back(start); 55 | for (int i = 0; i < numThreads; i++) { 56 | start += chunksize; 57 | if (i < remainder) start += 1; 58 | partition.push_back(start); 59 | } 60 | } 61 | }; 62 | 63 | 64 | } 65 | 66 | #endif -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # CMake file for TopoMS 3 | # ------------------------------------------------------------------------------ 4 | 5 | cmake_minimum_required(VERSION 3.9) 6 | 7 | message(STATUS "> configuring TopoMS in (" ${CMAKE_CURRENT_SOURCE_DIR} ")") 8 | 9 | project(TopoMS LANGUAGES CXX VERSION 1.1 DESCRIPTION "TopoMS") 10 | set(CMAKE_BUILD_TYPE Release) 11 | 12 | #set(CMAKE_VERBOSE_MAKEFILE 1) 13 | 14 | # ------------------------------------------------------------------------------ 15 | # compiler configuration 16 | 17 | #if(NOT CMAKE_COMPILER_IS_GNUCXX) 18 | # message(FATAL_ERROR "TopoMS requires a GNU compiler. CMake will fail.") 19 | #endif() 20 | 21 | # Compiler flags 22 | set(CMAKE_CXX_FLAGS "-O3") ## Optimize 23 | set(CMAKE_CXX_FLAGS "-std=c++0x -fpermissive -w") 24 | 25 | set(CMAKE_SHARED_LINKER_FLAGS "-s -lc++") ## Strip binary 26 | set(CMAKE_EXE_LINKER_FLAGS "-s -lc++") ## Strip binary 27 | #-lc++ for Apple 28 | 29 | # ------------------------------------------------------------------------------ 30 | # subdirectories 31 | 32 | set(PATH_EXT ${CMAKE_CURRENT_SOURCE_DIR}/external) 33 | set(PATH_MSC ${CMAKE_CURRENT_SOURCE_DIR}/msc) 34 | set(PATH_TOPOMS ${CMAKE_CURRENT_SOURCE_DIR}/topoms) 35 | set(PATH_CLI ${CMAKE_CURRENT_SOURCE_DIR}/topoms-cli) 36 | set(PATH_UI ${CMAKE_CURRENT_SOURCE_DIR}/topoms-ui) 37 | 38 | #message(STATUS " > PATH_MSC: " ${PATH_MSC}) 39 | #message(STATUS " > PATH_TOPOMS: " ${PATH_TOPOMS}) 40 | #message(STATUS " > PATH_CLI: " ${PATH_CLI}) 41 | #message(STATUS " > PATH_UI: " ${PATH_UI}) 42 | 43 | # target names 44 | set(TRG_LIB topoms) 45 | set(TRG_CLI topoms-cli) 46 | set(TRG_UI topoms-ui) 47 | 48 | # ------------------------------------------------------------------------------ 49 | # OpenMP 50 | 51 | find_package(OpenMP REQUIRED) 52 | 53 | #message(STATUS "OpenMP_CXX_FLAGS: " ${OpenMP_CXX_FLAGS}) 54 | #message(STATUS "OpenMP_EXE_LINKER_FLAGS: " ${OpenMP_EXE_LINKER_FLAGS}) 55 | 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 57 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") 58 | 59 | # ------------------------------------------------------------------------------ 60 | # VTK 61 | 62 | find_package(VTK 7.1 63 | HINTS ${PATH_EXT}/lib/cmake/vtk-7.1) 64 | 65 | if(VTK_FOUND) 66 | message(STATUS "Found VTK " ${VTK_VERSION} ": " ${VTK_INCLUDE_DIRS}) 67 | include(${VTK_USE_FILE}) 68 | add_definitions(-DUSE_VTK=TRUE) 69 | endif(VTK_FOUND) 70 | 71 | # ------------------------------------------------------------------------------ 72 | # TopoMS 73 | 74 | add_subdirectory(topoms) 75 | add_subdirectory(topoms-cli) 76 | 77 | OPTION(TOPOMS_BUILD_UI "Build User Interface" OFF) 78 | if(TOPOMS_BUILD_UI) 79 | add_subdirectory(topoms-ui) 80 | endif() 81 | 82 | # ------------------------------------------------------------------------------ 83 | -------------------------------------------------------------------------------- /topoms/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 2 | Produced at the Lawrence Livermore National Laboratory. 3 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 4 | (jediati@sci.utah.edu). 5 | LLNL-CODE-745278. All rights reserved. 6 | 7 | This file is part of TopoMS, Version 1.0. For details, see 8 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 9 | Notice. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are met: 13 | 14 | • Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the disclaimer below. 16 | • Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the disclaimer (as noted below) in the 18 | documentation and/or other materials provided with the distribution. 19 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 20 | used to endorse or promote products derived from this software without specific 21 | prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 27 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 32 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | Additional BSD Notice 36 | 37 | 1. This notice is required to be provided under our contract with the U.S. 38 | Department of Energy (DOE). This work was produced at Lawrence Livermore 39 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 40 | 41 | 2. Neither the United States Government nor Lawrence Livermore National 42 | Security, LLC nor any of their employees, makes any warranty, express or 43 | implied, or assumes any liability or responsibility for the accuracy, 44 | completeness, or usefulness of any information, apparatus, product, or process 45 | disclosed, or represents that its use would not infringe privately-owned 46 | rights. 47 | 48 | 3. Also, reference herein to any specific commercial products, process, or 49 | services by trade name, trademark, manufacturer or otherwise does not 50 | necessarily constitute or imply its endorsement, recommendation, or favoring by 51 | the United States Government or Lawrence Livermore National Security, LLC. The 52 | views and opinions of authors expressed herein do not necessarily state or 53 | reflect those of the United States Government or Lawrence Livermore National 54 | Security, LLC, and shall not be used for advertising or product endorsement 55 | purposes. 56 | -------------------------------------------------------------------------------- /topoms-cli/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 2 | Produced at the Lawrence Livermore National Laboratory. 3 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 4 | (jediati@sci.utah.edu). 5 | LLNL-CODE-745278. All rights reserved. 6 | 7 | This file is part of TopoMS, Version 1.0. For details, see 8 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 9 | Notice. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are met: 13 | 14 | • Redistributions of source code must retain the above copyright notice, this 15 | list of conditions and the disclaimer below. 16 | • Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the disclaimer (as noted below) in the 18 | documentation and/or other materials provided with the distribution. 19 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 20 | used to endorse or promote products derived from this software without specific 21 | prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 27 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 32 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | Additional BSD Notice 36 | 37 | 1. This notice is required to be provided under our contract with the U.S. 38 | Department of Energy (DOE). This work was produced at Lawrence Livermore 39 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 40 | 41 | 2. Neither the United States Government nor Lawrence Livermore National 42 | Security, LLC nor any of their employees, makes any warranty, express or 43 | implied, or assumes any liability or responsibility for the accuracy, 44 | completeness, or usefulness of any information, apparatus, product, or process 45 | disclosed, or represents that its use would not infringe privately-owned 46 | rights. 47 | 48 | 3. Also, reference herein to any specific commercial products, process, or 49 | services by trade name, trademark, manufacturer or otherwise does not 50 | necessarily constitute or imply its endorsement, recommendation, or favoring by 51 | the United States Government or Lawrence Livermore National Security, LLC. The 52 | views and opinions of authors expressed herein do not necessarily state or 53 | reflect those of the United States Government or Lawrence Livermore National 54 | Security, LLC, and shall not be used for advertising or product endorsement 55 | purposes. 56 | -------------------------------------------------------------------------------- /msc/include/topological_regular_grid_restricted.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef TOPOLOGICAL_REGULAR_GRID_RESTRICTED_H 31 | #define TOPOLOGICAL_REGULAR_GRID_RESTRICTED_H 32 | 33 | 34 | #include "topological_regular_grid.h" 35 | #include "labeling.h" 36 | 37 | 38 | namespace MSC { 39 | 40 | class TopologicalRegularGridRestricted : virtual public TopologicalRegularGrid { 41 | 42 | protected: 43 | const DenseLabeling *m_restriction; 44 | 45 | public: 46 | TopologicalRegularGridRestricted(RegularGrid* base_grid) : 47 | TopologicalRegularGrid(base_grid), m_restriction(nullptr) { 48 | //printf(" -- Created TopologicalRegularGridRestricted \n"); 49 | } 50 | 51 | void set_restriction(const DenseLabeling *restriction) { 52 | m_restriction = restriction; 53 | } 54 | char restrictionLabel(INDEX_TYPE cellid) const { 55 | 56 | if (m_restriction == nullptr) { 57 | std::cerr << " restriction not set for TopologicalRegularGridRestricted!\n"; 58 | } 59 | return m_restriction->GetLabel(cellid); 60 | } 61 | 62 | BOUNDARY_TYPE boundaryValue(INDEX_TYPE cellid) const { 63 | 64 | //printf("TopologicalRegularGridRestricted::boundaryValue()\n"); 65 | 66 | // TopologicalRegularGrid::boundaryValue returns 0,1,2,3 67 | // m_restriction has labels 0 or 1.. so this function returns (0,1,2,3) or (4,5,6,7) 68 | 69 | // Harsh added the following conditional on 07.28.2018 to make this class 70 | // also work for unrestricted meshes 71 | BOUNDARY_TYPE bval = TopologicalRegularGrid::boundaryValue (cellid); 72 | if (m_restriction == nullptr) { return bval; } 73 | else { return bval + (m_restriction->GetLabel (cellid) * (maxDim()+1)); } 74 | } 75 | }; 76 | } // end of namespace 77 | #endif 78 | -------------------------------------------------------------------------------- /topoms-cli/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | #include "TopoMS.h" 60 | 61 | int main(int argc, char** argv) { 62 | 63 | if(argc != 2 && argc != 3){ 64 | printf(" Usage: %s [input_file]\n", argv[0]); 65 | return 1; 66 | } 67 | 68 | std::string configfilename = argv[1]; 69 | std::string infilename = (argc == 2) ? "" : argv[2]; 70 | 71 | TopoMS topoms; 72 | bool success = topoms.load(configfilename, infilename); 73 | if(!success) { 74 | return 1; 75 | } 76 | 77 | topoms.init(); 78 | 79 | if( topoms.bader() ) 80 | topoms.write_bader(); 81 | 82 | if( topoms.msc() ) 83 | topoms.write_msc(); 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /topoms-ui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # CMake file for TopoMS-UI 3 | # ------------------------------------------------------------------------------ 4 | 5 | cmake_minimum_required(VERSION 3.9) 6 | 7 | # ------------------------------------------------------------------------------ 8 | # OpenGL and Qt 9 | 10 | find_package(OpenGL REQUIRED) 11 | include_directories(${OPENGL_INCLUDE_DIRS}) 12 | 13 | find_package(Qt5 COMPONENTS Core Gui OpenGL Widgets Xml PrintSupport REQUIRED) 14 | set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets Qt5::Xml Qt5::PrintSupport) 15 | 16 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 17 | set(CMAKE_AUTOUIC ON) 18 | set(CMAKE_AUTOMOC ON) 19 | 20 | include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} 21 | ${Qt5OpenGL_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} 22 | ${Qt5Xml_INCLUDE_DIRS} ${Qt5PrintSupport_INCLUDE_DIRS}) 23 | 24 | 25 | # ------------------------------------------------------------------------------ 26 | # Glew 27 | # TODO: move this into a FindQGLViewer.cmake file 28 | OPTION(USE_GLEW "Use GLEW for opengl wrangling (Windows)" OFF) 29 | if (USE_GLEW) 30 | find_package(GLEW REQUIRED) 31 | include_directories(${GLEW_INCLUDE_DIRS}) 32 | add_definitions(-DUSE_GLEW) 33 | endif(USE_GLEW) 34 | 35 | 36 | # ------------------------------------------------------------------------------ 37 | # libQGLViewer 38 | # TODO: move this into a FindQGLViewer.cmake file 39 | 40 | find_path(QGLVIEWER_INCLUDE_DIR 41 | NAMES QGLViewer/qglviewer.h 42 | PATHS 43 | /usr/include 44 | /opt/local/include 45 | /usr/local/include 46 | /sw/include 47 | ${QGL_DIR}/include 48 | HINTS ${PATH_EXT}/include 49 | PATH_SUFFIXES Headers) 50 | 51 | find_library(QGLVIEWER_LIBRARY 52 | NAMES qglviewer QGLViewer qglviewer-qt5 QGLViewer-qt5 53 | PATHS 54 | /usr/lib 55 | /usr/local/lib 56 | /opt/local/lib 57 | /sw/lib 58 | ${QGL_DIR}/lib 59 | ENV LD_LIBRARY_PATH 60 | ENV LIBRARY_PATH 61 | HINTS ${PATH_EXT}/lib 62 | PATH_SUFFIXES QGLViewer QGLViewer/release) 63 | 64 | if (QGLVIEWER_INCLUDE_DIR) 65 | message(STATUS "Found QGLViewer include directory: " ${QGLVIEWER_INCLUDE_DIR}) 66 | include_directories(${QGLVIEWER_INCLUDE_DIR}) 67 | else() 68 | message(FATAL_ERROR "QGLViewer include directory not found.") 69 | endif() 70 | 71 | if (QGLVIEWER_LIBRARY) 72 | message(STATUS "Found QGLViewer library: " ${QGLVIEWER_LIBRARY}) 73 | else() 74 | message(FATAL_ERROR "QGLViewer library not found.") 75 | endif() 76 | 77 | 78 | # ------------------------------------------------------------------------------ 79 | # ui code 80 | 81 | include_directories(${PATH_MSC}/include ${PATH_TOPOMS}/include) 82 | include_directories(${PATH_UI}/include) 83 | 84 | file(GLOB HDRS_TOPOMSUI ${PATH_UI}/include/*.h) 85 | file(GLOB SRCS_TOPOMSUI ${PATH_UI}/src/*.cpp ${PATH_UI}/src/*.cxx) 86 | 87 | # ------------------------------------------------------------------------------ 88 | # create the ui application 89 | 90 | add_executable(${TRG_UI} ${HDRS_TOPOMSUI} ${SRCS_TOPOMSUI}) 91 | 92 | target_link_libraries(${TRG_UI} LINK_PUBLIC ${TRG_LIB}) 93 | target_link_libraries(${TRG_UI} LINK_PUBLIC 94 | ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ${QGLVIEWER_LIBRARY} ) 95 | if(USE_GLEW) 96 | target_link_libraries(${TRG_UI} LINK_PUBLIC ${GLEW_LIBRARIES}) 97 | endif(USE_GLEW) 98 | 99 | install(TARGETS ${TRG_UI} 100 | BUNDLE DESTINATION bin 101 | RUNTIME DESTINATION bin) 102 | 103 | # ------------------------------------------------------------------------------ 104 | 105 | -------------------------------------------------------------------------------- /msc/include/timing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef TIMING_H 31 | #define TIMING_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include "basic_types.h" 37 | 38 | 39 | namespace MSC { 40 | 41 | typedef std::chrono::time_point < std::chrono::high_resolution_clock> TIMEP; 42 | class ThreadedTimer { 43 | protected: 44 | struct Timing { 45 | int activity; 46 | TIMEP start_time; 47 | }; 48 | struct ThreadTimings { 49 | int thread_id; 50 | std::vector < Timing > timings; 51 | }; 52 | 53 | ThreadTimings* m_thread_timings; 54 | int m_num_threads; 55 | TIMEP m_global_start; 56 | TIMEP m_global_end; 57 | public: 58 | 59 | 60 | 61 | ThreadedTimer(int num_threads) : m_num_threads(num_threads) { 62 | m_thread_timings = new ThreadTimings[m_num_threads]; 63 | } 64 | 65 | void StartGlobal() { 66 | m_global_start = std::chrono::high_resolution_clock::now(); 67 | } 68 | 69 | void EndGlobal() { 70 | m_global_end = std::chrono::high_resolution_clock::now(); 71 | for (int i = 0; i < m_num_threads; i++) this->RecordThreadActivity(i, 0); 72 | } 73 | 74 | void PrintAll() { 75 | printf(" took %d ms\n", std::chrono::duration_cast(m_global_end - m_global_start).count()); 76 | } 77 | 78 | void PrintAllToFile(char* fname, const char** strings) { 79 | 80 | FILE* fout = fopen(fname, "w"); 81 | for (int i = 0; i < m_num_threads; i++) { 82 | ThreadTimings& tt = m_thread_timings[i]; 83 | for (int a = 0; a < tt.timings.size() - 1; a++) { 84 | fprintf(fout, "%d %d %d %s\n", i, 85 | std::chrono::duration_cast(tt.timings[a].start_time - m_global_start), 86 | std::chrono::duration_cast(tt.timings[a + 1].start_time - m_global_start), strings[tt.timings[a].activity]); 87 | 88 | 89 | } 90 | } 91 | 92 | fclose(fout); 93 | } 94 | void RecordThreadActivity(int thread_num, int activity) { 95 | Timing t = { activity, std::chrono::high_resolution_clock::now() }; 96 | m_thread_timings[thread_num].timings.push_back(t); 97 | } 98 | 99 | }; 100 | 101 | } 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /msc/include/labeling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef VERTEX_LABELING_H 31 | #define VERTEX_LABELING_H 32 | 33 | #include "basic_types.h" 34 | 35 | namespace MSC { 36 | template 37 | class DenseLabeling { 38 | protected: 39 | LABEL_TYPE* m_labels; 40 | INDEX_TYPE m_num_labels; 41 | public: 42 | 43 | DenseLabeling(INDEX_TYPE num_labels) : m_num_labels(num_labels) { 44 | m_labels = new LABEL_TYPE[num_labels]; 45 | //printf(" allocated space for %d values of size %d\n", num_labels, sizeof(LABEL_TYPE)); 46 | } 47 | ~DenseLabeling() { 48 | delete[] m_labels; 49 | } 50 | 51 | void SetLabel(INDEX_TYPE id, LABEL_TYPE label) { 52 | m_labels[id] = label; 53 | } 54 | 55 | LABEL_TYPE GetLabel(INDEX_TYPE id) const { 56 | return m_labels[id]; 57 | } 58 | 59 | INDEX_TYPE GetNumLabels() const { 60 | return m_num_labels; 61 | } 62 | 63 | LABEL_TYPE& operator[](const INDEX_TYPE id) { return m_labels[id]; } 64 | const LABEL_TYPE& operator[](const INDEX_TYPE id) const { return m_labels[id]; } 65 | 66 | void SetAll(LABEL_TYPE label){ 67 | #pragma omp parallel for schedule(static) 68 | for (int i = 0; i < m_num_labels; i++) { 69 | m_labels[i] = label; 70 | } 71 | } 72 | 73 | void ReadFromFile(const char* filename) { 74 | FILE* fout = fopen(filename, "rb"); 75 | fread(m_labels, sizeof(LABEL_TYPE), m_num_labels, fout); 76 | fclose(fout); 77 | } 78 | 79 | void OutputToFile(const char* filename) const { 80 | FILE* fout = fopen(filename, "wb"); 81 | //printf("Sizeof label type: %d\n", sizeof(LABEL_TYPE)); 82 | fwrite(m_labels, sizeof(LABEL_TYPE), m_num_labels, fout); 83 | fclose(fout); 84 | } 85 | void OutputToIntFile(const char* filename) const { 86 | FILE* fout = fopen(filename, "wb"); 87 | //printf("Sizeof int type: %d\n", sizeof(int)); 88 | for (INDEX_TYPE i = 0; i < m_num_labels; i++) { 89 | int tval = (int)m_labels[i]; 90 | fwrite(&tval, sizeof(int), 1, fout); 91 | } 92 | fclose(fout); 93 | } 94 | void OutputToFloatFile(const char* filename) const { 95 | FILE* fout = fopen(filename, "wb"); 96 | //printf("Sizeof float type: %d\n", sizeof(float)); 97 | for (INDEX_TYPE i = 0; i < m_num_labels; i++) { 98 | float tval = (float)m_labels[i]; 99 | fwrite(&tval, sizeof(float), 1, fout); 100 | } 101 | fclose(fout); 102 | } 103 | 104 | LABEL_TYPE* LabelArray() { return m_labels; } 105 | }; 106 | 107 | 108 | 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TopoMS, Version 1.1 2 | #### Released: Nov 18, 2018 3 | 4 | 5 | 6 | 7 | ##### Author: Harsh Bhatia, hbhatia@llnl.gov; Attila G Gyulassy 8 | 9 | TopoMS is a computational tool for detailed topological analysis of molecular 10 | and condensed matter systems, including the computation of atomic volumes and 11 | charges through the quantum theory of atoms in molecules (also known as Bader 12 | analysis), as well as the complete molecular graph. With roots in techniques 13 | from computational topology, and using a shared-memory parallel approach, 14 | TopoMS provides scalable, numerically robust, and topologically consistent 15 | analysis. 16 | 17 | If you use TopoMS, please cite the following publication. 18 | * H Bhatia, A G Gyulassy, V Lordi, J E Pask, V Pascucci, and P-T Bremer, 19 | "TopoMS: Comprehensive Topological Exploration for Molecular and Condensed-Matter Systems," 20 | Journal of Computational Chemistry, vol. 39, issue 16, pp 936–952, June 2018. 21 | [doi:10.1002/jcc.25181](https://doi.org/10.1002/jcc.25181). 22 | 23 | TopoMS can be used as a command-line tool (`./topoms`) or with a GUI 24 | (`./topoms-ui`), where the latter also enables an interactive exploration of 25 | the molecular graph. 26 | 27 | TopoMS requires a configuration file to provide several important parameters 28 | for analysis. Both applications take a single command-line input -- the 29 | configuration file name. A detailed example of configuration file is 30 | provided in the `./configs` folder. 31 | 32 | ### Installation 33 | 34 | * TopoMS requires a `gnu` C++ compiler (preferably `gcc 7.3`). Note that for Mac, 35 | the default `gcc` is in fact `clang`. Unless you have it configured otherwise, 36 | you need to set the path of `gnu` compiler explicitly (see below). 37 | 38 | * In addition, `TopoMS-UI` requires the following to support visualization and 39 | user interface. TopoMS assumes the following are available on your machine. 40 | * `Qt 5.7`: Note that Qt often changes the API substantially between versions; 41 | please use the recommended version. Qt is available through a number of 42 | package managers. For example, for Mac, you can use `macports` to get Qt: 43 | `port install qt57`. Or you may install Qt from source. See [here](http://doc.qt.io/qt-5/linux.html#downloading-and-installing-qt) and 44 | [here](http://doc.qt.io/qt-5/linux-building.html). 45 | * `OpenGL`: Comes pre-installed on your machine. 46 | * `GLEW 2.1.0`: Extension Wrangler for OpenGL. Also available through common 47 | package managers. For Mac, `GLEW` is available via 48 | `macports`: `port install glew`. You may also install it from source. See [here](http://glew.sourceforge.net/build.html). 49 | 50 | * Visualization Toolkit (VTK): `TopoMS` requires VTK in order to output 51 | molecular graphs. Although optional, `VTK 7.1.1` is strongly suggested as a 52 | dependency. 53 | 54 | * Finally, `TopoMS-UI` also uses `QGLViewer 2.7` for visualization. See [here](http://libqglviewer.com/download.html). 55 | 56 | To simplify installation, scripts have been provided to build `TopoMS` as well 57 | as `TopoMS-UI` along with their dependencies (`VTK` and `QGLViewer`). Please see 58 | the usage below. Additional instructions for individual installation are 59 | provided separately in the respective folders, `topoms` and `topoms-ui`. 60 | 61 | ``` 62 | $ pwd 63 | /TopoMS 64 | $ export GNU_CXX=/opt/local/bin/g++ # example path; needed only for Mac 65 | $ sh install.topoms.sh 66 | $ sh install.topoms-ui.sh 67 | ``` 68 | 69 | `TopoMS` executables will be installed in `/TopoMS/build`, and 70 | dependencies (`VTK` and `QGLViewer`) will be installed in 71 | `/TopoMS/external`. 72 | 73 | **Note:** The provided scripts have been tested on Mac OS 10.13 and Red Hat linux. 74 | Support for installation on Windows will be provided in the future. 75 | 76 | ### Examples 77 | 78 | * Bader volumes of the atoms in Ethylene molecule 79 | 80 | 81 | 82 | * Complete molecular graph of a lithium salt (LiPF6) in Ethylene Carbonate solution 83 | 84 | 85 | 86 | ### License 87 | 88 | TopoMS is released under dual license. 89 | 90 | - BSD 91 | - The core functionality, `./topoms`, is released under BSD license by LLNL. 92 | - The MSC library, `./msc`, is released under BSD license by University of Utah. 93 | - GPL 94 | - The UI application, `./topoms-ui`, is released under GPL by LLNL. 95 | 96 | Please see the respective directories on more details about corresponding licenses. 97 | -------------------------------------------------------------------------------- /topoms/include/MSCBond.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file MSCBond.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2018 63 | * 64 | * @brief This file provides a class for analyzing a bond. 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This file provides a class for analyzing a bond. 69 | * 70 | */ 71 | 72 | #ifndef _MSCBOND_H_ 73 | #define _MSCBOND_H_ 74 | 75 | #include 76 | #include 77 | 78 | #include "basic_types.h" 79 | #include "vectors.h" 80 | 81 | namespace MS { 82 | class SystemInfo; 83 | } 84 | 85 | /** 86 | * @brief This struct provides a colleciton of utilities to handle MSC bonds 87 | */ 88 | struct MSCBond { 89 | 90 | // saddle node id and MSC coordinates 91 | INT_TYPE saddle; 92 | MSC::Vec3d scoords; 93 | 94 | // extrema ids and MSC coordiantes 95 | std::vector extrema; 96 | std::vector ecoords; 97 | 98 | // the corresponding atoms (starting with 1) 99 | std::vector atomIds; 100 | 101 | // geometric representation of paths 102 | std::vector> paths; 103 | 104 | // parameterization of the path 105 | std::vector> parameterization; 106 | 107 | // integrated charge and area (at the saddle) 108 | double ichg, iarea; 109 | 110 | // integrated charge and area along the path (indexed into the parameterization) 111 | std::vector bichg, biarea; 112 | 113 | // charge at the bond path 114 | std::vector bchg; 115 | 116 | // ------------------------------------------------------------------------- 117 | static void fix_periodic(MSC::Vec3d &p, const MSC::Vec3d &orig, const size_t dims[3]); 118 | 119 | // ------------------------------------------------------------------------- 120 | MSCBond(INT_TYPE _saddle=-1) : saddle(_saddle), ichg(-1), iarea(-1) {} 121 | 122 | void print() const; 123 | bool check2() const; 124 | void parameterize(const MS::SystemInfo &metadata); 125 | void get_points(MSC::Vec3d &origin, std::vector &nbrs, const size_t dims[], float p) const; 126 | void get_points_idx(MSC::Vec3d &origin, std::vector &nbrs, const size_t dims[], int pidx) const; 127 | }; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /scripts/plot_bondStats.py: -------------------------------------------------------------------------------- 1 | import re 2 | import argparse 3 | import numpy as np 4 | import operator 5 | import matplotlib.pyplot as plt 6 | 7 | class BondInfo: 8 | 9 | def __init__(self): 10 | 11 | self.id = 0 12 | self.pos = [0.,0.,0.] 13 | 14 | self.atomid = [0,0] 15 | self.atomsymb = ['.','.'] 16 | self.atompos = [[0.,0.,0.], [0.,0.,0.]] 17 | 18 | self.area = 0 19 | self.chg = 0 20 | 21 | self.p = [] 22 | self.val = [] 23 | self.ichg = [] 24 | self.iarea = [] 25 | 26 | def title(self): 27 | return '[{}-{} == {}-{}]'.format(self.atomsymb[0], self.atomid[0], self.atomsymb[1], self.atomid[1]) 28 | 29 | def organize(self, l, r): 30 | 31 | if self.atomsymb[0] in l and self.atomsymb[1] in r: 32 | return 33 | 34 | self.atomsymb[0],self.atomsymb[1] = self.atomsymb[1],self.atomsymb[0] 35 | self.atomid[0],self.atomid[1] = self.atomid[1],self.atomid[0] 36 | self.atompos[0],self.atompos[1] = self.atompos[1],self.atompos[0] 37 | 38 | self.p = list(reversed(self.p)) 39 | self.val = list(reversed(self.val)) 40 | 41 | def disp(self): 42 | print 'bond', self.id, 'connects to', self.atomid, ':', self.atomsymb, ':', 43 | print 'area =', self.area, 'chg =', self.chg, 44 | 45 | l = len(self.p) 46 | print ' #vals =', l, 47 | if l > 0: 48 | print ': [', min(self.p), max(self.p), ']', 49 | print '[', min(self.val), max(self.val), ']', 50 | #print '[', min(self.ichg), max(self.ichg), ']', 51 | #print '[', min(self.iarea), max(self.iarea), ']' 52 | else: 53 | print '' 54 | 55 | def replace(str, delims): 56 | for d in delims: 57 | str = str.replace(d, ' ') 58 | return str 59 | 60 | def read_bondStats(infilename): 61 | 62 | text_file = open(infilename, 'r') 63 | lines = text_file.read().split('\n') 64 | text_file.close() 65 | 66 | bonds = [] 67 | s = None 68 | nlines = len(lines) 69 | 70 | lidx = 0 71 | while(True): 72 | 73 | if lidx >= nlines: 74 | break 75 | 76 | l = lines[lidx] 77 | #print lidx, l, len(l) 78 | 79 | if 'bond_critical_point' in l: 80 | 81 | if s != None: 82 | s.organize(['Ca'], ['Cl']) 83 | s.disp() 84 | bonds.append(s) 85 | 86 | s = BondInfo() 87 | 88 | # read the saddle info from the current line 89 | tokens = replace(l, '[]()').split(' ') 90 | s.id = int(tokens[4]) 91 | for i in xrange(3): 92 | s.pos[i] = float(tokens[8+i]) 93 | 94 | # next two lines will give info about atoms 95 | for a in xrange(2): 96 | lidx += 1 97 | l = lines[lidx] 98 | tokens = replace(l, '[]()').split(' ') 99 | s.atomid[a] = int(tokens[7]) 100 | s.atomsymb[a] = tokens[9] 101 | for i in xrange(3): 102 | s.atompos[a][i] = float(tokens[11+i]) 103 | 104 | # next line will give charge and area 105 | lidx += 1 106 | l = lines[lidx] 107 | tokens = replace(l,',').split(' ') 108 | s.area = float(tokens[4]) 109 | s.chg = float(tokens[7]) 110 | 111 | elif len(l) > 0: 112 | l = [float(k) for k in l.split(',')] 113 | s.p.append(l[0]) 114 | s.val.append(l[1]) 115 | #s.ichg.append(l[2]) 116 | #s.iarea.append(l[3]) 117 | 118 | lidx += 1 119 | 120 | s.organize(['Ca'], ['Cl']) 121 | s.disp() 122 | bonds.append(s) 123 | 124 | #print 'read', len(bonds), 'bonds' 125 | return bonds 126 | 127 | 128 | def plot_bonds(bonds, type): 129 | 130 | assert type in [0,1,2] 131 | 132 | labels = ['Ca','Ca','Cl','Cl','Cl','Cl'] 133 | colors = ['black', 'red', 'green', 'blue', 'yellow', 'cyan'] 134 | atoms = [] 135 | 136 | #plt.figure(figsize=(8,6)) 137 | plt.figure() 138 | for s in bonds: 139 | 140 | x = s.p 141 | if type == 0: 142 | y = s.val 143 | elif type == 1: 144 | y = s.ichg 145 | elif type == 2: 146 | y = s.iarea 147 | 148 | plt.semilogy(x, y, linewidth=1, alpha=0.5) #linestyle='--', label=s.title()) 149 | 150 | atoms.append([s.atomid[0], x[0],y[0]]) 151 | atoms.append([s.atomid[1], x[-1],y[-1]]) 152 | 153 | atoms.sort(key = operator.itemgetter(0)) 154 | atoms = np.array(atoms) 155 | atoms[:,1] = atoms[:,1].round(decimals=2) 156 | atoms[:,2] = atoms[:,2].round(decimals=6) 157 | atoms = np.unique(atoms, axis=0) 158 | 159 | 160 | for id in xrange(1,7): 161 | ids = np.where(atoms[:,0] == id)[0] 162 | plt.scatter(atoms[ids,1],atoms[ids,2], c=colors[id-1], label=labels[id-1], alpha=0.5) 163 | 164 | 165 | plt.legend(loc=3) 166 | plt.xlim([-2,2]) 167 | plt.xlabel('distance from saddle along bond path (in Angstroms)') 168 | 169 | if type == 0: 170 | plt.ylabel('charge (number of electrons)') 171 | elif type == 1: 172 | plt.ylabel('integrated charge (number of electrons)') 173 | elif type == 2: 174 | plt.ylabel('integrated area') 175 | 176 | 177 | if __name__ == '__main__': 178 | 179 | parser = argparse.ArgumentParser(description='Plot bond statistics output from TopoMS') 180 | 181 | parser.add_argument('--infile', metavar='(infile)', required=True, nargs=1, help='Input stats file') 182 | args = parser.parse_args() 183 | 184 | bonds = read_bondStats(args.infile[0]) 185 | 186 | # -------------------------------------------------------------------------- 187 | # plot all bonds 188 | outfile = args.infile[0][:-4] 189 | 190 | plot_bonds(bonds, 0) 191 | plt.savefig(outfile+'_chg.pdf') 192 | print 'Saved plot:', outfile+'_chg.pdf' 193 | 194 | ''' 195 | plot_bonds(bonds, 1) 196 | plt.savefig(outfile+'_ichg.pdf') 197 | print 'Saved plot:', outfile+'_ichg.pdf' 198 | 199 | plot_bonds(bonds, 2) 200 | plt.savefig(outfile+'_iarea.pdf') 201 | print 'Saved plot:', outfile+'_iarea.pdf' 202 | ''' 203 | # -------------------------------------------------------------------------- 204 | -------------------------------------------------------------------------------- /topoms/src/Utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file Utils.cpp 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2017 63 | * 64 | * @brief This file provides some basic utility functions 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This file provides some basic utility functions 69 | * 70 | */ 71 | 72 | #include 73 | #include 74 | #include 75 | #include 76 | 77 | #ifndef _WIN32 78 | #include 79 | #include 80 | #endif 81 | 82 | #include "Utils.h" 83 | 84 | void Utils::print_separator(unsigned int n) { 85 | 86 | #ifndef _WIN32 87 | struct winsize w; 88 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); 89 | n = w.ws_col; 90 | #else 91 | n = 40; 92 | #endif 93 | for(int i=0; i Utils::tokenize(const std::string &line, char delim) { 152 | 153 | std::vector tokens; 154 | 155 | std::stringstream ss; 156 | ss.str(line); 157 | 158 | std::string item; 159 | while (std::getline(ss, item, delim)) { 160 | tokens.push_back( item ); 161 | } 162 | return tokens; 163 | } 164 | 165 | std::vector Utils::tokenize(std::string line){ 166 | 167 | // construct a stream from the string 168 | std::stringstream linestream(line); 169 | 170 | // use stream iterators to copy the stream to the vector as whitespace separated strings 171 | std::istream_iterator it_line(linestream); 172 | std::istream_iterator end_line; 173 | std::vector tokens(it_line, end_line); 174 | return tokens; 175 | } 176 | -------------------------------------------------------------------------------- /msc/include/msc_iterators.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef MSC_ITERATORS_H 31 | #define MSC_ITERATORS_H 32 | 33 | #include 34 | #include "morse_smale_complex_basic.h" 35 | #include "topological_regular_grid.h" 36 | 37 | namespace MSC { 38 | 39 | // ----------------------------------------------------------------------------- 40 | // node and arc iterators 41 | // ----------------------------------------------------------------------------- 42 | 43 | template 44 | class MSCIteratorNodes { 45 | protected: 46 | MSCType* mMSC; 47 | INT_TYPE currid; 48 | 49 | public: 50 | MSCIteratorNodes(MSCType* msc) : mMSC(msc){} 51 | void begin() { currid = 0; } 52 | void advance() { currid++; } 53 | INT_TYPE value() { return currid; } 54 | bool valid() { return currid < mMSC->nodes.size(); } 55 | }; 56 | 57 | // ----------------------------------------------------------------------------- 58 | template 59 | class MSCIteratorLivingNodes : public MSCIteratorNodes { 60 | protected: 61 | void advance_until_alive() { 62 | this->currid++; 63 | while (this->valid() && !this->mMSC->isNodeAlive(this->currid)) { 64 | this->currid++; 65 | } 66 | } 67 | public: 68 | MSCIteratorLivingNodes(MSCType* msc) : MSCIteratorNodes(msc) {} 69 | void begin() { 70 | MSCIteratorNodes::begin(); 71 | if (this->valid() && !this->mMSC->isNodeAlive(this->currid)) 72 | advance_until_alive(); 73 | } 74 | void advance() { 75 | advance_until_alive(); 76 | } 77 | }; 78 | 79 | // ----------------------------------------------------------------------------- 80 | template 81 | class MSCIteratorArcs { 82 | protected: 83 | MSCType* mMSC; 84 | INT_TYPE currid; 85 | 86 | public: 87 | MSCIteratorArcs(MSCType* msc) : mMSC(msc){} 88 | void begin() { currid = 0; } 89 | void advance() { currid++; } 90 | INT_TYPE value() { return currid; } 91 | bool valid() { return currid < mMSC->arcs.size(); } 92 | }; 93 | 94 | // ----------------------------------------------------------------------------- 95 | template 96 | class MSCIteratorLivingArcs : public MSCIteratorArcs { 97 | protected: 98 | void advance_until_alive() { 99 | this->currid++; 100 | while (this->valid() && !this->mMSC->isArcAlive(this->currid)) { 101 | this->currid++; 102 | } 103 | } 104 | public: 105 | MSCIteratorLivingArcs(MSCType* msc) : MSCIteratorArcs(msc) {} 106 | void begin() { 107 | MSCIteratorArcs::begin(); 108 | if (this->valid() && !this->mMSC->isNodeAlive(this->currid)) 109 | advance_until_alive(); 110 | } 111 | void advance() { 112 | advance_until_alive(); 113 | } 114 | }; 115 | 116 | // ----------------------------------------------------------------------------- 117 | template 118 | class MSCIteratorSurroundingArcs { 119 | protected: 120 | MSCType* mMSC; 121 | INT_TYPE mNID; 122 | INT_TYPE currarc; 123 | INT_TYPE next_arc(INT_TYPE arcid) { 124 | return mMSC->nextArc(mMSC->getArc(arcid), mNID); 125 | } 126 | 127 | public: 128 | MSCIteratorSurroundingArcs(MSCType* msc) : mMSC(msc){} 129 | 130 | bool valid() { return currarc != NULLID; } 131 | INT_TYPE value() { return currarc; } 132 | 133 | void begin(INT_TYPE nid) { 134 | mNID = nid; 135 | node& n = mMSC->getNode(mNID); 136 | currarc = n.firstarc; 137 | } 138 | void advance() { 139 | if (currarc == NULLID) return; 140 | currarc = next_arc(currarc); 141 | } 142 | }; 143 | 144 | // ----------------------------------------------------------------------------- 145 | template 146 | class MSCIteratorSurroundingLivingArcs : public MSCIteratorSurroundingArcs { 147 | protected: 148 | bool advance_until_alive() { 149 | this->currarc = this->next_arc(this->currarc); 150 | if (this->currarc == NULLID) return false; 151 | while (!this->mMSC->isArcAlive(this->currarc)) { 152 | this->currarc = next_arc(this->currarc); 153 | if (this->currarc == NULLID) return false; 154 | } 155 | return true; 156 | } 157 | public: 158 | MSCIteratorSurroundingLivingArcs(MSCType* msc) : MSCIteratorSurroundingArcs(msc) {} 159 | void begin(INT_TYPE nid) { 160 | MSCIteratorSurroundingArcs::begin(nid); 161 | if (!this->mMSC->isArcAlive(this->currarc)) advance_until_alive(); 162 | } 163 | void advance() { 164 | if (this->currarc == NULLID) return; 165 | advance_until_alive(); 166 | } 167 | }; 168 | 169 | } // end of namespace 170 | #endif 171 | -------------------------------------------------------------------------------- /topoms/include/Vec3.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file Vec3.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2017 63 | * 64 | * @brief This class handles 3-dimensional vector objects 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This class handles 3-dimensional vector objects 69 | * 70 | */ 71 | 72 | #ifndef _VEC3_H_ 73 | #define _VEC3_H_ 74 | 75 | #include 76 | #include 77 | 78 | template 79 | class Vec3 { 80 | 81 | private: 82 | T v[3]; 83 | 84 | public: 85 | Vec3() { v[0] = v[1] = v[2] = T(0); } 86 | Vec3(T x, T y, T z) { v[0] = x; v[1] = y; v[2] = z; } 87 | 88 | T& operator[](int i) { return v[i]; } 89 | const T& operator[](int i) const { return v[i]; } 90 | 91 | inline T magnSq() const { return (v[0] * v[0]) + (v[1] * v[1]) + (v[2] * v[2]); } 92 | inline T magn() const { return sqrt(magnSq()); } 93 | 94 | void operator=(const Vec3& other){ 95 | this->v[0] = other.v[0]; 96 | this->v[1] = other.v[1]; 97 | this->v[2] = other.v[2]; 98 | } 99 | void operator+=(const Vec3& other) { 100 | this->v[0] += other.v[0]; 101 | this->v[1] += other.v[1]; 102 | this->v[2] += other.v[2]; 103 | } 104 | void operator-=(const Vec3& other) { 105 | this->v[0] -= other.v[0]; 106 | this->v[1] -= other.v[1]; 107 | this->v[2] -= other.v[2]; 108 | } 109 | Vec3 operator+(const Vec3 &a) const { 110 | Vec3 res(*this); 111 | res += a; 112 | return res; 113 | } 114 | Vec3 operator-(const Vec3 &a) const { 115 | Vec3 res(*this); 116 | res -= a; 117 | return res; 118 | } 119 | Vec3 operator+(const T val) const { 120 | Vec3 res(*this); 121 | res.v[0] += val; res.v[1] += val; res.v[2] += val; 122 | return res; 123 | } 124 | Vec3 operator*(const T val) const { 125 | Vec3 res(this->v[0], this->v[1], this->v[2]);// = (*this); 126 | res.v[0] *= val; res.v[1] *= val; res.v[2] *= val; 127 | return res; 128 | } 129 | bool operator==(const Vec3& other) const { 130 | return memcmp(this, &other, sizeof(Vec3)) == 0; 131 | } 132 | 133 | // THIS GIVES REMAINDER, NOT MODULO 134 | Vec3 operator%(const Vec3& other) const{ 135 | Vec3 res; 136 | res.v[0] = this->v[0] % other.v[0]; 137 | res.v[1] = this->v[1] % other.v[1]; 138 | res.v[2] = this->v[2] % other.v[2]; 139 | return res; 140 | } 141 | 142 | operator Vec3() const { return Vec3(this->v[0], this->v[1], this->v[2]); } 143 | operator Vec3() const { return Vec3(this->v[0], this->v[1], this->v[2]); } 144 | 145 | // linear interpolation betwee 2 vectors: returns the vector a * (1-t) + b * t 146 | static Vec3 lerp(const Vec3& a, const Vec3& b, const double t) { 147 | return (a * (1.0 - t)) + (b * (t)); 148 | } 149 | 150 | void print_vi() const { 151 | printf("(%d, %d, %d)\n", v[0], v[1], v[2]); 152 | } 153 | void print_vf() const { 154 | printf("(%f, %f, %f)\n", v[0], v[1], v[2]); 155 | } 156 | 157 | // this is a hack that rounds towards -infinity for "small" negative values 158 | Vec3 int_floor() const { 159 | Vec3 dres = *this; 160 | dres = dres + 1000.0; 161 | Vec3 ires = dres; 162 | ires = ires + -1000; 163 | return ires; 164 | } 165 | }; 166 | 167 | 168 | typedef Vec3 Vec3i; 169 | typedef Vec3 Vec3b; 170 | typedef Vec3 Vec3f; 171 | typedef Vec3 Vec3d; 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /topoms/include/Mat3.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file Vec3.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2018 63 | * 64 | * @brief This class handles 3x3 matrix objects 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This class handles 3x3 matrix objects 69 | * 70 | */ 71 | 72 | #ifndef _MAT3_H_ 73 | #define _MAT3_H_ 74 | 75 | #include 76 | #include 77 | #include 78 | 79 | #include "Vec3.h" 80 | 81 | template 82 | class Mat3 { 83 | 84 | public: 85 | T v[3][3]; 86 | 87 | public: 88 | Mat3() { 89 | for(uint8_t i = 0; i < 3; i++) 90 | for(uint8_t j = 0; j < 3; j++) 91 | v[i][j] = T(0); 92 | } 93 | 94 | void eye() { 95 | for(uint8_t i = 0; i < 3; i++) 96 | for(uint8_t j = 0; j < 3; j++) 97 | v[i][j] = T(0); 98 | 99 | for(uint8_t i = 0; i < 3; i++) 100 | v[i][i] = T(1); 101 | } 102 | 103 | bool is_eye() const { 104 | 105 | Mat3 m; m.eye(); 106 | for(uint8_t i = 0; i < 3; i++) 107 | for(uint8_t j = 0; j < 3; j++){ 108 | if (fabs(v[i][j] - m.v[i][j]) > 0.0000001) 109 | return false; 110 | } 111 | return true; 112 | } 113 | 114 | bool is_cuboid() const { 115 | 116 | for(uint8_t i = 0; i < 3; i++) 117 | for(uint8_t j = 0; j < 3; j++){ 118 | if (i == j) { 119 | continue; 120 | } 121 | if (fabs(v[i][j]) > 0.0000001) 122 | return false; 123 | } 124 | return true; 125 | } 126 | T determinant() const { 127 | return v[0][0]*(v[1][1]*v[2][2] - v[1][2]*v[2][1]) 128 | - v[0][1]*(v[1][0]*v[2][2] - v[1][2]*v[2][0]) 129 | + v[0][2]*(v[1][0]*v[2][1] - v[1][1]*v[2][1]); 130 | } 131 | Mat3 inverse() const { 132 | 133 | Mat3 inv; 134 | double det = determinant(); 135 | if (fabs(det) < 0.000001) { 136 | std::cerr << "Cannot compute inverse for singular matrix!\n"; 137 | inv.eye(); 138 | return inv; 139 | } 140 | 141 | det = 1.0/det; 142 | inv.v[0][0] = det*(v[1][1]*v[2][2] - v[1][2]*v[2][1]); 143 | inv.v[0][1] = det*(v[0][2]*v[2][1] - v[0][1]*v[2][2]); 144 | inv.v[0][2] = det*(v[0][1]*v[1][2] - v[0][2]*v[1][1]); 145 | inv.v[1][0] = det*(v[1][2]*v[2][0] - v[1][0]*v[2][2]); 146 | inv.v[1][1] = det*(v[0][0]*v[2][2] - v[0][2]*v[2][0]); 147 | inv.v[1][2] = det*(v[0][2]*v[1][0] - v[0][0]*v[1][2]); 148 | inv.v[2][0] = det*(v[1][0]*v[2][1] - v[1][1]*v[2][0]); 149 | inv.v[2][1] = det*(v[0][1]*v[2][0] - v[0][0]*v[2][1]); 150 | inv.v[2][2] = det*(v[0][0]*v[1][1] - v[0][1]*v[1][0]); 151 | return inv; 152 | } 153 | 154 | void transform(const T in[3], T out[3]) const { 155 | for(uint8_t d = 0; d < 3; d++){ 156 | out[d] = in[0]*v[0][d] + in[1]*v[1][d] + in[2]*v[2][d]; 157 | } 158 | } 159 | 160 | Vec3 transform(const T in[3]) const { 161 | Vec3 out; 162 | for(uint8_t d = 0; d < 3; d++){ 163 | out[d] = in[0]*v[0][d] + in[1]*v[1][d] + in[2]*v[2][d]; 164 | } 165 | return out; 166 | } 167 | 168 | Vec3 transform(const Vec3 &in) const { 169 | Vec3 out; 170 | for(uint8_t d = 0; d < 3; d++){ 171 | out[d] = in[0]*v[0][d] + in[1]*v[1][d] + in[2]*v[2][d]; 172 | } 173 | return out; 174 | } 175 | 176 | std::vector linearize(bool homogenous = false) const { 177 | 178 | const size_t sz = (homogenous) ? 4 : 3; 179 | std::vector mat (sz*sz, T(0)); 180 | 181 | for(uint8_t r = 0; r < 3; r++) 182 | for(uint8_t c = 0; c < 3; c++) 183 | mat[sz*c + r] = v[r][c]; 184 | 185 | if (homogenous) { mat[15] = T(1); } 186 | return mat; 187 | } 188 | }; 189 | 190 | #endif 191 | -------------------------------------------------------------------------------- /topoms/include/MultilinearInterpolator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file MultilinearInterpolator.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 05/12/2017 63 | * 64 | * @brief This file provides a templated interpolator 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This file provides a templated interpolator 69 | * 70 | */ 71 | 72 | #ifndef _MLINEARINTERP_H_ 73 | #define _MLINEARINTERP_H_ 74 | 75 | #include 76 | #include 77 | #include 78 | 79 | #ifdef USE_VTK 80 | #include 81 | #include 82 | #include 83 | #include 84 | #endif 85 | 86 | // lerp based on lambda 87 | class MultilinearInterpolator { 88 | public: 89 | template 90 | static inline T lerp (T2 l, T f0, T f1) { 91 | return (1.0 - l)*f0 + l*f1; 92 | } 93 | template 94 | static inline T lerp2(T2 lx, T2 ly, T f00, T f01, T f10, T f11) { 95 | return lerp(ly, 96 | lerp(lx, f00, f01), 97 | lerp(lx, f10, f11)); 98 | } 99 | template 100 | static inline T lerp3(T2 lx, T2 ly, T2 lz, 101 | T f000, T f010, T f100, T f110, 102 | T f001, T f011, T f101, T f111) { 103 | return lerp(lz, 104 | lerp2(lx, ly, f000, f010, f100, f110), 105 | lerp2(lx, ly, f001, f011, f101, f111)); 106 | } 107 | 108 | template 109 | static inline T trilinear_interpolation(const T pos[3], const T *data, const size_t dims[3]) { 110 | 111 | // get a corner pixel and gather the barycentric 112 | size_t o[3]; 113 | double l[3]; 114 | for(unsigned d = 0; d < 3; d++){ 115 | l[d] = pos[d] - std::floor(pos[d]); 116 | o[d] = std::floor(pos[d]); 117 | } 118 | 119 | // gather the eight corners 120 | std::vector vals; 121 | vals.reserve(8); 122 | for(uint8_t iz = 0; iz <= 1; iz++){ 123 | for(uint8_t iy = 0; iy <= 1; iy++){ 124 | for(uint8_t ix = 0; ix <= 1; ix++){ 125 | 126 | // check perioudic boundary 127 | size_t z = iz+o[2]; 128 | size_t y = iy+o[1]; 129 | size_t x = ix+o[0]; 130 | 131 | if (z >= dims[2]) z -= dims[2]; 132 | if (y >= dims[1]) y -= dims[1]; 133 | if (x >= dims[0]) x -= dims[0]; 134 | 135 | size_t idx = z*dims[1]*dims[0] + y*dims[0] + x; 136 | vals.push_back(data[idx]); 137 | } 138 | } 139 | } 140 | 141 | return lerp3(l[0], l[1], l[2], vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7]); 142 | } 143 | 144 | #ifdef USE_VTK 145 | template 146 | static inline T trilinear_interpolation(const T pos[3], vtkImageData *volume) { 147 | 148 | int *dims = volume->GetDimensions(); 149 | 150 | // get a corner pixel and gather the barycentric 151 | size_t o[3]; 152 | double l[3]; 153 | for(unsigned d = 0; d < 3; d++){ 154 | l[d] = pos[d] - std::floor(pos[d]); 155 | o[d] = std::floor(pos[d]); 156 | } 157 | 158 | // gather the eight corners 159 | std::vector vals; 160 | vals.reserve(8); 161 | for(uint8_t iz = 0; iz <= 1; iz++){ 162 | for(uint8_t iy = 0; iy <= 1; iy++){ 163 | for(uint8_t ix = 0; ix <= 1; ix++){ 164 | 165 | // check perioudic boundary 166 | size_t z = iz+o[2]; 167 | size_t y = iy+o[1]; 168 | size_t x = ix+o[0]; 169 | 170 | if (z >= dims[2]) z -= dims[2]; 171 | if (y >= dims[1]) y -= dims[1]; 172 | if (x >= dims[0]) x -= dims[0]; 173 | 174 | size_t idx = z*dims[1]*dims[0] + y*dims[0] + x; 175 | vals.push_back(volume->GetPointData()->GetScalars()->GetComponent(idx, 0)); 176 | } 177 | } 178 | } 179 | 180 | return lerp3(l[0], l[1], l[2], vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7]); 181 | } 182 | #endif 183 | }; 184 | #endif 185 | -------------------------------------------------------------------------------- /msc/include/isolated_region_remover.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef ISOLATED_REGION_REMOVER_H 31 | #define ISOLATED_REGION_REMOVER_H 32 | 33 | 34 | #include "basic_types.h" 35 | #include "vectors.h" 36 | #include "labeling.h" 37 | #include "regular_grid.h" 38 | #include "regular_grid_trilinear_function.h" 39 | #include "adaptive_euler_advector.h" 40 | 41 | 42 | 43 | namespace MSC { 44 | template< class Comparer> 45 | class IsolatedRegionRemover { 46 | 47 | protected: 48 | DenseLabeling* m_input; 49 | DenseLabeling* m_destinations; 50 | const RegularGrid* m_grid; 51 | RegularGridTrilinearFunction* m_func; 52 | 53 | 54 | 55 | 56 | // if the vertex is a max, return own index 57 | // if the vertex has a higher neighbor with same label, return that (or highest such) 58 | // if the vertex does not have higher with same label, return highest id 59 | INDEX_TYPE GetHighestUpVertexIn6Neighborhood(INDEX_TYPE id) const { 60 | Vec3l t_neighbors[6]; 61 | Vec3l t_coords = m_grid->XYZ3d(id); 62 | int t_num_neighbors = m_grid->GatherExistingNeighbors6(t_coords, t_neighbors); 63 | 64 | bool has_samelabel_higher = false; 65 | bool is_max = true; 66 | INDEX_TYPE t_overall_highest = id; 67 | INDEX_TYPE t_highest_same_label = id; 68 | 69 | for (int i = 0; i < t_num_neighbors; i++) { 70 | INDEX_TYPE t_neighbor_vertex = m_grid->Index3d(t_neighbors[i]); 71 | if (mCompare->Compare(t_neighbor_vertex, t_overall_highest)) { 72 | t_overall_highest = t_neighbor_vertex; 73 | is_max = false; 74 | } 75 | if (m_input->GetLabel(id) == m_input->GetLabel(t_neighbor_vertex) && 76 | mCompare->Compare(t_neighbor_vertex, t_highest_same_label)) { 77 | t_highest_same_label = t_neighbor_vertex; 78 | has_samelabel_higher = true; 79 | } 80 | } 81 | if (is_max) return id; 82 | if (has_samelabel_higher) return t_highest_same_label; 83 | return t_overall_highest; 84 | } 85 | 86 | 87 | INDEX_TYPE PathCompressFind(INDEX_TYPE id) { 88 | if (m_destinations->GetLabel(id) == id) return id; 89 | INDEX_TYPE retval = PathCompressFind(m_destinations->GetLabel(id)); 90 | INDEX_TYPE idref = m_destinations->operator[](id); 91 | #pragma omp atomic 92 | m_destinations->operator[](id) += retval - idref; // this is stupid - openmp 2.0 supports only binops= for atomics 93 | return retval; 94 | } 95 | 96 | Comparer* mCompare; 97 | 98 | public: 99 | IsolatedRegionRemover(RegularGridTrilinearFunction* func, DenseLabeling* input) : 100 | m_input(input), m_func(func) { 101 | m_grid = func->GetGrid(); 102 | mCompare = new Comparer(func); 103 | } 104 | ~IsolatedRegionRemover(){ 105 | delete mCompare; 106 | delete m_destinations; 107 | } 108 | 109 | DenseLabeling* GetOutputLabels() { return m_destinations; } 110 | const RegularGrid* GetGrid() { return m_grid; } 111 | RegularGridTrilinearFunction* GetFunction() { return m_func; } 112 | void ComputeOutput() { 113 | 114 | 115 | m_destinations = new DenseLabeling(m_grid->NumElements()); 116 | const INDEX_TYPE t_num_vertices = m_grid->NumElements(); 117 | 118 | // set all potential extrema, so we terminate near them 119 | #pragma omp parallel for 120 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 121 | INDEX_TYPE nid = GetHighestUpVertexIn6Neighborhood(i); 122 | m_destinations->SetLabel(i, nid); 123 | } 124 | //#pragma omp parallel for 125 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 126 | PathCompressFind(i); 127 | } 128 | 129 | } 130 | 131 | 132 | 133 | }; 134 | 135 | class PathCompressor { 136 | 137 | protected: 138 | DenseLabeling* m_input; 139 | DenseLabeling* m_destinations; 140 | const RegularGrid* m_grid; 141 | 142 | 143 | 144 | 145 | // if the vertex is a max, return own index 146 | // if the vertex has a higher neighbor with same label, return that (or highest such) 147 | // if the vertex does not have higher with same label, return highest id 148 | 149 | INDEX_TYPE PathCompressFind(INDEX_TYPE id) { 150 | if (m_destinations->GetLabel(id) == id) return id; 151 | INDEX_TYPE retval = PathCompressFind(m_destinations->GetLabel(id)); 152 | // INDEX_TYPE idref = m_destinations->operator[](id); 153 | //#pragma omp atomic 154 | // m_destinations->operator[](id) += retval - idref; // this is stupid - openmp 2.0 supports only binops= for atomics 155 | m_destinations->SetLabel(id, retval); 156 | return retval; 157 | } 158 | 159 | //Comparer* mCompare; 160 | 161 | public: 162 | PathCompressor(RegularGridTrilinearFunction* func, DenseLabeling* input) : 163 | m_input(input) { 164 | m_grid = func->GetGrid(); 165 | } 166 | 167 | 168 | DenseLabeling* GetOutputLabels() { return m_destinations; } 169 | const RegularGrid* GetGrid() { return m_grid; } 170 | void ComputeOutput() { 171 | 172 | 173 | m_destinations = new DenseLabeling(m_grid->NumElements()); 174 | const INDEX_TYPE t_num_vertices = m_grid->NumElements(); 175 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 176 | m_destinations->SetLabel(i, m_input->GetLabel(i)); 177 | } 178 | 179 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 180 | PathCompressFind(i); 181 | } 182 | 183 | } 184 | 185 | 186 | 187 | }; 188 | 189 | 190 | 191 | } 192 | #endif 193 | -------------------------------------------------------------------------------- /msc/include/strictly_numeric_integrator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef INTEGRATOR_H 31 | #define INTEGRATOR_H 32 | 33 | #include 34 | #include 35 | #include "basic_types.h" 36 | #include "vectors.h" 37 | #include "labeling.h" 38 | #include "regular_grid.h" 39 | #include "regular_grid_trilinear_function.h" 40 | #include "adaptive_euler_advector.h" 41 | 42 | 43 | 44 | namespace MSC { 45 | class StrictlyNumericIntegrator { 46 | 47 | protected: 48 | DenseLabeling* m_destinations; 49 | RegularGrid* m_grid; 50 | RegularGridTrilinearFunction* m_func; 51 | 52 | 53 | Vec3i m_xyz; 54 | Vec3b m_periodic; 55 | FLOATTYPE m_error_threshold; 56 | FLOATTYPE m_gradient_threshold; 57 | 58 | char* m_fname; 59 | int m_rkindex; 60 | 61 | bool IsHighestVertexIn6Neighborhood(INDEX_TYPE id) const { 62 | Vec3l t_neighbors[6]; 63 | Vec3l t_coords = m_grid->XYZ3d(id); 64 | int t_num_neighbors = m_grid->GatherExistingNeighbors6(t_coords, t_neighbors); 65 | 66 | INDEX_TYPE t_current_lowest = id; 67 | for (int i = 0; i < t_num_neighbors; i++) { 68 | INDEX_TYPE t_neighbor_vertex = m_grid->Index3d(t_neighbors[i]); 69 | if (m_func->IsGreater(t_neighbor_vertex, t_current_lowest)) { 70 | return false; 71 | } 72 | } 73 | return true; 74 | } 75 | 76 | 77 | public: 78 | StrictlyNumericIntegrator(Vec3i xyz, Vec3b periodic, char* fname, FLOATTYPE error_threshold, FLOATTYPE gradient_threshold) : 79 | m_xyz(xyz), m_periodic(periodic), m_fname(fname), m_rkindex(1), 80 | m_gradient_threshold(gradient_threshold), m_error_threshold(error_threshold) { 81 | } 82 | void SetRKLevel(int level) { 83 | m_rkindex = level; 84 | } 85 | 86 | DenseLabeling* GetOutputLabels() { return m_destinations; } 87 | RegularGrid* GetGrid() { return m_grid; } 88 | RegularGridTrilinearFunction* GetFunction() { return m_func; } 89 | 90 | void BeginIntegration() { 91 | 92 | // SET UP CONTEXT FOR INTEGRATION 93 | m_grid = new RegularGrid(m_xyz, m_periodic); 94 | m_func = new RegularGridTrilinearFunction(m_grid); 95 | m_func->LoadImageFromFile(m_fname); 96 | 97 | m_func->ComputeGradFromImage(m_rkindex); 98 | 99 | m_destinations = new DenseLabeling(m_grid->NumElements()); 100 | const INDEX_TYPE t_num_vertices = m_grid->NumElements(); 101 | AdvectionChecker* inside_voxel_advection_checker = new TerminateNearCrits(m_destinations, m_grid); 102 | //AdvectionChecker* inside_voxel_advection_checker = new TerminateNearAssigned(m_destinations, m_grid); 103 | 104 | // set all potential maxima, so we terminate near them 105 | #pragma omp parallel for 106 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 107 | if (IsHighestVertexIn6Neighborhood(i)) { 108 | m_destinations->SetLabel(i, i); 109 | } 110 | else { 111 | m_destinations->SetLabel(i, -1); 112 | } 113 | } 114 | 115 | int t1, t2; t1 = t2 = 0; 116 | #pragma omp parallel 117 | { 118 | AdaptiveEulerAdvector<1> t_advector(m_grid, m_func, m_gradient_threshold, m_error_threshold, inside_voxel_advection_checker); 119 | 120 | #pragma omp for schedule(dynamic) nowait 121 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 122 | // early skip if this is already a maximum 123 | if (m_destinations->GetLabel(i) == i) { 124 | continue; 125 | } 126 | 127 | Vec3l t_coords = m_grid->XYZ3d(i); // get the coordinates of the poitn 128 | if (t_coords[0] == 0 && t_coords[1] == 0) printf("doing %d\n", t_coords[2]); 129 | Vec3d t_current_point = t_coords; 130 | int t_num_iterations_left = 500; 131 | bool t_continue = true; 132 | 133 | while (t_continue) { 134 | Vec3d t_next_point; 135 | ADVECTION_EVENT t_return_code; 136 | if (m_grid->DistToBoundary(t_coords) <= 1) { 137 | t_return_code = t_advector.AdvectThroughVoxelNearBoundary(t_current_point, t_num_iterations_left); 138 | t_coords = m_grid->Inbounds(t_current_point + 0.5); // get nearest integer voxel 139 | t1++; 140 | } 141 | else { 142 | t_return_code = t_advector.AdvectThroughVoxelNoCheck(t_current_point, t_num_iterations_left); 143 | t_coords = (t_current_point + 0.5); 144 | t2++; 145 | } 146 | INDEX_TYPE t_next_id = m_grid->Index3d(t_coords); 147 | // if we terminated or hit a critical point, then we are done 148 | if (t_return_code == ADVECTION_EVENT::LOW_GRADIENT|| 149 | t_return_code == ADVECTION_EVENT::HIT_EXTREMUM || 150 | t_return_code == ADVECTION_EVENT::HIT_PREASSIGNED || 151 | t_return_code == ADVECTION_EVENT::OVER_MAX_ITERATIONS) { 152 | m_destinations->SetLabel(i, t_next_id); 153 | t_continue = false; 154 | } 155 | } 156 | 157 | 158 | //if (m_grid->DistToBoundary()) {} 159 | //if (IsLowestVertexIn6Neighborhood(i)) { 160 | // m_destinations->SetLabel(i, i); 161 | //} 162 | //else { 163 | // m_destinations->SetLabel(i, -1); 164 | //} 165 | } 166 | 167 | 168 | printf("%d boundary, %d noboundary\n", t1, t2); 169 | } 170 | 171 | } 172 | 173 | 174 | 175 | }; 176 | 177 | 178 | 179 | 180 | } 181 | #endif 182 | -------------------------------------------------------------------------------- /install.topoms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ------------------------------------------------------------------------------ 4 | echo '' 5 | echo '> This script will install TopoMS and its dependencies.' 6 | echo ' Do you also want to install TopoMS-UI? (y/n) [default: n]' 7 | read BUILD_UI 8 | 9 | # ------------------------------------------------------------------------------ 10 | # check commands 11 | 12 | platform=`uname` 13 | 14 | command -v wget >/dev/null 2>&1 || { echo >&2 "Cannot find command 'wget'. Aborting."; exit 1; } 15 | command -v tar >/dev/null 2>&1 || { echo >&2 "Cannot find command 'tar'. Aborting."; exit 1; } 16 | command -v cmake >/dev/null 2>&1 || { echo >&2 "Cannot find command 'cmake'. Aborting."; exit 1; } 17 | 18 | if [ -n "${GNU_CXX}" ] ; then 19 | command -v "${GNU_CXX}" >/dev/null 2>&1 || { echo >&2 "Cannot find command '${GNU_CXX}'. Aborting."; exit 1; } 20 | echo '' 21 | echo "> Using" `"${GNU_CXX}" --version | head -n1`: `type gcc` 22 | else 23 | echo '' 24 | echo "> Using" `gcc --version | head -n1`: `type gcc` 25 | fi 26 | 27 | if [[ $BUILD_UI == y ]]; then 28 | command -v qmake >/dev/null 2>&1 || { echo >&2 "Cannot find command 'qmake'. Aborting."; exit 1; } 29 | echo "> "`qmake --version | tail -n1` 30 | 31 | if [ $platform == 'Darwin' ]; then 32 | alias qmake='qmake -spec macx-g++ INCLUDEPATH+=/usr/include' 33 | fi 34 | fi 35 | 36 | # ------------------------------------------------------------------------------ 37 | if false; then 38 | echo 39 | echo "# path to me ---------------> ${0} " 40 | echo "# parent path --------------> ${0%/*} " 41 | echo "# my name ------------------> ${0##*/} " 42 | fi 43 | 44 | # get the correct path of the TopoMS root 45 | if [ ${0} != ${0##*/} ]; then 46 | PATH_TopoMS=${0%/*} 47 | PATH_TopoMS=$(cd "$(dirname "$PATH_TopoMS")"; pwd)/$(basename "$PATH_TopoMS") 48 | else 49 | PATH_TopoMS=`pwd` 50 | fi 51 | 52 | NPROCS=20 53 | 54 | # ------------------------------------------------------------------------------ 55 | # install script for TopoMS and its depenencies 56 | # ------------------------------------------------------------------------------ 57 | echo '' 58 | echo '> Installing TopoMS and its dependencies for ('`whoami`') on ('`hostname`'). platform = ('$platform')' 59 | echo '' 60 | echo ' > pwd : '`pwd` 61 | echo ' > TopoMS Root Directory: '$PATH_TopoMS 62 | echo '' 63 | 64 | PATH_Ext=$PATH_TopoMS/external 65 | mkdir -p $PATH_Ext/downloads 66 | cd $PATH_Ext/downloads 67 | 68 | # ------------------------------------------------------------------------------ 69 | # VTK 7.1 70 | # ------------------------------------------------------------------------------ 71 | VTK_VERSION='7.1' 72 | VTK_VERSION_BUILD='1' 73 | VTK_NAME='VTK-'$VTK_VERSION'.'$VTK_VERSION_BUILD 74 | 75 | testfile=$PATH_Ext/lib/libvtkCommonCore-$VTK_VERSION* 76 | if ! ls $testfile 1> /dev/null 2>&1 ; then 77 | echo ' > '$VTK_NAME 78 | 79 | if ! ls $VTK_NAME.tar.gz 1> /dev/null 2>&1 ; then 80 | echo ' > Downloading '$VTK_NAME 81 | rm $PATH_Ext/vtk.download.log 2>/dev/null 82 | wget -o $PATH_Ext/vtk.download.log https://www.vtk.org/files/release/$VTK_VERSION/$VTK_NAME.tar.gz 83 | fi 84 | 85 | if ! ls $VTK_NAME 1> /dev/null 2>&1 ; then 86 | echo ' > Untarring the downloaded code' 87 | tar -xf $VTK_NAME.tar.gz 88 | fi 89 | 90 | echo ' > Setting out of source build ('$VTK_NAME'/build)' 91 | mkdir -p $VTK_NAME/build 92 | cd $VTK_NAME/build 93 | 94 | echo ' > Configuring VTK' 95 | rm $PATH_Ext/vtk.cmake.log 2>/dev/null 96 | cmake -DCMAKE_INSTALL_PREFIX=$PATH_Ext \ 97 | -DCMAKE_BUILD_TYPE=Release \ 98 | -DBUILD_SHARED_LIBS:BOOL=OFF \ 99 | -DVTK_WRAP_PYTHON:BOOL=ON \ 100 | -DVTK_USE_CXX11_FEATURES:BOOL=ON \ 101 | .. > $PATH_Ext/vtk.cmake.log 102 | 103 | echo ' > Building VTK' 104 | rm $PATH_Ext/vtk.make.log 2>/dev/null 105 | make -j$NPROCS > $PATH_Ext/vtk.make.log 106 | 107 | echo ' > Installing VTK' 108 | make install > $PATH_Ext/vtk.make.log 109 | 110 | if ls $testfile 1> /dev/null 2>&1 ; then 111 | echo ' > VTK successfully installed in '$PATH_Ext'.' 112 | else 113 | echo ' > VTK build failed. Please check the build logs in '$PATH_Ext'for more information.' 114 | fi 115 | else 116 | echo ' > '$VTK_NAME 'is already installed ('$PATH_Ext'). If you need to reinstall, please remove the existing installation.' 117 | fi 118 | 119 | # ------------------------------------------------------------------------------ 120 | # QGLViewer 2.7.1 121 | # ------------------------------------------------------------------------------ 122 | if [[ $BUILD_UI == y ]]; then 123 | 124 | QGL_VERSION='2.7' 125 | QGL_VERSION_BUILD='1' 126 | QGL_NAME='libQGLViewer-'$QGL_VERSION'.'$QGL_VERSION_BUILD 127 | 128 | testfile=$PATH_Ext/lib/libQGLViewer* 129 | if ! ls $testfile 1> /dev/null 2>&1 ; then 130 | echo ' > '$QGL_NAME 131 | 132 | if ! ls $QGL_NAME.tar.gz 1> /dev/null 2>&1 ; then 133 | echo ' > Downloading '$QGL_NAME 134 | rm $PATH_Ext/qgl.download.log 2>/dev/null 135 | wget -o $PATH_Ext/qgl.download.log http://www.libqglviewer.com/src/$QGL_NAME.tar.gz 136 | fi 137 | 138 | if ! ls $QGL_NAME 1> /dev/null 2>&1 ; then 139 | echo ' > Untarring the downloaded code' 140 | tar -xf $QGL_NAME.tar.gz 141 | fi 142 | 143 | echo ' > Setting out of source build ('$QGL_NAME'/build)' 144 | mkdir -p $QGL_NAME/build 145 | cd $QGL_NAME/build 146 | 147 | echo ' > Configuring QGLViewer' 148 | rm $PATH_Ext/qgl.cmake.log 2>/dev/null 149 | 150 | COMPILER="" 151 | if [ -n "${GNU_CXX}" ] ; then 152 | echo ' > CXX_COMPILER: '$GNU_CXX 153 | COMPILER="QMAKE_CXX=$GNU_CXX" 154 | fi 155 | 156 | qmake $COMPILER QMAKE_CXXFLAGS+='-w' \ 157 | QGLVIEWER_STATIC=yes PREFIX=$PATH_Ext \ 158 | ../QGLViewer > $PATH_Ext/qgl.qmake.log 159 | 160 | echo ' > Building QGLViewer' 161 | rm $PATH_Ext/qgl.make.log 2>/dev/null 162 | make -j$NPROCS > $PATH_Ext/qgl.make.log 163 | 164 | echo ' > Installing QGLViewer' 165 | make install > $PATH_Ext/qgl.make.log 166 | 167 | if ls $testfile 1> /dev/null 2>&1 ; then 168 | echo ' > QGLViewer successfully installed in '$PATH_Ext'.' 169 | else 170 | echo ' > QGLViewer build failed. Please check the build logs in '$PATH_Ext' for more information.' 171 | fi 172 | else 173 | echo ' > '$QGL_NAME 'is already installed ('$PATH_Ext'). If you need to reinstall, please remove the existing installation.' 174 | fi 175 | fi 176 | 177 | cd $PATH_TopoMS 178 | 179 | # ------------------------------------------------------------------------------ 180 | # TopoMS 181 | # ------------------------------------------------------------------------------ 182 | echo ' > TopoMS' 183 | 184 | mkdir -p build 185 | cd build 186 | 187 | echo ' > Configuring TopoMS' 188 | 189 | # parameters for cmake 190 | COMPILER="" 191 | if [ -n "${GNU_CXX}" ] ; then 192 | echo ' > CXX_COMPILER: '$GNU_CXX 193 | COMPILER="-DCMAKE_CXX_COMPILER=$GNU_CXX" 194 | fi 195 | 196 | UI="" 197 | if [[ $BUILD_UI == y ]]; then 198 | UI="-DTOPOMS_BUILD_UI=True" 199 | fi 200 | 201 | cmake $COMPILER $UI \ 202 | -DCMAKE_INSTALL_PREFIX=$PATH_TopoMS/install \ 203 | $PATH_TopoMS > topoms.cmake.log 204 | 205 | echo ' > Building TopoMS' 206 | 207 | make -j$NPROCS > topoms.make.log 208 | make install 209 | 210 | if ls TopoMS 1> /dev/null 2>&1 ; then 211 | echo ' > TopoMS successfully built in '`pwd` 212 | else 213 | echo ' > TopoMS build failed. Please check the build logs in '`pwd`' for more information.' 214 | fi 215 | 216 | # ------------------------------------------------------------------------------ 217 | # end of the install script 218 | # ------------------------------------------------------------------------------ 219 | -------------------------------------------------------------------------------- /msc/include/discrete_gradient_labeling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef DISCRETE_GRADIENT_LABELING_H 31 | #define DISCRETE_GRADIENT_LABELING_H 32 | 33 | #include "basic_types.h" 34 | #include "regular_grid.h" 35 | #include "labeling.h" 36 | #include "topological_regular_grid.h" 37 | 38 | namespace MSC { 39 | class DiscreteGradientLabeling { 40 | public: 41 | struct GradBitfield { 42 | unsigned char assigned : 1; 43 | unsigned char flag : 1; 44 | //unsigned char critical : 1; 45 | //unsigned char insorter : 1; 46 | //unsigned char dimA : 3; 47 | unsigned char pair : 3; 48 | unsigned char ldir : 3; 49 | }; 50 | protected: 51 | TopologicalRegularGrid* m_mesh; 52 | 53 | 54 | DenseLabeling* m_dgrad; 55 | 56 | public: 57 | DiscreteGradientLabeling(TopologicalRegularGrid* mesh) : m_mesh(mesh) { 58 | m_dgrad = new DenseLabeling(m_mesh->numCells()); 59 | } 60 | ////GradBitfield& GetBitField(INDEX_TYPE id) { 61 | //// return m_dgrad->GetLabel[id]; 62 | ////} 63 | 64 | 65 | GradBitfield& getBitfield(INDEX_TYPE cellid) { return (*m_dgrad)[cellid]; } 66 | // this is a super dangerous call - use at your own risk! 67 | // basically sometimes it is useful to change the mesh while 68 | // keeping the same underlying data structure - e.g. when you 69 | // want to switch to the logic of a complement mesh, but keep 70 | // the computation you did on the original mesh 71 | void resetMeshHandler(TopologicalRegularGrid* mesh) { 72 | m_mesh = mesh; 73 | } 74 | void ClearAllGradient() { 75 | memset(m_dgrad->LabelArray(), 0, sizeof(GradBitfield)*m_mesh->numCells()); 76 | } 77 | // ALWAYS VALID 78 | ASSIGNED_TYPE getAssigned(INDEX_TYPE cellid) const { 79 | return (*m_dgrad)[cellid].assigned; 80 | } 81 | 82 | void setAssigned(INDEX_TYPE cellid, ASSIGNED_TYPE value) { 83 | (*m_dgrad)[cellid].assigned = value; 84 | } 85 | 86 | // VALID ONLY AFTER FIRST ASSIGNMENT 87 | INDEX_TYPE getPair(INDEX_TYPE cellid) const{ 88 | return m_mesh->UncompressByteTo6NeighborOffset(cellid, (*m_dgrad)[cellid].pair); 89 | } 90 | 91 | void setPair(INDEX_TYPE cellid, INDEX_TYPE value) { 92 | (*m_dgrad)[cellid].pair = m_mesh->Compress6NeighborOffsetToByte(cellid, value); 93 | } 94 | 95 | bool getCritical(INDEX_TYPE cellid) const { 96 | return (*m_dgrad)[cellid].pair == 7; 97 | } 98 | void setCritical(INDEX_TYPE cellid, bool value) { 99 | if (value) (*m_dgrad)[cellid].pair = 7; 100 | } 101 | 102 | DIM_TYPE getDimAscMan(INDEX_TYPE cellid){ 103 | return (*m_dgrad)[cellid].ldir; 104 | } 105 | void setDimAscMan(INDEX_TYPE cellid, DIM_TYPE value){ 106 | (*m_dgrad)[cellid].ldir = value; 107 | } 108 | 109 | // VALID ONLY BEFORE FIRST ASSIGNEMT 110 | INDEX_TYPE getNumUnpairedFacets(INDEX_TYPE cellid) { 111 | return (*m_dgrad)[cellid].ldir; 112 | } 113 | void setNumUnpairedFacets(INDEX_TYPE cellid, INDEX_TYPE value) { 114 | (*m_dgrad)[cellid].ldir = value; 115 | } 116 | 117 | unsigned char getNumUnpairedFacets_new(INDEX_TYPE cellid) { 118 | return (*m_dgrad)[cellid].ldir; 119 | } 120 | unsigned char decrementNumUnpairedFacets_new(INDEX_TYPE cellid) { 121 | return --((*m_dgrad)[cellid].ldir); 122 | } 123 | void setNumUnpairedFacets_new(INDEX_TYPE cellid, unsigned char value) { 124 | (*m_dgrad)[cellid].ldir = value; 125 | } 126 | 127 | DIM_TYPE getMark(INDEX_TYPE cellid){ 128 | return (*m_dgrad)[cellid].pair; 129 | } 130 | void setMark(INDEX_TYPE cellid, DIM_TYPE value){ 131 | (*m_dgrad)[cellid].pair = value; 132 | } 133 | 134 | 135 | 136 | void outputToRenderer(const char* filenamebase) { 137 | 138 | char grad_name[1024]; 139 | sprintf(grad_name, "%s.grad", filenamebase); 140 | 141 | FILE* fgrad = fopen(grad_name, "wb"); 142 | 143 | for (int i = 0; i < m_mesh->numCells(); i++) { 144 | 145 | (*m_dgrad)[i].flag = (bool)m_mesh->boundaryValue(i); 146 | //if (i % 1000 == 0) 147 | // printf("cell[%d]:(%d, %d, %d, %d)\n", i, 148 | // m_dgrad[i].pair, 149 | // m_dgrad[i].ldir, 150 | // m_dgrad[i].flag, 151 | // m_dgrad[i].assigned); 152 | 153 | 154 | fwrite(&(*m_dgrad)[i], sizeof(GradBitfield), 1, fgrad); 155 | } 156 | fclose(fgrad); 157 | } 158 | 159 | void outputToFile(const char* filenamebase) { 160 | 161 | 162 | FILE* fgrad = fopen(filenamebase, "wb"); 163 | 164 | for (int i = 0; i < m_mesh->numCells(); i++) { 165 | 166 | (*m_dgrad)[i].flag = (bool)m_mesh->boundaryValue(i); 167 | 168 | //(*m_dgrad)[i].flag = 0; 169 | //(*m_dgrad)[i].assigned = 0; 170 | //(*m_dgrad)[i].pair = 0; 171 | //(*m_dgrad)[i].ldir = 0; 172 | 173 | fwrite(&(*m_dgrad)[i], sizeof(GradBitfield), 1, fgrad); 174 | } 175 | 176 | //printf(" -- Output to %s.. %d values of size %d\n", filenamebase, m_mesh->numCells (), sizeof(GradBitfield)); 177 | fclose(fgrad); 178 | } 179 | 180 | 181 | bool load_from_file(const char* filename) { 182 | 183 | FILE* fdat = fopen(filename, "rb"); 184 | if (fdat == NULL) { 185 | return false; 186 | 187 | } 188 | 189 | fread(m_dgrad->LabelArray(), sizeof(GradBitfield), m_mesh->numCells(), fdat); 190 | 191 | //for (int i = 0; i < m_mesh->numCells(); i++) { 192 | // 193 | // bitfield val; 194 | // fread(&val, sizeof(bitfield), 1, fdat); 195 | // m_dgrad[i]=val; 196 | 197 | //} 198 | 199 | fclose(fdat); 200 | return true; 201 | } 202 | 203 | }; 204 | 205 | } 206 | #endif 207 | -------------------------------------------------------------------------------- /scripts/VASPutils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy 3 | import math 4 | 5 | # Read VASP CAR format (CHGCAR, AECCAR, LOCPOT) 6 | def readCAR(infilename, read_field = True): 7 | 8 | if not os.path.isfile(infilename): 9 | raise Exception('File ({}) not found'.format(infilename)) 10 | 11 | # -------------------------------------------- 12 | # start reading CAR file 13 | f = open(infilename, 'r') 14 | print " --> Reading file ", f 15 | 16 | # -------------------------------------------- 17 | print " --> Reading header" 18 | sysname = f.readline()[:-1] 19 | scalingfactor = float(f.readline()) 20 | 21 | lattice = [] 22 | lattice.append( [float(x) for x in f.readline().split()] ) 23 | lattice.append( [float(y) for y in f.readline().split()] ) 24 | lattice.append( [float(z) for z in f.readline().split()] ) 25 | 26 | species = [] 27 | specieCounts = [] 28 | 29 | l = f.readline().split() 30 | 31 | # if this is not a digit, then these must be symbols 32 | if(l[0].isdigit() == False): 33 | species = l 34 | specieCounts = [int(cnt) for cnt in f.readline().split()] 35 | 36 | # else, this must already be the count. create fake symbols 37 | else: 38 | specieCounts = [int(cnt) for cnt in l] 39 | species = ['-' for x in specieCounts] 40 | 41 | numAtoms = sum(specieCounts) 42 | species = zip(species, specieCounts) 43 | 44 | # -------------------------------------------- 45 | print " --> Reading atom positions" 46 | coordType = f.readline()[:-1] 47 | 48 | pos = [] 49 | for i in range(0, numAtoms): 50 | pos.append( [float(x) for x in f.readline().split()] ) 51 | 52 | print " --> Reading grid information" 53 | t = f.readline() 54 | while len(t.split()) == 0: 55 | t = f.readline() 56 | 57 | grid = [int(x) for x in t.split()] 58 | sz = grid[0]*grid[1]*grid[2] 59 | 60 | # -------------------------------------------- 61 | print " --> Reading data " 62 | data = numpy.zeros(sz, dtype=numpy.float32) 63 | if(read_field == True): 64 | 65 | lines = f.readlines() 66 | curr_count = 0 67 | for line in lines: 68 | 69 | if line.startswith('augmentation'): 70 | #print curr_count, data[curr_count-1] 71 | break 72 | 73 | for token in line.split(): 74 | if curr_count < sz-1: 75 | data[curr_count] = numpy.float32(token) 76 | curr_count = curr_count+1 77 | 78 | if(curr_count >= sz): 79 | break 80 | 81 | f.close() 82 | 83 | # ---------------------------------------------------------- 84 | # ---- 09.13.2016 85 | # I want to index data as (x,y,z), so reshape in fortran order 86 | # this makes it easier to convert to vti, etc. 87 | 88 | data = numpy.reshape(data, [grid[0], grid[1], grid[2]], order = 'F') 89 | 90 | print '\t Data.shape = ', data.shape, '(in Fortran order)' 91 | return (sysname, scalingfactor, lattice, species, pos, grid, data) 92 | 93 | 94 | def writeCAR(outfilename, sysname, scalingfactor, lattice, species, positions, grid, data, write_data = False): 95 | 96 | # -------------------------------------------- 97 | # start reading CAR file 98 | f = open(outfilename, 'w') 99 | print " --> Writing file ", f 100 | 101 | # -------------------------------------------- 102 | print " --> Writing header" 103 | print >> f, sysname 104 | print >> f, '%16.12f' % scalingfactor 105 | 106 | for lat in lattice: 107 | print >> f, '%12.6f %12.6f %12.6f' % (lat[0], lat[1], lat[2]) 108 | 109 | for sp in species: 110 | f.write(' '+str(sp[0])) 111 | f.write('\n') 112 | for sp in species: 113 | f.write(' '+str(sp[1])) 114 | f.write('\n') 115 | 116 | print " --> Writing positions" 117 | f.write('Direct\n') 118 | 119 | for pos in positions: 120 | print >> f, '%10.6f %10.6f %10.6f' % (pos[0], pos[1], pos[2]) 121 | 122 | f.write('\n'+str(grid[0])+' '+str(grid[1])+' '+str(grid[2])+'\n') 123 | 124 | if (write_data): 125 | 126 | print " --> Writing data" 127 | data = data.flatten('F') 128 | #data = numpy.reshape(data, grid[0] * grid[1] * grid[2]) 129 | 130 | # write 5 values in a line 131 | nlines = data.shape[0] / 5 132 | for i in range(0, nlines): 133 | #print >> f, '%10.6f %10.6f %10.6f %10.6f %10.6f' % (data[5*i], data[5*i+1], data[5*i+2], data[5*i+3], data[5*i+4]) 134 | print >> f, '%0.11E %0.11E %0.11E %0.11E %0.11E' % (data[5*i], data[5*i+1], data[5*i+2], data[5*i+3], data[5*i+4]) 135 | 136 | data = numpy.reshape(data, [grid[0], grid[1], grid[2]], order = 'F') 137 | 138 | f.close() 139 | 140 | def readPOSCAR(infilename): 141 | 142 | # -------------------------------------------- 143 | # start reading CAR file 144 | f = open(infilename, 'r') 145 | print " --> Reading file ", f 146 | 147 | # -------------------------------------------- 148 | print " --> Reading header" 149 | sysname = f.readline()[:-1] 150 | scalingfactor = float(f.readline()) 151 | 152 | lattice = [] 153 | lattice.append( [float(x) for x in f.readline().split()] ) 154 | lattice.append( [float(y) for y in f.readline().split()] ) 155 | lattice.append( [float(z) for z in f.readline().split()] ) 156 | 157 | species = [] 158 | specieCounts = [] 159 | 160 | l = f.readline().split() 161 | 162 | # if this is not a digit, then these must be symbols 163 | if(l[0].isdigit() == False): 164 | species = l 165 | specieCounts = [int(cnt) for cnt in f.readline().split()] 166 | 167 | # else, this must already be the count. create fake symbols 168 | else: 169 | specieCounts = [int(cnt) for cnt in l] 170 | species = ['-' for x in specieCounts] 171 | 172 | numAtoms = sum(specieCounts) 173 | species = zip(species, specieCounts) 174 | 175 | # -------------------------------------------- 176 | print " --> Reading atom positions" 177 | coordType = f.readline()[:-1] 178 | 179 | pos = [] 180 | for i in range(0, numAtoms): 181 | pos.append( [float(x) for x in f.readline().split()] ) 182 | 183 | # -------------------------------------------- 184 | print " --> Reading atom velocties" 185 | 186 | vel = [] 187 | for i in range(0, numAtoms): 188 | l = f.readline() 189 | if len(l) == 0: 190 | break; 191 | vel.append( [float(x) for x in l.split()] ) 192 | 193 | return (sysname, scalingfactor, lattice, species, pos, vel) 194 | 195 | def writePOSCAR(outfilename, sysname, scalingfactor, lattice, species, positions, velocities): 196 | 197 | # -------------------------------------------- 198 | # start reading CAR file 199 | f = open(outfilename, 'w') 200 | print " --> Writing file ", f 201 | 202 | # -------------------------------------------- 203 | print " --> Writing header" 204 | print >> f, sysname 205 | print >> f, '%16.12f' % scalingfactor 206 | 207 | for lat in lattice: 208 | print >> f, '%12.6f %12.6f %12.6f' % (lat[0], lat[1], lat[2]) 209 | 210 | for sp in species: 211 | f.write(' '+str(sp[0])) 212 | f.write('\n') 213 | for sp in species: 214 | f.write(' '+str(sp[1])) 215 | f.write('\n') 216 | 217 | print " --> Writing positions" 218 | f.write('Direct\n') 219 | 220 | for pos in positions: 221 | print >> f, '%11.7f %11.7f %11.7f' % (pos[0], pos[1], pos[2]) 222 | 223 | print >> f, '' 224 | for vel in velocities: 225 | print >> f, '%11.7f %11.7f %11.7f' % (vel[0], vel[1], vel[2]) 226 | 227 | # Read VASP XDATCAR 228 | def readXDATCAR(infilename, read_only = None): 229 | 230 | # -------------------------------------------- 231 | # start reading CAR file 232 | f = open(infilename, 'r') 233 | print " --> Reading file ", f 234 | 235 | # -------------------------------------------- 236 | print " --> Reading header" 237 | t = f.readline().split() 238 | 239 | numatoms = int(t[0]) 240 | tmp = int(t[1]) 241 | numts = int(t[2]) 242 | 243 | t = f.readline().split() 244 | 245 | avol = float(t[0]) 246 | lattice = [float(t[1]), float(t[2]), float(t[3])] 247 | dt = float(t[4]) 248 | 249 | temp = float(f.readline()) 250 | 251 | # --- correct the units 252 | dt = dt*math.pow(10,12) 253 | lattice = [ k*math.pow(10,10) for k in lattice ] 254 | 255 | f.readline() 256 | f.readline() 257 | # -------------------------------------------- 258 | 259 | if(read_only != None): 260 | numts = read_only 261 | 262 | print " --> Allocating space for", numts, "timesteps" 263 | P = numpy.ndarray( (numatoms, numts, 3), dtype = numpy.float32 ) 264 | 265 | print " --> Reading positions" 266 | 267 | # for each time-step and each atom 268 | for t in range(numts): 269 | 270 | f.readline() # direct! 271 | for a in range(numatoms): 272 | P[a, t] = [float(x) for x in f.readline().split()] 273 | 274 | f.close() 275 | return (lattice, dt, P) 276 | -------------------------------------------------------------------------------- /msc/include/isolated_region_remover2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef ISOLATED_REGION_REMOVER_MASKED_H 31 | #define ISOLATED_REGION_REMOVER_MASKED_H 32 | 33 | 34 | #include "basic_types.h" 35 | #include "vectors.h" 36 | #include "labeling.h" 37 | #include "regular_grid.h" 38 | #include "regular_grid_trilinear_function.h" 39 | #include "adaptive_euler_advector.h" 40 | #include "timing.h" 41 | 42 | #include 43 | 44 | namespace MSC { 45 | template< class Comparer> 46 | class IsolatedRegionRemoverMasked { 47 | 48 | protected: 49 | const DenseLabeling* m_input; 50 | std::map m_inversemask; 51 | 52 | DenseLabeling* m_destinations_unmasked; 53 | 54 | DenseLabeling* m_destinations; 55 | const RegularGrid* m_grid; 56 | RegularGridTrilinearFunction* m_func; 57 | 58 | 59 | // if the vertex is a max, return own index 60 | // if the vertex has a higher neighbor with same label, return that (or highest such) 61 | // if the vertex does not have higher with same label, return highest id 62 | INDEX_TYPE GetHighestUpVertexIn6Neighborhood(INDEX_TYPE id) const { 63 | Vec3l t_neighbors[6]; 64 | Vec3l t_coords = m_grid->XYZ3d(id); 65 | int t_num_neighbors = m_grid->GatherExistingNeighbors6(t_coords, t_neighbors); 66 | 67 | bool has_samelabel_higher = false; 68 | bool is_max = true; 69 | INDEX_TYPE t_overall_highest = id; 70 | INDEX_TYPE t_highest_same_label = id; 71 | 72 | for (int i = 0; i < t_num_neighbors; i++) { 73 | INDEX_TYPE t_neighbor_vertex = m_grid->Index3d(t_neighbors[i]); 74 | if (mCompare->Compare(t_neighbor_vertex, t_overall_highest)) { 75 | t_overall_highest = t_neighbor_vertex; 76 | is_max = false; 77 | } 78 | if (m_input->GetLabel(id) == m_input->GetLabel(t_neighbor_vertex) && 79 | mCompare->Compare(t_neighbor_vertex, t_highest_same_label)) { 80 | t_highest_same_label = t_neighbor_vertex; 81 | has_samelabel_higher = true; 82 | } 83 | } 84 | if (is_max) return id; 85 | if (has_samelabel_higher) return t_highest_same_label; 86 | return t_overall_highest; 87 | } 88 | 89 | 90 | INDEX_TYPE PathCompressFind(INDEX_TYPE id) { 91 | if (m_destinations->GetLabel(id) == id) return id; 92 | INDEX_TYPE retval = PathCompressFind(m_destinations->GetLabel(id)); 93 | INDEX_TYPE idref = m_destinations->operator[](id); 94 | #pragma omp atomic 95 | m_destinations->operator[](id) += retval - idref; // this is stupid - openmp 2.0 supports only binops= for atomics 96 | return retval; 97 | } 98 | 99 | Comparer* mCompare; 100 | 101 | public: 102 | 103 | IsolatedRegionRemoverMasked(RegularGridTrilinearFunction* func, const DenseLabeling *input, const std::vector *mask) : 104 | m_input(input), m_func(func) { 105 | m_grid = func->GetGrid(); 106 | mCompare = new Comparer(func); 107 | 108 | for(int i = 0; i < mask->size(); i++) { 109 | m_inversemask.insert( std::pair (mask->at(i), i) ); 110 | } 111 | } 112 | 113 | ~IsolatedRegionRemoverMasked(){ 114 | delete mCompare; 115 | delete m_destinations; 116 | } 117 | 118 | DenseLabeling* GetOutputLabels() { return m_destinations; } 119 | DenseLabeling* GetOutputLabelsUnmasked() { return m_destinations_unmasked; } 120 | const RegularGrid* GetGrid() { return m_grid; } 121 | RegularGridTrilinearFunction* GetFunction() { return m_func; } 122 | void ComputeOutput(bool verbose = false) { 123 | 124 | 125 | ThreadedTimer gtimer(1); 126 | gtimer.StartGlobal(); 127 | 128 | if(verbose){ 129 | printf(" -- Cleaning noise in integration..."); 130 | fflush(stdout); 131 | } 132 | 133 | const INDEX_TYPE t_num_vertices = m_grid->NumElements(); 134 | 135 | m_destinations = new DenseLabeling(t_num_vertices); 136 | 137 | 138 | // set all potential extrema, so we terminate near them 139 | #pragma omp parallel for 140 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 141 | INDEX_TYPE nid = GetHighestUpVertexIn6Neighborhood(i); 142 | m_destinations->SetLabel(i, nid); 143 | } 144 | 145 | //#pragma omp parallel for 146 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 147 | PathCompressFind(i); 148 | } 149 | 150 | 151 | ThreadedTimer ltimer(1); 152 | ltimer.StartGlobal(); 153 | 154 | // create unmasked versions! 155 | m_destinations_unmasked = new DenseLabeling(t_num_vertices); 156 | 157 | #pragma omp parallel for 158 | for(int i = 0; i < t_num_vertices; i++) { 159 | 160 | if (m_input->GetLabel(i) < 0){ 161 | m_destinations->SetLabel(i, m_input->GetLabel(i)); 162 | continue; 163 | } 164 | m_destinations_unmasked->SetLabel(i, m_inversemask.at( m_destinations->GetLabel(i) )); 165 | } 166 | 167 | ltimer.EndGlobal(); 168 | gtimer.EndGlobal (); 169 | if (verbose){ 170 | printf(" done!"); gtimer.PrintAll(); 171 | //ltimer.PrintAll(); 172 | } 173 | } 174 | }; 175 | #if 0 176 | class PathCompressor { 177 | 178 | protected: 179 | DenseLabeling* m_input; 180 | DenseLabeling* m_destinations; 181 | const RegularGrid* m_grid; 182 | 183 | 184 | 185 | 186 | // if the vertex is a max, return own index 187 | // if the vertex has a higher neighbor with same label, return that (or highest such) 188 | // if the vertex does not have higher with same label, return highest id 189 | 190 | INDEX_TYPE PathCompressFind(INDEX_TYPE id) { 191 | if (m_destinations->GetLabel(id) == id) return id; 192 | INDEX_TYPE retval = PathCompressFind(m_destinations->GetLabel(id)); 193 | // INDEX_TYPE idref = m_destinations->operator[](id); 194 | //#pragma omp atomic 195 | // m_destinations->operator[](id) += retval - idref; // this is stupid - openmp 2.0 supports only binops= for atomics 196 | m_destinations->SetLabel(id, retval); 197 | return retval; 198 | } 199 | 200 | //Comparer* mCompare; 201 | 202 | public: 203 | PathCompressor(RegularGridTrilinearFunction* func, DenseLabeling* input) : 204 | m_input(input) { 205 | m_grid = func->GetGrid(); 206 | } 207 | 208 | 209 | DenseLabeling* GetOutputLabels() { return m_destinations; } 210 | const RegularGrid* GetGrid() { return m_grid; } 211 | void ComputeOutput() { 212 | 213 | 214 | m_destinations = new DenseLabeling(m_grid->NumElements()); 215 | const INDEX_TYPE t_num_vertices = m_grid->NumElements(); 216 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 217 | m_destinations->SetLabel(i, m_input->GetLabel(i)); 218 | } 219 | 220 | for (INDEX_TYPE i = 0; i < t_num_vertices; i++) { 221 | PathCompressFind(i); 222 | } 223 | 224 | } 225 | 226 | 227 | 228 | }; 229 | 230 | #endif 231 | 232 | } 233 | #endif 234 | -------------------------------------------------------------------------------- /topoms/src/MSCBond.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file MSCBond.cpp 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 05/12/2017 63 | * 64 | * @brief This file provides a collection of utilities to handle MSC bonds 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This file provides a collection of utilities to handle MSC bonds 69 | * 70 | */ 71 | 72 | #include 73 | #include 74 | #include 75 | 76 | #include "MSCBond.h" 77 | #include "MolecularSystem.h" 78 | #include "MultilinearInterpolator.h" 79 | 80 | bool is_zero(const float &v) { return fabs(v) < 0.00001; } 81 | bool compare(const float &a, const float &b) { return is_zero(a-b); } 82 | 83 | /// ------------------------------------------------------------------------ 84 | void MSCBond::print() const { 85 | 86 | printf(" Bond: %d (%f %f %f):\n", saddle, scoords[0],scoords[1],scoords[2]); 87 | for(unsigned int i = 0; i < atomIds.size(); i++) { 88 | printf("\t atom %d, extrema %d, pos (%f %f %f), path = %d\n", 89 | atomIds[i], extrema[i], ecoords[i][0],ecoords[i][1],ecoords[i][2], paths[i].size()); 90 | } 91 | } 92 | 93 | bool MSCBond::check2() const { 94 | 95 | if (atomIds.size() != 2 || extrema.size() != 2 || ecoords.size() != 2 || paths.size() != 2) { 96 | printf(" Bond %d does not attach to 2 extrema. sizes = [%d %d, %d %d]\n", 97 | saddle, paths.size(), atomIds.size(), extrema.size(), ecoords.size()); 98 | return false; 99 | } 100 | return true; 101 | } 102 | 103 | /// ------------------------------------------------------------------------ 104 | // TODO: this should go in utils 105 | void MSCBond::fix_periodic(MSC::Vec3d &p, const MSC::Vec3d &orig, const size_t dims[3]) { 106 | 107 | for(uint8_t d = 0; d < 3; d++) { 108 | 109 | if (p[d] - orig[d] > size_t(0.5*dims[d])) 110 | p[d] -= dims[d]; 111 | 112 | else if (orig[d] - p[d] > size_t(0.5*dims[d])) 113 | p[d] += dims[d]; 114 | } 115 | } 116 | 117 | /// ------------------------------------------------------------------------ 118 | void MSCBond::parameterize(const MS::SystemInfo &metadata) { 119 | 120 | if (!this->check2()){ 121 | return; 122 | } 123 | 124 | // make sure atom ids are in increasing order 125 | if (atomIds[1] < atomIds[0]) { 126 | std::swap(atomIds[0], atomIds[1]); 127 | std::swap(extrema[0], extrema[1]); 128 | std::swap(ecoords[0], ecoords[1]); 129 | std::swap(paths[0], paths[1]); 130 | } 131 | 132 | const size_t gdims[3] = {metadata.m_grid_dims[0],metadata.m_grid_dims[1],metadata.m_grid_dims[2]}; 133 | 134 | // convert saddle position to world coordinates 135 | float sgcoords[3] = {scoords[0],scoords[1],scoords[2]}; 136 | float swcoords[3]; 137 | metadata.grid_to_world(sgcoords, swcoords); 138 | 139 | //printf(" \n --> Parameterizing "); this->print(); 140 | 141 | parameterization.clear(); 142 | for(uint8_t k = 0; k < 2; k++) { 143 | 144 | const std::vector& path = this->paths[k]; 145 | for(uint8_t i = 0; i < path.size(); i++) { 146 | 147 | MSC::Vec3d pp = path[i]; 148 | 149 | // fix periodic 150 | fix_periodic(pp, scoords, gdims); 151 | 152 | // convert p to world coordinates 153 | float pgcoords[3] = {pp[0],pp[1],pp[2]}; 154 | float pwcoords[3]; 155 | metadata.grid_to_world(pgcoords, pwcoords); 156 | 157 | float diff[3] = {pwcoords[0]-swcoords[0], pwcoords[1]-swcoords[1], pwcoords[2]-swcoords[2]}; 158 | float p = std::sqrt(diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]); 159 | 160 | if (k == 0) p *= -1; 161 | 162 | if(parameterization.size() > 0) { 163 | if (compare(p, parameterization.back().first)) 164 | continue; 165 | } 166 | parameterization.push_back(std::pair(p, path[i])); 167 | } 168 | 169 | if (k == 0) 170 | std::reverse(parameterization.begin(), parameterization.end()); 171 | } 172 | return; 173 | for(int k = 0; k < parameterization.size(); k++) 174 | printf(" %f, (%f %f %f)\n", parameterization[k].first, parameterization[k].second[0], parameterization[k].second[1], parameterization[k].second[2]); 175 | } 176 | 177 | /// ------------------------------------------------------------------------ 178 | void MSCBond::get_points_idx(MSC::Vec3d &origin, std::vector &nbrs, const size_t dims[3], int pidx) const { 179 | 180 | if (pidx == -1) { 181 | origin = scoords; nbrs.push_back(ecoords[0]); nbrs.push_back(ecoords[1]); 182 | } 183 | else { 184 | origin = parameterization[pidx].second; 185 | if (pidx != 0) { 186 | nbrs.push_back(parameterization[pidx-1].second); 187 | } 188 | if (pidx != parameterization.size()-1) { 189 | nbrs.push_back(parameterization[pidx+1].second); 190 | } 191 | 192 | // if either was not found 193 | if (nbrs.size() != 2) { 194 | nbrs.push_back(origin - (nbrs.front()-origin)); 195 | } 196 | } 197 | 198 | // fix periodic 199 | for(uint8_t i = 0; i < nbrs.size(); i++) { 200 | fix_periodic(nbrs[i], origin, dims); 201 | } 202 | } 203 | 204 | /// ------------------------------------------------------------------------ 205 | void MSCBond::get_points(MSC::Vec3d &origin, std::vector &nbrs, const size_t dims[3], float p) const { 206 | 207 | // TODO: float comparison should move to utils 208 | if (fabs(p) < 0.000001) { 209 | return get_points(origin, nbrs, dims, -1); 210 | } 211 | 212 | if (p < 0) p = -1.0 * p * this->parameterization.front().first; 213 | else if (p > 0) p = p * this->parameterization.back().first; 214 | 215 | 216 | std::multimap dmap; 217 | for(unsigned int i = 0; i < parameterization.size(); i++) { 218 | dmap.insert(std::make_pair(fabs(p-parameterization[i].first), i)); 219 | } 220 | 221 | return get_points_idx(origin, nbrs, dims, int(dmap.begin()->second)); 222 | } 223 | 224 | /// ------------------------------------------------------------------------ 225 | -------------------------------------------------------------------------------- /scripts/compute_chgCOM.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import numpy as np 4 | import argparse 5 | 6 | from VASPutils import readCAR 7 | import matplotlib.pyplot as plt 8 | 9 | # ------------------------------------------------------------------------------ 10 | # VTK I/O 11 | # ------------------------------------------------------------------------------ 12 | def read_vti(filename, fieldname): 13 | 14 | if not os.path.isfile(filename): 15 | raise Exception('File ({}) not found'.format(filename)) 16 | 17 | import vtk 18 | from vtk.util import numpy_support 19 | 20 | print ' --> Reading ({}) from ({})'.format(fieldname, filename) 21 | 22 | reader = vtk.vtkXMLImageDataReader() 23 | reader.SetFileName(filename) 24 | reader.Update() 25 | dims = reader.GetOutput().GetDimensions() 26 | field = reader.GetOutput().GetPointData().GetArray(fieldname) 27 | field = numpy_support.vtk_to_numpy(field).reshape(dims[2], dims[1], dims[0]) 28 | field = np.swapaxes(field, 0,2) 29 | return field 30 | 31 | def write_vtp(filename, data): 32 | 33 | import vtk 34 | from vtk.util import numpy_support 35 | 36 | print ' --> Writing ({})'.format(filename) 37 | 38 | writer = vtk.vtkXMLPolyDataWriter() 39 | writer.SetFileName(filename) 40 | 41 | polydata = vtk.vtkPolyData() 42 | 43 | points = vtk.vtkPoints() 44 | cells = vtk.vtkCellArray() 45 | labels = [] 46 | 47 | # -------------------------------------------------------------------------- 48 | pid = 0 49 | kid = 0 50 | for key in data.keys(): 51 | 52 | pdata = data[key] 53 | #print key, '-->', kid, len(pdata) 54 | 55 | for p in pdata: 56 | points.InsertNextPoint(p[0],p[1],p[2]) 57 | pid += 1 58 | 59 | cell = vtk.vtkVertex() 60 | cell.GetPointIds().SetId(0, pid-1) 61 | cells.InsertNextCell(cell) 62 | 63 | labels.append(kid) 64 | kid += 1 65 | 66 | polydata.SetPoints(points) 67 | polydata.SetPolys(cells) 68 | 69 | VTK_data = numpy_support.numpy_to_vtk(num_array=np.array(labels)) 70 | VTK_data.SetName('plabels') 71 | polydata.GetPointData().AddArray(VTK_data) 72 | 73 | VTK_data2 = numpy_support.numpy_to_vtk(num_array=np.array(labels)) 74 | VTK_data2.SetName('clabels') 75 | polydata.GetCellData().AddArray(VTK_data2) 76 | 77 | writer.SetInputData(polydata) 78 | writer.Write() 79 | 80 | # ------------------------------------------------------------------------------ 81 | # text output of cocg 82 | # ------------------------------------------------------------------------------ 83 | def write_chgcom(filename, apos, cpos): 84 | 85 | print 'Writing', filename, '...', 86 | sys.stdout.flush() 87 | fp = open(filename, 'w') 88 | 89 | fp.write(" %4s %11s %11s %11s %13s %13s %13s %13s\n" % 90 | ("#", "X", "Y", "Z", "cX", "cY", "cZ", "magn(c)")); 91 | fp.write("-------------------------------------------------------------------------------------------------\n") 92 | 93 | for k in xrange(natoms): 94 | a = apos[k] 95 | c = cpos[k] 96 | fp.write(" %4s %11.6f %11.6f %11.6f %+1.6e %+1.6e %+1.6e %+1.6e\n" % 97 | (k, a[0], a[1], a[2], c[0], c[1], c[2], np.linalg.norm(np.array(c)))); 98 | 99 | #0:+1.2f 100 | 101 | fp.write("-------------------------------------------------------------------------------------------------\n") 102 | fp.close() 103 | print 'Done!' 104 | 105 | # ------------------------------------------------------------------------------ 106 | def periodic_displacement(a, b, dims): 107 | 108 | debug = False 109 | disp = a-b 110 | hdims = 0.5*dims 111 | if debug: 112 | print 'compute pdisp', a, b, dims, hdims 113 | print disp 114 | for i in [0,1,2]: 115 | if disp[i] > hdims[i]: 116 | if debug: 117 | print 'case 1: ', disp[i], 118 | disp[i] = disp[i] - dims[i] 119 | if debug: 120 | print '--->', disp[i], 121 | 122 | elif disp[i] < -hdims[i]: 123 | if debug: 124 | print 'case 2: ', disp[i], 125 | disp[i] = disp[i] + dims[i] 126 | if debug: 127 | print '--->', disp[i], 128 | #exit() 129 | if debug: 130 | print disp 131 | return disp 132 | 133 | # ------------------------------------------------------------------------------ 134 | # ------------------------------------------------------------------------------ 135 | if __name__ == '__main__': 136 | 137 | # -------------------------------------------------------------------------- 138 | parser = argparse.ArgumentParser(description='Compute charge center of mass using Bader analysis done through TopoMS') 139 | parser.add_argument('--infile', metavar='(infile)', required=True, nargs=1, help='Input CHGCAR file') 140 | args = parser.parse_args() 141 | 142 | chgVASPfilename = args.infile[0] # input VASP file 143 | chgVTIfilename = chgVASPfilename+'.vti' # this contains the VASP data in raw format 144 | volfilename = chgVASPfilename+'-Atoms2Vol.vti' 145 | periodic = True 146 | 147 | # -------------------------------------------------------------------------- 148 | # read chgcar file to get data about atomic position 149 | # we read function values from vti, hence pass False at the end 150 | (sysname, scalingfactor, lattice, species, atompos, grid, data) = readCAR(chgVASPfilename, False) 151 | 152 | def direct2grid(p): 153 | return np.array([int(round(grid[d]*p[d])) for d in xrange(3)]) 154 | 155 | def grid2direct(p): 156 | return np.array([p[d]/float(grid[d]) for d in xrange(3)]) 157 | 158 | def direct2phys(p): 159 | return np.array([scalingfactor*lattice[d][d]*p[d] for d in xrange(3)]) 160 | 161 | def phys2direct(p): 162 | return np.array([p[d]/(scalingfactor*lattice[d][d]) for d in xrange(3)]) 163 | 164 | def grid2phys(p): 165 | return np.array([scalingfactor*lattice[d][d]*p[d]/float(grid[d]) for d in xrange(3)]) 166 | 167 | def phys2grid(p): 168 | return np.array([p[d]*float(grid[d])/(scalingfactor*lattice[d][d]) for d in xrange(3)]) 169 | 170 | grid = np.array(grid) 171 | pdims = direct2phys([1.0,1.0,1.0]) 172 | spacings = grid2phys([1,1,1]) 173 | 174 | voxvol = spacings.prod() 175 | chgDens_fileUnit2e = 1.0 / float(grid[0]*grid[1]*grid[2]); 176 | 177 | # atoms in CHGCAR files are given in direct coordinates ([0,1]) 178 | # convert them to physical coordinates 179 | natoms = len(atompos) 180 | atompos = np.array([direct2phys(apos) for apos in atompos]) 181 | 182 | # volumes and charge 183 | chg = read_vti(chgVTIfilename, 'charge') * chgDens_fileUnit2e # convert from density to charge! 184 | vol = read_vti(volfilename, 'atom_labeling') 185 | 186 | # print info about the data 187 | print '\tLattice =', pdims 188 | print '\tGrid =', grid 189 | print '\tSpacings =', spacings 190 | print '\tVox vol =', voxvol 191 | print '\tSpecies =', species 192 | print '\tSharge =', chg.shape, chg.dtype, chg.min(), chg.max() 193 | print '\tLabels =', vol.shape, vol.dtype, np.unique(vol) 194 | print '\tAtom pos =\n', atompos 195 | 196 | assert(natoms == len(np.unique(vol))) 197 | assert(chg.shape[0] == grid[0] and chg.shape[1] == grid[1] and chg.shape[2] == grid[2]) 198 | assert(vol.shape[0] == grid[0] and vol.shape[1] == grid[1] and vol.shape[2] == grid[2]) 199 | 200 | # -------------------------------------------------------------------------- 201 | # for each Bader region (each atom) 202 | 203 | # total number of pixels 204 | anpixels = np.zeros(natoms, np.int) 205 | 206 | # total charge 207 | ascharges = np.zeros(natoms) 208 | 209 | # net displacement of all pixels (with respect to the atom) 210 | asdisps = np.zeros([natoms, 3]) 211 | 212 | # center of charge gravity 213 | # weighted sum of positions of all pixels (with respect to the atom) 214 | acocg = np.zeros([natoms, 3]) 215 | 216 | # go over all pixels 217 | for z in xrange(grid[2]): 218 | for y in xrange(grid[1]): 219 | for x in xrange(grid[0]): 220 | 221 | l = vol[x,y,z]-1 222 | c = chg[x,y,z] 223 | 224 | apos = atompos[l] 225 | ppix = grid2phys([x,y,z]) 226 | 227 | # i cant simply add pixels, because of periodic boundary 228 | # so, compute the displacement with respect to the atom 229 | disp = periodic_displacement(ppix, apos, pdims) 230 | 231 | anpixels[l] += 1 232 | ascharges[l] += c 233 | asdisps[l] += disp 234 | acocg[l] += c*disp 235 | 236 | ''' 237 | print ' bcnts :\n', anpixels 238 | print ' ascharges :\n', ascharges 239 | print ' asdisps :\n', asdisps 240 | print ' coc-gravity :\n', acocg 241 | ''' 242 | 243 | anpixels = anpixels.astype(np.float32) 244 | for k in xrange(natoms): 245 | acocg[k] /= anpixels[k] 246 | asdisps[k] /= anpixels[k] 247 | anpixels[k] *= voxvol # convert to physical volume 248 | 249 | for i in xrange(natoms): 250 | print 'Atom {} at {}: chg = {}, vol = {}, avg_disp {}, cocg = {}'.format( 251 | i+1, atompos[i], ascharges[i], anpixels[i], asdisps[i], acocg[i]) 252 | 253 | fname = volfilename[:-4] + '-chgcog.txt' 254 | write_chgcom(fname, atompos, acocg) 255 | # ------------------------------------------------------------------------------ 256 | # ------------------------------------------------------------------------------ 257 | -------------------------------------------------------------------------------- /msc/include/labeling_to_bounary_labeling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 University of Utah 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the copyright holder nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef VERTEX_LABELING_TO_BOUNDARY_LABELING_H 31 | #define VERTEX_LABELING_TO_BOUNDARY_LABELING_H 32 | 33 | #include 34 | #include "basic_types.h" 35 | #include "regular_grid.h" 36 | #include "topological_regular_grid.h" 37 | #include "labeling.h" 38 | #include "array_index_partition.h" 39 | 40 | namespace MSC { 41 | 42 | 43 | 44 | 45 | template 46 | class VertexLabelingToBoundaryLabeling { 47 | protected: 48 | DenseLabeling* m_input_labels; 49 | DenseLabeling* m_output_labels; 50 | 51 | TopologicalRegularGrid* m_topological_grid; 52 | public: 53 | 54 | VertexLabelingToBoundaryLabeling(DenseLabeling* input_labels, TopologicalRegularGrid* topological_grid) : 55 | m_input_labels(input_labels), m_topological_grid(topological_grid) { 56 | m_output_labels = new DenseLabeling(m_topological_grid->numCells()); 57 | m_output_labels->SetAll(0); 58 | } 59 | 60 | 61 | void OutputEdgesToFile(const char* filename) { 62 | FILE* fout = fopen(filename, "wb"); 63 | 64 | TopologicalRegularGrid::DCellsIterator edges(m_topological_grid, 1); 65 | for (edges.begin(); edges.valid(); edges.advance()) { 66 | INDEX_TYPE edge = edges.value(); 67 | if (m_output_labels->GetLabel(edge) == 1) 68 | fwrite(&edge, sizeof(INDEX_TYPE), 1, fout); 69 | } 70 | fclose(fout); 71 | 72 | } 73 | 74 | 75 | DenseLabeling* GetOutputLabels() { return m_output_labels; } 76 | 77 | DenseLabeling* ComputeBoundary() { 78 | #pragma omp parallel 79 | { 80 | int num_threads = omp_get_num_threads(); 81 | int thread_num = omp_get_thread_num(); 82 | std::vector partition; 83 | ArrayIndexPartitioner::EvenChunkSplit(m_topological_grid->numCells(), num_threads, partition); 84 | 85 | TopologicalRegularGrid::DCellsIterator edges(m_topological_grid, 1, partition[thread_num], partition[thread_num + 1]); 86 | for (edges.begin(); edges.valid(); edges.advance()) { 87 | TopologicalRegularGrid::FacetsIterator vertices(m_topological_grid); 88 | INDEX_TYPE edge = edges.value(); 89 | vertices.begin(edge); 90 | INDEX_TYPE vertex1 = vertices.value(); 91 | vertices.advance(); 92 | INDEX_TYPE vertex2 = vertices.value(); 93 | 94 | INDEX_TYPE vertex_number1 = m_topological_grid->VertexNumberFromCellID(vertex1); 95 | INDEX_TYPE vertex_number2 = m_topological_grid->VertexNumberFromCellID(vertex2); 96 | 97 | if ((*m_input_labels)[vertex_number1] != (*m_input_labels)[vertex_number2]) { 98 | (*m_output_labels)[edge] = 1; 99 | } 100 | 101 | } 102 | #pragma omp barrier 103 | TopologicalRegularGrid::DCellsIterator quads(m_topological_grid, 2, partition[thread_num], partition[thread_num + 1]); 104 | for (quads.begin(); quads.valid(); quads.advance()) { 105 | INDEX_TYPE quad = quads.value(); 106 | TopologicalRegularGrid::FacetsIterator quadedges(m_topological_grid); 107 | 108 | for (quadedges.begin(quad); quadedges.valid(); quadedges.advance()) { 109 | if ((*m_output_labels)[quadedges.value()] == 1) { 110 | (*m_output_labels)[quad] = 1; 111 | break; 112 | } 113 | } 114 | 115 | 116 | } 117 | #pragma omp barrier 118 | TopologicalRegularGrid::DCellsIterator voxels(m_topological_grid, 3, partition[thread_num], partition[thread_num + 1]); 119 | for (voxels.begin(); voxels.valid(); voxels.advance()) { 120 | INDEX_TYPE voxel = voxels.value(); 121 | TopologicalRegularGrid::FacetsIterator voxelquads(m_topological_grid); 122 | for (voxelquads.begin(voxel); voxelquads.valid(); voxelquads.advance()) { 123 | if ((*m_output_labels)[voxelquads.value()] == 1) { 124 | (*m_output_labels)[voxel] = 1; 125 | break; 126 | } 127 | } 128 | 129 | } 130 | 131 | 132 | } 133 | return m_output_labels; 134 | } 135 | 136 | 137 | 138 | DenseLabeling* ComputeBoundaryHACK() { 139 | #pragma omp parallel 140 | { 141 | int num_threads = omp_get_num_threads(); 142 | int thread_num = omp_get_thread_num(); 143 | std::vector partition; 144 | ArrayIndexPartitioner::EvenChunkSplit(m_topological_grid->numCells(), num_threads, partition); 145 | 146 | TopologicalRegularGrid::DCellsIterator edges(m_topological_grid, 1, partition[thread_num], partition[thread_num + 1]); 147 | for (edges.begin(); edges.valid(); edges.advance()) { 148 | TopologicalRegularGrid::FacetsIterator vertices(m_topological_grid); 149 | INDEX_TYPE edge = edges.value(); 150 | vertices.begin(edge); 151 | INDEX_TYPE vertex1 = vertices.value(); 152 | vertices.advance(); 153 | INDEX_TYPE vertex2 = vertices.value(); 154 | 155 | INDEX_TYPE vertex_number1 = m_topological_grid->VertexNumberFromCellID(vertex1); 156 | INDEX_TYPE vertex_number2 = m_topological_grid->VertexNumberFromCellID(vertex2); 157 | 158 | if ((*m_input_labels)[vertex_number1] != (*m_input_labels)[vertex_number2]) { 159 | INDEX_TYPE lv = ((*m_input_labels)[vertex_number1] > (*m_input_labels)[vertex_number2] ? (*m_input_labels)[vertex_number1] : (*m_input_labels)[vertex_number2]); 160 | (*m_output_labels)[edge] = (lv % 126 + 1); 161 | } 162 | 163 | } 164 | #pragma omp barrier 165 | TopologicalRegularGrid::DCellsIterator quads(m_topological_grid, 2, partition[thread_num], partition[thread_num + 1]); 166 | for (quads.begin(); quads.valid(); quads.advance()) { 167 | INDEX_TYPE quad = quads.value(); 168 | TopologicalRegularGrid::FacetsIterator quadedges(m_topological_grid); 169 | 170 | for (quadedges.begin(quad); quadedges.valid(); quadedges.advance()) { 171 | if ((*m_output_labels)[quadedges.value()] == 1) { 172 | (*m_output_labels)[quad] = 1; 173 | break; 174 | } 175 | } 176 | 177 | 178 | } 179 | #pragma omp barrier 180 | TopologicalRegularGrid::DCellsIterator voxels(m_topological_grid, 3, partition[thread_num], partition[thread_num + 1]); 181 | for (voxels.begin(); voxels.valid(); voxels.advance()) { 182 | INDEX_TYPE voxel = voxels.value(); 183 | TopologicalRegularGrid::FacetsIterator voxelquads(m_topological_grid); 184 | for (voxelquads.begin(voxel); voxelquads.valid(); voxelquads.advance()) { 185 | if ((*m_output_labels)[voxelquads.value()] == 1) { 186 | (*m_output_labels)[voxel] = 1; 187 | break; 188 | } 189 | } 190 | 191 | } 192 | 193 | 194 | } 195 | return m_output_labels; 196 | } 197 | 198 | }; 199 | 200 | 201 | 202 | 203 | } 204 | 205 | #endif 206 | -------------------------------------------------------------------------------- /topoms/include/ConfigParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file ConfigParser.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2017 63 | * 64 | * @brief This class handles the parsing of the input configuration file to TopoMS 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This class handles the parsing of the input configuration file to TopoMS. 69 | */ 70 | 71 | #ifndef _CONFIGPARSER_H_ 72 | #define _CONFIGPARSER_H_ 73 | 74 | #include 75 | #include 76 | #include 77 | 78 | #include "Utils.h" 79 | 80 | class Config { 81 | 82 | const std::string configname; 83 | 84 | public: 85 | std::string infiletype; // VASP or CUBE 86 | std::string fieldtype; // CHG or POT 87 | 88 | std::string infilename; 89 | std::string reffilename; 90 | 91 | bool is_periodic[3]; 92 | 93 | bool do_bader; // parameters for bader anlaysis 94 | double threshold_vacuum; 95 | 96 | bool do_msc; // parameters for msc 97 | double threshold_simp; 98 | double threshold_filt; 99 | 100 | double threshold_grad; // other internal parameters 101 | double threshold_error; 102 | int numiter; 103 | int rkindex; 104 | 105 | std::string tfpath; // optional 106 | 107 | public: 108 | /** 109 | * @brief Initialize the constructor for a config file. 110 | * 111 | * @param fname is the name of the config file 112 | */ 113 | Config(const std::string fname) : configname(fname), 114 | infilename(""), reffilename(""), infiletype(""), fieldtype(""), tfpath(""), 115 | do_bader(false), threshold_vacuum(-1), 116 | do_msc(false), threshold_simp(-1), threshold_filt(-1), 117 | threshold_grad(-1), threshold_error(-1), numiter(1), rkindex(1) 118 | { 119 | for(uint8_t i = 0; i < 3; i++){ 120 | is_periodic[i] = 0; 121 | //grid_dims[i] = 0; 122 | } 123 | } 124 | 125 | /** 126 | * @brief Parses the config file specified to the constructor. 127 | * 128 | * @return void 129 | */ 130 | void parse() { 131 | 132 | bool need_newline = false; 133 | 134 | std::cout << " Parsing config file (" << configname << ")..."; 135 | fflush(stdout); 136 | 137 | std::ifstream infile( configname.c_str() ); 138 | std::string line; 139 | 140 | // read all known parameters 141 | while (std::getline(infile, line)) { 142 | 143 | line = Utils::trim(line); 144 | if (line.empty() || line.at(0) == '#') 145 | continue; 146 | 147 | std::vector toks = Utils::tokenize(line, '='); 148 | std::string &p = toks[0]; 149 | std::string &v = toks[1]; 150 | 151 | Utils::trim(p); 152 | Utils::trim(v); 153 | 154 | Utils::toupper(p); 155 | 156 | if(p == "INFILE"){ infilename = v; continue; } 157 | if(p == "REFCHG"){ reffilename = v; continue; } 158 | if(p == "INFILETYPE"){ infiletype = Utils::toupper(v); continue; } 159 | if(p == "FIELDTYPE"){ fieldtype = Utils::toupper(v); continue; } 160 | 161 | if(p == "PERIODIC_DOMAIN"){ 162 | sscanf(v.c_str(), "%d %d %d", &is_periodic[0], &is_periodic[1], &is_periodic[2]); 163 | continue; 164 | } 165 | 166 | if(p == "BADER_VOLUMES"){ do_bader = (Utils::toupper(v) == "TRUE"); continue; } 167 | if(p == "THRESHOLD_VACUUM"){ threshold_vacuum = stof(v); continue; } 168 | 169 | if(p == "MOLECULAR_GRAPH"){ do_msc = (Utils::toupper(v) == "TRUE"); continue; } 170 | if(p == "THRESHOLD_SIMPL"){ threshold_simp = stof(v); continue; } 171 | if(p == "THRESHOLD_FILT"){ threshold_filt = stof(v); continue; } 172 | 173 | if(p == "THRESHOLD_GRAD"){ threshold_grad = stof(v); continue; } 174 | if(p == "THRESHOLD_ERROR"){ threshold_error = stof(v); continue; } 175 | if(p == "NUM_ITER"){ numiter = stoi(v); continue; } 176 | if(p == "RK_INDEX"){ rkindex = stoi(v); continue; } 177 | 178 | if(p == "TRANSFER_FUNC"){ tfpath = v; continue; } 179 | 180 | std::cerr << "\n Config::parse() - Ignoring unknown parameter: " << line; 181 | need_newline = true; 182 | } 183 | 184 | // check if everything is in order 185 | if (infilename.length() == 0) { 186 | std::cerr << "\n Config::parse() - Filename not specified. Aborting!\n"; 187 | exit(1); 188 | } 189 | if (infiletype.length() == 0) { 190 | std::cerr << "\n Config::parse() - Filetype not specified. Aborting!\n"; 191 | exit(1); 192 | } 193 | if (fieldtype.length() == 0) { 194 | std::cerr << "\n Config::parse() - Fieldtype not specified. Aborting!\n"; 195 | exit(1); 196 | } 197 | if (fieldtype != "CHG" && fieldtype != "POT" && fieldtype != "OTHER") { 198 | std::cerr << "\n Config::parse() - Invalid Fieldtype ("< 0) { 203 | reffilename = ""; 204 | std::cerr << "\n Config::parse() - Ignoring REFCHG because FIELDTYPE != CHG"; 205 | need_newline = true; 206 | } 207 | if(threshold_vacuum < 0){ 208 | threshold_vacuum = 0.1; 209 | std::cout << "\n Config::parse() - THRESHOLD_VACUUM not found. defaulting to " << threshold_vacuum; 210 | need_newline = true; 211 | } 212 | if(threshold_simp < 0){ 213 | threshold_simp = 1.0; 214 | std::cout << "\n Config::parse() - THRESHOLD_SIMPL not found. defaulting to " << threshold_simp; 215 | need_newline = true; 216 | } 217 | if(threshold_filt < 0){ 218 | threshold_filt = 1.0; 219 | std::cout << "\n Config::parse() - THRESHOLD_FILT not found. defaulting to " << threshold_filt; 220 | need_newline = true; 221 | } 222 | if(need_newline) 223 | std::cout << std::endl; 224 | std::cout << " Done!\n"; 225 | } 226 | }; 227 | 228 | #endif 229 | -------------------------------------------------------------------------------- /topoms/include/Material.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file Material.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2017 63 | * 64 | * @brief This class handles the properties of different types of materials 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This class handles the properties of different types of materials 69 | * 70 | */ 71 | 72 | #ifndef _MATERIAL_H_ 73 | #define _MATERIAL_H_ 74 | 75 | #include 76 | #include 77 | #include 78 | #include 79 | 80 | class Material { 81 | 82 | static std::string atomic_number_to_symbol(const unsigned int &_) { 83 | switch(_) { 84 | case 1 : return "H"; 85 | case 2 : return "He"; 86 | case 3 : return "Li"; 87 | case 4 : return "Be"; 88 | case 5 : return "B"; 89 | case 6 : return "C"; 90 | case 7 : return "N"; 91 | case 8 : return "O"; 92 | case 9 : return "F"; 93 | case 10 : return "Ne"; 94 | case 11 : return "Na"; 95 | case 12 : return "Mg"; 96 | case 13 : return "Al"; 97 | case 14 : return "Si"; 98 | case 15 : return "P"; 99 | case 16 : return "S"; 100 | case 17 : return "Cl"; 101 | case 18 : return "Ar"; 102 | case 19 : return "K"; 103 | case 20 : return "Ca"; 104 | case 21 : return "Sc"; 105 | case 22 : return "Ti"; 106 | case 23 : return "V"; 107 | case 24 : return "Cr"; 108 | case 25 : return "Mn"; 109 | case 26 : return "Fe"; 110 | case 27 : return "Co"; 111 | case 28 : return "Ni"; 112 | case 29 : return "Cu"; 113 | case 30 : return "Zn"; 114 | case 31 : return "Ga"; 115 | case 32 : return "Ge"; 116 | case 33 : return "As"; 117 | case 34 : return "Se"; 118 | case 35 : return "Br"; 119 | case 36 : return "Kr"; 120 | case 37 : return "Rb"; 121 | case 38 : return "Sr"; 122 | case 39 : return "Y"; 123 | case 40 : return "Zr"; 124 | case 41 : return "Nb"; 125 | case 42 : return "Mo"; 126 | case 43 : return "Tc"; 127 | case 44 : return "Ru"; 128 | case 45 : return "Rh"; 129 | case 46 : return "Pd"; 130 | case 47 : return "Ag"; 131 | case 48 : return "Cd"; 132 | case 49 : return "In"; 133 | case 50 : return "Sn"; 134 | case 51 : return "Sb"; 135 | case 52 : return "Te"; 136 | case 53 : return "I"; 137 | case 54 : return "Xe"; 138 | case 55 : return "Cs"; 139 | case 56 : return "Ba"; 140 | case 57 : return "La"; 141 | case 58 : return "Ce"; 142 | case 59 : return "Pr"; 143 | case 60 : return "Nd"; 144 | case 61 : return "Pm"; 145 | case 62 : return "Sm"; 146 | case 63 : return "Eu"; 147 | case 64 : return "Gd"; 148 | case 65 : return "Tb"; 149 | case 66 : return "Dy"; 150 | case 67 : return "Ho"; 151 | case 68 : return "Er"; 152 | case 69 : return "Tm"; 153 | case 70 : return "Yb"; 154 | case 71 : return "Lu"; 155 | case 72 : return "Hf"; 156 | case 73 : return "Ta"; 157 | case 74 : return "W"; 158 | case 75 : return "Re"; 159 | case 76 : return "Os"; 160 | case 77 : return "Ir"; 161 | case 78 : return "Pt"; 162 | case 79 : return "Au"; 163 | case 80 : return "Hg"; 164 | case 81 : return "Tl"; 165 | case 82 : return "Pb"; 166 | case 83 : return "Bi"; 167 | case 84 : return "Po"; 168 | case 85 : return "At"; 169 | case 86 : return "Rn"; 170 | case 87 : return "Fr"; 171 | case 88 : return "Ra"; 172 | case 89 : return "Ac"; 173 | case 90 : return "Th"; 174 | case 91 : return "Pa"; 175 | case 92 : return "U"; 176 | case 93 : return "Np"; 177 | case 94 : return "Pu"; 178 | case 95 : return "Am"; 179 | case 96 : return "Cm"; 180 | case 97 : return "Bk"; 181 | case 98 : return "Cf"; 182 | case 99 : return "Es"; 183 | case 100 : return "Fm"; 184 | case 101 : return "Md"; 185 | case 102 : return "No"; 186 | case 103 : return "Lr"; 187 | case 104 : return "Rf"; 188 | case 105 : return "Db"; 189 | case 106 : return "Sg"; 190 | case 107 : return "Bh"; 191 | case 108 : return "Hs"; 192 | case 109 : return "Mt"; 193 | case 110 : return "Ds"; 194 | case 111 : return "Rg"; 195 | case 112 : return "Uub"; 196 | case 113 : return "Uut"; 197 | case 114 : return "Uuq"; 198 | case 115 : return "Uup"; 199 | case 116 : return "Uuh"; 200 | case 117 : return "Uus"; 201 | case 118 : return "Uuo"; 202 | } 203 | return "unknown"; 204 | } 205 | public: 206 | std::string m_symbol; 207 | unsigned int m_atom_number; 208 | float m_charge; 209 | float *m_pos; 210 | 211 | Material(unsigned int n, float chg, float x, float y, float z) { 212 | m_symbol = ""; 213 | m_atom_number = n; 214 | m_charge = chg; 215 | m_pos = new float[3]; 216 | m_pos[0] = x; m_pos[1] = y; m_pos[2] = z; 217 | m_symbol = atomic_number_to_symbol(n); 218 | } 219 | 220 | Material(std::string s, float x, float y, float z) { 221 | m_symbol = s; 222 | m_atom_number = 0; 223 | m_charge = -1; 224 | m_pos = new float[3]; 225 | m_pos[0] = x; m_pos[1] = y; m_pos[2] = z; 226 | } 227 | 228 | float nelectrons() const { return (float) m_atom_number; } 229 | 230 | float radius() const { 231 | 232 | // get radius in Angstroms in Angstrom 233 | // http://www.periodictable.com/Properties/A/AtomicRadius.v.wt.html 234 | 235 | if(m_symbol == "F") return 0.42; 236 | if(m_symbol == "O") return 0.48; 237 | if(m_symbol == "H") return 0.53; 238 | if(m_symbol == "C") return 0.67; 239 | if(m_symbol == "Cl") return 0.79; 240 | if(m_symbol == "B") return 0.87; 241 | if(m_symbol == "P") return 0.98; 242 | if(m_symbol == "Li") return 1.67; 243 | if(m_symbol == "Ti") return 1.76; 244 | if(m_symbol == "Ca") return 1.94; 245 | 246 | return 1.0; 247 | } 248 | 249 | bool operator == (const Material &m) const { 250 | 251 | static const float eps = 0.00001; 252 | 253 | if (m_symbol.compare(m.m_symbol) != 0) return false; 254 | if (m_atom_number != m.m_atom_number) return false; 255 | if (fabs(m_charge - m.m_charge) > eps) return false; 256 | 257 | if (fabs(m_pos[0] - m.m_pos[0]) > eps) return false; 258 | if (fabs(m_pos[1] - m.m_pos[1]) > eps) return false; 259 | if (fabs(m_pos[2] - m.m_pos[2]) > eps) return false; 260 | return true; 261 | } 262 | 263 | void print(int id = -1) const { 264 | 265 | std::cout << " Atom "; 266 | if(id != -1) { std::cout << id << ": "; } 267 | if(m_symbol != "") { std::cout << m_symbol << " "; } 268 | if(m_atom_number != 0) { std::cout << "[" << int(m_atom_number) << "] "; } 269 | std::cout << "at (" << m_pos[0]<<", "< 34 | #include 35 | #include "basic_types.h" 36 | #include "topological_regular_grid.h" 37 | #include "array_index_partition.h" 38 | #include "regular_grid_trilinear_function.h" 39 | 40 | namespace MSC { 41 | 42 | typedef TopologicalRegularGrid Mesh; 43 | typedef float dtype; 44 | 45 | class TopologicalExplicitDenseMeshFunction { 46 | protected: 47 | Mesh* mMesh; 48 | dtype* mVals; 49 | public: 50 | 51 | //// assume all facet values are correct!!! 52 | dtype maxOfFacets(INDEX_TYPE cellid) { 53 | dtype result; 54 | Mesh::FacetsIterator fit(mMesh); 55 | fit.begin(cellid); 56 | result = this->cellValue(fit.value()); 57 | fit.advance(); 58 | for (; fit.valid(); fit.advance()) { 59 | dtype tmpother = cellValue(fit.value()); 60 | result = (result > tmpother ? result : tmpother); 61 | } 62 | return result; 63 | } 64 | 65 | INDEX_TYPE maxIdOfVerts(INDEX_TYPE cellid) { 66 | INDEX_TYPE result; 67 | Mesh::CellVerticesIterator vit(mMesh); 68 | vit.begin(cellid); 69 | result = vit.value(); 70 | vit.advance(); 71 | for (; vit.valid(); vit.advance()) { 72 | INDEX_TYPE tmpotherid = vit.value(); 73 | if (this->greaterThan(tmpotherid, result)) result = tmpotherid; 74 | } 75 | return result; 76 | } 77 | 78 | 79 | 80 | dtype minOfFacets(INDEX_TYPE cellid) { 81 | dtype result; 82 | Mesh::FacetsIterator fit(mMesh); 83 | fit.begin(cellid); 84 | result = this->cellValue(fit.value()); 85 | fit.advance(); 86 | for (; fit.valid(); fit.advance()) { 87 | dtype tmpother = cellValue(fit.value()); 88 | result = (result < tmpother ? result : tmpother); 89 | } 90 | return result; 91 | } 92 | // // assume all facet values are correct!!! 93 | //dtype ave_of_facets(CELL_INDEX_TYPE cellid) { 94 | // 95 | // dtype result = 0; 96 | // dtype count = 0; 97 | // 98 | // cellIterator it; 99 | // iteratorOperator& ito = my_mesh_handler->facets(cellid, it); 100 | // ito.begin(it); 101 | // 102 | // while (ito.valid(it)) { 103 | // result += cell_value(ito.value(it)); 104 | // count += 1; 105 | // ito.advance(it); 106 | // } 107 | // return result / count; 108 | //} 109 | //// first do 0's. Assume that the i'th 0-cell in the mesh is the i'th vertex in data 110 | //void set_vertex_values() { 111 | // mscBasicArray& values_r = *(my_values); 112 | 113 | // cellIterator it; 114 | // iteratorOperator& ito = my_mesh_handler->d_cells_iterator(0, it); 115 | // ito.begin(it); 116 | // CELL_INDEX_TYPE temp_grad_2_data = 0; 117 | // 118 | // while (ito.valid(it)) { 119 | // values_r[ito.value(it)] = my_data_handler->value(temp_grad_2_data); 120 | // temp_grad_2_data++; 121 | // ito.advance(it); 122 | // } 123 | //} 124 | 125 | //void set_cell_values(DIM_TYPE dim) { 126 | // mscBasicArray& values_r = *(my_values); 127 | 128 | // cellIterator it; 129 | // iteratorOperator& ito = my_mesh_handler->d_cells_iterator(dim, it); 130 | // ito.begin(it); 131 | // 132 | // while (ito.valid(it)) { 133 | // CELL_INDEX_TYPE temp_id = ito.value(it); 134 | // values_r[temp_id] = max_of_facets(temp_id); 135 | // ito.advance(it); 136 | // } 137 | //} 138 | 139 | public: 140 | TopologicalExplicitDenseMeshFunction() { 141 | mVals = NULL; 142 | mMesh = NULL; 143 | } 144 | 145 | ~TopologicalExplicitDenseMeshFunction() { 146 | if (mVals != NULL) delete[] mVals; 147 | } 148 | 149 | void setMeshAndAllocate(Mesh* m) { 150 | mMesh = m; 151 | if (mVals != NULL) delete[] mVals; 152 | mVals = new dtype[m->numCells()]; 153 | } 154 | 155 | dtype cellValue(INDEX_TYPE cellid) const { 156 | return mVals[cellid]; 157 | } 158 | 159 | void setCellValue(INDEX_TYPE cellid, dtype val) { 160 | mVals[cellid] = val; 161 | } 162 | 163 | void setCellValuesMaxOfVerts() { 164 | for (int i = 1; i <= mMesh->maxDim(); i++) { 165 | #pragma omp parallel 166 | { 167 | int num_threads = omp_get_num_threads(); 168 | int thread_num = omp_get_thread_num(); 169 | std::vector partition; 170 | ArrayIndexPartitioner::EvenChunkSplit(mMesh->numCells(), num_threads, partition); 171 | Mesh::DCellsIterator dcells(mMesh, i, partition[thread_num], partition[thread_num + 1]); 172 | for (dcells.begin(); dcells.valid(); dcells.advance()) { 173 | INDEX_TYPE cellid = dcells.value(); 174 | setCellValue(cellid, maxOfFacets(cellid)); 175 | } 176 | } 177 | } 178 | } 179 | 180 | void setCellValuesMinOfVerts() { 181 | for (int i = 1; i <= mMesh->maxDim(); i++) { 182 | #pragma omp parallel 183 | { 184 | int num_threads = omp_get_num_threads(); 185 | int thread_num = omp_get_thread_num(); 186 | std::vector partition; 187 | ArrayIndexPartitioner::EvenChunkSplit(mMesh->numCells(), num_threads, partition); 188 | Mesh::DCellsIterator dcells(mMesh, i, partition[thread_num], partition[thread_num + 1]); 189 | for (dcells.begin(); dcells.valid(); dcells.advance()) { 190 | INDEX_TYPE cellid = dcells.value(); 191 | setCellValue(cellid, minOfFacets(cellid)); 192 | } 193 | } 194 | } 195 | } 196 | 197 | const Mesh* mesh() const { 198 | return this->mMesh; 199 | } 200 | bool lessThan(INDEX_TYPE a, INDEX_TYPE b) const { 201 | dtype av = cellValue(a); 202 | dtype bv = cellValue(b); 203 | if (av < bv) return true; 204 | if (bv < av) return false; 205 | return a < b; 206 | } 207 | bool greaterThan(INDEX_TYPE a, INDEX_TYPE b) const { 208 | return lessThan (b, a); 209 | } 210 | 211 | bool copyVertexValuesFromGridFunction(RegularGridTrilinearFunction* func) { 212 | #pragma omp parallel 213 | { 214 | int num_threads = omp_get_num_threads(); 215 | int thread_num = omp_get_thread_num(); 216 | std::vector partition; 217 | ArrayIndexPartitioner::EvenChunkSplit(mMesh->numCells(), num_threads, partition); 218 | Mesh::DCellsIterator vertices(mMesh, 0, partition[thread_num], partition[thread_num + 1]); 219 | for (vertices.begin(); vertices.valid(); vertices.advance()) { 220 | INDEX_TYPE cellid = vertices.value(); 221 | setCellValue(cellid,func->SampleImage(this->mMesh->VertexNumberFromCellID(cellid)) ); 222 | } 223 | 224 | } 225 | return true; 226 | } 227 | 228 | 229 | // assumes file is binary, with contiguous dense vertex values, where the ith value corresponds to the 230 | // value of the vertex after the vertex iterator has been advanced i times. 231 | // must come after the set mesh and allocate call, because it uses the mesh iterator 232 | // to go through vertices 233 | // return value is bool representing success or failure 234 | bool loadVerticesFromDenseFile(const char* filename) { 235 | // check that mesh has been set, return if not 236 | if (mMesh == NULL) { 237 | printf("Error: load called before mesh was set and allocated\n"); 238 | return false; 239 | } 240 | 241 | FILE* fdat = fopen(filename, "rb"); 242 | if (fdat == NULL) { 243 | printf("ERROR: file %s not found\n", filename); 244 | return false; 245 | } 246 | 247 | #define TBUFFSIZE 4096 248 | dtype tbuff[TBUFFSIZE]; 249 | 250 | Mesh::DCellsIterator zeros(mMesh, 0); 251 | INDEX_TYPE dataposition = 0; 252 | INDEX_TYPE maxposition = mMesh->numCells(0); 253 | 254 | for (zeros.begin(); zeros.valid(); zeros.advance()) { 255 | 256 | if (dataposition % TBUFFSIZE == 0) { 257 | int numtoread = std::min((INDEX_TYPE) TBUFFSIZE, maxposition - dataposition); 258 | int numbytesread = fread(tbuff, sizeof(dtype), numtoread, fdat); 259 | if (numtoread != numbytesread) { 260 | printf("Error: read misalignment, %d, %d, %d\n", numtoread, numbytesread, dataposition); 261 | return false; 262 | } 263 | } 264 | 265 | INDEX_TYPE vert = zeros.value(); 266 | this->setCellValue(vert, tbuff[dataposition % TBUFFSIZE]); 267 | dataposition++; 268 | } 269 | fclose(fdat); 270 | return true; 271 | } 272 | 273 | }; 274 | } 275 | #endif 276 | -------------------------------------------------------------------------------- /topoms/include/Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Lawrence Livermore National Security, LLC. 3 | Produced at the Lawrence Livermore National Laboratory. 4 | Written by Harsh Bhatia (hbhatia@llnl.gov) and Attila G Gyulassy 5 | (jediati@sci.utah.edu). 6 | LLNL-CODE-745278. All rights reserved. 7 | 8 | This file is part of TopoMS, Version 1.0. For details, see 9 | https://github.com/LLNL/TopoMS. Please also read this link – Additional BSD 10 | Notice. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | • Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the disclaimer below. 17 | • Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the disclaimer (as noted below) in the 19 | documentation and/or other materials provided with the distribution. 20 | • Neither the name of the LLNS/LLNL nor the names of its contributors may be 21 | used to endorse or promote products derived from this software without specific 22 | prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE 28 | U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | 38 | 1. This notice is required to be provided under our contract with the U.S. 39 | Department of Energy (DOE). This work was produced at Lawrence Livermore 40 | National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. 41 | 42 | 2. Neither the United States Government nor Lawrence Livermore National 43 | Security, LLC nor any of their employees, makes any warranty, express or 44 | implied, or assumes any liability or responsibility for the accuracy, 45 | completeness, or usefulness of any information, apparatus, product, or process 46 | disclosed, or represents that its use would not infringe privately-owned 47 | rights. 48 | 49 | 3. Also, reference herein to any specific commercial products, process, or 50 | services by trade name, trademark, manufacturer or otherwise does not 51 | necessarily constitute or imply its endorsement, recommendation, or favoring by 52 | the United States Government or Lawrence Livermore National Security, LLC. The 53 | views and opinions of authors expressed herein do not necessarily state or 54 | reflect those of the United States Government or Lawrence Livermore National 55 | Security, LLC, and shall not be used for advertising or product endorsement 56 | purposes. 57 | */ 58 | 59 | /** 60 | * @file Utils.h 61 | * @author Harsh Bhatia (hbhatia@llnl.gov) 62 | * @date 10/01/2017 63 | * 64 | * @brief This header provides some basic utility functions 65 | * 66 | * @section DESCRIPTION 67 | * 68 | * This header provides some basic utility functions 69 | * 70 | */ 71 | 72 | #ifndef _UTILS_H_ 73 | #define _UTILS_H_ 74 | 75 | #include 76 | #include 77 | #include 78 | 79 | #include 80 | #include 81 | #include 82 | 83 | #include 84 | 85 | namespace Utils { 86 | 87 | // ------------------------------------------------------- 88 | // basic mathematical utilities 89 | 90 | inline bool equals(double a, double b){ return (fabs(a-b) < powf(10,-5)); } 91 | 92 | inline float dist_sq(const float p[3], const float q[3]){ 93 | return ((p[0]-q[0])*(p[0]-q[0]) + (p[1]-q[1])*(p[1]-q[1]) + (p[2]-q[2])*(p[2]-q[2])); 94 | } 95 | 96 | inline float dist(const float p[3], const float q[3]){ return std::sqrt(dist_sq(p, q)); } 97 | 98 | inline float magn_sq(const float a[3]){ return (a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); } 99 | 100 | inline float magn(const float a[3]){ return std::sqrt(magn_sq(a)); } 101 | 102 | inline float dot(const float a[3], const float b[3]){ return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]); } 103 | 104 | inline float* cross(const float a[3], const float b[3]){ 105 | float *cp = new float[3]; 106 | cp[0] = a[1]*b[2] - a[2]*b[1]; 107 | cp[1] = a[2]*b[0] - a[0]*b[2]; 108 | cp[2] = a[0]*b[1] - a[1]*b[0]; 109 | return cp; 110 | } 111 | 112 | template 113 | inline T lerp(const T &a, const T &b, float l) { 114 | return (a + (b-a)*l); 115 | } 116 | 117 | template 118 | inline T2 lerp (const T1 &x, const T1 &x0, const T1 &x1, const T2 &y0, const T2 &y1) { 119 | 120 | float l = (x0 == x1) ? 0.0f : (float) (x-x0) / (float) (x1-x0); 121 | return lerp (y0, y1, l); 122 | } 123 | 124 | template 125 | inline T lerp2(const T &a, const T &b, const T &c, const T &d, 126 | float l1, float l2) { 127 | return lerp( lerp(a,b,l1), lerp(c,d,l1), l2 ); 128 | } 129 | 130 | template 131 | inline T lerp3(const T &a, const T &b, const T &c, const T &d, 132 | const T &e, const T &f, const T &g, const T &h, 133 | float l1, float l2, float l3) { 134 | return lerp( lerp2(a, b, c, d, l1, l2), lerp2(e, f, g, h, l1, l2), l3 ); 135 | } 136 | 137 | template 138 | bool lies_value_in_range(T v, T a, T b){ 139 | return !( v < a || v > b ); 140 | } 141 | 142 | // ------------------------------------------------------------------------- 143 | // ------------------------------------------------------------------------- 144 | // Kahan summation 145 | 146 | namespace Kahan { 147 | 148 | template 149 | struct KahanObject { 150 | T sum; 151 | T correction; 152 | }; 153 | 154 | template 155 | KahanObject KahanSum(KahanObject accumulation, T value) { 156 | KahanObject result; 157 | T y = value - accumulation.correction; 158 | T t = accumulation.sum + y; 159 | result.correction = (t - accumulation.sum) - y; 160 | result.sum = t; 161 | return result; 162 | } 163 | 164 | template 165 | T sum(const std::vector &values) { 166 | KahanObject k0 = {0}; 167 | return std::accumulate(values.begin(), values.end(), k0, KahanSum).sum; 168 | } 169 | template 170 | T sum(const T *values, size_t sz) { 171 | KahanObject k0 = {0}; 172 | return std::accumulate(values, values+sz, k0, KahanSum).sum; 173 | } 174 | } 175 | 176 | template 177 | T sum(const std::vector &values) { 178 | return std::accumulate(values.begin(), values.end(), T(0)); 179 | } 180 | template 181 | T sum(const T *values, size_t sz) { 182 | return std::accumulate(values, values+sz, T(0)); 183 | } 184 | 185 | // ------------------------------------------------------------------------- 186 | // ------------------------------------------------------------------------- 187 | 188 | template 189 | typename std::vector::const_iterator get_lowerIterator(const std::vector &vals, const T& value){ 190 | 191 | // upper_bound returns an iterator pointing to the first element that is 192 | // greater than the value. 193 | typename std::vector::const_iterator geq = std::upper_bound(vals.begin(), vals.end(), value); 194 | if(geq == vals.begin()) return geq; 195 | return --geq; 196 | } 197 | 198 | template 199 | std::size_t get_lowerIndex(const std::vector &vals, const T& value){ 200 | return std::distance(vals.begin(), get_lowerIterator(vals, value)); 201 | } 202 | 203 | template 204 | inline std::size_t snap_to_axis(T val, const std::vector &values){ 205 | return get_closestIndex(values, val); 206 | } 207 | 208 | // ------------------------------------------------------------------------- 209 | // handling periodic boundary 210 | 211 | 212 | // wrap around in [0,1] 213 | inline float wrap_around(float val, float min, float max){ 214 | return (val < min) ? (val + (max-min)) : 215 | (val > max) ? (val - (max-min)) : val; 216 | } 217 | 218 | inline float get_periodicDisplacement(float p, float q, float span) { 219 | float d = p-q; 220 | return (d > 0.5f*span) ? (d - span) : // q is on the left end, and p is on the right end 221 | (d < -0.5f*span) ? (d + span) : // p is on the left end, and q is on the right end 222 | d; // else! 223 | } 224 | 225 | inline float get_periodicDist_sq(const float p[3], const float q[3], const float span[3]) { 226 | float r[3]; 227 | for(unsigned int i = 0; i < 3; i++){ 228 | r[i] = get_periodicDisplacement(p[i], q[i], span[i]); 229 | } 230 | return (r[0]*r[0] + r[1]*r[1] + r[2]*r[2]); 231 | } 232 | 233 | inline float get_periodicDist(const float p[3], const float q[3], const float span[3]) { 234 | return std::sqrt(get_periodicDist_sq(p,q,span)); 235 | } 236 | 237 | // ------------------------------------------------------------------------- 238 | // IO related 239 | std::string get_extn(std::string filename); 240 | std::string get_directory(std::string filename); 241 | 242 | // read the files in a given directory 243 | std::vector get_directory_listing(std::string searchstring); 244 | 245 | // ------------------------------------------------------------------------- 246 | // strung utilities 247 | inline std::string remove_carriagereturn(std::string& str) { 248 | 249 | if (str.length() == 0) return str; 250 | if (str[str.length()-1] == '\r') str = str.erase(str.length()-1, 1); 251 | return str; 252 | } 253 | 254 | inline std::string trim(std::string& str) { 255 | str.erase(0, str.find_first_not_of(' ')); //prefixing spaces 256 | str.erase(str.find_last_not_of(' ')+1); //surfixing spaces 257 | return str; 258 | } 259 | 260 | inline std::string rtrim(std::string& str) { 261 | str.erase(std::find_if(str.rbegin(), str.rend(), [](int ch) { 262 | return !std::isspace(static_cast(ch)); 263 | }).base(), str.end()); 264 | return str; 265 | } 266 | 267 | inline std::string toupper(std::string& str) { 268 | for(uint32_t i=0; str[i]!=0; i++) { 269 | if(97 <= str[i] && str[i] <= 122){ 270 | str[i]-=32; 271 | } 272 | } 273 | return str; 274 | } 275 | 276 | // tokenize a string 277 | std::vector tokenize(std::string line); 278 | std::vector tokenize(const std::string &line, char delim); 279 | 280 | 281 | // for formatting output 282 | void print_separator(unsigned int n = 120); 283 | } 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | #endif 293 | --------------------------------------------------------------------------------