Coverage for model_workflow/tools/get_first_frame.py: 71%

14 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-23 10:54 +0000

1from os.path import exists 

2from subprocess import run, PIPE, Popen 

3 

4from model_workflow.utils.constants import GROMACS_EXECUTABLE 

5from model_workflow.utils.type_hints import * 

6 

7# DANI: No lo muevo a gmx spells porque allí ya hay un get_first_frame con otra finalidad 

8def get_first_frame ( 

9 structure_file : 'File', 

10 trajectory_file : 'File', 

11 output_filepath : str 

12 ): 

13 """Get the trajectory first frame in PDB format using Gromacs.""" 

14 

15 # Run Gromacs 

16 p = Popen([ 

17 "echo", 

18 "System", 

19 ], stdout=PIPE) 

20 process = run([ 

21 GROMACS_EXECUTABLE, 

22 "trjconv", 

23 "-s", 

24 structure_file.path, 

25 "-f", 

26 trajectory_file.path, 

27 '-o', 

28 output_filepath, 

29 '-dump', 

30 '0', 

31 '-quiet' 

32 ], stdin=p.stdout, stdout=PIPE, stderr=PIPE) 

33 logs = process.stdout.decode() 

34 p.stdout.close() 

35 

36 # If output has not been generated then warn the user 

37 if not exists(output_filepath): 

38 print(logs) 

39 error_logs = process.stderr.decode() 

40 print(error_logs) 

41 raise SystemExit('Something went wrong with Gromacs')