Skip to content
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

C++ reimplementation of IDPP interpolation #369

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3672093
init cpp updates
shoubhikraj Oct 6, 2024
f9653de
small update
shoubhikraj Oct 6, 2024
dc183f2
idpp bug fix python
shoubhikraj Oct 9, 2024
da642b9
updates to C++ code
shoubhikraj Oct 9, 2024
1530c89
some updates
shoubhikraj Oct 9, 2024
a4f7c27
updates to C++ code
shoubhikraj Oct 10, 2024
58198dc
updates to C++ code
shoubhikraj Oct 10, 2024
47fe4e3
minor update
shoubhikraj Oct 13, 2024
cb79178
patch
shoubhikraj Oct 19, 2024
0370b29
updated cpp code
shoubhikraj Nov 13, 2024
dd8b233
further updates to C++ code
shoubhikraj Nov 13, 2024
9213060
add xtensor and update
shoubhikraj Nov 14, 2024
853a5a2
small update
shoubhikraj Nov 14, 2024
6003882
another update
shoubhikraj Nov 14, 2024
98aa539
unifinished update
shoubhikraj Nov 14, 2024
d68ac08
further updates to C++ code
shoubhikraj Nov 14, 2024
927efc5
first working commit
shoubhikraj Nov 14, 2024
7c14084
update
shoubhikraj Nov 14, 2024
c4b7296
update with LST strategy
shoubhikraj Nov 20, 2024
686153c
lst initial commit
shoubhikraj Nov 20, 2024
614df6c
small update
shoubhikraj Nov 21, 2024
c1ede0d
Revert "small update"
shoubhikraj Nov 21, 2024
752116e
Revert "lst initial commit"
shoubhikraj Nov 21, 2024
48ad4e3
debug update
shoubhikraj Nov 21, 2024
fc42cd8
minor update
shoubhikraj Nov 22, 2024
ba3a09f
minor refactor
shoubhikraj Nov 22, 2024
f1d7a97
remove xtensor
shoubhikraj Jan 3, 2025
23f3f46
update utils
shoubhikraj Jan 3, 2025
4f9dc2e
update not completely working
shoubhikraj Jan 6, 2025
aa9611e
working update
shoubhikraj Jan 8, 2025
909a644
fix some issues
shoubhikraj Jan 11, 2025
c7146ac
performance update
shoubhikraj Jan 12, 2025
c2cd097
c++11 compliance
shoubhikraj Jan 13, 2025
55da5c2
refactor to reduce function clutter
shoubhikraj Jan 13, 2025
d105b35
move class to python, unfinished
shoubhikraj Jan 13, 2025
46c54f7
minor update
shoubhikraj Jan 13, 2025
9210eab
unfinished update
shoubhikraj Jan 14, 2025
16f45dc
refactor idpp convergence
shoubhikraj Jan 19, 2025
315d1b5
pass params by struct
shoubhikraj Jan 19, 2025
b37e265
unfinished update
shoubhikraj Jan 20, 2025
f796974
unfinished update
shoubhikraj Jan 22, 2025
e51c9a1
unfinished update
shoubhikraj Jan 22, 2025
3ff1d6e
add function for relaxing path
shoubhikraj Jan 22, 2025
afdc533
unifinished update
shoubhikraj Jan 23, 2025
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
1 change: 1 addition & 0 deletions autode/ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_library(autode STATIC
include/points.h src/points.cpp
include/potentials.h src/potentials.cpp
include/utils.h src/utils.cpp
include/idpp.h src/idpp.cpp
)

Include(FetchContent)
Expand Down
194 changes: 194 additions & 0 deletions autode/ext/ade_idpp.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# distutils: language = c++
# distutils: sources = [autode/ext/src/idpp.cpp, autode/ext/src/utils.cpp]

import numpy as np
from autode.log import logger
import logging
from autode.ext.wrappers cimport calculate_idpp_path, IdppParams, get_path_length


cdef IdppParams handle_kwargs(kwargs) except *:
"""
Obtain an IdppParams object from keyword arguments. Allowed keys in
the kwargs dictionary are
sequential (bool): Whether to use the sequential IDPP

k_spr (float): The spring constant value

rms_gtol (float): The RMS gradient tolerance for the path

maxiter (int): Maximum number of iters for path

add_img_maxgtol (float): Max. gradient tolerance for adding
new images (only for sequential)

add_img_maxiter (int): Max. number of iters for adding new
images (only for sequential)

Args:
kwargs (dict): Dictionary of keyword arguments.

Returns:
(IdppParams):
"""
cdef IdppParams calc_params
calc_params.k_spr = kwargs.get('k_spr')
calc_params.sequential = kwargs.get('sequential')
calc_params.rmsgtol = kwargs.get('rms_gtol')
calc_params.maxiter = kwargs.get('maxiter')
calc_params.add_img_maxgtol = kwargs.get('add_img_maxgtol')
calc_params.add_img_maxiter = kwargs.get('add_img_maxiter')

