Coverage for biobb_mem/lipyphilic_biobb/common.py: 25%
12 statements
« prev ^ index » next coverage.py v7.6.11, created at 2025-02-10 11:25 +0000
« prev ^ index » next coverage.py v7.6.11, created at 2025-02-10 11:25 +0000
1""" Common functions for package biobb_mem.lipyphilic_biobb """
2import numpy as np
3from MDAnalysis.transformations.boxdimensions import set_dimensions
6def calculate_box(u):
7 print('Warning: trajectory probably has no box variable. Setting dimensions using the minimum and maximum positions of the atoms.')
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)
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())
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]))