Coverage for biobb_mem/lipyphilic_biobb/common.py: 32%

19 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-08 09:07 +0000

1""" Common functions for package biobb_mem.lipyphilic_biobb """ 

2import numpy as np 

3from MDAnalysis.transformations.boxdimensions import set_dimensions 

4from biobb_common.tools import file_utils as fu 

5 

6 

7def set_box(u): 

8 # Initialize min and max positions with extreme values 

9 min_pos = np.full(3, np.inf) 

10 max_pos = np.full(3, -np.inf) 

11 

12 # Iterate over all frames to find the overall min and max positions 

13 for ts in u.trajectory: 

14 positions = u.atoms.positions 

15 min_pos = np.minimum(min_pos, positions.min()) 

16 max_pos = np.maximum(max_pos, positions.max()) 

17 

18 # Calculate the dimensions of the box 

19 box_dimensions = max_pos - min_pos 

20 u.trajectory.add_transformations(set_dimensions([*box_dimensions, 90, 90, 90])) 

21 

22 

23def ignore_no_box(u, ignore_no_box, out_log, global_log): 

24 if u.dimensions is None: 

25 if ignore_no_box: 

26 fu.log('Setting box dimensions using the minimum and maximum positions of the atoms.', 

27 out_log, global_log) 

28 set_box(u) 

29 else: 

30 fu.log('The trajectory does not contain box information. ' 

31 'Please set the ignore_no_box property to True to ignore this error.', 

32 out_log, global_log) 

33 raise ValueError("Box dimensions are required but not found in the trajectory.")