├── .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