# change the debug option according to current logging level
debug_print = logger.isEnabledFor(logging.DEBUG)
calc_params.debug = debug_print

return calc_params



def get_interpolated_path(
init_coords,
final_coords,
n_images: int,
**kwargs,
):
"""
Obtain the interpolated path (using the IDPP method) from
the coordinates of the reactant and product states

Args:
init_coords (np.ndarray): Initial coordinates
final_coords (np.ndarray): Final coordinates
n_images (int): Number of images requested

Keyword Args:
sequential (bool): Whether to use the sequential IDPP
k_spr (float): The spring constant value
rms_gtol (float): The RMS gradient tolerance for the path
maxiter (int): Maximum number of iters for path
add_img_maxgtol (float): Max. gradient tolerance for adding
new images (only for sequential)
add_img_maxiter (int): Max. number of iters for adding new
images (only for sequential)

Returns:
(np.ndarray): Numpy array of coordinates of the
intermediate images in the path
"""
if init_coords.shape != final_coords.shape:
raise ValueError("Coordinates must have the same shape")

# access raw memory block of the arrays
init_coords = np.ascontiguousarray(
init_coords.ravel(), dtype=np.double
)
final_coords = np.ascontiguousarray(
final_coords.ravel(), dtype=np.double
)
cdef double [:] init_view = init_coords
cdef double [:] final_view = final_coords

coords_len = init_coords.shape[0]
interm_img_coordinates = np.zeros(
shape=((n_images - 2) * coords_len,),
order="C",
dtype=np.double
)
cdef double [:] img_coords_view = interm_img_coordinates
cdef IdppParams params = handle_kwargs(kwargs)

calculate_idpp_path(
&init_view[0],
&final_view[0],
int(coords_len),
n_images,
&img_coords_view[0],
params,
)
return interm_img_coordinates

def get_interp_path_length(
init_coords,
final_coords,
n_images: int,
**kwargs,
):
"""
Obtain the length of the interpolated path (using the IDPP method) from
the coordinates of the reactant and product states

Args:
init_coords (np.ndarray): Initial coordinates
final_coords (np.ndarray): Final coordinates
n_images (int): Number of images requested

Keyword Args:
sequential (bool): Whether to use the sequential IDPP
k_spr (float): The spring constant value
rms_gtol (float): The RMS gradient tolerance for the path
maxiter (int): Maximum number of iters for path
add_img_maxgtol (float): Max. gradient tolerance for adding
new images (only for sequential)
add_img_maxiter (int): Max. number of iters for adding new
images (only for sequential)

Returns:
(float): Length of the interpolated path
"""
if init_coords.shape != final_coords.shape:
raise ValueError("Coordinates must have the same shape")

# access raw memory block of the arrays
init_coords = np.ascontiguousarray(
init_coords.ravel(), dtype=np.double
)
final_coords = np.ascontiguousarray(
final_coords.ravel(), dtype=np.double
)
cdef double [:] init_view = init_coords
cdef double [:] final_view = final_coords
coords_len = init_coords.shape[0]

cdef IdppParams params = handle_kwargs(kwargs)

return get_path_length(
&init_view[0],
&final_view[0],
int(coords_len),
n_images,
params,
)

def relax_path(
all_coords,
n_images: int,
**kwargs,
):
"""
Relax a set of images using the IDPP method

Args:
all_coords: Numpy array of all coordinates, including the
reactant and product
n_images: Number of images supplied

Keyword Args:
sequential (bool): Whether to use the sequential IDPP
k_spr (float): The spring constant value
rms_gtol (float): The RMS gradient tolerance for the path
maxiter (int): Maximum number of iters for path
add_img_maxgtol (float): Max. gradient tolerance for adding
new images (only for sequential)
add_img_maxiter (int): Max. number of iters for adding new
images (only for sequential)
"""
all_coords_cont = np.ascontiguousarray(
all_coords.ravel(), dtype=np.double
)
cdef double [:] all_coords_view = all_coords_cont
assert all_coords_cont.shape[0] % n_images == 0
coords_len = all_coords_cont.shape[0] // n_images
assert coords_len % 3 == 0

cdef IdppParams params = handle_kwargs(kwargs)
Loading
Loading