Skip to main content
← OpenMECP Documentation

Module cleanup

Module cleanup 

Source
Expand description

Automated file cleanup for quantum chemistry calculations Automated file cleanup for quantum chemistry calculations.

This module provides functionality to automatically clean up temporary files generated during quantum chemistry calculations, particularly for ORCA calculations. The cleanup system uses a smart approach to prevent bus errors from excessive temporary files while preserving all essential files.

§Philosophy: Smart File Management

This implementation uses an intelligent file management strategy:

  • Always keep: Output files (.out, .log) and input files (.in, .inp)
  • Latest only: Energy/gradient files (.engrad) - only from the most recent step
  • Configurable: User-specified extensions from omecp_config.cfg
  • Delete everything else: All temporary and intermediate files

This prevents bus errors from accumulating thousands of temporary files during long MECP optimization runs.

§Features

  • Automatic cleanup after each QM calculation completes
  • Step-based .engrad filtering - keeps only the latest .engrad files
  • Whitelist preservation - preserves essential output and input files
  • Configurable via omecp_config.cfg for output file extensions
  • Program-specific handling (ORCA, Gaussian, XTB, etc.)
  • Comprehensive logging of all cleanup operations
  • Safe operations with proper error handling

§Configuration

The cleanup behavior is controlled via omecp_config.cfg. Add the cleanup section to your omecp_config.cfg file:

[cleanup]
# Enable or disable automatic cleanup (default: true)
enabled = true

# Verbose logging for cleanup operations (default: 1)
# 0 = quiet, 1 = normal, 2 = verbose
verbose = 1

# Additional file extensions to preserve (comma-separated)
# preserve_extensions = gbw,tmp,backup

Note: Output file extension is controlled by the [extensions] section:

[extensions]
orca = out        # All .out files will be preserved

§File Preservation Strategy

§Files Always Preserved (Never Deleted)

  • Output files (.out, .log, etc.) - Calculation results
  • Input files (.in, .inp) - Input files for calculations

§Files Latest Only (Step-Based Filtering)

  • Energy/gradient files (.engrad) - Only from the most recent optimization step
    • Format: {N}_state_{A|B}.engrad where N is the step number
    • Keeps: Files with maximum step number (e.g., 60_state_A.engrad)
    • Deletes: All other .engrad files (e.g., 59_state_*.engrad, 58_state_*.engrad, etc.)

§User-Configurable Extensions

  • Additional file extensions specified in omecp_config.cfg under [cleanup] section
  • All files with these extensions are preserved

§Files Always Deleted

  • SCF iteration files (.scf)
  • Temporary files (.tmp, .trash)
  • Lock files (.lock)
  • Old .engrad files (older than the latest step)
  • Any other file types not in the whitelist

§Usage Example

use omecp::cleanup::{CleanupManager, CleanupConfig};
use omecp::settings::SettingsManager;
use omecp::config::QMProgram;
use std::path::Path;

let settings_manager = SettingsManager::load()?;
let program = QMProgram::Orca;
let cleanup_config = CleanupConfig::from_settings_manager(&settings_manager, program);

let manager = CleanupManager::new(cleanup_config, program);
// Clean up files in the job directory
manager.cleanup_directory(Path::new("compound_x"))?;

§Error Handling

All cleanup operations return proper Result types and log errors without panicking. This ensures that cleanup failures don’t interrupt the main calculation workflow.

Structs§

CleanupConfig
Configuration for cleanup operations.
CleanupManager
Manages cleanup operations for quantum chemistry calculations.

Enums§

CleanupError
Errors that can occur during cleanup operations.

Type Aliases§

Result
Result type for cleanup operations