Open KarinDuong opened 3 months ago
With this code:
def fix_gro_file(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
with open(f'{file_path}', 'w') as file:
for line in lines:
print(f"before if : {len(line)}")
if len(line) > 30 :
print("if")
try:
print("try")
line_content = line.split()
if len(line_content) > 3:
print(line_content)
fixed_line = f" {line_content[0]:>7} {line_content[1]:>5} {line_content[2]:>4} {line_content[3][:5]:>7}{line_content[4][:5]:>7}{line_content[5][:5]:>7}\n"
print(fixed_line)
file.write(fixed_line)
else:
file.write(line)
except ValueError:
print(f"Warning: Could not parse line: {line}")
continue
else:
print("else")
file.write(line)
It works for ibuprofen_ethanol.gro
but not for methanol and water ...
Files from https://acs.figshare.com/articles/dataset/Small_Molecule_Solvation_Free_Energy_Enhanced_Conformational_Sampling_Using_Expanded_Ensemble_Molecular_Dynamics_Simulation/2615170 have some issues to be read by MDAnalysis. So I have to change the spacing and the float number