Coverage for model_workflow/tools/fix_gromacs_masses.py: 100%

9 statements  

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

1from os import environ 

2from pathlib import Path 

3 

4from model_workflow.utils.file import File 

5 

6# Replace the default gromacs masses file (atommass.dat) by our custom masses file 

7# This file includes relevant atoms also in all caps letters 

8# e.g. Zn and ZN 

9# This way we avoid gormacs not finding atoms because names are in caps 

10 

11# LORE: This was done with a symlink before 

12# In the gromacs data directory from the conda enviornment we created a relative symlink to the workflow atommass.dat 

13# This worked fine until we had a very specific issue with a cluster (gpucluster at IRB Barcelona) 

14# In this cluster there was two different paths to reach the home directory: /home/username and /orozco/homes/username 

15# The python __file__ values were using the /orozco/homes/username root despite we were calling it from /home/username 

16# Thus relative paths were all passing through the root and the different number of jumps was breaking the paths 

17# I spent half a day trying to get __file__ values using the /home/username root and I did not succeed 

18# Then we decided to just write the masses file in the conda enviornment every time 

19 

20# LORE: This was done by modifying the conda enviornment before 

21# However this lead to problems when containerizing the environment 

22# In one hand, there was no CONDA_PREFIX environmental variable 

23# But the real problem was that writting in the enviornment was not allowed 

24# Otherwise the container could not be shared between different user in a cluster 

25 

26# Set the path to the workflow custom masses file 

27resources = str(Path(__file__).parent.parent / "resources") 

28source_custom_masses_file = File(resources + '/atommass.dat') 

29 

30# Set the path to a local copy of the workflow custom masses file 

31# According to Justin Lemkul: 

32# "All GROMACS programs will read relevant database files from the working directory  

33# before referencing them from $GMXLIB." 

34local_custom_masses_file = File('atommass.dat') 

35 

36# Replace the original file by a symlink to our custom file if it is not done yet 

37def fix_gromacs_masses (): 

38 

39 # Check if the backup file exists and, if not, then rename the current masses file as the backup 

40 if not local_custom_masses_file.exists: 

41 local_custom_masses_file.set_symlink_to(source_custom_masses_file)