openff-toolkit 0.18.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- devtools/scripts/build_cookiecutter_json.py +22 -0
- docs/conf.py +296 -0
- docs/conftest.py +23 -0
- examples/conformer_energies/conformer_energies.py +143 -0
- examples/deprecated/SMIRNOFF_comparison/compare_molecule_energies.py +48 -0
- examples/deprecated/SMIRNOFF_comparison/compare_set_energies.py +58 -0
- examples/deprecated/liquid_box/create_mol2_pdb/create_mol2_pdb.py +193 -0
- examples/deprecated/liquid_box/openff_simulation.py +72 -0
- examples/deprecated/mixedFF_structure/generate_mixedFF_complex.py +56 -0
- examples/deprecated/testing/test_impropers/tleap_tools.py +120 -0
- examples/examples_helper.py +61 -0
- openff/toolkit/__init__.py +101 -0
- openff/toolkit/_tests/__init__.py +0 -0
- openff/toolkit/_tests/_stale_tests.py +146 -0
- openff/toolkit/_tests/conftest.py +108 -0
- openff/toolkit/_tests/create_molecules.py +494 -0
- openff/toolkit/_tests/mocking.py +145 -0
- openff/toolkit/_tests/molecule/__init__.py +1 -0
- openff/toolkit/_tests/molecule/test_state_enumeration.py +302 -0
- openff/toolkit/_tests/test_energies.py +136 -0
- openff/toolkit/_tests/test_examples.py +109 -0
- openff/toolkit/_tests/test_forcefield.py +3864 -0
- openff/toolkit/_tests/test_interchange.py +19 -0
- openff/toolkit/_tests/test_io.py +19 -0
- openff/toolkit/_tests/test_links.py +73 -0
- openff/toolkit/_tests/test_mm_molecule.py +404 -0
- openff/toolkit/_tests/test_molecule.py +4246 -0
- openff/toolkit/_tests/test_nagl.py +169 -0
- openff/toolkit/_tests/test_parameter_plugins.py +89 -0
- openff/toolkit/_tests/test_parameters.py +2898 -0
- openff/toolkit/_tests/test_toolkit_io.py +1088 -0
- openff/toolkit/_tests/test_toolkits.py +4418 -0
- openff/toolkit/_tests/test_topology.py +2485 -0
- openff/toolkit/_tests/test_utils.py +101 -0
- openff/toolkit/_tests/test_utils_callback.py +178 -0
- openff/toolkit/_tests/test_utils_collections.py +263 -0
- openff/toolkit/_tests/test_utils_serialization.py +168 -0
- openff/toolkit/_tests/utils.py +1747 -0
- openff/toolkit/data/README.md +8 -0
- openff/toolkit/data/molecules/AlkEthOH_test_filt1_ff.mol2 +2026 -0
- openff/toolkit/data/molecules/AlkEthOH_test_filt1_tripos.mol2 +2026 -0
- openff/toolkit/data/molecules/AlkEthOH_tripos.tar.gz +0 -0
- openff/toolkit/data/molecules/CID20742535_anion.sdf +50 -0
- openff/toolkit/data/molecules/CID20742535_neutral.sdf +51 -0
- openff/toolkit/data/molecules/FreeSolv.tar.gz +0 -0
- openff/toolkit/data/molecules/MiniDrugBank.sdf +33988 -0
- openff/toolkit/data/molecules/MiniDrugBank_tripos.mol2 +35462 -0
- openff/toolkit/data/molecules/PT2385.sdf +90 -0
- openff/toolkit/data/molecules/QL8.sdf +401 -0
- openff/toolkit/data/molecules/README.md +21 -0
- openff/toolkit/data/molecules/benzene.crd +8 -0
- openff/toolkit/data/molecules/benzene.mol2 +34 -0
- openff/toolkit/data/molecules/benzene.top +166 -0
- openff/toolkit/data/molecules/butane_multi.sdf +231 -0
- openff/toolkit/data/molecules/cyclohexane.mol2 +44 -0
- openff/toolkit/data/molecules/ethanol.mol2 +25 -0
- openff/toolkit/data/molecules/ethanol.sdf +23 -0
- openff/toolkit/data/molecules/ethanol_partial_charges.sdf +26 -0
- openff/toolkit/data/molecules/ethanol_reordered.mol2 +25 -0
- openff/toolkit/data/molecules/ethanol_reordered.sdf +23 -0
- openff/toolkit/data/molecules/ethene_rdkit.sdf +17 -0
- openff/toolkit/data/molecules/laromustine_ff.mol2 +71 -0
- openff/toolkit/data/molecules/laromustine_tripos.mol2 +71 -0
- openff/toolkit/data/molecules/methane_multiconformer.sdf +32 -0
- openff/toolkit/data/molecules/methane_multiconformer_properties.sdf +45 -0
- openff/toolkit/data/molecules/nh4.pdb +7 -0
- openff/toolkit/data/molecules/po4_phenylphosphate.pdb +46 -0
- openff/toolkit/data/molecules/ruxolitinib_conformers.sdf +910 -0
- openff/toolkit/data/molecules/toluene.mol2 +38 -0
- openff/toolkit/data/molecules/toluene.mol2.gz +0 -0
- openff/toolkit/data/molecules/toluene.pdb +30 -0
- openff/toolkit/data/molecules/toluene.sdf +36 -0
- openff/toolkit/data/molecules/toluene_charged.mol2 +38 -0
- openff/toolkit/data/molecules/z_3_hydroxy_propenal.sdf +23 -0
- openff/toolkit/data/proteins/5tbm_complex_solv.pdb +1928 -0
- openff/toolkit/data/proteins/5tbm_complex_solv_box.pdb +19563 -0
- openff/toolkit/data/proteins/CTerminal_ALA.pdb +20 -0
- openff/toolkit/data/proteins/CTerminal_ALA.sdf +43 -0
- openff/toolkit/data/proteins/CTerminal_ALA_ALA.pdb +30 -0
- openff/toolkit/data/proteins/CTerminal_ALA_ALA_misnamedH.pdb +30 -0
- openff/toolkit/data/proteins/CTerminal_ARG.pdb +34 -0
- openff/toolkit/data/proteins/CTerminal_TRP.pdb +34 -0
- openff/toolkit/data/proteins/MainChain_ALA.pdb +25 -0
- openff/toolkit/data/proteins/MainChain_ALA.sdf +52 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA.pdb +35 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA.sdf +69 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA_icodes.pdb +35 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA_no_hydrogens.pdb +17 -0
- openff/toolkit/data/proteins/MainChain_ARG.pdb +39 -0
- openff/toolkit/data/proteins/MainChain_ARG.sdf +81 -0
- openff/toolkit/data/proteins/MainChain_CYM.pdb +25 -0
- openff/toolkit/data/proteins/MainChain_CYS.pdb +26 -0
- openff/toolkit/data/proteins/MainChain_CYX.pdb +48 -0
- openff/toolkit/data/proteins/MainChain_CYX.sdf +96 -0
- openff/toolkit/data/proteins/MainChain_GLH.sdf +64 -0
- openff/toolkit/data/proteins/MainChain_GLU.sdf +63 -0
- openff/toolkit/data/proteins/MainChain_HID.pdb +32 -0
- openff/toolkit/data/proteins/MainChain_HIE.pdb +32 -0
- openff/toolkit/data/proteins/MainChain_HIE.sdf +67 -0
- openff/toolkit/data/proteins/MainChain_HIP.pdb +33 -0
- openff/toolkit/data/proteins/MainChain_HIP.sdf +70 -0
- openff/toolkit/data/proteins/MainChain_PRO.pdb +29 -0
- openff/toolkit/data/proteins/MainChain_TRP.pdb +39 -0
- openff/toolkit/data/proteins/NTerminal_ALA.pdb +21 -0
- openff/toolkit/data/proteins/NTerminal_ALA.sdf +45 -0
- openff/toolkit/data/proteins/NTerminal_ALA_ALA.pdb +31 -0
- openff/toolkit/data/proteins/NTerminal_ARG.pdb +35 -0
- openff/toolkit/data/proteins/NTerminal_TRP.pdb +35 -0
- openff/toolkit/data/proteins/T4-protein-unprocessed-4w51.pdb +1892 -0
- openff/toolkit/data/proteins/T4-protein.mol2 +5461 -0
- openff/toolkit/data/proteins/T4-protein.pdb +2637 -0
- openff/toolkit/data/proteins/T4-protein.sdf +5318 -0
- openff/toolkit/data/proteins/T4_protein_waters.pdb +2965 -0
- openff/toolkit/data/proteins/TwoMol_SER_CYS.pdb +50 -0
- openff/toolkit/data/proteins/aa_residues_substructures_explicit_bond_orders_with_caps.json +6435 -0
- openff/toolkit/data/proteins/aa_residues_substructures_explicit_bond_orders_with_caps_explicit_connectivity.json +6675 -0
- openff/toolkit/data/proteins/aa_residues_substructures_with_caps.json +6297 -0
- openff/toolkit/data/proteins/ace-ZZZ-gly-nme.pdb +78 -0
- openff/toolkit/data/proteins/ace-ZZZ-gly-nme.sdf +98 -0
- openff/toolkit/data/proteins/ace-a10-nme.sdf +229 -0
- openff/toolkit/data/proteins/ace-ala-nh2.pdb +21 -0
- openff/toolkit/data/proteins/fluoresceine_dyed_helix_capped.pdb +338 -0
- openff/toolkit/data/proteins/neutral_arginine.pdb +31 -0
- openff/toolkit/data/proteins/split_chain.pdb +74 -0
- openff/toolkit/data/proteins/split_chain_reordered.pdb +74 -0
- openff/toolkit/data/reference_energies/README.md +6 -0
- openff/toolkit/data/reference_energies/reference_0.8.0.json +1 -0
- openff/toolkit/data/reference_energies/reference_0.8.0.json.txt +180 -0
- openff/toolkit/data/reference_energies/reference_after_1007.json +1 -0
- openff/toolkit/data/reference_energies/reference_after_1007.json.txt +350 -0
- openff/toolkit/data/reference_energies/reference_after_802.json +1 -0
- openff/toolkit/data/reference_energies/reference_after_802.json.txt +291 -0
- openff/toolkit/data/systems/README.md +3 -0
- openff/toolkit/data/systems/amber/cyclohexane_ethanol_0.4_0.6.inpcrd +1511 -0
- openff/toolkit/data/systems/amber/cyclohexane_ethanol_0.4_0.6.prmtop +13367 -0
- openff/toolkit/data/systems/monomers/butanol.mol2 +38 -0
- openff/toolkit/data/systems/monomers/butanol.sdf +88 -0
- openff/toolkit/data/systems/monomers/cyclohexane.mol2 +45 -0
- openff/toolkit/data/systems/monomers/cyclohexane.sdf +105 -0
- openff/toolkit/data/systems/monomers/ethanol.mol2 +26 -0
- openff/toolkit/data/systems/monomers/ethanol.sdf +58 -0
- openff/toolkit/data/systems/monomers/methane.mol2 +18 -0
- openff/toolkit/data/systems/monomers/methane.sdf +38 -0
- openff/toolkit/data/systems/monomers/propane.mol2 +30 -0
- openff/toolkit/data/systems/monomers/propane.sdf +68 -0
- openff/toolkit/data/systems/monomers/tip3p_water.mol2 +14 -0
- openff/toolkit/data/systems/monomers/water.mol2 +14 -0
- openff/toolkit/data/systems/monomers/water.sdf +28 -0
- openff/toolkit/data/systems/packmol_boxes/cyclohexane_ethanol_0.4_0.6.pdb +6272 -0
- openff/toolkit/data/systems/packmol_boxes/cyclohexane_water.pdb +5524 -0
- openff/toolkit/data/systems/packmol_boxes/ethanol_water.pdb +5174 -0
- openff/toolkit/data/systems/packmol_boxes/propane_methane_butanol_0.2_0.3_0.5.pdb +7959 -0
- openff/toolkit/data/systems/test_systems/1_cyclohexane_1_ethanol.pdb +61 -0
- openff/toolkit/data/systems/test_systems/1_ethanol.pdb +24 -0
- openff/toolkit/data/systems/test_systems/1_ethanol_no_conect.pdb +15 -0
- openff/toolkit/data/systems/test_systems/1_ethanol_reordered.pdb +24 -0
- openff/toolkit/data/systems/test_systems/PE.pdb +67 -0
- openff/toolkit/data/systems/test_systems/README.md +3 -0
- openff/toolkit/data/systems/test_systems/T4_lysozyme_water_ions.pdb +29240 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH.offxml +61 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH_GBSA.offxml +78 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH_MDL.offxml +62 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH_parmAtFrosst.offxml +64 -0
- openff/toolkit/data/test_forcefields/GBSA_HCT-1.0.offxml +21 -0
- openff/toolkit/data/test_forcefields/GBSA_OBC1-1.0.offxml +18 -0
- openff/toolkit/data/test_forcefields/GBSA_OBC2-1.0.offxml +18 -0
- openff/toolkit/data/test_forcefields/README.md +23 -0
- openff/toolkit/data/test_forcefields/ammonia_minimal.offxml +27 -0
- openff/toolkit/data/test_forcefields/benzene_minimal.offxml +29 -0
- openff/toolkit/data/test_forcefields/chargeincrement-test.offxml +16 -0
- openff/toolkit/data/test_forcefields/frcmod.Frosst_AlkEthOH_withIDs +85 -0
- openff/toolkit/data/test_forcefields/ion_charges.offxml +18 -0
- openff/toolkit/data/test_forcefields/mangled.offxml +9 -0
- openff/toolkit/data/test_forcefields/old/README.md +9 -0
- openff/toolkit/data/test_forcefields/old/hbonds.offxml +11 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_2_spec_0_1.offxml +332 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_2_spec_0_2.offxml +338 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_2_spec_0_3.offxml +329 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_fixed_spec_0_1.offxml +342 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_fixed_spec_0_2.offxml +348 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_fixed_spec_0_3.offxml +337 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_spec_0_1.offxml +340 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_spec_0_2.offxml +346 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_spec_0_3.offxml +337 -0
- openff/toolkit/data/test_forcefields/smirff99Frosst_reference_0_1_spec.offxml +349 -0
- openff/toolkit/data/test_forcefields/smirnoff99Frosst_experimental.offxml +343 -0
- openff/toolkit/data/test_forcefields/smirnoff99Frosst_reference_0_1_spec.offxml +349 -0
- openff/toolkit/data/test_forcefields/smirnoff99Frosst_reference_0_2_spec.offxml +356 -0
- openff/toolkit/data/test_forcefields/test_forcefield.offxml +346 -0
- openff/toolkit/data/test_forcefields/tip3p.offxml +22 -0
- openff/toolkit/data/test_forcefields/unsupported_smirnoff_version.offxml +9 -0
- openff/toolkit/topology/__init__.py +43 -0
- openff/toolkit/topology/_mm_molecule.py +663 -0
- openff/toolkit/topology/molecule.py +6102 -0
- openff/toolkit/topology/topology.py +2555 -0
- openff/toolkit/typing/__init__.py +1 -0
- openff/toolkit/typing/engines/__init__.py +1 -0
- openff/toolkit/typing/engines/smirnoff/__init__.py +31 -0
- openff/toolkit/typing/engines/smirnoff/forcefield.py +1440 -0
- openff/toolkit/typing/engines/smirnoff/io.py +234 -0
- openff/toolkit/typing/engines/smirnoff/parameters.py +3839 -0
- openff/toolkit/typing/engines/smirnoff/plugins.py +91 -0
- openff/toolkit/utils/__init__.py +57 -0
- openff/toolkit/utils/_viz.py +104 -0
- openff/toolkit/utils/ambertools_wrapper.py +507 -0
- openff/toolkit/utils/base_wrapper.py +268 -0
- openff/toolkit/utils/builtin_wrapper.py +136 -0
- openff/toolkit/utils/callback.py +187 -0
- openff/toolkit/utils/collections.py +247 -0
- openff/toolkit/utils/constants.py +18 -0
- openff/toolkit/utils/exceptions.py +766 -0
- openff/toolkit/utils/nagl_wrapper.py +164 -0
- openff/toolkit/utils/openeye_wrapper.py +2750 -0
- openff/toolkit/utils/rdkit_wrapper.py +3302 -0
- openff/toolkit/utils/serialization.py +466 -0
- openff/toolkit/utils/toolkit_registry.py +509 -0
- openff/toolkit/utils/toolkits.py +217 -0
- openff/toolkit/utils/utils.py +805 -0
- openff_toolkit-0.18.0.dist-info/METADATA +109 -0
- openff_toolkit-0.18.0.dist-info/RECORD +231 -0
- openff_toolkit-0.18.0.dist-info/WHEEL +5 -0
- openff_toolkit-0.18.0.dist-info/licenses/LICENSE +21 -0
- openff_toolkit-0.18.0.dist-info/top_level.txt +5 -0
- utilities/deprecated/convert_frosst/convert_frcmod_0.1.py +251 -0
- utilities/deprecated/convert_frosst/convert_frcmod_0.2.py +249 -0
- utilities/deprecated/convert_frosst/convert_frcmod_0.3.py +249 -0
- utilities/make_substructure_dict/_cif_to_substructure_dict.py +955 -0
- utilities/make_substructure_dict/_make_chemical_substructures.py +46 -0
- utilities/make_substructure_dict/_make_metadata_assignment_substructures.py +35 -0
- utilities/test_plugins/custom_plugins/handler_plugins.py +48 -0
- utilities/test_plugins/setup.py +19 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from openff.utilities import requires_package as requires_pkg
|
|
3
|
+
|
|
4
|
+
from openff.toolkit.topology import Molecule
|
|
5
|
+
from openff.toolkit.typing.engines.smirnoff.forcefield import ForceField
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.xfail()
|
|
9
|
+
@requires_pkg("openff.interchange")
|
|
10
|
+
def test_basic_construction():
|
|
11
|
+
top = Molecule.from_smiles("C").to_topology()
|
|
12
|
+
parsley = ForceField("openff-1.0.0.offxml")
|
|
13
|
+
out = parsley.create_interchange(top)
|
|
14
|
+
|
|
15
|
+
assert out.topology is not None
|
|
16
|
+
assert out.topology.mdtop is not None
|
|
17
|
+
assert out.positions is None
|
|
18
|
+
for key in ["vdW", "Bonds", "ProperTorsions", "Electrostatics"]:
|
|
19
|
+
assert key in out.handlers
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Test classes and function in module openff.toolkit.typing.engines.smirnoff.io.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from openff.toolkit.typing.engines.smirnoff.io import XMLParameterIOHandler
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestXMLParameterIOHandler:
|
|
12
|
+
def test_from_string(self):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def test_raise_file_not_found(self):
|
|
16
|
+
"""Raise FileNotFoundError when the file doesn't exist."""
|
|
17
|
+
io_handler = XMLParameterIOHandler()
|
|
18
|
+
with pytest.raises(FileNotFoundError):
|
|
19
|
+
io_handler.parse_file("nonexisting_file.xml")
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import re
|
|
3
|
+
from urllib.request import Request, urlopen
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def find_readme_links() -> list[str]:
|
|
9
|
+
"""Yield all the links in the main README.md file.
|
|
10
|
+
|
|
11
|
+
Returns
|
|
12
|
+
-------
|
|
13
|
+
readme_examples : list[str]
|
|
14
|
+
The list of links included in the README.md file.
|
|
15
|
+
"""
|
|
16
|
+
if "site-packages" in __file__:
|
|
17
|
+
# This test file is being collected from the installed package, which
|
|
18
|
+
# does not provide the README file.
|
|
19
|
+
# Note that there will likely be a mis-bundled file
|
|
20
|
+
# $CONDA_PREFIX/lib/python3.x/site-packages/README.md, but this is not
|
|
21
|
+
# the toolkit's README file!
|
|
22
|
+
return list()
|
|
23
|
+
|
|
24
|
+
else:
|
|
25
|
+
readme_file_path = pathlib.Path(__file__).parents[3] / "README.md"
|
|
26
|
+
with open(readme_file_path.as_posix()) as f:
|
|
27
|
+
readme_content = f.read()
|
|
28
|
+
|
|
29
|
+
with open(readme_file_path.as_posix()) as f:
|
|
30
|
+
readme_content = f.read()
|
|
31
|
+
|
|
32
|
+
return re.findall("http[s]?://(?:[0-9a-zA-Z]|[-/.%:_])+", readme_content)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.parametrize("readme_link", find_readme_links())
|
|
36
|
+
def test_readme_links(readme_link):
|
|
37
|
+
"""Test URLs in README are reachable"""
|
|
38
|
+
# Some websites do not accept requests that don't specify the
|
|
39
|
+
# client and the type of accepted documents so we add fake info
|
|
40
|
+
# to avoid the response being an error.
|
|
41
|
+
headers = {
|
|
42
|
+
"User-Agent": "Mozilla/5.0",
|
|
43
|
+
"Accept": "application/xhtml+xml,text/html,application/xml;q=0.9,*/*;q=0.8",
|
|
44
|
+
}
|
|
45
|
+
request = Request(readme_link, headers=headers)
|
|
46
|
+
|
|
47
|
+
# Some DOI-based links are now behind DDoS protections, so skip them
|
|
48
|
+
if "doi.org" in readme_link:
|
|
49
|
+
pytest.skip("DOI links are behind DDoS protection and do not resolve")
|
|
50
|
+
if "codecov.io" in readme_link:
|
|
51
|
+
pytest.skip("Codecov website DOI also may be behind DDoS protection")
|
|
52
|
+
if "export" in readme_link:
|
|
53
|
+
# October 2023 Zenodo upgrade seems to have broken this link - although
|
|
54
|
+
# it is still accessible from the web UI (go to the landing page of a
|
|
55
|
+
# record, Export section (select BibTeX in drop-down) and click "Export"
|
|
56
|
+
# button will bring you to this link.
|
|
57
|
+
pytest.skip("Seems to be a Zenodo regression in bibtex link")
|
|
58
|
+
if readme_link.endswith("MIT"):
|
|
59
|
+
# January 22 2024: Link causing some failures, accessible in browser
|
|
60
|
+
pytest.skip("Flaky")
|
|
61
|
+
|
|
62
|
+
# Try to connect 5 times, keeping track of exceptions so useful feedback can be provided.
|
|
63
|
+
success = False
|
|
64
|
+
exception = None
|
|
65
|
+
for retry in range(5):
|
|
66
|
+
try:
|
|
67
|
+
urlopen(request)
|
|
68
|
+
success = True
|
|
69
|
+
break
|
|
70
|
+
except Exception as e:
|
|
71
|
+
exception = e
|
|
72
|
+
if not (success):
|
|
73
|
+
raise exception
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from openff.toolkit import Molecule, Topology
|
|
7
|
+
from openff.toolkit._tests.create_molecules import create_ethanol
|
|
8
|
+
from openff.toolkit._tests.create_molecules import (
|
|
9
|
+
dipeptide_residues_perceived as create_dipeptide,
|
|
10
|
+
)
|
|
11
|
+
from openff.toolkit._tests.utils import get_data_file_path, requires_rdkit
|
|
12
|
+
from openff.toolkit.topology._mm_molecule import _SimpleAtom, _SimpleMolecule
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.fixture()
|
|
16
|
+
def water():
|
|
17
|
+
water = _SimpleMolecule()
|
|
18
|
+
water.add_atom(atomic_number=8)
|
|
19
|
+
water.add_atom(atomic_number=1)
|
|
20
|
+
water.add_atom(atomic_number=1)
|
|
21
|
+
water.add_bond(0, 1)
|
|
22
|
+
water.add_bond(0, 2)
|
|
23
|
+
|
|
24
|
+
return water
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture()
|
|
28
|
+
def methane():
|
|
29
|
+
methane = _SimpleMolecule()
|
|
30
|
+
methane.add_atom(atomic_number=6)
|
|
31
|
+
methane.add_atom(atomic_number=1)
|
|
32
|
+
methane.add_atom(atomic_number=1)
|
|
33
|
+
methane.add_atom(atomic_number=1)
|
|
34
|
+
methane.add_atom(atomic_number=1)
|
|
35
|
+
methane.add_bond(0, 1)
|
|
36
|
+
methane.add_bond(0, 2)
|
|
37
|
+
methane.add_bond(0, 3)
|
|
38
|
+
methane.add_bond(0, 4)
|
|
39
|
+
|
|
40
|
+
return methane
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.fixture()
|
|
44
|
+
def methanol():
|
|
45
|
+
methanol = _SimpleMolecule()
|
|
46
|
+
methanol.add_atom(atomic_number=8)
|
|
47
|
+
methanol.add_atom(atomic_number=6)
|
|
48
|
+
methanol.add_atom(atomic_number=1)
|
|
49
|
+
methanol.add_atom(atomic_number=1)
|
|
50
|
+
methanol.add_atom(atomic_number=1)
|
|
51
|
+
methanol.add_bond(0, 1)
|
|
52
|
+
methanol.add_bond(1, 2)
|
|
53
|
+
methanol.add_bond(1, 3)
|
|
54
|
+
methanol.add_bond(1, 4)
|
|
55
|
+
|
|
56
|
+
return methanol
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.fixture()
|
|
60
|
+
def molecule_with_zero_atom():
|
|
61
|
+
molecule = _SimpleMolecule()
|
|
62
|
+
molecule.add_atom(atomic_number=6)
|
|
63
|
+
molecule.add_atom(atomic_number=0)
|
|
64
|
+
molecule.add_bond(0, 1)
|
|
65
|
+
|
|
66
|
+
return molecule
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.fixture()
|
|
70
|
+
def molecule_with_bogus_atom():
|
|
71
|
+
molecule = _SimpleMolecule()
|
|
72
|
+
molecule.add_atom(atomic_number=6)
|
|
73
|
+
molecule.add_atom(atomic_number=-1)
|
|
74
|
+
molecule.add_bond(0, 1)
|
|
75
|
+
|
|
76
|
+
return molecule
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@pytest.fixture()
|
|
80
|
+
def t4():
|
|
81
|
+
return _SimpleMolecule.from_molecule(Topology.from_pdb(get_data_file_path("proteins/T4-protein.pdb")).molecule(0))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class TestMMMolecule:
|
|
85
|
+
def test_create_water(self):
|
|
86
|
+
water = _SimpleMolecule()
|
|
87
|
+
water.add_atom(atomic_number=8)
|
|
88
|
+
water.add_atom(atomic_number=1)
|
|
89
|
+
water.add_atom(atomic_number=1)
|
|
90
|
+
water.add_bond(0, 1)
|
|
91
|
+
water.add_bond(0, 2)
|
|
92
|
+
assert water.n_atoms == 3
|
|
93
|
+
assert water.n_bonds == 2
|
|
94
|
+
assert water.n_conformers == 0
|
|
95
|
+
|
|
96
|
+
def test_bond_getters(self, water):
|
|
97
|
+
assert water.get_bond_between(0, 1) is not water.get_bond_between(0, 2)
|
|
98
|
+
assert water.bond(0) is not water.bond(1)
|
|
99
|
+
|
|
100
|
+
assert water.get_bond_between(0, 1) is water.bond(0)
|
|
101
|
+
assert water.get_bond_between(0, 2) is water.bond(1)
|
|
102
|
+
|
|
103
|
+
def test_hill_formula(
|
|
104
|
+
self,
|
|
105
|
+
water,
|
|
106
|
+
molecule_with_zero_atom,
|
|
107
|
+
molecule_with_bogus_atom,
|
|
108
|
+
):
|
|
109
|
+
assert water.hill_formula == "H2O"
|
|
110
|
+
assert molecule_with_zero_atom.hill_formula == "CX"
|
|
111
|
+
assert molecule_with_bogus_atom.hill_formula == "INVALID"
|
|
112
|
+
|
|
113
|
+
def test_to_networkx(self, water):
|
|
114
|
+
graph = water.to_networkx()
|
|
115
|
+
|
|
116
|
+
assert graph.number_of_nodes() == water.n_atoms
|
|
117
|
+
assert graph.number_of_edges() == water.n_bonds
|
|
118
|
+
|
|
119
|
+
def test_add_conformer(self, water):
|
|
120
|
+
water_molecule = Molecule.from_smiles("O")
|
|
121
|
+
water_molecule.generate_conformers(n_conformers=1)
|
|
122
|
+
|
|
123
|
+
assert water.n_conformers == 0
|
|
124
|
+
water.add_conformer(water_molecule.conformers[0])
|
|
125
|
+
assert water.n_conformers == 1
|
|
126
|
+
|
|
127
|
+
assert np.allclose(water.conformers[0], water_molecule.conformers[0])
|
|
128
|
+
|
|
129
|
+
def test_dict_roundtrip(self, water):
|
|
130
|
+
roundtrip = _SimpleMolecule.from_dict(water.to_dict())
|
|
131
|
+
|
|
132
|
+
assert roundtrip.n_atoms == water.n_atoms
|
|
133
|
+
assert roundtrip.n_bonds == water.n_bonds
|
|
134
|
+
|
|
135
|
+
for atom_index in range(roundtrip.n_atoms):
|
|
136
|
+
assert roundtrip.atom(atom_index).atomic_number == water.atom(atom_index).atomic_number
|
|
137
|
+
|
|
138
|
+
def test_dict_roundtrip_conformers(self, water):
|
|
139
|
+
water_molecule = Molecule.from_smiles("O")
|
|
140
|
+
water_molecule.generate_conformers(n_conformers=1)
|
|
141
|
+
|
|
142
|
+
water.add_conformer(water_molecule.conformers[0])
|
|
143
|
+
|
|
144
|
+
roundtrip = _SimpleMolecule.from_dict(water.to_dict())
|
|
145
|
+
|
|
146
|
+
assert water.n_conformers == roundtrip.n_conformers
|
|
147
|
+
assert np.allclose(water.conformers[0], roundtrip.conformers[0])
|
|
148
|
+
|
|
149
|
+
def test_from_molecule(self):
|
|
150
|
+
converted = _SimpleMolecule.from_molecule(Molecule.from_smiles("O"))
|
|
151
|
+
|
|
152
|
+
assert converted.n_atoms == 3
|
|
153
|
+
assert converted.n_bonds == 2
|
|
154
|
+
|
|
155
|
+
expected_atomic_numbers = [8, 1, 1]
|
|
156
|
+
for atom_index in range(converted.n_atoms):
|
|
157
|
+
found = converted.atom(atom_index).atomic_number
|
|
158
|
+
assert found == expected_atomic_numbers[atom_index]
|
|
159
|
+
|
|
160
|
+
def test_deepcopy(self, water, methane, methanol):
|
|
161
|
+
for molecule in [water, methane, methanol]:
|
|
162
|
+
molecule_copy = copy.deepcopy(molecule)
|
|
163
|
+
|
|
164
|
+
assert molecule_copy.n_atoms == molecule.n_atoms
|
|
165
|
+
assert molecule_copy.n_bonds == molecule.n_bonds
|
|
166
|
+
|
|
167
|
+
for atom, atom_copy in zip(
|
|
168
|
+
molecule.atoms,
|
|
169
|
+
molecule_copy.atoms,
|
|
170
|
+
):
|
|
171
|
+
assert atom.atomic_number == atom_copy.atomic_number
|
|
172
|
+
|
|
173
|
+
assert atom.molecule is molecule
|
|
174
|
+
assert atom_copy.molecule is molecule_copy
|
|
175
|
+
|
|
176
|
+
@pytest.mark.slow
|
|
177
|
+
@requires_rdkit
|
|
178
|
+
def test_deepcopy_t4(self, t4):
|
|
179
|
+
t4_copy = copy.deepcopy(t4)
|
|
180
|
+
|
|
181
|
+
assert t4_copy.n_atoms == t4.n_atoms
|
|
182
|
+
assert t4_copy.n_bonds == t4.n_bonds
|
|
183
|
+
|
|
184
|
+
for atom, atom_copy in zip(
|
|
185
|
+
t4.atoms,
|
|
186
|
+
t4_copy.atoms,
|
|
187
|
+
):
|
|
188
|
+
assert atom.atomic_number == atom_copy.atomic_number
|
|
189
|
+
|
|
190
|
+
assert atom.molecule is t4
|
|
191
|
+
assert atom_copy.molecule is t4_copy
|
|
192
|
+
|
|
193
|
+
def test_to_single_molecule_topology(self, methanol):
|
|
194
|
+
topology = methanol.to_topology()
|
|
195
|
+
|
|
196
|
+
assert topology.n_molecules == 1
|
|
197
|
+
assert topology.molecule(0).is_isomorphic_with(methanol)
|
|
198
|
+
|
|
199
|
+
assert topology.n_atoms == methanol.n_atoms
|
|
200
|
+
assert topology.n_bonds == methanol.n_bonds
|
|
201
|
+
|
|
202
|
+
@pytest.mark.slow
|
|
203
|
+
@requires_rdkit
|
|
204
|
+
def test_to_t4_topology(self, t4):
|
|
205
|
+
topology = t4.to_topology()
|
|
206
|
+
|
|
207
|
+
assert topology.n_molecules == 1
|
|
208
|
+
assert topology.molecule(0).is_isomorphic_with(t4)
|
|
209
|
+
|
|
210
|
+
assert topology.n_atoms == t4.n_atoms
|
|
211
|
+
assert topology.n_bonds == t4.n_bonds
|
|
212
|
+
|
|
213
|
+
def test_to_openmm_topology(self, methanol):
|
|
214
|
+
topology = methanol.to_topology().to_openmm()
|
|
215
|
+
|
|
216
|
+
assert topology.getNumAtoms() == methanol.n_atoms
|
|
217
|
+
assert topology.getNumBonds() == methanol.n_bonds
|
|
218
|
+
|
|
219
|
+
@pytest.mark.slow
|
|
220
|
+
@pytest.mark.skip(reason="Fails because of https://github.com/openforcefield/openff-toolkit/issues/1783")
|
|
221
|
+
def test_to_openmm_topology_t4(self, t4):
|
|
222
|
+
topology = t4.to_topology().to_openmm()
|
|
223
|
+
|
|
224
|
+
assert topology.getNumAtoms() == t4.n_atoms
|
|
225
|
+
assert topology.getNumBonds() == t4.n_bonds
|
|
226
|
+
|
|
227
|
+
def test_generate_unique_atom_names(self, water):
|
|
228
|
+
# Initially atom names default to empty string
|
|
229
|
+
assert hasattr(water.atom(0), "name")
|
|
230
|
+
assert water.atom(0).name == ""
|
|
231
|
+
|
|
232
|
+
assert water.has_unique_atom_names is False
|
|
233
|
+
# Assign unique atom names and ensure that they're unique
|
|
234
|
+
water.generate_unique_atom_names()
|
|
235
|
+
assert water.has_unique_atom_names is True
|
|
236
|
+
# Now manually make them not-unique and ensure that has_unique_atom_names reflects that
|
|
237
|
+
water.atom(0).name = "foo"
|
|
238
|
+
water.atom(1).name = "foo"
|
|
239
|
+
assert water.has_unique_atom_names is False
|
|
240
|
+
|
|
241
|
+
def test_atom_names_roundtrip(self, water):
|
|
242
|
+
water.atom(0).name = "FOO"
|
|
243
|
+
water.atom(1).name = "BAR"
|
|
244
|
+
water.atom(2).name = "BAZ"
|
|
245
|
+
|
|
246
|
+
roundtrip = copy.deepcopy(water)
|
|
247
|
+
|
|
248
|
+
assert roundtrip.atom(0).name == "FOO"
|
|
249
|
+
assert roundtrip.atom(1).name == "BAR"
|
|
250
|
+
assert roundtrip.atom(2).name == "BAZ"
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class TestSimpleAtom:
|
|
254
|
+
def test_atom_name_in_dict(self):
|
|
255
|
+
atom = _SimpleAtom(atomic_number=7, name="FLAG")
|
|
256
|
+
|
|
257
|
+
assert atom.to_dict()["name"] == "FLAG"
|
|
258
|
+
|
|
259
|
+
assert copy.deepcopy(atom).name == "FLAG"
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
class TestImpropers:
|
|
263
|
+
@pytest.mark.parametrize(
|
|
264
|
+
("smiles", "n_impropers", "n_pruned"),
|
|
265
|
+
[
|
|
266
|
+
("C", 24, 0),
|
|
267
|
+
("CC", 48, 0),
|
|
268
|
+
("N", 6, 6),
|
|
269
|
+
],
|
|
270
|
+
)
|
|
271
|
+
def test_pruned_impropers(self, smiles, n_impropers, n_pruned):
|
|
272
|
+
"""See equivalent test in TestMolecule."""
|
|
273
|
+
molecule = _SimpleMolecule.from_molecule(
|
|
274
|
+
Molecule.from_smiles(smiles),
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
assert molecule.n_impropers == n_impropers
|
|
278
|
+
assert len(list(molecule.smirnoff_impropers)) == n_pruned
|
|
279
|
+
assert len(list(molecule.amber_impropers)) == n_pruned
|
|
280
|
+
|
|
281
|
+
amber_impropers = {*molecule.amber_impropers}
|
|
282
|
+
|
|
283
|
+
for smirnoff_imp in molecule.smirnoff_impropers:
|
|
284
|
+
assert (
|
|
285
|
+
smirnoff_imp[1],
|
|
286
|
+
smirnoff_imp[0],
|
|
287
|
+
smirnoff_imp[2],
|
|
288
|
+
smirnoff_imp[3],
|
|
289
|
+
) in amber_impropers
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class TestIsomorphism:
|
|
293
|
+
@pytest.fixture()
|
|
294
|
+
def n_propanol(self):
|
|
295
|
+
return _SimpleMolecule.from_molecule(
|
|
296
|
+
Molecule.from_mapped_smiles("[H:5][C:1]([H:6])([H:7])[C:2]([H:8])([H:9])[C:3]([H:10])([H:11])[O:4][H:12]")
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
@pytest.fixture()
|
|
300
|
+
def iso_propanol(self):
|
|
301
|
+
return _SimpleMolecule.from_molecule(
|
|
302
|
+
Molecule.from_mapped_smiles("[H:5][C:1]([H:6])([H:7])[C:2]([H:8])([C:3]([H:10])([H:11])[H:12])[O:4][H:9]")
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
@pytest.fixture()
|
|
306
|
+
def o_dichlorobezene(self):
|
|
307
|
+
return _SimpleMolecule.from_molecule(
|
|
308
|
+
Molecule.from_mapped_smiles(
|
|
309
|
+
"[C:1]=1([Cl:7])[C:2]([H:9])=[C:3]([H:10])[C:4]([H:11])=[C:5]([H:12])[C:6]([Cl:8])=1"
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
@pytest.fixture()
|
|
314
|
+
def m_dichlorobezene(self):
|
|
315
|
+
return _SimpleMolecule.from_molecule(
|
|
316
|
+
Molecule.from_mapped_smiles(
|
|
317
|
+
"[C:1]([Cl:7])(=[C:2]1([H:9]))[C:3]([H:10])=[C:4]([H:11])[C:5]([H:12])=[C:6]([Cl:8])1"
|
|
318
|
+
)
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
@pytest.mark.parametrize("as_graphs", [True, False])
|
|
322
|
+
def test_are_isomorphic(self, water, methane, methanol, as_graphs):
|
|
323
|
+
if as_graphs:
|
|
324
|
+
water = water.to_networkx()
|
|
325
|
+
methane = methane.to_networkx()
|
|
326
|
+
methanol = methanol.to_networkx()
|
|
327
|
+
|
|
328
|
+
assert _SimpleMolecule.are_isomorphic(water, water)[0]
|
|
329
|
+
assert _SimpleMolecule.are_isomorphic(methane, methane)[0]
|
|
330
|
+
assert _SimpleMolecule.are_isomorphic(methanol, methanol)[0]
|
|
331
|
+
assert not _SimpleMolecule.are_isomorphic(water, methane)[0]
|
|
332
|
+
assert not _SimpleMolecule.are_isomorphic(water, methanol)[0]
|
|
333
|
+
assert not _SimpleMolecule.are_isomorphic(methane, methanol)[0]
|
|
334
|
+
|
|
335
|
+
def test_is_isomorphic_with(self, water, methane, methanol):
|
|
336
|
+
assert water.is_isomorphic_with(water)
|
|
337
|
+
assert methane.is_isomorphic_with(methane)
|
|
338
|
+
assert methanol.is_isomorphic_with(methanol)
|
|
339
|
+
assert not water.is_isomorphic_with(methane)
|
|
340
|
+
assert not water.is_isomorphic_with(methanol)
|
|
341
|
+
assert not methane.is_isomorphic_with(methanol)
|
|
342
|
+
|
|
343
|
+
def test_short_circuit_heterogeneous_input(self):
|
|
344
|
+
assert not _SimpleMolecule.are_isomorphic(
|
|
345
|
+
create_ethanol(),
|
|
346
|
+
_SimpleMolecule.from_molecule(create_ethanol()),
|
|
347
|
+
)[0]
|
|
348
|
+
|
|
349
|
+
assert not _SimpleMolecule.are_isomorphic(
|
|
350
|
+
_SimpleMolecule.from_molecule(create_ethanol()),
|
|
351
|
+
create_ethanol(),
|
|
352
|
+
)[0]
|
|
353
|
+
|
|
354
|
+
def test_graph_and_molecule_inputs(self, methanol):
|
|
355
|
+
graph = methanol.to_networkx()
|
|
356
|
+
|
|
357
|
+
assert _SimpleMolecule.are_isomorphic(methanol, graph)[0]
|
|
358
|
+
assert _SimpleMolecule.are_isomorphic(graph, methanol)[0]
|
|
359
|
+
|
|
360
|
+
def test_propanol_isopropanol_not_isomorphic(self, n_propanol, iso_propanol):
|
|
361
|
+
assert not _SimpleMolecule.are_isomorphic(n_propanol, iso_propanol)[0]
|
|
362
|
+
|
|
363
|
+
def test_o_m_dichlorobenzene_not_isomorphic(self, o_dichlorobezene, m_dichlorobezene):
|
|
364
|
+
assert not _SimpleMolecule.are_isomorphic(o_dichlorobezene, m_dichlorobezene)[0]
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
class TestHierarchyData:
|
|
368
|
+
@pytest.fixture()
|
|
369
|
+
def simple_dipeptide(self):
|
|
370
|
+
return _SimpleMolecule.from_molecule(create_dipeptide())
|
|
371
|
+
|
|
372
|
+
def test_mm_hierarchy(self):
|
|
373
|
+
molecule = create_dipeptide()
|
|
374
|
+
|
|
375
|
+
assert molecule.hierarchy_schemes is not None
|
|
376
|
+
|
|
377
|
+
mm_molecule = _SimpleMolecule.from_molecule(molecule)
|
|
378
|
+
|
|
379
|
+
assert mm_molecule.hierarchy_schemes.keys() == molecule.hierarchy_schemes.keys()
|
|
380
|
+
|
|
381
|
+
for scheme_name in molecule.hierarchy_schemes:
|
|
382
|
+
assert len(mm_molecule.hierarchy_schemes[scheme_name].hierarchy_elements) == len(
|
|
383
|
+
molecule.hierarchy_schemes[scheme_name].hierarchy_elements
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
def test_hierarchy_preserved_dict_roundtrip(self, simple_dipeptide):
|
|
387
|
+
roundtripped = _SimpleMolecule.from_dict(simple_dipeptide.to_dict())
|
|
388
|
+
|
|
389
|
+
assert [residue.residue_name for residue in roundtripped.residues] == [
|
|
390
|
+
"ACE",
|
|
391
|
+
"ALA",
|
|
392
|
+
]
|
|
393
|
+
|
|
394
|
+
assert [residue.residue_number for residue in roundtripped.residues] == [
|
|
395
|
+
"1",
|
|
396
|
+
"2",
|
|
397
|
+
]
|
|
398
|
+
|
|
399
|
+
def test_lookup_attribute_not_found(self, simple_dipeptide):
|
|
400
|
+
with pytest.raises(
|
|
401
|
+
AttributeError,
|
|
402
|
+
match=r"object has no attribute .*foobars",
|
|
403
|
+
):
|
|
404
|
+
simple_dipeptide.foobars
|