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,507 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wrapper class providing a minimal consistent interface to `AmberTools <http://ambermd.org/AmberTools.php>`_.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__all__ = ("AmberToolsToolkitWrapper",)
|
|
6
|
+
|
|
7
|
+
import functools
|
|
8
|
+
import subprocess
|
|
9
|
+
import tempfile
|
|
10
|
+
from collections import defaultdict
|
|
11
|
+
from shutil import which
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from openff.toolkit import Quantity, unit
|
|
17
|
+
from openff.toolkit.utils import base_wrapper, rdkit_wrapper
|
|
18
|
+
from openff.toolkit.utils.exceptions import (
|
|
19
|
+
AntechamberNotFoundError,
|
|
20
|
+
ChargeCalculationError,
|
|
21
|
+
ChargeMethodUnavailableError,
|
|
22
|
+
ToolkitUnavailableException,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from openff.toolkit.topology.molecule import Molecule
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AmberToolsToolkitWrapper(base_wrapper.ToolkitWrapper):
|
|
30
|
+
"""
|
|
31
|
+
AmberTools toolkit wrapper
|
|
32
|
+
|
|
33
|
+
.. warning :: This API is experimental and subject to change.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
_toolkit_name = "AmberTools"
|
|
37
|
+
_toolkit_installation_instructions = (
|
|
38
|
+
"The AmberTools toolkit (free and open source) can be found at https://anaconda.org/conda-forge/ambertools"
|
|
39
|
+
)
|
|
40
|
+
_supported_charge_methods = {
|
|
41
|
+
"am1bcc": {
|
|
42
|
+
"antechamber_keyword": "bcc",
|
|
43
|
+
"min_confs": 1,
|
|
44
|
+
"max_confs": 1,
|
|
45
|
+
"rec_confs": 1,
|
|
46
|
+
},
|
|
47
|
+
"am1-mulliken": {
|
|
48
|
+
"antechamber_keyword": "mul",
|
|
49
|
+
"min_confs": 1,
|
|
50
|
+
"max_confs": 1,
|
|
51
|
+
"rec_confs": 1,
|
|
52
|
+
},
|
|
53
|
+
"gasteiger": {
|
|
54
|
+
"antechamber_keyword": "gas",
|
|
55
|
+
"min_confs": 0,
|
|
56
|
+
"max_confs": 0,
|
|
57
|
+
"rec_confs": 0,
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
SUPPORTED_CHARGE_METHODS = _supported_charge_methods
|
|
62
|
+
|
|
63
|
+
def __init__(self):
|
|
64
|
+
super().__init__()
|
|
65
|
+
|
|
66
|
+
if not self.is_available():
|
|
67
|
+
raise ToolkitUnavailableException(
|
|
68
|
+
f"The required toolkit {self._toolkit_name} is not "
|
|
69
|
+
f"available. {self._toolkit_installation_instructions}"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# TODO: Find AMBERHOME or executable home, checking miniconda if needed
|
|
73
|
+
# Store an instance of an RDKitToolkitWrapper for file I/O
|
|
74
|
+
self._rdkit_toolkit_wrapper = rdkit_wrapper.RDKitToolkitWrapper()
|
|
75
|
+
|
|
76
|
+
@functools.cached_property
|
|
77
|
+
def _toolkit_version(self):
|
|
78
|
+
from openff.utilities.provenance import get_ambertools_version
|
|
79
|
+
|
|
80
|
+
return get_ambertools_version()
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def is_available() -> bool:
|
|
84
|
+
"""
|
|
85
|
+
Check whether the AmberTools toolkit is installed
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
is_installed
|
|
90
|
+
True if AmberTools is installed, False otherwise.
|
|
91
|
+
|
|
92
|
+
"""
|
|
93
|
+
# TODO: Check all tools needed
|
|
94
|
+
ANTECHAMBER_PATH = which("antechamber")
|
|
95
|
+
if ANTECHAMBER_PATH is None:
|
|
96
|
+
return False
|
|
97
|
+
# AmberToolsToolkitWrapper needs RDKit to do basically anything, since its interface requires SDF I/O
|
|
98
|
+
if not (rdkit_wrapper.RDKitToolkitWrapper.is_available()):
|
|
99
|
+
return False
|
|
100
|
+
return True
|
|
101
|
+
|
|
102
|
+
def assign_partial_charges(
|
|
103
|
+
self,
|
|
104
|
+
molecule: "Molecule",
|
|
105
|
+
partial_charge_method: str | None = None,
|
|
106
|
+
use_conformers: list[Quantity] | None = None,
|
|
107
|
+
strict_n_conformers: bool = False,
|
|
108
|
+
normalize_partial_charges: bool = True,
|
|
109
|
+
_cls=None,
|
|
110
|
+
):
|
|
111
|
+
"""
|
|
112
|
+
Compute partial charges with AmberTools using antechamber/sqm, and assign
|
|
113
|
+
the new values to the partial_charges attribute.
|
|
114
|
+
|
|
115
|
+
.. warning :: This API experimental and subject to change.
|
|
116
|
+
|
|
117
|
+
.. todo ::
|
|
118
|
+
|
|
119
|
+
* Do we want to also allow ESP/RESP charges?
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
molecule
|
|
124
|
+
Molecule for which partial charges are to be computed
|
|
125
|
+
partial_charge_method
|
|
126
|
+
The charge model to use. One of ['gasteiger', 'am1bcc', 'am1-mulliken'].
|
|
127
|
+
If None, 'am1-mulliken' will be used.
|
|
128
|
+
use_conformers
|
|
129
|
+
with shape (n_atoms, 3) and dimension of distance. Optional, default = None
|
|
130
|
+
List of unit-wrapped numpy arrays to use for partial charge calculation.
|
|
131
|
+
If None, an appropriate number of conformers will be generated.
|
|
132
|
+
strict_n_conformers
|
|
133
|
+
Whether to raise an exception if an invalid number of conformers is provided for
|
|
134
|
+
the given charge method.
|
|
135
|
+
If this is False and an invalid number of conformers is found, a warning will be raised.
|
|
136
|
+
normalize_partial_charges
|
|
137
|
+
Whether to offset partial charges so that they sum to the total formal charge of the molecule.
|
|
138
|
+
This is used to prevent accumulation of rounding errors when the partial charge generation method has
|
|
139
|
+
low precision.
|
|
140
|
+
_cls
|
|
141
|
+
Molecule constructor
|
|
142
|
+
|
|
143
|
+
Raises
|
|
144
|
+
------
|
|
145
|
+
ChargeMethodUnavailableError if the requested charge method can not be handled by this toolkit
|
|
146
|
+
|
|
147
|
+
ChargeCalculationError if the charge method is supported by this toolkit, but fails
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
import os
|
|
151
|
+
import subprocess
|
|
152
|
+
|
|
153
|
+
from openff.toolkit.topology import Molecule
|
|
154
|
+
|
|
155
|
+
if partial_charge_method is None:
|
|
156
|
+
partial_charge_method = "am1-mulliken"
|
|
157
|
+
else:
|
|
158
|
+
# Standardize method name for string comparisons
|
|
159
|
+
partial_charge_method = partial_charge_method.lower()
|
|
160
|
+
|
|
161
|
+
if partial_charge_method not in self._supported_charge_methods:
|
|
162
|
+
raise ChargeMethodUnavailableError(
|
|
163
|
+
f"partial_charge_method '{partial_charge_method}' is not available from AmberToolsToolkitWrapper. "
|
|
164
|
+
f"Available charge methods are {self._supported_charge_methods}"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
charge_method = self._supported_charge_methods[partial_charge_method]
|
|
168
|
+
|
|
169
|
+
if _cls is None:
|
|
170
|
+
_cls = Molecule
|
|
171
|
+
|
|
172
|
+
# Make a temporary copy of the molecule, since we'll be messing with its conformers
|
|
173
|
+
mol_copy = _cls(molecule)
|
|
174
|
+
|
|
175
|
+
if use_conformers is None:
|
|
176
|
+
if charge_method["rec_confs"] == 0:
|
|
177
|
+
mol_copy._conformers = None
|
|
178
|
+
else:
|
|
179
|
+
mol_copy.generate_conformers(
|
|
180
|
+
n_conformers=charge_method["rec_confs"],
|
|
181
|
+
rms_cutoff=0.25 * unit.angstrom,
|
|
182
|
+
toolkit_registry=rdkit_wrapper.RDKitToolkitWrapper(),
|
|
183
|
+
)
|
|
184
|
+
# TODO: What's a "best practice" RMS cutoff to use here?
|
|
185
|
+
else:
|
|
186
|
+
mol_copy._conformers = None
|
|
187
|
+
for conformer in use_conformers:
|
|
188
|
+
mol_copy._add_conformer(conformer)
|
|
189
|
+
self._check_n_conformers(
|
|
190
|
+
mol_copy,
|
|
191
|
+
partial_charge_method=partial_charge_method,
|
|
192
|
+
min_confs=charge_method["min_confs"],
|
|
193
|
+
max_confs=charge_method["max_confs"],
|
|
194
|
+
strict_n_conformers=strict_n_conformers,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
ANTECHAMBER_PATH = which("antechamber")
|
|
198
|
+
if ANTECHAMBER_PATH is None:
|
|
199
|
+
raise AntechamberNotFoundError("Antechamber not found, cannot run assign_partial_charges()")
|
|
200
|
+
|
|
201
|
+
# Compute charges
|
|
202
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
203
|
+
net_charge = mol_copy.total_charge.m_as(unit.elementary_charge)
|
|
204
|
+
# Write out molecule in SDF format
|
|
205
|
+
# TODO: How should we handle multiple conformers?
|
|
206
|
+
self._rdkit_toolkit_wrapper.to_file(mol_copy, f"{tmpdir}/molecule.sdf", file_format="sdf")
|
|
207
|
+
# Compute desired charges
|
|
208
|
+
# TODO: Add error handling if antechamber chokes
|
|
209
|
+
short_charge_method = charge_method["antechamber_keyword"]
|
|
210
|
+
subprocess.check_output(
|
|
211
|
+
[
|
|
212
|
+
"antechamber",
|
|
213
|
+
"-i",
|
|
214
|
+
"molecule.sdf",
|
|
215
|
+
"-fi",
|
|
216
|
+
"sdf",
|
|
217
|
+
"-o",
|
|
218
|
+
"charged.mol2",
|
|
219
|
+
"-fo",
|
|
220
|
+
"mol2",
|
|
221
|
+
"-pf",
|
|
222
|
+
"yes",
|
|
223
|
+
"-dr",
|
|
224
|
+
"n",
|
|
225
|
+
"-c",
|
|
226
|
+
str(short_charge_method),
|
|
227
|
+
"-nc",
|
|
228
|
+
str(net_charge),
|
|
229
|
+
],
|
|
230
|
+
cwd=tmpdir,
|
|
231
|
+
)
|
|
232
|
+
# Write out just charges
|
|
233
|
+
subprocess.check_output(
|
|
234
|
+
[
|
|
235
|
+
"antechamber",
|
|
236
|
+
"-dr",
|
|
237
|
+
"n",
|
|
238
|
+
"-i",
|
|
239
|
+
"charged.mol2",
|
|
240
|
+
"-fi",
|
|
241
|
+
"mol2",
|
|
242
|
+
"-o",
|
|
243
|
+
"charges2.mol2",
|
|
244
|
+
"-fo",
|
|
245
|
+
"mol2",
|
|
246
|
+
"-c",
|
|
247
|
+
"wc",
|
|
248
|
+
"-cf",
|
|
249
|
+
"charges.txt",
|
|
250
|
+
"-pf",
|
|
251
|
+
"yes",
|
|
252
|
+
],
|
|
253
|
+
cwd=tmpdir,
|
|
254
|
+
)
|
|
255
|
+
# Check to ensure charges were actually produced
|
|
256
|
+
if not os.path.exists(f"{tmpdir}/charges.txt"):
|
|
257
|
+
# TODO: copy files into local directory to aid debugging?
|
|
258
|
+
raise ChargeCalculationError(
|
|
259
|
+
"Antechamber/sqm partial charge calculation failed on "
|
|
260
|
+
f"molecule {molecule.name} (SMILES {molecule.to_smiles()})"
|
|
261
|
+
)
|
|
262
|
+
# Read the charges
|
|
263
|
+
with open(f"{tmpdir}/charges.txt") as infile:
|
|
264
|
+
contents = infile.read()
|
|
265
|
+
text_charges = contents.split()
|
|
266
|
+
charges_array = np.zeros([molecule.n_atoms], np.float64)
|
|
267
|
+
for index, token in enumerate(text_charges):
|
|
268
|
+
charges_array[index] = float(token)
|
|
269
|
+
# TODO: Ensure that the atoms in charged.mol2 are in the same order as in molecule.sdf
|
|
270
|
+
molecule.partial_charges = Quantity(charges_array, unit.elementary_charge)
|
|
271
|
+
|
|
272
|
+
if normalize_partial_charges:
|
|
273
|
+
molecule._normalize_partial_charges()
|
|
274
|
+
|
|
275
|
+
def _modify_sqm_in_to_request_bond_orders(self, file_path):
|
|
276
|
+
"""
|
|
277
|
+
Modify a sqm.in file produced by antechamber to include the "printbondorders=1" directive
|
|
278
|
+
in the header. This method will overwrite the original file.
|
|
279
|
+
|
|
280
|
+
Parameters
|
|
281
|
+
----------
|
|
282
|
+
file_path
|
|
283
|
+
The path to sqm.in
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
data = open(file_path).read()
|
|
287
|
+
|
|
288
|
+
# Original sqm.in file headerlooks like:
|
|
289
|
+
|
|
290
|
+
# Run semi-empirical minimization
|
|
291
|
+
# &qmmm
|
|
292
|
+
# qm_theory='AM1', grms_tol=0.0005,
|
|
293
|
+
# scfconv=1.d-10, ndiis_attempts=700, qmcharge=0,
|
|
294
|
+
# /
|
|
295
|
+
# ... (atom coordinates in something like XYZ format) ...
|
|
296
|
+
|
|
297
|
+
# To get WBOs, we need to add "printbondorders=1" to the list of keywords
|
|
298
|
+
|
|
299
|
+
# First, split the sqm.in text at the "/" mark at the end of the header
|
|
300
|
+
datasp = data.split("/")
|
|
301
|
+
# Insert the "printbondorders" directive in a new line and re-add the "/"
|
|
302
|
+
datasp.insert(1, "printbondorders=1, \n /")
|
|
303
|
+
# Reassemble the file text
|
|
304
|
+
new_data = "".join(datasp)
|
|
305
|
+
# Write the new file contents, overwriting the original file.
|
|
306
|
+
with open(file_path, "w") as of:
|
|
307
|
+
of.write(new_data)
|
|
308
|
+
|
|
309
|
+
def _get_fractional_bond_orders_from_sqm_out(self, file_path, validate_elements=None):
|
|
310
|
+
"""
|
|
311
|
+
Process a SQM output file containing bond orders, and return a dict of the form
|
|
312
|
+
dict[atom_1_index, atom_2_index] = fractional_bond_order
|
|
313
|
+
|
|
314
|
+
Parameters
|
|
315
|
+
----------
|
|
316
|
+
file_path
|
|
317
|
+
File path for sqm output file
|
|
318
|
+
validate_elements
|
|
319
|
+
The element symbols expected in molecule index order. A ValueError will be raised
|
|
320
|
+
if the elements are not found in this order.
|
|
321
|
+
|
|
322
|
+
Returns
|
|
323
|
+
-------
|
|
324
|
+
bond_orders
|
|
325
|
+
A dictionary where the keys are tuples of two atom indices and the values are
|
|
326
|
+
floating-point bond orders. The keys are sorted in ascending order, such that
|
|
327
|
+
the lower atom index is key[0] and the higher is key[1].
|
|
328
|
+
"""
|
|
329
|
+
|
|
330
|
+
# Example sqm.out section with WBOs:
|
|
331
|
+
# Bond Orders
|
|
332
|
+
#
|
|
333
|
+
# QMMM: NUM1 ELEM1 NUM2 ELEM2 BOND_ORDER
|
|
334
|
+
# QMMM: 2 C 1 C 1.41107532
|
|
335
|
+
# QMMM: 3 C 1 C 1.41047804
|
|
336
|
+
# ...
|
|
337
|
+
# QMMM: 15 H 13 H 0.00000954
|
|
338
|
+
# QMMM: 15 H 14 H 0.00000813
|
|
339
|
+
#
|
|
340
|
+
# --------- Calculation Completed ----------
|
|
341
|
+
|
|
342
|
+
data = open(file_path).read()
|
|
343
|
+
|
|
344
|
+
begin_sep = """ Bond Orders
|
|
345
|
+
|
|
346
|
+
QMMM: NUM1 ELEM1 NUM2 ELEM2 BOND_ORDER
|
|
347
|
+
""" # noqa
|
|
348
|
+
end_sep = """
|
|
349
|
+
|
|
350
|
+
--------- Calculation Completed ----------
|
|
351
|
+
"""
|
|
352
|
+
# Extract the chunk of text between begin_sep and end_sep, and split it by newline
|
|
353
|
+
fbo_lines = data.split(begin_sep)[1].split(end_sep)[0].split("\n")
|
|
354
|
+
|
|
355
|
+
# Iterate over the lines and populate the dict to return
|
|
356
|
+
bond_orders = dict()
|
|
357
|
+
for line in fbo_lines:
|
|
358
|
+
linesp = line.split()
|
|
359
|
+
atom_index_1 = int(linesp[1])
|
|
360
|
+
atom_element_1 = linesp[2]
|
|
361
|
+
atom_index_2 = int(linesp[3])
|
|
362
|
+
atom_element_2 = linesp[4]
|
|
363
|
+
bond_order = float(linesp[5])
|
|
364
|
+
|
|
365
|
+
# If validate_elements was provided, ensure that the ordering of element symbols is what we expected
|
|
366
|
+
if validate_elements is not None:
|
|
367
|
+
if (atom_element_1 != validate_elements[atom_index_1 - 1]) or (
|
|
368
|
+
atom_element_2 != validate_elements[atom_index_2 - 1]
|
|
369
|
+
):
|
|
370
|
+
# raise ValueError('\n'.join(fbo_lines))
|
|
371
|
+
raise ValueError(
|
|
372
|
+
f"Elements or indexing in sqm output differ from expectation. "
|
|
373
|
+
f"Expected {validate_elements[atom_index_1]} with index {atom_index_1} and "
|
|
374
|
+
f"{validate_elements[atom_index_2]} with index {atom_index_2}, "
|
|
375
|
+
f"but SQM output has {atom_element_1} and {atom_element_2} for the same atoms."
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
# To make lookup easier, we identify bonds as integer tuples with the lowest atom index
|
|
379
|
+
# first and the highest second.
|
|
380
|
+
index_tuple = tuple(sorted([atom_index_1, atom_index_2]))
|
|
381
|
+
bond_orders[index_tuple] = bond_order
|
|
382
|
+
return bond_orders
|
|
383
|
+
|
|
384
|
+
def assign_fractional_bond_orders(
|
|
385
|
+
self,
|
|
386
|
+
molecule: "Molecule",
|
|
387
|
+
bond_order_model: str | None = None,
|
|
388
|
+
use_conformers: list[str] | None = None,
|
|
389
|
+
_cls=None,
|
|
390
|
+
):
|
|
391
|
+
"""
|
|
392
|
+
Update and store list of bond orders this molecule. Bond orders are stored on each
|
|
393
|
+
bond, in the `bond.fractional_bond_order` attribute.
|
|
394
|
+
|
|
395
|
+
.. warning :: This API is experimental and subject to change.
|
|
396
|
+
|
|
397
|
+
Parameters
|
|
398
|
+
----------
|
|
399
|
+
molecule
|
|
400
|
+
The molecule to assign wiberg bond orders to
|
|
401
|
+
bond_order_model
|
|
402
|
+
The charge model to use. Only allowed value is 'am1-wiberg'. If None, 'am1-wiberg' will be used.
|
|
403
|
+
use_conformers
|
|
404
|
+
The conformers to use for fractional bond order calculation. If None, an appropriate
|
|
405
|
+
number of conformers will be generated by an available ToolkitWrapper.
|
|
406
|
+
_cls
|
|
407
|
+
Molecule constructor
|
|
408
|
+
"""
|
|
409
|
+
from openff.toolkit.topology import Molecule
|
|
410
|
+
|
|
411
|
+
ANTECHAMBER_PATH = which("antechamber")
|
|
412
|
+
if ANTECHAMBER_PATH is None:
|
|
413
|
+
raise AntechamberNotFoundError(
|
|
414
|
+
"Antechamber not found, cannot run AmberToolsToolkitWrapper.assign_fractional_bond_orders()"
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
if _cls is None:
|
|
418
|
+
_cls = Molecule
|
|
419
|
+
|
|
420
|
+
# Make a copy since we'll be messing with this molecule's conformers
|
|
421
|
+
temp_mol = _cls(molecule)
|
|
422
|
+
|
|
423
|
+
if use_conformers is None:
|
|
424
|
+
temp_mol.generate_conformers(
|
|
425
|
+
n_conformers=1,
|
|
426
|
+
toolkit_registry=self._rdkit_toolkit_wrapper,
|
|
427
|
+
)
|
|
428
|
+
else:
|
|
429
|
+
temp_mol._conformers = None
|
|
430
|
+
for conformer in use_conformers:
|
|
431
|
+
temp_mol._add_conformer(conformer)
|
|
432
|
+
|
|
433
|
+
if len(temp_mol.conformers) == 0:
|
|
434
|
+
raise ValueError(
|
|
435
|
+
"No conformers present in molecule submitted for fractional bond order calculation. Consider "
|
|
436
|
+
"loading the molecule from a file with geometry already present or running "
|
|
437
|
+
"molecule.generate_conformers() before calling molecule.assign_fractional_bond_orders"
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
# Compute bond orders
|
|
441
|
+
bond_order_model_to_antechamber_keyword = {"am1-wiberg": "mul"}
|
|
442
|
+
supported_bond_order_models = list(bond_order_model_to_antechamber_keyword.keys())
|
|
443
|
+
if bond_order_model is None:
|
|
444
|
+
bond_order_model = "am1-wiberg"
|
|
445
|
+
|
|
446
|
+
bond_order_model = bond_order_model.lower()
|
|
447
|
+
|
|
448
|
+
if bond_order_model not in supported_bond_order_models:
|
|
449
|
+
raise ValueError(
|
|
450
|
+
f"Bond order model '{bond_order_model}' is not supported by AmberToolsToolkitWrapper. "
|
|
451
|
+
f"Supported models are {supported_bond_order_models}"
|
|
452
|
+
)
|
|
453
|
+
ac_charge_keyword = bond_order_model_to_antechamber_keyword[bond_order_model]
|
|
454
|
+
|
|
455
|
+
bond_orders = defaultdict(list)
|
|
456
|
+
|
|
457
|
+
for conformer in [*temp_mol.conformers]:
|
|
458
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
459
|
+
net_charge = temp_mol.total_charge
|
|
460
|
+
# Write out molecule in SDF format
|
|
461
|
+
temp_mol._conformers = [conformer]
|
|
462
|
+
self._rdkit_toolkit_wrapper.to_file(temp_mol, f"{tmpdir}/molecule.sdf", file_format="sdf")
|
|
463
|
+
# Prepare sqm.in file as if we were going to run charge calc
|
|
464
|
+
# TODO: Add error handling if antechamber chokes
|
|
465
|
+
subprocess.check_output(
|
|
466
|
+
[
|
|
467
|
+
"antechamber",
|
|
468
|
+
"-i",
|
|
469
|
+
"molecule.sdf",
|
|
470
|
+
"-fi",
|
|
471
|
+
"sdf",
|
|
472
|
+
"-o",
|
|
473
|
+
"sqm.in",
|
|
474
|
+
"-fo",
|
|
475
|
+
"sqmcrt",
|
|
476
|
+
"-pf",
|
|
477
|
+
"yes",
|
|
478
|
+
"-c",
|
|
479
|
+
ac_charge_keyword,
|
|
480
|
+
"-nc",
|
|
481
|
+
str(net_charge),
|
|
482
|
+
],
|
|
483
|
+
cwd=tmpdir,
|
|
484
|
+
)
|
|
485
|
+
# Modify sqm.in to request bond order calculation
|
|
486
|
+
self._modify_sqm_in_to_request_bond_orders(f"{tmpdir}/sqm.in")
|
|
487
|
+
# Run sqm to get bond orders
|
|
488
|
+
subprocess.check_output(["sqm", "-i", "sqm.in", "-o", "sqm.out", "-O"], cwd=tmpdir)
|
|
489
|
+
# Ensure that antechamber/sqm did not change the indexing by checking against
|
|
490
|
+
# an ordered list of element symbols for this molecule
|
|
491
|
+
expected_elements = [atom.symbol for atom in molecule.atoms]
|
|
492
|
+
conformer_bond_orders = self._get_fractional_bond_orders_from_sqm_out(
|
|
493
|
+
f"{tmpdir}/sqm.out", validate_elements=expected_elements
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
for bond_indices, value in conformer_bond_orders.items():
|
|
497
|
+
bond_orders[bond_indices].append(value)
|
|
498
|
+
|
|
499
|
+
# Note that sqm calculate WBOs for ALL PAIRS of atoms, not just those that have
|
|
500
|
+
# bonds defined in the original molecule. So here we iterate over the bonds in
|
|
501
|
+
# the original molecule and only nab the WBOs for those.
|
|
502
|
+
for bond in molecule.bonds:
|
|
503
|
+
# The atom index tuples that act as bond indices are ordered from lowest to highest by
|
|
504
|
+
# _get_fractional_bond_orders_from_sqm_out, so here we make sure that we look them up in
|
|
505
|
+
# sorted order as well
|
|
506
|
+
sorted_atom_indices = sorted(tuple([bond.atom1_index + 1, bond.atom2_index + 1]))
|
|
507
|
+
bond.fractional_bond_order = np.mean(bond_orders[tuple(sorted_atom_indices)])
|