datamol.graph
¶
get_all_path_between(mol, atom_idx_1, atom_idx_2, ignore_cycle_basis=False)
¶
Get all simple path between two atoms of a molecule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule |
required |
atom_idx_1 |
int
|
Atom index 1. |
required |
atom_idx_2 |
int
|
Atom index 2. |
required |
ignore_cycle_basis |
bool
|
Whether to ignore cycle basis. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
list
|
list of path between two atoms. |
Source code in datamol/graph.py
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 |
|
match_molecular_graphs(mol1, mol2, match_atoms_on=['atomic_num'], match_bonds_on=['bond_type'])
¶
Match the node indices of 2 molecular graphs, with optional usage of atomic number and edge type.
Note
The matching fails if the hydrogens are implicit in one molecule, but explicit in the other.
Note
Explicit hydrogens might lead to too many matches, since for an atom with 2 hydrogens, they can be re-ordered in any way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol1 |
Mol
|
A molecule. |
required |
mol2 |
Mol
|
A molecule. |
required |
match_atoms_on |
List[str]
|
Properties on which to match the atom types.
By default, it matches on the Other properties are defined by the |
['atomic_num']
|
match_bonds_on |
List[str]
|
Properties on which to match the bond types.
Empty list means that it does not consider bond features during matching.
By default, it matches on the |
['bond_type']
|
Returns:
Type | Description |
---|---|
List[Dict[int, int]]
|
A list of all matches dictionaries. In case of a single match, the list has len==1. |
List[Dict[int, int]]
|
Each dictionary contains as key the indices of |
List[Dict[int, int]]
|
indices of |
Source code in datamol/graph.py
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 |
|
reorder_mol_from_template(mol, mol_template, enforce_atomic_num=False, enforce_bond_type=False, ambiguous_match_mode='No', verbose=True)
¶
Re-order the nodes of a molecular graph from the nodes of a template molecule. Molecular graphs and atom types need to be identical, but edge types and charges are not enforced.
This is particularily useful when dealing with XYZ files containing node ordering, but with missing information regarding charges and edge types.
Note
- If you only need to match bond orders, you can check the function
rdkit.Chem.AllChem.AssignBondOrdersFromTemplate
. - The matching fails if the hydrogens are implicit in one molecule, but explicit in the other.
- Explicit hydrogens might lead to too many matches, since for an atom with 2 hydrogens, they can be re-ordered in any way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
The molecule to re-order |
required |
mol_template |
Mol
|
The molecule containing the right node order. |
required |
enforce_atomic_num |
bool
|
Whether to enforce atomic number. Atomic numbers are always enforced
for a first try. If no match are found and this parameter is |
False
|
enforce_bond_type |
bool
|
Whether to enforce bond types. Bond types are always enforced
for a first try. If no match are found and this parameter is |
False
|
ambiguous_match_mode |
str
|
Whether to allow ambiguous matching. This means that,
if there are many matches to the molecule, it will still re-order
the molecule according to specific rules. Options are:
- "no": Does not allow ambiguous matching.
- "hs-only": Allow matching of ambiguous hydrogens. Does not work if trying
to match implicit with explicit hydrogens.
- "first": Return the first match.
- "best": Return the match with the least errors on atom type, edges type, and edge stereo.
Errors on the atoms are counted with 1 point, on the charge with 0.25 points,
on the edges with 0.25 points, and on the Stereo with 0.05 points.
If the option |
'No'
|
verbose |
bool
|
Whether to warn when the matching does not work or is ambiguous.
Different warnings are raised depending on the value of |
True
|
Returns:
Type | Description |
---|---|
Optional[Mol]
|
|
Optional[Mol]
|
|
Optional[Mol]
|
|
Source code in datamol/graph.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
to_graph(mol)
¶
Convert a molecule to a network x graph. A list of properties are added to every nodes and edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
Returns:
Name | Type | Description |
---|---|---|
mol_graph |
Graph
|
a graph representing the molecule. |
Source code in datamol/graph.py
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 |
|