Skip to content

Commit

Permalink
Add sigma scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
cschran authored and dev-zero committed Dec 8, 2021
1 parent 0704e03 commit 652d16e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 19 deletions.
36 changes: 34 additions & 2 deletions src/nnp_acsf.F
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,15 @@ SUBROUTINE nnp_scale_acsf(nnp, ind, dsymdxyz)
DO j = 1, nnp%n_rad(ind)
nnp%arc(ind)%layer(1)%node(j) = &
nnp%arc(ind)%layer(1)%node(j)/ &
(nnp%rad(ind)%loc_max(j) - nnp%rad(ind)%loc_min(j))
(nnp%rad(ind)%loc_max(j) - nnp%rad(ind)%loc_min(j))* &
(nnp%scmax - nnp%scmin) + nnp%scmin
END DO
off = nnp%n_rad(ind)
DO j = 1, nnp%n_ang(ind)
nnp%arc(ind)%layer(1)%node(j + off) = &
nnp%arc(ind)%layer(1)%node(j + off)/ &
(nnp%ang(ind)%loc_max(j) - nnp%ang(ind)%loc_min(j))
(nnp%ang(ind)%loc_max(j) - nnp%ang(ind)%loc_min(j))* &
(nnp%scmax - nnp%scmin) + nnp%scmin
END DO
END IF
ELSE IF (nnp%scale_acsf) THEN
Expand All @@ -366,6 +368,20 @@ SUBROUTINE nnp_scale_acsf(nnp, ind, dsymdxyz)
(nnp%ang(ind)%loc_max(j) - nnp%ang(ind)%loc_min(j))* &
(nnp%scmax - nnp%scmin) + nnp%scmin
END DO
ELSE IF (nnp%scale_sigma_acsf) THEN
DO j = 1, nnp%n_rad(ind)
nnp%arc(ind)%layer(1)%node(j) = &
(nnp%rad(ind)%y(j) - nnp%rad(ind)%loc_av(j))/ &
nnp%rad(ind)%sigma(j)* &
(nnp%scmax - nnp%scmin) + nnp%scmin
END DO
off = nnp%n_rad(ind)
DO j = 1, nnp%n_ang(ind)
nnp%arc(ind)%layer(1)%node(j + off) = &
(nnp%ang(ind)%y(j) - nnp%ang(ind)%loc_av(j))/ &
nnp%ang(ind)%sigma(j)* &
(nnp%scmax - nnp%scmin) + nnp%scmin
END DO
ELSE
DO j = 1, nnp%n_rad(ind)
nnp%arc(ind)%layer(1)%node(j) = nnp%rad(ind)%y(j)
Expand Down Expand Up @@ -395,6 +411,22 @@ SUBROUTINE nnp_scale_acsf(nnp, ind, dsymdxyz)
(nnp%scmax - nnp%scmin)
END DO
END DO
ELSE IF (nnp%scale_sigma_acsf) THEN
DO k = 1, nnp%num_atoms
DO j = 1, nnp%n_rad(ind)
dsymdxyz(:, j, k) = dsymdxyz(:, j, k)/ &
nnp%rad(ind)%sigma(j)* &
(nnp%scmax - nnp%scmin)
END DO
END DO
off = nnp%n_rad(ind)
DO k = 1, nnp%num_atoms
DO j = 1, nnp%n_ang(ind)
dsymdxyz(:, j + off, k) = dsymdxyz(:, j + off, k)/ &
nnp%ang(ind)%sigma(j)* &
(nnp%scmax - nnp%scmin)
END DO
END DO
END IF
END IF

Expand Down
66 changes: 55 additions & 11 deletions src/nnp_environment.F
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,14 @@ SUBROUTINE nnp_init_model(nnp_env)
CHARACTER(len=2) :: ele
CHARACTER(len=def_str_len) :: dummy, line
CHARACTER(len=default_path_length) :: base_name, file_name
INTEGER :: handle, i, i_com, iweight, j, k, l, &
INTEGER :: handle, i, i_com, io, iweight, j, k, l, &
n_weight, nele, nuc_ele, symfnct_type, &
unit_nr
LOGICAL :: at_end, atom_e_found, explicit, first, &
found
REAL(KIND=dp) :: energy
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: weights
REAL(KIND=dp), DIMENSION(7) :: test_array
REAL(KIND=dp), DIMENSION(:), POINTER :: work
TYPE(cp_logger_type), POINTER :: logger
TYPE(cp_parser_type), POINTER :: parser
Expand Down Expand Up @@ -292,6 +293,7 @@ SUBROUTINE nnp_init_model(nnp_env)

! read number of elements and cut_type and check for scale and center
nnp_env%scale_acsf = .FALSE.
nnp_env%scale_sigma_acsf = .FALSE.
! Defaults for scale min and max:
nnp_env%scmin = 0.0_dp
nnp_env%scmax = 1.0_dp
Expand All @@ -318,7 +320,11 @@ SUBROUTINE nnp_init_model(nnp_env)

