Line data Source code
1 : /*----------------------------------------------------------------------------*/
2 : /* CP2K: A general program to perform molecular dynamics simulations */
3 : /* Copyright 2000-2026 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 2073456 : libgrpp_shell_t *libgrpp_new_shell(double *origin, int L, int num_primitives,
33 : double *coeffs, double *alpha) {
34 2073456 : libgrpp_shell_t *shell = (libgrpp_shell_t *)malloc(sizeof(libgrpp_shell_t));
35 :
36 2073456 : shell->L = L;
37 2073456 : shell->origin[0] = origin[0];
38 2073456 : shell->origin[1] = origin[1];
39 2073456 : shell->origin[2] = origin[2];
40 2073456 : shell->cart_size = (L + 1) * (L + 2) / 2;
41 2073456 : shell->cart_list = libgrpp_generate_shell_cartesians(L);
42 :
43 2073456 : shell->num_primitives = num_primitives;
44 2073456 : shell->coeffs = (double *)calloc(num_primitives, sizeof(double));
45 2073456 : shell->alpha = (double *)calloc(num_primitives, sizeof(double));
46 4146912 : for (int i = 0; i < num_primitives; i++) {
47 2073456 : shell->coeffs[i] = coeffs[i];
48 2073456 : shell->alpha[i] = alpha[i];
49 : }
50 :
51 2073456 : return shell;
52 : }
53 :
54 : /**
55 : * creates deep copy of the 'libgrpp_shell_t' object
56 : */
57 987422 : libgrpp_shell_t *libgrpp_shell_deep_copy(libgrpp_shell_t *src_shell) {
58 1974844 : libgrpp_shell_t *new_shell = libgrpp_new_shell(
59 987422 : src_shell->origin, src_shell->L, src_shell->num_primitives,
60 : src_shell->coeffs, src_shell->alpha);
61 :
62 987422 : return new_shell;
63 : }
64 :
65 : /**
66 : * removes primitive gaussians (from the contracted function)
67 : * with zero coefficients
68 : */
69 987422 : void libgrpp_shell_shrink(libgrpp_shell_t *shell) {
70 987422 : int nprim = 0;
71 :
72 1974844 : for (int i = 0; i < shell->num_primitives; i++) {
73 987422 : if (fabs(shell->coeffs[i]) > LIBGRPP_ZERO_THRESH) {
74 987422 : shell->coeffs[nprim] = shell->coeffs[i];
75 987422 : shell->alpha[nprim] = shell->alpha[i];
76 987422 : nprim++;
77 : }
78 : }
79 :
80 987422 : shell->num_primitives = nprim;
81 987422 : }
82 :
83 : /**
84 : * multiplies coefficients of the primitive gaussians by their normalization
85 : * factors
86 : */
87 987422 : void libgrpp_shell_mult_normcoef(libgrpp_shell_t *shell) {
88 1974844 : for (int i = 0; i < shell->num_primitives; i++) {
89 987422 : double norm_factor =
90 987422 : libgrpp_gaussian_norm_factor(shell->L, 0, 0, shell->alpha[i]);
91 987422 : shell->coeffs[i] *= norm_factor;
92 : }
93 987422 : }
94 :
95 : /**
96 : * returns number of Cartesian primitives encapsulated inside the shell
97 : */
98 1086034 : int libgrpp_get_shell_size(libgrpp_shell_t *shell) { return shell->cart_size; }
99 :
100 : /**
101 : * destructor for the shell object
102 : */
103 2073456 : void libgrpp_delete_shell(libgrpp_shell_t *shell) {
104 2073456 : free(shell->cart_list);
105 2073456 : free(shell->coeffs);
106 2073456 : free(shell->alpha);
107 2073456 : free(shell);
108 2073456 : }
109 :
110 2073456 : int *libgrpp_generate_shell_cartesians(int L) {
111 2073456 : int ncart = (L + 1) * (L + 2) / 2;
112 :
113 2073456 : int *cart_list = (int *)calloc(3 * ncart, sizeof(int));
114 2073456 : libgrpp_params.cartesian_generator(L, cart_list);
115 :
116 2073456 : return cart_list;
117 : }
|