Line data Source code
1 : /*----------------------------------------------------------------------------*/ 2 : /* CP2K: A general program to perform molecular dynamics simulations */ 3 : /* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */ 4 : /* */ 5 : /* SPDX-License-Identifier: MIT */ 6 : /*----------------------------------------------------------------------------*/ 7 : 8 : /* 9 : * libgrpp - a library for the evaluation of integrals over 10 : * generalized relativistic pseudopotentials. 11 : * 12 : * Copyright (C) 2021-2023 Alexander Oleynichenko 13 : */ 14 : 15 : /* 16 : * representation of atom-centered shell of contracted Gaussian functions 17 : */ 18 : #include <math.h> 19 : #include <stdlib.h> 20 : 21 : #ifndef M_PI 22 : #define M_PI 3.1415926535897932384626433 23 : #endif 24 : 25 : #include "libgrpp.h" 26 : 27 : #include "grpp_norm_gaussian.h" 28 : 29 : /** 30 : * constructs new object representing a shell; returns pointer to it. 31 : */ 32 574678 : libgrpp_shell_t *libgrpp_new_shell(double *origin, int L, int num_primitives, 33 : double *coeffs, double *alpha) { 34 574678 : libgrpp_shell_t *shell = (libgrpp_shell_t *)malloc(sizeof(libgrpp_shell_t)); 35 : 36 574678 : shell->L = L; 37 574678 : shell->origin[0] = origin[0]; 38 574678 : shell->origin[1] = origin[1]; 39 574678 : shell->origin[2] = origin[2]; 40 574678 : shell->cart_size = (L + 1) * (L + 2) / 2; 41 574678 : shell->cart_list = libgrpp_generate_shell_cartesians(L); 42 : 43 574678 : shell->num_primitives = num_primitives; 44 574678 : shell->coeffs = (double *)calloc(num_primitives, sizeof(double)); 45 574678 : shell->alpha = (double *)calloc(num_primitives, sizeof(double)); 46 1149356 : for (int i = 0; i < num_primitives; i++) { 47 574678 : shell->coeffs[i] = coeffs[i]; 48 574678 : shell->alpha[i] = alpha[i]; 49 : } 50 : 51 574678 : return shell; 52 : } 53 : 54 : /** 55 : * creates deep copy of the 'libgrpp_shell_t' object 56 : */ 57 275414 : libgrpp_shell_t *libgrpp_shell_deep_copy(libgrpp_shell_t *src_shell) { 58 550828 : libgrpp_shell_t *new_shell = libgrpp_new_shell( 59 275414 : src_shell->origin, src_shell->L, src_shell->num_primitives, 60 : src_shell->coeffs, src_shell->alpha); 61 : 62 275414 : return new_shell; 63 : } 64 : 65 : /** 66 : * removes primitive gaussians (from the contracted function) 67 : * with zero coefficients 68 : */ 69 275414 : void libgrpp_shell_shrink(libgrpp_shell_t *shell) { 70 275414 : int nprim = 0; 71 : 72 550828 : for (int i = 0; i < shell->num_primitives; i++) { 73 275414 : if (fabs(shell->coeffs[i]) > LIBGRPP_ZERO_THRESH) { 74 275414 : shell->coeffs[nprim] = shell->coeffs[i]; 75 275414 : shell->alpha[nprim] = shell->alpha[i]; 76 275414 : nprim++; 77 : } 78 : } 79 : 80 275414 : shell->num_primitives = nprim; 81 275414 : } 82 : 83 : /** 84 : * multiplies coefficients of the primitive gaussians by their normalization 85 : * factors 86 : */ 87 275414 : void libgrpp_shell_mult_normcoef(libgrpp_shell_t *shell) { 88 550828 : for (int i = 0; i < shell->num_primitives; i++) { 89 275414 : double norm_factor = 90 275414 : libgrpp_gaussian_norm_factor(shell->L, 0, 0, shell->alpha[i]); 91 275414 : shell->coeffs[i] *= norm_factor; 92 : } 93 275414 : } 94 : 95 : /** 96 : * returns number of Cartesian primitives encapsulated inside the shell 97 : */ 98 299264 : int libgrpp_get_shell_size(libgrpp_shell_t *shell) { return shell->cart_size; } 99 : 100 : /** 101 : * destructor for the shell object 102 : */ 103 574678 : void libgrpp_delete_shell(libgrpp_shell_t *shell) { 104 574678 : free(shell->cart_list); 105 574678 : free(shell->coeffs); 106 574678 : free(shell->alpha); 107 574678 : free(shell); 108 574678 : } 109 : 110 574678 : int *libgrpp_generate_shell_cartesians(int L) { 111 574678 : int ncart = (L + 1) * (L + 2) / 2; 112 : 113 574678 : int *cart_list = (int *)calloc(3 * ncart, sizeof(int)); 114 574678 : libgrpp_params.cartesian_generator(L, cart_list); 115 : 116 574678 : return cart_list; 117 : }