datamol.mol
¶
add_hs(mol, explicit_only=False, add_coords=False, only_on_atoms=None, add_residue_info=False)
¶
Adds hydrogens to the molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
explicit_only |
bool
|
whether to only add explicit hydrogens. |
False
|
add_coords |
bool
|
whether to add 3D coordinates to the hydrogens. |
False
|
only_on_atoms |
Optional[List[int]]
|
a list of atoms to add hydrogens only on. |
None
|
add_residue_info |
bool
|
whether to add residue information to the hydrogens. Useful for PDB files. |
False
|
Source code in datamol/mol.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
|
adjust_singleton(mol)
¶
Remove all atoms that are essentially disconnected singleton nodes in the molecular graph. For example, the chlorine atom and methane fragment will be removed in Cl.[N:1]1=CC(O)=CC2CCCCC12.CC.C", but not the ethane fragment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
Source code in datamol/mol.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
|
atom_indices_to_mol(mol, copy=True)
¶
Add the molAtomMapNumber
property to each atoms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule |
required |
copy |
bool
|
Whether to copy the molecule. |
True
|
Source code in datamol/mol.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 |
|
atom_list_to_bond(mol, atom_indices, bond_as_idx=False)
¶
Return a list of existing bond indices between a list of atom indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
atom_indices |
List[int]
|
A list of atom indices. |
required |
Source code in datamol/mol.py
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
|
clear_atom_map_number(mol, copy=True)
¶
Clear the molAtomMapNumber
property of the atom's molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
copy |
bool
|
Whether to copy the molecule. |
True
|
Source code in datamol/mol.py
902 903 904 905 906 907 908 909 |
|
clear_atom_props(mol, property_keys=None, copy=True, include_private=False, include_computed=False)
¶
Clear atom properties from a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
property_keys |
Optional[Union[List[str], str]]
|
If set, only the set properties will be cleared. It not set, all the properties are cleared. |
None
|
copy |
bool
|
Whether to copy the molecule. |
True
|
include_private |
bool
|
Whether to also clean the private properties. |
False
|
include_computed |
bool
|
Whether to also clean the computed properties. |
False
|
Source code in datamol/mol.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 |
|
clear_mol_props(mol, property_keys=None, copy=True, include_private=False, include_computed=False)
¶
Clear properties from a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
property_keys |
Optional[Union[List[str], str]]
|
If set, only the set properties will be cleared. It not set, all the properties are cleared. |
None
|
copy |
bool
|
Whether to copy the molecule. |
True
|
include_private |
bool
|
Whether to also clean the private properties. |
False
|
include_computed |
bool
|
Whether to also clean the computed properties. |
False
|
Source code in datamol/mol.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
|
compute_ring_system(mol, include_spiro=True)
¶
Compute the list of ring system in a molecule. This is based on RDKit's cookbook: https://www.rdkit.org/docs/Cookbook.html#rings-aromaticity-and-kekulization
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
input molecule |
required |
include_spiro |
bool
|
whether to include spiro rings. |
True
|
Returns:
Name | Type | Description |
---|---|---|
ring_system |
List[Set[int]]
|
list of ring system (atom indices). |
Source code in datamol/mol.py
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 |
|
copy_mol(mol)
¶
Copy a molecule and return a new one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule to copy. |
required |
Source code in datamol/mol.py
49 50 51 52 53 54 55 |
|
copy_mol_props(source, destination, include_private=False, include_computed=False)
¶
Copy properties from one source molecule to another destination molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
Mol
|
a molecule to copy from. |
required |
destination |
Mol
|
a molecule to copy to. |
required |
include_private |
bool
|
Include private properties. |
False
|
include_computed |
bool
|
Include computed properties. |
False
|
Source code in datamol/mol.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
|
decrease_bond(bond)
¶
Remove one single bond from the input bond. Note that you should first kekulize your molecules and remove non-standard bond.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bond |
Chem.rdchem.Bond
|
a bond. |
required |
Source code in datamol/mol.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
fix_mol(mol, n_iter=1, remove_singleton=False, largest_only=False, inplace=False)
¶
Fix error in molecule using a greedy approach.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
input molecule to fix |
required |
n_iter |
int
|
Number of valence fix iteration to apply |
1
|
remove_singleton |
bool
|
Whether |
False
|
largest_only |
bool
|
Whether only the largest fragment should be kept |
False
|
inplace |
bool
|
Whether to return a copy of the mol or perform in place operation |
False
|
Returns:
Type | Description |
---|---|
Optional[Mol]
|
Fixed molecule. |
Source code in datamol/mol.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
fix_valence(mol, inplace=False, allow_ring_break=False)
¶
Identify and try to fix valence issues by removing any supplemental bond that should not be in the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
input molecule with incorrect valence for some atoms |
required |
inplace |
bool
|
Whether to modify in place or make a copy |
False
|
allow_ring_break |
bool
|
Whether bond removal involving ring is allowed. |
False
|
Returns:
Type | Description |
---|---|
Optional[Mol]
|
Fixed potential valence issue in molecule or original molecule when nothing is broken |
Optional[Mol]
|
of if failed. |
Source code in datamol/mol.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
fix_valence_charge(mol, inplace=False)
¶
Fix valence issues that are due to incorrect charges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
Input molecule with incorrect valence for some atoms |
required |
inplace |
bool
|
Whether to modify in place or make a copy. |
False
|
Returns:
Type | Description |
---|---|
Optional[Mol]
|
Fixed molecule via charge correction or original molecule if failed. |
Source code in datamol/mol.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
get_atom_positions(mol, conf_id=-1, reorder_to_atom_map_number=False)
¶
Return the atom positions of a given molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
conf_id |
int
|
The conformer ID to set the conformer to. |
-1
|
reorder_to_atom_map_number |
bool
|
Whether to reorder the positions to map the
atom map numbers given by the |
False
|
Source code in datamol/mol.py
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 |
|
hash_mol(mol, hash_scheme='all')
¶
Generate a unique hash code for a molecule based on chemistry. If two molecules are chemically “the same”, they should have the same hash.
Using molhash adds value beyond using SMILES because it:
- Ignores SMILES features that are not chemically meaningful (e.g. atom map numbers).
- Canonicalizes enhanced stereochemistry groups. For example
C[C@H](O)CC |&1:1|
andC[C@@H](O)CC |&1:1|
have the same molhash. - Canonicalizes S group data (for example, polymer data).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
hash_scheme |
str
|
There are three hash schemes: - "all": most strict hash scheme utilizing all layers. - "no_stereo": excludes stereo sensitive layers. - "no_tautomers": excludes tautomer sensitive layers. |
'all'
|
Returns:
Type | Description |
---|---|
str
|
The hash as a 40 chars string. |
Source code in datamol/mol.py
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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
incorrect_valence(a, update=False)
¶
Check if an atom connection is not valid or all the atom of a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
Union[Mol, Chem.rdchem.Atom]
|
atom or molecule to check for valence issue. |
required |
update |
bool
|
Update owning molecule property cache first. |
False
|
Returns:
Type | Description |
---|---|
bool
|
Whether the input atom valence is correct. |
Source code in datamol/mol.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
is_transition_metal(at)
¶
Check if atom is a transition metal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
at |
Chem.rdchem.Atom
|
an atom. |
required |
Source code in datamol/mol.py
737 738 739 740 741 742 743 744 |
|
keep_largest_fragment(mol)
¶
Only keep largest fragment of each molecule.
Source code in datamol/mol.py
728 729 730 731 732 733 734 |
|
make_scaffold_generic(mol, include_bonds=False)
¶
Make the atom in a scaffold or molecule generic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule or a scaffold. |
required |
include_bonds |
bool
|
Whether we should also update bond order or keep as is. |
False
|
Source code in datamol/mol.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 |
|
protect_atoms(mol, substruct=None, atoms=None, in_place=False)
¶
Protect a list of atoms or substruct in a molecule.
The _protected attributes of a molecule is used by RDKit in several functions, especially for reactions where "protected" atoms are disallowed from taking part in reactions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
input molecule to protect |
required |
substruct |
Optional[Mol]
|
optional substructure query to identify atoms to protect |
None
|
atoms |
Optional[Union[List[int], int]]
|
optional list of atom indices to protect |
None
|
in_place |
bool
|
whether to perform the protection in place or return a copy of the molecule |
False
|
Source code in datamol/mol.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
|
randomize_atoms(mol)
¶
Randomize the position of the atoms in a mol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
Returns:
Name | Type | Description |
---|---|---|
mol |
Optional[Mol]
|
a molecule. |
Source code in datamol/mol.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
remove_dummies(mol, dummy='*')
¶
Remove dummy atoms from molecules.
Source code in datamol/mol.py
651 652 653 654 655 656 657 658 659 660 661 662 |
|
remove_hs(mol, implicit_only=False, update_explicit_count=False, sanitize=True)
¶
Removes hydrogens from a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
implicit_only |
bool
|
whether to only remove implicit hydrogens. |
False
|
update_explicit_count |
bool
|
whether to update the explicit hydrogen count. |
False
|
sanitize |
bool
|
whether to sanitize the molecule after the hydrogens are removed. |
True
|
Source code in datamol/mol.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
|
reorder_atoms(mol, break_ties=True, include_chirality=True, include_isotopes=True)
¶
Reorder the atoms in a mol. It ensures a single atom order for the same molecule, regardless of its original representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
break_ties |
bool
|
Force breaking of ranked ties. |
True
|
include_chirality |
bool
|
Use chiral information when computing rank. |
True
|
include_isotopes |
bool
|
Use isotope information when computing rank. |
True
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Optional[Mol]
|
a molecule. |
Source code in datamol/mol.py
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 |
|
replace_dummies_atoms(mol, atom='C', dummy='*', replace_all=True)
¶
Remove dummy atoms from molecules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
molecule with dummies |
required |
atom |
str
|
replacement atom, default is carbon |
'C'
|
dummy |
str
|
dummy atom representation |
'*'
|
replace_all |
bool
|
Whether to replace all dummies |
True
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Optional[Mol]
|
Molecule with dummy replaced |
Source code in datamol/mol.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
same_mol(mol1, mol2, use_non_standard_inchikey=False)
¶
Check two molecules are the same by comparing their InChiKey.
Invalid molecules (None) are always considered as not the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol1 |
Optional[Mol]
|
A molecule. |
required |
mol2 |
Optional[Mol]
|
A molecule. |
required |
use_non_standard_inchikey |
bool
|
Whether to use the standard or non-standard InChiKey. |
False
|
Source code in datamol/mol.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
sanitize_first(mols, charge_neutral=False, sanifix=True)
¶
Sanitize a list of molecules and return the first valid molecule seen in the list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
List[Mol]
|
a list of molecules. |
required |
charge_neutral |
bool
|
whether charge neutralization should be applied. |
False
|
sanifix |
bool
|
whether to run the sanifix from James Davidson (sanifix4.py) that try to adjust aromatic nitrogens. |
True
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Mol
|
a molecule. |
Source code in datamol/mol.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
sanitize_mol(mol, charge_neutral=False, sanifix=True, verbose=True, add_hs=False)
¶
An augmented version of RDKit sanitize=True
. It uses a
mol-SMILES-mol conversion to catch potential aromaticity errors
and try to fix aromatic nitrogen (using the popular sanifix4 script).
Optionally, it can neutralize the charge of the molecule.
Note #1: Only the first conformer (if present) will be preserved and a warning will be displayed if more than one conformer is detected.
Note #2: The molecule's properties will be preserved but the atom's properties will be lost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
charge_neutral |
bool
|
whether charge neutralization should be applied. |
False
|
sanifix |
bool
|
whether to run the sanifix from James Davidson (sanifix4.py) that try to adjust aromatic nitrogens. |
True
|
verbose |
bool
|
Whether displaying a warning about multiple conformers. |
True
|
add_hs |
bool
|
Add hydrogens to the returned molecule. Useful when the input molecule already contains hydrogens. |
False
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Optional[Mol]
|
a molecule. |
Source code in datamol/mol.py
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 |
|
sanitize_smiles(smiles, isomeric=True)
¶
Takes SMILES string and returns its sanitized version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles |
Optional[str]
|
smiles to be sanitized. |
required |
isomeric |
bool
|
Whether to include information about stereochemistry in the SMILES. |
True
|
Returns:
Type | Description |
---|---|
Optional[str]
|
sanitized smiles. |
Source code in datamol/mol.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
set_atom_positions(mol, positions, conf_id=0, copy=True, use_atom_map_numbers=True, remove_previous_conformers=True)
¶
Add a conformer to a molecule given the atom's positions.
The conformer 3D flag is automatically set if all the z coordinates are 0.
Example:
The below example is common when you want to reconstruct a molecule object from its SMILES and its held out atomic positions. The position array is ordered according to the atom number seen in the SMILES. This is a common data structure when working with Quantum Mechanics dataset.
import datamol as dm
import numpy as np
# We start with a SMILES where every atoms is mapped to a specific number
smiles = "[H:14][c:5]1[c:3]([c:7]([c:4]([c:6]([c:8]1[N:10]([H:18])[C:2](=[N+:11]([H:19])[H:20])[N:9]([H:16])[H:17])[H:15])[H:13])[F:1])[H:12]"
# Every atom position below is mapped to the atom number in the SMILES above
positions = [
[1.7, -6.67, 3.15],
[0.2, 4.72, 0.78],
[3.54, -2.64, 2.88],
[0.43, -3.87, -0.09],
[3.44, -0.2, 1.8],
[0.02, -1.5, -1.0],
[2.12, -4.54, 1.9],
[1.5, 0.48, 0.02],
[0.53, 7.24, 0.25],
[1.17, 2.91, -0.85],
[-1.22, 4.15, 2.71],
[4.64, -3.24, 4.55],
[-0.89, -5.43, -0.78],
[4.52, 1.43, 2.45],
[-1.45, -1.02, -2.48],
[-0.15, 8.68, 1.38],
[1.65, 7.88, -1.21],
[2.24, 3.64, -2.15],
[-1.96, 2.4, 3.0],
[-2.02, 5.59, 3.71],
]
# We build the mol object by setting `remove_hs` to `False`.
# This is important so the hydrogens and their atom number are preserved.
mol = dm.to_mol(smiles, remove_hs=False)
# If you plot the molecule with `dm.to_image(mol)`, you'll notice
# the atom numbers are added to the drawing.
# Now we set the atom positions to the newly constructed `mol` object.
# Here it's important to set `use_atom_map_numbers` to `True`, so the atom numbers
# from the SMILES are used to match the input positions array.
# Under the hood, RDKit has set the `molAtomMapNumber` property to all the atoms in the
# molecule.
new_mol = dm.set_atom_positions(
mol=mol,
positions=positions,
conf_id=0,
use_atom_map_numbers=True,
)
# The newly set conformer now had the correct 3D positions.
# You can visualize the molecule with `dm.to_image(new_mol)` in 2D
# or `dm.viz.conformers(new_mol)`.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
positions |
npt.ArrayLike
|
An array or a list of atomic positions. Shape of |
required |
conf_id |
int
|
The conformer ID to set the conformer to. |
0
|
copy |
bool
|
Whether to copy the molecule. |
True
|
use_atom_map_numbers |
bool
|
Whether to input positions are ordered given the atom mapped
numbers set in the |
True
|
remove_previous_conformers |
bool
|
Whether to remove the previous conformers if any in the input molecule. |
True
|
Source code in datamol/mol.py
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 |
|
set_dative_bonds(mol, from_atoms=(7, 8))
¶
Replaces some single bonds between metals and atoms with atomic numbers in fromAtoms with dative bonds. The replacement is only done if the atom has "too many" bonds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
molecule with bond to modify |
required |
from_atoms |
Tuple[int, int]
|
List of atoms (symbol or atomic number) to consider for bond replacement. By default, only Nitrogen (7) and Oxygen (8) are considered. |
(7, 8)
|
Returns:
Type | Description |
---|---|
Optional[Mol]
|
The modified molecule. |
Source code in datamol/mol.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 |
|
set_mol_props(mol, props, copy=False)
¶
Set properties to a mol from a dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
the mol where to copy the props. |
required |
props |
Dict[str, Any]
|
the props to copy. |
required |
copy |
bool
|
whether to copy the provided mol |
False
|
Source code in datamol/mol.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
|
standardize_mol(mol, disconnect_metals=False, normalize=True, reionize=True, uncharge=False, stereo=True)
¶
This function returns a standardized version the given molecule. It relies on the
RDKit rdMolStandardize
module
which is largely inspired from MolVS.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule to standardize. |
required |
disconnect_metals |
bool
|
Disconnect metals that are defined as covalently bonded to non-metal. Depending on the source of the database, some compounds may be reported in salt form or associated to metallic ions (e.g. the sodium salt of a carboxylic compound). In most cases, these counter-ions are not relevant so the use of this function is required before further utilization of the dataset. In summary the process is the following:
|
False
|
normalize |
bool
|
Applies a series of standard transformations to correct functional groups and recombine charges. It corrects drawing errors and standardizes functional groups in the molecule as well as ensuring the overall proper charge of the compound. It includes:
|
True
|
reionize |
bool
|
If one or more acidic functionalities are present in the molecule, this option ensures the correct neutral/ionized state for such functional groups. Molecules are uncharged by adding and/or removing hydrogens. For zwitterions, hydrogens are moved to eliminate charges where possible. However, in cases where there is a positive charge that is not neutralizable, an attempt is made to also preserve the corresponding negative charge The algorithm works as follows:
|
True
|
uncharge |
bool
|
This option neutralize the molecule by reversing the protonation state of protonated and deprotonated groups, if present (e.g. a carboxylate is re-protonated to the corresponding carboxylic acid). In cases where there is a positive charge that is not neutralizable, an attempt is made to also preserve the corresponding negative charge to ensure a net zero charge. |
False
|
stereo |
bool
|
Stereochemical information is corrected and/or added if missing using built-in RDKit functionality to force a clean recalculation of stereochemistry ( |
True
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Mol
|
A standardized molecule. |
Source code in datamol/mol.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
standardize_smiles(smiles, tautomer=False)
¶
Apply smile standardization procedure. This is a convenient function wrapped arrounf RDKit smiles standardizer and tautomeric canonicalization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles |
str
|
Smiles to standardize |
required |
tautomer |
bool
|
Whether to canonicalize tautomers |
False
|
Returns:
Name | Type | Description |
---|---|---|
standard_smiles |
str
|
the standardized smiles |
Source code in datamol/mol.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
strip_mol_to_core(mol, bond_cutter=None)
¶
Strip a molecule to its core, i.e. remove all atoms not in the core. This method 'guess' the molecular core, by finding the ring system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
bond_cutter |
Mol
|
A molecule used to cut the bonds. |
None
|
Source code in datamol/mol.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
|
substructure_matching_bonds(mol, query, **kwargs)
¶
Perform a substructure match using GetSubstructMatches
but instead
of returning only the atom indices also return the bond indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
query |
Mol
|
A molecule used as a query to match against. |
required |
**kwargs |
Any
|
Any other arguments to pass to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
atom_matches |
list
|
A list of lists of atom indices. |
bond_matches |
list
|
A list of lists of bond indices. |
Source code in datamol/mol.py
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
|
to_mol(mol, add_hs=False, explicit_only=False, ordered=False, kekulize=False, sanitize=True, allow_cxsmiles=True, parse_name=True, remove_hs=True, strict_cxsmiles=True)
¶
Convert an input molecule (smiles representation) into a Mol
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
A SMILES or a molecule. |
required |
add_hs |
bool
|
Whether hydrogens should be added the molecule after the SMILES has been parsed. |
False
|
explicit_only |
bool
|
Whether to only add explicit hydrogen or both
(implicit and explicit). when |
False
|
ordered |
bool
|
Whether the atom should be ordered. This option is important if you want to ensure that the features returned will always maintain a single atom order for the same molecule, regardless of its original SMILES representation. |
False
|
kekulize |
bool
|
Whether to perform kekulization of the input molecules. |
False
|
sanitize |
bool
|
Whether to apply rdkit sanitization when input is a SMILES. |
True
|
allow_cxsmiles |
bool
|
Recognize and parse CXSMILES. |
True
|
parse_name |
bool
|
Parse (and set) the molecule name as well. |
True
|
remove_hs |
bool
|
Wether to remove the hydrogens from the input SMILES. |
True
|
strict_cxsmiles |
bool
|
Throw an exception if the CXSMILES parsing fails. |
True
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Optional[Mol]
|
the molecule if some conversion have been made. If the conversion fails |
Optional[Mol]
|
None is returned so make sure that you handle this case on your own. |
Source code in datamol/mol.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 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 |
|
to_neutral(mol)
¶
Neutralize the charge of a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Optional[Mol]
|
a molecule. |
required |
Returns:
Name | Type | Description |
---|---|---|
mol |
Optional[Mol]
|
a molecule. |
Source code in datamol/mol.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
to_scaffold_murcko(mol, make_generic=False)
¶
Extract the Murcko scaffold from a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
make_generic |
bool
|
Whether to make the scaffold generic. |
False
|
Source code in datamol/mol.py
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 |
|
unique_id(mol)
¶
A datamol unique molecule ID.
The ID is an MD5 hash of the non-standard InChiKey provided
by dm.to_inchikey_non_standard()
. It guarantees uniqueness for
different tautomeric forms of the same molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
Source code in datamol/mol.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|