From 8f2eb5db560fd789fa57ec1f15441278b07d1d3e Mon Sep 17 00:00:00 2001 From: marvinfriede <51965259+marvinfriede@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:53:20 +0100 Subject: [PATCH 1/3] Add dedr tests for charged systems --- test/test_model.f90 | 74 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/test/test_model.f90 b/test/test_model.f90 index 5a5e3df7..c3065309 100644 --- a/test/test_model.f90 +++ b/test/test_model.f90 @@ -16,7 +16,7 @@ module test_model use mctc_env, only : wp use mctc_env_testing, only : new_unittest, unittest_type, error_type, check, test_failed - use mctc_io_structure, only : structure_type + use mctc_io_structure, only : structure_type, new use mstore, only : get_structure use multicharge_data, only : get_covalent_rad use multicharge_model @@ -55,7 +55,10 @@ subroutine collect_model(testsuite) & new_unittest("dqdr-mb09", test_dqdr_mb09), & & new_unittest("dqdr-mb10", test_dqdr_mb10), & & new_unittest("dqdL-mb11", test_dqdL_mb11), & - & new_unittest("dqdL-mb12", test_dqdL_mb12) & + & new_unittest("dqdL-mb12", test_dqdL_mb12), & + & new_unittest("gradient-h2plus", test_g_h2plus), & + & new_unittest("gradient-znooh", test_g_znooh), & + & new_unittest("dqdr-znooh", test_dqdr_znooh) & & ] end subroutine collect_model @@ -601,4 +604,71 @@ subroutine test_dqdL_mb12(error) end subroutine test_dqdL_mb12 +subroutine test_g_h2plus(error) + + !> Error handling + type(error_type), allocatable, intent(out) :: error + + type(structure_type) :: mol + + integer, parameter :: nat = 2 + real(wp), parameter :: charge = 1.0_wp + integer, parameter :: num(nat) = [1, 1] + real(wp), parameter :: xyz(3, nat) = reshape([ & + & +0.00000000000000_wp, +0.00000000000000_wp, +0.00000000000000_wp, & + & +1.00000000000000_wp, +0.00000000000000_wp, +0.00000000000000_wp],& + & [3, nat]) + + call new(mol, num, xyz, charge) + call test_numgrad(error, mol) + +end subroutine test_g_h2plus + + +subroutine test_g_znooh(error) + + !> Error handling + type(error_type), allocatable, intent(out) :: error + + type(structure_type) :: mol + + integer, parameter :: nat = 4 + real(wp), parameter :: charge = -1.0_wp + integer, parameter :: num(nat) = [30, 8, 8, 1] + real(wp), parameter :: xyz(3, nat) = reshape([ & + & -0.30631629283878_wp, -1.11507514203552_wp, +0.00000000000000_wp, & + & -0.06543072660074_wp, -4.32862093666082_wp, +0.00000000000000_wp, & + & -0.64012239724097_wp, +2.34966763895920_wp, +0.00000000000000_wp, & + & +1.01186941668051_wp, +3.09402843973713_wp, +0.00000000000000_wp],& + & [3, nat]) + + call new(mol, num, xyz, charge) + call test_numgrad(error, mol) + +end subroutine test_g_znooh + + +subroutine test_dqdr_znooh(error) + + !> Error handling + type(error_type), allocatable, intent(out) :: error + + type(structure_type) :: mol + + integer, parameter :: nat = 4 + real(wp), parameter :: charge = -1.0_wp + integer, parameter :: num(nat) = [30, 8, 8, 1] + real(wp), parameter :: xyz(3, nat) = reshape([ & + & -0.30631629283878_wp, -1.11507514203552_wp, +0.00000000000000_wp, & + & -0.06543072660074_wp, -4.32862093666082_wp, +0.00000000000000_wp, & + & -0.64012239724097_wp, +2.34966763895920_wp, +0.00000000000000_wp, & + & +1.01186941668051_wp, +3.09402843973713_wp, +0.00000000000000_wp],& + & [3, nat]) + + call new(mol, num, xyz, charge) + call test_numdqdr(error, mol) + +end subroutine test_dqdr_znooh + + end module test_model From 084ddfc4a433f5dcb3cc02e6c6c0ba7920527919 Mon Sep 17 00:00:00 2001 From: thfroitzheim <92028749+thfroitzheim@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:02:18 +0100 Subject: [PATCH 2/3] Remove Lagrange-multiplier from the electrostatic energy (fixes charged gradient) --- src/multicharge/model.F90 | 3 ++- test/unit/test_model.f90 | 24 ++++++++++++------------ test/unit/test_pbc.f90 | 17 ++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/multicharge/model.F90 b/src/multicharge/model.F90 index 6d2b28e3..ac57c027 100644 --- a/src/multicharge/model.F90 +++ b/src/multicharge/model.F90 @@ -494,7 +494,8 @@ subroutine solve(self, mol, cn, dcndr, dcndL, energy, gradient, sigma, qvec, dqd end if if (present(energy)) then - call symv(amat, vrhs, xvec, alpha=0.5_wp, beta=-1.0_wp, uplo='l') + call symv(amat(:, :mol%nat), vrhs(:mol%nat), xvec(:mol%nat), & + & alpha=0.5_wp, beta=-1.0_wp, uplo='l') energy(:) = energy(:) + vrhs(:mol%nat) * xvec(:mol%nat) end if diff --git a/test/unit/test_model.f90 b/test/unit/test_model.f90 index 770d368d..68a5dd93 100644 --- a/test/unit/test_model.f90 +++ b/test/unit/test_model.f90 @@ -467,12 +467,12 @@ subroutine test_e_mb03(error) type(structure_type) :: mol real(wp), parameter :: ref(16) = [& - &-1.13826350631987E-1_wp,-5.62509056571450E-1_wp, 2.40314584307323E-2_wp, & - & 2.34612384482528E-1_wp, 3.24513111881020E-1_wp, 4.02366323905675E-2_wp, & - &-2.17529318207133E-1_wp, 2.75364844977006E-2_wp, 4.02137369467059E-2_wp, & - & 5.04840322940993E-2_wp,-3.53634572772168E-1_wp,-1.87985748794416E-1_wp, & - &-2.52739835528964E-1_wp, 1.24520645208966E-1_wp, 2.69468093358888E-1_wp, & - & 2.15919407508634E-2_wp] + &-2.18698345033562E-1_wp,-1.04793885931268E+0_wp, 4.78963353574572E-2_wp, & + & 5.76566377591676E-1_wp, 7.37187470977927E-1_wp, 8.06020047053305E-2_wp, & + &-4.19837955782898E-1_wp, 5.49627510550566E-2_wp, 8.01486728591565E-2_wp, & + & 1.00618944521776E-1_wp,-6.61715169034150E-1_wp,-3.60531647289563E-1_wp, & + &-4.87729666337974E-1_wp, 2.48257554279938E-1_wp, 6.96027176590956E-1_wp, & + & 4.31679925875087E-2_wp] call get_structure(mol, "MB16-43", "03") call gen_test(error, mol, eref=ref) @@ -487,12 +487,12 @@ subroutine test_e_mb04(error) type(structure_type) :: mol real(wp), parameter :: ref(16) = [& - & 5.48650497749607E-2_wp,-2.25780913208624E-1_wp, 4.35281631902307E-2_wp, & - &-1.57205780814366E-1_wp, 4.09837366864403E-3_wp, 6.31282692438352E-2_wp, & - & 7.48306233723622E-2_wp, 5.87730150647742E-2_wp, 6.10308494414398E-2_wp, & - & 8.63933930367129E-2_wp,-9.99483536957020E-2_wp, 2.02497843626054E-1_wp, & - & 3.47529062386466E-2_wp,-2.37058804560779E-1_wp, 6.74225102943070E-2_wp, & - &-1.36552339896561E-1_wp] + & 1.13974214746111E-1_wp,-4.41735365367827E-1_wp, 8.99036489938394E-2_wp, & + &-2.97539904703271E-1_wp, 8.05174117097006E-3_wp, 1.31105783760276E-1_wp, & + & 1.54594451996644E-1_wp, 1.19929653841255E-1_wp, 1.26056586309101E-1_wp, & + & 1.78439005754586E-1_wp,-1.98703462666082E-1_wp, 4.19630120027785E-1_wp, & + & 7.05569220334930E-2_wp,-4.50925107441869E-1_wp, 1.39289602382354E-1_wp, & + &-2.67853086061429E-1_wp] call get_structure(mol, "MB16-43", "04") call gen_test(error, mol, eref=ref) diff --git a/test/unit/test_pbc.f90 b/test/unit/test_pbc.f90 index bb245bbc..6849e2b6 100644 --- a/test/unit/test_pbc.f90 +++ b/test/unit/test_pbc.f90 @@ -419,15 +419,14 @@ subroutine test_e_formamide(error) type(structure_type) :: mol real(wp), parameter :: ref(24) = [& - & 1.89757620852359E-1_wp, 1.89760760029133E-1_wp, 1.89737950594800E-1_wp, & - & 1.89748797090202E-1_wp, 2.03099343220260E-1_wp, 2.03086622963944E-1_wp, & - & 2.03077163423409E-1_wp, 2.03088145719017E-1_wp, 8.99074841863554E-2_wp, & - & 8.99082451986937E-2_wp, 8.99093436347654E-2_wp, 8.99109153737500E-2_wp, & - & 1.64940329265701E-1_wp, 1.64930611448213E-1_wp, 1.64944104143581E-1_wp, & - & 1.64952535219774E-1_wp,-4.28537080109528E-1_wp,-4.28526505049323E-1_wp, & - &-4.28489488988212E-1_wp,-4.28513466458521E-1_wp,-3.29599028782344E-1_wp, & - &-3.29588887030536E-1_wp,-3.29602200135643E-1_wp,-3.29600393007701E-1_wp] - + & 4.01878116759118E-1_wp, 4.01884779867146E-1_wp, 4.01836430415694E-1_wp, & + & 4.01859412981015E-1_wp, 4.30132679242368E-1_wp, 4.30105708698129E-1_wp, & + & 4.30085668404029E-1_wp, 4.30108945050621E-1_wp, 1.90400193163051E-1_wp, & + & 1.90401822781550E-1_wp, 1.90404130981992E-1_wp, 1.90407447306916E-1_wp, & + & 3.33868335196572E-1_wp, 3.33848682655264E-1_wp, 3.33875977331594E-1_wp, & + & 3.33893030511429E-1_wp,-8.35635584733599E-1_wp,-8.35614926719694E-1_wp, & + &-8.35542684637248E-1_wp,-8.35589488474056E-1_wp,-6.31079122091240E-1_wp, & + &-6.31059677948463E-1_wp,-6.31085206912995E-1_wp,-6.31081747027041E-1_wp] call get_structure(mol, "X23", "formamide") call gen_test(error, mol, eref=ref) From 39707aff5778a2dc06d9285f8906ca1f3871df19 Mon Sep 17 00:00:00 2001 From: thfroitzheim <92028749+thfroitzheim@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:11:17 +0100 Subject: [PATCH 3/3] Update validation --- test/validation/01_h3+/multicharge_ref.json | 22 +++--- .../03_etlicl-/multicharge_ref.json | 72 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/test/validation/01_h3+/multicharge_ref.json b/test/validation/01_h3+/multicharge_ref.json index f0628165..100721d4 100644 --- a/test/validation/01_h3+/multicharge_ref.json +++ b/test/validation/01_h3+/multicharge_ref.json @@ -1,21 +1,21 @@ { - "version": "0.2.0", - "energy": 5.9509615561036766E-01, + "version": "0.3.0", + "energy": 1.5766947458356364E+00, "gradient": [ - -3.8496744880950964E-03, - 6.6678318059824465E-03, + -3.8496744880951068E-03, + 6.6678318059824847E-03, 0.0000000000000000E+00, - -3.8496744880951173E-03, - -6.6678318059824535E-03, + -3.8496744880951311E-03, + -6.6678318059824916E-03, 0.0000000000000000E+00, - 7.6993489761902068E-03, - 1.2143064331837650E-17, + 7.6993489761902484E-03, + 8.6736173798840355E-18, 0.0000000000000000E+00 ], "charges": [ - 3.3333333333333348E-01, - 3.3333333333333304E-01, - 3.3333333333333337E-01 + 3.3333333333333326E-01, + 3.3333333333333282E-01, + 3.3333333333333326E-01 ], "coordination numbers": [ 9.0462899697901555E-01, diff --git a/test/validation/03_etlicl-/multicharge_ref.json b/test/validation/03_etlicl-/multicharge_ref.json index 6effd3be..71146700 100644 --- a/test/validation/03_etlicl-/multicharge_ref.json +++ b/test/validation/03_etlicl-/multicharge_ref.json @@ -1,43 +1,43 @@ { - "version": "0.2.0", - "energy": -8.1229405654410192E-01, + "version": "0.3.0", + "energy": -1.2655150253649601E+00, "gradient": [ - 1.4232201382417559E-05, - -1.0290897995788412E-02, - -4.8111471404044259E-19, - 8.8181192331940640E-03, - 1.6040868979181680E-02, - -2.1684043449710089E-19, - -1.1262761030204154E-03, - -7.9344514548550888E-04, - -6.7762635780344027E-21, - 7.6009524154963947E-04, - -7.1958985135979090E-04, - 1.1312329300021994E-03, - 7.6009524154963903E-04, - -7.1958985135979036E-04, - -1.1312329300021988E-03, - -7.6669966088608894E-04, - 6.8324957888392694E-04, - 1.1831223238083551E-03, - -7.6669966088608894E-04, - 6.8324957888392704E-04, - -1.1831223238083551E-03, - 2.6974466454641639E-03, - 1.2199223431970472E-05, - 5.4210108624275222E-20, - -1.0390313138347335E-02, - -4.8960445163879988E-03, - -1.3552527156068805E-20 + 1.4232201382419511E-05, + -1.0290897995788414E-02, + -7.9621097041904232E-19, + 8.8181192331940623E-03, + 1.6040868979181687E-02, + -2.4227803486599938E-19, + -1.1262761030204163E-03, + -7.9344514548550953E-04, + -1.1858461261560205E-20, + 7.6009524154963893E-04, + -7.1958985135979015E-04, + 1.1312329300021985E-03, + 7.6009524154963806E-04, + -7.1958985135978950E-04, + -1.1312329300021975E-03, + -7.6669966088608774E-04, + 6.8324957888392509E-04, + 1.1831223238083525E-03, + -7.6669966088608774E-04, + 6.8324957888392498E-04, + -1.1831223238083525E-03, + 2.6974466454641613E-03, + 1.2199223431968954E-05, + 9.4817310917030215E-20, + -1.0390313138347332E-02, + -4.8960445163879953E-03, + -2.3716922523120409E-20 ], "charges": [ - -3.7490477825182533E-01, - -4.9002846040519082E-01, - -1.3110484383964643E-02, - -1.7219399835397248E-02, - -1.7219399835397234E-02, - -1.2981335776944464E-02, - -1.2981335776944464E-02, + -3.7490477825182544E-01, + -4.9002846040519094E-01, + -1.3110484383964657E-02, + -1.7219399835397220E-02, + -1.7219399835397199E-02, + -1.2981335776944408E-02, + -1.2981335776944408E-02, 5.5301996167376810E-01, -6.1457476740810379E-01 ],