From 731d4cb7f40d01572d37ca7523d69d444fa1e2a8 Mon Sep 17 00:00:00 2001 From: brucefan1983 Date: Sun, 4 Aug 2024 17:28:37 +0800 Subject: [PATCH 1/2] typewise cutoff factors --- src/force/nep3.cu | 41 +++++++++++++++++++---------- src/force/nep3.cuh | 3 +++ src/force/nep3_multigpu.cu | 41 +++++++++++++++++++---------- src/force/nep3_multigpu.cuh | 3 +++ src/force/nep3_small_box.cuh | 24 ++++++++++------- src/main_nep/fitness.cu | 7 ++--- src/main_nep/nep3.cu | 22 +++++++++++----- src/main_nep/nep3.cuh | 3 +++ src/main_nep/parameters.cu | 51 +++++++++++++++++++++++++++++++++--- src/main_nep/parameters.cuh | 3 +++ 10 files changed, 147 insertions(+), 51 deletions(-) diff --git a/src/force/nep3.cu b/src/force/nep3.cu index f71cba1e1..fb3e8cc97 100644 --- a/src/force/nep3.cu +++ b/src/force/nep3.cu @@ -171,8 +171,8 @@ NEP3::NEP3(const char* file_potential, const int num_atoms) // cutoff 4.2 3.7 80 47 1 tokens = get_tokens(input); - if (tokens.size() != 5 && tokens.size() != 7) { - std::cout << "This line should be cutoff rc_radial rc_angular MN_radial MN_angular [use_typewise_cutoff] [use_typewise_cutoff_zbl].\n"; + if (tokens.size() != 5 && tokens.size() != 8) { + std::cout << "This line should be cutoff rc_radial rc_angular MN_radial MN_angular [radial_factor] [angular_factor] [zbl_factor].\n"; exit(1); } paramb.rc_radial = get_float_from_token(tokens[1], __FILE__, __LINE__); @@ -189,9 +189,16 @@ NEP3::NEP3(const char* file_potential, const int num_atoms) printf(" enlarged MN_radial = %d.\n", paramb.MN_radial); printf(" enlarged MN_angular = %d.\n", paramb.MN_angular); - if (tokens.size() == 7) { - paramb.use_typewise_cutoff = get_int_from_token(tokens[5], __FILE__, __LINE__); - paramb.use_typewise_cutoff_zbl = get_int_from_token(tokens[6], __FILE__, __LINE__); + if (tokens.size() == 8) { + paramb.typewise_cutoff_radial_factor = get_float_from_token(tokens[5], __FILE__, __LINE__); + paramb.typewise_cutoff_angular_factor = get_float_from_token(tokens[6], __FILE__, __LINE__); + paramb.typewise_cutoff_zbl_factor = get_float_from_token(tokens[7], __FILE__, __LINE__); + if (paramb.typewise_cutoff_radial_factor > 0.0f) { + paramb.use_typewise_cutoff = true; + } + if (paramb.typewise_cutoff_zbl_factor > 0.0f) { + paramb.use_typewise_cutoff_zbl = true; + } } #ifdef USE_TABLE if (paramb.use_typewise_cutoff) { @@ -510,8 +517,8 @@ static __global__ void find_neighbor_list_large_box( if (paramb.use_typewise_cutoff) { int z1 = paramb.atomic_numbers[t1]; int z2 = paramb.atomic_numbers[t2]; - rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.5f, rc_radial); - rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.0f, rc_angular); + rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_radial_factor, rc_radial); + rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_angular_factor, rc_angular); } if (d12_square >= rc_radial * rc_radial) { @@ -593,7 +600,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -640,7 +648,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -793,7 +802,8 @@ static __global__ void find_force_radial( float fc12, fcp12; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -935,7 +945,8 @@ static __global__ void find_partial_force_angular( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -1045,7 +1056,7 @@ static __global__ void find_force_ZBL( float rc_outer = zbl.rc_outer; if (paramb.use_typewise_cutoff_zbl) { // zi and zj start from 1, so need to minus 1 here - rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * 0.6f, rc_outer); + rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * paramb.typewise_cutoff_zbl_factor, rc_outer); rc_inner = rc_outer * 0.5f; } find_f_and_fp_zbl(zizj, a_inv, rc_inner, rc_outer, d12, d12inv, f, fp); @@ -1571,7 +1582,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -1617,7 +1629,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); diff --git a/src/force/nep3.cuh b/src/force/nep3.cuh index 9f3af45de..b83b10be6 100644 --- a/src/force/nep3.cuh +++ b/src/force/nep3.cuh @@ -49,6 +49,9 @@ public: struct ParaMB { bool use_typewise_cutoff = false; bool use_typewise_cutoff_zbl = false; + float typewise_cutoff_radial_factor = 0.0f; + float typewise_cutoff_angular_factor = 0.0f; + float typewise_cutoff_zbl_factor = 0.0f; int version = 4; // NEP version, 3 for NEP3 and 4 for NEP4 int model_type = 0; // 0=potential, 1=dipole, 2=polarizability, 3=temperature-dependent free energy diff --git a/src/force/nep3_multigpu.cu b/src/force/nep3_multigpu.cu index b3d54e9a1..493f7238a 100644 --- a/src/force/nep3_multigpu.cu +++ b/src/force/nep3_multigpu.cu @@ -173,8 +173,8 @@ NEP3_MULTIGPU::NEP3_MULTIGPU( // cutoff 4.2 3.7 80 47 1 tokens = get_tokens(input); - if (tokens.size() != 5 && tokens.size() != 7) { - std::cout << "This line should be cutoff rc_radial rc_angular MN_radial MN_angular [use_typewise_cutoff] [use_typewise_cutoff_zbl].\n"; + if (tokens.size() != 5 && tokens.size() != 8) { + std::cout << "This line should be cutoff rc_radial rc_angular MN_radial MN_angular [radial_factor] [angular_factor] [zbl_factor].\n"; exit(1); } paramb.rc_radial = get_float_from_token(tokens[1], __FILE__, __LINE__); @@ -191,9 +191,16 @@ NEP3_MULTIGPU::NEP3_MULTIGPU( printf(" enlarged MN_radial = %d.\n", paramb.MN_radial); printf(" enlarged MN_angular = %d.\n", paramb.MN_angular); - if (tokens.size() == 7) { - paramb.use_typewise_cutoff = get_int_from_token(tokens[5], __FILE__, __LINE__); - paramb.use_typewise_cutoff_zbl = get_int_from_token(tokens[6], __FILE__, __LINE__); + if (tokens.size() == 8) { + paramb.typewise_cutoff_radial_factor = get_float_from_token(tokens[5], __FILE__, __LINE__); + paramb.typewise_cutoff_angular_factor = get_float_from_token(tokens[6], __FILE__, __LINE__); + paramb.typewise_cutoff_zbl_factor = get_float_from_token(tokens[7], __FILE__, __LINE__); + if (paramb.typewise_cutoff_radial_factor > 0.0f) { + paramb.use_typewise_cutoff = true; + } + if (paramb.typewise_cutoff_zbl_factor > 0.0f) { + paramb.use_typewise_cutoff_zbl = true; + } } #ifdef USE_TABLE if (paramb.use_typewise_cutoff) { @@ -784,8 +791,8 @@ static __global__ void find_neighbor_list_large_box( if (paramb.use_typewise_cutoff) { int z1 = paramb.atomic_numbers[t1]; int z2 = paramb.atomic_numbers[t2]; - rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.5f, rc_radial); - rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.0f, rc_angular); + rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_radial_factor, rc_radial); + rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_angular_factor, rc_angular); } if (d12_square >= rc_radial * rc_radial) { @@ -866,7 +873,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -912,7 +920,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -1061,7 +1070,8 @@ static __global__ void find_force_radial( float fc12, fcp12; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -1203,7 +1213,8 @@ static __global__ void find_partial_force_angular( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -1312,7 +1323,7 @@ static __global__ void find_force_ZBL( float rc_outer = zbl.rc_outer; if (paramb.use_typewise_cutoff_zbl) { // zi and zj start from 1, so need to minus 1 here - rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * 0.6f, rc_outer); + rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * paramb.typewise_cutoff_zbl_factor, rc_outer); rc_inner = rc_outer * 0.5f; } find_f_and_fp_zbl(zizj, a_inv, rc_inner, rc_outer, d12, d12inv, f, fp); @@ -1972,7 +1983,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -2018,7 +2030,8 @@ static __global__ void find_descriptor( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); diff --git a/src/force/nep3_multigpu.cuh b/src/force/nep3_multigpu.cuh index 8b81de6db..8200d82d6 100644 --- a/src/force/nep3_multigpu.cuh +++ b/src/force/nep3_multigpu.cuh @@ -79,6 +79,9 @@ public: struct ParaMB { bool use_typewise_cutoff = false; bool use_typewise_cutoff_zbl = false; + float typewise_cutoff_radial_factor = 0.0f; + float typewise_cutoff_angular_factor = 0.0f; + float typewise_cutoff_zbl_factor = 0.0f; int num_gpus = 1; int version = 4; // NEP version, 3 for NEP3 and 4 for NEP4 int model_type = diff --git a/src/force/nep3_small_box.cuh b/src/force/nep3_small_box.cuh index 4e99dfef1..d3883c14a 100644 --- a/src/force/nep3_small_box.cuh +++ b/src/force/nep3_small_box.cuh @@ -131,8 +131,8 @@ static __global__ void find_neighbor_list_small_box( if (paramb.use_typewise_cutoff) { int z1 = paramb.atomic_numbers[t1]; int z2 = paramb.atomic_numbers[t2]; - rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.5f, rc_radial); - rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.0f, rc_angular); + rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_radial_factor, rc_radial); + rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_angular_factor, rc_angular); } if (distance_square < rc_radial * rc_radial) { @@ -214,7 +214,8 @@ static __global__ void find_descriptor_small_box( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -257,7 +258,8 @@ static __global__ void find_descriptor_small_box( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -380,7 +382,8 @@ static __global__ void find_descriptor_small_box( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -423,7 +426,8 @@ static __global__ void find_descriptor_small_box( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -524,7 +528,8 @@ static __global__ void find_force_radial_small_box( float fc12, fcp12; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -669,7 +674,8 @@ static __global__ void find_force_angular_small_box( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -801,7 +807,7 @@ static __global__ void find_force_ZBL_small_box( float rc_outer = zbl.rc_outer; if (paramb.use_typewise_cutoff_zbl) { // zi and zj start from 1, so need to minus 1 here - rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * 0.6f, rc_outer); + rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * paramb.typewise_cutoff_zbl_factor, rc_outer); rc_inner = rc_outer * 0.5f; } find_f_and_fp_zbl(zizj, a_inv, rc_inner, rc_outer, d12, d12inv, f, fp); diff --git a/src/main_nep/fitness.cu b/src/main_nep/fitness.cu index 47cbb24ec..539ba4407 100644 --- a/src/main_nep/fitness.cu +++ b/src/main_nep/fitness.cu @@ -312,13 +312,14 @@ void Fitness::write_nep_txt(FILE* fid_nep, Parameters& para, float* elite) if (para.use_typewise_cutoff || para.use_typewise_cutoff_zbl) { fprintf( fid_nep, - "cutoff %g %g %d %d %d %d\n", + "cutoff %g %g %d %d %g %g %g\n", para.rc_radial, para.rc_angular, max_NN_radial, max_NN_angular, - para.use_typewise_cutoff ? 1 : 0, - para.use_typewise_cutoff_zbl ? 1 : 0); + para.typewise_cutoff_radial_factor, + para.typewise_cutoff_angular_factor, + para.typewise_cutoff_zbl_factor); } else { fprintf( fid_nep, diff --git a/src/main_nep/nep3.cu b/src/main_nep/nep3.cu index 760035762..e3e71a3e0 100644 --- a/src/main_nep/nep3.cu +++ b/src/main_nep/nep3.cu @@ -88,8 +88,8 @@ static __global__ void gpu_find_neighbor_list( if (use_typewise_cutoff) { int z1 = paramb.atomic_numbers[t1]; int z2 = paramb.atomic_numbers[t2]; - rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.5f, rc_radial); - rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * 2.0f, rc_angular); + rc_radial = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_radial_factor, rc_radial); + rc_angular = min((COVALENT_RADIUS[z1] + COVALENT_RADIUS[z2]) * paramb.typewise_cutoff_angular_factor, rc_angular); } if (distance_square < rc_radial * rc_radial) { NL_radial[count_radial * N + n1] = n2; @@ -142,7 +142,8 @@ static __global__ void find_descriptors_radial( int t2 = g_type[n2]; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -197,7 +198,8 @@ static __global__ void find_descriptors_angular( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc(rc, rcinv, d12, fc12); @@ -247,6 +249,9 @@ NEP3::NEP3( paramb.rcinv_angular = 1.0f / paramb.rc_angular; paramb.use_typewise_cutoff = para.use_typewise_cutoff; paramb.use_typewise_cutoff_zbl = para.use_typewise_cutoff_zbl; + paramb.typewise_cutoff_radial_factor = para.typewise_cutoff_radial_factor; + paramb.typewise_cutoff_angular_factor = para.typewise_cutoff_angular_factor; + paramb.typewise_cutoff_zbl_factor = para.typewise_cutoff_zbl_factor; paramb.num_types = para.num_types; paramb.n_max_radial = para.n_max_radial; paramb.n_max_angular = para.n_max_angular; @@ -569,7 +574,8 @@ static __global__ void find_force_radial( float fc12, fcp12; float rc = paramb.rc_radial; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.5f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_radial_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -668,7 +674,8 @@ static __global__ void find_force_angular( int t2 = g_type[n2]; float rc = paramb.rc_angular; if (paramb.use_typewise_cutoff) { - rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * 2.0f, rc); + rc = min((COVALENT_RADIUS[paramb.atomic_numbers[t1]] + + COVALENT_RADIUS[paramb.atomic_numbers[t2]]) * paramb.typewise_cutoff_angular_factor, rc); } float rcinv = 1.0f / rc; find_fc_and_fcp(rc, rcinv, d12, fc12, fcp12); @@ -787,7 +794,8 @@ static __global__ void find_force_ZBL( float rc_outer = zbl.rc_outer; if (paramb.use_typewise_cutoff_zbl) { // zi and zj start from 1, so need to minus 1 here - rc_outer = min((COVALENT_RADIUS[zi - 1] + COVALENT_RADIUS[zj - 1]) * 0.6f, rc_outer); + rc_outer = min((COVALENT_RADIUS[zi - 1] + + COVALENT_RADIUS[zj - 1]) * paramb.typewise_cutoff_zbl_factor, rc_outer); rc_inner = rc_outer * 0.5f; } find_f_and_fp_zbl(zizj, a_inv, rc_inner, rc_outer, d12, d12inv, f, fp); diff --git a/src/main_nep/nep3.cuh b/src/main_nep/nep3.cuh index 8c08ad06b..b06daeeaf 100644 --- a/src/main_nep/nep3.cuh +++ b/src/main_nep/nep3.cuh @@ -43,6 +43,9 @@ public: struct ParaMB { bool use_typewise_cutoff = false; bool use_typewise_cutoff_zbl = false; + float typewise_cutoff_radial_factor = 2.5f; + float typewise_cutoff_angular_factor = 2.0f; + float typewise_cutoff_zbl_factor = 0.65f; float rc_radial = 0.0f; // radial cutoff float rc_angular = 0.0f; // angular cutoff float rcinv_radial = 0.0f; // inverse of the radial cutoff diff --git a/src/main_nep/parameters.cu b/src/main_nep/parameters.cu index 53b7852c6..47e7e1f43 100644 --- a/src/main_nep/parameters.cu +++ b/src/main_nep/parameters.cu @@ -101,6 +101,9 @@ void Parameters::set_default_parameters() sigma0 = 0.1f; use_typewise_cutoff = false; use_typewise_cutoff_zbl = false; + typewise_cutoff_radial_factor = -1.0f; + typewise_cutoff_angular_factor = -1.0f; + typewise_cutoff_zbl_factor = -1.0f; type_weight_cpu.resize(NUM_ELEMENTS); zbl_para.resize(550); // Maximum number of zbl parameters @@ -300,12 +303,15 @@ void Parameters::report_inputs() if (is_use_typewise_cutoff_set) { printf(" (input) use %s cutoff for NEP.\n", use_typewise_cutoff ? "typewise" : "global"); + printf(" radial factor = %g.\n", typewise_cutoff_radial_factor); + printf(" angular factor = %g.\n", typewise_cutoff_angular_factor); } else { printf(" (default) use %s cutoff for NEP.\n", use_typewise_cutoff ? "typewise" : "global"); } if (is_use_typewise_cutoff_zbl_set) { printf(" (input) use %s cutoff for ZBL.\n", use_typewise_cutoff_zbl ? "typewise" : "global"); + printf(" factor = %g.\n", typewise_cutoff_zbl_factor); } else { printf(" (default) use %s cutoff for ZBL.\n", use_typewise_cutoff_zbl ? "typewise" : "global"); } @@ -978,18 +984,55 @@ void Parameters::parse_sigma0(const char** param, int num_param) void Parameters::parse_use_typewise_cutoff(const char** param, int num_param) { - if (num_param != 1) { - PRINT_INPUT_ERROR("use_typewise_cutoff should have no parameter.\n"); + if (num_param != 1 && num_param != 3) { + PRINT_INPUT_ERROR("use_typewise_cutoff should have 0 or 2 parameters.\n"); } use_typewise_cutoff = true; is_use_typewise_cutoff_set = true; + typewise_cutoff_radial_factor = 2.5f; + typewise_cutoff_angular_factor = 2.0f; + + if (num_param == 3) { + double typewise_cutoff_radial_factor_temp = 0.0; + if (!is_valid_real(param[1], &typewise_cutoff_radial_factor_temp)) { + PRINT_INPUT_ERROR("typewise_cutoff_radial_factor should be a number.\n"); + } + typewise_cutoff_radial_factor = typewise_cutoff_radial_factor_temp; + + double typewise_cutoff_angular_factor_temp = 0.0; + if (!is_valid_real(param[2], &typewise_cutoff_angular_factor_temp)) { + PRINT_INPUT_ERROR("typewise_cutoff_angular_factor should be a number.\n"); + } + typewise_cutoff_angular_factor = typewise_cutoff_angular_factor_temp; + } + + if (typewise_cutoff_angular_factor < 1.5f) { + PRINT_INPUT_ERROR("typewise_cutoff_angular_factor must >= 1.5.\n"); + } + + if (typewise_cutoff_radial_factor < typewise_cutoff_angular_factor) { + PRINT_INPUT_ERROR("typewise_cutoff_radial_factor must >= typewise_cutoff_angular_factor.\n"); + } } void Parameters::parse_use_typewise_cutoff_zbl(const char** param, int num_param) { - if (num_param != 1) { - PRINT_INPUT_ERROR("use_typewise_cutoff_zbl should have no parameter.\n"); + if (num_param != 1 && num_param != 2) { + PRINT_INPUT_ERROR("use_typewise_cutoff_zbl should have 0 or 1 parameter.\n"); } use_typewise_cutoff_zbl = true; is_use_typewise_cutoff_zbl_set = true; + typewise_cutoff_zbl_factor = 0.65f; + + if (num_param == 2) { + double typewise_cutoff_zbl_factor_temp = 0.0; + if (!is_valid_real(param[1], &typewise_cutoff_zbl_factor_temp)) { + PRINT_INPUT_ERROR("typewise_cutoff_zbl_factor should be a number.\n"); + } + typewise_cutoff_zbl_factor = typewise_cutoff_zbl_factor_temp; + } + + if (typewise_cutoff_zbl_factor < 0.5f) { + PRINT_INPUT_ERROR("typewise_cutoff_zbl_factor must >= 0.5.\n"); + } } diff --git a/src/main_nep/parameters.cuh b/src/main_nep/parameters.cuh index d1b329806..97d2ca0ba 100644 --- a/src/main_nep/parameters.cuh +++ b/src/main_nep/parameters.cuh @@ -57,6 +57,9 @@ public: float sigma0; bool use_typewise_cutoff; bool use_typewise_cutoff_zbl; + float typewise_cutoff_radial_factor; + float typewise_cutoff_angular_factor; + float typewise_cutoff_zbl_factor; // check if a parameter has been set: bool is_train_mode_set; From 57803d4ce516e5157a5276cb4aafe13547ccc510 Mon Sep 17 00:00:00 2001 From: brucefan1983 Date: Wed, 7 Aug 2024 19:20:28 +0800 Subject: [PATCH 2/2] remove nep2 totally --- src/force/nep3.cu | 2 -- src/force/nep3_multigpu.cu | 2 -- src/utilities/nep_utilities.cuh | 30 ++++++++++-------------------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/force/nep3.cu b/src/force/nep3.cu index fb3e8cc97..e013bf954 100644 --- a/src/force/nep3.cu +++ b/src/force/nep3.cu @@ -394,7 +394,6 @@ void NEP3::construct_table(float* parameters) parameters + (annmb.dim + 2) * annmb.num_neurons1 * (paramb.version == 4 ? paramb.num_types : 1) + 1; construct_table_radial_or_angular( - paramb.version, paramb.num_types, paramb.num_types_sq, paramb.n_max_radial, @@ -405,7 +404,6 @@ void NEP3::construct_table(float* parameters) gn_radial.data(), gnp_radial.data()); construct_table_radial_or_angular( - paramb.version, paramb.num_types, paramb.num_types_sq, paramb.n_max_angular, diff --git a/src/force/nep3_multigpu.cu b/src/force/nep3_multigpu.cu index 493f7238a..7ef00fcda 100644 --- a/src/force/nep3_multigpu.cu +++ b/src/force/nep3_multigpu.cu @@ -354,7 +354,6 @@ NEP3_MULTIGPU::NEP3_MULTIGPU( (paramb.version == 4 ? paramb.num_types : 1) + 1; construct_table_radial_or_angular( - paramb.version, paramb.num_types, paramb.num_types_sq, paramb.n_max_radial, @@ -365,7 +364,6 @@ NEP3_MULTIGPU::NEP3_MULTIGPU( gn_radial.data(), gnp_radial.data()); construct_table_radial_or_angular( - paramb.version, paramb.num_types, paramb.num_types_sq, paramb.n_max_angular, diff --git a/src/utilities/nep_utilities.cuh b/src/utilities/nep_utilities.cuh index 14debd31f..4b5d764fb 100644 --- a/src/utilities/nep_utilities.cuh +++ b/src/utilities/nep_utilities.cuh @@ -853,7 +853,6 @@ __device__ void find_index_and_weight( } static void construct_table_radial_or_angular( - const int version, const int num_types, const int num_types_sq, const int n_max, @@ -873,26 +872,17 @@ static void construct_table_radial_or_angular( int t12 = t1 * num_types + t2; float fn12[MAX_NUM_N]; float fnp12[MAX_NUM_N]; - if (version == 2) { - find_fn_and_fnp(n_max, rcinv, d12, fc12, fcp12, fn12, fnp12); - for (int n = 0; n <= n_max; ++n) { - int index_all = (table_index * num_types_sq + t12) * (n_max + 1) + n; - gn[index_all] = fn12[n] * ((num_types == 1) ? 1.0f : c[n * num_types_sq + t12]); - gnp[index_all] = fnp12[n] * ((num_types == 1) ? 1.0f : c[n * num_types_sq + t12]); - } - } else { - find_fn_and_fnp(basis_size, rcinv, d12, fc12, fcp12, fn12, fnp12); - for (int n = 0; n <= n_max; ++n) { - float gn12 = 0.0f; - float gnp12 = 0.0f; - for (int k = 0; k <= basis_size; ++k) { - gn12 += fn12[k] * c[(n * (basis_size + 1) + k) * num_types_sq + t12]; - gnp12 += fnp12[k] * c[(n * (basis_size + 1) + k) * num_types_sq + t12]; - } - int index_all = (table_index * num_types_sq + t12) * (n_max + 1) + n; - gn[index_all] = gn12; - gnp[index_all] = gnp12; + find_fn_and_fnp(basis_size, rcinv, d12, fc12, fcp12, fn12, fnp12); + for (int n = 0; n <= n_max; ++n) { + float gn12 = 0.0f; + float gnp12 = 0.0f; + for (int k = 0; k <= basis_size; ++k) { + gn12 += fn12[k] * c[(n * (basis_size + 1) + k) * num_types_sq + t12]; + gnp12 += fnp12[k] * c[(n * (basis_size + 1) + k) * num_types_sq + t12]; } + int index_all = (table_index * num_types_sq + t12) * (n_max + 1) + n; + gn[index_all] = gn12; + gnp[index_all] = gnp12; } } }