@@ -688,6 +688,21 @@ def test_ensure_independent_atom_ids(self):
688688 # checks second resonance structure id
689689 self .assertNotEqual (s2 .molecule [1 ].atoms [0 ].id , - 1 )
690690
691+ def test_ensure_independent_atom_ids_no_resonance (self ):
692+ """
693+ Ensure ensure_independent_atom_ids does not generate resonance
694+ """
695+ s1 = Species ().fromSMILES ('CCC' )
696+ s2 = Species ().fromSMILES ('C=C[CH]C' )
697+ self .assertEqual (s2 .molecule [0 ].atoms [0 ].id , - 1 )
698+
699+ ensure_independent_atom_ids ([s1 , s2 ],resonance = False )
700+ # checks resonance structures
701+ self .assertEqual (len (s2 .molecule ),1 )
702+ # checks that atom ids are changed
703+ for atom in s2 .molecule [0 ].atoms :
704+ self .assertNotEqual (atom .id , - 1 )
705+
691706 def testSaveEntry (self ):
692707 """
693708 tests that save entry can run
@@ -839,25 +854,171 @@ def test_generate_reactions_from_families_product_resonance(self):
839854 self .assertEqual (len (reaction_list ), 1 )
840855 self .assertEqual (reaction_list [0 ].degeneracy , 2 )
841856
842- reaction_list = self .database .kinetics .generate_reactions_from_families (reactants , products , only_families = ['H_Abstraction' ], resonance = False )
843857
858+
859+ def test_generate_reactions_from_families_product_resonance2 (self ):
860+ """Test that we can specify the no product resonance structure when generating reactions"""
861+ reactants = [
862+ Molecule ().fromSMILES ('CCC=C' ),
863+ Molecule ().fromSMILES ('[H]' ),
864+ ]
865+ products = [
866+ Molecule ().fromSMILES ('CC=C[CH2]' ),
867+ Molecule ().fromSMILES ('[H][H]' ),
868+ ]
869+
870+ reaction_list = self .database .kinetics .generate_reactions_from_families (reactants , products , only_families = ['H_Abstraction' ], resonance = False )
844871 self .assertEqual (len (reaction_list ), 0 )
845872
873+ self .assertTrue (isinstance (products [0 ],Species ))
874+ self .assertEqual (len (products [0 ].molecule ),1 )
875+
846876 def test_generate_reactions_from_libraries (self ):
847877 """Test that we can generate reactions from libraries"""
848878 reactants = [
849879 Molecule ().fromSMILES ('CC=O' ),
850880 Molecule ().fromSMILES ('[H]' ),
851881 ]
852- products = [
853- Molecule ().fromSMILES ('[CH2]C=O' ),
854- Molecule ().fromSMILES ('[H][H]' ),
855- ]
856882
857883 reaction_list = self .database .kinetics .generate_reactions_from_libraries (reactants )
858884
859885 self .assertEqual (len (reaction_list ), 3 )
860886
887+ def test_generate_reactions_from_libraries2 (self ):
888+ """Test that we can generate reactions from libraries specifying products"""
889+ reactants = [
890+ Molecule ().fromSMILES ('CC=O' ),
891+ Molecule ().fromSMILES ('[H]' ),
892+ ]
893+ products = [
894+ Molecule ().fromSMILES ('[CH2]C=O' ),
895+ Molecule ().fromSMILES ('[H][H]' ),
896+ ]
861897 reaction_list_2 = self .database .kinetics .generate_reactions_from_libraries (reactants , products )
862898
863899 self .assertEqual (len (reaction_list_2 ), 1 )
900+
901+ def test_add_atom_labels_for_reaction (self ):
902+ """Test that addAtomLabelsForReaction can identify reactions with resonance
903+ The molecule [CH]=C=C has resonance in this reaction"""
904+ from rmgpy .data .rmg import getDB
905+ reactants = [
906+ Molecule ().fromSMILES ('C=C=C' ),
907+ Molecule ().fromSMILES ('[CH]=C=C' ),
908+ ]
909+ products = [
910+ Molecule ().fromSMILES ('C#C[CH2]' ),
911+ Molecule ().fromSMILES ('C#CC' ),
912+ ]
913+ reaction = TemplateReaction (reactants = reactants ,
914+ products = products ,
915+ family = 'H_Abstraction' )
916+ reaction .ensure_species (reactant_resonance = True , product_resonance = True )
917+ family = getDB ('kinetics' ).families ['H_Abstraction' ]
918+ family .addAtomLabelsForReaction (reaction , output_with_resonance = False )
919+
920+ # test that the reaction has labels
921+ found_labels = []
922+ for species in reaction .reactants :
923+ for atom in species .molecule [0 ].atoms :
924+ if atom .label != '' :
925+ found_labels .append (atom .label )
926+ self .assertEqual (len (found_labels ), 3 )
927+ self .assertIn ('*1' ,found_labels )
928+ self .assertIn ('*2' ,found_labels )
929+ self .assertIn ('*3' ,found_labels )
930+
931+ # test for the products too
932+ found_labels = []
933+ for species in reaction .products :
934+ for atom in species .molecule [0 ].atoms :
935+ if atom .label != '' :
936+ found_labels .append (atom .label )
937+ self .assertEqual (len (found_labels ), 3 )
938+ self .assertIn ('*1' ,found_labels )
939+ self .assertIn ('*2' ,found_labels )
940+ self .assertIn ('*3' ,found_labels )
941+
942+ def test_add_atom_labels_for_reaction_2 (self ):
943+ """Test that addAtomLabelsForReaction can identify reactions with identical references
944+ The molecule [CH]=C=C has resonance in this reaction"""
945+ from rmgpy .data .rmg import getDB
946+ s1 = Species ().fromSMILES ('C=C=C' )
947+ s2 = Species ().fromSMILES ('C=C=[CH]' )
948+ s3 = Species ().fromSMILES ('C#CC' )
949+ s2 .generate_resonance_structures ()
950+ reactants = [s1 ,s2 ]
951+ products = [s2 ,s3 ]
952+ reaction = TemplateReaction (reactants = reactants ,
953+ products = products ,
954+ family = 'H_Abstraction' )
955+ family = getDB ('kinetics' ).families ['H_Abstraction' ]
956+ print reaction .reactants
957+ print reaction .products
958+ family .addAtomLabelsForReaction (reaction , output_with_resonance = False )
959+
960+ # test that the reaction has labels
961+ found_labels = []
962+ for species in reaction .reactants :
963+ for atom in species .molecule [0 ].atoms :
964+ if atom .label != '' :
965+ found_labels .append (atom .label )
966+ self .assertEqual (len (found_labels ), 3 ,'wrong number of labels found {0}' .format (found_labels ))
967+ self .assertIn ('*1' ,found_labels )
968+ self .assertIn ('*2' ,found_labels )
969+ self .assertIn ('*3' ,found_labels )
970+
971+ # test for the products too
972+ found_labels = []
973+ for species in reaction .products :
974+ for atom in species .molecule [0 ].atoms :
975+ if atom .label != '' :
976+ found_labels .append (atom .label )
977+ self .assertEqual (len (found_labels ), 3 )
978+ self .assertIn ('*1' ,found_labels )
979+ self .assertIn ('*2' ,found_labels )
980+ self .assertIn ('*3' ,found_labels )
981+
982+ def test_add_atom_labels_for_reaction_3 (self ):
983+ """Test that addAtomLabelsForReaction can identify reactions with resonance and isotopes"""
984+ from rmgpy .data .rmg import getDB
985+ mr0 = Molecule ().fromAdjacencyList ('1 C u0 p0 c0 i13 {3,D} {4,S} {5,S}\n 2 *1 C u0 p0 c0 {3,D} {6,S} {7,S}\n 3 C u0 p0 c0 {1,D} {2,D}\n 4 H u0 p0 c0 {1,S}\n 5 H u0 p0 c0 {1,S}\n 6 H u0 p0 c0 {2,S}\n 7 *4 H u0 p0 c0 {2,S}\n ' )
986+ mr1a = Molecule ().fromAdjacencyList ('multiplicity 2\n 1 C u0 p0 c0 i13 {2,D} {4,S} {5,S}\n 2 C u0 p0 c0 {1,D} {3,D}\n 3 *1 C u1 p0 c0 {2,D} {6,S}\n 4 H u0 p0 c0 {1,S}\n 5 H u0 p0 c0 {1,S}\n 6 H u0 p0 c0 {3,S}\n ' )
987+ mr1b = Molecule ().fromAdjacencyList ('multiplicity 2\n 1 C u1 p0 c0 i13 {2,S} {4,S} {5,S}\n 2 C u0 p0 c0 {1,S} {3,T}\n 3 *1 C u0 p0 c0 {2,T} {6,S}\n 4 H u0 p0 c0 {1,S}\n 5 H u0 p0 c0 {1,S}\n 6 H u0 p0 c0 {3,S}\n ' )
988+ mp1a = Molecule ().fromAdjacencyList ('multiplicity 2\n 1 C u0 p0 c0 {2,D} {4,S} {5,S}\n 2 C u0 p0 c0 {1,D} {3,D}\n 3 *1 C u1 p0 c0 i13 {2,D} {6,S}\n 4 H u0 p0 c0 {1,S}\n 5 H u0 p0 c0 {1,S}\n 6 H u0 p0 c0 {3,S}\n ' )
989+ mp1b = Molecule ().fromAdjacencyList ('multiplicity 2\n 1 C u1 p0 c0 {2,S} {4,S} {5,S}\n 2 C u0 p0 c0 {1,S} {3,T}\n 3 *1 C u0 p0 c0 i13 {2,T} {6,S}\n 4 H u0 p0 c0 {1,S}\n 5 H u0 p0 c0 {1,S}\n 6 H u0 p0 c0 {3,S}\n ' )
990+ s1 = Species (molecule = [mr0 ])
991+ s2 = Species (molecule = [mr1a ,mr1b ])
992+ s3 = Species (molecule = [mp1a ,mp1b ])
993+ reactants = [s1 ,s2 ]
994+ products = [s1 ,s3 ]
995+ reaction = TemplateReaction (reactants = reactants ,
996+ products = products ,
997+ family = 'H_Abstraction' )
998+ family = getDB ('kinetics' ).families ['H_Abstraction' ]
999+ print reaction .reactants
1000+ print reaction .products
1001+ family .addAtomLabelsForReaction (reaction , output_with_resonance = False )
1002+
1003+ # test that the reaction has labels
1004+ found_labels = []
1005+ for species in reaction .reactants :
1006+ for atom in species .molecule [0 ].atoms :
1007+ if atom .label != '' :
1008+ found_labels .append (atom .label )
1009+ self .assertEqual (len (found_labels ), 3 ,'wrong number of labels found {0}' .format (found_labels ))
1010+ self .assertIn ('*1' ,found_labels )
1011+ self .assertIn ('*2' ,found_labels )
1012+ self .assertIn ('*3' ,found_labels )
1013+
1014+ # test for the products too
1015+ found_labels = []
1016+ for species in reaction .products :
1017+ for atom in species .molecule [0 ].atoms :
1018+ if atom .label != '' :
1019+ found_labels .append (atom .label )
1020+ self .assertEqual (len (found_labels ), 3 )
1021+ self .assertIn ('*1' ,found_labels )
1022+ self .assertIn ('*2' ,found_labels )
1023+ self .assertIn ('*3' ,found_labels )
1024+
0 commit comments