CALL parser_search_string(parser, "scale_symmetry_functions_sigma", .TRUE., found, &
search_from_begin_of_file=.TRUE.)
IF (found) CPABORT("NNP| Option scale_symmetry_functions_sigma not yet supported.")
nnp_env%scale_sigma_acsf = found
! keywords are identical up to ending
IF (nnp_env%scale_acsf .AND. nnp_env%scale_sigma_acsf) THEN
nnp_env%scale_acsf = .FALSE.
END IF

CALL parser_search_string(parser, "scale_min_short_atomic", .TRUE., found, line, &
search_from_begin_of_file=.TRUE.)
Expand All @@ -331,6 +337,10 @@ SUBROUTINE nnp_init_model(nnp_env)
CALL parser_search_string(parser, "center_symmetry_functions", .TRUE., found, &
search_from_begin_of_file=.TRUE.)
nnp_env%center_acsf = found
! n2p2 overwrites sigma scaling, if centering is requested:
IF (nnp_env%scale_sigma_acsf .AND. nnp_env%center_acsf) THEN
nnp_env%scale_sigma_acsf = .FALSE.
END IF

CALL parser_search_string(parser, "normalize_nodes", .TRUE., found, &
search_from_begin_of_file=.TRUE.)
Expand Down Expand Up @@ -491,6 +501,7 @@ SUBROUTINE nnp_init_model(nnp_env)
ALLOCATE (nnp_env%rad(i)%loc_min(nnp_env%n_rad(i)))
ALLOCATE (nnp_env%rad(i)%loc_max(nnp_env%n_rad(i)))
ALLOCATE (nnp_env%rad(i)%loc_av(nnp_env%n_rad(i)))
ALLOCATE (nnp_env%rad(i)%sigma(nnp_env%n_rad(i)))
ALLOCATE (nnp_env%rad(i)%ele(nnp_env%n_rad(i)))
ALLOCATE (nnp_env%rad(i)%nuc_ele(nnp_env%n_rad(i)))
nnp_env%rad(i)%funccut = 0.0_dp
Expand All @@ -508,6 +519,7 @@ SUBROUTINE nnp_init_model(nnp_env)
ALLOCATE (nnp_env%ang(i)%loc_min(nnp_env%n_ang(i)))
ALLOCATE (nnp_env%ang(i)%loc_max(nnp_env%n_ang(i)))
ALLOCATE (nnp_env%ang(i)%loc_av(nnp_env%n_ang(i)))
ALLOCATE (nnp_env%ang(i)%sigma(nnp_env%n_ang(i)))
ALLOCATE (nnp_env%ang(i)%ele1(nnp_env%n_ang(i)))
ALLOCATE (nnp_env%ang(i)%ele2(nnp_env%n_ang(i)))
ALLOCATE (nnp_env%ang(i)%nuc_ele1(nnp_env%n_ang(i)))
Expand Down Expand Up @@ -611,27 +623,59 @@ SUBROUTINE nnp_init_model(nnp_env)
CALL nnp_write_arc(nnp_env, logger%para_env)

! read scaling information from file
IF (nnp_env%scale_acsf .OR. nnp_env%center_acsf) THEN
IF (nnp_env%scale_acsf .OR. nnp_env%center_acsf .OR. nnp_env%scale_sigma_acsf) THEN
IF (logger%para_env%ionode) THEN
WRITE (unit_nr, *) "NNP| Reading scaling information from file: ", TRIM(file_name)
END IF
CALL section_vals_val_get(nnp_env%nnp_input, "SCALE_FILE_NAME", &
c_val=file_name)
CALL parser_create(parser, file_name, para_env=logger%para_env)

! Get number of elements in scaling file
CALL parser_read_line(parser, 1)
k = 0
DO WHILE (k < 7)
READ (parser%input_line, *, IOSTAT=io) test_array(1:k)
IF (io == -1) EXIT
k = k + 1
END DO
k = k - 1

IF (k == 5 .AND. nnp_env%scale_sigma_acsf) THEN
CPABORT("Sigma scaling requested, but scaling.data does not contain sigma.")
END IF

