├── .clang-format ├── .github └── workflows │ └── netsci_CI.yml ├── .gitignore ├── .gitmodules ├── .readthedocs.yaml ├── CMakeLists.txt ├── README.md ├── build_scripts └── cuda_architecture.cu ├── cnpy ├── CMakeLists.txt ├── include │ └── cnpy.h └── src │ └── cnpy.cpp ├── cuarray ├── CMakeLists.txt ├── include │ └── cuarray.h ├── python │ ├── cuarray │ │ └── __init__.py │ └── setup.py ├── samples │ ├── cpp │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── CuArray_CuArray.cpp │ │ │ ├── CuArray_allocateDevice.cpp │ │ │ ├── CuArray_allocateHost.cpp │ │ │ ├── CuArray_allocatedDevice.cpp │ │ │ ├── CuArray_allocatedHost.cpp │ │ │ ├── CuArray_argsort.cpp │ │ │ ├── CuArray_bytes.cpp │ │ │ ├── CuArray_deallocateHost.cpp │ │ │ ├── CuArray_device.cpp │ │ │ ├── CuArray_fromCuArrayDeepCopy.cpp │ │ │ ├── CuArray_fromCuArrayShallowCopy.cpp │ │ │ ├── CuArray_fromNumpy1.cpp │ │ │ ├── CuArray_fromNumpy2.cpp │ │ │ ├── CuArray_get.cpp │ │ │ ├── CuArray_host.cpp │ │ │ ├── CuArray_init1.cpp │ │ │ ├── CuArray_init2.cpp │ │ │ ├── CuArray_load.cpp │ │ │ ├── CuArray_m.cpp │ │ │ ├── CuArray_n.cpp │ │ │ ├── CuArray_owner.cpp │ │ │ ├── CuArray_save.cpp │ │ │ ├── CuArray_set.cpp │ │ │ ├── CuArray_size.cpp │ │ │ ├── CuArray_sort.cpp │ │ │ ├── CuArray_subscriptOperator.cpp │ │ │ ├── CuArray_toDevice.cpp │ │ │ ├── CuArray_toHost.cpp │ │ │ ├── CuArray_toNumpy1.cpp │ │ │ └── CuArray_toNumpy2.cpp │ └── python │ │ ├── CuArray___getitem__.py │ │ ├── CuArray___init__.py │ │ ├── CuArray_argsort.py │ │ ├── CuArray_fromCuArray.py │ │ ├── CuArray_fromNumpy1D.py │ │ ├── CuArray_fromNumpy2D.py │ │ ├── CuArray_get.py │ │ ├── CuArray_init.py │ │ ├── CuArray_load.py │ │ ├── CuArray_m.py │ │ ├── CuArray_n.py │ │ ├── CuArray_save.py │ │ ├── CuArray_set.py │ │ ├── CuArray_size.py │ │ ├── CuArray_sort.py │ │ ├── CuArray_toNumpy1D.py │ │ └── CuArray_toNumpy2D.py ├── src │ └── cuarray.cu ├── swig │ ├── numpy.i │ ├── numpy_float_array.i │ ├── numpy_int_array.i │ ├── python_cuarray.i │ ├── python_cuarray_docs.i │ ├── python_cuarray_headers.i │ ├── python_cuarray_ignore.i │ ├── python_cuarray_include.i │ ├── python_cuarray_pythoncode.i │ ├── python_cuarray_rename.i │ ├── python_cuarray_template.i │ ├── python_cuarray_typemaps.i │ ├── tcl_cuarray.i │ ├── tcl_cuarray_headers.i │ ├── tcl_cuarray_ignore.i │ ├── tcl_cuarray_include.i │ ├── tcl_cuarray_rename.i │ └── tcl_cuarray_template.i └── tcl │ ├── create_vmd_package.tcl │ └── cuarray.tcl ├── docs ├── Makefile ├── conf.py ├── index.rst ├── installation.rst ├── introduction.rst ├── make.bat ├── media │ ├── protG_short.dcd │ ├── protG_short.pdb │ ├── prot_G_gen_corr_global.png │ ├── prot_G_gen_corr_local.png │ ├── raw_correl_apo.png │ └── serca_correl.png ├── program_options.rst ├── requirements.txt ├── requirements.yaml ├── tutorial.rst ├── tutorial1_simple_gaussian_mi.rst ├── tutorial2_protein_structure_gc.rst └── tutorial3_bootstrapping.rst ├── doxygen └── index.h ├── examples ├── README ├── bootstrap_sample.py ├── find_mutual_inf_sample.py ├── make_two_cols_indep_data.py └── sample.dat ├── install.sh ├── netcalc ├── CMakeLists.txt ├── include │ ├── generalized_correlation.h │ ├── hedetniemi.h │ ├── math_utils.h │ ├── mutual_information.h │ ├── platform.h │ └── psi.h ├── python │ ├── netcalc │ │ └── __init__.py │ └── setup.py ├── samples │ └── python │ │ ├── NetCalc_generalizedCorrelation.py │ │ ├── NetCalc_generalizedCorrelationWithCheckpointing.py │ │ ├── NetCalc_mutualInformation.py │ │ └── NetCalc_mutualInformationWithCheckpointing.py ├── scratch │ ├── checkpointing_scratch.cpp │ └── hedetniemi_scratch.cpp ├── src │ ├── generalized_correlation.cpp │ ├── generalized_correlation_cpu.cpp │ ├── generalized_correlation_gpu.cpp │ ├── hedetniemi.cpp │ ├── hedetniemi_cpu.cpp │ ├── hedetniemi_gpu.cu │ ├── math_utils.cpp │ ├── math_utils_gpu.cu │ ├── mutual_information.cpp │ ├── mutual_information_cpu.cpp │ ├── mutual_information_gpu.cu │ └── psi.cpp └── swig │ ├── numpy.i │ ├── numpy_int_array.i │ ├── python_netcalc.i │ ├── python_netcalc_header.i │ ├── python_netcalc_include.i │ └── python_netcalc_rename.i ├── netchem ├── CMakeLists.txt ├── include │ ├── atom.h │ ├── atoms.h │ ├── chemical_properties.h │ ├── dcd │ │ ├── dcd.h │ │ ├── endianswap.h │ │ ├── fastio.h │ │ ├── largefiles.h │ │ ├── molfile_plugin.h │ │ └── vmdplugin.h │ ├── json │ │ ├── LISCENSE.MIT │ │ ├── include │ │ │ └── nlohmann │ │ │ │ ├── adl_serializer.hpp │ │ │ │ ├── byte_container_with_subtype.hpp │ │ │ │ ├── detail │ │ │ │ ├── abi_macros.hpp │ │ │ │ ├── conversions │ │ │ │ │ ├── from_json.hpp │ │ │ │ │ ├── to_chars.hpp │ │ │ │ │ └── to_json.hpp │ │ │ │ ├── exceptions.hpp │ │ │ │ ├── hash.hpp │ │ │ │ ├── input │ │ │ │ │ ├── binary_reader.hpp │ │ │ │ │ ├── input_adapters.hpp │ │ │ │ │ ├── json_sax.hpp │ │ │ │ │ ├── lexer.hpp │ │ │ │ │ ├── parser.hpp │ │ │ │ │ └── position_t.hpp │ │ │ │ ├── iterators │ │ │ │ │ ├── internal_iterator.hpp │ │ │ │ │ ├── iter_impl.hpp │ │ │ │ │ ├── iteration_proxy.hpp │ │ │ │ │ ├── iterator_traits.hpp │ │ │ │ │ ├── json_reverse_iterator.hpp │ │ │ │ │ └── primitive_iterator.hpp │ │ │ │ ├── json_custom_base_class.hpp │ │ │ │ ├── json_pointer.hpp │ │ │ │ ├── json_ref.hpp │ │ │ │ ├── macro_scope.hpp │ │ │ │ ├── macro_unscope.hpp │ │ │ │ ├── meta │ │ │ │ │ ├── call_std │ │ │ │ │ │ ├── begin.hpp │ │ │ │ │ │ └── end.hpp │ │ │ │ │ ├── cpp_future.hpp │ │ │ │ │ ├── detected.hpp │ │ │ │ │ ├── identity_tag.hpp │ │ │ │ │ ├── is_sax.hpp │ │ │ │ │ ├── std_fs.hpp │ │ │ │ │ ├── type_traits.hpp │ │ │ │ │ └── void_t.hpp │ │ │ │ ├── output │ │ │ │ │ ├── binary_writer.hpp │ │ │ │ │ ├── output_adapters.hpp │ │ │ │ │ └── serializer.hpp │ │ │ │ ├── string_concat.hpp │ │ │ │ ├── string_escape.hpp │ │ │ │ └── value_t.hpp │ │ │ │ ├── json.hpp │ │ │ │ ├── json_fwd.hpp │ │ │ │ ├── ordered_map.hpp │ │ │ │ └── thirdparty │ │ │ │ └── hedley │ │ │ │ ├── hedley.hpp │ │ │ │ └── hedley_undef.hpp │ │ ├── single_include │ │ │ └── nlohmann │ │ │ │ ├── json.hpp │ │ │ │ └── json_fwd.hpp │ │ └── tools │ │ │ ├── amalgamate │ │ │ ├── CHANGES.md │ │ │ ├── README.md │ │ │ ├── amalgamate.py │ │ │ ├── config_json.json │ │ │ └── config_json_fwd.json │ │ │ ├── gdb_pretty_printer │ │ │ ├── README.md │ │ │ └── nlohmann-json.py │ │ │ ├── generate_natvis │ │ │ ├── README.md │ │ │ ├── generate_natvis.py │ │ │ └── nlohmann_json.natvis.j2 │ │ │ ├── macro_builder │ │ │ └── main.cpp │ │ │ └── serve_header │ │ │ ├── README.md │ │ │ ├── demo.png │ │ │ ├── requirements.txt │ │ │ ├── serve_header.py │ │ │ └── serve_header.yml.example │ ├── network.h │ ├── node.h │ ├── serializer.h │ └── utils.h ├── python │ ├── netchem │ │ ├── __init__.py │ │ └── data │ │ │ ├── __init__.py │ │ │ ├── pyro.tar.gz │ │ │ └── test.tar.gz │ └── setup.py ├── samples │ └── python │ │ ├── NetChem_Atom_chainId.py │ │ ├── NetChem_Atom_element.py │ │ ├── NetChem_Atom_index.py │ │ ├── NetChem_Atom_mass.py │ │ ├── NetChem_Atom_name.py │ │ ├── NetChem_Atom_occupancy.py │ │ ├── NetChem_Atom_residueId.py │ │ ├── NetChem_Atom_residueName.py │ │ ├── NetChem_Atom_segmentId.py │ │ ├── NetChem_Atom_serial.py │ │ ├── NetChem_Atom_tag.py │ │ ├── NetChem_Atom_temperatureFactor.py │ │ ├── NetChem_Atoms_at.py │ │ ├── NetChem_Atoms_atoms.py │ │ ├── NetChem_Atoms_numAtoms.py │ │ ├── NetChem_Network_atoms.py │ │ ├── NetChem_Network_init.py │ │ ├── NetChem_Network_load.py │ │ ├── NetChem_Network_nodeCoordinates1.py │ │ ├── NetChem_Network_nodeCoordinates2.py │ │ ├── NetChem_Network_nodeFromAtomIndex.py │ │ ├── NetChem_Network_nodes.py │ │ ├── NetChem_Network_numFrames.py │ │ ├── NetChem_Network_numNodes.py │ │ ├── NetChem_Network_save.py │ │ ├── NetChem_Node_atoms.py │ │ ├── NetChem_Node_index.py │ │ ├── NetChem_Node_numAtoms.py │ │ ├── NetChem_Node_tag.py │ │ └── NetChem_Node_totalMass.py ├── scratch │ └── stride_scratch.cpp ├── src │ ├── atom.cpp │ ├── atoms.cpp │ ├── dcd │ │ └── dcd.cpp │ ├── network.cpp │ ├── node.cpp │ ├── serializer.cpp │ └── utils.cpp └── swig │ ├── python_netchem.i │ ├── python_netchem_headers.i │ ├── python_netchem_include.i │ ├── python_netchem_template.i │ └── python_netchem_typemaps.i ├── netsci.yml ├── pyproject.toml ├── pytest.ini ├── tests ├── CMakeLists.txt ├── cuarray │ ├── cpp │ │ ├── CMakeLists.txt │ │ ├── FloatCuArrayFixture.h │ │ └── FloatCuArray_test.cpp │ └── python │ │ ├── conftest.py │ │ └── test_FloatCuArray.py ├── data │ ├── 2X_1D_1000_4.npy │ └── 2X_1D_2000_4.npy ├── netcalc │ ├── cpp │ │ ├── CMakeLists.txt │ │ ├── GeneralizedCorrelation_test.cpp │ │ ├── MutualInformation_test.cpp │ │ └── data │ │ │ ├── 2X_1D_1000_4.npy │ │ │ └── 2X_1D_2000_4.npy │ └── python │ │ ├── test_GeneralizedCorrelation.py │ │ └── test_MutualInformation.py └── netchem │ ├── cpp │ ├── CMakeLists.txt │ ├── NetworkStride1_test.cpp │ ├── NetworkStride2_test.cpp │ ├── NetworkStride3_test.cpp │ ├── NetworkStrideCoordinateEquality_test.cpp │ └── data │ │ ├── test.dcd │ │ └── test.pdb │ └── python │ └── test_Network.py └── tutorial ├── protG_short.dcd ├── protG_short.pdb ├── tutorial_1_simple_gaussian.ipynb ├── tutorial_2_gen_corr_protein.ipynb └── tutorial_3_bootstrap.ipynb /.clang-format: -------------------------------------------------------------------------------- 1 | # Generated from CLion C/C++ Code Style settings 2 | BasedOnStyle: LLVM 3 | AccessModifierOffset: -4 4 | AlignAfterOpenBracket: Align 5 | AlignConsecutiveAssignments: None 6 | AlignOperands: Align 7 | AllowAllArgumentsOnNextLine: false 8 | AllowAllConstructorInitializersOnNextLine: false 9 | AllowAllParametersOfDeclarationOnNextLine: false 10 | AllowShortBlocksOnASingleLine: Always 11 | AllowShortCaseLabelsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: All 13 | AllowShortIfStatementsOnASingleLine: Always 14 | AllowShortLambdasOnASingleLine: All 15 | AllowShortLoopsOnASingleLine: true 16 | AlwaysBreakAfterReturnType: None 17 | AlwaysBreakTemplateDeclarations: Yes 18 | BreakBeforeBraces: Custom 19 | BraceWrapping: 20 | AfterCaseLabel: false 21 | AfterClass: false 22 | AfterControlStatement: Never 23 | AfterEnum: false 24 | AfterFunction: false 25 | AfterNamespace: false 26 | AfterUnion: false 27 | BeforeCatch: false 28 | BeforeElse: false 29 | IndentBraces: false 30 | SplitEmptyFunction: false 31 | SplitEmptyRecord: true 32 | BreakBeforeBinaryOperators: None 33 | BreakBeforeTernaryOperators: true 34 | BreakConstructorInitializers: BeforeColon 35 | BreakInheritanceList: BeforeColon 36 | ColumnLimit: 0 37 | CompactNamespaces: false 38 | ContinuationIndentWidth: 8 39 | IndentCaseLabels: true 40 | IndentPPDirectives: None 41 | IndentWidth: 4 42 | KeepEmptyLinesAtTheStartOfBlocks: true 43 | MaxEmptyLinesToKeep: 2 44 | NamespaceIndentation: All 45 | ObjCSpaceAfterProperty: false 46 | ObjCSpaceBeforeProtocolList: true 47 | PointerAlignment: Right 48 | ReflowComments: false 49 | SpaceAfterCStyleCast: true 50 | SpaceAfterLogicalNot: false 51 | SpaceAfterTemplateKeyword: false 52 | SpaceBeforeAssignmentOperators: true 53 | SpaceBeforeCpp11BracedList: false 54 | SpaceBeforeCtorInitializerColon: true 55 | SpaceBeforeInheritanceColon: true 56 | SpaceBeforeParens: ControlStatements 57 | SpaceBeforeRangeBasedForLoopColon: false 58 | SpaceInEmptyParentheses: false 59 | SpacesBeforeTrailingComments: 0 60 | SpacesInAngles: false 61 | SpacesInCStyleCastParentheses: false 62 | SpacesInContainerLiterals: false 63 | SpacesInParentheses: false 64 | SpacesInSquareBrackets: false 65 | TabWidth: 4 66 | UseTab: Never 67 | -------------------------------------------------------------------------------- /.github/workflows/netsci_CI.yml: -------------------------------------------------------------------------------- 1 | name: netcalc 2 | on: [push] 3 | jobs: 4 | run: 5 | runs-on: [self-hosted] 6 | defaults: 7 | run: 8 | shell: bash -l {0} 9 | env: 10 | repo_token: ${{ secrets.GITHUB_TOKEN }} 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: conda-incubator/setup-miniconda@v2 14 | with: 15 | miniconda-version: "latest" 16 | channels: bioconda, conda-forge, defaults, anaconda 17 | environment-file: netsci.yml 18 | auto-update-conda: false 19 | auto-activate-base: false 20 | show-channel-urls: true 21 | activate-environment: netsci 22 | 23 | - name: build 24 | shell: bash -l {0} 25 | run: | 26 | wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null 27 | sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ jammy main' 28 | sudo apt-get update && sudo apt-get install -y cmake 29 | mkdir build 30 | cd build 31 | cmake .. 32 | 33 | 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .ipynb_checkpoints 3 | Untitled.ipynb 4 | build/ 5 | cmake-build-debug/ 6 | collapsible_doc_code_examples.py 7 | cuarray/python/build/ 8 | cuarray/python/cuarray.egg-info/ 9 | cuarray/python/cuarray/cuarray.py 10 | cuarray/python/cuarray/python_cuarrayPYTHON_wrap.cxx 11 | cuarray/python/dist/ 12 | cuarray/tcl/cuarray.so 13 | cuarray/python/cuarray/_python_cuarray.so 14 | cuarray/lib 15 | cuarray/swig/generate_documentation.py 16 | cuarray/swig/python_cuarray_docs.i 17 | netcalc/python/build/ 18 | netcalc/python/dist/ 19 | netcalc/python/netcalc.egg-info/ 20 | netcalc/python/netcalc/netcalc.py 21 | netcalc/python/netcalc/python_netcalcPYTHON_wrap.cxx 22 | netcalc/python/netcalc/_python_netcalc.so 23 | netcalc/lib 24 | netchem/python/build/ 25 | netchem/python/dist/ 26 | netchem/python/netchem.egg-info/ 27 | netchem/python/netchem/__pycache__/ 28 | netchem/python/netchem/data/__pycache__/ 29 | netchem/python/netchem/netchem.py 30 | netchem/python/netchem/python_netchemPYTHON_wrap.cxx 31 | netchem/python/netchem/_python_netchem.so 32 | netchem/lib 33 | out/ 34 | pyautodoc/ 35 | tests/cuarray/python/__pycache__/ 36 | tests/netcalc/python/__pycache__/ 37 | tests/netchem/python/__pycache__/ 38 | cnpy/ 39 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/.gitmodules -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | 3 | version: 2 4 | 5 | build: 6 | os: ubuntu-22.04 7 | tools: 8 | python: "3.12" 9 | 10 | sphinx: 11 | configuration: docs/conf.py 12 | 13 | python: 14 | install: 15 | - requirements: docs/requirements.txt 16 | - method: pip 17 | path: . 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

NetSci
A Toolkit for High Performance Scientific Network Analysis Computation

