Substructure Match
Check if a fragment (which can contain dummy or any atoms represented by "*") is a strict substructure of a molecule. A strict substructure means that no additional atoms should be present in the molecule other than those explicitly defined in the fragment. Extra atoms (including hydrogen atoms) are only allowed at the sites of dummy atoms in the fragment.
Example Use
from fragmentretro.substructure_matcher import SubstructureMatcher
fragment_smiles = "[4*]CCN[5*]",
molecule_smiles = "CCCNC"
print(SubstructureMatcher.is_strict_substructure(fragment_smiles, molecule_smiles))
# should print True
Source Code
fragmentretro.substructure_matcher
SubstructureMatcher
Source code in src/fragmentretro/substructure_matcher.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
__init__(BBs, useChirality=True, parallelize=False, num_cores=None, core_factor=10)
Initialize with a set of building blocks (BBs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
BBs
|
BBsType
|
Set of building block SMILES strings. |
required |
useChirality
|
bool
|
Whether to match chirality. |
True
|
parallelize
|
bool
|
Whether to enable parallel processing. |
False
|
num_cores
|
int | None
|
Number of CPU cores to use for parallel processing. If None, uses all available cores. |
None
|
core_factor
|
int
|
Factor to determine when to use parallel processing. If the number of BBs is greater than
|
10
|
Source code in src/fragmentretro/substructure_matcher.py
convert_to_smarts(fragment_smiles)
staticmethod
Convert a fragment SMILES string into a SMARTS string with hydrogen counts explicitly specified, and convert dummy atoms into wildcards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment_smiles
|
str
|
SMILES string of the fragment. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SMARTS string with explicit hydrogen counts, handling dummy atoms. |
Source code in src/fragmentretro/substructure_matcher.py
addH_to_wildcard_neighbors(fragment_smarts)
staticmethod
Adjust SMARTS by adding hydrogens to neighbors of wildcard atoms (*).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment_smarts
|
str
|
Fragment SMARTS string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Adjusted SMARTS string with explicit hydrogen counts for neighbors of wildcards. |
Source code in src/fragmentretro/substructure_matcher.py
is_strict_substructure(fragment_smiles, molecule_smiles, useChirality=True)
staticmethod
Check if the fragment is a strict substructure of the molecule. No extra atoms or branchings should be in the molecule other than the ones explicitly defined in the fragment, except for dummy atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment_smiles
|
str
|
SMILES string of the fragment. |
required |
molecule_smiles
|
str
|
SMILES string of the molecule. |
required |
useChirality
|
bool
|
whether to match chirality |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the fragment is a strict substructure of the molecule, False otherwise. |
Source code in src/fragmentretro/substructure_matcher.py
get_substructure_BBs(fragment)
Get the set of building blocks (BBs) that the fragment matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
str
|
SMILES string of the fragment. |
required |
Returns:
| Type | Description |
|---|---|
BBsType
|
Set of building block SMILES strings that the fragment matches. |