diff --git a/image_analysis/structure_refinement/ModelValidation.cpp b/image_analysis/structure_refinement/ModelValidation.cpp index 14bc6ed39..17d4f39e6 100644 --- a/image_analysis/structure_refinement/ModelValidation.cpp +++ b/image_analysis/structure_refinement/ModelValidation.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -59,11 +60,20 @@ gemmi::Grid map_from_coefficients(gemmi::AsuData> &co return MapFromFPhi(gemmi::get_f_phi_on_grid(coef, size, true)); } +// A file this run may already have written - the validation in the model's setting writes over the +// first one's maps - is removed before it is written again, not truncated: XFS (and ext4) flush a file +// truncated and rewritten when it is closed, and three 150 MB maps forced out to a disk that way cost +// seconds where a fresh file costs nothing. +void remove_before_rewriting(const std::string &path) { + std::remove(path.c_str()); +} + // Write a map as CCP4; return its RMS (the sigma the map is read in). double write_ccp4(const gemmi::Grid &map, const std::string &path) { gemmi::Ccp4 ccp4; ccp4.grid = map; ccp4.update_ccp4_header(2); + remove_before_rewriting(path); ccp4.write_ccp4_map(path); return ccp4.hstats.rms; } @@ -1466,6 +1476,7 @@ ModelValidationResult Validate(const std::vector &merged, } mtz.nreflections = static_cast(terms.size()); mtz.data = std::move(data); + remove_before_rewriting(output_prefix + "_maps.mtz"); mtz.write_to_file(output_prefix + "_maps.mtz"); } catch (const std::exception &e) { logger.Warning("Model validation: could not write map MTZ: {}", e.what());