@@ -1208,6 +1208,65 @@ def test_adsorbate_thermo_generation_bidentate_nonadjacent(self):
12081208 assert "radical" in thermo .comment , "Expected to need radical correctinos to find CH2j-CH2-CH2j"
12091209 assert "Adsorption correction" in thermo .comment , "Adsorption correction not added to thermo."
12101210
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+
12111270
12121271class TestThermoAccuracy :
12131272 """
@@ -1626,57 +1685,6 @@ def test_get_ring_groups_from_comments(self):
16261685
16271686 self .database .get_ring_groups_from_comments (spc .thermo )
16281687
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 (rmgpy .__file__ ), "data/test_data/" )
1636- database2 .load (os .path .join (path , "thermo" ), 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- # remove the group
1648- rad_group .remove_group (group_to_remove )
1649-
1650- # afterwards group_to_remove should not be in the database or root's children
1651- assert group_to_remove not in list (rad_group .entries .values ())
1652- assert group_to_remove not in root .children
1653-
1654- for child in children :
1655- # group_to_remove children should all be in roots item.component and children attribuetes
1656- assert child .label in root .item .components
1657- assert child in root .children
1658- # the children should all have root a their parent now
1659- assert child .parent is root
1660-
1661- # Specific to ThermoDatabase, (above test apply to all base class Database)
1662- # we check that unicode entry.data pointers are correctly reassigned
1663-
1664- # if group_to_remove is a pointer and another node pointed to it, we copy
1665- # group_to_remove pointer
1666- assert rad_group .entries ["OJ" ].data is group_to_remove .data
1667-
1668- # Remove an entry with a ThermoData object
1669- group_to_remove2 = rad_group .entries ["CsJ" ]
1670- rad_group .remove_group (group_to_remove2 )
1671- # If group_to_remove was a data object, we point toward parent instead
1672- assert rad_group .entries ["RJ2_triplet" ].data == group_to_remove2 .parent .label
1673- # If the parent pointed toward group_to_remove, we need should have copied data object
1674- Tlist = [300 , 400 , 500 , 600 , 800 , 1000 , 1500 ]
1675- assert not isinstance (group_to_remove2 .parent .data , str )
1676- assert group_to_remove2 .parent .data .get_enthalpy (298 ) == group_to_remove2 .data .get_enthalpy (298 )
1677- assert group_to_remove2 .parent .data .get_entropy (298 ) == group_to_remove2 .data .get_entropy (298 )
1678- assert all ([group_to_remove2 .parent .data .get_heat_capacity (x ) == group_to_remove2 .data .get_heat_capacity (x ) for x in Tlist ])
1679-
16801688 def test_is_ring_partial_matched (self ):
16811689 # create testing molecule
16821690 smiles = "C1CC2CCCC3CCCC(C1)C23"
0 commit comments