Coverage for mddb_workflow/tools/get_box_size.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-29 15:48 +0000

1# This script is used to find out the box size (x, y and z) in a pdb topology 

2# This process is carried by Gromacs 

3 

4from os import remove 

5 

6from mddb_workflow.utils.gmx_spells import run_gromacs 

7 

8# Set the box analysis filename 

9# This analysis is used here to mine the box size data 

10# It is never used further 

11BOX_ANALYSIS = 'box.xvg' 

12 

13# input_topology_filename - The name string of the input topology file (path) 

14# Tested supported formats are .pdb and .tpr 

15# input_trajectory_filename - The name string of the input trajectory file (path) 

16# Tested supported formats are .trr and .xtc 

17# DANI: This is very old code and probably will not work most times 

18def get_box_size( 

19 input_topology_filename: str, 

20 input_trajectory_filename: str, 

21) -> tuple: 

22 # Generate the box analysis 

23 # WARNING: Do not use the first_frame here instead of the trajectory 

24 # In modified topologies the first frame pdb may have lost box size data 

25 run_gromacs(f'traj -s {input_topology_filename} -f {input_trajectory_filename} \ 

26 -ob {BOX_ANALYSIS} -b 0 -e 0', user_input = 'System', 

27 expected_output_filepath = BOX_ANALYSIS) 

28 # Read the box analysis and get the desired data 

29 boxsizex, boxsizey, boxsizez = "", "", "" 

30 with open(BOX_ANALYSIS, 'r') as file: 

31 for line in file: 

32 if line.startswith(("#", "@")) == False: 

33 # Simulation box 'x' size 

34 boxsizex = float(line.split()[1]) 

35 # Simulation box 'y' size 

36 boxsizey = float(line.split()[2]) 

37 # Simulation box 'z' size 

38 boxsizez = float(line.split()[3]) 

39 # Remove the box analysis 

40 remove(BOX_ANALYSIS) 

41 # Display it 

42 print(f'Box size: ({boxsizex},{boxsizey},{boxsizez})') 

43 # Return gromacs logs 

44 return (boxsizex, boxsizey, boxsizez)