Skip to content

Commit

Permalink
Dump state file for minimum system energy (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund authored Jan 11, 2024
1 parent 7f1a0f5 commit 3b4d6c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/_docs/analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ All units in $k\_BT$.
`file` | Output filename (`.dat`, `.csv`, `.dat.gz`)
`nstep` | Interval between samples
`nskip=0` | Number of initial steps excluded from the analysis
`save_min_conf=false` | Dump minimum energy configuration to `PQR` file
`save_min_conf=false` | Dump minimum energy configuration to a `PQR` and state file


### Penalty function
Expand Down
2 changes: 1 addition & 1 deletion docs/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ properties:

systemenergy:
properties:
file: {type: string}
file: {type: string, pattern: "(.*?)\\.(dat|dat.gz|csv)$", description: "Output filename (.dat|.dat.gz|.csv)"}
nstep: {type: integer}
nskip: {type: integer, default: 0, description: Initial steps to skip}
save_min_conf:
Expand Down
14 changes: 12 additions & 2 deletions src/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ void SystemEnergy::normalize() {
/**
* @brief Checks if the current energy is the lowest so far and saves the configuration if so.
*
* The output is hardcoded to PQR format, tagged with the step number and energy.
* The output is hardcoded to PQR format, tagged with the step number and energy. In addition,
* we dump Space to a state file that can be used to restart a simulation.
*
* @return True if a new minimum energy was encountered
*/
Expand All @@ -254,9 +255,18 @@ bool SystemEnergy::updateMinimumEnergy(const double current_energy) {
return false;
}
minimum_energy = current_energy;
const auto filename = MPI::prefix + "mininum_energy.pqr";

auto filename = MPI::prefix + "mininum_energy.pqr";
faunus_logger->debug("{}: saving {} ({:.2f} kT) at step {}", name, filename, minimum_energy, getNumberOfSteps());
PQRWriter(PQRWriter::Style::PQR).save(filename, spc.groups, spc.geometry.getLength());

filename = MPI::prefix + "mininum_energy.state";
if (std::ofstream file(filename); file) {
faunus_logger->debug("{}: saving {} ({:.2f} kT) at step {}", name, filename, minimum_energy, getNumberOfSteps());
json j;
Faunus::to_json(j, spc);
file << std::setw(1) << j;
}
return true;
}

Expand Down

0 comments on commit 3b4d6c1

Please sign in to comment.