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