48
48
*/
49
49
50
50
public class QMLibraryEditor {
51
-
52
- //data fields
51
+
52
+ //data fields
53
53
/** The object representing the dictionary. */
54
54
private static BufferedWriter dictionaryFile = null ;
55
-
55
+
56
56
/** The object representing the library */
57
57
private static BufferedWriter libraryFile = null ;
58
-
59
- /** The newline character to use. */
60
- private static String newLine = System .getProperty ("line.separator" );
61
-
62
- /** Number of species added to Library used for naming */
63
- //may have to get rid of this if I find naming is important
64
- private static int counter = 0 ;
65
-
66
- //Constructor
67
-
68
- //methods
69
- /** Initializes the two files Dictionary.txt and Library.txt */
70
- public static void initialize () {
71
- try {
58
+
59
+ /** The newline character to use. */
60
+ private static String newLine = System .getProperty ("line.separator" );
61
+
62
+ /** Number of species added to Library used for naming */
63
+ //may have to get rid of this if I find naming is important
64
+ private static int counter = 0 ;
65
+
66
+ //Constructor
67
+
68
+ //methods
69
+ /** Initializes the two files Dictionary.txt and Library.txt */
70
+ public static void initialize () {
71
+ try {
72
72
// Open the log file (throws IOException if unsuccessful)
73
73
dictionaryFile = new BufferedWriter (new FileWriter ("QMThermoLibrary/Dictionary.txt" , true ));
74
74
Logger .info ("Creating Dictionary for QM Thermo Library" );
75
75
}
76
76
catch (IOException e ) {
77
77
// This is pretty essential to new QMTP regime. Stop if it fails
78
- Logger .critical ("Could not create QM Thermo Dictionary" );
78
+ Logger .critical ("Could not create QM Thermo Dictionary" );
79
79
System .exit (0 );
80
80
}
81
-
82
- try {
81
+
82
+ try {
83
83
// Open the log file (throws IOException if unsuccessful)
84
- // Boolean Argument in FileWriter means that it will append to existing files.
84
+ // Boolean Argument in FileWriter means that it will append to existing files.
85
85
libraryFile = new BufferedWriter (new FileWriter ("QMThermoLibrary/Library.txt" , true ));
86
86
Logger .info ("Creating Library for QM Thermo Library" );
87
87
}
88
88
catch (IOException e ) {
89
- // This is pretty essential to new QMTP regime. Stop if it fails
90
- Logger .critical ("Could not create QM Thermo Library" );
89
+ // This is pretty essential to new QMTP regime. Stop if it fails
90
+ Logger .critical ("Could not create QM Thermo Library" );
91
91
System .exit (0 );
92
92
}
93
-
94
- }
95
-
93
+
94
+ }
95
+
96
96
/**
97
97
* Close the Dictionary and Library when finished.
98
98
*/
99
99
public static void finish () {
100
100
try {
101
101
// Close the log file (throws IOException if unsuccessful)
102
- if (dictionaryFile != null ) dictionaryFile .close ();
102
+ if (dictionaryFile != null ) dictionaryFile .close ();
103
103
if (libraryFile != null ) libraryFile .close ();
104
104
}
105
105
catch (IOException e ) {
106
- throw new RuntimeException (e );
106
+ throw new RuntimeException (e );
107
107
}
108
108
}
109
-
109
+
110
110
/**
111
111
* Adds species to Dictionary.txt and Library.txt
112
112
*/
113
113
//Will probably require p_graph also
114
114
//Using InChI as name as per suggestion by gmagoon
115
115
public static void addQMTPThermo (ChemGraph p_graph , String inChI , ThermoData qmResult , String qmMethod , String qmProgram ){
116
- //Count the number of species added for naming
117
- counter ++;
118
- //Create comment for logger. I need to double check if naming convention will interfere with model
119
- String comment = "Adding " + inChI + " to the QMTP thermo Library" ;
120
- // String name = "SQM(";
121
- // name.concat(Integer.toString(counter));
122
- // name.concat(")");
123
-
124
- Logger .info (comment );
125
- //finish implementation of this method
126
- addLibraryEntry (inChI , qmResult , qmMethod , qmProgram );
127
- //finish implementation of this method
128
- addDictionaryEntry (inChI , p_graph );
116
+ //Count the number of species added for naming
117
+ counter ++;
118
+ //Create comment for logger. I need to double check if naming convention will interfere with model
119
+ String comment = "Adding " + inChI + " to the QMTP thermo Library" ;
120
+ // String name = "SQM(";
121
+ // name.concat(Integer.toString(counter));
122
+ // name.concat(")");
123
+
124
+ Logger .info (comment );
125
+ //finish implementation of this method
126
+ addLibraryEntry (inChI , qmResult , qmMethod , qmProgram );
127
+ //finish implementation of this method
128
+ addDictionaryEntry (inChI , p_graph );
129
129
}
130
130
/**
131
131
* Adds an entry to the Library of the QMTP thermo library using
132
132
* the ThermData calculated from mm4 or pm3.
133
133
*/
134
134
public static void addLibraryEntry (String inChI , ThermoData qmResult , String qmMethod , String qmProgram ) {
135
- //Assumes name in thermo library doesn't have to match the name in RMG
136
- //Not sure how true this is..figures crossed
137
- //line will be the entry to add to Library.txt using the format used in RMG thermo librarys
138
- String line = new String (inChI + " " );
139
- line = (line +Double .toString (qmResult .getH298 ()) + " " );
140
- line = (line +Double .toString (qmResult .getS298 ())+ " " );
141
- line = (line +Double .toString (qmResult .getCp300 ())+ " " );
142
- line = (line +Double .toString (qmResult .getCp400 ())+ " " );
143
- line = (line +Double .toString (qmResult .getCp500 ())+ " " );
144
- line = (line +Double .toString (qmResult .getCp600 ())+ " " );
145
- line = (line +Double .toString (qmResult .getCp800 ())+ " " );
146
- line = (line +Double .toString (qmResult .getCp1000 ())+ " " );
147
- line = (line +Double .toString (qmResult .getCp1500 ())+ " " );
148
- line = (line +Double .toString (qmResult .getDH ())+ " " );
149
- line = (line +Double .toString (qmResult .getDS ())+ " " );
150
- line = (line +Double .toString (qmResult .getDCp ())+ " " );
151
-
152
- //include the source of the calculation
153
- line = (line + qmProgram + " " + qmMethod + " Calculation" );
154
-
155
- //write to Library.txt
135
+ //Assumes name in thermo library doesn't have to match the name in RMG
136
+ //Not sure how true this is..figures crossed
137
+ //line will be the entry to add to Library.txt using the format used in RMG thermo librarys
138
+ String line = new String (inChI + " " );
139
+ line = (line +Double .toString (qmResult .getH298 ()) + " " );
140
+ line = (line +Double .toString (qmResult .getS298 ())+ " " );
141
+ line = (line +Double .toString (qmResult .getCp300 ())+ " " );
142
+ line = (line +Double .toString (qmResult .getCp400 ())+ " " );
143
+ line = (line +Double .toString (qmResult .getCp500 ())+ " " );
144
+ line = (line +Double .toString (qmResult .getCp600 ())+ " " );
145
+ line = (line +Double .toString (qmResult .getCp800 ())+ " " );
146
+ line = (line +Double .toString (qmResult .getCp1000 ())+ " " );
147
+ line = (line +Double .toString (qmResult .getCp1500 ())+ " " );
148
+ line = (line +Double .toString (qmResult .getDH ())+ " " );
149
+ line = (line +Double .toString (qmResult .getDS ())+ " " );
150
+ line = (line +Double .toString (qmResult .getDCp ())+ " " );
151
+
152
+ //include the source of the calculation
153
+ line = (line + qmProgram + " " + qmMethod + " Calculation" );
154
+
155
+ //write to Library.txt
156
156
try {
157
- libraryFile .write (line + newLine );
158
- libraryFile .flush ();
157
+ libraryFile .write (line + newLine );
158
+ libraryFile .flush ();
159
159
}
160
160
catch (IOException e ) {
161
161
// What should we do here?
162
- throw new RuntimeException (e );
162
+ throw new RuntimeException (e );
163
163
}
164
-
164
+
165
165
}
166
166
/**
167
167
* Adds an entry to the Dictionary.txt of the QMTP thermo library using
168
168
*/
169
169
public static void addDictionaryEntry (String inChI , ChemGraph p_graph ) {
170
- //Assumes name in thermo library doesn't have to match the name in RMG
171
- //Not sure how true this is..figures crossed
172
- //definition is a string of the name and adjacency list to be added to Dictionary.txt
173
- int i = 1 ;
174
- String definition = new String (inChI + newLine );
175
- //toString(i) is used as opposed to toString because that seems to give the adjacency list
176
- //without prefacing it with the chemical formula
177
- definition = (definition + p_graph .toString (i ) + newLine + newLine );
178
-
179
- //write to Dictionary.txt
170
+ //Assumes name in thermo library doesn't have to match the name in RMG
171
+ //Not sure how true this is..figures crossed
172
+ //definition is a string of the name and adjacency list to be added to Dictionary.txt
173
+ int i = 1 ;
174
+ String definition = new String (inChI + newLine );
175
+ //toString(i) is used as opposed to toString because that seems to give the adjacency list
176
+ //without prefacing it with the chemical formula
177
+ definition = (definition + p_graph .toString (i ) + newLine + newLine );
178
+
179
+ //write to Dictionary.txt
180
180
try {
181
- dictionaryFile .write (definition );
182
- dictionaryFile .flush ();
181
+ dictionaryFile .write (definition );
182
+ dictionaryFile .flush ();
183
183
}
184
184
catch (IOException e ) {
185
185
// What should we do here?
186
- throw new RuntimeException (e );
186
+ throw new RuntimeException (e );
187
187
}
188
188
}
189
-
189
+
190
190
/**
191
191
* Adds an entry to the Dictionary.txt of the QMTP thermo library using
192
192
* @throws IOException
193
193
194
194
*/
195
195
public static HashMap readLibrary (String p_qmThermoFileName ) throws IOException {
196
- try {
197
- FileReader in = new FileReader (p_qmThermoFileName );
198
- BufferedReader data = new BufferedReader (in );
199
- String line = ChemParser .readMeaningfulLine (data , true );
200
- HashMap <String , ThermoData > library = new HashMap <String , ThermoData >();
201
- while (line !=null ){
202
- String [] result = line .split ("\\ s" );
203
-
204
- // Construct information to create instance of ThermData
205
- String inChI = result [0 ];
206
- String thermo = result [1 ];
207
-
208
- for (int i =2 ; i <13 ; i ++){
209
- thermo = thermo + " " + result [i ];
210
- }
211
-
212
- int listLength = result .length ;
213
- String comments = result [13 ];
214
- //check this upper bound might need to be listLength + 1 -nyee
215
- for (int i =14 ; i < listLength ; i ++){
216
- comments = comments + " " + result [i ];
217
- }
218
-
219
- //Parse out thermoData, and include name and comments
220
- ThermoData thermoData = ChemParser .parseThermoFromLibrary (thermo );
221
- ThermoData newThermoData = new ThermoData (inChI , thermoData , comments );
222
-
223
- library .put (inChI , newThermoData );
224
- line = ChemParser .readMeaningfulLine (data , true );
225
- }
226
-
227
- in .close ();
228
- return library ;
229
-
230
- }
231
-
232
- catch (IOException e ) {
233
- Logger .logStackTrace (e );
234
- throw new IOException ("Can't read thermo in primary thermo library!" );
235
- }
236
-
196
+ try {
197
+ FileReader in = new FileReader (p_qmThermoFileName );
198
+ BufferedReader data = new BufferedReader (in );
199
+ String line = ChemParser .readMeaningfulLine (data , true );
200
+ HashMap <String , ThermoData > library = new HashMap <String , ThermoData >();
201
+ while (line !=null ){
202
+ String [] result = line .split ("\\ s" );
203
+
204
+ // Construct information to create instance of ThermData
205
+ String inChI = result [0 ];
206
+ String thermo = result [1 ];
207
+
208
+ for (int i =2 ; i <13 ; i ++){
209
+ thermo = thermo + " " + result [i ];
210
+ }
211
+
212
+ int listLength = result .length ;
213
+ String comments = result [13 ];
214
+ //check this upper bound might need to be listLength + 1 -nyee
215
+ for (int i =14 ; i < listLength ; i ++){
216
+ comments = comments + " " + result [i ];
217
+ }
218
+
219
+ //Parse out thermoData, and include name and comments
220
+ ThermoData thermoData = ChemParser .parseThermoFromLibrary (thermo );
221
+ ThermoData newThermoData = new ThermoData (inChI , thermoData , comments );
222
+
223
+ library .put (inChI , newThermoData );
224
+ line = ChemParser .readMeaningfulLine (data , true );
225
+ }
226
+
227
+ in .close ();
228
+ return library ;
229
+
230
+ }
231
+
232
+ catch (IOException e ) {
233
+ Logger .logStackTrace (e );
234
+ throw new IOException ("Can't read thermo in primary thermo library!" );
235
+ }
236
+
237
237
}
238
238
}
0 commit comments