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

Write state file for minimum system energy #442

Merged
merged 1 commit into from
Jan 11, 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
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
Loading