SAFE
SAFE Encoder-Decoder¶
SAFEConverter
¶
Molecule line notation conversion from SMILES to SAFE
A SAFE representation is a string based representation of a molecule decomposition into fragment components, separated by a dot ('.'). Note that each component (fragment) might not be a valid molecule by themselves, unless explicitely correct to add missing hydrogens.
Slicing algorithms
By default SAFE strings are generated using BRICS
, however, the following alternative are supported:
- Hussain-Rea (
hr
) - RECAP (
recap
) - RDKit's MMPA (
mmpa
) - Any possible attachment points (
attach
)
Furthermore, you can also provide your own slicing algorithm, which should return a pair of atoms corresponding to the bonds to break.
Source code in safe/converter.py
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 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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
__init__(slicer='brics', require_hs=None, use_original_opener_for_attach=True, ignore_stereo=False)
¶
Constructor for the SAFE converter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slicer
|
Optional[Union[str, List[str], Callable]]
|
slicer algorithm to use for encoding. Can either be one of the supported slicing algorithm (SUPPORTED_SLICERS) or a custom callable that returns the bond ids that can be sliced. |
'brics'
|
require_hs
|
Optional[bool]
|
whether the slicing algorithm require the molecule to have hydrogen explictly added.
|
None
|
use_original_opener_for_attach
|
bool
|
whether to use the original branch opener digit when adding back mapping number to attachment points, or use simple enumeration. |
True
|
ignore_stereo
|
bool
|
RDKIT does not support some particular SAFE subset when stereochemistry is defined. |
False
|
Source code in safe/converter.py
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 |
|
decoder(inp, as_mol=False, canonical=False, fix=True, remove_dummies=True, remove_added_hs=True)
¶
Convert input SAFE representation to smiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inp
|
str
|
input SAFE representation to decode as a valid molecule or smiles |
required |
as_mol
|
bool
|
whether to return a molecule object or a smiles string |
False
|
canonical
|
bool
|
whether to return a canonical |
False
|
fix
|
bool
|
whether to fix the SAFE representation to take into account non-connected attachment points |
True
|
remove_dummies
|
bool
|
whether to remove dummy atoms from the SAFE representation. Note that removing_dummies is incompatible with |
True
|
remove_added_hs
|
bool
|
whether to remove all the added hydrogen atoms after applying dummy removal for recovery |
True
|
Source code in safe/converter.py
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 |
|
encoder(inp, canonical=True, randomize=False, seed=None, constraints=None, allow_empty=False, rdkit_safe=True)
¶
Convert input smiles to SAFE representation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inp
|
Union[str, Mol]
|
input smiles |
required |
canonical
|
bool
|
whether to return canonical smiles string. Defaults to True |
True
|
randomize
|
Optional[bool]
|
whether to randomize the safe string encoding. Will be ignored if canonical is provided |
False
|
seed
|
Optional[int]
|
optional seed to use when allowing randomization of the SAFE encoding. Randomization happens at two steps: 1. at the original smiles representation by randomization the atoms. 2. at the SAFE conversion by randomizing fragment orders |
None
|
constraints
|
Optional[List[Mol]]
|
List of molecules or pattern to preserve during the SAFE construction. Any bond slicing would happen outside of a substructure matching one of the patterns. |
None
|
allow_empty
|
bool
|
whether to allow the slicing algorithm to return empty bonds |
False
|
rdkit_safe
|
bool
|
whether to apply rdkit-safe digit standardization to the output SAFE string. |
True
|
Source code in safe/converter.py
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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
randomize(mol, rng=None)
staticmethod
¶
Randomize the position of the atoms in a mol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
molecules to randomize |
required |
rng
|
Optional[int]
|
optional seed to use |
None
|
Source code in safe/converter.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
encode(inp, canonical=True, randomize=False, seed=None, slicer=None, require_hs=None, constraints=None, ignore_stereo=False)
¶
Convert input smiles to SAFE representation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inp
|
Union[str, Mol]
|
input smiles |
required |
canonical
|
bool
|
whether to return canonical SAFE string. Defaults to True |
True
|
randomize
|
Optional[bool]
|
whether to randomize the safe string encoding. Will be ignored if canonical is provided |
False
|
seed
|
Optional[int]
|
optional seed to use when allowing randomization of the SAFE encoding. |
None
|
slicer
|
Optional[Union[List[str], str, Callable]]
|
slicer algorithm to use for encoding. Defaults to "brics". |
None
|
require_hs
|
Optional[bool]
|
whether the slicing algorithm require the molecule to have hydrogen explictly added. |
None
|
constraints
|
Optional[List[Mol]]
|
List of molecules or pattern to preserve during the SAFE construction. |
None
|
ignore_stereo
|
Optional[bool]
|
RDKIT does not support some particular SAFE subset when stereochemistry is defined. |
False
|
Source code in safe/converter.py
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 |
|
decode(safe_str, as_mol=False, canonical=False, fix=True, remove_added_hs=True, remove_dummies=True, ignore_errors=False)
¶
Convert input SAFE representation to smiles Args: safe_str: input SAFE representation to decode as a valid molecule or smiles as_mol: whether to return a molecule object or a smiles string canonical: whether to return a canonical smiles or a randomized smiles fix: whether to fix the SAFE representation to take into account non-connected attachment points remove_added_hs: whether to remove the hydrogen atoms that have been added to fix the string. remove_dummies: whether to remove dummy atoms from the SAFE representation ignore_errors: whether to ignore error and return None on decoding failure or raise an error
Source code in safe/converter.py
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 439 440 441 442 443 444 445 446 447 |
|
SAFE Design¶
SAFEDesign
¶
Molecular generation using SAFE pretrained model
Source code in safe/sample.py
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 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 350 351 352 353 354 355 356 357 358 359 360 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 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 492 493 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 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 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 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 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 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 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 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 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 809 810 811 812 813 814 815 816 817 818 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 852 853 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 902 903 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 942 943 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 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 1010 1011 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 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
|
__init__(model, tokenizer, generation_config=None, safe_encoder=None, verbose=True)
¶
SAFEDesign constructor
Info
Design methods in SAFE are not deterministic when it comes to the token sampling step.
If a method accepts a random_seed
, it's for the SAFE-related algorithms and not the
sampling from the autoregressive model. To ensure you get a deterministic sampling,
please set the seed at the transformers
package level.
import safe as sf
import transformers
my_seed = 100
designer = sf.SAFEDesign(...)
transformers.set_seed(100) # use this before calling a design function
designer.linker_generation(...)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Union[SAFEDoubleHeadsModel, str]
|
input SAFEDoubleHeadsModel to use for generation |
required |
tokenizer
|
Union[str, SAFETokenizer]
|
input SAFETokenizer to use for generation |
required |
generation_config
|
Optional[Union[str, GenerationConfig]]
|
input GenerationConfig to use for generation |
None
|
safe_encoder
|
Optional[SAFEConverter]
|
custom safe encoder to use |
None
|
verbose
|
bool
|
whether to print out logging information during generation |
True
|
Source code in safe/sample.py
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 |
|
__mix_sequences(prefix_sequences, suffix_sequences, prefix, suffix, n_samples, mol_linker_slicer)
¶
Use generated prefix and suffix sequences to form new molecules that will be the merging of both. This is the two step scaffold morphing and linker generation scheme Args: prefix_sequences: list of prefix sequences suffix_sequences: list of suffix sequences prefix: decoded smiles of the prefix suffix: decoded smiles of the suffix n_samples: number of samples to generate
Source code in safe/sample.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
|
de_novo_generation(n_samples_per_trial=10, sanitize=False, n_trials=None, **kwargs)
¶
Perform de novo generation using the pretrained SAFE model.
De novo generation is equivalent to not having any prefix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples_per_trial
|
int
|
number of new molecules to generate |
10
|
sanitize
|
bool
|
whether to perform sanitization, aka, perform control to ensure what is asked is what is returned |
False
|
n_trials
|
Optional[int]
|
number of randomization to perform |
None
|
kwargs
|
Optional[Dict[Any, Any]]
|
any argument to provide to the underlying generation function |
{}
|
Source code in safe/sample.py
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 757 758 759 760 761 762 763 |
|
linker_generation(*groups, n_samples_per_trial=10, n_trials=1, sanitize=False, do_not_fragment_further=True, random_seed=None, model_only=False, **kwargs)
¶
Perform linker generation using the pretrained SAFE model. Linker generation is really just scaffold morphing underlying.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
groups
|
Union[str, Mol]
|
list of fragments to link together, they are joined in the order provided |
()
|
n_samples_per_trial
|
int
|
number of new molecules to generate for each randomization |
10
|
n_trials
|
Optional[int]
|
number of randomization to perform |
1
|
do_not_fragment_further
|
Optional[bool]
|
whether to fragment the scaffold further or not |
True
|
sanitize
|
bool
|
whether to sanitize the generated molecules |
False
|
random_seed
|
Optional[int]
|
random seed to use |
None
|
model_only
|
Optional[bool]
|
whether to use the model only ability and nothing more. |
False
|
kwargs
|
Optional[Dict[Any, Any]]
|
any argument to provide to the underlying generation function |
{}
|
Source code in safe/sample.py
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 |
|
load_default(model_dir=None, device=None, verbose=False, **kwargs)
classmethod
¶
Load default SAFEGenerator model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verbose
|
bool
|
whether to print out logging information during generation |
False
|
model_dir
|
Optional[str]
|
Optional path to model folder to use instead of the default one.
If provided the tokenizer should be in the model_dir named as |
None
|
device
|
str
|
optional device where to move the model |
None
|
kwargs
|
Any
|
any additional argument to pass to the init function |
{}
|
Source code in safe/sample.py
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 |
|
load_from_wandb(artifact_path, device=None, verbose=True, **kwargs)
classmethod
¶
Load SAFE model and tokenizer from a Weights and Biases (wandb) artifact. By default, the model will be downloaded into SAFE_MODEL_ROOT.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifact_path
|
str
|
The path to the wandb artifact in the format |
required |
device
|
Optional[str]
|
The device where the model should be loaded ('cpu' or 'cuda'). If None, it defaults to the available device. |
None
|
verbose
|
bool
|
Whether to print out logging information during generation. |
True
|
Returns:
Name | Type | Description |
---|---|---|
SAFEDesign |
SAFEDesign
|
An instance of SAFEDesign class with the model, tokenizer, and generation config loaded from wandb. |
Source code in safe/sample.py
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 |
|
motif_extension(motif, n_samples_per_trial=10, n_trials=1, sanitize=False, do_not_fragment_further=True, random_seed=None, **kwargs)
¶
Perform motif extension using the pretrained SAFE model. Motif extension is really just scaffold decoration underlying.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
motif
|
Union[str, Mol]
|
scaffold (with attachment points) to decorate |
required |
n_samples_per_trial
|
int
|
number of new molecules to generate for each randomization |
10
|
n_trials
|
Optional[int]
|
number of randomization to perform |
1
|
do_not_fragment_further
|
Optional[bool]
|
whether to fragment the scaffold further or not |
True
|
sanitize
|
bool
|
whether to sanitize the generated molecules and check |
False
|
random_seed
|
Optional[int]
|
random seed to use |
None
|
kwargs
|
Optional[Dict[Any, Any]]
|
any argument to provide to the underlying generation function |
{}
|
Source code in safe/sample.py
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 522 523 524 525 526 |
|
pattern_decoration(scaffold, n_samples_per_trial=10, n_trials=1, do_not_fragment_further=True, sanitize=False, random_seed=None, add_dot=True, n_scaff_random=3, n_scaff_samples=10, scaff_temperature=1.0, **kwargs)
¶
Perform pattern decoration using the pretrained SAFE model. The pattern decoration algorithm works by first examplifying the patterns as a set of scaffold then performing scaffold decoration on each scaffold.
Warning
Designing molecules from a given molecule pattern is more challenging than fragment-constrained design. SAFE does not currently support complex SMARTS pattern schemes (e.g., valence or connectivity constraints, some ring constraints). This function works best when sampling given a list of atoms. However, sampling depends on the model's conditional probabilities, meaning that if the model assigns zero probability to a token, you are unlikely to see it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scaffold
|
Union[str, Mol]
|
Scaffold (with attachment points) to decorate. |
required |
n_samples_per_trial
|
int
|
Number of new molecules to generate for each randomization. |
10
|
n_trials
|
int
|
Number of randomizations to perform. |
1
|
do_not_fragment_further
|
bool
|
Whether to prevent further fragmentation of the scaffold. |
True
|
sanitize
|
bool
|
Whether to sanitize the generated molecules and ensure the scaffold is present. |
False
|
random_seed
|
Optional[int]
|
Seed for randomization. |
None
|
n_scaff_random
|
Optional[int]
|
Number of scaffold randomizations to try (to reposition constraints in the string and increase rollout likelihood). Increasing this will improve sampling, but will require more time. |
3
|
n_scaff_samples
|
Optional[int]
|
Maximum number of samples to sample for a given scaffold from the pattern. Increasing this will make sure you have more diversity in the scaffold coming from the pattern |
10
|
scaff_temperature
|
float
|
Temperature to use when sampling valid scaffolds from the pattern. Higher temperature means more diverse scaffold |
1.0
|
kwargs
|
Optional[Dict[Any, Any]]
|
Additional arguments for the underlying generation function. |
{}
|
Returns:
Type | Description |
---|---|
List[str]
|
List of decorated molecule sequences. |
Source code in safe/sample.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 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 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
scaffold_decoration(scaffold, n_samples_per_trial=10, n_trials=1, do_not_fragment_further=True, sanitize=False, random_seed=None, add_dot=True, **kwargs)
¶
Perform scaffold decoration using the pretrained SAFE model
For scaffold decoration, we basically starts with a prefix with the attachment point. We first convert the prefix into valid safe string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scaffold
|
Union[str, Mol]
|
scaffold (with attachment points) to decorate |
required |
n_samples_per_trial
|
int
|
number of new molecules to generate for each randomization |
10
|
n_trials
|
Optional[int]
|
number of randomization to perform |
1
|
do_not_fragment_further
|
Optional[bool]
|
whether to fragment the scaffold further or not |
True
|
sanitize
|
bool
|
whether to sanitize the generated molecules and check if the scaffold is still present |
False
|
random_seed
|
Optional[int]
|
random seed to use |
None
|
kwargs
|
Optional[Dict[Any, Any]]
|
any argument to provide to the underlying generation function |
{}
|
Source code in safe/sample.py
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 630 631 632 633 634 635 636 637 638 |
|
scaffold_morphing(side_chains=None, mol=None, core=None, n_samples_per_trial=10, n_trials=1, sanitize=False, do_not_fragment_further=True, random_seed=None, **kwargs)
¶
Perform scaffold morphing decoration using the pretrained SAFE model
For scaffold morphing, we try to replace the core by a new one. If the side_chains are provided, we use them. If a combination of molecule and core is provided, then, we use them to extract the side chains and performing the scaffold morphing then.
Finding the side chains
The algorithm to find the side chains from core assumes that the core we get as input has attachment points. Those attachment points are never considered as part of the query, rather they are used to define the attachment points. See ~sf.utils.compute_side_chains for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
side_chains
|
Optional[Union[Mol, str, List[Union[str, Mol]]]]
|
side chains to use to perform scaffold morphing (joining as best as possible the set of fragments) |
None
|
mol
|
Optional[Union[Mol, str]]
|
input molecules when side_chains are not provided |
None
|
core
|
Optional[Union[Mol, str]]
|
core to morph into another scaffold |
None
|
n_samples_per_trial
|
int
|
number of new molecules to generate for each randomization |
10
|
n_trials
|
Optional[int]
|
number of randomization to perform |
1
|
do_not_fragment_further
|
Optional[bool]
|
whether to fragment the scaffold further or not |
True
|
sanitize
|
bool
|
whether to sanitize the generated molecules |
False
|
random_seed
|
Optional[int]
|
random seed to use |
None
|
kwargs
|
Optional[Dict[Any, Any]]
|
any argument to provide to the underlying generation function |
{}
|
Source code in safe/sample.py
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 |
|
super_structure(core, n_samples_per_trial=10, n_trials=1, sanitize=False, do_not_fragment_further=True, random_seed=None, attachment_point_depth=None, **kwargs)
¶
Perform super structure generation using the pretrained SAFE model.
To generate super-structure, we basically just create various attachment points to the input core, then perform scaffold decoration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
core
|
Union[str, Mol]
|
input substructure to use. We aim to generate super structures of this molecule |
required |
n_samples_per_trial
|
int
|
number of new molecules to generate for each randomization |
10
|
n_trials
|
Optional[int]
|
number of different attachment points to consider |
1
|
do_not_fragment_further
|
Optional[bool]
|
whether to fragment the scaffold further or not |
True
|
sanitize
|
bool
|
whether to sanitize the generated molecules |
False
|
random_seed
|
Optional[int]
|
random seed to use |
None
|
attachment_point_depth
|
Optional[int]
|
depth of opening the attachment points. Increasing this, means you increase the number of substitution point to consider. |
None
|
kwargs
|
Optional[Dict[Any, Any]]
|
any argument to provide to the underlying generation function |
{}
|
Source code in safe/sample.py
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 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
SAFE Tokenizer¶
SAFESplitter
¶
Standard Splitter for SAFE string
Source code in safe/tokenizer.py
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 |
|
detokenize(chars)
¶
Detokenize SAFE notation
Source code in safe/tokenizer.py
75 76 77 78 79 |
|
pre_tokenize(pretok)
¶
Pretokenize using an input pretokenizer object from the tokenizer library
Source code in safe/tokenizer.py
85 86 87 |
|
split(n, normalized)
¶
Perform splitting for pretokenization
Source code in safe/tokenizer.py
81 82 83 |
|
tokenize(line)
¶
Tokenize a safe string into characters.
Source code in safe/tokenizer.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
SAFETokenizer
¶
Bases: PushToHubMixin
Class to initialize and train a tokenizer for SAFE string Once trained, you can use the converted version of the tokenizer to an HuggingFace PreTrainedTokenizerFast
Source code in safe/tokenizer.py
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 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 350 351 352 353 354 355 356 357 358 359 360 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 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 492 493 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 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 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 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
bos_token_id
property
¶
Get the bos token id
cls_token_id
property
¶
Get the cls token id
eos_token_id
property
¶
Get the eos token id
mask_token_id
property
¶
Get the mask token id
pad_token_id
property
¶
Get the pad token id
sep_token_id
property
¶
Get the sep token id
unk_token_id
property
¶
Get the unk token id
__getstate__()
¶
Getting state to allow pickling
Source code in safe/tokenizer.py
215 216 217 218 219 220 221 222 |
|
__len__()
¶
Gets the count of tokens in vocab along with special tokens.
Source code in safe/tokenizer.py
246 247 248 249 250 |
|
__setstate__(d)
¶
Setting state during reloading pickling
Source code in safe/tokenizer.py
224 225 226 227 228 229 230 |
|
decode(ids, skip_special_tokens=True, ignore_stops=False, stop_token_ids=None)
¶
Decodes a list of ids to molecular representation in the format in which this tokenizer was created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
list
|
list of IDs |
required |
skip_special_tokens
|
bool
|
whether to skip all special tokens when encountering them |
True
|
ignore_stops
|
bool
|
whether to ignore the stop tokens, thus decoding till the end |
False
|
stop_token_ids
|
Optional[List[int]]
|
optional list of stop token ids to use |
None
|
Returns:
Name | Type | Description |
---|---|---|
sequence |
str
|
str representation of molecule |
Source code in safe/tokenizer.py
334 335 336 337 338 339 340 341 342 343 344 345 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 374 375 376 377 378 379 380 381 382 383 |
|
encode(sample_str, ids_only=True, **kwargs)
¶
Encodes a given molecule string once training is done
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_str
|
str
|
Sample string to encode molecule |
required |
ids_only
|
bool
|
whether to return only the ids or the encoding objet |
True
|
Returns:
Name | Type | Description |
---|---|---|
object |
list
|
Returns encoded list of IDs |
Source code in safe/tokenizer.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
from_dict(data)
classmethod
¶
Load tokenizer from dict
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
dictionary containing the tokenizer info |
required |
Source code in safe/tokenizer.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
from_pretrained(pretrained_model_name_or_path, cache_dir=None, force_download=False, local_files_only=False, token=None, return_fast_tokenizer=False, proxies=None, **kwargs)
classmethod
¶
Instantiate a [~tokenization_utils_base.PreTrainedTokenizerBase
] (or a derived class) from a predefined
tokenizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretrained_model_name_or_path
|
Union[str, PathLike]
|
Can be either:
|
required |
cache_dir
|
Optional[Union[str, PathLike]]
|
Path to a directory in which a downloaded predefined tokenizer vocabulary files should be cached if the standard cache should not be used. |
None
|
force_download
|
bool
|
Whether or not to force the (re-)download the vocabulary files and override the cached versions if they exist. |
False
|
proxies
|
Optional[Dict[str, str]]
|
A dictionary of proxy servers to use by protocol or endpoint, e.g.,
|
None
|
token
|
Optional[Union[str, bool]]
|
The token to use as HTTP bearer authorization for remote files.
If |
None
|
local_files_only
|
bool
|
Whether or not to only rely on local files and not to attempt to download any files. |
False
|
return_fast_tokenizer
|
Optional[bool]
|
Whether to return fast tokenizer or not. |
False
|
Examples:
# We can't instantiate directly the base class *PreTrainedTokenizerBase* so let's show our examples on a derived class: BertTokenizer
# Download vocabulary from huggingface.co and cache.
tokenizer = SAFETokenizer.from_pretrained("datamol-io/safe-gpt")
# If vocabulary files are in a directory (e.g. tokenizer was saved using *save_pretrained('./test/saved_model/')*)
tokenizer = SAFETokenizer.from_pretrained("./test/saved_model/")
# If the tokenizer uses a single vocabulary file, you can point directly to this file
tokenizer = BertTokenizer.from_pretrained("./test/saved_model/tokenizer.json")
Source code in safe/tokenizer.py
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 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 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
get_pretrained(**kwargs)
¶
Get a pretrained tokenizer from this tokenizer
Returns:
Type | Description |
---|---|
PreTrainedTokenizerFast
|
Returns pre-trained fast tokenizer for hugging face models. |
Source code in safe/tokenizer.py
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 |
|
load(file_name)
classmethod
¶
Load the current tokenizer from file
Source code in safe/tokenizer.py
324 325 326 327 328 329 330 331 332 |
|
push_to_hub(repo_id, use_temp_dir=None, commit_message=None, private=None, token=None, max_shard_size='10GB', create_pr=False, safe_serialization=False, **deprecated_kwargs)
¶
Upload the tokenizer to the 🤗 Model Hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id
|
str
|
The name of the repository you want to push your {object} to. It should contain your organization name when pushing to a given organization. |
required |
use_temp_dir
|
Optional[bool]
|
Whether or not to use a temporary directory to store the files saved before they are pushed to the Hub.
Will default to |
None
|
commit_message
|
Optional[str]
|
Message to commit while pushing. Will default to |
None
|
private
|
Optional[bool]
|
Whether or not the repository created should be private. |
None
|
token
|
Optional[Union[bool, str]]
|
The token to use as HTTP bearer authorization for remote files. If |
None
|
max_shard_size
|
Optional[Union[int, str]]
|
Only applicable for models. The maximum size for a checkpoint before being sharded. Checkpoints shard
will then be each of size lower than this size. If expressed as a string, needs to be digits followed
by a unit (like |
'10GB'
|
create_pr
|
bool
|
Whether or not to create a PR with the uploaded files or directly commit. |
False
|
safe_serialization
|
bool
|
Whether or not to convert the model weights in safetensors format for safer serialization. |
False
|
Source code in safe/tokenizer.py
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 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
save(file_name=None)
¶
Saves the :class:~tokenizers.Tokenizer
to the file at the given path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
File where to save tokenizer |
None
|
Source code in safe/tokenizer.py
292 293 294 295 296 297 298 299 300 301 302 303 |
|
save_pretrained(*args, **kwargs)
¶
Save pretrained tokenizer
Source code in safe/tokenizer.py
288 289 290 |
|
set_special_tokens(tokenizer, bos_token=CLS_TOKEN, eos_token=SEP_TOKEN)
classmethod
¶
Set special tokens for a tokenizer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenizer
|
Tokenizer
|
tokenizer for which special tokens will be set |
required |
bos_token
|
str
|
Optional bos token to use |
CLS_TOKEN
|
eos_token
|
str
|
Optional eos token to use |
SEP_TOKEN
|
Source code in safe/tokenizer.py
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 |
|
to_dict(**kwargs)
¶
Convert tokenizer to dict
Source code in safe/tokenizer.py
274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
train(files, **kwargs)
¶
This is to train a new tokenizer from either a list of file or some input data
Args
files (str): file in which your molecules are separated by new line
kwargs (dict): optional args for the tokenizer train
Source code in safe/tokenizer.py
203 204 205 206 207 208 209 210 211 212 213 |
|
train_from_iterator(data, **kwargs)
¶
Train the Tokenizer using the provided iterator.
You can provide anything that is a Python Iterator
* A list of sequences :obj:List[str]
* A generator that yields :obj:str
or :obj:List[str]
* A Numpy array of strings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Iterator
|
data iterator |
required |
**kwargs
|
Any
|
additional keyword argument for the tokenizer |
{}
|
Source code in safe/tokenizer.py
232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
Utils¶
MolSlicer
¶
Slice a molecule into head-linker-tail
Source code in safe/utils.py
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 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 |
|
__call__(mol, expected_head=None)
¶
Perform slicing of the input molecule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Union[Mol, str]
|
input molecule |
required |
expected_head
|
Union[Mol, str]
|
substructure that should be part of the head. The small fragment containing this substructure would be kept as head |
None
|
Source code in safe/utils.py
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 |
|
__init__(shortest_linker=False, min_linker_size=0, require_ring_system=True, verbose=False)
¶
Constructor of bond slicer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shortest_linker
|
bool
|
whether to consider longuest or shortest linker. Does not have any effect when expected_head group is provided during splitting |
False
|
min_linker_size
|
int
|
minimum linker size |
0
|
require_ring_system
|
bool
|
whether all fragment needs to have a ring system |
True
|
verbose
|
bool
|
whether to allow verbosity in logging |
False
|
Source code in safe/utils.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
get_ring_system(mol)
¶
Get the list of ring system from a molecule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
input molecule for which we are computing the ring system |
required |
Source code in safe/utils.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
link_fragments(linker, head, tail)
classmethod
¶
Link fragments together using the provided linker
Parameters:
Name | Type | Description | Default |
---|---|---|---|
linker
|
Union[Mol, str]
|
linker to use |
required |
head
|
Union[Mol, str]
|
head fragment |
required |
tail
|
Union[Mol, str]
|
tail fragment |
required |
Source code in safe/utils.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
attr_as(obj, field, value)
¶
Temporary replace the value of an object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
object to temporary patch |
required |
field
|
str
|
name of the key to change |
required |
value
|
Any
|
value of key to be temporary changed |
required |
Source code in safe/utils.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
compute_side_chains(mol, core, label_by_index=False)
¶
Compute the side chain of a molecule given a core
Finding the side chains
The algorithm to find the side chains from core assumes that the core we get as input has attachment points. Those attachment points are never considered as part of the query, rather they are used to define the attachment points on the side chains. Removing the attachment points from the core is exactly the same as keeping them.
mol = "CC1=C(C(=NO1)C2=CC=CC=C2Cl)C(=O)NC3C4N(C3=O)C(C(S4)(C)C)C(=O)O"
core0 = "CC1(C)CN2C(CC2=O)S1"
core1 = "CC1(C)SC2C(-*)C(=O)N2C1-*"
core2 = "CC1N2C(SC1(C)C)C(N)C2=O"
side_chain = compute_side_chain(core=core0, mol=mol)
dm.to_image([side_chain, core0, mol])
mol
, but core2 is not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
molecule to split |
required |
core
|
Mol
|
core to use for deriving the side chains |
required |
Source code in safe/utils.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
convert_to_safe(mol, canonical=False, randomize=False, seed=1, slicer='brics', split_fragment=True, fraction_hs=None, resolution=0.5)
¶
Convert a molecule to a safe representation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
molecule to convert |
required |
canonical
|
bool
|
whether to use canonical encoding |
False
|
randomize
|
bool
|
whether to randomize the encoding |
False
|
seed
|
Optional[int]
|
random seed |
1
|
slicer
|
str
|
the slicer to use for fragmentation |
'brics'
|
split_fragment
|
bool
|
whether to split fragments |
True
|
fraction_hs
|
bool
|
proportion of random atom to which we will add explicit hydrogens |
None
|
resolution
|
Optional[float]
|
resolution for the partitioning algorithm |
0.5
|
seed
|
Optional[int]
|
random seed |
1
|
Source code in safe/utils.py
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 |
|
filter_by_substructure_constraints(sequences, substruct, n_jobs=-1)
¶
Check whether the input substructures are present in each of the molecule in the sequences
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequences
|
List[Union[str, Mol]]
|
list of molecules to validate |
required |
substruct
|
Union[str, Mol]
|
substructure to use as query |
required |
n_jobs
|
int
|
number of jobs to use for parallelization |
-1
|
Source code in safe/utils.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
find_partition_edges(G, partition)
¶
Find the edges connecting the subgraphs in a given partition of a graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
G
|
Graph
|
The original graph. |
required |
partition
|
list of list of nodes
|
The partition of the graph where each element is a list of nodes representing a subgraph. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
List[Tuple]
|
A list of edges connecting the subgraphs in the partition. |
Source code in safe/utils.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
fragment_aware_spliting(mol, fraction_hs=None, **kwargs)
¶
Custom splitting algorithm for dataset building.
This slicing strategy will cut any bond including bonding with hydrogens However, only one cut per atom is allowed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
molecule to split |
required |
fraction_hs
|
Optional[bool]
|
proportion of random atom to which we will add explicit hydrogens |
None
|
kwargs
|
Any
|
additional arguments to pass to the partitioning algorithm |
{}
|
Source code in safe/utils.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
list_individual_attach_points(mol, depth=None)
¶
List all individual attachement points.
We do not allow multiple attachment points per substitution position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
molecule for which we need to open the attachment points |
required |
Source code in safe/utils.py
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 |
|
mol_partition(mol, query=None, seed=None, **kwargs)
¶
Partition a molecule into fragments using a bond query
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
Mol
|
molecule to split |
required |
query
|
Optional[Mol]
|
bond query to use for splitting |
None
|
seed
|
Optional[int]
|
random seed |
None
|
kwargs
|
Any
|
additional arguments to pass to the partitioning algorithm |
{}
|
Source code in safe/utils.py
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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
standardize_attach(inputs, standard_attach='[*]')
¶
Standardize the attachment points of a molecule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
str
|
input molecule |
required |
standard_attach
|
str
|
standard attachment point to use |
'[*]'
|
Source code in safe/utils.py
571 572 573 574 575 576 577 578 579 580 581 |
|