Skip to content

Commit cb93dd4

Browse files
committed
flip charge upon restarting
1 parent 878140b commit cb93dd4

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/main_nep/parameters.cu

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,15 +1299,23 @@ void Parameters::parse_charge_mode(const char** param, int num_param)
12991299
{
13001300
is_charge_mode_set = true;
13011301

1302-
if (num_param != 2) {
1303-
PRINT_INPUT_ERROR("charge_mode should have one parameter.\n");
1302+
if (num_param != 2 && num_param != 3) {
1303+
PRINT_INPUT_ERROR("charge_mode should have one or two parameters.\n");
13041304
}
13051305
if (!is_valid_int(param[1], &charge_mode)) {
13061306
PRINT_INPUT_ERROR("charge mode should be an integer.\n");
13071307
}
13081308
if (charge_mode < 0 || charge_mode > 5) {
13091309
PRINT_INPUT_ERROR("charge mode should be 0 or 1 or 2 or 3 or 4 or 5.");
13101310
}
1311+
if (num_param == 3) {
1312+
if (!is_valid_int(param[2], &flip_charge)) {
1313+
PRINT_INPUT_ERROR("flip_charge should be an integer.\n");
1314+
}
1315+
if (flip_charge < 0 || flip_charge > 1) {
1316+
PRINT_INPUT_ERROR("flip_charge should be 0 or 1.");
1317+
}
1318+
}
13111319
}
13121320

13131321
void Parameters::parse_fine_tune(const char** param, int num_param)

src/main_nep/parameters.cuh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public:
6868
int output_descriptor;
6969
int charge_mode; // add dynamic charge to NEP potential model
7070
bool has_bec = false; // check if there are target BEC values
71+
int flip_charge = 0; // 1 for flipping charges upon restarting
7172
int fine_tune = 0; // fine_tune option; 0=no, 1=yes
7273
std::string fine_tune_nep_txt = "";
7374
std::string fine_tune_nep_restart = "";

src/main_nep/snes.cu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ void SNES::initialize_mu_and_sigma(Parameters& para)
121121
int count = fscanf(fid_restart, "%f%f", &mu[n], &sigma[n]);
122122
PRINT_SCANF_ERROR(count, 2, "Reading error for nep.restart.");
123123
}
124+
// flip the charges if needed
125+
if (para.charge_mode && para.flip_charge) {
126+
const int num_part = (para.dim + 2) * para.num_neurons1;
127+
for (int t = 0; t < para.num_types; ++t) {
128+
for (int n = para.number_of_variables_ann_1 * t + num_part; n < para.number_of_variables_ann_1 * (t + 1); ++n) {
129+
mu[n] = -mu[n];
130+
}
131+
}
132+
}
124133
fclose(fid_restart);
125134
}
126135
gpuSetDevice(0); // normally use GPU-0

0 commit comments

Comments
 (0)