CALL parser_reset(parser)
DO i = 1, nnp_env%n_ele
DO j = 1, nnp_env%n_rad(i)
CALL parser_read_line(parser, 1)
READ (parser%input_line, *) dummy, dummy, &
nnp_env%rad(i)%loc_min(j), &
nnp_env%rad(i)%loc_max(j), &
nnp_env%rad(i)%loc_av(j)
IF (nnp_env%scale_sigma_acsf) THEN
READ (parser%input_line, *) dummy, dummy, &
nnp_env%rad(i)%loc_min(j), &
nnp_env%rad(i)%loc_max(j), &
nnp_env%rad(i)%loc_av(j), &
nnp_env%rad(i)%sigma(j)
ELSE
READ (parser%input_line, *) dummy, dummy, &
nnp_env%rad(i)%loc_min(j), &
nnp_env%rad(i)%loc_max(j), &
nnp_env%rad(i)%loc_av(j)
END IF
END DO
DO j = 1, nnp_env%n_ang(i)
CALL parser_read_line(parser, 1)
READ (parser%input_line, *) dummy, dummy, &
nnp_env%ang(i)%loc_min(j), &
nnp_env%ang(i)%loc_max(j), &
nnp_env%ang(i)%loc_av(j)
IF (nnp_env%scale_sigma_acsf) THEN
READ (parser%input_line, *) dummy, dummy, &
nnp_env%ang(i)%loc_min(j), &
nnp_env%ang(i)%loc_max(j), &
nnp_env%ang(i)%loc_av(j), &
nnp_env%ang(i)%sigma(j)
ELSE
READ (parser%input_line, *) dummy, dummy, &
nnp_env%ang(i)%loc_min(j), &
nnp_env%ang(i)%loc_max(j), &
nnp_env%ang(i)%loc_av(j)
END IF
END DO
END DO
CALL parser_release(parser)
Expand Down
19 changes: 13 additions & 6 deletions src/nnp_environment_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ MODULE nnp_environment_types
CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele ! elements(n_ele)
INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele ! elements(n_ele)
LOGICAL :: scale_acsf
LOGICAL :: scale_sigma_acsf
LOGICAL :: center_acsf
LOGICAL :: normnodes
INTEGER :: n_radgrp
Expand Down Expand Up @@ -163,9 +164,10 @@ MODULE nnp_environment_types
!> \param funccut - distance cutoff bohr - DIM(n_rad)
!> \param eta - eta parameter of radial sym fncts bohr^-2 - DIM(n_rad)
!> \param rs - r shift parameter of radial sym fncts bohr - DIM(n_rad)
!> \param loc_min - minimum of the sym fnct DIM(n_rad,n_com)
!> \param loc_max - maximum of the sym fnct DIM(n_rad,n_com)
!> \param loc_av - average of the sym fnct DIM(n_rad,n_com)
!> \param loc_min - minimum of the sym fnct DIM(n_rad)
!> \param loc_max - maximum of the sym fnct DIM(n_rad)
!> \param loc_av - average of the sym fnct DIM(n_rad)
!> \param sigma - SD of the sym fnc DIM(n_rad)
!> \param ele - element associated to the sym fnct DIM(n_rad)
!> \param nuc_ele - associated atomic number DIM(n_rad)
!> \author Christoph Schran (christoph.schran@rub.de)
Expand All @@ -179,6 +181,7 @@ MODULE nnp_environment_types
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_min
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_max
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_av
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: sigma
CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele
INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele
INTEGER :: n_symfgrp
Expand All @@ -192,9 +195,10 @@ MODULE nnp_environment_types
!> \param eta - eta param. of angular sym fncts bohr^-2 - DIM(n_ang)
!> \param zeta - zeta param. of angular sym fncts DIM(n_ang)
!> \param lam - lambda param. of angular sym fncts DIM(n_ang)
!> \param loc_min - minimum of the sym fnct DIM(n_ang,n_com)
!> \param loc_max - maximum of the sym fnct DIM(n_ang,n_com)
!> \param loc_av - average of the sym fnct DIM(n_ang,n_com)
!> \param loc_min - minimum of the sym fnct DIM(n_ang)
!> \param loc_max - maximum of the sym fnct DIM(n_ang)
!> \param loc_av - average of the sym fnct DIM(n_ang)
!> \param sigma - SD of the sym fnc DIM(n_ang)
!> \param ele1,ele2 - elements associated to the sym fnct DIM(n_ang)
!> \param nuc_ele2, nuc_ele2 - associated atomic numbers DIM(n_ang)
!> \author Christoph Schran (christoph.schran@rub.de)
Expand All @@ -210,6 +214,7 @@ MODULE nnp_environment_types
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_min
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_max
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_av
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: sigma
CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele1
CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele2
INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele1
Expand Down Expand Up @@ -333,6 +338,7 @@ SUBROUTINE nnp_env_release(nnp_env)
nnp_env%rad(i)%loc_min, &
nnp_env%rad(i)%loc_max, &
nnp_env%rad(i)%loc_av, &
nnp_env%rad(i)%sigma, &
nnp_env%rad(i)%ele, &
nnp_env%rad(i)%nuc_ele, &
nnp_env%rad(i)%symfgrp)
Expand All @@ -356,6 +362,7 @@ SUBROUTINE nnp_env_release(nnp_env)
nnp_env%ang(i)%loc_min, &
nnp_env%ang(i)%loc_max, &
nnp_env%ang(i)%loc_av, &
nnp_env%ang(i)%sigma, &
nnp_env%ang(i)%ele1, &
nnp_env%ang(i)%ele2, &
nnp_env%ang(i)%nuc_ele1, &
Expand Down

0 comments on commit 652d16e

Please sign in to comment.