Coverage for biobb_mem/fatslim/common.py: 88%
24 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 09:07 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 09:07 +0000
1from MDAnalysis.transformations.boxdimensions import set_dimensions
2from biobb_common.tools import file_utils as fu
3import glob
4import shutil
5import os
8def set_box(u):
9 # Calculate the dimensions of the box
10 positions = u.atoms.positions
11 box_dimensions = positions.max(axis=0) - positions.min(axis=0)
12 # Set the box dimensions
13 u.trajectory.add_transformations(set_dimensions([*box_dimensions, 90, 90, 90]))
16def ignore_no_box(u, ignore_no_box, out_log, global_log):
17 # FATSLiM ValueError: Box does not correspond to PBC=xyz
18 if u.dimensions is None:
19 if ignore_no_box:
20 fu.log('Setting box dimensions using the minimum and maximum positions of the atoms.',
21 out_log, global_log)
22 set_box(u)
23 else:
24 fu.log('The trajectory does not contain box information. '
25 'Please set the ignore_no_box property to True to ignore this error.',
26 out_log, global_log)
27 raise ValueError("Box dimensions are required but not found in the trajectory.")
30def move_output_file(file, out_file_path, out_log, global_log):
31 # Add a wildcard to support multiples frames output (it adds 0000 suffix)
32 base, ext = os.path.splitext(file)
33 file_glob = base + '*' + ext
34 files_to_move = glob.glob(file_glob)
35 if files_to_move:
36 fu.log(f"Renaming file {files_to_move[0]} to {out_file_path}", out_log, global_log)
37 # Move the file to the output path
38 shutil.move(files_to_move[0], out_file_path)
39 else:
40 fu.log(f"Warning: File {file} not found, APL calculation might have failed.", out_log, global_log)