Skip to content

V2 wip #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: C++ test

on:
workflow_dispatch:
push:
branches: ["v2_wip"]
paths:
- ".github/workflows/cpp.yml"
pull_request:
branches: ["v2_wip"]

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.10", "3.11"]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Add requirements
run: python -m pip install --upgrade wheel setuptools numpy gsd networkx biopython matplotlib

- name: build and install python module
run: pip install --verbose .

- name: build cpp tests
run: |
cmake -S tests/cpp -B build/ -DpatchyAnalysisTools_ROOT=$(python -m patchyAnalysisTools --cmakefiles)
cmake --build build/

- name: run cpp tests
run: |
cd build/
ctest
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
40 changes: 40 additions & 0 deletions .github/pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pip

on:
workflow_dispatch:
pull_request:
push:
branches:
- v2_wip
paths:
- ".github/workflows/pip.yml"

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.11"]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Add requirements
run: python -m pip install --upgrade wheel setuptools numpy gsd networkx biopython matplotlib

- name: Build and install
run: pip install --verbose .[test]

- name: Test
run: |
cd tests
python -m pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ eggs/
build/
dist/
*/__pycache__/
_skbuild
.pytest_cache
*/*.egg-info
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "pybind11"]
path = pybind11
url = https://github.com/pybind/pybind11.git
branch = master
95 changes: 95 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"__verbose_abort": "cpp",
"bitset": "cpp",
"charconv": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"format": "cpp",
"forward_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"optional": "cpp",
"queue": "cpp",
"ratio": "cpp",
"semaphore": "cpp",
"set": "cpp",
"span": "cpp",
"stack": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"unordered_set": "cpp",
"valarray": "cpp",
"variant": "cpp",
"__nullptr": "cpp",
"__string": "cpp",
"chrono": "cpp"
},
"cmake.configureOnOpen": true
}
84 changes: 84 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.15..3.26)

set(CMAKE_CXX_STANDARD 20)


project(
patchyAnalysisTools
VERSION "2.0.0"
LANGUAGES CXX)

include(GNUInstallDirs)

file (GLOB SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")


# define the C++ library "patchyAnalysisTools"
add_library(patchyAnalysisTools SHARED ${SOURCE_FILES})

target_include_directories(
patchyAnalysisTools PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})


install(
TARGETS patchyAnalysisTools
EXPORT patchyAnalysisToolsTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

set(PATCHYANALYSISTOOLS_CMAKE_PACKAGE_INSTALL_SUBDIR "share/patchyAnalysisTools/cmake")

install(
EXPORT patchyAnalysisToolsTargets
DESTINATION ${PATCHYANALYSISTOOLS_CMAKE_PACKAGE_INSTALL_SUBDIR})

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
patchyAnalysisToolsConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/patchyAnalysisToolsConfig.cmake.in" patchyAnalysisToolsConfig.cmake
INSTALL_DESTINATION ${PATCHYANALYSISTOOLS_CMAKE_PACKAGE_INSTALL_SUBDIR})

install(FILES "${PROJECT_BINARY_DIR}/patchyAnalysisToolsConfig.cmake"
"${PROJECT_BINARY_DIR}/patchyAnalysisToolsConfigVersion.cmake"
DESTINATION ${PATCHYANALYSISTOOLS_CMAKE_PACKAGE_INSTALL_SUBDIR})

# if called by scikit-build
if(DEFINED SKBUILD)

# call pybind11-config to obtain the root of the cmake package
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11 --cmakedir
OUTPUT_VARIABLE pybind11_ROOT_RAW)
string(STRIP ${pybind11_ROOT_RAW} pybind11_ROOT)
find_package(pybind11)

pybind11_add_module(_patchyAnalysisTools MODULE
"${PROJECT_SOURCE_DIR}/src/patchyAnalysisTools/patchyAnalysisTools_py.cpp")

target_link_libraries(_patchyAnalysisTools PRIVATE patchyAnalysisTools)

# Installing the extension module to the root of the package
install(TARGETS _patchyAnalysisTools DESTINATION .)

configure_file("${PROJECT_SOURCE_DIR}/src/patchyAnalysisTools/__main__.py.in"
"${PROJECT_BINARY_DIR}/src/patchyAnalysisTools/__main__.py")

install(FILES "${PROJECT_BINARY_DIR}/src/patchyAnalysisTools/__main__.py" DESTINATION .)


if(APPLE)
set_target_properties(
_patchyAnalysisTools PROPERTIES INSTALL_RPATH "@loader_path/${CMAKE_INSTALL_LIBDIR}")
else()
set_target_properties(_patchyAnalysisTools PROPERTIES INSTALL_RPATH
"$ORIGIN/${CMAKE_INSTALL_LIBDIR}")
endif()

endif()
81 changes: 6 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,9 @@
# patchyAnalysisTools

A set of tools to analyze the output of patchy particle simulations. Works with a very specific format of trajectory files, but the I/O methods can be extended for the analysis tools to work on arbitrary trajectory file formats. See examples for details.
(In the process of rewriting the whole thing in C++, with python bindings, to support efficient calculation of various trajectory-wide quantities).

## Installation

git clone https://github.com/sodiumnitrate/patchyAnalysisTools.git
cd patchyAnalysisTools
python setup.py install

## Examples

(See the `examples` folder for more details.)

### Loading the module

You can load the module as

import patchyAnalysisTools.trajectory as trj

The following examples all use the alias `trj` for the module.

### Loading trajectories

To load a trajectory:

traj = trj.trajectory(file_name="traj.conf")

where `traj.conf` is a trajectory file with specific formatting requirements (see examples). Patch information is then read from a file and set for the `traj` object by

traj.set_patch_info("patches.dat")

where `patches.dat` is again a special file (see examples). _Some_ analysis can be done without reading and setting patch information, but most require this for determining bonds, etc.

### Selecting frames or subtrajectories

To select the last frame:

last_frame = traj.get_last_frame()

To select an arbitrary frame:

frame = traj.get_frame(10)

To select a range of frames:

subtraj = traj.get_frame(10,20)

### Bonding and cluster info

Determination of bonding and cluster information requires the patches to have been set in the trajectory before a frame is selected (see above).

First, we determine bonds:

frame.get_list_of_interacting_pairs()

If the trajectory file has the number of bonds per particle written, we can double check the calculated bonds against these values:

frame.check_calculated_bonds_against_bond_numbers()

We then determine the clusters by

frame.set_cluster_info()

To find the percolating clusters:

frame.find_percolating_clusters()

To check if system is percolated:

frame.is_system_percolated()

which returns a boolean.

## What's missing
The main thing that is incomplete in this package is support for the output of Gibbs-Ensemble simulations (which contain two boxes). Some of the tools in this package support it, some don't. I may complete it at one point, but for now, everything is only tested for regular simulation outputs.

It is also important to note that not all the tools in this package are thoroughly tested for simulation output with non-cubic boxes.
## TODO:
1. GSD C API. Handling things on the python side for now.
2. Proper error handling from the C++ side, visible to python as well. Using `throw`s for now.
3. ~~C++-level tests. Sticking to `pytest` for now.~~
4. Libraries for rotations.
3 changes: 3 additions & 0 deletions cmake/patchyAnalysisToolsConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/patchyAnalysisToolsTargets.cmake")
Loading