Skip to main content
← OpenMECP Documentation

CleanupManager

Struct CleanupManager 

Source
pub struct CleanupManager {
    config: CleanupConfig,
    program: QMProgram,
}
Expand description

Manages cleanup operations for quantum chemistry calculations.

Fields§

§config: CleanupConfig

Cleanup configuration with whitelist

§program: QMProgram

QM program type

Implementations§

Source§

impl CleanupManager

Source

pub fn new(config: CleanupConfig, program: QMProgram) -> Self

Creates a new cleanup manager.

§Arguments
  • config - Cleanup configuration with whitelist
  • program - QM program type
§Returns

Returns a new CleanupManager instance

Source

pub fn cleanup_directory(&self, directory: &Path) -> Result<()>

Cleans up temporary files in the specified directory.

Uses a smart approach: preserves essential files and keeps only the latest .engrad files to prevent bus errors from excessive files.

§Arguments
  • directory - Path to the directory to clean (e.g., job directory from input file stem)
§Returns

Returns Ok(()) on success or a CleanupError on failure

Source

fn find_max_step_number(&self, files: &[(PathBuf, String)]) -> usize

Finds the maximum step number from .inp files in the directory.

Scans for files matching the pattern {N}_state_{A|B}.inp and returns the maximum step number N found.

§Arguments
  • files - List of (path, filename) tuples
§Returns

Returns the maximum step number found, or 0 if no step-based files exist

Source

fn extract_step_from_engrad(&self, filename: &str) -> Option<usize>

Extracts the step number from a .engrad filename.

Parses files matching the pattern {N}_state_{A|B}.engrad and returns the step number N.

§Arguments
  • filename - The filename to parse
§Returns

Returns Some(step_number) if the filename matches the pattern, None otherwise

Source

pub fn should_preserve_file( &self, extension: &str, _path: &Path, filename: &str, max_step: usize, ) -> bool

Determines if a file should be preserved (whitelist check with step-based filtering).

Files are preserved based on:

  1. Extension in whitelist (always keep)
  2. Special filename patterns (always keep)
  3. .engrad files from the latest step (keep only)
  4. All other files (delete)
§Arguments
  • extension - File extension without the dot
  • path - Full file path
  • filename - Just the filename
  • max_step - Maximum step number from .inp files
§Returns

Returns true if the file should be preserved, false otherwise

Source

pub fn cleanup_file(&self, file_path: &Path) -> Result<bool>

Cleans up a single file if it’s not in the whitelist.

Note: For .engrad files, this method conservatively deletes them unless they are from the latest step. To use step-based filtering, use cleanup_directory() instead.

§Arguments
  • file_path - Path to the file to clean
§Returns

Returns Ok(true) if file was deleted, Ok(false) if preserved

Source

fn should_preserve_file_simple(&self, extension: &str, filename: &str) -> bool

Simplified whitelist check for files that don’t need step-based filtering.

§Arguments
  • extension - File extension without the dot
  • filename - Just the filename
§Returns

Returns true if the file should be preserved, false otherwise

Source

pub fn config(&self) -> &CleanupConfig

Gets the cleanup configuration (read-only).

Source

pub fn would_preserve(&self, file_path: &Path) -> bool

Checks if a file would be preserved without actually cleaning it

Note: For .engrad files, this returns false (use cleanup_directory for step-based filtering)

§Arguments
  • file_path - Path to check
§Returns

Returns true if the file would be preserved (is in whitelist)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.