|
22 | 22 |
|
23 | 23 | from openforcefield.utils.toolkits import (OpenEyeToolkitWrapper, RDKitToolkitWrapper, |
24 | 24 | AmberToolsToolkitWrapper, BuiltInToolkitWrapper, ToolkitRegistry, |
| 25 | + ToolkitWrapper, |
25 | 26 | GAFFAtomTypeWarning, UndefinedStereochemistryError, |
26 | 27 | ChargeMethodUnavailableError, IncorrectNumConformersError, |
27 | 28 | IncorrectNumConformersWarning) |
@@ -2166,8 +2167,93 @@ def test_assign_partial_charges_wrong_n_confs(self): |
2166 | 2167 | use_conformers=molecule.conformers, |
2167 | 2168 | strict_n_conformers=True) |
2168 | 2169 |
|
| 2170 | +class TestToolkitWrapper: |
| 2171 | + """Test the ToolkitWrapper class""" |
| 2172 | + def test_check_n_conformers(self): |
| 2173 | + """Ensure that _check_n_conformers is working properly""" |
| 2174 | + tkw = ToolkitWrapper() |
| 2175 | + mol = create_ethanol() |
| 2176 | + |
| 2177 | + ## Test molecule with no conformers |
| 2178 | + # Check with no min or max should pass |
| 2179 | + tkw._check_n_conformers(mol, 'nocharge') |
| 2180 | + # Check with min=1 should warn |
| 2181 | + with pytest.warns(IncorrectNumConformersWarning, |
| 2182 | + match="has 0 conformers, but charge method 'nocharge' expects at least 1"): |
| 2183 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=1) |
| 2184 | + # Check with min=1 and strict_n_conformers should raise an error |
| 2185 | + with pytest.raises(IncorrectNumConformersError, |
| 2186 | + match="has 0 conformers, but charge method 'nocharge' expects at least 1"): |
| 2187 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=1, strict_n_conformers=True) |
| 2188 | + # Check with min=1, max=1 and strict_n_conformers should raise an error |
| 2189 | + with pytest.raises(IncorrectNumConformersError, |
| 2190 | + match="has 0 conformers, but charge method 'nocharge' expects exactly 1"): |
| 2191 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=1, max_confs=1, strict_n_conformers=True) |
| 2192 | + # Check with min=1, max=2 and strict_n_conformers should raise an error |
| 2193 | + with pytest.raises(IncorrectNumConformersError, |
| 2194 | + match="has 0 conformers, but charge method 'nocharge' expects between 1 and 2"): |
| 2195 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=1, max_confs=2, strict_n_conformers=True) |
| 2196 | + # Check with max=1 should pass |
| 2197 | + tkw._check_n_conformers(mol, 'nocharge', max_confs=1, strict_n_conformers=True) |
| 2198 | + |
| 2199 | + ## Test molecule with conformers |
| 2200 | + # Add some conformers |
| 2201 | + mol.generate_conformers(n_conformers=1) |
| 2202 | + for _ in range(9): |
| 2203 | + mol.add_conformer(mol.conformers[0]) |
| 2204 | + |
| 2205 | + # Check with no min or max should pass |
| 2206 | + tkw._check_n_conformers(mol, 'nocharge') |
| 2207 | + |
| 2208 | + ## min_confs checks |
| 2209 | + # Check with min=1 should be fine |
| 2210 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=1) |
| 2211 | + # Check with min=10 should be fine |
| 2212 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=10) |
| 2213 | + # Check with min=11 should warn |
| 2214 | + with pytest.warns(IncorrectNumConformersWarning, |
| 2215 | + match="has 10 conformers, but charge method 'nocharge' expects at least 11"): |
| 2216 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=11) |
| 2217 | + # Check with min=11 and strict_n_conformers should raise an error |
| 2218 | + with pytest.raises(IncorrectNumConformersError, |
| 2219 | + match="has 10 conformers, but charge method 'nocharge' expects at least 11"): |
| 2220 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=11, strict_n_conformers=True) |
| 2221 | + |
| 2222 | + ## max_confs checks |
| 2223 | + # Check with max=1 and strict_n_conformers should raise an error |
| 2224 | + with pytest.raises(IncorrectNumConformersError, |
| 2225 | + match="has 10 conformers, but charge method 'nocharge' expects at most 1"): |
| 2226 | + tkw._check_n_conformers(mol, 'nocharge', max_confs=1, strict_n_conformers=True) |
| 2227 | + # Check with max=10 and strict_n_conformers should be OK |
| 2228 | + tkw._check_n_conformers(mol, 'nocharge', max_confs=10, strict_n_conformers=True) |
| 2229 | + # Check with max=11 and strict_n_conformers should be OK |
| 2230 | + tkw._check_n_conformers(mol, 'nocharge', max_confs=11, strict_n_conformers=True) |
| 2231 | + |
| 2232 | + ## min_confs and max_confs checks |
| 2233 | + # Check with max=10 and min=10 and strict_n_conformers should be OK |
| 2234 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=10, max_confs=10, strict_n_conformers=True) |
| 2235 | + # Check with max=10 and min=9 and strict_n_conformers should be OK |
| 2236 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=9, max_confs=10, strict_n_conformers=True) |
| 2237 | + # Check with max=11 and min=10 and strict_n_conformers should be OK |
| 2238 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=10, max_confs=11, strict_n_conformers=True) |
| 2239 | + # Check with max=11 and min=9 and strict_n_conformers should be OK |
| 2240 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=9, max_confs=11, strict_n_conformers=True) |
| 2241 | + # Check with min=9 and max=9 and strict_n_conformers should raise an error |
| 2242 | + with pytest.raises(IncorrectNumConformersError, |
| 2243 | + match="has 10 conformers, but charge method 'nocharge' expects exactly 9"): |
| 2244 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=9, max_confs=9, strict_n_conformers=True) |
| 2245 | + # Check with min=1 and max=9 and strict_n_conformers should raise an error |
| 2246 | + with pytest.raises(IncorrectNumConformersError, |
| 2247 | + match="has 10 conformers, but charge method 'nocharge' expects between 1 and 9"): |
| 2248 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=1, max_confs=9, strict_n_conformers=True) |
| 2249 | + # Check with min=11 and max=12 and strict_n_conformers should raise an error |
| 2250 | + with pytest.raises(IncorrectNumConformersError, |
| 2251 | + match="has 10 conformers, but charge method 'nocharge' expects between 11 and 12"): |
| 2252 | + tkw._check_n_conformers(mol, 'nocharge', min_confs=11, max_confs=12, strict_n_conformers=True) |
| 2253 | + |
| 2254 | + |
2169 | 2255 | class TestToolkitRegistry: |
2170 | | - """Test the ToolkitRegistry""" |
| 2256 | + """Test the ToolkitRegistry class""" |
2171 | 2257 |
|
2172 | 2258 | @pytest.mark.skipif(not OpenEyeToolkitWrapper.is_available(), reason='OpenEye Toolkit not available') |
2173 | 2259 | def test_register_openeye(self): |
|
0 commit comments