@@ -1208,6 +1208,65 @@ def test_adsorbate_thermo_generation_bidentate_nonadjacent(self):
1208
1208
assert "radical" in thermo .comment , "Expected to need radical correctinos to find CH2j-CH2-CH2j"
1209
1209
assert "Adsorption correction" in thermo .comment , "Adsorption correction not added to thermo."
1210
1210
1211
+ def test_remove_group (self ):
1212
+ """
1213
+ Test removing groups, using nodes near the root of radical.py
1214
+ """
1215
+ # load up test data designed for this test
1216
+ database2 = ThermoDatabase ()
1217
+ path = os .path .join (os .path .dirname (__file__ ),".." ,"test_data" ,"testing_database" ,"thermo" )
1218
+ database2 .load (path , depository = False )
1219
+
1220
+ # load up the thermo radical database as a test
1221
+ rad_group = database2 .groups ["radical" ]
1222
+
1223
+ # use root as removed groups parent, which should be an LogicOr node
1224
+ root = rad_group .top [0 ]
1225
+ # use group to remove as
1226
+ group_to_remove = rad_group .entries ["RJ" ]
1227
+ children = group_to_remove .children
1228
+
1229
+ # set up for testing below
1230
+ rad_group .entries ["OJ" ].data = "RJ"
1231
+
1232
+ # remove the group
1233
+ rad_group .remove_group (group_to_remove )
1234
+
1235
+ # afterwards group_to_remove should not be in the database or root's children
1236
+ assert group_to_remove not in list (rad_group .entries .values ())
1237
+ assert group_to_remove not in root .children
1238
+
1239
+ for child in children :
1240
+ # group_to_remove children should all be in roots item.component and children attribuetes
1241
+ assert child .label in root .item .components
1242
+ assert child in root .children
1243
+ # the children should all have root a their parent now
1244
+ assert child .parent is root
1245
+
1246
+ # Specific to ThermoDatabase, (above test apply to all base class Database)
1247
+ # we check that unicode entry.data pointers are correctly reassigned
1248
+
1249
+ # if group_to_remove is a pointer and another node pointed to it, we copy
1250
+ # group_to_remove pointer
1251
+ # OJ pointed to RJ and RJ pointed to CJ so if you remove RJ then OJ should point to CJ
1252
+ assert rad_group .entries ["OJ" ].data is group_to_remove .data
1253
+
1254
+ # Remove an entry with a ThermoData object
1255
+ group_to_remove2 = rad_group .entries ["Cs_P" ]
1256
+ rad_group .remove_group (group_to_remove2 )
1257
+ # If group_to_remove was a data object, we point toward parent instead
1258
+ # CsCsJ pointed to Cs_P, which had data.
1259
+ # After we remove Cs_P, CsCsJ points to the parent, which was CsJ
1260
+ assert rad_group .entries ["CsCsJ" ].data == group_to_remove2 .parent .label
1261
+ # If the parent pointed toward group_to_remove, we need should have copied data object
1262
+ # CsJ (the parent) used to just point at Cs_P.
1263
+ # After we remove Cs_P, CsJ should contain the data copied from Cs_P
1264
+ Tlist = [300 , 400 , 500 , 600 , 800 , 1000 , 1500 ]
1265
+ assert not isinstance (group_to_remove2 .parent .data , str )
1266
+ assert group_to_remove2 .parent .data .get_enthalpy (298 ) == group_to_remove2 .data .get_enthalpy (298 )
1267
+ assert group_to_remove2 .parent .data .get_entropy (298 ) == group_to_remove2 .data .get_entropy (298 )
1268
+ assert all ([group_to_remove2 .parent .data .get_heat_capacity (x ) == group_to_remove2 .data .get_heat_capacity (x ) for x in Tlist ])
1269
+
1211
1270
1212
1271
class TestThermoAccuracy :
1213
1272
"""
@@ -1626,65 +1685,6 @@ def test_get_ring_groups_from_comments(self):
1626
1685
1627
1686
self .database .get_ring_groups_from_comments (spc .thermo )
1628
1687
1629
- def test_remove_group (self ):
1630
- """
1631
- Test that removing groups using nodes near the root of radical.py
1632
- """
1633
- # load up test data designed for this test
1634
- database2 = ThermoDatabase ()
1635
- path = os .path .join (os .path .dirname (__file__ ),".." ,"test_data" ,"testing_database" ,"thermo" )
1636
- database2 .load (path , depository = False )
1637
-
1638
- # load up the thermo radical database as a test
1639
- rad_group = database2 .groups ["radical" ]
1640
-
1641
- # use root as removed groups parent, which should be an LogicOr node
1642
- root = rad_group .top [0 ]
1643
- # use group to remove as
1644
- group_to_remove = rad_group .entries ["RJ" ]
1645
- children = group_to_remove .children
1646
-
1647
- # set up for testing below
1648
- rad_group .entries ["OJ" ].data = "RJ"
1649
-
1650
- # remove the group
1651
- rad_group .remove_group (group_to_remove )
1652
-
1653
- # afterwards group_to_remove should not be in the database or root's children
1654
- assert group_to_remove not in list (rad_group .entries .values ())
1655
- assert group_to_remove not in root .children
1656
-
1657
- for child in children :
1658
- # group_to_remove children should all be in roots item.component and children attribuetes
1659
- assert child .label in root .item .components
1660
- assert child in root .children
1661
- # the children should all have root a their parent now
1662
- assert child .parent is root
1663
-
1664
- # Specific to ThermoDatabase, (above test apply to all base class Database)
1665
- # we check that unicode entry.data pointers are correctly reassigned
1666
-
1667
- # if group_to_remove is a pointer and another node pointed to it, we copy
1668
- # group_to_remove pointer
1669
- # OJ pointed to RJ and RJ pointed to CJ so if you remove RJ then OJ should point to CJ
1670
- assert rad_group .entries ["OJ" ].data is group_to_remove .data
1671
-
1672
- # Remove an entry with a ThermoData object
1673
- group_to_remove2 = rad_group .entries ["Cs_P" ]
1674
- rad_group .remove_group (group_to_remove2 )
1675
- # If group_to_remove was a data object, we point toward parent instead
1676
- # CsCsJ pointed to Cs_P, which had data.
1677
- # After we remove Cs_P, CsCsJ points to the parent, which was CsJ
1678
- assert rad_group .entries ["CsCsJ" ].data == group_to_remove2 .parent .label
1679
- # If the parent pointed toward group_to_remove, we need should have copied data object
1680
- # CsJ (the parent) used to just point at Cs_P.
1681
- # After we remove Cs_P, CsJ should contain the data copied from Cs_P
1682
- Tlist = [300 , 400 , 500 , 600 , 800 , 1000 , 1500 ]
1683
- assert not isinstance (group_to_remove2 .parent .data , str )
1684
- assert group_to_remove2 .parent .data .get_enthalpy (298 ) == group_to_remove2 .data .get_enthalpy (298 )
1685
- assert group_to_remove2 .parent .data .get_entropy (298 ) == group_to_remove2 .data .get_entropy (298 )
1686
- assert all ([group_to_remove2 .parent .data .get_heat_capacity (x ) == group_to_remove2 .data .get_heat_capacity (x ) for x in Tlist ])
1687
-
1688
1688
def test_is_ring_partial_matched (self ):
1689
1689
# create testing molecule
1690
1690
smiles = "C1CC2CCCC3CCCC(C1)C23"
0 commit comments