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,955 @@
|
|
|
1
|
+
# flake8: noqa
|
|
2
|
+
"""
|
|
3
|
+
Tools for generating library of substructures from the Chemical Component
|
|
4
|
+
Dictionary (CCD).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import copy
|
|
8
|
+
import json
|
|
9
|
+
from collections import OrderedDict, defaultdict
|
|
10
|
+
from copy import deepcopy
|
|
11
|
+
|
|
12
|
+
import rdkit
|
|
13
|
+
from CifFile import ReadCif
|
|
14
|
+
from openff.units.elements import SYMBOLS
|
|
15
|
+
from rdkit import Chem
|
|
16
|
+
|
|
17
|
+
from openff.toolkit import Molecule
|
|
18
|
+
from openff.toolkit.utils.rdkit_wrapper import RDKitToolkitWrapper
|
|
19
|
+
|
|
20
|
+
_SYMBOL_TO_ATOMIC_NUMBER = {v: k for k, v in SYMBOLS.items()}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Amber ff porting functions
|
|
24
|
+
def remove_charge_and_bond_order_from_guanidinium(rdmol):
|
|
25
|
+
"""
|
|
26
|
+
To correct for chemical perception issues with possible resonance states of arginine,
|
|
27
|
+
remove all charge from the guanidinium group, and set all bond orders to 4. This will
|
|
28
|
+
mark the resonant bonds with a unique "$" character in the SMARTS, which we can later
|
|
29
|
+
replace.
|
|
30
|
+
"""
|
|
31
|
+
for atom in rdmol.GetAtoms():
|
|
32
|
+
# print(dir(atom))
|
|
33
|
+
if atom.GetAtomicNum() != 6: # element.symbol != "C":
|
|
34
|
+
continue
|
|
35
|
+
nitrogen_neighbors = 0
|
|
36
|
+
for neighbor in atom.GetNeighbors():
|
|
37
|
+
if neighbor.GetAtomicNum() == 7:
|
|
38
|
+
nitrogen_neighbors += 1
|
|
39
|
+
if nitrogen_neighbors != 3:
|
|
40
|
+
continue
|
|
41
|
+
atom.SetFormalCharge(0)
|
|
42
|
+
for neighbor in atom.GetNeighbors():
|
|
43
|
+
neighbor.SetFormalCharge(0)
|
|
44
|
+
for bond in atom.GetBonds():
|
|
45
|
+
# Set bond order 4, which will produce a "$" character. We later replace this with "~".
|
|
46
|
+
# print(dir(bond))
|
|
47
|
+
bond.SetBondType(rdkit.Chem.BondType.QUADRUPLE)
|
|
48
|
+
# bond.SetBondType(Chem.BondType.AROMATIC)
|
|
49
|
+
# bond.SetBondType(Chem.BondType.OTHER)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def remove_charge_and_bond_order_from_imidazole(rdmol):
|
|
53
|
+
"""
|
|
54
|
+
To correct for chemical perception issues with possible resonance states of histidine,
|
|
55
|
+
remove all charge from the imidazole group, and set all bond orders to 4. This will
|
|
56
|
+
mark the resonant bonds with a unique "$" character in the SMARTS, which we can later
|
|
57
|
+
replace.
|
|
58
|
+
"""
|
|
59
|
+
# matches = offmol.chemical_environment_matches('[C:1]1~[C:2]~[N:3]~[C:4]~[N:5]1')
|
|
60
|
+
imidazole_substructure = rdkit.Chem.MolFromSmarts("[C:1]1~[C:2]~[N:3]~[C:4]~[N:5]1")
|
|
61
|
+
matches = rdmol.GetSubstructMatches(imidazole_substructure)
|
|
62
|
+
all_imidazole_atoms = set()
|
|
63
|
+
for match in matches:
|
|
64
|
+
for idx in match:
|
|
65
|
+
all_imidazole_atoms.add(idx)
|
|
66
|
+
|
|
67
|
+
for atom in rdmol.GetAtoms():
|
|
68
|
+
if atom.GetIdx() in all_imidazole_atoms:
|
|
69
|
+
atom.SetFormalCharge(0)
|
|
70
|
+
|
|
71
|
+
for bond in rdmol.GetBonds():
|
|
72
|
+
# print(dir(bond))
|
|
73
|
+
if (bond.GetBeginAtomIdx() in all_imidazole_atoms) and (bond.GetEndAtomIdx() in all_imidazole_atoms):
|
|
74
|
+
bond.SetBondType(rdkit.Chem.BondType.QUADRUPLE)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class CifSubstructures:
|
|
78
|
+
"""
|
|
79
|
+
Substructure from CIF formatted files.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
# bond order dictionary translation from mmcif
|
|
83
|
+
bond_order_dict = {"SING": 1, "DOUB": 2, "TRIP": 3, "QUAD": 4}
|
|
84
|
+
|
|
85
|
+
def __init__(self):
|
|
86
|
+
"""
|
|
87
|
+
Create object with substructures data from CIF files.
|
|
88
|
+
"""
|
|
89
|
+
self.data = defaultdict(defaultdict) # Dictionary where to store substructures data
|
|
90
|
+
self._cif_multi_entry_object = None
|
|
91
|
+
|
|
92
|
+
def from_file(
|
|
93
|
+
self,
|
|
94
|
+
cif_file,
|
|
95
|
+
discard_keyword="FRAGMENT",
|
|
96
|
+
replace_quadruple_bond_with_any: bool = True,
|
|
97
|
+
remove_charge_bond_order_resonant: bool = True,
|
|
98
|
+
):
|
|
99
|
+
"""
|
|
100
|
+
Reads cif formatted file and fills substructure information.
|
|
101
|
+
|
|
102
|
+
Sequential runs combine information from different files.
|
|
103
|
+
|
|
104
|
+
Parameters
|
|
105
|
+
__________
|
|
106
|
+
cif_file : str or file-like object
|
|
107
|
+
File path string, URL or file-like object.
|
|
108
|
+
discard_keyword : str, optional, default='FRAGMENT'
|
|
109
|
+
Keyword in _chem_comp.name for filtering out entries. Default is 'FRAGMENT'.
|
|
110
|
+
remove_charge_bond_order_resonant: bool, optional, default=True
|
|
111
|
+
Removes bond order and charge information from guanidium and imidazole resonant groups.
|
|
112
|
+
replace_quadruple_bond_with_any: bool, optional, default=True:
|
|
113
|
+
Replace expected unique quadruple bond symbol ($) with any order symbol (~) in smarts patterns.
|
|
114
|
+
"""
|
|
115
|
+
# read cif file
|
|
116
|
+
self._cif_multi_entry_object = ReadCif(cif_file)
|
|
117
|
+
# fill data dictionary
|
|
118
|
+
self._fill_substructure_data(
|
|
119
|
+
discard_keyword=discard_keyword,
|
|
120
|
+
replace_quadruple_bond_with_any=replace_quadruple_bond_with_any,
|
|
121
|
+
remove_charge_bond_order_resonant=remove_charge_bond_order_resonant,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def to_json_file(self, output_file, indent=4):
|
|
125
|
+
"""
|
|
126
|
+
Return a JSON serialized representation.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
__________
|
|
130
|
+
output_file : str
|
|
131
|
+
Path string for output file.
|
|
132
|
+
indent : int, optional, default=4
|
|
133
|
+
If not None, will pretty-print with specified number of spaces for indentation.
|
|
134
|
+
|
|
135
|
+
Returns
|
|
136
|
+
_______
|
|
137
|
+
serialized : str
|
|
138
|
+
A JSON serialized representation of the object.
|
|
139
|
+
"""
|
|
140
|
+
with open(output_file, "w") as library_file:
|
|
141
|
+
json.dump(self.data, library_file, indent=indent)
|
|
142
|
+
|
|
143
|
+
def clear_data(self):
|
|
144
|
+
"""
|
|
145
|
+
Clears current data structures read from files.
|
|
146
|
+
|
|
147
|
+
Useful if you want to start reading cif files from scratch.
|
|
148
|
+
"""
|
|
149
|
+
self.data = defaultdict(defaultdict)
|
|
150
|
+
self._cif_multi_entry_object = None
|
|
151
|
+
|
|
152
|
+
@staticmethod
|
|
153
|
+
def _generate_atom_symbol_number_dictionary(cif_entry):
|
|
154
|
+
"""
|
|
155
|
+
Generate symbol to atomic number dictionary, given entry information from cif file.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
__________
|
|
159
|
+
cif_entry : CifFile.StarFile.StarBlock
|
|
160
|
+
Data block entry from cif file.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
_______
|
|
164
|
+
symbol_to_num_dict : dict
|
|
165
|
+
Atom symbol to atomic number (key, value) dictionary.
|
|
166
|
+
"""
|
|
167
|
+
# Is this de-duplicated? i.e. can it be ["C", "C", "H"] or only ["C", "H"] ?
|
|
168
|
+
atom_symbol_list: list[str] = cif_entry["_chem_comp_atom.type_symbol"]
|
|
169
|
+
|
|
170
|
+
# Is this dict a de-duplicated mapping between element symbols and atomic numbers
|
|
171
|
+
# for the elements in this cif file? If so, can maybe do it in one step
|
|
172
|
+
"""
|
|
173
|
+
symbol_to_num_dict: dict[str, int] = {
|
|
174
|
+
symbol: atomic_number for atomic_number, symbol in SYMBOLS.items() if atomic_number in
|
|
175
|
+
cif_entry["_chem_comp_atom.type_symbol"]
|
|
176
|
+
}
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
symbol_to_num_dict: dict[str, int] = {symbol: _SYMBOL_TO_ATOMIC_NUMBER[symbol] for symbol in atom_symbol_list}
|
|
180
|
+
|
|
181
|
+
return symbol_to_num_dict
|
|
182
|
+
|
|
183
|
+
@staticmethod
|
|
184
|
+
def _get_atom_by_name(molecule, name: str):
|
|
185
|
+
"""
|
|
186
|
+
Gets first occurrence of atom object from a molecule by its name.
|
|
187
|
+
|
|
188
|
+
Parameters
|
|
189
|
+
__________
|
|
190
|
+
molecule : Molecule
|
|
191
|
+
Molecule object where to look.
|
|
192
|
+
name : str
|
|
193
|
+
Atom name string to match against molecule atoms.
|
|
194
|
+
|
|
195
|
+
Returns
|
|
196
|
+
_______
|
|
197
|
+
atom_match : Atom or None
|
|
198
|
+
First occurrence of Atom with the given name, in molecule. None if not found.
|
|
199
|
+
"""
|
|
200
|
+
for atom in molecule.atoms:
|
|
201
|
+
if atom.name == name:
|
|
202
|
+
match = atom
|
|
203
|
+
break
|
|
204
|
+
else:
|
|
205
|
+
match = None
|
|
206
|
+
return match
|
|
207
|
+
|
|
208
|
+
def _gather_atoms_information(self, cif_entry_data):
|
|
209
|
+
"""
|
|
210
|
+
Gather minimum required atom information for creating toolkit Atoms.
|
|
211
|
+
|
|
212
|
+
Returns
|
|
213
|
+
_______
|
|
214
|
+
atom_information_array : tuple
|
|
215
|
+
Multidimensional tuple with atoms information.
|
|
216
|
+
"""
|
|
217
|
+
symbol_to_num_dict = self._generate_atom_symbol_number_dictionary(cif_entry_data)
|
|
218
|
+
atom_names = cif_entry_data["_chem_comp_atom.atom_id"]
|
|
219
|
+
atomic_numbers = [symbol_to_num_dict[x] for x in cif_entry_data["_chem_comp_atom.type_symbol"]]
|
|
220
|
+
formal_charges = [int(x) for x in cif_entry_data["_chem_comp_atom.charge"]]
|
|
221
|
+
is_aromatic = [False if x == "N" else True for x in cif_entry_data["_chem_comp_atom.pdbx_aromatic_flag"]]
|
|
222
|
+
stereochemistry = [None if x == "N" else x for x in cif_entry_data["_chem_comp_atom.pdbx_stereo_config"]]
|
|
223
|
+
leaving_atoms_list = cif_entry_data["_chem_comp_atom.pdbx_leaving_atom_flag"]
|
|
224
|
+
return (
|
|
225
|
+
atom_names,
|
|
226
|
+
atomic_numbers,
|
|
227
|
+
formal_charges,
|
|
228
|
+
is_aromatic,
|
|
229
|
+
stereochemistry,
|
|
230
|
+
leaving_atoms_list,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
def _gather_bonds_information(self, cif_entry_data):
|
|
234
|
+
"""
|
|
235
|
+
Gather minimum required bond information for creating toolkit Bonds.
|
|
236
|
+
|
|
237
|
+
Returns
|
|
238
|
+
_______
|
|
239
|
+
bond_information_array : tuple
|
|
240
|
+
Multidimensional tuple with bonds information.
|
|
241
|
+
"""
|
|
242
|
+
atom1_name_list = cif_entry_data["_chem_comp_bond.atom_id_1"]
|
|
243
|
+
atom2_name_list = cif_entry_data["_chem_comp_bond.atom_id_2"]
|
|
244
|
+
bond_order_list = [self.bond_order_dict[x] for x in cif_entry_data["_chem_comp_bond.value_order"]]
|
|
245
|
+
is_aromatic_bond_list = [
|
|
246
|
+
False if x == "N" else True for x in cif_entry_data["_chem_comp_bond.pdbx_aromatic_flag"]
|
|
247
|
+
]
|
|
248
|
+
stereochemistry_bond_list = [
|
|
249
|
+
None if x == "N" else x for x in cif_entry_data["_chem_comp_bond.pdbx_stereo_config"]
|
|
250
|
+
]
|
|
251
|
+
return (
|
|
252
|
+
atom1_name_list,
|
|
253
|
+
atom2_name_list,
|
|
254
|
+
bond_order_list,
|
|
255
|
+
is_aromatic_bond_list,
|
|
256
|
+
stereochemistry_bond_list,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
@staticmethod
|
|
260
|
+
def _get_subrdmol(
|
|
261
|
+
rdmol: rdkit.Chem.rdchem.Mol,
|
|
262
|
+
indices: list = [],
|
|
263
|
+
sanitize: bool = False,
|
|
264
|
+
remove_charge_bond_order_resonant: bool = True,
|
|
265
|
+
):
|
|
266
|
+
"""
|
|
267
|
+
Create new sub-molecule from selected atom indices
|
|
268
|
+
|
|
269
|
+
Parameters
|
|
270
|
+
----------
|
|
271
|
+
rdmol: rdkit.Chem.rdchem.Mol
|
|
272
|
+
Input molecule
|
|
273
|
+
indices: iterable of ints
|
|
274
|
+
atom indices to include from input molecule, indexed from 0
|
|
275
|
+
sanitize: bool
|
|
276
|
+
whether to sanitize the molecule (recommend: no)
|
|
277
|
+
|
|
278
|
+
Returns
|
|
279
|
+
-------
|
|
280
|
+
rdkit.Chem.rdchem.Mol: subset of molecule
|
|
281
|
+
"""
|
|
282
|
+
submol = rdkit.Chem.RWMol(rdmol)
|
|
283
|
+
ix = sorted([at.GetIdx() for at in rdmol.GetAtoms() if at.GetIdx() not in indices])
|
|
284
|
+
for i in ix[::-1]:
|
|
285
|
+
submol.RemoveAtom(int(i))
|
|
286
|
+
if sanitize:
|
|
287
|
+
rdkit.Chem.SanitizeMol(submol)
|
|
288
|
+
|
|
289
|
+
for atom in submol.GetAtoms():
|
|
290
|
+
# print(dir(atom))
|
|
291
|
+
atom.SetNoImplicit(True)
|
|
292
|
+
|
|
293
|
+
if remove_charge_bond_order_resonant:
|
|
294
|
+
remove_charge_and_bond_order_from_imidazole(submol)
|
|
295
|
+
remove_charge_and_bond_order_from_guanidinium(submol)
|
|
296
|
+
return submol
|
|
297
|
+
|
|
298
|
+
def _get_smiles(
|
|
299
|
+
self,
|
|
300
|
+
mol: Molecule,
|
|
301
|
+
indices: list = [],
|
|
302
|
+
label_indices: list = [],
|
|
303
|
+
replace_quadruple_bond_with_any: bool = True,
|
|
304
|
+
remove_charge_bond_order_resonant: bool = True,
|
|
305
|
+
):
|
|
306
|
+
"""
|
|
307
|
+
Get SMARTS of selected atoms in molecule
|
|
308
|
+
|
|
309
|
+
Parameters
|
|
310
|
+
----------
|
|
311
|
+
mol: openff.toolkit.Molecule
|
|
312
|
+
Input molecule
|
|
313
|
+
indices: iterable of ints
|
|
314
|
+
atom indices to include in SMARTS, indexed from 0
|
|
315
|
+
label_indices: iterable of ints
|
|
316
|
+
atom indices to label, indexed from 0. The atoms
|
|
317
|
+
will be labelled in the order specified. Labels
|
|
318
|
+
begin from 1.
|
|
319
|
+
|
|
320
|
+
Returns
|
|
321
|
+
-------
|
|
322
|
+
str: SMARTS string
|
|
323
|
+
"""
|
|
324
|
+
rdmol = mol.to_rdkit()
|
|
325
|
+
for i, lix in enumerate(label_indices, 1):
|
|
326
|
+
at = rdmol.GetAtomWithIdx(int(lix))
|
|
327
|
+
at.SetAtomMapNum(i)
|
|
328
|
+
indices = sorted(set(indices) | set(label_indices))
|
|
329
|
+
submol = self._get_subrdmol(
|
|
330
|
+
rdmol,
|
|
331
|
+
indices,
|
|
332
|
+
remove_charge_bond_order_resonant=remove_charge_bond_order_resonant,
|
|
333
|
+
)
|
|
334
|
+
smiles = rdkit.Chem.MolToSmiles(submol, allHsExplicit=True)
|
|
335
|
+
# TODO: This doesn't seem to be having an effect. It is replacing bond orders regardless.
|
|
336
|
+
if replace_quadruple_bond_with_any:
|
|
337
|
+
smiles = smiles.replace("$", "~")
|
|
338
|
+
return smiles
|
|
339
|
+
|
|
340
|
+
def _add_substructure_data_entry(
|
|
341
|
+
self,
|
|
342
|
+
atoms_information,
|
|
343
|
+
bonds_information,
|
|
344
|
+
entry_code,
|
|
345
|
+
replace_quadruple_bond_with_any: bool = True,
|
|
346
|
+
remove_charge_bond_order_resonant: bool = True,
|
|
347
|
+
):
|
|
348
|
+
"""
|
|
349
|
+
Read substructure from entry data in cif file and fill data object with smiles.
|
|
350
|
+
|
|
351
|
+
Parameters
|
|
352
|
+
__________
|
|
353
|
+
atoms_information : list[tuple[str,int]]
|
|
354
|
+
Iterable of tuple of atom info.
|
|
355
|
+
Currently [atom_name, element, formal_charge, is_aromatic, stereo, is_leaving]
|
|
356
|
+
bonds_information : list[tuple[str,int]]
|
|
357
|
+
Iterable of tuple of bond info.
|
|
358
|
+
Currently [atom1_name, atom2_name, bond_order, is_aromatic, stereo]
|
|
359
|
+
"""
|
|
360
|
+
offmol = Molecule()
|
|
361
|
+
|
|
362
|
+
atom_name_to_idx = dict()
|
|
363
|
+
# add atoms
|
|
364
|
+
for (
|
|
365
|
+
atom_name,
|
|
366
|
+
atomic_number,
|
|
367
|
+
formal_charge,
|
|
368
|
+
is_aromatic,
|
|
369
|
+
stereochemistry,
|
|
370
|
+
is_leaving,
|
|
371
|
+
) in atoms_information:
|
|
372
|
+
# if include_leaving:
|
|
373
|
+
# Add all atoms
|
|
374
|
+
atom_idx = offmol.add_atom(
|
|
375
|
+
atomic_number,
|
|
376
|
+
formal_charge,
|
|
377
|
+
is_aromatic,
|
|
378
|
+
stereochemistry=stereochemistry,
|
|
379
|
+
name=atom_name,
|
|
380
|
+
)
|
|
381
|
+
atom_name_to_idx[atom_name] = atom_idx
|
|
382
|
+
for (
|
|
383
|
+
atom1_name,
|
|
384
|
+
atom2_name,
|
|
385
|
+
bond_order,
|
|
386
|
+
is_aromatic,
|
|
387
|
+
stereochemistry,
|
|
388
|
+
) in bonds_information:
|
|
389
|
+
# try:
|
|
390
|
+
atom1_idx = atom_name_to_idx[atom1_name]
|
|
391
|
+
atom2_idx = atom_name_to_idx[atom2_name]
|
|
392
|
+
offmol.add_bond(
|
|
393
|
+
atom1_idx,
|
|
394
|
+
atom2_idx,
|
|
395
|
+
bond_order,
|
|
396
|
+
is_aromatic=is_aromatic,
|
|
397
|
+
stereochemistry=stereochemistry,
|
|
398
|
+
)
|
|
399
|
+
# # TODO: Broad exception. We should raise a specific error.
|
|
400
|
+
# except Exception: # happens when atom is not found, i.e. no leaving atoms.
|
|
401
|
+
# continue
|
|
402
|
+
# Get smiles
|
|
403
|
+
atom_indices = list(range(offmol.n_atoms))
|
|
404
|
+
smiles = self._get_smiles(
|
|
405
|
+
offmol,
|
|
406
|
+
indices=atom_indices,
|
|
407
|
+
label_indices=atom_indices,
|
|
408
|
+
replace_quadruple_bond_with_any=replace_quadruple_bond_with_any,
|
|
409
|
+
remove_charge_bond_order_resonant=remove_charge_bond_order_resonant,
|
|
410
|
+
)
|
|
411
|
+
if smiles not in self.data[entry_code]:
|
|
412
|
+
atom_names = [atom_info[0] for atom_info in atoms_information]
|
|
413
|
+
self.data[entry_code][smiles] = atom_names
|
|
414
|
+
|
|
415
|
+
def _fill_substructure_data(
|
|
416
|
+
self,
|
|
417
|
+
discard_keyword="FRAGMENT",
|
|
418
|
+
replace_quadruple_bond_with_any: bool = True,
|
|
419
|
+
remove_charge_bond_order_resonant: bool = True,
|
|
420
|
+
):
|
|
421
|
+
"""
|
|
422
|
+
Fills data dictionary with the substructure information.
|
|
423
|
+
|
|
424
|
+
Parameters
|
|
425
|
+
__________
|
|
426
|
+
discard_keyword : str, optional, default='FRAGMENT'
|
|
427
|
+
Keyword in _chem_comp.name for filtering out entries. Default is 'FRAGMENT'.
|
|
428
|
+
"""
|
|
429
|
+
# override_dict contains atoms that we DO want to treat as leaving, even
|
|
430
|
+
# though the actual entries don't have them flagged as leaving. The "H2" entries
|
|
431
|
+
# in this list are hydrogens attached to the backbone N, which are (for some reason)
|
|
432
|
+
# recorded as NH2, with neither H marked as "leaving", which causes the
|
|
433
|
+
# substructures to be unable to match main-chain appearances of the amino acids.
|
|
434
|
+
override_dict = {
|
|
435
|
+
# LYN
|
|
436
|
+
"lys_lfoh_dhz3": ["H2"],
|
|
437
|
+
# GLU
|
|
438
|
+
"glu_lfoh_dhe2": ["H2"],
|
|
439
|
+
# HIE
|
|
440
|
+
"his_lfoh_dhd1": ["H2"],
|
|
441
|
+
# ASP
|
|
442
|
+
"asp_lfoh_dhd2": ["H2"],
|
|
443
|
+
# HID
|
|
444
|
+
"his_lfoh_dhe2": ["H2"],
|
|
445
|
+
# CYX
|
|
446
|
+
"cys": ["HG"],
|
|
447
|
+
# CYM
|
|
448
|
+
"cys_lfoh_dhg": ["H1", "H2"],
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
for entry, entry_data in self._cif_multi_entry_object.items():
|
|
452
|
+
# Skip entries matching discard filtering keyword in comp name
|
|
453
|
+
comp_name = entry_data["_chem_comp.name"]
|
|
454
|
+
if discard_keyword in comp_name:
|
|
455
|
+
continue
|
|
456
|
+
# Gather necessary data for creating/adding atoms
|
|
457
|
+
atoms_information = [*zip(*self._gather_atoms_information(entry_data))]
|
|
458
|
+
# Gather information for bonds
|
|
459
|
+
bonds_information = [*zip(*self._gather_bonds_information(entry_data))]
|
|
460
|
+
|
|
461
|
+
for override_list in override_dict.get(entry, []):
|
|
462
|
+
for idx, atom in enumerate(atoms_information):
|
|
463
|
+
if atom[0] in override_list:
|
|
464
|
+
new_atom_tuple = (
|
|
465
|
+
atom[0],
|
|
466
|
+
atom[1],
|
|
467
|
+
atom[2],
|
|
468
|
+
atom[3],
|
|
469
|
+
atom[4],
|
|
470
|
+
"Y",
|
|
471
|
+
)
|
|
472
|
+
atoms_information[idx] = new_atom_tuple
|
|
473
|
+
# Only take three letter code for key -- Note it uses the new atom_names list
|
|
474
|
+
entry_code = entry_data["_chem_comp.three_letter_code"]
|
|
475
|
+
# Generate structures with permutations of leaving atoms. For example, if a COH
|
|
476
|
+
# motif has -OH group marked as leaving, this will add
|
|
477
|
+
# 1) the O- intermediate where only the H has left, as well as
|
|
478
|
+
# 2) the structure with the entire OH removed.
|
|
479
|
+
# Only atoms marked as "leaving" may have their formal charge changed by
|
|
480
|
+
# this function, so the remaining C when the OH is removed still has a
|
|
481
|
+
# neutral charge.
|
|
482
|
+
info_tuples = self._recursive_prepare_atom_bond_info(
|
|
483
|
+
atoms_information, bonds_information, return_list=list()
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
# Also add a structure with ALL leaving atoms removed
|
|
487
|
+
atoms_info_copy = copy.deepcopy(atoms_information)
|
|
488
|
+
bonds_info_copy = copy.deepcopy(bonds_information)
|
|
489
|
+
atom_idxs_to_remove = [idx for idx, at in enumerate(atoms_info_copy) if at[5] == "Y"]
|
|
490
|
+
atom_names_to_remove = [atoms_info_copy[idx][0] for idx in atom_idxs_to_remove]
|
|
491
|
+
bond_idxs_to_remove = list()
|
|
492
|
+
for bond_idx, bond in enumerate(bonds_info_copy):
|
|
493
|
+
if (bond[0] in atom_names_to_remove) or (bond[1] in atom_names_to_remove):
|
|
494
|
+
bond_idxs_to_remove.append(bond_idx)
|
|
495
|
+
|
|
496
|
+
for atom_idx_to_remove in atom_idxs_to_remove[::-1]:
|
|
497
|
+
atoms_info_copy.pop(atom_idx_to_remove)
|
|
498
|
+
for bond_idx_to_remove in bond_idxs_to_remove[::-1]:
|
|
499
|
+
bonds_info_copy.pop(bond_idx_to_remove)
|
|
500
|
+
info_tuples.append((atoms_info_copy, bonds_info_copy))
|
|
501
|
+
|
|
502
|
+
# Generate substructure entries for all prepared substructures
|
|
503
|
+
for atoms_information, bonds_information in info_tuples:
|
|
504
|
+
self._add_substructure_data_entry(
|
|
505
|
+
atoms_information,
|
|
506
|
+
bonds_information,
|
|
507
|
+
entry_code,
|
|
508
|
+
replace_quadruple_bond_with_any=replace_quadruple_bond_with_any,
|
|
509
|
+
remove_charge_bond_order_resonant=remove_charge_bond_order_resonant,
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
def _recursive_prepare_atom_bond_info(self, atoms_info, bonds_info, return_list=list()):
|
|
513
|
+
"""
|
|
514
|
+
This method makes permutations of the substructure with leaving atoms left and removed.
|
|
515
|
+
If some leaving atoms are bound to other leaving atoms, this method produces all permutations
|
|
516
|
+
of the leaving atom chains that are possible without creating a disconnected molecular graph.
|
|
517
|
+
|
|
518
|
+
If multiple leaving atoms form a chain, then this method attempts to keep the graph chemically
|
|
519
|
+
valid by subtracting one from the formal charge of each leaving atom when its neighbor is removed.
|
|
520
|
+
However non-leaving atoms will never have their formal charge changed.
|
|
521
|
+
|
|
522
|
+
Parameters
|
|
523
|
+
----------
|
|
524
|
+
atoms_info : list[tuple[str,int]]
|
|
525
|
+
Iterable of tuple of atom info.
|
|
526
|
+
Currently [atom_name, element, formal_charge, is_aromatic, stereo, is_leaving]
|
|
527
|
+
bonds_info : list[tuple[str,int]]
|
|
528
|
+
Iterable of tuple of bond info.
|
|
529
|
+
Currently [atom1_name, atom2_name, bond_order, is_aromatic, stereo]
|
|
530
|
+
"""
|
|
531
|
+
return_list.append((atoms_info, bonds_info))
|
|
532
|
+
for leaving_atom_idx, leaving_atom_info_tuple in enumerate(atoms_info):
|
|
533
|
+
# If the atom isn't leaving then we don't need to do anything
|
|
534
|
+
if leaving_atom_info_tuple[5] == "N":
|
|
535
|
+
continue
|
|
536
|
+
# If the atom IS leaving, then find any bonds it's involved in
|
|
537
|
+
leaving_atom_name = leaving_atom_info_tuple[0]
|
|
538
|
+
involved_bond_indices = list()
|
|
539
|
+
for bond_idx, bond_info_tuple in enumerate(bonds_info):
|
|
540
|
+
if leaving_atom_name in bond_info_tuple[:2]:
|
|
541
|
+
involved_bond_indices.append(bond_idx)
|
|
542
|
+
# If this leaving atom is involved in more than one bond, then
|
|
543
|
+
# don't remove it, since doing so would disconnect the molecule
|
|
544
|
+
if len(involved_bond_indices) != 1:
|
|
545
|
+
continue
|
|
546
|
+
atoms_info_copy = copy.deepcopy(atoms_info)
|
|
547
|
+
bonds_info_copy = copy.deepcopy(bonds_info)
|
|
548
|
+
|
|
549
|
+
# Determine whether the neighbor of the leaving atom is also leaving
|
|
550
|
+
bond_info_tuple = bonds_info[involved_bond_indices[0]]
|
|
551
|
+
neighbor_atom_name = [name for name in bond_info_tuple[:2] if name != leaving_atom_name][0]
|
|
552
|
+
for neighbor_atom_idx, neighbor_atom_info_tuple in enumerate(atoms_info):
|
|
553
|
+
if neighbor_atom_info_tuple[0] != neighbor_atom_name:
|
|
554
|
+
continue
|
|
555
|
+
neighbor_atom_is_also_leaving = neighbor_atom_info_tuple[5] == "Y"
|
|
556
|
+
# If the neighbor atom is ALSO leaving, then deduct 1 from its formal charge
|
|
557
|
+
if neighbor_atom_is_also_leaving:
|
|
558
|
+
new_atom_tuple = (
|
|
559
|
+
neighbor_atom_info_tuple[0],
|
|
560
|
+
neighbor_atom_info_tuple[1],
|
|
561
|
+
neighbor_atom_info_tuple[2] - 1,
|
|
562
|
+
neighbor_atom_info_tuple[3],
|
|
563
|
+
neighbor_atom_info_tuple[4],
|
|
564
|
+
neighbor_atom_info_tuple[5],
|
|
565
|
+
)
|
|
566
|
+
atoms_info_copy[neighbor_atom_idx] = new_atom_tuple
|
|
567
|
+
atoms_info_copy.pop(leaving_atom_idx)
|
|
568
|
+
bonds_info_copy.pop(involved_bond_indices[0])
|
|
569
|
+
return_list = self._recursive_prepare_atom_bond_info(
|
|
570
|
+
atoms_info_copy, bonds_info_copy, return_list=return_list
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
return return_list
|
|
574
|
+
|
|
575
|
+
def _patch_known_problems(self):
|
|
576
|
+
"""
|
|
577
|
+
Monkey-patching known problems with current aa-variants-v1.cif from CCD.
|
|
578
|
+
|
|
579
|
+
.. warning: Needed as of Oct-21-2021
|
|
580
|
+
"""
|
|
581
|
+
|
|
582
|
+
substructures_to_fix = {
|
|
583
|
+
"PRO": [
|
|
584
|
+
(
|
|
585
|
+
"[N-:1]1[C@@:2]([C-:3]=[O:4])([H:8])[C:5]([H:9])([H:10])[C:6]([H:11])([H:12])[C:7]1([H:13])[H:14]",
|
|
586
|
+
"[N:1]1[C@@:2]([C:3]=[O:4])([H:8])[C:5]([H:9])([H:10])[C:6]([H:11])([H:12])[C:7]1([H:13])[H:14]",
|
|
587
|
+
),
|
|
588
|
+
],
|
|
589
|
+
"HIS": [
|
|
590
|
+
(
|
|
591
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O:11][H:18])([C:5]([C:6]1=[C:8]([H:16])[N-:10][C:9]([H:17])=[N+:7]1[H:15])([H:13])[H:14])[H:12])([H:19])[H:20]",
|
|
592
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O:11][H:18])([C:5]([C:6]1=[C:8]([H:16])[N:10]=[C:9]([H:17])[N:7]1[H:15])([H:13])[H:14])[H:12])([H:19])[H:20]",
|
|
593
|
+
),
|
|
594
|
+
(
|
|
595
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O-:11])([C:5]([C:6]1=[C:8]([H:16])[N-:10][C:9]([H:17])=[N+:7]1[H:15])([H:13])[H:14])[H:12])([H:18])[H:19]",
|
|
596
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O-:11])([C:5]([C:6]1=[C:8]([H:16])[N:10]=[C:9]([H:17])[N:7]1[H:15])([H:13])[H:14])[H:12])([H:18])[H:19]",
|
|
597
|
+
),
|
|
598
|
+
(
|
|
599
|
+
"[N:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:8]([H:15])[N-:10][C:9]([H:16])=[N+:7]1[H:14])([H:12])[H:13])[H:11])([H:17])[H:18]",
|
|
600
|
+
"[N:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:8]([H:15])[N:10]=[C:9]([H:16])[N:7]1[H:14])([H:12])[H:13])[H:11])([H:17])[H:18]",
|
|
601
|
+
),
|
|
602
|
+
(
|
|
603
|
+
"[N:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:8]([H:15])[N-:10][C:9]([H:16])=[N+:7]1[H:14])([H:12])[H:13])[H:11])[H:17]",
|
|
604
|
+
"[N:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:8]([H:15])[N:10]=[C:9]([H:16])[N:7]1[H:14])([H:12])[H:13])[H:11])[H:17]",
|
|
605
|
+
),
|
|
606
|
+
(
|
|
607
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O-:11])([C:5]([C:6]1=[C:8]([H:16])[N-:10][C:9]([H:17])=[N+:7]1[H:15])([H:13])[H:14])[H:12])[H:18]",
|
|
608
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O-:11])([C:5]([C:6]1=[C:8]([H:16])[N:10]=[C:9]([H:17])[N:7]1[H:15])([H:13])[H:14])[H:12])[H:18]",
|
|
609
|
+
),
|
|
610
|
+
(
|
|
611
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O:11][H:18])([C:5]([C:6]1=[C:8]([H:16])[N-:10][C:9]([H:17])=[N+:7]1[H:15])([H:13])[H:14])[H:12])[H:19]",
|
|
612
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O:11][H:18])([C:5]([C:6]1=[C:8]([H:16])[N:10]=[C:9]([H:17])[N:7]1[H:15])([H:13])[H:14])[H:12])[H:19]",
|
|
613
|
+
),
|
|
614
|
+
(
|
|
615
|
+
"[N+:1]([C@:2]([C:3](=[O:4])[O-:11])([C:5]([C:6]1=[C:8]([H:16])[N-:10][C:9]([H:17])=[N+:7]1[H:15])([H:13])[H:14])[H:12])([H:18])([H:19])[H:20]",
|
|
616
|
+
"[N+:1]([C@:2]([C:3](=[O:4])[O-:11])([C:5]([C:6]1=[C:8]([H:16])[N:10]=[C:9]([H:17])[N:7]1[H:15])([H:13])[H:14])[H:12])([H:18])([H:19])[H:20]",
|
|
617
|
+
),
|
|
618
|
+
(
|
|
619
|
+
"[N+:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:8]([H:15])[N-:10][C:9]([H:16])=[N+:7]1[H:14])([H:12])[H:13])[H:11])([H:17])([H:18])[H:19]",
|
|
620
|
+
"[N+:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:8]([H:15])[N:10]=[C:9]([H:16])[N:7]1[H:14])([H:12])[H:13])[H:11])([H:17])([H:18])[H:19]",
|
|
621
|
+
),
|
|
622
|
+
],
|
|
623
|
+
"TRP": [
|
|
624
|
+
(
|
|
625
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O:15][H:24])([C:5]([C:6]1=[C:7]([H:19])[N-:9][c:10]2[c:8]1[c:11]([H:20])[c:13]([H:22])[c:14]([H:23])[c:12]2[H:21])([H:17])[H:18])[H:16])([H:25])[H:26]",
|
|
626
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O:15][H:24])([C:5]([C:6]1=[C:7]([H:19])[N:9][c:10]2[c:8]1[c:11]([H:20])[c:13]([H:22])[c:14]([H:23])[c:12]2[H:21])([H:17])[H:18])[H:16])([H:25])[H:26]",
|
|
627
|
+
),
|
|
628
|
+
(
|
|
629
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O-:15])([C:5]([C:6]1=[C:7]([H:19])[N-:9][c:10]2[c:8]1[c:11]([H:20])[c:13]([H:22])[c:14]([H:23])[c:12]2[H:21])([H:17])[H:18])[H:16])([H:24])[H:25]",
|
|
630
|
+
"[N:1]([C@:2]([C:3](=[O:4])[O-:15])([C:5]([C:6]1=[C:7]([H:19])[N:9][c:10]2[c:8]1[c:11]([H:20])[c:13]([H:22])[c:14]([H:23])[c:12]2[H:21])([H:17])[H:18])[H:16])([H:24])[H:25]",
|
|
631
|
+
),
|
|
632
|
+
(
|
|
633
|
+
"[N:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:7]([H:18])[N-:9][c:10]2[c:8]1[c:11]([H:19])[c:13]([H:21])[c:14]([H:22])[c:12]2[H:20])([H:16])[H:17])[H:15])([H:23])[H:24]",
|
|
634
|
+
"[N:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:7]([H:18])[N:9][c:10]2[c:8]1[c:11]([H:19])[c:13]([H:21])[c:14]([H:22])[c:12]2[H:20])([H:16])[H:17])[H:15])([H:23])[H:24]",
|
|
635
|
+
),
|
|
636
|
+
(
|
|
637
|
+
"[N+:1]([C@:2]([C:3](=[O:4])[O-:15])([C:5]([C:6]1=[C:7]([H:19])[N-:9][c:10]2[c:8]1[c:11]([H:20])[c:13]([H:22])[c:14]([H:23])[c:12]2[H:21])([H:17])[H:18])[H:16])([H:24])([H:25])[H:26]",
|
|
638
|
+
"[N+:1]([C@:2]([C:3](=[O:4])[O-:15])([C:5]([C:6]1=[C:7]([H:19])[N:9][c:10]2[c:8]1[c:11]([H:20])[c:13]([H:22])[c:14]([H:23])[c:12]2[H:21])([H:17])[H:18])[H:16])([H:24])([H:25])[H:26]",
|
|
639
|
+
),
|
|
640
|
+
(
|
|
641
|
+
"[N+:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:7]([H:18])[N-:9][c:10]2[c:8]1[c:11]([H:19])[c:13]([H:21])[c:14]([H:22])[c:12]2[H:20])([H:16])[H:17])[H:15])([H:23])([H:24])[H:25]",
|
|
642
|
+
"[N+:1]([C@:2]([C:3]=[O:4])([C:5]([C:6]1=[C:7]([H:18])[N:9][c:10]2[c:8]1[c:11]([H:19])[c:13]([H:21])[c:14]([H:22])[c:12]2[H:20])([H:16])[H:17])[H:15])([H:23])([H:24])[H:25]",
|
|
643
|
+
),
|
|
644
|
+
],
|
|
645
|
+
}
|
|
646
|
+
# Fix PRO smarts substructure
|
|
647
|
+
for aa_name, replacement_list in substructures_to_fix.items():
|
|
648
|
+
for old_smarts, new_smarts in replacement_list:
|
|
649
|
+
self.data[aa_name][new_smarts] = self.data[aa_name][old_smarts]
|
|
650
|
+
self.data[aa_name].pop(old_smarts)
|
|
651
|
+
|
|
652
|
+
def _add_common_substructures(self):
|
|
653
|
+
"""
|
|
654
|
+
.. warning: Needed as of Oct-21-2021
|
|
655
|
+
"""
|
|
656
|
+
|
|
657
|
+
# Add common caps
|
|
658
|
+
self.data["ACE"] = {"[C:1](=[O:2])[C:3]([H:4])([H:5])[H:6]": ["C", "O", "CH3", "H1", "H2", "H3"]}
|
|
659
|
+
self.data["NME"] = {"[N:1]([C:2]([H:4])([H:5])[H:6])[H:3]": ["N", "C", "H", "H1", "H2", "H3"]}
|
|
660
|
+
self.data["NH2"] = {"[N:1]([H:2])[H:3]": ["N", "HN1", "HN2"]}
|
|
661
|
+
|
|
662
|
+
def _add_common_linkages(self):
|
|
663
|
+
"""
|
|
664
|
+
.. warning: Needed as of Oct-21-2021
|
|
665
|
+
"""
|
|
666
|
+
|
|
667
|
+
self.data["PEPTIDE_BOND"] = {
|
|
668
|
+
"[C:1](=[O:2])[N:3]": [
|
|
669
|
+
"C",
|
|
670
|
+
"O",
|
|
671
|
+
"N",
|
|
672
|
+
]
|
|
673
|
+
}
|
|
674
|
+
self.data["DISULFIDE"] = {
|
|
675
|
+
"[S:1][S:2]": [
|
|
676
|
+
"SG",
|
|
677
|
+
"SG",
|
|
678
|
+
]
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
def _reformat_substructs(self):
|
|
682
|
+
"""
|
|
683
|
+
Implemented 7/7/23: add-on to existing substructure library to reformat amino acids
|
|
684
|
+
to a new format. Self contained for now to the following function:
|
|
685
|
+
"""
|
|
686
|
+
|
|
687
|
+
def add_atom(
|
|
688
|
+
rdmol,
|
|
689
|
+
begin_atom_idx,
|
|
690
|
+
new_atom_smarts,
|
|
691
|
+
bond_order=Chem.rdchem.BondType.SINGLE,
|
|
692
|
+
):
|
|
693
|
+
# adds atom with single bond, returns new mol
|
|
694
|
+
emol = Chem.RWMol(deepcopy(rdmol))
|
|
695
|
+
new_atom = Chem.AtomFromSmarts(new_atom_smarts)
|
|
696
|
+
idx = emol.AddAtom(new_atom)
|
|
697
|
+
assert idx == rdmol.GetNumAtoms()
|
|
698
|
+
emol.AddBond(begin_atom_idx, idx, order=bond_order)
|
|
699
|
+
return emol.GetMol()
|
|
700
|
+
|
|
701
|
+
def _get_maximum_map_num(rdmol):
|
|
702
|
+
return max([atom.GetAtomMapNum() for atom in rdmol.GetAtoms()])
|
|
703
|
+
|
|
704
|
+
def _fill_out_query(rdmol):
|
|
705
|
+
params = Chem.SmilesParserParams()
|
|
706
|
+
params.removeHs = False
|
|
707
|
+
params.sanitize = True
|
|
708
|
+
rdmol = Chem.MolFromSmiles(
|
|
709
|
+
Chem.MolToSmiles(
|
|
710
|
+
deepcopy(rdmol),
|
|
711
|
+
isomericSmiles=False,
|
|
712
|
+
kekuleSmiles=True,
|
|
713
|
+
canonical=False,
|
|
714
|
+
),
|
|
715
|
+
params,
|
|
716
|
+
) # create non-query version of substruct
|
|
717
|
+
Chem.Kekulize(rdmol, clearAromaticFlags=True) # kekulize using molops (regular molecule required here)
|
|
718
|
+
rdmol = Chem.MolFromSmarts(
|
|
719
|
+
Chem.MolToSmiles(
|
|
720
|
+
deepcopy(rdmol),
|
|
721
|
+
isomericSmiles=False,
|
|
722
|
+
kekuleSmiles=True,
|
|
723
|
+
canonical=False,
|
|
724
|
+
)
|
|
725
|
+
) # remake into query mol
|
|
726
|
+
current_map_num = 1 + _get_maximum_map_num(rdmol) # do not change existing atom map numbers!
|
|
727
|
+
for atom in rdmol.GetAtoms():
|
|
728
|
+
if atom.GetAtomicNum() > 0:
|
|
729
|
+
if atom.GetAtomMapNum() == 0:
|
|
730
|
+
atom.SetAtomMapNum(current_map_num)
|
|
731
|
+
current_map_num += 1
|
|
732
|
+
atom.SetChiralTag(Chem.rdchem.ChiralType.CHI_UNSPECIFIED)
|
|
733
|
+
a_num = atom.GetAtomicNum()
|
|
734
|
+
D_num = len([0 for _ in atom.GetBonds()])
|
|
735
|
+
F_num = atom.GetFormalCharge()
|
|
736
|
+
query_string = f"[#{a_num}D{D_num}{F_num:+}:{current_map_num}]"
|
|
737
|
+
query = Chem.AtomFromSmarts(query_string)
|
|
738
|
+
atom.SetQuery(query)
|
|
739
|
+
elif atom.GetAtomicNum() == 0:
|
|
740
|
+
atom.SetAtomMapNum(current_map_num)
|
|
741
|
+
current_map_num += 1
|
|
742
|
+
query_string = f"[*:{current_map_num}]"
|
|
743
|
+
query = Chem.AtomFromSmarts(query_string)
|
|
744
|
+
atom.SetQuery(query)
|
|
745
|
+
else:
|
|
746
|
+
raise Exception
|
|
747
|
+
for bond in rdmol.GetBonds():
|
|
748
|
+
if bond.GetBondType() == Chem.rdchem.BondType.AROMATIC:
|
|
749
|
+
raise Exception # there should be no aromatic bonds unless kekulization has failed
|
|
750
|
+
elif bond.GetBondType() == Chem.rdchem.BondType.SINGLE:
|
|
751
|
+
query = Chem.BondFromSmarts("-")
|
|
752
|
+
bond.SetQuery(query)
|
|
753
|
+
|
|
754
|
+
return rdmol
|
|
755
|
+
|
|
756
|
+
def get_atom_with_map_num(rdmol, map_num):
|
|
757
|
+
for atom in rdmol.GetAtoms():
|
|
758
|
+
if atom.GetAtomMapNum() == map_num:
|
|
759
|
+
return atom
|
|
760
|
+
return None
|
|
761
|
+
|
|
762
|
+
def clear_query(rdmol):
|
|
763
|
+
for atom in rdmol.GetAtoms():
|
|
764
|
+
atom.SetAtomMapNum(0)
|
|
765
|
+
n = atom.GetAtomicNum()
|
|
766
|
+
c = atom.GetFormalCharge()
|
|
767
|
+
query_string = f"[#{n}{c:+}]"
|
|
768
|
+
query = Chem.AtomFromSmarts(query_string)
|
|
769
|
+
atom.SetQuery(query)
|
|
770
|
+
|
|
771
|
+
new_subs_dict = OrderedDict()
|
|
772
|
+
# = [(Smarts without terminal groups , [ids to add port to], [ids to add H to], [id of amide bond carbon])]
|
|
773
|
+
amino_acid_subs = [
|
|
774
|
+
(
|
|
775
|
+
Chem.MolFromSmarts(
|
|
776
|
+
"[N+:1](-[H])(-[H])1[C@@:2]([C:3](=[O:4]))([H:9])[C:5]([H:10])([H:11])[C:6]([H:12])([H:13])[C:7]1([H:14])[H:15]"
|
|
777
|
+
),
|
|
778
|
+
[],
|
|
779
|
+
[],
|
|
780
|
+
4,
|
|
781
|
+
),
|
|
782
|
+
(
|
|
783
|
+
Chem.MolFromSmarts(
|
|
784
|
+
"[N+0:1](-[H])1[C@@:2]([C:3](=[O:4]))([H:9])[C:5]([H:10])([H:11])[C:6]([H:12])([H:13])[C:7]1([H:14])[H:15]"
|
|
785
|
+
),
|
|
786
|
+
[],
|
|
787
|
+
[],
|
|
788
|
+
3,
|
|
789
|
+
),
|
|
790
|
+
(
|
|
791
|
+
Chem.MolFromSmarts(
|
|
792
|
+
"[N+1:1](-[H])1[C@@:2]([C:3](=[O:4]))([H:9])[C:5]([H:10])([H:11])[C:6]([H:12])([H:13])[C:7]1([H:14])[H:15]"
|
|
793
|
+
),
|
|
794
|
+
[0],
|
|
795
|
+
[],
|
|
796
|
+
3,
|
|
797
|
+
),
|
|
798
|
+
(
|
|
799
|
+
Chem.MolFromSmarts(
|
|
800
|
+
"[N+0:1]1[C@@:2]([C:3](=[O:4]))([H:9])[C:5]([H:10])([H:11])[C:6]([H:12])([H:13])[C:7]1([H:14])[H:15]"
|
|
801
|
+
),
|
|
802
|
+
[0],
|
|
803
|
+
[],
|
|
804
|
+
2,
|
|
805
|
+
),
|
|
806
|
+
(
|
|
807
|
+
Chem.MolFromSmarts(
|
|
808
|
+
"[N+](-[H])(-[H])(-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S+0:6]([H]))([H:9])[H:10])[H:8]"
|
|
809
|
+
),
|
|
810
|
+
[],
|
|
811
|
+
[],
|
|
812
|
+
5,
|
|
813
|
+
),
|
|
814
|
+
(
|
|
815
|
+
Chem.MolFromSmarts("[N+](-[H])(-[H])(-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S+0:6])([H:9])[H:10])[H:8]"),
|
|
816
|
+
[8],
|
|
817
|
+
[],
|
|
818
|
+
5,
|
|
819
|
+
),
|
|
820
|
+
(
|
|
821
|
+
Chem.MolFromSmarts("[N+](-[H])(-[H])(-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S-1:6])([H:9])[H:10])[H:8]"),
|
|
822
|
+
[],
|
|
823
|
+
[],
|
|
824
|
+
5,
|
|
825
|
+
),
|
|
826
|
+
(
|
|
827
|
+
Chem.MolFromSmarts("[N](-[H])(-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S+0:6]([H]))([H:9])[H:10])[H:8]"),
|
|
828
|
+
[],
|
|
829
|
+
[],
|
|
830
|
+
4,
|
|
831
|
+
),
|
|
832
|
+
(
|
|
833
|
+
Chem.MolFromSmarts("[N](-[H])(-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S+0:6])([H:9])[H:10])[H:8]"),
|
|
834
|
+
[7],
|
|
835
|
+
[],
|
|
836
|
+
4,
|
|
837
|
+
),
|
|
838
|
+
(
|
|
839
|
+
Chem.MolFromSmarts("[N](-[H])(-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S-1:6])([H:9])[H:10])[H:8]"),
|
|
840
|
+
[],
|
|
841
|
+
[],
|
|
842
|
+
4,
|
|
843
|
+
),
|
|
844
|
+
(
|
|
845
|
+
Chem.MolFromSmarts("[N](-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S+0:6]([H]))([H:9])[H:10])[H:8]"),
|
|
846
|
+
[0],
|
|
847
|
+
[],
|
|
848
|
+
3,
|
|
849
|
+
),
|
|
850
|
+
(
|
|
851
|
+
Chem.MolFromSmarts("[N](-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S+0:6])([H:9])[H:10])[H:8]"),
|
|
852
|
+
[0, 6],
|
|
853
|
+
[],
|
|
854
|
+
3,
|
|
855
|
+
),
|
|
856
|
+
(
|
|
857
|
+
Chem.MolFromSmarts("[N](-[H])-[C@:2]([C:3](=[O:4]))([C:5]([S-1:6])([H:9])[H:10])[H:8]"),
|
|
858
|
+
[0],
|
|
859
|
+
[],
|
|
860
|
+
3,
|
|
861
|
+
),
|
|
862
|
+
(
|
|
863
|
+
Chem.MolFromSmarts("[N:1][C@:2]([C:3](=[O:4]))([C:5]([S+0:6]([H]))([H:9])[H:10])[H:8]"),
|
|
864
|
+
[0, 0],
|
|
865
|
+
[],
|
|
866
|
+
2,
|
|
867
|
+
),
|
|
868
|
+
(
|
|
869
|
+
Chem.MolFromSmarts("[N:1][C@:2]([C:3](=[O:4]))([C:5]([S+0:6])([H:9])[H:10])[H:8]"),
|
|
870
|
+
[0, 0, 5],
|
|
871
|
+
[],
|
|
872
|
+
2,
|
|
873
|
+
),
|
|
874
|
+
(
|
|
875
|
+
Chem.MolFromSmarts("[N:1][C@:2]([C:3](=[O:4]))([C:5]([S-1:6])([H:9])[H:10])[H:8]"),
|
|
876
|
+
[0, 0],
|
|
877
|
+
[],
|
|
878
|
+
2,
|
|
879
|
+
),
|
|
880
|
+
(
|
|
881
|
+
Chem.MolFromSmarts("[N+](-[H])(-[H])(-[H])-[C@](-[H])(-[*])-[C](=[O])"),
|
|
882
|
+
[],
|
|
883
|
+
[],
|
|
884
|
+
7,
|
|
885
|
+
),
|
|
886
|
+
(
|
|
887
|
+
Chem.MolFromSmarts("[N](-[H])(-[H])-[C@](-[H])(-[*])-[C](=[O])"),
|
|
888
|
+
[],
|
|
889
|
+
[],
|
|
890
|
+
6,
|
|
891
|
+
),
|
|
892
|
+
(Chem.MolFromSmarts("[N](-[H])-[C@](-[H])(-[*])-[C](=[O])"), [0], [], 5),
|
|
893
|
+
]
|
|
894
|
+
special_cases = {
|
|
895
|
+
"[C:1](=[O:2])[C:3]([H:4])([H:5])[H:6]": "[*]-[C:1](=[O:2])[C:3]([H:4])([H:5])[H:6]",
|
|
896
|
+
"[N:1]([C:2]([H:4])([H:5])[H:6])[H:3]": "[*]-[N:1]([C:2]([H:4])([H:5])[H:6])[H:3]",
|
|
897
|
+
"[N:1]([H:2])[H:3]": "[*]-C(=O)[N:1]([H:2])[H:3]",
|
|
898
|
+
"[C:1](=[O:2])[N:3]": "[*]-[C:1](=[O:2])[N:3](-[H])[C:4](-[*])(-[*])(-[*])",
|
|
899
|
+
"[S:1][S:2]": "[*]-[S:1]-[S:2]-[*]",
|
|
900
|
+
}
|
|
901
|
+
for res_name, subs in self.data.items():
|
|
902
|
+
res_dict = OrderedDict()
|
|
903
|
+
res_num = 0
|
|
904
|
+
for substruct, atom_names in subs.items():
|
|
905
|
+
rdmol = Chem.MolFromSmarts(substruct)
|
|
906
|
+
old_rdmol = deepcopy(rdmol)
|
|
907
|
+
query = tuple()
|
|
908
|
+
add_port = []
|
|
909
|
+
add_Hs = []
|
|
910
|
+
carboxyl_C = -1
|
|
911
|
+
for query, add_port, add_Hs, carboxyl_C in amino_acid_subs:
|
|
912
|
+
aa_match = rdmol.GetSubstructMatch(query)
|
|
913
|
+
if aa_match:
|
|
914
|
+
break
|
|
915
|
+
if not aa_match and substruct not in special_cases.keys():
|
|
916
|
+
raise Exception(f"{res_name}, {substruct} has no match")
|
|
917
|
+
if substruct in special_cases.keys():
|
|
918
|
+
if special_cases[substruct]:
|
|
919
|
+
rdmol = Chem.MolFromSmarts(special_cases[substruct])
|
|
920
|
+
else: # empty, discard
|
|
921
|
+
continue
|
|
922
|
+
else:
|
|
923
|
+
# add * where appropriate
|
|
924
|
+
for port_idx in add_port:
|
|
925
|
+
rdmol = add_atom(rdmol, aa_match[port_idx], "[*]")
|
|
926
|
+
# add H where appropriate
|
|
927
|
+
for H_idx in add_Hs:
|
|
928
|
+
rdmol = add_atom(rdmol, aa_match[H_idx], "[H]")
|
|
929
|
+
# add port to carboxyl atom if needed
|
|
930
|
+
carb = rdmol.GetAtomWithIdx(aa_match[carboxyl_C])
|
|
931
|
+
if carb.GetDegree() == 2:
|
|
932
|
+
rdmol = add_atom(rdmol, aa_match[carboxyl_C], "[*]")
|
|
933
|
+
formated_rdmol = _fill_out_query(rdmol)
|
|
934
|
+
# In this document, the only new atoms I add are *, so edit the atom names
|
|
935
|
+
num_new_atoms = formated_rdmol.GetNumAtoms() - len(atom_names)
|
|
936
|
+
atom_names = atom_names + ["*"] * num_new_atoms
|
|
937
|
+
sub_smarts = Chem.MolToSmarts(formated_rdmol)
|
|
938
|
+
res_num += 1
|
|
939
|
+
|
|
940
|
+
sub_smarts = sub_smarts.replace("&", "")
|
|
941
|
+
res_dict[sub_smarts] = atom_names
|
|
942
|
+
|
|
943
|
+
new_subs_dict[res_name] = res_dict
|
|
944
|
+
|
|
945
|
+
# validate using toolkit validator to check
|
|
946
|
+
check_dict = dict()
|
|
947
|
+
for res_name, subs in new_subs_dict.items():
|
|
948
|
+
res_num = 0
|
|
949
|
+
for substruct, atom_names in subs.items():
|
|
950
|
+
check_dict[f"{res_name}_{res_num}"] = [substruct]
|
|
951
|
+
res_num += 1
|
|
952
|
+
RDKitToolkitWrapper()._validate_custom_substructures(
|
|
953
|
+
custom_substructures=check_dict, forbidden_keys=[]
|
|
954
|
+
) # errors if any are invalid
|
|
955
|
+
self.data = new_subs_dict
|