1010import shutil
1111
1212from rmgpy import settings as rmg_settings
13+ from rmgpy .data .thermo import ThermoLibrary
1314from rmgpy .rmg .pdep import PDepNetwork , PDepReaction
1415from rmgpy .species import Species
15- from rmgpy .thermo import NASA
16+ from rmgpy .thermo import NASA , ThermoData
17+ from rmgpy .statmech import Conformer , IdealGasTranslation , NonlinearRotor , HarmonicOscillator
1618
1719from arc .common import read_yaml_file
1820from arc .species import ARCSpecies
@@ -551,7 +553,7 @@ def test_determine_species_based_on_sa():
551553
552554def test_determine_species_from_pdep_network ():
553555 """Test determining species from pdep network"""
554- t3 = run_minimal (project_directory = os .path .join (DATA_BASE_PATH , 'pdep_network' ),
556+ t3 = run_minimal (project_directory = os .path .join (DATA_BASE_PATH , 'pdep_network' ),
555557 iteration = 1 ,
556558 set_paths = True ,
557559 )
@@ -761,6 +763,106 @@ def test_add_species():
761763 assert found_h2
762764
763765
766+ def test_add_to_rmg_library ():
767+ """Test adding thermo calculations to an existing thermo library"""
768+ libraries_path = os .path .join (DATA_BASE_PATH , 'libraries' )
769+ if not os .path .isdir (libraries_path ):
770+ os .makedirs (libraries_path )
771+
772+ spc_1 = Species (
773+ index = 1 ,
774+ label = 'C2H4' ,
775+ thermo = ThermoData (
776+ Tdata = ([300.0 , 400.0 , 500.0 , 600.0 , 800.0 , 1000.0 , 1500.0 ], 'K' ),
777+ Cpdata = ([3.0 , 4.0 , 5.0 , 6.0 , 8.0 , 10.0 , 15.0 ], 'cal/(mol*K)' ),
778+ H298 = (- 20.0 , 'kcal/mol' ),
779+ S298 = (50.0 , 'cal/(mol*K)' ),
780+ Tmin = (300.0 , 'K' ),
781+ Tmax = (2000.0 , 'K' ),
782+ ),
783+ conformer = Conformer (
784+ E0 = (0.0 , 'kJ/mol' ),
785+ modes = [
786+ IdealGasTranslation (mass = (28.03 , 'amu' )),
787+ NonlinearRotor (inertia = ([5.6952e-47 , 2.7758e-46 , 3.3454e-46 ], 'kg*m^2' ), symmetry = 1 ),
788+ HarmonicOscillator (frequencies = ([834.50 , 973.31 , 975.37 , 1067.1 , 1238.5 , 1379.5 , 1472.3 , 1691.3 ,
789+ 3121.6 , 3136.7 , 3192.5 , 3221.0 ], 'cm^-1' )),
790+ ],
791+ spin_multiplicity = 1 ,
792+ optical_isomers = 1 ,
793+ ),
794+ smiles = 'C=C' ,
795+ )
796+
797+ spc_2 = Species (
798+ index = 2 ,
799+ label = 'CH4' ,
800+ thermo = ThermoData (
801+ Tdata = ([300.0 , 400.0 , 500.0 , 600.0 , 800.0 , 1000.0 , 1500.0 ], 'K' ),
802+ Cpdata = ([3.0 , 4.0 , 5.0 , 6.0 , 8.0 , 10.0 , 15.0 ], 'cal/(mol*K)' ),
803+ H298 = (- 50.0 , 'kcal/mol' ),
804+ S298 = (100.0 , 'cal/(mol*K)' ),
805+ Tmin = (300.0 , 'K' ),
806+ Tmax = (2000.0 , 'K' ),
807+ ),
808+ conformer = Conformer (
809+ E0 = (0.0 , 'kJ/mol' ),
810+ modes = [
811+ IdealGasTranslation (mass = (28.03 , 'amu' )),
812+ NonlinearRotor (inertia = ([5.6952e-47 , 2.7758e-46 , 3.3454e-46 ], 'kg*m^2' ), symmetry = 1 ),
813+ ],
814+ spin_multiplicity = 1 ,
815+ optical_isomers = 1 ,
816+ ),
817+ smiles = 'C' ,
818+ )
819+
820+ spc_3 = Species (
821+ index = 2 ,
822+ label = 'CH4' ,
823+ thermo = ThermoData (
824+ Tdata = ([300.0 , 400.0 , 500.0 , 600.0 , 800.0 , 1000.0 , 1500.0 ], 'K' ),
825+ Cpdata = ([3.0 , 4.0 , 5.0 , 6.0 , 8.0 , 10.0 , 15.0 ], 'cal/(mol*K)' ),
826+ H298 = (- 92.0 , 'kcal/mol' ), # this is different
827+ S298 = (12.0 , 'cal/(mol*K)' ), # this is different
828+ Tmin = (300.0 , 'K' ),
829+ Tmax = (2000.0 , 'K' ),
830+ ),
831+ conformer = Conformer (
832+ E0 = (0.0 , 'kJ/mol' ),
833+ modes = [
834+ IdealGasTranslation (mass = (28.03 , 'amu' )),
835+ NonlinearRotor (inertia = ([5.6952e-47 , 2.7758e-46 , 3.3454e-46 ], 'kg*m^2' ), symmetry = 1 ),
836+ ],
837+ spin_multiplicity = 1 ,
838+ optical_isomers = 1 ,
839+ ),
840+ smiles = 'C' ,
841+ )
842+
843+ for lib_name , spc_list in [('RMG_library' , [spc_1 , spc_2 ]), ('ARC_library' , [spc_3 ])]:
844+ thermo_library = ThermoLibrary (name = lib_name , long_desc = lib_name )
845+ for i , spc in enumerate (spc_list ):
846+ thermo_library .load_entry (index = i ,
847+ label = spc .label ,
848+ molecule = spc .to_adjacency_list (),
849+ thermo = spc .thermo ,
850+ shortDesc = spc .label ,
851+ longDesc = spc .label )
852+ thermo_library .save (os .path .join (libraries_path , f'{ lib_name } .py' ))
853+
854+ t3 = run_minimal ()
855+ t3 .paths ['ARC thermo lib' ] = os .path .join (libraries_path , 'ARC_library.py' )
856+ t3 .paths ['RMG T3 thermo lib' ] = os .path .join (libraries_path , 'RMG_library.py' )
857+ t3 .add_to_rmg_library ()
858+ with open (t3 .paths ['RMG T3 thermo lib' ], 'r' ) as f :
859+ lines = f .readlines ()
860+ for line in [" H298 = (-92,'kcal/mol'),\n " ,
861+ " S298 = (12,'cal/(mol*K)'),\n " ,
862+ ]:
863+ assert line in lines
864+
865+
764866def test_dump_species ():
765867 """Test dump species for restart purposes"""
766868 # create an empty `iteration_5` directory
@@ -860,6 +962,7 @@ def test_check_overtime():
860962
861963def teardown_module ():
862964 """teardown any state that was previously setup with a setup_module method."""
965+
863966 # delete log files
864967 for i in range (10 ):
865968 directory = os .path .join (restart_base_path , f'r{ i } ' )
@@ -870,11 +973,25 @@ def teardown_module():
870973 log_archive = os .path .join (directory , 'log_archive' )
871974 if os .path .isdir (log_archive ):
872975 shutil .rmtree (log_archive )
873- os .remove (os .path .join (restart_base_path , 'r6' , 'iteration_6' , 'ARC' , 'T3_ARC_restart_test.info' ))
976+
977+ # other files to delete
978+ files = [os .path .join (restart_base_path , 'r6' , 'iteration_6' , 'ARC' , 'T3_ARC_restart_test.info' ),
979+ os .path .join (restart_base_path , 'r6' , 'iteration_6' , 'ARC' , 'input.yml' ),
980+ os .path .join (restart_base_path , 'r6' , 'species.yml' ),
981+ os .path .join (DATA_BASE_PATH , 'process_arc' , 'species.yml' ),
982+ ]
983+ for file in files :
984+ if os .path .isfile (file ):
985+ os .remove (file )
986+
874987 # delete folders
875988 for directory in [test_minimal_project_directory ,
876989 dump_species_path ,
877990 os .path .join (DATA_BASE_PATH , 'minimal_data' , 'log_archive' ),
991+ os .path .join (DATA_BASE_PATH , 'determine_species' , 'log_archive' ),
992+ os .path .join (DATA_BASE_PATH , 'pdep_network' , 'log_archive' ),
993+ os .path .join (DATA_BASE_PATH , 'process_arc' , 'log_archive' ),
994+ os .path .join (DATA_BASE_PATH , 'libraries' ),
878995 os .path .join (restart_base_path , 'r6' , 'iteration_6' , 'ARC' , 'output' ),
879996 os .path .join (restart_base_path , 'r6' , 'iteration_6' , 'ARC' , 'log_and_restart_archive' ),
880997 ]:
0 commit comments