Skip to content

Commit

Permalink
unfinished update
Browse files Browse the repository at this point in the history
  • Loading branch information
shoubhikraj committed Jan 14, 2025
1 parent 46c54f7 commit 9210eab
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
28 changes: 28 additions & 0 deletions autode/ext/ade_idpp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ from autode.log import logger
import logging
from autode.ext.wrappers cimport calculate_idpp_path


def get_interpolated_path(
init_coords: np.ndarray,
final_coords: np.ndarray,
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)
"""
pass

class IDPP:
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion autode/ext/include/arrayhelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,4 @@ namespace arrx {

}

#endif // ADE_ARRX_HELPER_HPP
#endif // ADE_ARRX_HELPER_HPP
14 changes: 13 additions & 1 deletion autode/ext/include/idpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace autode
int iter = 0; // current number of iterations
int maxiter; // maximum number of iterations
int n_backtrack = 0; // number of backtracks
double gtol; // gradient tolerance criteria

const double bb_maxstep = 0.02; // max step size for BB
const double sd_maxstep = 0.01; // max step size for SD
Expand All @@ -117,7 +118,7 @@ namespace autode
double en, last_en; // current & last energies
arrx::array1d step;

explicit BBMinimiser(int max_iter);
explicit BBMinimiser(int max_iter, double tol);

void calc_bb_step();

Expand All @@ -134,6 +135,17 @@ namespace autode
void minimise_neb(NEB& neb, const IDPPPotential& pot);
};

/* A struct containing parameters used for IDPP */
struct idpp_params {
double k_spr; // spring constant
bool sequential; // whether sequential IDPP or not
bool debug;
double rmsgtol; // RMS gradient tolerance for path
int maxiter; // maxiter for path
double add_img_gtol; // Max gradient tol. for adding img
double add_img_maxiter; // maxiter for each image addition
};

void calculate_idpp_path(double* init_coords_ptr,
double* final_coords_ptr,
int coords_len,
Expand Down
21 changes: 13 additions & 8 deletions autode/ext/src/idpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ namespace autode {
int n_added = 4;

while (n_added <= n_images) {
auto opt = BBMinimiser(idpp_config::add_img_maxiter);
auto opt = BBMinimiser(idpp_config::add_img_maxiter,
idpp_config::add_img_maxgtol);
auto conv_idx = opt.min_frontier(*this, frontier, pot);
if (n_added == n_images) break;
this->add_image_next_to(conv_idx);
Expand Down Expand Up @@ -524,12 +525,16 @@ namespace autode {
}
}

BBMinimiser::BBMinimiser(int max_iter)
: maxiter(max_iter) {
BBMinimiser::BBMinimiser(int max_iter, double tol)
: maxiter(max_iter), gtol(tol) {
/* Create a Barzilai-Borwein minimiser
*
* Arguments:
* max_iter: Maximum number of iterations
* tol: Tolerance criteria - for minimising frontier
* images, this is the maximum component of the gradient
* vector, for minimising NEB path, this is the RMS of
* the total gradient
*/
}

Expand Down Expand Up @@ -641,8 +646,8 @@ namespace autode {
std::cout << " Energies = (" << neb.images[idxs.left].en <<
" , " << neb.images[idxs.right].en << " RMS(g) = "
<< arrx::rms_v(grad) << "\n";
if (neb.images[idxs.left].max_g() < idpp_config::add_img_maxgtol
|| neb.images[idxs.right].max_g() < idpp_config::add_img_maxgtol)
if (neb.images[idxs.left].max_g() < gtol
|| neb.images[idxs.right].max_g() < gtol)
{
break;
}
Expand Down Expand Up @@ -684,7 +689,7 @@ namespace autode {
auto curr_rms_g = arrx::rms_v(grad);
if (idpp_config::debug_pr) std::cout << " Path energy = " << en
<< " RMS grad = " << curr_rms_g << "\n";
if (curr_rms_g < idpp_config::path_rmsgtol) break;
if (curr_rms_g < gtol) break;
this->take_step();
iter++;
neb.set_coords(coords);
Expand Down Expand Up @@ -761,7 +766,7 @@ namespace autode {
} else {
neb.fill_linear_interp();
}
auto opt = BBMinimiser(maxiter);
auto opt = BBMinimiser(maxiter, gtol);
opt.minimise_neb(neb, potential);

// copy the final coordinates to the output array
Expand Down Expand Up @@ -822,7 +827,7 @@ namespace autode {
} else {
neb.fill_linear_interp();
}
auto opt = BBMinimiser(maxiter);
auto opt = BBMinimiser(maxiter, gtol);
opt.minimise_neb(neb, potential);

double dist;
Expand Down
2 changes: 1 addition & 1 deletion autode/ext/wrappers.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ cdef extern from "include/idpp.h" namespace "autode":
int coords_len,
int n_images,
double k_spr,
bool sequential,
bool_t sequential,
double gtol,
int maxiter) except +

0 comments on commit 9210eab

Please sign in to comment.