2 | 3 | --- 4 | 5 | # Overview 6 | NetSci is a specialized toolkit designed for advanced network analysis in computational sciences. Utilizing the 7 | capabilities of modern GPUs, it offers a powerful and efficient solution for processing computationally demanding 8 | network analysis metrics while delivering state-of-the-art performance. 9 | For detailed **installation** instructions and **tutorials**, please visit [NetSci User Documentation](https://netsci.readthedocs.io/) 10 | For **API documentation** and a general **overview** of C++/CUDA portions of the project, please visit the [NetSci Developer Documentation](https://netscianalysis.github.io). 11 | 12 | # Installation 13 | 14 | Download Miniconda Installation Script: 15 | 16 | ``` 17 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 18 | ``` 19 | 20 | Execute the Installation Script: 21 | 22 | ``` 23 | bash Miniconda3-latest-Linux-x86_64.sh 24 | ``` 25 | 26 | Update Environment Settings: 27 | 28 | ``` 29 | source ~/.bashrc 30 | ``` 31 | 32 | Install Git with Conda: 33 | 34 | ``` 35 | conda install -c conda-forge git 36 | ``` 37 | 38 | Clone the NetSci Repository: 39 | 40 | ``` 41 | git clone https://github.com/netscianalysis/netsci.git 42 | ``` 43 | 44 | Navigate to the NetSci Root Directory: 45 | 46 | ``` 47 | cd netsci 48 | ``` 49 | 50 | Create NetSci Conda Environment: 51 | 52 | ``` 53 | conda env create -f netsci.yml 54 | ``` 55 | 56 | Activate NetSci Conda Environment: 57 | 58 | ``` 59 | conda activate netsci 60 | ``` 61 | 62 | Create CMake Build Directory: 63 | 64 | ``` 65 | mkdir build 66 | ``` 67 | 68 | Set NetSci Root Directory Variable: 69 | 70 | ``` 71 | NETSCI_ROOT=$(pwd) 72 | ``` 73 | 74 | Navigate to the CMake Build Directory: 75 | 76 | ``` 77 | cd ${NETSCI_ROOT}/build 78 | ``` 79 | 80 | Compile CUDA Architecture Script: 81 | 82 | ``` 83 | nvcc ${NETSCI_ROOT}/build_scripts/cuda_architecture.cu -o cuda_architecture 84 | ``` 85 | 86 | Set CUDA Architecture Variable: 87 | 88 | ``` 89 | CUDA_ARCHITECTURE=$(./cuda_architecture) 90 | ``` 91 | 92 | Configure the Build with CMake: 93 | 94 | ``` 95 | cmake .. -DCONDA_DIR=$CONDA_PREFIX -DCUDA_ARCHITECTURE=${CUDA_ARCHITECTURE} 96 | ``` 97 | 98 | Build NetSci: 99 | 100 | ``` 101 | cmake --build . -j 102 | ``` 103 | 104 | Build NetSci Python Interface: 105 | 106 | ``` 107 | make python 108 | ``` 109 | 110 | Test C++ and CUDA Backend: 111 | 112 | ``` 113 | ctest 114 | ``` 115 | 116 | Run Python Interface Tests:: 117 | 118 | ``` 119 | cd ${NETSCI_ROOT} 120 | pytest 121 | ``` 122 | 123 | # Examples and Tutorials 124 | 125 | Examples may be found in the examples/ subdirectory. 126 | 127 | Detailed tutorials can be found at [NetSci User Documentation](https://netsci.readthedocs.io/). 128 | 129 | Jupyter notebooks of tutorials can be found in the tutorials/ subdirectory. 130 | 131 | # Citing NetSci 132 | 133 | If you use NetSci, please cite the following paper: 134 | 135 | * NetSci: A Library for High Performance Biomolecular Simulation Network Analysis Computation 136 | Andrew M. Stokely, Lane W. Votapka, Marcus T. Hock, Abigail E. Teitgen, J. Andrew McCammon, Andrew D. McCulloch, and Rommie E. Amaro 137 | Journal of Chemical Information and Modeling 2024 64 (20), 7966-7976 138 | DOI: 10.1021/acs.jcim.4c00899 139 | 140 | # Copyright 141 | 142 | Copyright (c) 2024, Andy Stokely and Lane Votapka 143 | 144 | 145 | -------------------------------------------------------------------------------- /build_scripts/cuda_architecture.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | cudaDeviceProp prop; 7 | cudaError_t status; 8 | int device_count; 9 | int device_index = 0; 10 | if (argc > 1) { 11 | device_index = atoi(argv[1]); 12 | } 13 | 14 | status = cudaGetDeviceCount(&device_count); 15 | if (status != cudaSuccess) { 16 | fprintf(stderr,"cudaGetDeviceCount() failed: %s\n", cudaGetErrorString(status)); 17 | return -1; 18 | } 19 | if (device_index >= device_count) { 20 | fprintf(stderr, "Specified device index %d exceeds the maximum (the device count on this system is %d)\n", device_index, device_count); 21 | return -1; 22 | } 23 | status = cudaGetDeviceProperties(&prop, device_index); 24 | if (status != cudaSuccess) { 25 | fprintf(stderr,"cudaGetDeviceProperties() for device device_index failed: %s\n", cudaGetErrorString(status)); 26 | return -1; 27 | } 28 | int v = prop.major * 10 + prop.minor; 29 | printf("%d\n", v); 30 | } -------------------------------------------------------------------------------- /cnpy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CLEAN_FILES_AND_DIRS 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/* 4 | ) 5 | set_directory_properties( 6 | PROPERTIES 7 | ADDITIONAL_CLEAN_FILES "${CLEAN_FILES_AND_DIRS}" 8 | ) 9 | 10 | add_library( 11 | cnpy SHARED 12 | ${CMAKE_CURRENT_SOURCE_DIR}/src/cnpy.cpp 13 | ) 14 | set_target_properties( 15 | cnpy 16 | PROPERTIES 17 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib 18 | LINK_LIBRARIES "${CNPY_LINK_LIBRARIES}" 19 | ) -------------------------------------------------------------------------------- /cuarray/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(CLEAN_FILES_AND_DIRS 2 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/* 3 | ${CMAKE_CURRENT_SOURCE_DIR}/python/build 4 | ${CMAKE_CURRENT_SOURCE_DIR}/python/cuarray.egg-info 5 | ${CMAKE_CURRENT_SOURCE_DIR}/python/dist 6 | ${CMAKE_CURRENT_SOURCE_DIR}/python/cuarray/*.so* 7 | ${CMAKE_CURRENT_SOURCE_DIR}/python/cuarray/cuarray.py 8 | ${CMAKE_CURRENT_SOURCE_DIR}/python/cuarray/*.cxx* 9 | ${CMAKE_CURRENT_SOURCE_DIR}/tcl/* 10 | ) 11 | SET_DIRECTORY_PROPERTIES( 12 | PROPERTIES 13 | ADDITIONAL_CLEAN_FILES "${CLEAN_FILES_AND_DIRS}" 14 | ) 15 | SET_SOURCE_FILES_PROPERTIES( 16 | ${CMAKE_CURRENT_SOURCE_DIR}/swig/python_cuarray.i 17 | PROPERTIES 18 | CPLUSPLUS ON 19 | SWIG_MODULE_NAME cuarray 20 | ) 21 | 22 | SET_SOURCE_FILES_PROPERTIES( 23 | ${CMAKE_CURRENT_SOURCE_DIR}/swig/tcl_cuarray.i 24 | PROPERTIES 25 | CPLUSPLUS ON 26 | SWIG_MODULE_NAME cuarray 27 | ) 28 | 29 | ADD_LIBRARY(cuarray SHARED 30 | ${CMAKE_CURRENT_SOURCE_DIR}/src/cuarray.cu 31 | ) 32 | ADD_DEPENDENCIES(cuarray cnpy) 33 | SET_TARGET_PROPERTIES( 34 | cuarray 35 | PROPERTIES 36 | CUDA_SEPARABLE_COMPILATION ON 37 | CUDA_ARCHITECTURES ${CUDA_ARCHITECTURE} 38 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib 39 | LINK_LIBRARIES "${CUARRAY_LINK_LIBRARIES}" 40 | ) 41 | IF (${BUILD_PYTHON_BINDINGS}) 42 | SWIG_ADD_LIBRARY(python_cuarray 43 | LANGUAGE python 44 | OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python/cuarray 45 | SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/swig/python_cuarray.i 46 | ) 47 | SET_TARGET_PROPERTIES( 48 | python_cuarray 49 | PROPERTIES 50 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/cuarray 51 | LINK_LIBRARIES "${CUARRAY_PYTHON_LINK_LIBRARIES}" 52 | ) 53 | SET(PIP_UNINSTALL_CUARRAY_ARGS "uninstall" "cuarray" "-y") 54 | SET(PYTHON_CUARRAY_INSTALL_ARGS "setup.py" "install") 55 | ADD_CUSTOM_TARGET(PythonCuArrayInstall 56 | COMMAND pip ${PIP_UNINSTALL_CUARRAY_ARGS} 57 | COMMAND ${Python3_EXECUTABLE} ${PYTHON_CUARRAY_INSTALL_ARGS} 58 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/cuarray/python 59 | ) 60 | ENDIF () 61 | 62 | IF (${BUILD_TCL_BINDINGS}) 63 | SWIG_ADD_LIBRARY(tcl_cuarray 64 | LANGUAGE tcl 65 | OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tcl 66 | SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/swig/tcl_cuarray.i 67 | ) 68 | SET_TARGET_PROPERTIES( 69 | tcl_cuarray 70 | PROPERTIES 71 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tcl 72 | LINK_LIBRARIES "${CUARRAY_TCL_LINK_LIBRARIES}" 73 | PREFIX "" 74 | OUTPUT_NAME "cuarray" 75 | SUFFIX ".so" 76 | ) 77 | SWIG_LINK_LIBRARIES(tcl_cuarray cuarray) 78 | IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tcl/tcl_cuarrayTCL_wrap.cxx) 79 | FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/tcl/tcl_cuarrayTCL_wrap.cxx) 80 | ENDIF () 81 | IF (${CREATE_VMD_TCL_PACKAGE}) 82 | SET(ENV{VMD_TCL_INDEX_PATH} "${VMD_LIB_DIR}/scripts/vmd/tclIndex") 83 | SET(ENV{TCL_CUARRAY_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/tcl") 84 | SET(ENV{TCL_CUARRAY_LIB_PATH} "$ENV{TCL_CUARRAY_DIR}/cuarray.so") 85 | SET(ENV{TCL_CUARRAY_SCRIPT_PATH} "$ENV{TCL_CUARRAY_DIR}/cuarray.tcl") 86 | EXECUTE_PROCESS( 87 | COMMAND tclsh ${CMAKE_CURRENT_SOURCE_DIR}/tcl/create_vmd_package.tcl 88 | ) 89 | ENDIF (${CREATE_VMD_TCL_PACKAGE}) 90 | ENDIF (${BUILD_TCL_BINDINGS}) 91 | -------------------------------------------------------------------------------- /cuarray/python/cuarray/__init__.py: -------------------------------------------------------------------------------- 1 | from .cuarray import FloatCuArray 2 | from .cuarray import IntCuArray 3 | -------------------------------------------------------------------------------- /cuarray/python/setup.py: -------------------------------------------------------------------------------- 1 | 2 | from setuptools import find_packages 3 | from setuptools import setup 4 | import os 5 | 6 | path = os.path.relpath(os.path.dirname(__file__)) 7 | 8 | setup( 9 | author='Andy Stokely', 10 | email='amstokely@ucsd.edu', 11 | name='cuarray', 12 | install_requires=[], 13 | platforms=['Linux', 14 | 'Unix', ], 15 | python_requires="<=3.9", 16 | py_modules=[path + "/cuarray/cuarray"], 17 | packages=find_packages() + [''], 18 | zip_safe=False, 19 | package_data={ 20 | '': [ 21 | path + '/cuarray/_python_cuarray.so' 22 | ] 23 | }, 24 | ) 25 | -------------------------------------------------------------------------------- /cuarray/samples/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/CMakeLists.txt -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_CuArray.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_CuArray.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_allocateDevice.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_allocateDevice.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_allocateHost.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_allocateHost.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_allocatedDevice.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_allocatedDevice.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_allocatedHost.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_allocatedHost.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_argsort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_argsort.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_bytes.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_bytes.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_deallocateHost.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_deallocateHost.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_device.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_device.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_fromCuArrayDeepCopy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_fromCuArrayDeepCopy.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_fromCuArrayShallowCopy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_fromCuArrayShallowCopy.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_fromNumpy1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_fromNumpy1.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_fromNumpy2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_fromNumpy2.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_get.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_get.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_host.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_host.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_init1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_init1.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_init2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_init2.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_load.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_load.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_m.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_m.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_n.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_n.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_owner.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_owner.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_save.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_save.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_set.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_set.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_size.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_size.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_sort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_sort.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_subscriptOperator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_subscriptOperator.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_toDevice.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_toDevice.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_toHost.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_toHost.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_toNumpy1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_toNumpy1.cpp -------------------------------------------------------------------------------- /cuarray/samples/cpp/src/CuArray_toNumpy2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/cpp/src/CuArray_toNumpy2.cpp -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray___getitem__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray___getitem__.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray___init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray___init__.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_argsort.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_argsort.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_fromCuArray.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_fromCuArray.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_fromNumpy1D.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_fromNumpy1D.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_fromNumpy2D.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_fromNumpy2D.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_get.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_get.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_init.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_init.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_load.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_load.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_m.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_m.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_n.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_n.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_save.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_save.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_set.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_set.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_size.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_size.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_sort.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_sort.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_toNumpy1D.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_toNumpy1D.py -------------------------------------------------------------------------------- /cuarray/samples/python/CuArray_toNumpy2D.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/samples/python/CuArray_toNumpy2D.py -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray.i: -------------------------------------------------------------------------------- 1 | %module cuarray 2 | 3 | %include "std_string.i" 4 | %include "python_cuarray_docs.i" 5 | %include "python_cuarray_headers.i" 6 | %include "numpy_float_array.i" 7 | %include "numpy_int_array.i" 8 | %include "python_cuarray_typemaps.i" 9 | %include "python_cuarray_include.i" 10 | %include "python_cuarray_ignore.i" 11 | %include "python_cuarray_rename.i" 12 | %include "python_cuarray_template.i" 13 | %include "python_cuarray_pythoncode.i" 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray_headers.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #define SWIG_FILE_WITH_INIT 3 | #include "cuarray.h" 4 | %} -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray_ignore.i: -------------------------------------------------------------------------------- 1 | %ignore fromCuArrayShallowCopy; 2 | -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray_include.i: -------------------------------------------------------------------------------- 1 | 2 | %include cuarray.h -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray_pythoncode.i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/cuarray/swig/python_cuarray_pythoncode.i -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray_rename.i: -------------------------------------------------------------------------------- 1 | 2 | 3 | %rename(fromNumpy1D) CuArray::fromNumpy( 4 | float *NUMPY_ARRAY, 5 | int NUMPY_ARRAY_DIM1 6 | ); 7 | %rename(fromNumpy2D) CuArray::fromNumpy( 8 | float *NUMPY_ARRAY, 9 | int NUMPY_ARRAY_DIM1, 10 | int NUMPY_ARRAY_DIM2 11 | ); 12 | %rename(fromNumpy1D) CuArray::fromNumpy( 13 | int *NUMPY_ARRAY, 14 | int NUMPY_ARRAY_DIM1 15 | ); 16 | %rename(fromNumpy2D) CuArray::fromNumpy( 17 | int *NUMPY_ARRAY, 18 | int NUMPY_ARRAY_DIM1, 19 | int NUMPY_ARRAY_DIM2 20 | ); 21 | %rename(toNumpy1D) CuArray::toNumpy( 22 | float **NUMPY_ARRAY, 23 | int **NUMPY_ARRAY_DIM1 24 | ); 25 | %rename(toNumpy2D) CuArray::toNumpy( 26 | float **NUMPY_ARRAY, 27 | int **NUMPY_ARRAY_DIM1, 28 | int **NUMPY_ARRAY_DIM2 29 | ); 30 | %rename(toNumpy1D) CuArray::toNumpy( 31 | int **NUMPY_ARRAY, 32 | int **NUMPY_ARRAY_DIM1 33 | ); 34 | %rename(toNumpy2D) CuArray::toNumpy( 35 | int **NUMPY_ARRAY, 36 | int **NUMPY_ARRAY_DIM1, 37 | int **NUMPY_ARRAY_DIM2 38 | ); 39 | %rename(fromCuArray) fromCuArrayDeepCopy; -------------------------------------------------------------------------------- /cuarray/swig/python_cuarray_template.i: -------------------------------------------------------------------------------- 1 | %template(IntCuArray) CuArray; 2 | %template(FloatCuArray) CuArray; 3 | %template(IntCuArrayRow) CuArrayRow; 4 | %template(FloatCuArrayRow) CuArrayRow; 5 | -------------------------------------------------------------------------------- /cuarray/swig/tcl_cuarray.i: -------------------------------------------------------------------------------- 1 | %module cuarray 2 | 3 | %include "std_string.i" 4 | %include "tcl_cuarray_headers.i" 5 | %include "tcl_cuarray_include.i" 6 | %include "tcl_cuarray_ignore.i" 7 | %include "tcl_cuarray_rename.i" 8 | %include "tcl_cuarray_template.i" 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cuarray/swig/tcl_cuarray_headers.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #define SWIG_FILE_WITH_INIT 3 | #include "cuarray.h" 4 | %} -------------------------------------------------------------------------------- /cuarray/swig/tcl_cuarray_ignore.i: -------------------------------------------------------------------------------- 1 | %ignore fromCuArrayShallowCopy; 2 | %ignore fromNumpy; 3 | -------------------------------------------------------------------------------- /cuarray/swig/tcl_cuarray_include.i: -------------------------------------------------------------------------------- 1 | 2 | %include cuarray.h -------------------------------------------------------------------------------- /cuarray/swig/tcl_cuarray_rename.i: -------------------------------------------------------------------------------- 1 | %rename(fromCuArray) fromCuArrayDeepCopy; -------------------------------------------------------------------------------- /cuarray/swig/tcl_cuarray_template.i: -------------------------------------------------------------------------------- 1 | %template(IntCuArray) CuArray; 2 | %template(FloatCuArray) CuArray; 3 | %template(IntCuArrayRow) CuArrayRow; 4 | %template(FloatCuArrayRow) CuArrayRow; 5 | -------------------------------------------------------------------------------- /cuarray/tcl/create_vmd_package.tcl: -------------------------------------------------------------------------------- 1 | if {[string first cuarray.tcl [exec tail -n 1 "$env(VMD_TCL_INDEX_PATH)"]] == -1} { 2 | exec echo load "$env(TCL_CUARRAY_LIB_PATH)" >> "$env(TCL_CUARRAY_SCRIPT_PATH)" 3 | exec echo load "$env(TCL_CUARRAY_LIB_PATH)" >> "$env(VMD_TCL_INDEX_PATH)" 4 | exec echo source "$env(TCL_CUARRAY_SCRIPT_PATH)" >> "$env(VMD_TCL_INDEX_PATH)" 5 | } 6 | 7 | -------------------------------------------------------------------------------- /cuarray/tcl/cuarray.tcl: -------------------------------------------------------------------------------- 1 | proc loadFloatCuArray {fname} { 2 | set floatCuArray [FloatCuArray] 3 | $floatCuArray load $fname 4 | return $floatCuArray 5 | } 6 | 7 | proc saveFloatCuArray {fname cuArray} { 8 | $cuArray save $fname 9 | } 10 | 11 | proc argsortFloatCuArray {cuArray} { 12 | set argsortCuArray [$cuArray argsort] 13 | return $argsortCuArray 14 | } 15 | 16 | proc sortFloatCuArray {cuArray} { 17 | set sortedCuArray [$cuArray sort] 18 | return $sortedCuArray 19 | } 20 | 21 | proc floatCuArrayToList {cuArray} { 22 | set a [list] 23 | for {set i 0} {$i < [$cuArray m]} {incr i} { 24 | set b [list] 25 | for {set j 0} {$j < [$cuArray n]} {incr j} { 26 | lappend b [$cuArray get $i $j] 27 | } 28 | lappend a $b 29 | } 30 | return $a 31 | } 32 | 33 | proc loadIntCuArray {fname} { 34 | set intCuArray [IntCuArray] 35 | $intCuArray load $fname 36 | return $intCuArray 37 | } 38 | 39 | proc saveIntCuArray {fname cuArray} { 40 | $cuArray save $fname 41 | } 42 | 43 | proc intCuArrayToList {cuArray} { 44 | set a [list] 45 | for {set i 0} {$i < [$cuArray m]} {incr i} { 46 | set b [list] 47 | for {set j 0} {$j < [$cuArray n]} {incr j} { 48 | lappend b [$cuArray get $i $j] 49 | } 50 | lappend a $b 51 | } 52 | return $a 53 | } 54 | 55 | proc argsortIntCuArray {cuArray} { 56 | set argsortCuArray [$cuArray argsort]} 57 | return $argsortCuArray 58 | } 59 | 60 | proc sortIntCuArray {cuArray} { 61 | set sortedCuArray [$cuArray sort] 62 | return $sortedCuArray 63 | } 64 | load /home/astokely/CLionProjects/netsci/cuarray/tcl/cuarray.so 65 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = netsci 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | NetSci: A Toolkit for High Performance Scientific Network Analysis Computation 2 | ============================================================================== 3 | 4 | :Release: |release| 5 | :Date: |today| 6 | 7 | **NetSci** NetSci is a specialized toolkit designed for advanced network analysis in computational sciences. Utilizing the capabilities of modern GPUs, it offers a powerful and efficient solution for processing computationally demanding network analysis metrics while delivering state-of-the-art performance. 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Contents: 12 | 13 | introduction 14 | installation 15 | program_options 16 | tutorial 17 | 18 | Cite NetSci 19 | =========== 20 | 21 | If you wish to cite NetSci, please cite the following paper: 22 | 23 | * NetSci: A Library for High Performance Biomolecular Simulation Network Analysis Computation. Andrew M. Stokely, Lane W. Votapka, Marcus T. Hock, Abigail E. Teitgen, J. Andrew McCammon, Andrew D. McCulloch, and Rommie E. Amaro. Journal of Chemical Information and Modeling 2024 64 (20), 7966-7976. DOI: 10.1021/acs.jcim.4c00899 24 | 25 | Getting Involved 26 | ================ 27 | 28 | Please report **bugs** or **enhancement requests** through the `Issue 29 | Tracker`_. 30 | 31 | .. _Issue Tracker: https://github.com/netscianalysis/netsci/issues 32 | 33 | Indices and tables 34 | ================== 35 | 36 | * :ref:`genindex` 37 | * :ref:`modindex` 38 | * :ref:`search` 39 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | At this time, NetSci has only been tested on Linux systems. Therefore, all 5 | installation instructions are for Linux only. 6 | 7 | NetSci is designed with a focus on ease of installation and long-term stability, ensuring compatibility with Linux systems featuring CUDA-capable GPUs (compute capability 3.5 and above). It leverages well-supported core C++ and Python libraries to maintain simplicity and reliability. 8 | 9 | Download Miniconda Installation Script: 10 | 11 | ``wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh`` 12 | 13 | Execute the Installation Script: 14 | 15 | ``bash Miniconda3-latest-Linux-x86_64.sh`` 16 | 17 | Update Environment Settings: 18 | 19 | ``source ~/.bashrc`` 20 | 21 | Install Git with Conda: 22 | 23 | ``conda install -c conda-forge git`` 24 | 25 | Clone the NetSci Repository: 26 | 27 | ``git clone https://github.com/netscianalysis/netsci.git`` 28 | 29 | Navigate to the NetSci Root Directory: 30 | 31 | ``cd netsci`` 32 | 33 | Create NetSci Conda Environment: 34 | 35 | ``conda env create -f netsci.yml`` 36 | 37 | Activate NetSci Conda Environment: 38 | 39 | ``conda activate netsci`` 40 | 41 | Create CMake Build Directory: 42 | 43 | ``mkdir build`` 44 | 45 | Set NetSci Root Directory Variable: 46 | 47 | ``NETSCI_ROOT=$(pwd)`` 48 | 49 | Navigate to the CMake Build Directory: 50 | 51 | ``cd ${NETSCI_ROOT}/build`` 52 | 53 | Compile CUDA Architecture Script: 54 | 55 | ``nvcc ${NETSCI_ROOT}/build_scripts/cuda_architecture.cu -o cuda_architecture`` 56 | 57 | Set CUDA Architecture Variable: 58 | 59 | ``CUDA_ARCHITECTURE=$(./cuda_architecture)`` 60 | 61 | Configure the Build with CMake: 62 | 63 | ``cmake .. -DCONDA_DIR=$CONDA_PREFIX -DCUDA_ARCHITECTURE=${CUDA_ARCHITECTURE}`` 64 | 65 | Build NetSci: 66 | 67 | ``cmake --build . -j`` 68 | 69 | Build NetSci Python Interface: 70 | 71 | ``make python`` 72 | 73 | Test C++ and CUDA Backend: 74 | 75 | ``ctest`` 76 | 77 | Run Python Interface Tests:: 78 | 79 | cd ${NETSCI_ROOT} 80 | pytest 81 | 82 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=netsci 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/media/protG_short.dcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/docs/media/protG_short.dcd -------------------------------------------------------------------------------- /docs/media/prot_G_gen_corr_global.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/docs/media/prot_G_gen_corr_global.png -------------------------------------------------------------------------------- /docs/media/prot_G_gen_corr_local.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/docs/media/prot_G_gen_corr_local.png -------------------------------------------------------------------------------- /docs/media/raw_correl_apo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/docs/media/raw_correl_apo.png -------------------------------------------------------------------------------- /docs/media/serca_correl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/docs/media/serca_correl.png -------------------------------------------------------------------------------- /docs/program_options.rst: -------------------------------------------------------------------------------- 1 | Program Options for NetSci 2 | ========================== 3 | 4 | This page contains brief descriptions of common functions and inputs used 5 | in NetSci. 6 | 7 | netcalc.mutualInformation 8 | ------------------------- 9 | 10 | A call to mutualInformation will be formatted as follows:: 11 | 12 | netcalc.mutualInformation(X, I, ab, k, N, xd, d, platform) 13 | 14 | Each of the arguments are described below: 15 | 16 | X 17 | The input data, converted to a form that NetSci can use directly. 18 | Must be of type cuarray.FloatCuArray(). 19 | 20 | I 21 | The output MI, which is passed by reference for the function to fill out, 22 | with entries for each pair of distributions specified for an MI calculation. 23 | Must be of type cuarray.FloatCuArray(). 24 | 25 | ab 26 | An array that represents which pairs of distributions to compute. This can be adjusted 27 | to exclude the computation of certain pairs of distributions, if desired. 28 | Must be of type cuarray.IntCuArray(). 29 | 30 | k 31 | This is the "k" of "k-nearest-neighbors" - that is - how many neighbors to each point 32 | are taken in Kraskov's algorithm. Kraskov recommends a value of "k" between 2 and 4, 33 | although situations where k=6 have also been used. In general, a lower value of "k" 34 | reduces bias, but increases noise, and a higher value of "k" reduces noise, but 35 | increases bias for non-independent distributions. If testing for independence, bias 36 | is not such an issue, so k can be as large as N/2, according to Kraskov et al., 37 | where N is the number of data points. 38 | Must be of type int, greater than zero. 39 | 40 | N 41 | The number of data points sampled from each distribution. 42 | Must be of type int greater than zero. 43 | 44 | xd 45 | The number of distributions per MI calculation. At this time, only the MI of two 46 | distributions can be calculated at a time in NetSci, so xd=2. 47 | Must be of type int, and only xd=2 is currently supported in Netsci. 48 | 49 | d 50 | Dimensionality of the data. In the case of 1D Gaussians, the dimensionality is equal to 51 | one. In contrast, for example, the positions of atoms in a protein would be three-dimensional 52 | data. 53 | Must be of type int, greater than zero. 54 | 55 | platform 56 | Which platform to use. If the GPU platform is desired, set this value to netcalc.GPU_PLATFORM, 57 | otherwise, if the CPU platform is desired, set this value to netcalc.CPU_PLATFORM. 58 | 59 | netcalc.generalizedCorrelation 60 | ------------------------------ 61 | 62 | A call to generalizedCorrelation will be formatted as follows:: 63 | 64 | netcalc.generalizedCorrelation(X, R, ab, k, n, d, xd, platform) 65 | 66 | The parameters ab, k, d, xd, and platform are the same as in the previous section 67 | "netcalc.mutualInformation". The new, or different, parameters are: 68 | 69 | X 70 | The input data, But unlike with the mutualInformation function above, this "X" is 71 | obtained from a netchem.Graph() object, specificall from the nodeCoordinates() method. 72 | 73 | R 74 | The output correlation matrix, which is passed by reference for the function to 75 | fill out, with entries for each pair of distributions specified for a generalized 76 | correlation calculation. 77 | Must be of type cuarray.FloatCuArray(). 78 | 79 | n 80 | The number of frames for the loaded trajectory. 81 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx-rtd-theme 2 | -------------------------------------------------------------------------------- /docs/requirements.yaml: -------------------------------------------------------------------------------- 1 | name: docs 2 | channels: 3 | - defaults 4 | dependencies: 5 | # Base depends 6 | - python=3.12 7 | - pip 8 | - cython 9 | 10 | # Pip-only installs 11 | - pip: 12 | - sphinx-autoapi 13 | - sphinx-rtd-theme 14 | 15 | -------------------------------------------------------------------------------- /docs/tutorial.rst: -------------------------------------------------------------------------------- 1 | Tutorials for NetSci 2 | ==================== 3 | 4 | Follow these tutorials to learn how to use NetSci. 5 | 6 | It is assumed that you have completed the installation and tests outlined in the 7 | :doc:`Installation` documentation. 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Contents: 12 | 13 | tutorial1_simple_gaussian_mi 14 | tutorial2_protein_structure_gc 15 | tutorial3_bootstrapping 16 | -------------------------------------------------------------------------------- /docs/tutorial3_bootstrapping.rst: -------------------------------------------------------------------------------- 1 | Tutorial 3: Error Estimation with Bootstrapping 2 | =============================================== 3 | 4 | In this tutorial, we will estimate the error margins of a 5 | MI calculation by employing a bootstrapping method. A 6 | Jupyter notebook of this tutorial can be found in the repository 7 | https://github.com/netscianalysis/ in the tutorials/ folder. 8 | 9 | Make sure to activate the NetSci conda environment:: 10 | 11 | conda activate netsci 12 | 13 | Bootstrapping Analysis 14 | ---------------------- 15 | 16 | The following Python code will sample data from two independent 17 | Gaussian distributions, with mean zero and standard deviation of 1, 18 | creating a file named 'sample.dat' (This is the same method as in 19 | tutorial 1: Simple Gaussian MI):: 20 | 21 | import numpy as np 22 | 23 | # 100 rows 24 | N = 100 25 | 26 | # 2 columns 27 | M = 2 28 | 29 | gaussian_2D = np.zeros((M, N)).astype(np.float32) 30 | for i in range(M): 31 | gaussian_2D[i,:] = np.random.normal(size=N) 32 | 33 | with open("sample.dat", "w") as f: 34 | f.write("column1\tcolumn2\n") 35 | for i in range(N): 36 | f.write(str(gaussian_2D[0,i])+"\t"+str(gaussian_2D[1,i])+"\n") 37 | 38 | Inside sample.dat, there are two columns of data, each containing 100 rows 39 | (not including the header):: 40 | 41 | column1 column2 42 | -0.7315501 -0.2413269 43 | -1.012331 0.03488477 44 | -0.5544968 -1.5803745 45 | -0.86383635 0.91249526 46 | 2.1049206 -0.46482915 47 | 0.84087217 1.1912068 48 | 2.6172605 1.1999675 49 | -0.52112085 0.1250357 50 | -0.9300766 0.73021877 51 | 1.1873163 2.590006 52 | -1.0747769 -0.05441373 53 | ... 54 | 55 | 56 | Now, let us compute the MI, and also run a bootstrapping analysis for 57 | an error estimate:: 58 | 59 | import numpy as np 60 | 61 | import netcalc 62 | import cuarray 63 | 64 | # k-nearest neighbors number 65 | k = 1 66 | 67 | # Dimensionality of data 68 | d = 1 69 | 70 | # Two dimensions of distributions 71 | xd = 2 72 | 73 | # Number of data points in 2D distribution 74 | N = 100 75 | 76 | # Number of bootstrap samples of the data to compute 77 | NUM_BOOTSTRAP_SAMPLES = 10 78 | 79 | # Define all pair correlations that will be computed 80 | num_nodes = 2 81 | num_node_pairs = num_nodes**2 82 | ab = cuarray.IntCuArray() 83 | ab.init(num_node_pairs, 2) 84 | for i in range(num_nodes): 85 | for j in range(num_nodes): 86 | node_pair_index = i*num_nodes + j 87 | ab[node_pair_index][0] = i 88 | ab[node_pair_index][1] = j 89 | 90 | # Load the data into a numpy array 91 | data_list = [] 92 | with open("sample.dat", "r") as f: 93 | for i, line in enumerate(f.readlines()): 94 | if i == 0: 95 | # Skip the data header 96 | continue 97 | 98 | line = line.strip().split() 99 | col1_datum = line[0] 100 | col2_datum = line[1] 101 | data_list.append([col1_datum, col2_datum]) 102 | 103 | assert len(data_list) == N 104 | 105 | two_columns_of_data = np.array(data_list, dtype=np.float32).T 106 | 107 | # The input array 108 | X = cuarray.FloatCuArray() 109 | X.fromNumpy2D(two_columns_of_data) 110 | 111 | # The output array 112 | I = cuarray.FloatCuArray() 113 | 114 | netcalc.mutualInformation(X, I, ab, k, N, xd, d, netcalc.GPU_PLATFORM) 115 | 116 | mutual_information = I[0][1] 117 | 118 | bootstrap_MI_array = np.zeros(NUM_BOOTSTRAP_SAMPLES) 119 | for b in range(NUM_BOOTSTRAP_SAMPLES): 120 | # The input array 121 | X = cuarray.FloatCuArray() 122 | 123 | # Shuffle the data with replacement 124 | shuffled_two_columns_of_data = np.zeros(two_columns_of_data.shape, dtype=np.float32) 125 | indices = np.random.choice(np.arange(N), size=N, replace=True) 126 | shuffled_two_columns_of_data[0,:] = two_columns_of_data[0, indices] 127 | shuffled_two_columns_of_data[1,:] = two_columns_of_data[1, indices] 128 | X.fromNumpy2D(shuffled_two_columns_of_data) 129 | 130 | # The output array 131 | I = cuarray.FloatCuArray() 132 | 133 | netcalc.mutualInformation(X, I, ab, k, N, xd, d, netcalc.GPU_PLATFORM) 134 | 135 | bootstrap_MI_array[b] = I[0][1] 136 | 137 | bootstrap_error = np.std(bootstrap_MI_array) 138 | print("predicted mutual information for sample.dat:", mutual_information, "+/-", bootstrap_error) 139 | 140 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | Run some example calculations with Netsci. 2 | 3 | Be sure that Netsci is installed and the correct Conda environment 4 | is loaded: 5 | 6 | conda activate netsci 7 | 8 | # Independent Gaussian Data 9 | 10 | As a very simple example of how Netsci can be used to find the mutual 11 | information (MI) between two sets of data, run the following 12 | script to generate random data sampled from independent Gaussian 13 | distributions: 14 | 15 | ``` 16 | python make_two_cols_indep_data.py 17 | ``` 18 | 19 | That will create a file named "sample.dat", which has two columns, 20 | representing each independent distribution, and 100 rows, which are 21 | instances sampled from the distributions. The mutual information 22 | of each can be computed by running: 23 | 24 | ``` 25 | python find_mutual_inf_sample.py 26 | ``` 27 | 28 | The mutual information between each distribution will be printed to 29 | the terminal. 30 | 31 | One may also estimate the error margins for a MI calculation by using 32 | bootstrapping. An example is provided by running: 33 | 34 | ``` 35 | python bootstrap_sample.py 36 | ``` 37 | -------------------------------------------------------------------------------- /examples/bootstrap_sample.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrate how one may compute error margins for mutual 3 | information estimates of our data file sample.dat using 4 | a bootstrapping analysis. 5 | """ 6 | 7 | import numpy as np 8 | 9 | import netcalc 10 | import cuarray 11 | 12 | # k-nearest neighbors number 13 | k = 1 14 | 15 | # Dimensionality of data 16 | d = 1 17 | 18 | # Two dimensions of distributions 19 | xd = 2 20 | 21 | # Number of data points in 2D distribution 22 | N = 100 23 | 24 | # Number of bootstrap samples of the data to compute 25 | NUM_BOOTSTRAP_SAMPLES = 10 26 | 27 | # Define all pair correlations that will be computed 28 | num_nodes = 2 29 | num_node_pairs = num_nodes**2 30 | ab = cuarray.IntCuArray() 31 | ab.init(num_node_pairs, 2) 32 | for i in range(num_nodes): 33 | for j in range(num_nodes): 34 | node_pair_index = i*num_nodes + j 35 | ab[node_pair_index][0] = i 36 | ab[node_pair_index][1] = j 37 | 38 | # Load the data into a numpy array 39 | data_list = [] 40 | with open("sample.dat", "r") as f: 41 | for i, line in enumerate(f.readlines()): 42 | if i == 0: 43 | # Skip the data header 44 | continue 45 | 46 | line = line.strip().split() 47 | col1_datum = line[0] 48 | col2_datum = line[1] 49 | data_list.append([col1_datum, col2_datum]) 50 | 51 | assert len(data_list) == N 52 | 53 | two_columns_of_data = np.array(data_list, dtype=np.float32).T 54 | 55 | # The input array 56 | X = cuarray.FloatCuArray() 57 | X.fromNumpy2D(two_columns_of_data) 58 | 59 | # The output array 60 | I = cuarray.FloatCuArray() 61 | 62 | netcalc.mutualInformation(X, I, ab, k, N, xd, d, netcalc.GPU_PLATFORM) 63 | 64 | mutual_information = I[0][1] 65 | 66 | bootstrap_MI_array = np.zeros(NUM_BOOTSTRAP_SAMPLES) 67 | for b in range(NUM_BOOTSTRAP_SAMPLES): 68 | # The input array 69 | X = cuarray.FloatCuArray() 70 | 71 | # Shuffle the data with replacement 72 | shuffled_two_columns_of_data = np.zeros(two_columns_of_data.shape, dtype=np.float32) 73 | indices = np.random.choice(np.arange(N), size=N, replace=True) 74 | shuffled_two_columns_of_data[0,:] = two_columns_of_data[0, indices] 75 | shuffled_two_columns_of_data[1,:] = two_columns_of_data[1, indices] 76 | X.fromNumpy2D(shuffled_two_columns_of_data) 77 | 78 | # The output array 79 | I = cuarray.FloatCuArray() 80 | 81 | netcalc.mutualInformation(X, I, ab, k, N, xd, d, netcalc.GPU_PLATFORM) 82 | 83 | bootstrap_MI_array[b] = I[0][1] 84 | 85 | bootstrap_error = np.std(bootstrap_MI_array) 86 | print("predicted mutual information for sample.dat:", mutual_information, "+/-", bootstrap_error) 87 | 88 | -------------------------------------------------------------------------------- /examples/find_mutual_inf_sample.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how two columns of data points may have their 3 | mutual information computed using Netsci 4 | """ 5 | 6 | import numpy as np 7 | 8 | import netcalc 9 | import cuarray 10 | 11 | # k-nearest neighbors number 12 | k = 1 13 | 14 | # Dimensionality of data 15 | d = 1 16 | 17 | # Two dimensions of distributions 18 | xd = 2 19 | 20 | # Number of data points in 2D distribution 21 | N = 100 22 | 23 | # Define all pair correlations that will be computed 24 | num_nodes = 2 25 | num_node_pairs = num_nodes**2 26 | ab = cuarray.IntCuArray() 27 | ab.init(num_node_pairs, 2) 28 | for i in range(num_nodes): 29 | for j in range(num_nodes): 30 | node_pair_index = i*num_nodes + j 31 | ab[node_pair_index][0] = i 32 | ab[node_pair_index][1] = j 33 | 34 | # Load the data into a numpy array 35 | data_list = [] 36 | with open("sample.dat", "r") as f: 37 | for i, line in enumerate(f.readlines()): 38 | if i == 0: 39 | # Skip the data header 40 | continue 41 | 42 | line = line.strip().split() 43 | col1_datum = line[0] 44 | col2_datum = line[1] 45 | data_list.append([col1_datum, col2_datum]) 46 | 47 | assert len(data_list) == N 48 | 49 | two_columns_of_data = np.array(data_list, dtype=np.float32).T 50 | 51 | # The input array 52 | X = cuarray.FloatCuArray() 53 | X.fromNumpy2D(two_columns_of_data) 54 | 55 | # The output array 56 | I = cuarray.FloatCuArray() 57 | 58 | netcalc.mutualInformation(X, I, ab, k, N, xd, d, netcalc.GPU_PLATFORM) 59 | 60 | mutual_information = I[0][1] 61 | 62 | print("predicted mutual information for sample.dat:", mutual_information) 63 | 64 | -------------------------------------------------------------------------------- /examples/make_two_cols_indep_data.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | # 100 rows 4 | N = 100 5 | 6 | # 2 columns 7 | M = 2 8 | 9 | gaussian_2D = np.zeros((M, N)).astype(np.float32) 10 | for i in range(M): 11 | gaussian_2D[i,:] = np.random.normal(size=N) 12 | 13 | with open("sample.dat", "w") as f: 14 | f.write("column1\tcolumn2\n") 15 | for i in range(N): 16 | f.write(str(gaussian_2D[0,i])+"\t"+str(gaussian_2D[1,i])+"\n") 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/sample.dat: -------------------------------------------------------------------------------- 1 | column1 column2 2 | -0.7315501 -0.2413269 3 | -1.012331 0.03488477 4 | -0.5544968 -1.5803745 5 | -0.86383635 0.91249526 6 | 2.1049206 -0.46482915 7 | 0.84087217 1.1912068 8 | 2.6172605 1.1999675 9 | -0.52112085 0.1250357 10 | -0.9300766 0.73021877 11 | 1.1873163 2.590006 12 | -1.0747769 -0.05441373 13 | 1.0476282 0.61519086 14 | 0.6361121 -1.4341183 15 | 0.55301565 -0.09167507 16 | -1.2820184 -0.25575283 17 | -0.5306381 -0.7668061 18 | -0.8799893 -0.7736396 19 | 1.2383957 -0.20671625 20 | -0.9563655 0.8671628 21 | 1.0053614 -1.6274067 22 | 0.42955267 0.37595642 23 | -1.5292956 -1.6516632 24 | 0.1278499 2.437931 25 | 0.9350737 -0.09094291 26 | 2.049749 -1.2999451 27 | -2.0561872 -0.053689316 28 | 0.626855 0.76937574 29 | -1.5972594 -1.4422097 30 | -1.1293385 -0.66408396 31 | 0.24408312 1.014315 32 | 0.8064287 -0.91980857 33 | 1.1426443 0.07012048 34 | -0.0640505 -1.2625673 35 | -0.6499298 1.1464368 36 | 0.29706925 0.8105039 37 | -0.96371645 1.1274403 38 | 0.56626445 -0.19289415 39 | -0.17497069 0.18429323 40 | -0.6886185 0.3828746 41 | -2.3062603 0.21274923 42 | 1.37922 -0.08559582 43 | 0.34343073 2.0778315 44 | -1.0769498 -0.68324625 45 | -0.27429348 0.8493873 46 | -0.079594806 -1.1693989 47 | 0.047895443 0.4125156 48 | -0.90493286 -0.19137838 49 | 1.6378697 -1.0332998 50 | -0.20349254 0.6178145 51 | 2.022148 0.3936873 52 | -0.16008286 1.2054222 53 | 1.2384135 -0.5046945 54 | -0.66015697 -0.54840016 55 | 0.93411905 0.53448284 56 | -0.51570857 -0.24030447 57 | 0.8326304 -0.26273513 58 | -2.0736732 0.3355227 59 | 1.4169493 0.3917693 60 | -0.33110943 -1.21886 61 | -0.67238796 -0.761188 62 | -0.18473223 0.4604932 63 | 0.7150656 1.0103374 64 | -1.5934802 -0.7745481 65 | -0.9642912 -0.41870007 66 | 1.6678939 3.4223826 67 | 0.8647618 -3.0841336 68 | -0.8004003 1.2064784 69 | -0.18531647 0.5072023 70 | 0.13842905 1.1174558 71 | 0.66258824 0.82555485 72 | 0.33609375 -0.6534637 73 | -2.0120873 -0.51198417 74 | 1.0629641 -0.31787252 75 | -2.8582766 2.1292703 76 | 0.23317564 0.62016463 77 | 1.2875621 -1.086997 78 | -0.9189713 -0.011757697 79 | -1.3810606 -1.3216977 80 | 0.6310501 0.6945632 81 | -1.4764296 -1.4454916 82 | 1.5506268 0.58793837 83 | -1.1552042 0.9369074 84 | 0.78062624 0.5720422 85 | 1.1205202 0.5649733 86 | 0.52997667 -0.3239132 87 | -0.733178 -0.8194146 88 | -1.0195599 -1.0602125 89 | -1.0560397 -1.0020539 90 | 0.92842615 0.4196956 91 | -0.053909604 0.29971042 92 | 0.20473078 0.12111267 93 | 1.014522 -0.020160262 94 | 0.56692797 -0.7931056 95 | -0.020879423 0.24323434 96 | -0.59649396 -0.92143637 97 | -0.8160203 0.17585017 98 | -0.38025358 1.8927022 99 | 0.29731482 1.0570496 100 | 0.23707008 0.5361591 101 | 0.43477994 0.0909581 102 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | pip uninstall netcalc netchem cuarray -y 2 | cd build 3 | make clean 4 | cd .. 5 | rm -rf build 6 | mkdir build 7 | cd build 8 | cmake .. -DCONDA_DIR=$CONDA_PREFIX 9 | cmake --build . -j 10 | make python 11 | 12 | -------------------------------------------------------------------------------- /netcalc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CLEAN_FILES_AND_DIRS 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/* 4 | ${CMAKE_CURRENT_SOURCE_DIR}/python/build 5 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netcalc.egg-info 6 | ${CMAKE_CURRENT_SOURCE_DIR}/python/dist 7 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netcalc/*.so* 8 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netcalc/netcalc.py 9 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netcalc/*.cxx* 10 | ) 11 | set_directory_properties( 12 | PROPERTIES 13 | ADDITIONAL_CLEAN_FILES "${CLEAN_FILES_AND_DIRS}" 14 | ) 15 | 16 | set_source_files_properties( 17 | ${CMAKE_CURRENT_SOURCE_DIR}/swig/python_netcalc.i 18 | PROPERTIES 19 | CPLUSPLUS ON 20 | SWIG_MODULE_NAME netcalc 21 | ) 22 | 23 | add_library(netcalc SHARED 24 | ${CMAKE_CURRENT_SOURCE_DIR}/src/mutual_information_gpu.cu 25 | ${CMAKE_CURRENT_SOURCE_DIR}/src/math_utils_gpu.cu 26 | ${CMAKE_CURRENT_SOURCE_DIR}/src/math_utils.cpp 27 | ${CMAKE_CURRENT_SOURCE_DIR}/src/generalized_correlation_gpu.cpp 28 | ${CMAKE_CURRENT_SOURCE_DIR}/src/mutual_information_cpu.cpp 29 | ${CMAKE_CURRENT_SOURCE_DIR}/src/generalized_correlation_cpu.cpp 30 | ${CMAKE_CURRENT_SOURCE_DIR}/src/mutual_information.cpp 31 | ${CMAKE_CURRENT_SOURCE_DIR}/src/hedetniemi_cpu.cpp 32 | ${CMAKE_CURRENT_SOURCE_DIR}/src/hedetniemi.cpp 33 | ${CMAKE_CURRENT_SOURCE_DIR}/src/hedetniemi_gpu.cu 34 | ${CMAKE_CURRENT_SOURCE_DIR}/src/generalized_correlation.cpp 35 | ${CMAKE_CURRENT_SOURCE_DIR}/src/psi.cpp 36 | ) 37 | add_dependencies(netcalc cuarray) 38 | set_target_properties( 39 | netcalc 40 | PROPERTIES 41 | CUDA_SEPARABLE_COMPILATION ON 42 | CUDA_ARCHITECTURES ${CUDA_ARCHITECTURE} 43 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib 44 | LINK_LIBRARIES "${NETCALC_LINK_LIBRARIES}" 45 | ) 46 | if (${BUILD_PYTHON_BINDINGS}) 47 | swig_add_library(python_netcalc 48 | LANGUAGE python 49 | OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python/netcalc 50 | SOURCES 51 | ${CMAKE_CURRENT_SOURCE_DIR}/swig/python_netcalc.i 52 | ) 53 | add_dependencies(python_netcalc netcalc) 54 | set_target_properties( 55 | python_netcalc 56 | PROPERTIES 57 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/netcalc 58 | LINK_LIBRARIES "${NETCALC_PYTHON_LINK_LIBRARIES}" 59 | ) 60 | 61 | set(PIP_UNINSTALL_NETCALC_ARGS "uninstall" "netcalc" "-y") 62 | set(PYTHON_NETCALC_INSTALL_ARGS "setup.py" "install") 63 | add_custom_target(PythonNetCalcInstall 64 | COMMAND pip ${PIP_UNINSTALL_NETCALC_ARGS} 65 | COMMAND ${Python3_EXECUTABLE} ${PYTHON_NETCALC_INSTALL_ARGS} 66 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/netcalc/python 67 | ) 68 | endif (${BUILD_PYTHON_BINDINGS}) 69 | 70 | add_executable( 71 | hedetniemi_scratch 72 | ${CMAKE_CURRENT_SOURCE_DIR}/scratch/hedetniemi_scratch.cpp 73 | ) 74 | add_dependencies(hedetniemi_scratch netcalc) 75 | 76 | add_executable( 77 | checkpointing_scratch 78 | ${CMAKE_CURRENT_SOURCE_DIR}/scratch/checkpointing_scratch.cpp 79 | ) 80 | add_dependencies(checkpointing_scratch netcalc) 81 | set_target_properties( 82 | checkpointing_scratch 83 | PROPERTIES 84 | LINK_LIBRARIES "${NETCALC_SCRATCH_LINK_LIBRARIES}" 85 | ) 86 | -------------------------------------------------------------------------------- /netcalc/include/math_utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by astokely on 5/16/23. 3 | // 4 | 5 | #ifndef NETSCI_MATH_UTILS_H 6 | #define NETSCI_MATH_UTILS_H 7 | 8 | #include "cuarray.h" 9 | #include "platform.h" 10 | 11 | /** 12 | * \brief Computes the mean of the rows in a matrix. 13 | * 14 | * This function calculates the mean of each row in the input matrix 'a' 15 | * and stores the result in the output array 'u'. 16 | * 17 | * \param a Pointer to the input matrix of type CuArray. 18 | * \param u Pointer to the output array where the mean will be stored, of type CuArray. 19 | * \param m Number of rows in the matrix. 20 | * \param n Number of columns in the matrix. 21 | * \param platform Platform used for computation. Use 0 for GPU and 1 for CPU. 22 | */ 23 | void mean( 24 | CuArray* a, 25 | CuArray* u, 26 | int m, 27 | int n, 28 | int platform 29 | ); 30 | 31 | /** 32 | * \brief Computes the mean of the rows in a matrix on the GPU. 33 | * 34 | * This function calculates the mean of each row in the input matrix 'a' 35 | * on the GPU and stores the result in the output array 'u'. 36 | * 37 | * \param a Pointer to the input matrix of type CuArray. 38 | * \param u Pointer to the output array where the mean will be stored, of type CuArray. 39 | * \param m Number of rows in the matrix. 40 | * \param n Number of columns in the matrix. 41 | */ 42 | void meanGpu( 43 | CuArray* a, 44 | CuArray* u, 45 | int m, 46 | int n 47 | ); 48 | 49 | /** 50 | * \brief Computes the standard deviation of each row in a matrix. 51 | * 52 | * This function calculates the standard deviation of the elements in each row 53 | * of the input matrix 'a' and stores the result in the output array 'sigma'. 54 | * The mean of each row is also calculated and stored in the array 'u'. 55 | * 56 | * \param a Pointer to the input matrix of type CuArray. 57 | * \param u Pointer to the array where the mean will be stored, of type CuArray. 58 | * \param sigma Pointer to the output array where the standard deviation will be stored, of type CuArray. 59 | * \param m Number of rows in the matrix. 60 | * \param n Number of columns in the matrix. 61 | * \param platform Platform used for computation. Use 0 for GPU and 1 for CPU. 62 | */ 63 | void standardDeviation( 64 | CuArray* a, 65 | CuArray* u, 66 | CuArray* sigma, 67 | int m, 68 | int n, 69 | int platform 70 | ); 71 | 72 | /** 73 | * \brief Computes the standard deviation of each row in a matrix on the GPU. 74 | * 75 | * This function calculates the standard deviation of the elements in each row 76 | * of the input matrix 'a' on the GPU and stores the result in the output array 'sigma'. 77 | * The mean of each row is also calculated and stored in the array 'u'. 78 | * 79 | * \param a Pointer to the input matrix of type CuArray. 80 | * \param u Pointer to the array where the mean will be stored, of type CuArray. 81 | * \param sigma Pointer to the output array where the standard deviation will be stored, of type CuArray. 82 | * \param m Number of rows in the matrix. 83 | * \param n Number of columns in the matrix. 84 | */ 85 | void standardDeviationGpu( 86 | CuArray* a, 87 | CuArray* u, 88 | CuArray* sigma, 89 | int m, 90 | int n 91 | ); 92 | 93 | #endif // NETSCI_MATH_UTILS_H -------------------------------------------------------------------------------- /netcalc/include/platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by astokely on 7/26/23. 3 | // 4 | 5 | #ifndef NETSCI_PLATFORM_H 6 | #define NETSCI_PLATFORM_H 7 | 8 | namespace netcalc { 9 | const int GPU_PLATFORM = 0; 10 | const int CPU_PLATFORM = 1; 11 | } 12 | 13 | #endif //NETSCI_PLATFORM_H 14 | -------------------------------------------------------------------------------- /netcalc/include/psi.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 3/24/23. 3 | // 4 | 5 | #ifndef MUTUAL_INFORMATION_SHARED_MEMORY_PSI_H 6 | #define MUTUAL_INFORMATION_SHARED_MEMORY_PSI_H 7 | 8 | #include 9 | #include "cuarray.h" 10 | 11 | /*! 12 | * \brief Generates the diagamma array used in the mutual information calculation. 13 | * 14 | * This function generates the diagamma array and stores it in the provided output array 'psi'. 15 | * 16 | * \param psi Pointer to the output array where the diagamma array will be stored. 17 | * \param n Number of observations in each random variable. 18 | */ 19 | void generatePsi( 20 | CuArray* psi, 21 | int n 22 | ); 23 | 24 | #endif // MUTUAL_INFORMATION_SHARED_MEMORY_PSI_H 25 | -------------------------------------------------------------------------------- /netcalc/python/setup.py: -------------------------------------------------------------------------------- 1 | 2 | from setuptools import find_packages 3 | from setuptools import setup 4 | import os 5 | 6 | path = os.path.relpath(os.path.dirname(__file__)) 7 | 8 | setup( 9 | author='Andy Stokely', 10 | email='amstokely@ucsd.edu', 11 | name='netcalc', 12 | install_requires=[], 13 | platforms=['Linux', 14 | 'Unix', ], 15 | python_requires=">=3.9", 16 | py_modules=[path + "/netcalc/netcalc"], 17 | packages=find_packages() + [''], 18 | zip_safe=False, 19 | package_data={ 20 | '': [ 21 | path + '/netcalc/_python_netcalc.so' 22 | ] 23 | }, 24 | ) 25 | -------------------------------------------------------------------------------- /netcalc/samples/python/NetCalc_generalizedCorrelation.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netcalc/samples/python/NetCalc_generalizedCorrelation.py -------------------------------------------------------------------------------- /netcalc/samples/python/NetCalc_generalizedCorrelationWithCheckpointing.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netcalc/samples/python/NetCalc_generalizedCorrelationWithCheckpointing.py -------------------------------------------------------------------------------- /netcalc/samples/python/NetCalc_mutualInformation.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netcalc/samples/python/NetCalc_mutualInformation.py -------------------------------------------------------------------------------- /netcalc/samples/python/NetCalc_mutualInformationWithCheckpointing.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netcalc/samples/python/NetCalc_mutualInformationWithCheckpointing.py -------------------------------------------------------------------------------- /netcalc/scratch/checkpointing_scratch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mutual_information.h" 3 | 4 | int main() { 5 | int n = 290; 6 | auto ab = new CuArray; 7 | ab->init(n*n, 2); 8 | for (int i = 0; i < n; i++) { 9 | for (int j = 0; j < 290; j++) { 10 | ab->set(i, i*n+j, 0); 11 | ab->set(j, i*n+j, 1); 12 | } 13 | } 14 | std::string checkpointFileName = "test_84000.npy"; 15 | auto restartAb = new CuArray; 16 | netcalc::generateRestartAbFromCheckpointFile( 17 | ab, 18 | restartAb, 19 | checkpointFileName 20 | ); 21 | 22 | for (int i = 0; i < restartAb->m(); i++) { 23 | std::cout 24 | << restartAb->get(i, 0) << " " 25 | << restartAb->get(i, 1) << std::endl; 26 | } 27 | delete ab; 28 | delete restartAb; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /netcalc/scratch/hedetniemi_scratch.cpp: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | return 0; 4 | } -------------------------------------------------------------------------------- /netcalc/src/generalized_correlation_cpu.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 4/17/23. 3 | // 4 | #include "generalized_correlation.h" 5 | #include "mutual_information.h" 6 | #include 7 | 8 | float netcalc::generalizedCorrelationCpu( 9 | CuArray *Xa, 10 | CuArray *Xb, 11 | int k, 12 | int n, 13 | int xd, 14 | int d 15 | ) { 16 | float mutualInformation = netcalc::mutualInformationCpu( 17 | Xa, Xb, k, n, xd, d 18 | ); 19 | if (mutualInformation <= 0.0) { 20 | return 0.0; 21 | } else { 22 | return (float) std::sqrt( 23 | 1.0 - (float) std::exp(-(2.0 / (float) d) * mutualInformation) 24 | ); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /netcalc/src/generalized_correlation_gpu.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 4/17/23. 3 | // 4 | #include "generalized_correlation.h" 5 | #include "mutual_information.h" 6 | #include 7 | 8 | float netcalc::generalizedCorrelationGpu( 9 | CuArray *Xa, 10 | CuArray *Xb, 11 | int k, 12 | int n, 13 | int xd, 14 | int d 15 | ) { 16 | float mutualInformation = 17 | netcalc::mutualInformationGpu( 18 | Xa, 19 | Xb, 20 | k, 21 | n, 22 | xd, 23 | d 24 | ); 25 | if (mutualInformation <= 0.0) { 26 | return 0.0; 27 | } else { 28 | return (float) std::sqrt( 29 | 1.0 - (float) exp(-(2.0 / (float) d) * mutualInformation) 30 | ); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /netcalc/src/hedetniemi.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by astokely on 5/10/23. 3 | // 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "hedetniemi.h" 9 | 10 | void netcalc::hedetniemiAllShortestPaths( 11 | CuArray *A, 12 | CuArray *H, 13 | CuArray *paths, 14 | int maxPathLength, 15 | float tolerance, 16 | int platform 17 | ) { 18 | H->init(A->m(), 19 | A->n()); 20 | if (platform == 0) { 21 | netcalc::hedetniemiAllShortestPathsGpu(A, 22 | H, 23 | paths, 24 | tolerance, 25 | maxPathLength 26 | ); 27 | } else if (platform == 1) { 28 | netcalc::hedetniemiAllShortestPathsCpu(A, 29 | H, 30 | paths, 31 | tolerance, 32 | maxPathLength 33 | ); 34 | } else { 35 | throw std::invalid_argument("Invalid platform"); 36 | } 37 | } 38 | 39 | void netcalc::hedetniemiAllShortestPathLengths( 40 | CuArray *A, 41 | CuArray *H, 42 | int maxPathLength, 43 | int platform 44 | ) { 45 | H->init(A->m(), 46 | A->n()); 47 | if (platform == 0) { 48 | netcalc::hedetniemiAllShortestPathLengthsGpu(A, 49 | H, 50 | maxPathLength 51 | ); 52 | 53 | } 54 | } 55 | 56 | void netcalc::correlationToAdjacency( 57 | CuArray *A, 58 | CuArray *C, 59 | int n, 60 | int platform 61 | ) { 62 | A->init(n, 63 | n); 64 | if (platform == 0) { 65 | netcalc::correlationToAdjacencyGpu(A, 66 | C, 67 | n); 68 | } 69 | } 70 | 71 | void netcalc::recoverSingleShortestPath( 72 | int **NUMPY_ARRAY, 73 | int **NUMPY_ARRAY_DIM1, 74 | CuArray *paths, 75 | int maxPathLength, 76 | int i, 77 | int j 78 | ) { 79 | *(NUMPY_ARRAY_DIM1) = new int[1]; 80 | (*NUMPY_ARRAY_DIM1)[0] = 0; 81 | std::vector path; 82 | path.push_back(i); 83 | int n = (int) std::sqrt(paths->n() / maxPathLength); 84 | for (int k = 0; k < maxPathLength; k++) { 85 | auto node = paths->get(0, 86 | i * maxPathLength * n + 87 | j * maxPathLength + k); 88 | if (std::find( 89 | path.begin(), 90 | path.end(), 91 | node) == path.end()) { 92 | path.push_back(node); 93 | } 94 | } 95 | if (std::find( 96 | path.begin(), 97 | path.end(), 98 | j) == path.end()) { 99 | path.push_back(j); 100 | } 101 | (*NUMPY_ARRAY_DIM1)[0] = (int) path.size(); 102 | *NUMPY_ARRAY = new int[(*NUMPY_ARRAY_DIM1)[0]]; 103 | std::copy( 104 | path.begin(), 105 | path.end(), 106 | *NUMPY_ARRAY 107 | ); 108 | } 109 | -------------------------------------------------------------------------------- /netcalc/src/hedetniemi_cpu.cpp: -------------------------------------------------------------------------------- 1 | // 2 | #include "hedetniemi.h" 3 | #include 4 | 5 | void netcalc::hedetniemiAllShortestPathsCpu( 6 | CuArray *A, 7 | CuArray *H, 8 | CuArray *paths, 9 | float tolerance, 10 | int maxPathLength 11 | 12 | ) { 13 | std::cout 14 | << "Path finding on CPU is not implemented yet." 15 | << std::endl; 16 | } 17 | -------------------------------------------------------------------------------- /netcalc/src/math_utils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by astokely on 5/16/23. 3 | // 4 | #include "math_utils.h" 5 | 6 | void mean( 7 | CuArray *a, 8 | CuArray *u, 9 | int m, 10 | int n, 11 | int platform 12 | ) { 13 | 14 | m = a->size() / n; 15 | u->init(1, m); 16 | if (platform == 0) { 17 | meanGpu(a, u, m, n); 18 | } 19 | } 20 | 21 | void standardDeviation( 22 | CuArray *a, 23 | CuArray *u, 24 | CuArray *sigma, 25 | int m, 26 | int n, 27 | int platform 28 | ) { 29 | 30 | m = a->size() / n; 31 | u->init(1, m); 32 | sigma->init(1, m); 33 | if (platform == 0) { 34 | standardDeviationGpu(a, u, sigma, m, n); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /netcalc/src/mutual_information_cpu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mutual_information.h" 4 | #include "psi.h" 5 | 6 | float netcalc::mutualInformationCpu( 7 | CuArray *Xa, 8 | CuArray *Xb, 9 | int k, 10 | int n, 11 | int xd, 12 | int d 13 | ) { 14 | auto *psi = new CuArray; 15 | psi->init(1, n + 1); 16 | generatePsi(psi, n); 17 | auto *nXa = new CuArray; 18 | nXa->init(1, n); 19 | auto *nXb = new CuArray; 20 | nXb->init(1, n); 21 | float averageXaXbPsiK = 0.0; 22 | for (int i = 0; i < n; i++) { 23 | nXa->set(0, 0, i); 24 | nXb->set(0, 0, i); 25 | auto *dZ = new CuArray; 26 | dZ->init(1, n); 27 | for (int j = 0; j < n; j++) { 28 | float dXa = std::abs(Xa->get(0, i) 29 | - Xa->get(0, j)); 30 | for (int di = 1; di < d; di++) { 31 | dXa = std::max( 32 | dXa, 33 | std::abs(Xa->get(0, i + (di * n)) 34 | - Xa->get(0, j + (di * n))) 35 | ); 36 | } 37 | float dXb = std::abs(Xb->get(0, i) 38 | - Xb->get(0, j)); 39 | for (int di = 1; di < d; di++) { 40 | dXb = std::max( 41 | dXb, 42 | std::abs(Xb->get(0, i + (di * n)) 43 | - Xb->get(0, j + (di * n))) 44 | ); 45 | } 46 | dZ->set(std::max(dXa, dXb), 0, j); 47 | } 48 | std::vector argMin(n); 49 | std::iota(argMin.begin(), argMin.end(), 0); 50 | std::sort(argMin.begin(), argMin.end(), [&]( 51 | int i, 52 | int j 53 | ) { return (*dZ)[i] < (*dZ)[j]; }); 54 | float epsXa = 0.0; 55 | float epsXb = 0.0; 56 | for (int ki = 1; ki < k + 1; ki++) { 57 | float dXa = std::abs(Xa->get(0, i) 58 | - Xa->get(0, argMin[ki])); 59 | for (int di = 1; di < d; di++) { 60 | dXa = std::max( 61 | dXa, 62 | std::abs(Xa->get(0, i + (di * n)) 63 | - Xa->get(0, argMin[ki] + (di * n))) 64 | ); 65 | } 66 | float dXb = std::abs(Xb->get(0, i) 67 | - Xb->get(0, argMin[ki])); 68 | for (int di = 1; di < d; di++) { 69 | dXb = std::max( 70 | dXb, 71 | std::abs(Xb->get(0, i + (di * n)) 72 | - Xb->get(0, argMin[ki] + (di * n))) 73 | ); 74 | } 75 | epsXa = std::max(epsXa, dXa); 76 | epsXb = std::max(epsXb, dXb); 77 | } 78 | for (int j = 0; j < n; j++) { 79 | float dXa = std::abs(Xa->get(0, i) 80 | - Xa->get(0, j)); 81 | for (int di = 1; di < d; di++) { 82 | dXa = std::max( 83 | dXa, 84 | std::abs(Xa->get(0, i + (di * n)) 85 | - Xa->get(0, j + (di * n))) 86 | ); 87 | } 88 | float dXb = std::abs(Xb->get(0, i) 89 | - Xb->get(0, j)); 90 | for (int di = 1; di < d; di++) { 91 | dXb = std::max( 92 | dXb, 93 | std::abs(Xb->get(0, i + (di * n)) 94 | - Xb->get(0, j + (di * n))) 95 | ); 96 | } 97 | if (dXa <= epsXa) { 98 | nXa->set( 99 | nXa->get(0, i) + 1, 100 | 0, i); 101 | } 102 | if (dXb <= epsXb) { 103 | nXb->set( 104 | nXb->get(0, i) + 1, 105 | 0, i); 106 | } 107 | } 108 | nXa->set(nXa->get(0, i) - 1, 0, i); 109 | nXb->set(nXb->get(0, i) - 1, 0, i); 110 | averageXaXbPsiK += ((*psi)[(*nXa)[i]] + (*psi)[(*nXb)[i]]); 111 | delete dZ; 112 | } 113 | averageXaXbPsiK /= (float) n; 114 | delete nXa; 115 | delete nXb; 116 | float mutualInformation = psi->get(0, n) + psi->get(0, k) - 117 | (float) (1.0 / (float) k) - 118 | averageXaXbPsiK; 119 | delete psi; 120 | return mutualInformation; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /netcalc/src/psi.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 3/24/23. 3 | // 4 | #include "psi.h" 5 | 6 | void generatePsi( 7 | CuArray *psi, 8 | int n 9 | ) { 10 | psi->set(-0.57721566490153, 0, 1); 11 | for (int i = 0; i < n; i++) { 12 | if (i > 0) { 13 | auto inversePsiIndex = (float) (1.0 / 14 | static_cast(i)); 15 | psi->set(psi->get(0, i) 16 | + inversePsiIndex, 0, i + 1); 17 | 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /netcalc/swig/numpy_int_array.i: -------------------------------------------------------------------------------- 1 | %include "numpy.i" 2 | %init %{ 3 | import_array(); 4 | %} 5 | 6 | 7 | %fragment("FreeCap", "header") { 8 | void FreeCap (PyObject *cap) { 9 | void *array = (void *) PyCapsule_GetPointer( 10 | cap, 11 | NULL 12 | ); 13 | if (array 14 | != NULL) { 15 | free(array); 16 | } 17 | } 18 | 19 | } 20 | 21 | %typemap(in, numinputs = 0 22 | ) ( 23 | int **NUMPY_ARRAY, 24 | int **NUMPY_ARRAY_DIM1 25 | ) 26 | ( 27 | int *NUMPY_ARRAY_tmp, 28 | int *NUMPY_ARRAY_DIM1_tmp 29 | ) { 30 | $1 = &NUMPY_ARRAY_tmp; 31 | $2 = &NUMPY_ARRAY_DIM1_tmp; 32 | } 33 | 34 | %typemap(argout, fragment = "FreeCap" 35 | ) ( 36 | int **NUMPY_ARRAY, 37 | int **NUMPY_ARRAY_DIM1 38 | ) { 39 | npy_intp dims[1] = {(*($2))[0]}; 40 | PyObject *obj = PyArray_SimpleNewFromData( 41 | 1, 42 | dims, 43 | NPY_INT32, 44 | (void *) (*$1)); 45 | PyArrayObject *array = (PyArrayObject *) obj; 46 | PyObject *cap = PyCapsule_New((void *) (*$1), 47 | NULL, 48 | FreeCap 49 | ); 50 | PyArray_SetBaseObject(array, cap 51 | ); 52 | $result = SWIG_Python_AppendOutput( 53 | $result, 54 | obj 55 | ); 56 | free(*$2); 57 | } 58 | -------------------------------------------------------------------------------- /netcalc/swig/python_netcalc.i: -------------------------------------------------------------------------------- 1 | %module netcalc 2 | 3 | %include "std_string.i" 4 | %include "python_netcalc_rename.i" 5 | %include "python_netcalc_header.i" 6 | %include "numpy_int_array.i" 7 | %include "python_netcalc_include.i" 8 | 9 | -------------------------------------------------------------------------------- /netcalc/swig/python_netcalc_header.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #define SWIG_FILE_WITH_INIT 3 | #include "mutual_information.h" 4 | #include "generalized_correlation.h" 5 | #include "math_utils.h" 6 | #include "hedetniemi.h" 7 | #include "platform.h" 8 | %} -------------------------------------------------------------------------------- /netcalc/swig/python_netcalc_include.i: -------------------------------------------------------------------------------- 1 | %include mutual_information.h 2 | %include math_utils.h 3 | %include generalized_correlation.h 4 | %include hedetniemi.h 5 | %include platform.h 6 | -------------------------------------------------------------------------------- /netcalc/swig/python_netcalc_rename.i: -------------------------------------------------------------------------------- 1 | %rename(generalizedCorrelation) 2 | netcalc::generalizedCorrelation( 3 | CuArray* X, 4 | CuArray* R, 5 | CuArray* ab, 6 | int k, 7 | int n, 8 | int xd, 9 | int d, 10 | int platform 11 | ); 12 | 13 | %rename(generalizedCorrelationWithCheckpointing) 14 | netcalc::generalizedCorrelation( 15 | CuArray* X, 16 | CuArray* R, 17 | CuArray* ab, 18 | int k, 19 | int n, 20 | int xd, 21 | int d, 22 | int platform, 23 | int checkpointFrequency, 24 | std::string checkpointFileName 25 | ); 26 | 27 | %rename(mutualInformation) 28 | netcalc::mutualInformation( 29 | CuArray *X, 30 | CuArray *I, 31 | CuArray *ab, 32 | int k, 33 | int n, 34 | int xd, 35 | int d, 36 | int platform 37 | ); 38 | 39 | %rename(mutualInformationWithCheckpointing) 40 | netcalc::mutualInformation( 41 | CuArray *X, 42 | CuArray *I, 43 | CuArray *ab, 44 | int k, 45 | int n, 46 | int xd, 47 | int d, 48 | int platform, 49 | int checkpointFrequency, 50 | std::string checkpointFileName 51 | ); 52 | 53 | -------------------------------------------------------------------------------- /netchem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CLEAN_FILES_AND_DIRS 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/* 4 | ${CMAKE_CURRENT_SOURCE_DIR}/python/build 5 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netchem.egg-info 6 | ${CMAKE_CURRENT_SOURCE_DIR}/python/dist 7 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netchem/*.so* 8 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netchem/netchem.py 9 | ${CMAKE_CURRENT_SOURCE_DIR}/python/netchem/*.cxx* 10 | ) 11 | set_directory_properties( 12 | PROPERTIES 13 | ADDITIONAL_CLEAN_FILES "${CLEAN_FILES_AND_DIRS}" 14 | ) 15 | 16 | set_source_files_properties( 17 | ${CMAKE_CURRENT_SOURCE_DIR}/swig/python_netchem.i 18 | PROPERTIES 19 | CPLUSPLUS ON 20 | SWIG_MODULE_NAME netchem 21 | ) 22 | 23 | add_library(netchem SHARED 24 | ${CMAKE_CURRENT_SOURCE_DIR}/src/serializer.cpp 25 | ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cpp 26 | ${CMAKE_CURRENT_SOURCE_DIR}/src/dcd/dcd.cpp 27 | ${CMAKE_CURRENT_SOURCE_DIR}/src/atom.cpp 28 | ${CMAKE_CURRENT_SOURCE_DIR}/src/node.cpp 29 | ${CMAKE_CURRENT_SOURCE_DIR}/src/network.cpp 30 | ${CMAKE_CURRENT_SOURCE_DIR}/src/atoms.cpp 31 | ) 32 | add_dependencies(netchem cuarray) 33 | set_target_properties( 34 | netchem 35 | PROPERTIES 36 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib 37 | LINK_LIBRARIES "${NETCHEM_LINK_LIBRARIES}" 38 | ) 39 | if (${BUILD_PYTHON_BINDINGS}) 40 | swig_add_library(python_netchem 41 | LANGUAGE python 42 | OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python/netchem 43 | SOURCES 44 | ${CMAKE_CURRENT_SOURCE_DIR}/swig/python_netchem.i 45 | ) 46 | set_target_properties( 47 | python_netchem 48 | PROPERTIES 49 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/netchem 50 | LINK_LIBRARIES "${NETCHEM_PYTHON_LINK_LIBRARIES}" 51 | ) 52 | 53 | set(PIP_UNINSTALL_NETCHEM_ARGS "uninstall" "netchem" "-y") 54 | set(PYTHON_NETCHEM_INSTALL_ARGS "setup.py" "install") 55 | add_custom_target(PythonNetChemInstall 56 | COMMAND pip ${PIP_UNINSTALL_NETCHEM_ARGS} 57 | COMMAND ${Python3_EXECUTABLE} ${PYTHON_NETCHEM_INSTALL_ARGS} 58 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/netchem/python 59 | ) 60 | endif (${BUILD_PYTHON_BINDINGS}) 61 | add_executable( 62 | stride_scratch 63 | ${CMAKE_CURRENT_SOURCE_DIR}/scratch/stride_scratch.cpp 64 | ) 65 | add_dependencies(stride_scratch netchem) 66 | set_target_properties( 67 | stride_scratch 68 | PROPERTIES 69 | LINK_LIBRARIES "${NETCHEM_SCRATCH_LINK_LIBRARIES}" 70 | ) 71 | -------------------------------------------------------------------------------- /netchem/include/atoms.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by astokely on 5/4/23. 3 | // 4 | 5 | #ifndef NETSCI_ATOMS_H 6 | #define NETSCI_ATOMS_H 7 | 8 | 9 | #include "atom.h" 10 | #include 11 | #include 12 | #include "nlohmann/json.hpp" 13 | 14 | 15 | class Atoms { 16 | public: 17 | /** 18 | * \brief Default constructor for Atoms. 19 | * 20 | * Constructs an empty Atoms object. 21 | */ 22 | Atoms(); 23 | 24 | /** 25 | * \brief Add an Atom to the Atoms collection. 26 | * 27 | * Adds the specified Atom to the collection of Atoms. 28 | * 29 | * \param atom Pointer to the Atom to add. 30 | */ 31 | void addAtom(Atom* atom); 32 | 33 | /** 34 | * \brief Get the number of Atoms in the collection. 35 | * 36 | * Returns the number of Atoms in the collection. 37 | * 38 | * \return The number of Atoms. 39 | * 40 | * @PythonExample{NetChem_Atoms_numAtoms.py} 41 | */ 42 | int numAtoms() const; 43 | 44 | /** 45 | * \brief Get the Atom with the specified index. 46 | * 47 | * Returns a pointer to the Atom with the specified index. 48 | * 49 | * \param atomIndex The index of the Atom. 50 | * \return A pointer to the Atom with the specified index. 51 | * 52 | * @PythonExample{NetChem_Atoms_at.py} 53 | */ 54 | Atom* at(int atomIndex); 55 | 56 | /** 57 | * \brief Get the number of unique Atom tags. 58 | * 59 | * Returns the number of unique Atom tags. 60 | * Atoms with the same tag belong to the same Node. 61 | * 62 | * \return The number of unique Atom tags. 63 | */ 64 | int numUniqueTags() const; 65 | 66 | /** 67 | * \brief Get a reference to the vector of Atoms. 68 | * 69 | * Returns a reference to the vector of Atoms. 70 | * 71 | * \return A reference to the vector of Atoms. 72 | * 73 | * @PythonExample{NetChem_Atoms_atoms.py} 74 | */ 75 | std::vector& atoms(); 76 | 77 | private: 78 | friend nlohmann::adl_serializer; 79 | std::vector atoms_; 80 | std::set uniqueTags_; 81 | }; 82 | 83 | 84 | #endif //NETSCI_ATOMS_H 85 | 86 | -------------------------------------------------------------------------------- /netchem/include/dcd/dcd.h: -------------------------------------------------------------------------------- 1 | #include "fastio.h" /* must come before others, for O_DIRECT... */ 2 | #include "molfile_plugin.h" 3 | 4 | #ifndef DCDPLUGIN_H 5 | #define DCDPLUGIN_H 6 | 7 | typedef struct { 8 | fio_fd fd; 9 | int natoms; 10 | int nsets; 11 | int setsread; 12 | int istart; 13 | int nsavc; 14 | double delta; 15 | int nfixed; 16 | float *x, *y, *z; 17 | int *freeind; 18 | float *fixedcoords; 19 | int reverse; 20 | int charmm; 21 | int first; 22 | int with_unitcell; 23 | } dcdhandle; 24 | 25 | #ifndef M_PI_2 26 | #define M_PI_2 1.57079632679489661922 27 | #endif 28 | 29 | #define RECSCALE32BIT 1 30 | #define RECSCALE64BIT 2 31 | #define RECSCALEMAX 2 32 | 33 | /* Define error codes that may be returned by the DCD routines */ 34 | #define DCD_SUCCESS 0 /* No problems */ 35 | #define DCD_EOF -1 /* Normal EOF */ 36 | #define DCD_DNE -2 /* DCD file does not exist */ 37 | #define DCD_OPENFAILED -3 /* Open of DCD file failed */ 38 | #define DCD_BADREAD -4 /* read call on DCD file failed */ 39 | #define DCD_BADEOF -5 /* premature EOF found in DCD file */ 40 | #define DCD_BADFORMAT -6 /* format of DCD file is wrong */ 41 | #define DCD_FILEEXISTS -7 /* output file already exists */ 42 | #define DCD_BADMALLOC -8 /* malloc failed */ 43 | #define DCD_BADWRITE -9 /* write call on DCD file failed */ 44 | 45 | /* Define feature flags for this DCD file */ 46 | #define DCD_IS_XPLOR 0x00 47 | #define DCD_IS_CHARMM 0x01 48 | #define DCD_HAS_4DIMS 0x02 49 | #define DCD_HAS_EXTRA_BLOCK 0x04 50 | #define DCD_HAS_64BIT_REC 0x08 51 | 52 | /* defines used by write_dcdstep */ 53 | #define NFILE_POS 8L 54 | #define NSTEP_POS 20L 55 | 56 | /* READ Macro to make porting easier */ 57 | #define READ(fd, buf, size) fio_fread(((void *) (buf)), (size), 1, (fd)) 58 | 59 | /* WRITE Macro to make porting easier */ 60 | #define WRITE(fd, buf, size) fio_fwrite(((void *) buf), (size), 1, (fd)) 61 | 62 | /* XXX This is broken - fread never returns -1 */ 63 | #define CHECK_FREAD(X, msg) if ((X)==-1) { return(DCD_BADREAD); } 64 | #define CHECK_FEOF(X, msg) if ((X)==0) { return(DCD_BADEOF); } 65 | 66 | dcdhandle *open_dcd_read (const char *path, 67 | int *natoms, 68 | int *nsets); 69 | void close_file_read(dcdhandle *v); 70 | int read_next_timestep(dcdhandle *v, int natoms, molfile_timestep_t *ts); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /netchem/include/dcd/largefiles.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | *cr 3 | *cr (C) Copyright 1995-2009 The Board of Trustees of the 4 | *cr University of Illinois 5 | *cr All Rights Reserved 6 | *cr 7 | ***************************************************************************/ 8 | 9 | /*************************************************************************** 10 | * RCS INFORMATION: 11 | * 12 | * $RCSfile: largefiles.h,v $ 13 | * $Author: johns $ $Locker: $ $State: Exp $ 14 | * $Revision: 1.3 $ $Date: 2009/04/29 15:45:31 $ 15 | * 16 | *************************************************************************** 17 | * DESCRIPTION: 18 | * Platform dependent defines for enabling 64-bit file I/O on 32-bit machines 19 | * 20 | ***************************************************************************/ 21 | 22 | #if defined(_AIX) 23 | /* Define to enable large file extensions on AIX */ 24 | #define _LARGE_FILE 25 | #define _LARGE_FILES 26 | #else 27 | /* Defines which enable LFS I/O interfaces for large (>2GB) file support 28 | * on 32-bit machines. These must be defined before inclusion of any 29 | * system headers. 30 | */ 31 | #ifndef _LARGEFILE_SOURCE 32 | #define _LARGEFILE_SOURCE 33 | #endif 34 | #define _FILE_OFFSET_BITS 64 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /netchem/include/json/LISCENSE.MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2022 Niels Lohmann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copyHost, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/adl_serializer.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | NLOHMANN_JSON_NAMESPACE_BEGIN 19 | 20 | /// @sa https://json.nlohmann.me/api/adl_serializer/ 21 | template 22 | struct adl_serializer 23 | { 24 | /// @brief convert a JSON value to any value type 25 | /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ 26 | template 27 | static auto from_json(BasicJsonType && j, TargetType& val) noexcept( 28 | noexcept(::nlohmann::from_json(std::forward(j), val))) 29 | -> decltype(::nlohmann::from_json(std::forward(j), val), void()) 30 | { 31 | ::nlohmann::from_json(std::forward(j), val); 32 | } 33 | 34 | /// @brief convert a JSON value to any value type 35 | /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ 36 | template 37 | static auto from_json(BasicJsonType && j) noexcept( 38 | noexcept(::nlohmann::from_json(std::forward(j), detail::identity_tag {}))) 39 | -> decltype(::nlohmann::from_json(std::forward(j), detail::identity_tag {})) 40 | { 41 | return ::nlohmann::from_json(std::forward(j), detail::identity_tag {}); 42 | } 43 | 44 | /// @brief convert any value type to a JSON value 45 | /// @sa https://json.nlohmann.me/api/adl_serializer/to_json/ 46 | template 47 | static auto to_json(BasicJsonType& j, TargetType && val) noexcept( 48 | noexcept(::nlohmann::to_json(j, std::forward(val)))) 49 | -> decltype(::nlohmann::to_json(j, std::forward(val)), void()) 50 | { 51 | ::nlohmann::to_json(j, std::forward(val)); 52 | } 53 | }; 54 | 55 | NLOHMANN_JSON_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/byte_container_with_subtype.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // uint8_t, uint64_t 12 | #include // tie 13 | #include // move 14 | 15 | #include 16 | 17 | NLOHMANN_JSON_NAMESPACE_BEGIN 18 | 19 | /// @brief an internal type for a backed binary type 20 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/ 21 | template 22 | class byte_container_with_subtype : public BinaryType 23 | { 24 | public: 25 | using container_type = BinaryType; 26 | using subtype_type = std::uint64_t; 27 | 28 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ 29 | byte_container_with_subtype() noexcept(noexcept(container_type())) 30 | : container_type() 31 | {} 32 | 33 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ 34 | byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) 35 | : container_type(b) 36 | {} 37 | 38 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ 39 | byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) 40 | : container_type(std::move(b)) 41 | {} 42 | 43 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ 44 | byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) 45 | : container_type(b) 46 | , m_subtype(subtype_) 47 | , m_has_subtype(true) 48 | {} 49 | 50 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ 51 | byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) 52 | : container_type(std::move(b)) 53 | , m_subtype(subtype_) 54 | , m_has_subtype(true) 55 | {} 56 | 57 | bool operator==(const byte_container_with_subtype& rhs) const 58 | { 59 | return std::tie(static_cast(*this), m_subtype, m_has_subtype) == 60 | std::tie(static_cast(rhs), rhs.m_subtype, rhs.m_has_subtype); 61 | } 62 | 63 | bool operator!=(const byte_container_with_subtype& rhs) const 64 | { 65 | return !(rhs == *this); 66 | } 67 | 68 | /// @brief sets the binary subtype 69 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/ 70 | void set_subtype(subtype_type subtype_) noexcept 71 | { 72 | m_subtype = subtype_; 73 | m_has_subtype = true; 74 | } 75 | 76 | /// @brief return the binary subtype 77 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/ 78 | constexpr subtype_type subtype() const noexcept 79 | { 80 | return m_has_subtype ? m_subtype : static_cast(-1); 81 | } 82 | 83 | /// @brief return whether the value has a subtype 84 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/ 85 | constexpr bool has_subtype() const noexcept 86 | { 87 | return m_has_subtype; 88 | } 89 | 90 | /// @brief clears the binary subtype 91 | /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/ 92 | void clear_subtype() noexcept 93 | { 94 | m_subtype = 0; 95 | m_has_subtype = false; 96 | } 97 | 98 | private: 99 | subtype_type m_subtype = 0; 100 | bool m_has_subtype = false; 101 | }; 102 | 103 | NLOHMANN_JSON_NAMESPACE_END 104 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/abi_macros.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | // This file contains all macro definitions affecting or depending on the ABI 12 | 13 | #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK 14 | #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) 15 | #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2 16 | #warning "Already included a different version of the library!" 17 | #endif 18 | #endif 19 | #endif 20 | 21 | #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) 22 | #define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) 23 | #define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum) 24 | 25 | #ifndef JSON_DIAGNOSTICS 26 | #define JSON_DIAGNOSTICS 0 27 | #endif 28 | 29 | #ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 30 | #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 31 | #endif 32 | 33 | #if JSON_DIAGNOSTICS 34 | #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag 35 | #else 36 | #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS 37 | #endif 38 | 39 | #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 40 | #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp 41 | #else 42 | #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON 43 | #endif 44 | 45 | #ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION 46 | #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 47 | #endif 48 | 49 | // Construct the namespace ABI tags component 50 | #define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b 51 | #define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ 52 | NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) 53 | 54 | #define NLOHMANN_JSON_ABI_TAGS \ 55 | NLOHMANN_JSON_ABI_TAGS_CONCAT( \ 56 | NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ 57 | NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) 58 | 59 | // Construct the namespace version component 60 | #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ 61 | _v ## major ## _ ## minor ## _ ## patch 62 | #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ 63 | NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) 64 | 65 | #if NLOHMANN_JSON_NAMESPACE_NO_VERSION 66 | #define NLOHMANN_JSON_NAMESPACE_VERSION 67 | #else 68 | #define NLOHMANN_JSON_NAMESPACE_VERSION \ 69 | NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ 70 | NLOHMANN_JSON_VERSION_MINOR, \ 71 | NLOHMANN_JSON_VERSION_PATCH) 72 | #endif 73 | 74 | // Combine namespace components 75 | #define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b 76 | #define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ 77 | NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) 78 | 79 | #ifndef NLOHMANN_JSON_NAMESPACE 80 | #define NLOHMANN_JSON_NAMESPACE \ 81 | nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ 82 | NLOHMANN_JSON_ABI_TAGS, \ 83 | NLOHMANN_JSON_NAMESPACE_VERSION) 84 | #endif 85 | 86 | #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN 87 | #define NLOHMANN_JSON_NAMESPACE_BEGIN \ 88 | namespace nlohmann \ 89 | { \ 90 | inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ 91 | NLOHMANN_JSON_ABI_TAGS, \ 92 | NLOHMANN_JSON_NAMESPACE_VERSION) \ 93 | { 94 | #endif 95 | 96 | #ifndef NLOHMANN_JSON_NAMESPACE_END 97 | #define NLOHMANN_JSON_NAMESPACE_END \ 98 | } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ 99 | } // namespace nlohmann 100 | #endif 101 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/hash.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // uint8_t 12 | #include // size_t 13 | #include // hash 14 | 15 | #include 16 | #include 17 | 18 | NLOHMANN_JSON_NAMESPACE_BEGIN 19 | namespace detail 20 | { 21 | 22 | // boost::hash_combine 23 | inline std::size_t combine(std::size_t seed, std::size_t h) noexcept 24 | { 25 | seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U); 26 | return seed; 27 | } 28 | 29 | /*! 30 | @brief hash a JSON value 31 | 32 | The hash function tries to rely on std::hash where possible. Furthermore, the 33 | type of the JSON value is taken into account to have different hash values for 34 | null, 0, 0U, and false, etc. 35 | 36 | @tparam BasicJsonType basic_json specialization 37 | @param j JSON value to hash 38 | @return hash value of j 39 | */ 40 | template 41 | std::size_t hash(const BasicJsonType& j) 42 | { 43 | using string_t = typename BasicJsonType::string_t; 44 | using number_integer_t = typename BasicJsonType::number_integer_t; 45 | using number_unsigned_t = typename BasicJsonType::number_unsigned_t; 46 | using number_float_t = typename BasicJsonType::number_float_t; 47 | 48 | const auto type = static_cast(j.type()); 49 | switch (j.type()) 50 | { 51 | case BasicJsonType::value_t::null: 52 | case BasicJsonType::value_t::discarded: 53 | { 54 | return combine(type, 0); 55 | } 56 | 57 | case BasicJsonType::value_t::object: 58 | { 59 | auto seed = combine(type, j.size()); 60 | for (const auto& element : j.items()) 61 | { 62 | const auto h = std::hash {}(element.key()); 63 | seed = combine(seed, h); 64 | seed = combine(seed, hash(element.value())); 65 | } 66 | return seed; 67 | } 68 | 69 | case BasicJsonType::value_t::array: 70 | { 71 | auto seed = combine(type, j.size()); 72 | for (const auto& element : j) 73 | { 74 | seed = combine(seed, hash(element)); 75 | } 76 | return seed; 77 | } 78 | 79 | case BasicJsonType::value_t::string: 80 | { 81 | const auto h = std::hash {}(j.template get_ref()); 82 | return combine(type, h); 83 | } 84 | 85 | case BasicJsonType::value_t::boolean: 86 | { 87 | const auto h = std::hash {}(j.template get()); 88 | return combine(type, h); 89 | } 90 | 91 | case BasicJsonType::value_t::number_integer: 92 | { 93 | const auto h = std::hash {}(j.template get()); 94 | return combine(type, h); 95 | } 96 | 97 | case BasicJsonType::value_t::number_unsigned: 98 | { 99 | const auto h = std::hash {}(j.template get()); 100 | return combine(type, h); 101 | } 102 | 103 | case BasicJsonType::value_t::number_float: 104 | { 105 | const auto h = std::hash {}(j.template get()); 106 | return combine(type, h); 107 | } 108 | 109 | case BasicJsonType::value_t::binary: 110 | { 111 | auto seed = combine(type, j.get_binary().size()); 112 | const auto h = std::hash {}(j.get_binary().has_subtype()); 113 | seed = combine(seed, h); 114 | seed = combine(seed, static_cast(j.get_binary().subtype())); 115 | for (const auto byte : j.get_binary()) 116 | { 117 | seed = combine(seed, std::hash {}(byte)); 118 | } 119 | return seed; 120 | } 121 | 122 | default: // LCOV_EXCL_LINE 123 | JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE 124 | return 0; // LCOV_EXCL_LINE 125 | } 126 | } 127 | 128 | } // namespace detail 129 | NLOHMANN_JSON_NAMESPACE_END 130 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/input/position_t.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // size_t 12 | 13 | #include 14 | 15 | NLOHMANN_JSON_NAMESPACE_BEGIN 16 | namespace detail 17 | { 18 | 19 | /// struct to capture the start position of the current token 20 | struct position_t 21 | { 22 | /// the total number of characters read 23 | std::size_t chars_read_total = 0; 24 | /// the number of characters read in the current line 25 | std::size_t chars_read_current_line = 0; 26 | /// the number of lines read 27 | std::size_t lines_read = 0; 28 | 29 | /// conversion to size_t to preserve SAX interface 30 | constexpr operator size_t() const 31 | { 32 | return chars_read_total; 33 | } 34 | }; 35 | 36 | } // namespace detail 37 | NLOHMANN_JSON_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/iterators/internal_iterator.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | NLOHMANN_JSON_NAMESPACE_BEGIN 15 | namespace detail 16 | { 17 | 18 | /*! 19 | @brief an iterator value 20 | 21 | @note This structure could easily be a union, but MSVC currently does not allow 22 | unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. 23 | */ 24 | template struct internal_iterator 25 | { 26 | /// iterator for JSON objects 27 | typename BasicJsonType::object_t::iterator object_iterator {}; 28 | /// iterator for JSON arrays 29 | typename BasicJsonType::array_t::iterator array_iterator {}; 30 | /// generic iterator for all other types 31 | primitive_iterator_t primitive_iterator {}; 32 | }; 33 | 34 | } // namespace detail 35 | NLOHMANN_JSON_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/iterators/iterator_traits.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // random_access_iterator_tag 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | NLOHMANN_JSON_NAMESPACE_BEGIN 18 | namespace detail 19 | { 20 | 21 | template 22 | struct iterator_types {}; 23 | 24 | template 25 | struct iterator_types < 26 | It, 27 | void_t> 29 | { 30 | using difference_type = typename It::difference_type; 31 | using value_type = typename It::value_type; 32 | using pointer = typename It::pointer; 33 | using reference = typename It::reference; 34 | using iterator_category = typename It::iterator_category; 35 | }; 36 | 37 | // This is required as some compilers implement std::iterator_traits in a way that 38 | // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. 39 | template 40 | struct iterator_traits 41 | { 42 | }; 43 | 44 | template 45 | struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> 46 | : iterator_types 47 | { 48 | }; 49 | 50 | template 51 | struct iterator_traits::value>> 52 | { 53 | using iterator_category = std::random_access_iterator_tag; 54 | using value_type = T; 55 | using difference_type = ptrdiff_t; 56 | using pointer = T*; 57 | using reference = T&; 58 | }; 59 | 60 | } // namespace detail 61 | NLOHMANN_JSON_NAMESPACE_END 62 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/iterators/json_reverse_iterator.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // ptrdiff_t 12 | #include // reverse_iterator 13 | #include // declval 14 | 15 | #include 16 | 17 | NLOHMANN_JSON_NAMESPACE_BEGIN 18 | namespace detail 19 | { 20 | 21 | ////////////////////// 22 | // reverse_iterator // 23 | ////////////////////// 24 | 25 | /*! 26 | @brief a template for a reverse iterator class 27 | 28 | @tparam Base the base iterator type to reverse. Valid types are @ref 29 | iterator (to create @ref reverse_iterator) and @ref const_iterator (to 30 | create @ref const_reverse_iterator). 31 | 32 | @requirement The class satisfies the following concept requirements: 33 | - 34 | [BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator): 35 | The iterator that can be moved can be moved in both directions (i.e. 36 | incremented and decremented). 37 | - [OutputIterator](https://en.cppreference.com/w/cpp/named_req/OutputIterator): 38 | It is possible to write to the pointed-to element (only if @a Base is 39 | @ref iterator). 40 | 41 | @since version 1.0.0 42 | */ 43 | template 44 | class json_reverse_iterator : public std::reverse_iterator 45 | { 46 | public: 47 | using difference_type = std::ptrdiff_t; 48 | /// shortcut to the reverse iterator adapter 49 | using base_iterator = std::reverse_iterator; 50 | /// the reference type for the pointed-to element 51 | using reference = typename Base::reference; 52 | 53 | /// create reverse iterator from iterator 54 | explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept 55 | : base_iterator(it) {} 56 | 57 | /// create reverse iterator from base class 58 | explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} 59 | 60 | /// post-increment (it++) 61 | json_reverse_iterator operator++(int)& // NOLINT(cert-dcl21-cpp) 62 | { 63 | return static_cast(base_iterator::operator++(1)); 64 | } 65 | 66 | /// pre-increment (++it) 67 | json_reverse_iterator& operator++() 68 | { 69 | return static_cast(base_iterator::operator++()); 70 | } 71 | 72 | /// post-decrement (it--) 73 | json_reverse_iterator operator--(int)& // NOLINT(cert-dcl21-cpp) 74 | { 75 | return static_cast(base_iterator::operator--(1)); 76 | } 77 | 78 | /// pre-decrement (--it) 79 | json_reverse_iterator& operator--() 80 | { 81 | return static_cast(base_iterator::operator--()); 82 | } 83 | 84 | /// add to iterator 85 | json_reverse_iterator& operator+=(difference_type i) 86 | { 87 | return static_cast(base_iterator::operator+=(i)); 88 | } 89 | 90 | /// add to iterator 91 | json_reverse_iterator operator+(difference_type i) const 92 | { 93 | return static_cast(base_iterator::operator+(i)); 94 | } 95 | 96 | /// subtract from iterator 97 | json_reverse_iterator operator-(difference_type i) const 98 | { 99 | return static_cast(base_iterator::operator-(i)); 100 | } 101 | 102 | /// return difference 103 | difference_type operator-(const json_reverse_iterator& other) const 104 | { 105 | return base_iterator(*this) - base_iterator(other); 106 | } 107 | 108 | /// access to successor 109 | reference operator[](difference_type n) const 110 | { 111 | return *(this->operator+(n)); 112 | } 113 | 114 | /// return the key of an object iterator 115 | auto key() const -> decltype(std::declval().key()) 116 | { 117 | auto it = --this->base(); 118 | return it.key(); 119 | } 120 | 121 | /// return the value of an iterator 122 | reference value() const 123 | { 124 | auto it = --this->base(); 125 | return it.operator * (); 126 | } 127 | }; 128 | 129 | } // namespace detail 130 | NLOHMANN_JSON_NAMESPACE_END 131 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/iterators/primitive_iterator.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // ptrdiff_t 12 | #include // numeric_limits 13 | 14 | #include 15 | 16 | NLOHMANN_JSON_NAMESPACE_BEGIN 17 | namespace detail 18 | { 19 | 20 | /* 21 | @brief an iterator for primitive JSON types 22 | 23 | This class models an iterator for primitive JSON types (boolean, number, 24 | string). It's only purpose is to allow the iterator/const_iterator classes 25 | to "iterate" over primitive values. Internally, the iterator is modeled by 26 | a `difference_type` variable. Value begin_value (`0`) models the begin, 27 | end_value (`1`) models past the end. 28 | */ 29 | class primitive_iterator_t 30 | { 31 | private: 32 | using difference_type = std::ptrdiff_t; 33 | static constexpr difference_type begin_value = 0; 34 | static constexpr difference_type end_value = begin_value + 1; 35 | 36 | JSON_PRIVATE_UNLESS_TESTED: 37 | /// iterator as signed integer type 38 | difference_type m_it = (std::numeric_limits::min)(); 39 | 40 | public: 41 | constexpr difference_type get_value() const noexcept 42 | { 43 | return m_it; 44 | } 45 | 46 | /// set iterator to a defined beginning 47 | void set_begin() noexcept 48 | { 49 | m_it = begin_value; 50 | } 51 | 52 | /// set iterator to a defined past the end 53 | void set_end() noexcept 54 | { 55 | m_it = end_value; 56 | } 57 | 58 | /// return whether the iterator can be dereferenced 59 | constexpr bool is_begin() const noexcept 60 | { 61 | return m_it == begin_value; 62 | } 63 | 64 | /// return whether the iterator is at end 65 | constexpr bool is_end() const noexcept 66 | { 67 | return m_it == end_value; 68 | } 69 | 70 | friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept 71 | { 72 | return lhs.m_it == rhs.m_it; 73 | } 74 | 75 | friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept 76 | { 77 | return lhs.m_it < rhs.m_it; 78 | } 79 | 80 | primitive_iterator_t operator+(difference_type n) noexcept 81 | { 82 | auto result = *this; 83 | result += n; 84 | return result; 85 | } 86 | 87 | friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept 88 | { 89 | return lhs.m_it - rhs.m_it; 90 | } 91 | 92 | primitive_iterator_t& operator++() noexcept 93 | { 94 | ++m_it; 95 | return *this; 96 | } 97 | 98 | primitive_iterator_t operator++(int)& noexcept // NOLINT(cert-dcl21-cpp) 99 | { 100 | auto result = *this; 101 | ++m_it; 102 | return result; 103 | } 104 | 105 | primitive_iterator_t& operator--() noexcept 106 | { 107 | --m_it; 108 | return *this; 109 | } 110 | 111 | primitive_iterator_t operator--(int)& noexcept // NOLINT(cert-dcl21-cpp) 112 | { 113 | auto result = *this; 114 | --m_it; 115 | return result; 116 | } 117 | 118 | primitive_iterator_t& operator+=(difference_type n) noexcept 119 | { 120 | m_it += n; 121 | return *this; 122 | } 123 | 124 | primitive_iterator_t& operator-=(difference_type n) noexcept 125 | { 126 | m_it -= n; 127 | return *this; 128 | } 129 | }; 130 | 131 | } // namespace detail 132 | NLOHMANN_JSON_NAMESPACE_END 133 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/json_custom_base_class.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // conditional, is_same 4 | 5 | #include 6 | 7 | NLOHMANN_JSON_NAMESPACE_BEGIN 8 | namespace detail 9 | { 10 | 11 | /*! 12 | @brief Default base class of the @ref basic_json class. 13 | 14 | So that the correct implementations of the copyHost / move ctors / assign operators 15 | of @ref basic_json do not require complex case distinctions 16 | (no base class / custom base class used as customization point), 17 | @ref basic_json always has a base class. 18 | By default, this class is used because it is empty and thus has no effect 19 | on the behavior of @ref basic_json. 20 | */ 21 | struct json_default_base {}; 22 | 23 | template 24 | using json_base_class = typename std::conditional < 25 | std::is_same::value, 26 | json_default_base, 27 | T 28 | >::type; 29 | 30 | } // namespace detail 31 | NLOHMANN_JSON_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/json_ref.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | NLOHMANN_JSON_NAMESPACE_BEGIN 18 | namespace detail 19 | { 20 | 21 | template 22 | class json_ref 23 | { 24 | public: 25 | using value_type = BasicJsonType; 26 | 27 | json_ref(value_type&& value) 28 | : owned_value(std::move(value)) 29 | {} 30 | 31 | json_ref(const value_type& value) 32 | : value_ref(&value) 33 | {} 34 | 35 | json_ref(std::initializer_list init) 36 | : owned_value(init) 37 | {} 38 | 39 | template < 40 | class... Args, 41 | enable_if_t::value, int> = 0 > 42 | json_ref(Args && ... args) 43 | : owned_value(std::forward(args)...) 44 | {} 45 | 46 | // class should be movable only 47 | json_ref(json_ref&&) noexcept = default; 48 | json_ref(const json_ref&) = delete; 49 | json_ref& operator=(const json_ref&) = delete; 50 | json_ref& operator=(json_ref&&) = delete; 51 | ~json_ref() = default; 52 | 53 | value_type moved_or_copied() const 54 | { 55 | if (value_ref == nullptr) 56 | { 57 | return std::move(owned_value); 58 | } 59 | return *value_ref; 60 | } 61 | 62 | value_type const& operator*() const 63 | { 64 | return value_ref ? *value_ref : owned_value; 65 | } 66 | 67 | value_type const* operator->() const 68 | { 69 | return &** this; 70 | } 71 | 72 | private: 73 | mutable value_type owned_value = nullptr; 74 | value_type const* value_ref = nullptr; 75 | }; 76 | 77 | } // namespace detail 78 | NLOHMANN_JSON_NAMESPACE_END 79 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/macro_unscope.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | // restore clang diagnostic settings 12 | #if defined(__clang__) 13 | #pragma clang diagnostic pop 14 | #endif 15 | 16 | // clean up 17 | #undef JSON_ASSERT 18 | #undef JSON_INTERNAL_CATCH 19 | #undef JSON_THROW 20 | #undef JSON_PRIVATE_UNLESS_TESTED 21 | #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION 22 | #undef NLOHMANN_BASIC_JSON_TPL 23 | #undef JSON_EXPLICIT 24 | #undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL 25 | #undef JSON_INLINE_VARIABLE 26 | #undef JSON_NO_UNIQUE_ADDRESS 27 | #undef JSON_DISABLE_ENUM_SERIALIZATION 28 | #undef JSON_USE_GLOBAL_UDLS 29 | 30 | #ifndef JSON_TEST_KEEP_MACROS 31 | #undef JSON_CATCH 32 | #undef JSON_TRY 33 | #undef JSON_HAS_CPP_11 34 | #undef JSON_HAS_CPP_14 35 | #undef JSON_HAS_CPP_17 36 | #undef JSON_HAS_CPP_20 37 | #undef JSON_HAS_FILESYSTEM 38 | #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM 39 | #undef JSON_HAS_THREE_WAY_COMPARISON 40 | #undef JSON_HAS_RANGES 41 | #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 42 | #endif 43 | 44 | #include 45 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/meta/call_std/begin.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | 15 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); 16 | 17 | NLOHMANN_JSON_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/meta/call_std/end.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | 15 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); 16 | 17 | NLOHMANN_JSON_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/meta/detected.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | 15 | NLOHMANN_JSON_NAMESPACE_BEGIN 16 | namespace detail 17 | { 18 | 19 | // https://en.cppreference.com/w/cpp/experimental/is_detected 20 | struct nonesuch 21 | { 22 | nonesuch() = delete; 23 | ~nonesuch() = delete; 24 | nonesuch(nonesuch const&) = delete; 25 | nonesuch(nonesuch const&&) = delete; 26 | void operator=(nonesuch const&) = delete; 27 | void operator=(nonesuch&&) = delete; 28 | }; 29 | 30 | template class Op, 33 | class... Args> 34 | struct detector 35 | { 36 | using value_t = std::false_type; 37 | using type = Default; 38 | }; 39 | 40 | template class Op, class... Args> 41 | struct detector>, Op, Args...> 42 | { 43 | using value_t = std::true_type; 44 | using type = Op; 45 | }; 46 | 47 | template class Op, class... Args> 48 | using is_detected = typename detector::value_t; 49 | 50 | template class Op, class... Args> 51 | struct is_detected_lazy : is_detected { }; 52 | 53 | template class Op, class... Args> 54 | using detected_t = typename detector::type; 55 | 56 | template class Op, class... Args> 57 | using detected_or = detector; 58 | 59 | template class Op, class... Args> 60 | using detected_or_t = typename detected_or::type; 61 | 62 | template class Op, class... Args> 63 | using is_detected_exact = std::is_same>; 64 | 65 | template class Op, class... Args> 66 | using is_detected_convertible = 67 | std::is_convertible, To>; 68 | 69 | } // namespace detail 70 | NLOHMANN_JSON_NAMESPACE_END 71 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/meta/identity_tag.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | // dispatching helper struct 18 | template struct identity_tag {}; 19 | 20 | } // namespace detail 21 | NLOHMANN_JSON_NAMESPACE_END 22 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/meta/std_fs.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #if JSON_HAS_EXPERIMENTAL_FILESYSTEM 14 | #include 15 | NLOHMANN_JSON_NAMESPACE_BEGIN 16 | namespace detail 17 | { 18 | namespace std_fs = std::experimental::filesystem; 19 | } // namespace detail 20 | NLOHMANN_JSON_NAMESPACE_END 21 | #elif JSON_HAS_FILESYSTEM 22 | #include 23 | NLOHMANN_JSON_NAMESPACE_BEGIN 24 | namespace detail 25 | { 26 | namespace std_fs = std::filesystem; 27 | } // namespace detail 28 | NLOHMANN_JSON_NAMESPACE_END 29 | #endif 30 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/meta/void_t.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | template struct make_void 18 | { 19 | using type = void; 20 | }; 21 | template using void_t = typename make_void::type; 22 | 23 | } // namespace detail 24 | NLOHMANN_JSON_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/detail/string_escape.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | /*! 18 | @brief replace all occurrences of a substring by another string 19 | 20 | @param[in,out] s the string to manipulate; changed so that all 21 | occurrences of @a f are replaced with @a t 22 | @param[in] f the substring to replace with @a t 23 | @param[in] t the string to replace @a f 24 | 25 | @pre The search string @a f must not be empty. **This precondition is 26 | enforced with an assertion.** 27 | 28 | @since version 2.0.0 29 | */ 30 | template 31 | inline void replace_substring(StringType& s, const StringType& f, 32 | const StringType& t) 33 | { 34 | JSON_ASSERT(!f.empty()); 35 | for (auto pos = s.find(f); // find first occurrence of f 36 | pos != StringType::npos; // make sure f was found 37 | s.replace(pos, f.size(), t), // replace with t, and 38 | pos = s.find(f, pos + t.size())) // find next occurrence of f 39 | {} 40 | } 41 | 42 | /*! 43 | * @brief string escaping as described in RFC 6901 (Sect. 4) 44 | * @param[in] s string to escape 45 | * @return escaped string 46 | * 47 | * Note the order of escaping "~" to "~0" and "/" to "~1" is important. 48 | */ 49 | template 50 | inline StringType escape(StringType s) 51 | { 52 | replace_substring(s, StringType{"~"}, StringType{"~0"}); 53 | replace_substring(s, StringType{"/"}, StringType{"~1"}); 54 | return s; 55 | } 56 | 57 | /*! 58 | * @brief string unescaping as described in RFC 6901 (Sect. 4) 59 | * @param[in] s string to unescape 60 | * @return unescaped string 61 | * 62 | * Note the order of escaping "~1" to "/" and "~0" to "~" is important. 63 | */ 64 | template 65 | static void unescape(StringType& s) 66 | { 67 | replace_substring(s, StringType{"~1"}, StringType{"/"}); 68 | replace_substring(s, StringType{"~0"}, StringType{"~"}); 69 | } 70 | 71 | } // namespace detail 72 | NLOHMANN_JSON_NAMESPACE_END 73 | -------------------------------------------------------------------------------- /netchem/include/json/include/nlohmann/json_fwd.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.2 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ 10 | #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ 11 | 12 | #include // int64_t, uint64_t 13 | #include // map 14 | #include // allocator 15 | #include // string 16 | #include // vector 17 | 18 | #include 19 | 20 | /*! 21 | @brief namespace for Niels Lohmann 22 | @see https://github.com/nlohmann 23 | @since version 1.0.0 24 | */ 25 | NLOHMANN_JSON_NAMESPACE_BEGIN 26 | 27 | /*! 28 | @brief default JSONSerializer template argument 29 | 30 | This serializer ignores the template arguments and uses ADL 31 | ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) 32 | for serialization. 33 | */ 34 | template 35 | struct adl_serializer; 36 | 37 | /// a class to store JSON values 38 | /// @sa https://json.nlohmann.me/api/basic_json/ 39 | template class ObjectType = 40 | std::map, 41 | template class ArrayType = std::vector, 42 | class StringType = std::string, class BooleanType = bool, 43 | class NumberIntegerType = std::int64_t, 44 | class NumberUnsignedType = std::uint64_t, 45 | class NumberFloatType = double, 46 | template class AllocatorType = std::allocator, 47 | template class JSONSerializer = 48 | adl_serializer, 49 | class BinaryType = std::vector, // cppcheck-suppress syntaxError 50 | class CustomBaseClass = void> 51 | class basic_json; 52 | 53 | /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document 54 | /// @sa https://json.nlohmann.me/api/json_pointer/ 55 | template 56 | class json_pointer; 57 | 58 | /*! 59 | @brief default specialization 60 | @sa https://json.nlohmann.me/api/json/ 61 | */ 62 | using json = basic_json<>; 63 | 64 | /// @brief a minimal map-like container that preserves insertion order 65 | /// @sa https://json.nlohmann.me/api/ordered_map/ 66 | template 67 | struct ordered_map; 68 | 69 | /// @brief specialization that maintains the insertion order of object keys 70 | /// @sa https://json.nlohmann.me/api/ordered_json/ 71 | using ordered_json = basic_json; 72 | 73 | NLOHMANN_JSON_NAMESPACE_END 74 | 75 | #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ 76 | -------------------------------------------------------------------------------- /netchem/include/json/tools/amalgamate/CHANGES.md: -------------------------------------------------------------------------------- 1 | The following changes have been made to the code with respect to : 2 | 3 | - Resolved inspection results from PyCharm: 4 | - replaced tabs with spaces 5 | - added encoding annotation 6 | - reindented file to remove trailing whitespaces 7 | - unused import `sys` 8 | - membership check 9 | - made function from `_is_within` 10 | - removed unused variable `actual_path` 11 | -------------------------------------------------------------------------------- /netchem/include/json/tools/amalgamate/README.md: -------------------------------------------------------------------------------- 1 | 2 | # amalgamate.py - Amalgamate C source and header files 3 | 4 | Origin: https://bitbucket.org/erikedlund/amalgamate 5 | 6 | Mirror: https://github.com/edlund/amalgamate 7 | 8 | `amalgamate.py` aims to make it easy to use SQLite-style C source and header 9 | amalgamation in projects. 10 | 11 | For more information, please refer to: http://sqlite.org/amalgamation.html 12 | 13 | ## Here be dragons 14 | 15 | `amalgamate.py` is quite dumb, it only knows the bare minimum about C code 16 | required in order to be able to handle trivial include directives. It can 17 | produce weird results for unexpected code. 18 | 19 | Things to be aware of: 20 | 21 | `amalgamate.py` will not handle complex include directives correctly: 22 | 23 | #define HEADER_PATH "path/to/header.h" 24 | #include HEADER_PATH 25 | 26 | In the above example, `path/to/header.h` will not be included in the 27 | amalgamation (HEADER_PATH is never expanded). 28 | 29 | `amalgamate.py` makes the assumption that each source and header file which 30 | is not empty will end in a new-line character, which is not immediately 31 | preceded by a backslash character (see 5.1.1.2p1.2 of ISO C99). 32 | 33 | `amalgamate.py` should be usable with C++ code, but raw string literals from 34 | C++11 will definitely cause problems: 35 | 36 | R"delimiter(Terrible raw \ data " #include )delimiter" 37 | R"delimiter(Terrible raw \ data " escaping)delimiter" 38 | 39 | In the examples above, `amalgamate.py` will stop parsing the raw string literal 40 | when it encounters the first quotation mark, which will produce unexpected 41 | results. 42 | 43 | ## Installing amalgamate.py 44 | 45 | Python v.2.7.0 or higher is required. 46 | 47 | `amalgamate.py` can be tested and installed using the following commands: 48 | 49 | ./test.sh && sudo -k cp ./amalgamate.py /usr/local/bin/ 50 | 51 | ## Using amalgamate.py 52 | 53 | amalgamate.py [-v] -c path/to/config.json -s path/to/source/dir \ 54 | [-p path/to/prologue.(c|h)] 55 | 56 | * The `-c, --config` option should specify the path to a JSON config file which 57 | lists the source files, include paths and where to write the resulting 58 | amalgamation. Have a look at `test/source.c.json` and `test/include.h.json` 59 | to see two examples. 60 | 61 | * The `-s, --source` option should specify the path to the source directory. 62 | This is useful for supporting separate source and build directories. 63 | 64 | * The `-p, --prologue` option should specify the path to a file which will be 65 | added to the beginning of the amalgamation. It is optional. 66 | 67 | -------------------------------------------------------------------------------- /netchem/include/json/tools/amalgamate/config_json.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "JSON for Modern C++", 3 | "target": "single_include/nlohmann/json.hpp", 4 | "sources": [ 5 | "include/nlohmann/json.hpp" 6 | ], 7 | "include_paths": ["include"] 8 | } 9 | -------------------------------------------------------------------------------- /netchem/include/json/tools/amalgamate/config_json_fwd.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "JSON for Modern C++", 3 | "target": "single_include/nlohmann/json_fwd.hpp", 4 | "sources": [ 5 | "include/nlohmann/json_fwd.hpp" 6 | ], 7 | "include_paths": ["include"] 8 | } 9 | -------------------------------------------------------------------------------- /netchem/include/json/tools/gdb_pretty_printer/README.md: -------------------------------------------------------------------------------- 1 | # GDB Pretty Printer 2 | 3 | File [nlohmann-json.py](nlohmann-json.py) contains a pretty printer for GDB for JSON values of this library. It was originally published as [Gist](https://gist.github.com/ssbssa/60da5339c6e6036b2afce17de06050ea#file-nlohmann-json-py) by [Hannes Domani](https://github.com/ssbssa). 4 | 5 | ## How to use 6 | 7 | - Add line 8 | 9 | ``` 10 | source /path/to/nlohmann-json.py 11 | ``` 12 | 13 | to `~/.gdbinit`. Note you must replace `/path/to` with whatever path you stored file `nlohmann-json.py`. 14 | - In GDB, debug as usual. When you want to pretty-print a JSON value `var`, type 15 | 16 | ``` 17 | p -pretty on -array on -- var 18 | ``` 19 | 20 | The result should look like 21 | 22 | ``` 23 | $1 = std::map with 5 elements = { 24 | ["Baptiste"] = std::map with 1 element = { 25 | ["first"] = "second" 26 | }, 27 | ["Emmanuel"] = std::vector of length 3, capacity 3 = { 28 | 3, 29 | "25", 30 | 0.5 31 | }, 32 | ["Jean"] = 0.7, 33 | ["Zorg"] = std::map with 8 elements = { 34 | ["array"] = std::vector of length 3, capacity 3 = { 35 | 1, 36 | 0, 37 | 2 38 | }, 39 | ["awesome_str"] = "bleh", 40 | ["bool"] = true, 41 | ["flex"] = 0.2, 42 | ["float"] = 5.22, 43 | ["int"] = 5, 44 | ["nested"] = std::map with 1 element = { 45 | ["bar"] = "barz" 46 | }, 47 | ["trap "] = "you fell" 48 | }, 49 | ["empty"] = nlohmann::detail::value_t::null 50 | } 51 | ``` 52 | 53 | Requires Python 3.9+. Last tested with GDB 12.1. 54 | See [#1952](https://github.com/nlohmann/json/issues/1952) for more information. Please post questions there. 55 | 56 | ## Copyright 57 | 58 | MIT License 59 | 60 | Copyright (C) 2020 [Hannes Domani](https://github.com/ssbssa) 61 | 62 | Permission is hereby granted, free of charge, to any person obtaining a copyHost 63 | of this software and associated documentation files (the "Software"), to deal 64 | in the Software without restriction, including without limitation the rights 65 | to use, copyHost, modify, merge, publish, distribute, sublicense, and/or sell 66 | copies of the Software, and to permit persons to whom the Software is 67 | furnished to do so, subject to the following conditions: 68 | 69 | The above copyright notice and this permission notice shall be included in all 70 | copies or substantial portions of the Software. 71 | 72 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 73 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 74 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 75 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 76 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 77 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 78 | SOFTWARE. 79 | -------------------------------------------------------------------------------- /netchem/include/json/tools/gdb_pretty_printer/nlohmann-json.py: -------------------------------------------------------------------------------- 1 | import gdb 2 | import re 3 | 4 | ns_pattern = re.compile(r'nlohmann(::json_abi(?P\w*)(_v(?P\d+)_(?P\d+)_(?P\d+))?)?::(?P.+)') 5 | class JsonValuePrinter: 6 | "Print a json-value" 7 | 8 | def __init__(self, val): 9 | self.val = val 10 | 11 | def to_string(self): 12 | if self.val.type.strip_typedefs().code == gdb.TYPE_CODE_FLT: 13 | return ("%.6f" % float(self.val)).rstrip("0") 14 | return self.val 15 | 16 | def json_lookup_function(val): 17 | m = ns_pattern.fullmatch(val.type.strip_typedefs().name) 18 | name = m.group('name') 19 | if name and name.startswith('basic_json<') and name.endswith('>'): 20 | m = ns_pattern.fullmatch(str(val['m_type'])) 21 | t = m.group('name') 22 | if t and t.startswith('detail::value_t::'): 23 | try: 24 | union_val = val['m_value'][t.removeprefix('detail::value_t::')] 25 | if union_val.type.code == gdb.TYPE_CODE_PTR: 26 | return gdb.default_visualizer(union_val.dereference()) 27 | else: 28 | return JsonValuePrinter(union_val) 29 | except Exception: 30 | return JsonValuePrinter(val['m_type']) 31 | 32 | gdb.pretty_printers.append(json_lookup_function) 33 | -------------------------------------------------------------------------------- /netchem/include/json/tools/generate_natvis/README.md: -------------------------------------------------------------------------------- 1 | generate_natvis.py 2 | ================== 3 | 4 | Generate the Natvis debugger visualization file for all supported namespace combinations. 5 | 6 | ## Usage 7 | 8 | ``` 9 | ./generate_natvis.py --version X.Y.Z output_directory/ 10 | ``` 11 | -------------------------------------------------------------------------------- /netchem/include/json/tools/generate_natvis/generate_natvis.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import itertools 5 | import jinja2 6 | import os 7 | import re 8 | import sys 9 | 10 | def semver(v): 11 | if not re.fullmatch(r'\d+\.\d+\.\d+', v): 12 | raise ValueError 13 | return v 14 | 15 | if __name__ == '__main__': 16 | parser = argparse.ArgumentParser() 17 | parser.add_argument('--version', required=True, type=semver, help='Library version number') 18 | parser.add_argument('output', help='Output directory for nlohmann_json.natvis') 19 | args = parser.parse_args() 20 | 21 | namespaces = ['nlohmann'] 22 | abi_prefix = 'json_abi' 23 | abi_tags = ['_diag', '_ldvcmp'] 24 | version = '_v' + args.version.replace('.', '_') 25 | inline_namespaces = [] 26 | 27 | # generate all combinations of inline namespace names 28 | for n in range(0, len(abi_tags) + 1): 29 | for tags in itertools.combinations(abi_tags, n): 30 | ns = abi_prefix + ''.join(tags) 31 | inline_namespaces += [ns, ns + version] 32 | 33 | namespaces += [f'{namespaces[0]}::{ns}' for ns in inline_namespaces] 34 | 35 | env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]), autoescape=True, trim_blocks=True, 36 | lstrip_blocks=True, keep_trailing_newline=True) 37 | template = env.get_template('nlohmann_json.natvis.j2') 38 | natvis = template.render(namespaces=namespaces) 39 | 40 | with open(os.path.join(args.output, 'nlohmann_json.natvis'), 'w') as f: 41 | f.write(natvis) 42 | -------------------------------------------------------------------------------- /netchem/include/json/tools/generate_natvis/nlohmann_json.natvis.j2: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {% for ns in namespaces %} 7 | 8 | 9 | null 10 | {*(m_value.object)} 11 | {*(m_value.array)} 12 | {*(m_value.string)} 13 | {m_value.boolean} 14 | {m_value.number_integer} 15 | {m_value.number_unsigned} 16 | {m_value.number_float} 17 | discarded 18 | 19 | 20 | *(m_value.object),view(simple) 21 | 22 | 23 | *(m_value.array),view(simple) 24 | 25 | 26 | 27 | 28 | 30 | 31 | {second} 32 | 33 | second 34 | 35 | 36 | 37 | {% endfor %} 38 | 39 | -------------------------------------------------------------------------------- /netchem/include/json/tools/macro_builder/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void build_code(int max_args) 8 | { 9 | stringstream ss; 10 | ss << "#define NLOHMANN_JSON_EXPAND( x ) x" << endl; 11 | ss << "#define NLOHMANN_JSON_GET_MACRO("; 12 | for (int i = 0 ; i < max_args ; i++) 13 | ss << "_" << i + 1 << ", "; 14 | ss << "NAME,...) NAME" << endl; 15 | 16 | ss << "#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\" << endl; 17 | for (int i = max_args ; i > 1 ; i--) 18 | ss << "NLOHMANN_JSON_PASTE" << i << ", \\" << endl; 19 | ss << "NLOHMANN_JSON_PASTE1)(__VA_ARGS__))" << endl; 20 | 21 | ss << "#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)" << endl; 22 | for (int i = 3 ; i <= max_args ; i++) 23 | { 24 | ss << "#define NLOHMANN_JSON_PASTE" << i << "(func, "; 25 | for (int j = 1 ; j < i -1 ; j++) 26 | ss << "v" << j << ", "; 27 | ss << "v" << i-1 << ") NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE" << i-1 << "(func, "; 28 | for (int j = 2 ; j < i-1 ; j++) 29 | ss << "v" << j << ", "; 30 | ss << "v" << i-1 << ")" << endl; 31 | } 32 | 33 | cout << ss.str() << endl; 34 | } 35 | 36 | int main(int argc, char** argv) 37 | { 38 | int max_args = 64; 39 | build_code(max_args); 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /netchem/include/json/tools/serve_header/README.md: -------------------------------------------------------------------------------- 1 | serve_header.py 2 | =============== 3 | 4 | Serves the `single_include/nlohmann/json.hpp` header file over HTTP(S). 5 | 6 | The header file is automatically amalgamated on demand. 7 | 8 | ![serve_header.py demo](demo.png) 9 | 10 | ## Prerequisites 11 | 12 | 1. Make sure these Python packages are installed. 13 | ``` 14 | PyYAML 15 | watchdog 16 | ``` 17 | (see `tools/serve_header/requirements.txt`) 18 | 19 | 2. To serve the header over HTTPS (which is required by Compiler Explorer at this time), a certificate is needed. 20 | The recommended method for creating a locally-trusted certificate is to use [`mkcert`](https://github.com/FiloSottile/mkcert). 21 | - Install the `mkcert` certificate authority into your trust store(s): 22 | ``` 23 | $ mkcert -install 24 | ``` 25 | - Create a certificate for `localhost`: 26 | ``` 27 | $ mkcert localhost 28 | ``` 29 | The command will create two files, `localhost.pem` and `localhost-key.pem`, in the current working directory. It is recommended to create them in the top level or project root directory. 30 | 31 | ## Usage 32 | 33 | `serve_header.py` has a built-in default configuration that will serve the `single_include/nlohmann/json.hpp` header file relative to the top level or project root directory it is homed in. 34 | The built-in configuration expects the certificate `localhost.pem` and the private key `localhost-key.pem`to be located in the top level or project root directory. 35 | 36 | To start serving the `json.hpp` header file at `https://localhost:8443/json.hpp`, run this command from the top level or project root directory: 37 | ``` 38 | $ make serve_header 39 | ``` 40 | 41 | Open [Compiler Explorer](https://godbolt.org/) and try it out: 42 | ```cpp 43 | #include 44 | using namespace nlohmann; 45 | 46 | #include 47 | 48 | int main() { 49 | // these macros are dynamically injected into the header file 50 | std::cout << JSON_BUILD_TIME << " (" << JSON_BUILD_COUNT << ")\n"; 51 | 52 | return 0; 53 | } 54 | ``` 55 | 56 | > `serve_header.py` dynamically injects the macros `JSON_BUILD_COUNT` and `JSON_BUILD_TIME` into the served header file. By comparing build count or time output from the compiled program with the output from `serve_header.py`, one can be reasonably sure the compiled code uses the expected revision of the header file. 57 | 58 | ## Configuration 59 | 60 | `serve_header.py` will try to read a configuration file `serve_header.yml` in the top level or project root directory, and will fall back on built-in defaults if the file cannot be read. 61 | An annotated example configuration can be found in `tools/serve_header/serve_header.yml.example`. 62 | 63 | ## Serving `json.hpp` from multiple project directory instances or working trees 64 | 65 | `serve_header.py` was designed with the goal of supporting multiple project roots or working trees at the same time. 66 | The recommended directory structure is shown below but `serve_header.py` can work with other structures as well, including a nested hierarchy. 67 | ``` 68 | json/ ⮜ the parent or web server root directoy 69 | ├── develop/ ⮜ the main git checkout 70 | │ └── ... 71 | ├── feature1/ 72 | │ └── ... any number of additional 73 | ├── feature2/ ⮜ working trees (e.g., created 74 | │ └── ... with git worktree) 75 | └── feature3/ 76 | └── ... 77 | ``` 78 | 79 | To serve the header of each working tree at `https://localhost:8443//json.hpp`, a configuration file is needed. 80 | 1. Create the file `serve_header.yml` in the top level or project root directory of any working tree: 81 | ```yaml 82 | root: .. 83 | ``` 84 | By shifting the web server root directory up one level, the `single_include/nlohmann/json.hpp` header files relative to each sibling directory or working tree will be served. 85 | 86 | 2. Start `serve_header.py` by running this command from the same top level or project root directory the configuration file is located in: 87 | ``` 88 | $ make serve_header 89 | ``` 90 | 91 | `serve_header.py` will automatically detect the addition or removal of working trees anywhere within the configured web server root directory. 92 | -------------------------------------------------------------------------------- /netchem/include/json/tools/serve_header/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/include/json/tools/serve_header/demo.png -------------------------------------------------------------------------------- /netchem/include/json/tools/serve_header/requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==6.0 2 | watchdog==2.1.7 3 | -------------------------------------------------------------------------------- /netchem/include/json/tools/serve_header/serve_header.yml.example: -------------------------------------------------------------------------------- 1 | # all paths are relative to the project root 2 | 3 | # the root directory for the web server 4 | # root: . 5 | 6 | # configure SSL 7 | # https: 8 | # enabled: true 9 | # these filenames are listed in .gitignore 10 | # cert_file: localhost.pem 11 | # key_file: localhost-key.pem 12 | 13 | # address and port for the server to listen on 14 | # bind: null 15 | # port: 8443 16 | -------------------------------------------------------------------------------- /netchem/include/node.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file node.h 3 | * \brief Defines the Node class representing a node in a graph. 4 | */ 5 | 6 | #ifndef CURVA_NODE_H 7 | #define CURVA_NODE_H 8 | 9 | #include "atoms.h" 10 | #include "cuarray.h" 11 | 12 | /** 13 | * \class Node 14 | * \brief Represents a node in a graph. 15 | */ 16 | class Node { 17 | public: 18 | /** 19 | * \brief Default constructor for Node. 20 | */ 21 | Node(); 22 | 23 | /** 24 | * \brief Destructor for Node. 25 | */ 26 | ~Node(); 27 | 28 | /** 29 | * \brief Constructor for Node with specified number of frames and index. 30 | * 31 | * \param numFrames Number of frames. 32 | * \param index_ Index of the node. 33 | */ 34 | Node(unsigned int numFrames, unsigned int index_); 35 | 36 | /** 37 | * \brief Add an Atom to the Node. 38 | * 39 | * Adds the specified Atom to the Node along with its corresponding coordinates. 40 | * 41 | * \param atom Pointer to the Atom object. 42 | * \param coordinates Pointer to the coordinates array. 43 | * \param nodeCoordinates Pointer to the node coordinates array. 44 | */ 45 | void addAtom(Atom* atom, CuArray* coordinates, CuArray* nodeCoordinates); 46 | 47 | /** 48 | * \brief Get the tag of the Node. 49 | * 50 | * Returns the tag of the Node, which represents its unique identifier. 51 | * 52 | * \return The tag of the Node. 53 | * 54 | * @PythonExample{NetChem_Node_tag.py} 55 | */ 56 | std::string tag(); 57 | 58 | /** 59 | * \brief Get the number of Atoms in the Node. 60 | * 61 | * Returns the number of Atoms contained in the Node. 62 | * 63 | * \return The number of Atoms in the Node. 64 | * 65 | * @PythonExample{NetChem_Node_numAtoms.py} 66 | */ 67 | unsigned int numAtoms() const; 68 | 69 | /** 70 | * \brief Get the index of the Node. 71 | * 72 | * Returns the index of the Node. 73 | * 74 | * \return The index of the Node. 75 | * 76 | * @PythonExample{NetChem_Node_index.py} 77 | */ 78 | unsigned int index() const; 79 | 80 | /** 81 | * \brief Get the total mass of the Node. 82 | * 83 | * Returns the total mass of the Node, calculated as the sum of the masses 84 | * of all the Atoms in the Node. 85 | * 86 | * \return The total mass of the Node. 87 | * 88 | * @PythonExample{NetChem_Node_totalMass.py} 89 | */ 90 | float totalMass() const; 91 | 92 | /** 93 | * \brief Get the hash value of the Node. 94 | * 95 | * Returns the hash value of the Node, which is a unique identifier 96 | * based on its tag and index. 97 | * 98 | * \return The hash value of the Node. 99 | */ 100 | unsigned int hash() const; 101 | 102 | /** 103 | * \brief Get a vector of pointers to the Atoms in the Node. 104 | * 105 | * Returns a vector of pointers to the Atoms contained in the Node. 106 | * 107 | * \return A vector of pointers to the Atoms in the Node. 108 | * 109 | * @PythonExample{NetChem_Node_atoms.py} 110 | */ 111 | std::vector atoms() const; 112 | 113 | private: 114 | friend nlohmann::adl_serializer; 115 | 116 | friend class Network; 117 | 118 | unsigned int _numAtoms; // Number of Atoms in the Node. 119 | std::vector atomIndices_; // Indices of the Atoms in the Node. 120 | unsigned int _index; // Index of the Node. 121 | float _totalMass; // Total mass of the Node. 122 | std::string _tag; // Tag of the Node. 123 | std::vector atoms_; // Pointers to the Atoms in the Node. 124 | unsigned int _hash = 0; // Hash value of the Node. 125 | unsigned int _numFrames; // Number of frames. 126 | }; 127 | 128 | #endif // CURVA_NODE_H 129 | -------------------------------------------------------------------------------- /netchem/include/serializer.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------* 2 | * CuRva * 3 | *--------------------------------------------------------------------* 4 | * This is part of the GPU-accelerated, random variable analysis * 5 | * library CuRva. * 6 | * Copyright (C) 2022 Andy Stokely * 7 | * * 8 | * This program is free software: you can redistribute it * 9 | * and/or modify it under the terms of the GNU General Public License * 10 | * as published by the Free Software Foundation, either version 3 of * 11 | * the License, or (at your option) any later version. * 12 | * * 13 | * This program is distributed in the hope that it will be useful, * 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 | * GNU General Public License for more details. * 17 | * * 18 | * You should have received a copy of the GNU General Public License * 19 | * along with this program. * 20 | * If not, see * 21 | * -------------------------------------------------------------------*/ 22 | 23 | #ifndef CURVA_SERIALIZER_H 24 | #define CURVA_SERIALIZER_H 25 | 26 | #include "json/include/nlohmann/json.hpp" 27 | #include "atom.h" 28 | #include "node.h" 29 | #include "network.h" 30 | 31 | namespace nlohmann { 32 | 33 | 34 | template<> 35 | struct adl_serializer { 36 | #pragma clang diagnostic push 37 | #pragma ide diagnostic ignored "NotImplementedFunctions" 38 | 39 | static Atom *from_json( 40 | const json &j 41 | ); 42 | 43 | #pragma clang diagnostic pop 44 | 45 | #pragma clang diagnostic push 46 | #pragma ide diagnostic ignored "NotImplementedFunctions" 47 | 48 | static void to_json( 49 | json &j, 50 | Atom *atom 51 | ); 52 | }; 53 | 54 | template<> 55 | struct adl_serializer { 56 | #pragma clang diagnostic push 57 | #pragma ide diagnostic ignored "NotImplementedFunctions" 58 | 59 | static Atoms *from_json( 60 | const json &j 61 | ); 62 | 63 | #pragma clang diagnostic pop 64 | 65 | #pragma clang diagnostic push 66 | #pragma ide diagnostic ignored "NotImplementedFunctions" 67 | 68 | static void to_json( 69 | json &j, 70 | Atoms *atoms 71 | ); 72 | }; 73 | 74 | template<> 75 | struct adl_serializer { 76 | 77 | 78 | #pragma clang diagnostic push 79 | #pragma ide diagnostic ignored "NotImplementedFunctions" 80 | 81 | static void to_json( 82 | json &j, 83 | Node *node 84 | ); 85 | 86 | static Node *from_json( 87 | const json &j 88 | ); 89 | }; 90 | template<> 91 | struct adl_serializer { 92 | 93 | 94 | #pragma clang diagnostic push 95 | #pragma ide diagnostic ignored "NotImplementedFunctions" 96 | 97 | static void to_json( 98 | json &j, 99 | Network *graph 100 | ); 101 | 102 | static Network *from_json( 103 | const json &j 104 | ); 105 | }; 106 | 107 | } 108 | #endif //CURVA_SERIALIZER_H 109 | 110 | -------------------------------------------------------------------------------- /netchem/python/netchem/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tempfile 3 | import shutil 4 | from dataclasses import asdict, dataclass 5 | from pathlib import Path 6 | import tarfile 7 | from importlib import resources 8 | from typing import ItemsView, KeysView, ValuesView, Mapping, Union 9 | 10 | from .netchem import Atom 11 | from .netchem import Atoms 12 | from .netchem import Node 13 | from .netchem import Network 14 | from .netchem import Network as Graph 15 | 16 | 17 | @dataclass 18 | class NetworkSettings(Mapping): 19 | trajectoryFile: Union[str, Path] 20 | topologyFile: Union[str, Path] 21 | firstFrame: int 22 | lastFrame: int 23 | stride: int = 1 24 | 25 | def __post_init__(self): 26 | self.trajectoryFile = str(self.trajectoryFile) 27 | self.topologyFile = str(self.topologyFile) 28 | 29 | def __iter__(self): 30 | return iter(asdict(self)) 31 | 32 | def __len__(self): 33 | return len(self.__slots__) 34 | 35 | def __getitem__(self, key: str): 36 | return getattr(self, key) 37 | 38 | def items(self) -> ItemsView: 39 | return ItemsView(self) 40 | 41 | def keys(self) -> KeysView: 42 | return KeysView(self) 43 | 44 | def values(self) -> ValuesView: 45 | return ValuesView(self) 46 | 47 | 48 | def data_files(key: str) -> tuple: 49 | temp_dir = tempfile.mkdtemp() 50 | data_files_dict = dict( 51 | test="test.tar.gz", 52 | pyro="pyro.tar.gz", 53 | ) 54 | cwd = Path.cwd() 55 | with resources.path("netchem.data", data_files_dict[key]) as tarball_file: 56 | os.chdir(tarball_file.parent) 57 | tarball = tarfile.open(tarball_file) 58 | tarball_members = [tarball_file.parent / f.name for f in tarball.getmembers()] 59 | temp_files = [Path(temp_dir) / f.name for f in tarball_members] 60 | tarball.extractall() 61 | tarball.close() 62 | for tarball_member, temp_file in zip(tarball_members, temp_files): 63 | shutil.copy(tarball_member, temp_file) 64 | tarball_member.unlink() 65 | os.chdir(cwd) 66 | return ( 67 | Path(temp_dir) / f"{key}.dcd", 68 | Path(temp_dir) / f"{key}.pdb" 69 | ) 70 | -------------------------------------------------------------------------------- /netchem/python/netchem/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/python/netchem/data/__init__.py -------------------------------------------------------------------------------- /netchem/python/netchem/data/pyro.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/python/netchem/data/pyro.tar.gz -------------------------------------------------------------------------------- /netchem/python/netchem/data/test.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/python/netchem/data/test.tar.gz -------------------------------------------------------------------------------- /netchem/python/setup.py: -------------------------------------------------------------------------------- 1 | 2 | from setuptools import find_packages 3 | from setuptools import setup 4 | import os 5 | 6 | path = os.path.relpath(os.path.dirname(__file__)) 7 | 8 | setup( 9 | author='Andy Stokely', 10 | email='amstokely@ucsd.edu', 11 | name='netchem', 12 | install_requires=[], 13 | platforms=['Linux', 14 | 'Unix', ], 15 | python_requires="<=3.9", 16 | py_modules=[ 17 | path + "/netchem/netchem", 18 | path + "/netchem/data", 19 | ], 20 | packages=find_packages() + [''], 21 | zip_safe=False, 22 | package_data={ 23 | '': [ 24 | path + '/netchem/_python_netchem.so', 25 | path + '/netchem/data/test.tar.gz', 26 | path + '/netchem/data/pyro.tar.gz', 27 | ], 28 | }, 29 | ) 30 | -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_chainId.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_chainId.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_element.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_element.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_index.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_index.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_mass.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_mass.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_name.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_name.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_occupancy.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_occupancy.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_residueId.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_residueId.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_residueName.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_residueName.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_segmentId.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_segmentId.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_serial.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_serial.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_tag.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_tag.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atom_temperatureFactor.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atom_temperatureFactor.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atoms_at.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atoms_at.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atoms_atoms.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atoms_atoms.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Atoms_numAtoms.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Atoms_numAtoms.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_atoms.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_atoms.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_init.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_init.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_load.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_load.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_nodeCoordinates1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_nodeCoordinates1.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_nodeCoordinates2.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_nodeCoordinates2.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_nodeFromAtomIndex.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_nodeFromAtomIndex.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_nodes.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_nodes.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_numFrames.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_numFrames.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_numNodes.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_numNodes.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Network_save.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Network_save.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Node_atoms.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Node_atoms.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Node_index.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Node_index.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Node_numAtoms.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Node_numAtoms.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Node_tag.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Node_tag.py -------------------------------------------------------------------------------- /netchem/samples/python/NetChem_Node_totalMass.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/netchem/samples/python/NetChem_Node_totalMass.py -------------------------------------------------------------------------------- /netchem/scratch/stride_scratch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "network.h" 4 | #include "cuarray.h" 5 | 6 | int main() { 7 | std::string dcdFile = 8 | "/home/astokely/CLionProjects/netsci/tests/netchem/cpp" 9 | "/data/test.dcd"; 10 | std::string pdbFile = "/home/astokely/CLionProjects/netsci/tests/netchem/cpp" 11 | "/data/test.pdb"; 12 | int firstFrame = 0; 13 | int lastFrame = 9; 14 | int stride = 3; 15 | auto network3 = new Network(); 16 | auto network1 = new Network(); 17 | network3->init( 18 | dcdFile, 19 | pdbFile, 20 | firstFrame, 21 | lastFrame, 22 | stride 23 | ); 24 | network1->init( 25 | dcdFile, 26 | pdbFile, 27 | firstFrame, 28 | lastFrame, 29 | 1 30 | ); 31 | auto nodeCoordinates3 = network3->nodeCoordinates(); 32 | auto nodeCoordinates1 = network1->nodeCoordinates(); 33 | for (int i = 0; i < 290; i++) { 34 | for (int j = 0; j < network3->numFrames(); j++) { 35 | std::cout << nodeCoordinates3->get(i, j) << " "; 36 | std::cout << nodeCoordinates3->get(i, j + network3->numFrames()) << 37 | " "; 38 | std::cout << nodeCoordinates3->get(i, j + 2*network3->numFrames()) << 39 | " "; 40 | std::cout << j * stride << std::endl; 41 | } 42 | std::cout << std::endl; 43 | for (int j = 0; j < network1->numFrames(); j++) { 44 | std::cout << nodeCoordinates1->get(i, j) << " "; 45 | std::cout << nodeCoordinates1->get(i, j + network1->numFrames()) << 46 | " "; 47 | std::cout << nodeCoordinates1->get(i, j + 2*network1->numFrames()) << 48 | " "; 49 | std::cout << j * 1 << std::endl; 50 | } 51 | std::cout << std::endl; 52 | std::cout << std::endl; 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /netchem/src/atoms.cpp: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------* 2 | * CuRva * 3 | *--------------------------------------------------------------------* 4 | * This is part of the GPU-accelerated, random variable analysis * 5 | * library CuRva. * 6 | * Copyright (C) 2022 Andy Stokely * 7 | * * 8 | * This program is free software: you can redistribute it * 9 | * and/or modify it under the terms of the GNU General Public License * 10 | * as published by the Free Software Foundation, either version 3 of * 11 | * the License, or (at your option) any later version. * 12 | * * 13 | * This program is distributed in the hope that it will be useful, * 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 | * GNU General Public License for more details. * 17 | * * 18 | * You should have received a copy of the GNU General Public License * 19 | * along with this program. * 20 | * If not, see * 21 | * -------------------------------------------------------------------*/ 22 | 23 | #include "atoms.h" 24 | 25 | Atoms::Atoms () = default; 26 | 27 | void Atoms::addAtom(Atom *atom) { 28 | this->uniqueTags_.insert(atom->tag()); 29 | atoms_.push_back(atom); 30 | } 31 | 32 | int Atoms::numAtoms () const { 33 | return static_cast(atoms_.size()); 34 | } 35 | 36 | Atom *Atoms::at(int atomIndex) { 37 | return atoms_.at(atomIndex); 38 | } 39 | 40 | int Atoms::numUniqueTags () const { 41 | return static_cast(uniqueTags_.size()); 42 | } 43 | 44 | std::vector &Atoms::atoms() { 45 | return this->atoms_; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /netchem/src/utils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by astokely on 5/3/23. 3 | // 4 | /*--------------------------------------------------------------------* 5 | * CuRva * 6 | *--------------------------------------------------------------------* 7 | * This is part of the GPU-accelerated, random variable analysis * 8 | * library CuRva. * 9 | * Copyright (C) 2022 Andy Stokely * 10 | * * 11 | * This program is free software: you can redistribute it * 12 | * and/or modify it under the terms of the GNU General Public License * 13 | * as published by the Free Software Foundation, either version 3 of * 14 | * the License, or (at your option) any later version. * 15 | * * 16 | * This program is distributed in the hope that it will be useful, * 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 | * GNU General Public License for more details. * 20 | * * 21 | * You should have received a copy of the GNU General Public License * 22 | * along with this program. * 23 | * If not, see * 24 | * -------------------------------------------------------------------*/ 25 | 26 | #include "utils.h" 27 | #include 28 | #include 29 | 30 | void utils::determineLastFrame ( 31 | int *lastFrame, 32 | int numFrames 33 | ) { 34 | if (*lastFrame 35 | == -1) { 36 | *lastFrame = numFrames 37 | - 1; 38 | } 39 | } 40 | 41 | void utils::generateIndicesArray ( 42 | unsigned int **indicesArray, 43 | int size 44 | ) { 45 | *indicesArray = new unsigned int[size]; 46 | std::iota( 47 | *indicesArray, 48 | *indicesArray 49 | + size, 50 | 0 51 | ); 52 | } 53 | 54 | bool utils::isRecordAtom (std::string &pdbLine) { 55 | size_t isRecordAtom = pdbLine.find("ATOM"); 56 | if (isRecordAtom 57 | != std::string::npos) { 58 | return true; 59 | } else { 60 | return false; 61 | } 62 | } 63 | 64 | bool utils::isEndOfFrame (std::string &pdbLine) { 65 | size_t isEndOfFrame = pdbLine.find("END"); 66 | if (isEndOfFrame 67 | != std::string::npos) { 68 | return true; 69 | } else { 70 | return false; 71 | } 72 | } 73 | 74 | std::string utils::removeWhiteSpace (std::string str) { 75 | str.erase( 76 | std::remove_if( 77 | str.begin(), 78 | str.end(), 79 | isspace 80 | ), 81 | str.end() 82 | ); 83 | return str; 84 | } 85 | 86 | double utils::strToDouble (const std::string &str) { 87 | return std::stod(str); 88 | } 89 | 90 | int utils::strToInt (const std::string &str) { 91 | return std::stoi(str); 92 | } 93 | 94 | unsigned int utils::hashString ( 95 | const std::string &str 96 | ) { 97 | const char *strPtr = str.data(); 98 | unsigned int h = HASH_FIRSTH; 99 | while (*strPtr) { 100 | h = ( 101 | h 102 | * HASH_A 103 | ) 104 | ^ ( 105 | strPtr[0] 106 | * HASH_B 107 | ); 108 | strPtr++; 109 | } 110 | return h; 111 | } 112 | 113 | int utils::substringInString ( 114 | const std::string &str, 115 | const std::string 116 | &substr 117 | ) { 118 | if (str.find(substr) 119 | != std::string::npos) { 120 | return 1; 121 | } 122 | return 0; 123 | } -------------------------------------------------------------------------------- /netchem/swig/python_netchem.i: -------------------------------------------------------------------------------- 1 | %module netchem 2 | 3 | %include "std_string.i" 4 | %include "std_vector.i" 5 | %include "std_map.i" 6 | %include 7 | %include "python_netchem_headers.i" 8 | %include "python_netchem_template.i" 9 | %include "python_netchem_typemaps.i" 10 | %include "python_netchem_include.i" 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /netchem/swig/python_netchem_headers.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #define SWIG_FILE_WITH_INIT 3 | #include "atom.h" 4 | #include "atoms.h" 5 | #include "network.h" 6 | #include "node.h" 7 | %} 8 | -------------------------------------------------------------------------------- /netchem/swig/python_netchem_include.i: -------------------------------------------------------------------------------- 1 | %include atoms.h 2 | %include atom.h 3 | %include network.h 4 | %include node.h 5 | 6 | -------------------------------------------------------------------------------- /netchem/swig/python_netchem_template.i: -------------------------------------------------------------------------------- 1 | %template(AtomVector) std::vector; 2 | %template(NodeVector) std::vector; 3 | -------------------------------------------------------------------------------- /netchem/swig/python_netchem_typemaps.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | %} 5 | 6 | %inline %{ 7 | class StopAtomsIterator{}; 8 | class AtomsIterator{ 9 | public: 10 | AtomsIterator( 11 | std::vector::iterator _cur, 12 | int numAtoms_ 13 | ) : cur(_cur), numAtoms(numAtoms_) {} 14 | AtomsIterator* __iter__() 15 | { 16 | return this; 17 | } 18 | std::vector::iterator cur; 19 | int numAtoms; 20 | int stopAtNextIteration = 0; 21 | }; 22 | %} 23 | %include "exception.i" 24 | 25 | %exception AtomsIterator::__next__{ 26 | try { 27 | $action // calls %extend function next() below 28 | } 29 | catch (StopAtomsIterator) { 30 | PyErr_SetString(PyExc_StopIteration, "End of iterator"); 31 | return NULL; 32 | } 33 | } 34 | %extend AtomsIterator{ 35 | Atom * __next__() { 36 | if (!$self->stopAtNextIteration) { 37 | if ((*($self->cur))->index() == $self->numAtoms - 1) { 38 | $self->stopAtNextIteration = 1; 39 | } 40 | return *($self->cur++); 41 | } 42 | throw StopAtomsIterator(); 43 | } 44 | } 45 | 46 | %extend Atoms{ 47 | AtomsIterator __iter__() { 48 | return AtomsIterator($self->atoms().begin(), $self->numAtoms()); 49 | } 50 | }; 51 | 52 | %inline %{ 53 | class StopNetworkIterator{}; 54 | class NetworkIterator{ 55 | public: 56 | NetworkIterator( 57 | std::vector::iterator _cur, 58 | int numNodes_ 59 | ) : cur(_cur), numNodes(numNodes_) {} 60 | NetworkIterator* __iter__() 61 | { 62 | return this; 63 | } 64 | std::vector::iterator cur; 65 | int numNodes; 66 | int stopAtNextIteration = 0; 67 | }; 68 | %} 69 | %include "exception.i" 70 | 71 | %exception NetworkIterator::__next__{ 72 | try { 73 | $action // calls %extend function next() below 74 | } 75 | catch (StopNetworkIterator) { 76 | PyErr_SetString(PyExc_StopIteration, "End of iterator"); 77 | return NULL; 78 | } 79 | } 80 | %extend NetworkIterator{ 81 | Node * __next__() { 82 | if (!$self->stopAtNextIteration) { 83 | if ((*($self->cur))->index() == $self->numNodes - 1) { 84 | $self->stopAtNextIteration = 1; 85 | } 86 | return *($self->cur++); 87 | } 88 | throw StopNetworkIterator(); 89 | } 90 | } 91 | 92 | %extend Network{ 93 | NetworkIterator __iter__() { 94 | return NetworkIterator($self->nodes().begin(), $self->nodes().size()); 95 | } 96 | }; 97 | 98 | %extend Atoms{ 99 | Atom *__getitem__(int atomIndex) { 100 | return $self->atoms().at(atomIndex); 101 | } 102 | }; 103 | 104 | %extend Atom{ 105 | std::string __repr__() { 106 | std::stringstream repr_ss; 107 | repr_ss << "Index: " << $self->index() << std::endl; 108 | repr_ss << "Serial: " << $self->serial() << std::endl; 109 | repr_ss << "Name: " << $self->name() << std::endl; 110 | repr_ss << "Element: " << $self->element() << std::endl; 111 | repr_ss << "Residue ID: " << $self->residueId() << std::endl; 112 | repr_ss << "Residue Name: " << $self->residueName() << 113 | std::endl; 114 | repr_ss << "Chain ID: " << $self->chainId() << std::endl; 115 | repr_ss << "Segment ID: " << $self->segmentId() << std::endl; 116 | repr_ss << "Mass: " << $self->mass(); 117 | return repr_ss.str(); 118 | } 119 | }; 120 | 121 | %extend Node{ 122 | std::string __repr__() { 123 | std::stringstream repr_ss; 124 | repr_ss << "Index: " << $self->index() << std::endl; 125 | repr_ss << "Tag: " << $self->tag() << std::endl; 126 | repr_ss << "Total Mass: " << $self->totalMass() << 127 | std::endl; 128 | repr_ss << "Number of Atoms: " << $self->numAtoms(); 129 | return repr_ss.str(); 130 | } 131 | }; 132 | -------------------------------------------------------------------------------- /netsci.yml: -------------------------------------------------------------------------------- 1 | name: netsci 2 | dependencies: 3 | - python=3.10 4 | - conda-forge::cmake 5 | - conda-forge::numpy 6 | - conda-forge::doxygen 7 | - conda-forge::boost 8 | - conda-forge::swig 9 | - conda-forge::pytest -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "versioningit~=2.0"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | # Self-descriptive entries which should always be present 6 | [project] 7 | name = "netsci" 8 | description = "A Toolkit for High Performance Scientific Network Analysis Computation" 9 | dynamic = ["version"] 10 | readme = "README.md" 11 | authors = [ 12 | { name = "Andy Stokely", email = "andystokely@gmail.com" }, 13 | { name = "Lane Votapka", email = "lvotapka@protonmail.com" } 14 | ] 15 | license = { text = "MIT" } 16 | # See https://pypi.org/classifiers/ 17 | classifiers = [ 18 | "License :: OSI Approved :: MIT License", 19 | "Programming Language :: Python :: 3", 20 | ] 21 | requires-python = ">=3.8" 22 | # Declare any run-time dependencies that should be installed with the package. 23 | dependencies = [ 24 | "numpy", 25 | "scipy", 26 | "matplotlib", 27 | "pytest", 28 | ] 29 | 30 | # Update the urls once the hosting is set up. 31 | [project.urls] 32 | "Source" = "https://github.com/netscianalysis/netsci.git" 33 | "Documentation" = "https://netsci.readthedocs.io" 34 | 35 | [tool.setuptools] 36 | # This subkey is a beta stage development and keys may change in the future, see https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html for more details 37 | # 38 | # As of version 0.971, mypy does not support type checking of installed zipped 39 | # packages (because it does not actually import the Python packages). 40 | # We declare the package not-zip-safe so that our type hints are also available 41 | # when checking client code that uses our (installed) package. 42 | # Ref: 43 | # https://mypy.readthedocs.io/en/stable/installed_packages.html?highlight=zip#using-installed-packages-with-mypy-pep-561 44 | zip-safe = false 45 | # Let setuptools discover the package in the current directory, 46 | # but be explicit about non-Python files. 47 | # See also: 48 | # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration 49 | # Note that behavior is currently evolving with respect to how to interpret the 50 | # "data" and "tests" subdirectories. As of setuptools 63, both are automatically 51 | # included if namespaces is true (default), even if the package is named explicitly 52 | # (instead of using 'find'). With 'find', the 'tests' subpackage is discovered 53 | # recursively because of its __init__.py file, but the data subdirectory is excluded 54 | # with include-package-data = false and namespaces = false. 55 | include-package-data = true 56 | [tool.setuptools.packages.find] 57 | namespaces = true 58 | where = ["."] 59 | 60 | # Ref https://setuptools.pypa.io/en/latest/userguide/datafiles.html#package-data 61 | [tool.setuptools.package-data] 62 | qmrebind = [ 63 | "py.typed", 64 | # Commenting these so that other packages can easily import seekr2 test data. 65 | # "*.dat", 66 | # "*.txt", 67 | # "*.pdb", 68 | # "*.pqr", 69 | # "*.parm7", 70 | # "*.prmtop", 71 | # "*.rst7", 72 | # "*.xml", 73 | ] 74 | 75 | [tool.versioningit] 76 | default-version = "1.0.0" 77 | 78 | [tool.versioningit.format] 79 | distance = "{base_version}+{distance}.{vcs}{rev}" 80 | dirty = "{base_version}+{distance}.{vcs}{rev}.dirty" 81 | distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty" 82 | 83 | [tool.versioningit.vcs] 84 | # The method key: 85 | method = "git" # <- The method name 86 | # Parameters to pass to the method: 87 | match = ["*"] 88 | default-tag = "2.1.0" 89 | 90 | [tool.versioningit.write] 91 | file = "netsci/_version.py" 92 | 93 | 94 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | 2 | [pytest] 3 | testpaths = 4 | tests/netcalc/python 5 | tests/cuarray/python 6 | tests/netchem/python 7 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(TEST_DATA_DIR ${CMAKE_SOURCE_DIR}/tests/data) 3 | message(${TEST_DATA_DIR}) 4 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/netcalc/cpp) 5 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cuarray/cpp) 6 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/netchem/cpp) 7 | -------------------------------------------------------------------------------- /tests/cuarray/cpp/FloatCuArrayFixture.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 4/4/23. 3 | // 4 | 5 | #ifndef NETSCI_FLOATCUARRAYFIXTURE_H 6 | #define NETSCI_FLOATCUARRAYFIXTURE_H 7 | 8 | #include "gtest/gtest.h" 9 | #include "cuarray.h" 10 | 11 | class FloatCuArrayFixture : public ::testing::Test { 12 | protected: 13 | void SetUp() override { 14 | data = new float[2000]; 15 | for (int i = 0; i < 2000; i++) { 16 | data[i] = static_cast(rand()) / 17 | static_cast(RAND_MAX); 18 | } 19 | cuArrayNoData = new CuArray; 20 | cuArrayNoData->init( 21 | 20, 22 | 100 23 | ); 24 | cuArrayWithData = new CuArray; 25 | cuArrayWithData->init( 26 | data, 27 | 20, 28 | 100 29 | ); 30 | } 31 | 32 | void TearDown() override { 33 | delete cuArrayNoData; 34 | delete cuArrayWithData; 35 | delete[] data; 36 | } 37 | 38 | CuArray *cuArrayNoData; 39 | CuArray *cuArrayWithData; 40 | float *data; 41 | }; 42 | 43 | #endif //NETSCI_FLOATCUARRAYFIXTURE_H 44 | -------------------------------------------------------------------------------- /tests/cuarray/python/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import cuarray 3 | import numpy as np 4 | 5 | 6 | @pytest.fixture(scope='session') 7 | def FloatCuArrayNoDataFixture(): 8 | m, n = 20, 100 9 | floatCuArrayNoData = cuarray.FloatCuArray() 10 | floatCuArrayNoData.init(m, n) 11 | return floatCuArrayNoData 12 | 13 | 14 | @pytest.fixture(scope='session') 15 | def FloatCuArrayWithDataFixture(): 16 | m, n = 20, 100 17 | floatCuArrayWithData = cuarray.FloatCuArray() 18 | floatCuArrayWithData.fromNumpy2D( 19 | np.random.random((m, n)).astype(np.float32) 20 | ) 21 | return floatCuArrayWithData 22 | -------------------------------------------------------------------------------- /tests/cuarray/python/test_FloatCuArray.py: -------------------------------------------------------------------------------- 1 | import cuarray 2 | import pytest 3 | 4 | 5 | @pytest.fixture(autouse=True) 6 | def change_test_dir(request, monkeypatch): 7 | monkeypatch.chdir(request.fspath.dirname) 8 | 9 | 10 | def test_FloatCuArrayNoData_m(FloatCuArrayNoDataFixture): 11 | assert FloatCuArrayNoDataFixture.m() == 20 12 | 13 | 14 | def test_FloatCuArrayNoData_n(FloatCuArrayNoDataFixture): 15 | assert FloatCuArrayNoDataFixture.n() == 100 16 | 17 | 18 | def test_FloatCuArrayNoData_bytes(FloatCuArrayNoDataFixture): 19 | assert FloatCuArrayNoDataFixture.bytes() == 8000 20 | 21 | 22 | def test_FloatCuArrayNoData_size(FloatCuArrayNoDataFixture): 23 | assert FloatCuArrayNoDataFixture.size() == 2000 24 | 25 | 26 | def test_FloatCuArrayNoData_allocatedHost(FloatCuArrayNoDataFixture): 27 | assert FloatCuArrayNoDataFixture.allocatedHost() == 1 28 | 29 | 30 | def test_FloatCuArrayNoData_allocatedDevice(FloatCuArrayNoDataFixture): 31 | assert FloatCuArrayNoDataFixture.allocatedDevice() == 0 32 | 33 | 34 | def test_FloatCuArrayNoData_host(FloatCuArrayNoDataFixture): 35 | for i in range(FloatCuArrayNoDataFixture.m()): 36 | for j in range(FloatCuArrayNoDataFixture.n()): 37 | assert FloatCuArrayNoDataFixture.get(i, j) == 0.0 38 | 39 | 40 | def test_FloatCuArrayNoData_toDeviceNegative(FloatCuArrayNoDataFixture): 41 | FloatCuArrayNoDataFixture.toDevice() 42 | assert FloatCuArrayNoDataFixture.allocatedDevice() == 0 43 | FloatCuArrayNoDataFixture.deallocateDevice() 44 | 45 | 46 | def test_FloatCuArrayNoData_toDevicePositive(FloatCuArrayNoDataFixture): 47 | FloatCuArrayNoDataFixture.allocateDevice() 48 | FloatCuArrayNoDataFixture.toDevice() 49 | assert FloatCuArrayNoDataFixture.allocatedDevice() == 1 50 | FloatCuArrayNoDataFixture.deallocateDevice() 51 | 52 | 53 | def test_FloatCuArray_fromCuArray(FloatCuArrayWithDataFixture): 54 | floatCuArray = cuarray.FloatCuArray() 55 | floatCuArray.fromCuArray( 56 | cuArray=FloatCuArrayWithDataFixture, 57 | start=18, 58 | end=19, 59 | m=2, 60 | n=100, 61 | ) 62 | assert floatCuArray.m() == 2 63 | assert floatCuArray.n() == 100 64 | assert floatCuArray.bytes() == 800 65 | assert floatCuArray.size() == 200 66 | assert floatCuArray.allocatedHost() == 1 67 | assert floatCuArray.allocatedDevice() == 0 68 | assert floatCuArray.owner() == 1 69 | for i in range(floatCuArray.m()): 70 | for j in range(floatCuArray.n()): 71 | assert floatCuArray.get(i, j) == FloatCuArrayWithDataFixture.get( 72 | 18 + i, j 73 | ) 74 | -------------------------------------------------------------------------------- /tests/data/2X_1D_1000_4.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/tests/data/2X_1D_1000_4.npy -------------------------------------------------------------------------------- /tests/data/2X_1D_2000_4.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/tests/data/2X_1D_2000_4.npy -------------------------------------------------------------------------------- /tests/netcalc/cpp/data/2X_1D_1000_4.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/tests/netcalc/cpp/data/2X_1D_1000_4.npy -------------------------------------------------------------------------------- /tests/netcalc/cpp/data/2X_1D_2000_4.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/tests/netcalc/cpp/data/2X_1D_2000_4.npy -------------------------------------------------------------------------------- /tests/netchem/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(NETCHEM_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 3 | file(COPY ${TEST_DATA_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 4 | message(${TEST_DATA_DIR}) 5 | add_executable( 6 | NetworkStride1_test 7 | ${NETCHEM_TEST_DIR}/NetworkStride1_test.cpp) 8 | add_dependencies(NetworkStride1_test netchem) 9 | set_target_properties( 10 | NetworkStride1_test 11 | PROPERTIES 12 | LINK_LIBRARIES "${NETCHEM_TEST_LINK_LIBRARIES}" 13 | ) 14 | add_executable( 15 | NetworkStride2_test 16 | ${NETCHEM_TEST_DIR}/NetworkStride2_test.cpp) 17 | add_dependencies(NetworkStride2_test netchem) 18 | set_target_properties( 19 | NetworkStride2_test 20 | PROPERTIES 21 | LINK_LIBRARIES "${NETCHEM_TEST_LINK_LIBRARIES}" 22 | ) 23 | add_executable( 24 | NetworkStride3_test 25 | ${NETCHEM_TEST_DIR}/NetworkStride3_test.cpp) 26 | add_dependencies(NetworkStride3_test netchem) 27 | set_target_properties( 28 | NetworkStride3_test 29 | PROPERTIES 30 | LINK_LIBRARIES "${NETCHEM_TEST_LINK_LIBRARIES}" 31 | ) 32 | 33 | add_executable( 34 | NetworkStrideCoordinateEquality_test 35 | ${NETCHEM_TEST_DIR}/NetworkStrideCoordinateEquality_test.cpp) 36 | add_dependencies(NetworkStrideCoordinateEquality_test netchem) 37 | set_target_properties( 38 | NetworkStrideCoordinateEquality_test 39 | PROPERTIES 40 | LINK_LIBRARIES "${NETCHEM_TEST_LINK_LIBRARIES}" 41 | ) 42 | 43 | add_test( 44 | NAME NetworkStride1_numFrames 45 | COMMAND NetworkStride1_test --gtest_filter=*NetworkStride1_numFrames* 46 | WORKING_DIRECTORY ${NETCHEM_TEST_DIR} 47 | ) 48 | add_test( 49 | NAME NetworkStride2_numFrames 50 | COMMAND NetworkStride2_test --gtest_filter=*NetworkStride2_numFrames* 51 | WORKING_DIRECTORY ${NETCHEM_TEST_DIR} 52 | ) 53 | add_test( 54 | NAME NetworkStride3_numFrames 55 | COMMAND NetworkStride3_test --gtest_filter=*NetworkStride3_numFrames* 56 | WORKING_DIRECTORY ${NETCHEM_TEST_DIR} 57 | ) 58 | add_test( 59 | NAME NetworkStrideCoordinateEqualityStride1Stride2 60 | COMMAND NetworkStrideCoordinateEquality_test --gtest_filter=*NetworkStrideCoordinateEqualityStride1Stride2* 61 | WORKING_DIRECTORY ${NETCHEM_TEST_DIR} 62 | ) 63 | add_test( 64 | NAME NetworkStrideCoordinateEqualityStride1Stride3 65 | COMMAND NetworkStrideCoordinateEquality_test --gtest_filter=*NetworkStrideCoordinateEqualityStride1Stride3* 66 | WORKING_DIRECTORY ${NETCHEM_TEST_DIR} 67 | 68 | ) 69 | -------------------------------------------------------------------------------- /tests/netchem/cpp/NetworkStride1_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 4/5/23. 3 | // 4 | #include 5 | #include 6 | #include "network.h" 7 | 8 | class NetworkTest : public ::testing::Test { 9 | protected: 10 | void SetUp() override { 11 | networkStride1.init( 12 | "data/test.dcd", 13 | "data/test.pdb", 14 | 0, 15 | 9, 16 | 1 17 | ); 18 | } 19 | 20 | Network networkStride1; 21 | }; 22 | 23 | TEST_F( 24 | NetworkTest, 25 | NetworkStride1_numFrames 26 | ) { 27 | EXPECT_EQ( 28 | 10, 29 | networkStride1.numFrames() 30 | ); 31 | } 32 | 33 | TEST_F( 34 | NetworkTest, 35 | NetworkStride1_nodeCoordinates_m 36 | ) { 37 | EXPECT_EQ( 38 | 290, 39 | networkStride1.nodeCoordinates()->m() 40 | ); 41 | } 42 | 43 | TEST_F( 44 | NetworkTest, 45 | NetworkStride1_nodeCoordinates_n 46 | ) { 47 | EXPECT_EQ( 48 | 30, 49 | networkStride1.nodeCoordinates()->n() 50 | ); 51 | } 52 | 53 | 54 | 55 | int main( 56 | int argc, 57 | char **argv 58 | ) { 59 | ::testing::InitGoogleTest(&argc, 60 | argv); 61 | return RUN_ALL_TESTS(); 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/netchem/cpp/NetworkStride2_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 4/5/23. 3 | // 4 | #include 5 | #include "network.h" 6 | 7 | class NetworkTest : public ::testing::Test { 8 | protected: 9 | void SetUp() override { 10 | networkStride2.init( 11 | "data/test.dcd", 12 | "data/test.pdb", 13 | 0, 14 | 9, 15 | 2 16 | ); 17 | } 18 | 19 | Network networkStride2; 20 | 21 | }; 22 | 23 | TEST_F( 24 | NetworkTest, 25 | NetworkStride2_numFrames 26 | ) { 27 | EXPECT_EQ( 28 | 5, 29 | networkStride2.numFrames() 30 | ); 31 | } 32 | 33 | TEST_F( 34 | NetworkTest, 35 | NetworkStride2_nodeCoordinates_m 36 | ) { 37 | EXPECT_EQ( 38 | 290, 39 | networkStride2.nodeCoordinates()->m() 40 | ); 41 | } 42 | 43 | TEST_F( 44 | NetworkTest, 45 | NetworkStride2_nodeCoordinates_n 46 | ) { 47 | EXPECT_EQ( 48 | 15, 49 | networkStride2.nodeCoordinates()->n() 50 | ); 51 | } 52 | 53 | int main( 54 | int argc, 55 | char **argv 56 | ) { 57 | ::testing::InitGoogleTest(&argc, 58 | argv); 59 | return RUN_ALL_TESTS(); 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /tests/netchem/cpp/NetworkStride3_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by andy on 4/5/23. 3 | // 4 | #include 5 | #include 6 | #include "network.h" 7 | 8 | class NetworkTest : public ::testing::Test { 9 | protected: 10 | void SetUp() override { 11 | 12 | networkStride3.init( 13 | "data/test.dcd", 14 | "data/test.pdb", 15 | 0, 16 | 9, 17 | 3 18 | ); 19 | } 20 | 21 | Network networkStride3; 22 | 23 | }; 24 | 25 | TEST_F( 26 | NetworkTest, 27 | NetworkStride3_numFrames 28 | ) { 29 | EXPECT_EQ( 30 | 4, 31 | networkStride3.numFrames() 32 | ); 33 | } 34 | 35 | TEST_F( 36 | NetworkTest, 37 | NetworkStride3_nodeCoordinates_m 38 | ) { 39 | EXPECT_EQ( 40 | 290, 41 | networkStride3.nodeCoordinates()->m() 42 | ); 43 | } 44 | 45 | TEST_F( 46 | NetworkTest, 47 | NetworkStride3_nodeCoordinates_n 48 | ) { 49 | EXPECT_EQ( 50 | 9, 51 | networkStride3.nodeCoordinates()->n() 52 | ); 53 | } 54 | 55 | int main( 56 | int argc, 57 | char **argv 58 | ) { 59 | ::testing::InitGoogleTest(&argc, 60 | argv); 61 | return RUN_ALL_TESTS(); 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/netchem/cpp/data/test.dcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/tests/netchem/cpp/data/test.dcd -------------------------------------------------------------------------------- /tests/netchem/python/test_Network.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import pytest 4 | from pathlib import Path 5 | 6 | import netchem 7 | import cuarray 8 | 9 | 10 | @pytest.fixture(scope="module") 11 | def global_network_parameters(): 12 | trajectoryFile, topologyFile = tuple(map( 13 | lambda f : str(f), netchem.data_files(key="test") 14 | )) 15 | return dict( 16 | trajectoryFile=trajectoryFile, 17 | topologyFile=topologyFile, 18 | firstFrame=0, 19 | lastFrame=9, 20 | ) 21 | 22 | 23 | @pytest.fixture(scope="module") 24 | def Stride1Network(global_network_parameters): 25 | network = netchem.Network() 26 | network.init( 27 | **global_network_parameters, 28 | stride=1, 29 | ) 30 | return network 31 | 32 | 33 | @pytest.fixture(scope="module") 34 | def Stride2Network(global_network_parameters): 35 | network = netchem.Network() 36 | network.init( 37 | **global_network_parameters, 38 | stride=2, 39 | ) 40 | return network 41 | 42 | 43 | @pytest.fixture(scope="module") 44 | def Stride3Network(global_network_parameters): 45 | network = netchem.Network() 46 | network.init( 47 | **global_network_parameters, 48 | stride=3, 49 | ) 50 | return network 51 | 52 | 53 | @pytest.fixture(scope="module") 54 | def Network(global_network_parameters): 55 | network = netchem.Network() 56 | network.init( 57 | **global_network_parameters, 58 | ) 59 | return network 60 | 61 | 62 | def test_Stride1CoordinateEquality(Stride1Network, Network): 63 | for i in range(289): 64 | for j in range(30): 65 | assert ( 66 | Stride1Network.nodeCoordinates()[i][j] 67 | == Network.nodeCoordinates()[i][j] 68 | ) 69 | 70 | 71 | def test_Stride2CoordinateEquality(Stride2Network, Network): 72 | for i in range(289): 73 | for j in range(15): 74 | assert ( 75 | Stride2Network.nodeCoordinates()[i][j] 76 | == Network.nodeCoordinates()[i][2 * j] 77 | ) 78 | 79 | 80 | def test_Stride3CoordinateEquality(Stride3Network, Network): 81 | for i in range(289): 82 | assert ( 83 | Stride3Network.nodeCoordinates()[i][0] 84 | == Network.nodeCoordinates()[i][0] 85 | ) 86 | assert ( 87 | Stride3Network.nodeCoordinates()[i][4] 88 | == Network.nodeCoordinates()[i][10] 89 | ) 90 | assert ( 91 | Stride3Network.nodeCoordinates()[i][8] 92 | == Network.nodeCoordinates()[i][20] 93 | ) 94 | for j in range(1, 4): 95 | assert ( 96 | Stride3Network.nodeCoordinates()[i][j] 97 | == Network.nodeCoordinates()[i][3 * j] 98 | ) 99 | assert ( 100 | Stride3Network.nodeCoordinates()[i][j + 4] 101 | == Network.nodeCoordinates()[i][3 * j + 10] 102 | ) 103 | assert ( 104 | Stride3Network.nodeCoordinates()[i][j + 8] 105 | == Network.nodeCoordinates()[i][3 * j + 20] 106 | ) 107 | 108 | -------------------------------------------------------------------------------- /tutorial/protG_short.dcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netscianalysis/netsci/16e3c5e75771c810f63e56b929a5fd7133bd4e4c/tutorial/protG_short.dcd --------------------------------------------------------------------------------