Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typewise cutoff factors #684

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions src/force/nep3.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/force/nep3.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 27 additions & 14 deletions src/force/nep3_multigpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/force/nep3_multigpu.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
24 changes: 15 additions & 9 deletions src/force/nep3_small_box.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/main_nep/fitness.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading