#### Edit cafemol input file for path and md step
#### Usage: $ python3 edit_input.py input_file output_path pdb_path
#### given input file is edited in place.

import sys
import fileinput

if len( sys.argv ) < 4:
    print("provide input file, output path, pdb_path")
    sys.exit()

input_file = sys.argv[1]
out_path = sys.argv[2]
pdb_path = sys.argv[3]
out_file = "format.inp"
with open(input_file,'r') as fin, open(out_file, 'w') as fout :
    for line in fin:
        if line.startswith("path "):
            line_string = "path = "+out_path
            fout.write(line_string+"\n")
        elif line.startswith("path_pdb"):
            line_string = "path_pdb = "+pdb_path
            fout.write(line_string+"\n")
        elif line.startswith("path_ini"):
            line_string = "path_ini = "+pdb_path
            fout.write(line_string+"\n")
        elif line.startswith("i_run_mode"):
            line_string = "i_run_mode = 2"
            fout.write(line_string+"\n")
        elif line.startswith("n_tstep(1)"):
            line_string = "n_tstep(1) = 1"
            fout.write(line_string+"\n")
        else:
            fout.write(line)
