-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput_proc.py
168 lines (132 loc) · 6.5 KB
/
input_proc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
""" A repository of functions which process the information of the command line as well as the input file. """
import os
import sys
import argparse
from specs import Input
from specs import Molecule
from specs import PlotParameter
from specs import OutFileParameter
def input_processor():
""" Checks command line input from user. Prints error messages if needed. Causes program to exit. """
parser = argparse.ArgumentParser(
description="Produces a plot of a computed potential energy surface.")
parser.add_argument('-i',
'--input',
type=str,
default='input.dat',
help="Name of the input file to be read in")
#parser.add_argument('-o', '--output', type=str, default='output.dat', help="Name of the output file to be created.")
args = parser.parse_args()
Input.input_file_name = args.input
#Input.output_file_name = args.output
if not os.path.exists(Input.input_file_name):
print(("Could not locate input file: " + Input.input_file_name))
sys.exit()
return None
def section_finder():
""" Checks for section headers and calls appropriate function if the finder is found. """
with open(Input.input_file_name, 'r') as infile:
Input.input_file_content = infile.readlines()
Input.input_file_length = len(Input.input_file_content)
for i in range(0, Input.input_file_length):
if '$energies' in Input.input_file_content[i]:
energy_processor(i)
if '$connect' in Input.input_file_content[i]:
connection_processor(i)
if '$plot_format' in Input.input_file_content[i]:
plot_format_processor(i)
calc_stuff()
return None
def energy_processor(section_start):
""" Reads the information for each molecular species that the user is interested in. """
for i in range(section_start + 1, Input.input_file_length):
tmp = Input.input_file_content[i].lstrip().rstrip().split()
if '#' not in tmp[0]:
if '$end' in tmp[0]:
break
elif 'above' not in tmp:
Molecule.species_count += 1
Molecule.ground_species_count += 1
Molecule.name.append(str(tmp[0]))
Molecule.energy.append(float(tmp[1]))
else:
Molecule.species_count += 1
Molecule.above_species_count += 1
Molecule.name.append(str(tmp[0]))
Molecule.energy.append(float(tmp[1]))
Molecule.above_state.append(str(tmp[3]))
Molecule.range_energy = max(Molecule.energy) - min(Molecule.energy)
Molecule.max_energy = max(Molecule.energy)
Molecule.min_energy = min(Molecule.energy)
return None
def connection_processor(section_start):
""" Processes information to plot out the connection lines. """
Molecule.connection_type = Input.input_file_content[
section_start + 1].lstrip().rstrip().lower()
for i in range(section_start + 1, Input.input_file_length):
tmp = Input.input_file_content[i].lstrip().rstrip().split()
if '#' not in tmp[0]:
if '$end' in tmp[0]:
break
Molecule.connection_count += 1
for k in range(0, Molecule.species_count):
if Molecule.name[k] == tmp[0]:
Molecule.left_connection.append(k + 1)
if Molecule.name[k] == tmp[2]:
Molecule.right_connection.append(k + 1)
return None
def plot_format_processor(section_start):
""" Processes information to format the plot. """
for i in range(section_start + 1, Input.input_file_length):
tmp = Input.input_file_content[i].lstrip().rstrip().split()
if '#' not in tmp[0]:
if '$end' in tmp[0]:
break
else:
if 'y_axis_top_extend' in tmp[0]:
PlotParameter.y_axis_top_extend = float(tmp[2])
if 'y_axis_bot_extend' in tmp[0]:
PlotParameter.y_axis_bot_extend = float(tmp[2])
if 'y_axis_label' in tmp[0]:
PlotParameter.y_axis_label = str(tmp[2])
if 'x_axis_right_extend' in tmp[0]:
PlotParameter.x_axis_right_extend = float(tmp[2])
if 'x_axis_label' in tmp[0]:
PlotParameter.x_axis_label = str(tmp[2])
if 'name_vshift_scale' in tmp[0]:
PlotParameter.name_vshift_scale_fact = float(tmp[2])
if 'name_font_size' in tmp[0]:
PlotParameter.name_font_size = int(tmp[2])
if 'energy_vshift_scale' in tmp[0]:
PlotParameter.energy_vshift_scale_fact = float(tmp[2])
if 'energy_font_size' in tmp[0]:
PlotParameter.energy_font_size = int(tmp[2])
if 'species_line_spacing' in tmp[0]:
PlotParameter.species_line_spacing = float(tmp[2])
if 'species_line_length' in tmp[0]:
PlotParameter.species_line_length = float(tmp[2])
if 'species_line_width' in tmp[0]:
PlotParameter.species_line_width = float(tmp[2])
if 'connection_line_width' in tmp[0]:
PlotParameter.connection_line_width = float(tmp[2])
if 'latex_text = on' in tmp[0]:
PlotParameter.name_latex_format = 'on'
if 'ytick_min' in tmp[0]:
PlotParameter.tick_min = float(tmp[2])
if 'ytick_max' in tmp[0]:
PlotParameter.tick_max = float(tmp[2])
if 'ytick_intvl' in tmp[0]:
PlotParameter.tick_intvl = float(tmp[2])
return None
def calc_stuff():
""" Using input from user, determine parameters for plot formatting. """
PlotParameter.name_vshift = 0.5#PlotParameter.name_vshift_scale_fact * Molecule.range_energy
PlotParameter.energy_vshift = 1.5#PlotParameter.energy_vshift_scale_fact * Molecule.range_energy
PlotParameter.y_axis_top_lim = Molecule.max_energy + PlotParameter.y_axis_top_extend
PlotParameter.y_axis_bot_lim = Molecule.min_energy - PlotParameter.y_axis_bot_extend
PlotParameter.x_axis_right_lim = Molecule.ground_species_count + PlotParameter.x_axis_right_extend
if PlotParameter.name_latex_format == 'on':
for k in range(0, Molecule.species_count):
tmp = '$' + name[k] + '$'
name[k] = tmp
sys.dont_write_bytecode = True