GROMACS version: 2021.5
GROMACS modification: No
I am trying to make free energy landscape plot using the gsham tool of gromacs. Everything works fine until the step in which I have to convert the .xpm file to .txt file. Whenever I convert it, a file is generated but it has very less data points for me to plot the 3d graph.
Please let me know where is the issue. I am pasting the python script I used for conversion of .xpm to .txt
#!/usr/bin/env python
import sys
“”"
Utility tool to convert xpm files generated by GROMACS to a 3-column text file.
“”"
USAGE = “USAGE: xpm2txt.py -f -o [-s]\n”
USAGE+= “Options:\n”
USAGE+= “\t-s\t(int)\tSorts the output by a given column”
USAGE+= “\n” # always keep this line
Parse arguments
read_input, read_output, sort = False, False, False
xpm_file, out_file, column_sort = None, None, None
for arg in sys.argv[1:]:
if read_input:
read_input = False
xpm_file = arg
elif read_output:
read_output = False
out_file = arg
elif sort:
sort = False
column_sort = int(arg)
if arg[0] == “-”:
if arg == “-f”:
read_input = True
continue
elif arg == “-o”:
read_output = True
continue
elif arg == “-s”:
sort = True
else:
print (USAGE)
sys.stderr.write(‘ERROR: Option not recognized: %s\n’ %arg)
sys.exit(1)
if not xpm_file:
print (USAGE)
sys.stderr.write(‘ERROR: You forgot to provide an input file.\n’)
sys.exit(1)
if not out_file:
out_file = “out.txt”
Parse XPM file
xpm_handle = open(xpm_file)
xpm_data =
x_axis, y_axis = ,
letter_to_value = {}
for line in xpm_handle:
if line.startswith(“/* x-axis”):
x_axis = map(float, line.split()[2:-2]) # We trim the last value
if line.startswith("/* y-axis"):
y_axis = map(float, line.split()[2:-2]) # We trim the last value
if line.startswith('"') and x_axis and y_axis: # Read data
xpm_data.insert(0, line.strip().strip(',')[1:-1])
if line.startswith('"') and len(line.split()) > 4:
letter = line.split()[0][1:]
value = float(line.split()[-2][1:-1])
letter_to_value[letter] = value
xpm_handle.close()
Match x/y/data
txt_values =
y_axisFloatList = list(map(float,y_axis))
for y_index, data_value in enumerate(xpm_data):
y_value = y_axisFloatList[y_index]
for x_index, x_value in enumerate(x_axis):
txt_values.append([x_value, y_value, letter_to_value[data_value[x_index]]])
Apply sorting if requested
if column_sort:
try:
txt_values.sort(key=lambda x: x[column_sort-1])
except IndexError:
print (USAGE)
sys.stderr.write(‘ERROR: Column not found (%s)\n’ %(column_sort))
sys.exit(1)
Print to file
out_handle = open(out_file, ‘w’)
for x, y, z in txt_values:
out_handle.write(“%3.5f\t%3.5f\t%3.5f\n” %(x,y,z))
out_handle.close()
I am also pasting the .txt file with very less data points below for reference.
2.04380 | 2.25463 | 13.60000 |
---|---|---|
2.04733 | 2.25463 | 13.60000 |
2.05085 | 2.25463 | 13.60000 |
2.05437 | 2.25463 | 13.60000 |
2.05790 | 2.25463 | 13.60000 |
2.06142 | 2.25463 | 12.40000 |
2.06495 | 2.25463 | 13.60000 |
2.06847 | 2.25463 | 13.60000 |
2.07200 | 2.25463 | 13.60000 |
2.07552 | 2.25463 | 13.60000 |
2.07904 | 2.25463 | 13.60000 |
2.08257 | 2.25463 | 13.60000 |
2.08609 | 2.25463 | 13.60000 |
2.08962 | 2.25463 | 13.60000 |
2.09314 | 2.25463 | 13.60000 |
2.09667 | 2.25463 | 13.60000 |
2.10019 | 2.25463 | 13.60000 |
2.10371 | 2.25463 | 13.60000 |
2.10724 | 2.25463 | 13.60000 |
2.11076 | 2.25463 | 13.60000 |
2.11429 | 2.25463 | 13.60000 |
2.11781 | 2.25463 | 13.60000 |
2.12134 | 2.25463 | 13.60000 |
2.12486 | 2.25463 | 13.60000 |
2.12838 | 2.25463 | 13.60000 |
2.13191 | 2.25463 | 13.60000 |
2.13543 | 2.25463 | 13.60000 |
2.13896 | 2.25463 | 13.60000 |
2.14248 | 2.25463 | 13.60000 |
2.14601 | 2.25463 | 13.60000 |
2.14953 | 2.25463 | 13.60000 |
2.15305 | 2.25463 | 13.60000 |