5252from rmgpy .statmech .vibration import HarmonicOscillator
5353from rmgpy .pdep .collision import SingleExponentialDown
5454from rmgpy .transport import TransportData
55- from rmgpy .thermo import NASA , Wilhoit
55+ from rmgpy .thermo import NASA , Wilhoit , ThermoData , NASAPolynomial
5656from rmgpy .species import Species , TransitionState
5757import rmgpy .constants as constants
5858
@@ -180,16 +180,19 @@ def update_species_attributes(self, species=None):
180180 self .energy_transfer_model = species .energyTransferModel
181181 if species .thermo is not None :
182182 self .thermo = species .thermo .as_dict ()
183- thermo_data = species .getThermoData ()
184- h298 = thermo_data .getEnthalpy (298 ) / 4184.
185- s298 = thermo_data .getEntropy (298 ) / 4.184
186- cp = dict ()
187- for t in [300 , 400 , 500 , 600 , 800 , 1000 , 1500 , 2000 , 2400 ]:
188- temp_str = '{0} K' .format (t )
189- cp [temp_str ] = '{0:.2f}' .format (thermo_data .getHeatCapacity (t ) / 4.184 )
190- self .thermo_data = {'H298' : '{0:.2f} kcal/mol' .format (h298 ),
191- 'S298' : '{0:.2f} cal/mol*K' .format (s298 ),
192- 'Cp (cal/mol*K)' : cp }
183+ data = species .getThermoData ()
184+ h298 = data .getEnthalpy (298 ) / 4184.
185+ s298 = data .getEntropy (298 ) / 4.184
186+ temperatures = numpy .array ([300 , 400 , 500 , 600 , 800 , 1000 , 1500 , 2000 , 2400 ])
187+ cp = []
188+ for t in temperatures :
189+ cp .append (data .getHeatCapacity (t ) / 4.184 )
190+
191+ self .thermo_data = ThermoData (H298 = (h298 , 'kcal/mol' ),
192+ S298 = (s298 , 'cal/(mol*K)' ),
193+ Tdata = (temperatures , 'K' ),
194+ Cpdata = (cp , 'cal/(mol*K)' ),
195+ )
193196
194197 def update_xyz_string (self ):
195198 """
@@ -228,21 +231,30 @@ def save_yaml(self, path):
228231 yaml .dump (data = self .as_dict (), stream = f )
229232 logging .debug ('Dumping species {0} data as {1}' .format (self .label , filename ))
230233
231- def load_yaml (self , path , species , pdep = False ):
234+ def load_yaml (self , path , label = None , pdep = False ):
232235 """
233236 Load the all statMech data from the .yml file in `path` into `species`
234237 `pdep` is a boolean specifying whether or not jobList includes a pressureDependentJob.
235238 """
236- logging .info ('Loading statistical mechanics parameters for {0} from .yml file...' .format (species .label ))
239+ yml_file = os .path .basename (path )
240+ if label :
241+ logging .info ('Loading statistical mechanics parameters for {0} from {1} file...' .format (label , yml_file ))
242+ else :
243+ logging .info ('Loading statistical mechanics parameters from {0} file...' .format (yml_file ))
237244 with open (path , 'r' ) as f :
238245 data = yaml .safe_load (stream = f )
239- try :
240- if species .label != data ['label' ]:
241- logging .debug ('Found different labels for species: {0} in input file, and {1} in the .yml file. '
242- 'Using the label "{0}" for this species.' .format (species .label , data ['label' ]))
243- except KeyError :
244- # Lacking label in the YAML file is strange, but accepted
245- logging .debug ('Did not find label for species {0} in .yml file.' .format (species .label ))
246+ if label :
247+ # First, warn the user if the label doesn't match
248+ try :
249+ if label != data ['label' ]:
250+ logging .debug ('Found different labels for species: {0} in input file, and {1} in the .yml file. '
251+ 'Using the label "{0}" for this species.' .format (label , data ['label' ]))
252+ except KeyError :
253+ # Lacking label in the YAML file is strange, but accepted
254+ logging .debug ('Did not find label for species {0} in .yml file.' .format (label ))
255+
256+ # Then, set the ArkaneSpecies label to the user supplied label
257+ data ['label' ] = label
246258 try :
247259 class_name = data ['class' ]
248260 except KeyError :
@@ -265,19 +277,32 @@ def load_yaml(self, path, species, pdep=False):
265277 'SingleExponentialDown' : SingleExponentialDown ,
266278 'Wilhoit' : Wilhoit ,
267279 'NASA' : NASA ,
280+ 'NASAPolynomial' : NASAPolynomial ,
281+ 'ThermoData' : ThermoData ,
282+ 'np_array' : numpy .array ,
268283 }
269284 freq_data = None
270285 if 'imaginary_frequency' in data :
271286 freq_data = data ['imaginary_frequency' ]
272287 del data ['imaginary_frequency' ]
288+ if not data ['is_ts' ]:
289+ if 'smiles' in data :
290+ data ['species' ] = Species (SMILES = data ['smiles' ])
291+ elif 'adjacency_list' in data :
292+ data ['species' ] = Species ().fromAdjacencyList (data ['adjacency_list' ])
293+ elif 'inchi' in data :
294+ data ['species' ] = Species (InChI = data ['inchi' ])
295+ else :
296+ raise ValueError ('Cannot load ArkaneSpecies from YAML file {0}. Either `smiles`, `adjacency_list`, or '
297+ 'InChI must be specified' .format (path ))
298+ # Finally, set the species label so that the special attributes are updated properly
299+ data ['species' ].label = data ['label' ]
300+
273301 self .make_object (data = data , class_dict = class_dict )
274302 if freq_data is not None :
275303 self .imaginary_frequency = ScalarQuantity ()
276- self .imaginary_frequency .make_object (data = freq_data , class_dict = dict ())
277- self .adjacency_list = data ['adjacency_list' ] if 'adjacency_list' in data else None
278- self .inchi = data ['inchi' ] if 'inchi' in data else None
279- self .smiles = data ['smiles' ] if 'smiles' in data else None
280- self .is_ts = data ['is_ts' ] if 'is_ts' in data else False
304+ self .imaginary_frequency .make_object (data = freq_data , class_dict = class_dict )
305+
281306 if pdep and not self .is_ts and (self .transport_data is None or self .energy_transfer_model is None ):
282307 raise ValueError ('Transport data and an energy transfer model must be given if pressure-dependent '
283308 'calculations are requested. Check file {0}' .format (path ))
@@ -347,7 +372,7 @@ def get_element_mass(input_element, isotope=None):
347372 else :
348373 # no specific isotope is required
349374 if len (mass_list [0 ]) == 2 :
350- # isotop weight is unavailable, use the first entry
375+ # isotope weight is unavailable, use the first entry
351376 mass = mass_list [0 ][1 ]
352377 logging .warn ("Assuming isotop {0} is representative of element {1}" .format (mass_list [0 ][0 ], symbol ))
353378 else :
0 commit comments