Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8201c2c
Switch pyobjcryst to nanobind, directly including objcryst++ (submodu…
vincefn Aug 12, 2026
2ab7fe4
Update version
vincefn Aug 12, 2026
117cb30
feat: update objcryst submodule and expose new features (PRs #107,#10…
vincefn Sep 1, 2026
acc01c6
chore: allow Python 3.15, set 2026.2.0rc0 and use PyPI libboost-headers
vincefn Nov 3, 2026
7ae3117
chore: update objcryst submodule to master (ba6ca89)
vincefn Nov 3, 2026
18e6337
feat: port March-Dollase texture (#119) and TOF profile (#120) to nan…
vincefn Nov 3, 2026
efddce8
Fix lifetime management regressions in Atom bindings
SYMSCAE Nov 3, 2026
12b9087
test: add Atom/ScatteringPower lifetime tests (#123)
vincefn Nov 4, 2026
3452813
Fix lifetime management regressions in Atom bindings (#124)
SYMSCAE Nov 4, 2026
765d058
Merge branch 'diffpy:nanobind_migration_test' into nanobind_migration…
SYMSCAE Nov 7, 2026
2b74b6f
build: build self-contained PyPI wheels with cibuildwheel
SYMSCAE Nov 8, 2026
7951366
ci: update workflow
SYMSCAE Nov 9, 2026
def1a60
ci: switch link to upstream v0
SYMSCAE Nov 10, 2026
4d8552d
doc: cleanup todo
SYMSCAE Nov 10, 2026
3492bde
fix: return numpy arrays from CrystVector/CrystMatrix bindings
clemisch Nov 13, 2026
0d9a511
add news file
clemisch Nov 13, 2026
493b6d8
remove single-argument binding of PrepareRefParList
clemisch Nov 13, 2026
a2f6f0d
add news file
clemisch Nov 13, 2026
c91557f
fix news file
clemisch Nov 13, 2026
16059bc
Merge pull request #130 from clemisch/129_preparerefparlist-silent
sbillinge Nov 14, 2026
c10d6c0
chore: separate build dependencies from conda.txt and pip.txt
SYMSCAE Nov 14, 2026
c2df30c
Merge pull request #128 from clemisch/127_getlatticepar-converter
sbillinge Nov 14, 2026
d72bb3a
Merge pull request #126 from SYMSCAE/cibuildwheel
sbillinge Nov 14, 2026
d6aba8f
chore: merge main into nanobind_migration_test (keep nanobind tree)
vincefn Nov 15, 2026
94fc212
test: restore reflection-profile tests dropped in nanobind port
vincefn Nov 15, 2026
0a305f7
docs: update README installation for nanobind/CMake build
vincefn Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/build-and-publish-docs-on-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
uses: scikit-package/release-scripts/.github/workflows/_release-docs.yml@v0
with:
project: pyobjcryst
submodules: "true"
c_extension: true
headless: false
python_version: ${{ fromJSON(needs.get-python-version.outputs.latest_python_version) }}
5 changes: 5 additions & 0 deletions .github/workflows/build-wheel-release-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ jobs:
#
# Choose this for open-source packages distributed via PyPI and/or
# conda-forge where broad public availability is the goal.
#
# build_c_ext_with_cibw builds the wheels with cibuildwheel using
# [tool.cibuildwheel] in pyproject.toml.
build-release:
uses: scikit-package/release-scripts/.github/workflows/_build-wheel-release-upload.yml@v0
with:
project: pyobjcryst
submodules: "true"
c_extension: true
build_c_ext_with_cibw: true
maintainer_github_username: sbillinge
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/matrix-and-codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
uses: scikit-package/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0
with:
project: pyobjcryst
submodules: "true"
c_extension: true
headless: false
secrets:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
uses: scikit-package/release-scripts/.github/workflows/_tests-on-pr.yml@v0
with:
project: pyobjcryst
submodules: "true"
c_extension: true
headless: false
secrets:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,8 @@ target/

# source distribution tarball
libdiffpy-*.tar.gz

# ObjCryst run-log autosave files (MonteCarloObj/LSQ XML dumps), produced
# any time an example notebook/script runs an optimization.
ObjCryst*.xml
*-Run#*-Cost-*.xml
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/objcryst"]
path = extern/objcryst
url = https://github.com/vincefn/objcryst.git
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Vendored third-party sources (objcryst submodule, cctbx, newmat)
exclude: "^extern/"
default_language_version:
python: python3
ci:
Expand Down
199 changes: 199 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
cmake_minimum_required(VERSION 3.15)

project(pyobjcryst CXX)

# Require C++17 globally
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# ---------------------------------------------------------------------------
# Python / nanobind
# ---------------------------------------------------------------------------
find_package(Python 3.11 REQUIRED COMPONENTS Interpreter Development.Module NumPy)

execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import nanobind; print(nanobind.cmake_dir())"
OUTPUT_VARIABLE NB_CMAKE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
list(APPEND CMAKE_PREFIX_PATH "${NB_CMAKE_DIR}")
find_package(nanobind CONFIG REQUIRED)

# ---------------------------------------------------------------------------
# Boost (header-only: format, rational, date_time used by ObjCryst sources)
# Priority: explicit BOOST_INCLUDE_DIR, then the PyPI `libboost-headers`
# package (used for isolated pip builds), then system/conda headers.
# ---------------------------------------------------------------------------
if(BOOST_INCLUDE_DIR)
set(PYOBJCRYST_BOOST_INCLUDE_DIR "${BOOST_INCLUDE_DIR}")
else()
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import importlib.util, os; s = importlib.util.find_spec('libboost_headers'); print(os.path.join(s.submodule_search_locations[0], 'include') if s else '')"
OUTPUT_VARIABLE _PYPI_BOOST_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(_PYPI_BOOST_INCLUDE_DIR AND EXISTS "${_PYPI_BOOST_INCLUDE_DIR}/boost/rational.hpp")
set(PYOBJCRYST_BOOST_INCLUDE_DIR "${_PYPI_BOOST_INCLUDE_DIR}")
else()
find_path(BOOST_SYSTEM_INCLUDE_DIR boost/rational.hpp
HINTS "$ENV{BOOST_ROOT}/include" "$ENV{Boost_ROOT}/include" "$ENV{CONDA_PREFIX}/include"
)
if(NOT BOOST_SYSTEM_INCLUDE_DIR)
message(FATAL_ERROR
"Boost headers not found. Install them with `pip install libboost-headers`, "
"`conda install -c conda-forge libboost-headers`, or set -DBOOST_INCLUDE_DIR=<path>.")
endif()
set(PYOBJCRYST_BOOST_INCLUDE_DIR "${BOOST_SYSTEM_INCLUDE_DIR}")
endif()
endif()
message(STATUS "Using Boost headers from: ${PYOBJCRYST_BOOST_INCLUDE_DIR}")

# ---------------------------------------------------------------------------
# External source paths
# ---------------------------------------------------------------------------
set(OBJCRYST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/extern/objcryst/ObjCryst")
set(NEWMAT_SRC "${CMAKE_CURRENT_SOURCE_DIR}/extern/newmat")
set(CCTBX_SRC "${CMAKE_CURRENT_SOURCE_DIR}/extern/cctbx")

# ---------------------------------------------------------------------------
# Generate version.h so that ObjCryst sources can be compiled standalone
# ---------------------------------------------------------------------------
set(PYOBJCRYST_EMBED_VERSION_MAJOR 2024)
set(PYOBJCRYST_EMBED_VERSION_MINOR 1)
set(PYOBJCRYST_EMBED_VERSION_MICRO 0)
set(PYOBJCRYST_EMBED_VERSION_PATCH 3)
# Build integer: MAJOR*1e9 + MINOR*1e6 + MICRO*1e3 + PATCH
math(EXPR PYOBJCRYST_EMBED_VERSION
"${PYOBJCRYST_EMBED_VERSION_MAJOR} * 1000000000 + \
${PYOBJCRYST_EMBED_VERSION_MINOR} * 1000000 + \
${PYOBJCRYST_EMBED_VERSION_MICRO} * 1000 + \
${PYOBJCRYST_EMBED_VERSION_PATCH}")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/ObjCryst/version.h"
@ONLY
)

# ---------------------------------------------------------------------------
# newmat static library
# ---------------------------------------------------------------------------
set(NEWMAT_SOURCES
${NEWMAT_SRC}/bandmat.cpp
${NEWMAT_SRC}/evalue.cpp
${NEWMAT_SRC}/myexcept.cpp
${NEWMAT_SRC}/newmat1.cpp
${NEWMAT_SRC}/newmat2.cpp
${NEWMAT_SRC}/newmat3.cpp
${NEWMAT_SRC}/newmat4.cpp
${NEWMAT_SRC}/newmat5.cpp
${NEWMAT_SRC}/newmat6.cpp
${NEWMAT_SRC}/newmat7.cpp
${NEWMAT_SRC}/newmat8.cpp
${NEWMAT_SRC}/newmat9.cpp
${NEWMAT_SRC}/newmatex.cpp
${NEWMAT_SRC}/sort.cpp
${NEWMAT_SRC}/submat.cpp
)

add_library(newmat STATIC ${NEWMAT_SOURCES})
target_include_directories(newmat PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/extern")
set_property(TARGET newmat PROPERTY POSITION_INDEPENDENT_CODE ON)

# ---------------------------------------------------------------------------
# cctbx static library
# ---------------------------------------------------------------------------
file(GLOB_RECURSE CCTBX_SOURCES
"${CCTBX_SRC}/cctbx/eltbx/*.cpp"
"${CCTBX_SRC}/cctbx/sgtbx/*.cpp"
"${CCTBX_SRC}/cctbx/miller/*.cpp"
"${CCTBX_SRC}/cctbx/uctbx/*.cpp"
)

add_library(cctbx STATIC ${CCTBX_SOURCES})
target_include_directories(cctbx PUBLIC
"${CCTBX_SRC}/include"
"${Python_ROOT_DIR}/include"
"${PYOBJCRYST_BOOST_INCLUDE_DIR}"
)
set_property(TARGET cctbx PROPERTY POSITION_INDEPENDENT_CODE ON)

# ---------------------------------------------------------------------------
# ObjCryst++ static library
# ---------------------------------------------------------------------------
file(GLOB OBJCRYST_SOURCES
"${OBJCRYST_SRC}/ObjCryst/*.cpp"
"${OBJCRYST_SRC}/RefinableObj/*.cpp"
"${OBJCRYST_SRC}/CrystVector/*.cpp"
"${OBJCRYST_SRC}/Quirks/VFNDebug.cpp"
"${OBJCRYST_SRC}/Quirks/VFNStreamFormat.cpp"
"${OBJCRYST_SRC}/Quirks/ci_string.cpp"
)
list(APPEND OBJCRYST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cpp")

add_library(ObjCryst STATIC ${OBJCRYST_SOURCES})

target_include_directories(ObjCryst PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/extern/objcryst"
"${CCTBX_SRC}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/extern"
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${PYOBJCRYST_BOOST_INCLUDE_DIR}"
)
set_property(TARGET ObjCryst PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(ObjCryst PUBLIC
REAL=double
BOOST_ERROR_CODE_HEADER_ONLY
$<$<CONFIG:Debug>:__DEBUG__>
)
target_link_libraries(ObjCryst PUBLIC cctbx newmat)

# Put VFNDebug.cpp first so debug-level constants are defined before use
if(NOT MSVC)
set_source_files_properties(
"${OBJCRYST_SRC}/Quirks/VFNDebug.cpp"
PROPERTIES COMPILE_FLAGS "-O0"
)
endif()

# MSVC: same settings as the libobjcryst Windows build (/EHsc, M_PI etc.),
# plus /bigobj for the large binding translation units.
if(MSVC)
foreach(_tgt newmat cctbx ObjCryst)
target_compile_definitions(${_tgt} PUBLIC _USE_MATH_DEFINES NOMINMAX)
target_compile_options(${_tgt} PUBLIC /EHsc /bigobj)
endforeach()
endif()

# ---------------------------------------------------------------------------
# nanobind extension: _pyobjcryst
# ---------------------------------------------------------------------------
file(GLOB NB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/extensions/*.cpp")

nanobind_add_module(_pyobjcryst STABLE_ABI NB_STATIC ${NB_SOURCES})

target_include_directories(_pyobjcryst PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/extern/objcryst"
"${CCTBX_SRC}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/extern"
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${PYOBJCRYST_BOOST_INCLUDE_DIR}"
${Python_NumPy_INCLUDE_DIRS}
"${CMAKE_CURRENT_SOURCE_DIR}/src/extensions"
)

target_link_libraries(_pyobjcryst PRIVATE ObjCryst)

# Install into pyobjcryst package
install(TARGETS _pyobjcryst LIBRARY DESTINATION pyobjcryst)

# Licenses of the statically linked third-party code ship with the wheel.
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/extern/objcryst/LICENSE.txt"
DESTINATION pyobjcryst/licenses/objcryst)
install(FILES "${CCTBX_SRC}/LICENSE_2_0.txt" "${CCTBX_SRC}/COPYRIGHT_2_0.txt"
DESTINATION pyobjcryst/licenses/cctbx)
install(FILES "${NEWMAT_SRC}/readme.txt" "${NEWMAT_SRC}/nm11.htm"
DESTINATION pyobjcryst/licenses/newmat)
25 changes: 13 additions & 12 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
graft src
graft tests
graft requirements
recursive-include src *
include AUTHORS.txt LICENSE*.txt README.rst
recursive-exclude src *.pyc *.so
global-exclude .gitattributes .gitignore .gitarchive.cfg
global-exclude .DS_Store

include AUTHORS.rst LICENSE*.rst README.rst
# Avoid user content in setup.cfg to make distribution reproducible.
exclude setup.cfg

# Exclude all bytecode files and __pycache__ directories
global-exclude *.py[cod] # Exclude all .pyc, .pyo, and .pyd files.
global-exclude *.so # Exclude shared object files.
global-exclude .DS_Store # Exclude Mac filesystem artifacts.
global-exclude __pycache__ # Exclude Python cache directories.
global-exclude .git* # Exclude git files and directories.
global-exclude .idea # Exclude PyCharm project settings.
global-exclude SConscript.configure SConscript # SCons build scripts
# Exclude git-tracked files spuriously added by setuptools_scm
exclude .coveragerc
exclude .travis*
prune conda-recipe
prune devutils
prune doc
65 changes: 23 additions & 42 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The second paper describes the c++ crystallographic objects in
Installation
------------

The latest release of ``pyobjcryst`` runs in python versions 3.12, 3.13 and 3.14. You may
The latest release of ``pyobjcryst`` runs in python versions 3.12, 3.13, 3.14 and 3.15. You may
specify an earlier release if you need it to run in an earlier version of Python.

The preferred method is to use `Miniconda Python
Expand Down Expand Up @@ -127,56 +127,38 @@ Alternative methods of installation

These approaches are not recommended but reproduced here for advanced users.
You can use ``pip`` to download and install the latest release from
`Python Package Index <https://pypi.python.org>`_.
`Python Package Index <https://pypi.python.org>`_. The PyPI wheels are
self-contained (ObjCryst++, cctbx and newmat are built in), so no compiler
or conda libraries are needed ::

Pyobjcryst can be installed from pip. We recommend installing the dependencies that can be
found in ``requirements/conda.txt`` from conda-forge, e.g., ::

conda create -n pyobjcryst-env python=3.14
conda activate pyobjcryst-env
conda install -c conda-forge numpy libobjcryst libboost-devel libboost-python packaging ipywidgets matplotlib-base ipympl py3dmol
pip install pyobjcryst

If you prefer to install from sources, after installing the dependencies, obtain the source archive from
`GitHub <https://github.com/diffpy/pyobjcryst/>`_. Once installed, ``cd`` into your ``pyobjcryst`` directory
and run the following ::

pip install .

An alternative way of installing pyobjcryst is to use the SCons tool,
which can speed up the process by compiling C++ files in several
parallel jobs (-j4)::
The optional graphical dependencies can be installed with ::

conda install scons
conda install --file requirements/conda.txt
scons -j4 dev
pip install ipywidgets matplotlib ipympl py3dmol

See ``scons -h`` for description of build targets and options.
To build from source, a C++ compiler is required; CMake, nanobind and the
Boost headers are fetched automatically by ``pip``. ObjCryst++ is included
as a git submodule, so clone with ``--recursive`` (or run
``git submodule update --init`` in an existing clone) ::

Alternatively, on Ubuntu Linux the required software can be installed using ::

sudo apt-get install \
python-setuptools python-numpy scons \
build-essential python-dev libboost-all-dev

If this doesn't work, please see the `requirements/conda.txt` file for the
latest list of requirements.
git clone --recursive https://github.com/diffpy/pyobjcryst.git
cd pyobjcryst
pip install .

The ``libobjcryst`` library can also be installed as per the instructions at
https://github.com/diffpy/libobjcryst. Make sure other required software are
also in place and then run from the pyobjcryst directory ::
Outside a conda environment, e.g. on Ubuntu Linux, the compiler and Boost
headers can be installed using ::

pip install .
sudo apt-get install build-essential python3-dev python3-pip libboost-dev

You may need to use sudo with system Python so the process is allowed to copy files to system
directories, unless you are installing into a conda environment. If administrator (root) access is not
available, see the usage information from python setup.py install --help for options to install
to a user-writable location.
Boost headers can also be installed from conda-forge (``libboost-headers``),
or their location given explicitly with
``pip install . -Ccmake.define.BOOST_INCLUDE_DIR=<path>``.

Testing your installation
-------------------------

The installation integrity can be verified by executing the included tests with
The installation integrity can be verified by executing the included tests.

First install test dependencies then type pytest::

Expand Down Expand Up @@ -208,11 +190,10 @@ If it fails by black or isort, just rerun and it should pass (black and isort wi
pass after they are modified). If the flake8 test fails please see the error messages and fix them manually before
trying to commit again.

When developing it is preferable to compile the C++ files with
SCons using the ``build=debug`` option, which compiles the extension
module with debug information and C-assertions checks ::
When developing it is preferable to compile the extension module with
debug information and C-assertions checks ::

scons -j4 build=debug dev
pip install -e . -Ccmake.build-type=Debug

Improvements and fixes are always appreciated.

Expand Down
Loading
Loading