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
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 |
|
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
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
|
atom_indices_to_mol(mol, copy=False)
¶
Add the molAtomMapNumber
property to each atoms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule |
required |
copy |
bool
|
Whether to copy the molecule. |
False
|
Source code in datamol/mol.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 |
|
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
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
|
clear_mol_props(mol, copy=True, include_private=False, include_computed=False)
¶
Clear all properties from a 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
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
|
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
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 |
|
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
57 58 59 60 61 62 63 |
|
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
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
|
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
495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
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
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
|
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
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
|
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
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 |
|
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
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
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
685 686 687 688 689 690 691 692 |
|
keep_largest_fragment(mol)
¶
Only keep largest fragment of each molecule.
Source code in datamol/mol.py
676 677 678 679 680 681 682 |
|
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
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 |
|
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
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 |
|
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
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
remove_dummies(mol, dummy='*')
¶
Remove dummy atoms from molecules.
Source code in datamol/mol.py
599 600 601 602 603 604 605 606 607 608 609 610 |
|
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
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
|
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
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 |
|
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
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
|
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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
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
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
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
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 |
|
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
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 |
|
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
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
|
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
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
|
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
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 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 |
|
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
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
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
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
|
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
854 855 856 857 858 859 860 861 862 863 864 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 900 901 |
|
to_mol(mol, add_hs=False, explicit_only=False, ordered=False, kekulize=False, sanitize=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. |
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
|
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
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 |
|
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
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
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
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 |
|
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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|