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

8 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-12-03 18:45 +0000

1from mddb_workflow.utils.constants import GROMACS_CUSTOM_MASSES_FILEPATH 

2from mddb_workflow.utils.file import File 

3 

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

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

6# e.g. Zn and ZN 

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

8 

9# LORE: This was done with a symlink before 

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

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

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

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

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

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

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

17 

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

19# However this lead to problems when containerizing the environment 

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

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

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

23 

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

25def fix_gromacs_masses (): 

26 

27 # Set the source file 

28 # WARNING: Note that this must be done here, not outside the function 

29 # Otherwise a workflow called with a '-dir' parameter would have a wrong relative path 

30 source_custom_masses_file = File(GROMACS_CUSTOM_MASSES_FILEPATH) 

31 

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

33 # According to Justin Lemkul: 

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

35 # before referencing them from $GMXLIB." 

36 local_custom_masses_file = File('atommass.dat') 

37 

38 # This was a symlink before 

39 # Make sure any reamining symlinks are removed 

40 if local_custom_masses_file.is_symlink(): local_custom_masses_file.remove() 

41 

42 # Check if the backup file exists and, if not, then copy the reference 

43 if not local_custom_masses_file.exists: 

44 source_custom_masses_file.copy_to(local_custom_masses_file)