Functionalise & docking¶
Fragment attachment and host-guest docking utilities:
cage_isomer_builder.utils.functionalise.
Attaching fragments at R sites and docking guests into a host.
max_guests_in_host ¶
max_guests_in_host(host, guests, ratios=None, max_attempts=1000, overlap_tolerance=0.75, inner_radius_fraction=0.9, seed=None)
Number of guest copies that fit in the host's cavity at once, from a Random
Sequential Adsorption packing (see _build_guest_packing) with the same
overlap test as :func:place_guest_in_host. The result depends on seed
and max_attempts; it is not a guaranteed maximum.
Before any placement, each guest is checked against the host's largest
window (:func:cage_isomer_builder.utils.cavity.largest_window); a guest
wider than every opening raises at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
Atoms
|
|
required |
guests
|
ase.Atoms or sequence of ase.Atoms
|
One guest type, or several to mix. |
required |
ratios
|
sequence of float
|
Relative share of each guest type (several guest types only). Default: equal shares. |
None
|
max_attempts
|
int
|
Consecutive failed placements after which the packing counts as jammed. |
1000
|
overlap_tolerance
|
float
|
Closest allowed approach of two atoms (host-guest or guest-guest) as a fraction of the sum of their van der Waals radii: 2.55 A for C...C and 1.8 A for H...H at 0.75. 1.0 means van der Waals spheres may not overlap. |
0.75
|
inner_radius_fraction
|
float
|
Fraction of the cavity radius in which guest centres are placed, a small
margin from the wall (contacts are already limited by
|
0.9
|
seed
|
int
|
Seed for a reproducible result. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The number of guest copies placed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a guest's narrowest cross-section is wider than the host's largest window (not raised for a closed host), or the host or a guest contains R-site markers. |
Examples:
>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
... linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None) # the UiO-66 tetrahedral cage
>>> host, methane = cage.to_ase(), example_data.read("methane")
>>> from cage_isomer_builder.utils.functionalise import max_guests_in_host
>>> max_guests_in_host(host, methane, seed=0) # in its 7.5 A cavity
4
>>> max_guests_in_host(host, example_data.read("ibuprofen")) # wider than every window
Traceback (most recent call last):
...
ValueError: guests[0]'s narrowest cross-section (5.83 A) is larger than the host's largest window (4.30 A), so it cannot enter the cavity in any orientation.
Source code in cage_isomer_builder/utils/functionalise.py
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 | |
place_guest_in_host ¶
place_guest_in_host(host, guests, n_complexes=1, n_guests=1, ratios=None, max_attempts=1000, overlap_tolerance=0.75, inner_radius_fraction=0.9, host_bond_matrix=None, seed=None, method='rsa', n_samples=1000, contact_scale=0.75, dispersion='auto')
Build n_complexes host-guest complexes.
Two placement methods:
method="rsa"(default): random placement wherever the guests fit.method="energy": each guest at its lowest-energy site, scored with dispersion (see "Energy method").
Strategy (RSA)
- The docking sphere is the largest sphere inside the host
(:func:
cage_isomer_builder.utils.cavity.pore_sphere), or a mean-atom-distance sphere when the host has no enclosed cavity. - A guest wider than the host's largest window
(:func:
cage_isomer_builder.utils.cavity.largest_window) is refused before any placement. - One Random Sequential Adsorption packing of the cavity is built (see _build_guest_packing); any subset of it is a valid placement.
- Each complex takes a different random subset of
n_guestscopies.n_guestsis capped to the packing size, andn_complexesto the number of distinct subsets, each with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
Atoms
|
The cage. |
required |
guests
|
ase.Atoms or sequence of ase.Atoms
|
One guest type, or several to mix (the type of each copy is chosen by a ratio-weighted round robin). |
required |
n_complexes
|
int
|
Number of complexes. |
1
|
n_guests
|
int
|
Guest copies per complex, capped to what fits. |
1
|
ratios
|
sequence of float
|
Relative share of each guest type. Default: equal shares. |
None
|
max_attempts
|
int
|
Consecutive failed placements after which the RSA packing counts as jammed. |
1000
|
overlap_tolerance
|
float
|
Closest allowed approach of two atoms as a fraction of the sum of their van der Waals radii (RSA). |
0.75
|
inner_radius_fraction
|
float
|
Fraction of the cavity radius in which guest centres are placed. Smaller values shrink the usable cavity. |
0.9
|
host_bond_matrix
|
(ndarray, shape(len(host), len(host)))
|
The host's bond orders, e.g. from |
None
|
seed
|
int
|
Seed for the packing, the subsets and the energy search. |
None
|
method
|
(rsa, energy)
|
|
"rsa"
|
n_samples
|
int
|
Energy method: random positions tried per guest, each in 24 orientations. |
1000
|
contact_scale
|
float
|
Energy method: closest allowed approach of two atoms as a fraction of the sum of their van der Waals radii. Both scoring models have their own repulsion, which normally keeps atoms further apart than this. |
0.75
|
dispersion
|
str or dict
|
Energy method scoring: |
"auto"
|
Energy method
- The C6 coefficients of the host and each guest type are computed once with dftd4 (UFF: per-element parameters).
- For each guest,
n_samplesrandom positions in the docking sphere are scored in 24 orientations each; the best pose of each of 30 sites is minimised as a rigid body (L-BFGS). - Complex
cputs its first guest at thec-th best site; each further guest goes to the lowest-energy site left, so guest-guest dispersion counts too. - Each complex is rescored (D4: a full dftd4 calculation with the
three-body term, plus the UFF repulsion). The energy (eV) is stored in
complex.atoms.info["interaction_energy"]and the model incomplex.atoms.info["dispersion_model"]. Complexes are returned lowest energy first; with fewer sites thann_complexes, the result is capped with a warning.
Returns:
| Type | Description |
|---|---|
list of HostGuestComplex
|
Named tuples |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a guest is wider than the host's largest window, the host or a guest
contains R-site markers, or |
Examples:
>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
... linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None) # the UiO-66 tetrahedral cage
>>> host, methane = cage.to_ase(), example_data.read("methane")
>>> from cage_isomer_builder.utils.functionalise import place_guest_in_host
>>> complexes = place_guest_in_host(host, methane, n_guests=2, n_complexes=2, seed=0,
... host_bond_matrix=cage.get_bond_matrix())
>>> len(complexes), len(complexes[0].guest_labels), len(complexes[0].atoms) - len(host)
(2, 2, 10)
>>> best = place_guest_in_host(host, methane, method="energy", n_samples=200, seed=0)[0]
>>> best.atoms.info["dispersion_model"], bool(best.atoms.info["interaction_energy"] < 0)
('D4(pbe)+UFF repulsion', True)
Source code in cage_isomer_builder/utils/functionalise.py
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 | |
functionalise_host ¶
functionalise_host(host_system, sub_fragment, bond_length=1.5, host_marker='X', fragment_marker='X', guests=None, n_complexes=1, n_guests=1, ratios=None, max_attempts=1000, overlap_tolerance=0.75, inner_radius_fraction=0.9, seed=None)
Attach a fragment at the single site of a host and, optionally, dock guests
in the result (see :func:place_guest_in_host).
The fragment is aligned to the host's site, moved so that its bonding atom sits on the site, and merged into the host; both marker atoms are removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host_system
|
Atoms
|
Host with one site atom. |
required |
sub_fragment
|
Atoms
|
Fragment with one marker atom at its bonding end. |
required |
bond_length
|
float
|
Length (Angstrom) of the new host-fragment bond. |
1.5
|
host_marker
|
str
|
Symbol of the site atom in the host ( |
'X'
|
fragment_marker
|
str
|
Symbol of the marker atom in the fragment. |
'X'
|
guests
|
ase.Atoms or sequence of ase.Atoms
|
Guests to dock. |
None
|
n_complexes
|
As for :func: |
1
|
|
n_guests
|
As for :func: |
1
|
|
ratios
|
As for :func: |
1
|
|
max_attempts
|
As for :func: |
1
|
|
overlap_tolerance
|
As for :func: |
1
|
|
inner_radius_fraction
|
As for :func: |
1
|
|
seed
|
As for :func: |
1
|
Returns:
| Type | Description |
|---|---|
ase.Atoms, HostGuestComplex or list of HostGuestComplex
|
The functionalised host if |
Notes
With guests, the bond matrix of each complex is perceived from the
functionalised host's geometry. To use exact bonds, attach the fragment and
call :func:place_guest_in_host with host_bond_matrix yourself.
Examples:
>>> from ase.build import molecule
>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.utils.functionalise import functionalise_host
>>> host = molecule("C6H6")
>>> host[6].symbol = "X" # one site, on C 0
>>> aniline = functionalise_host(host, example_data.read("NH2"))
>>> aniline.get_chemical_formula()
'C6H7N'
Source code in cage_isomer_builder/utils/functionalise.py
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 | |
functionalise_isomer_sites ¶
functionalise_isomer_sites(host_system, fragments, ratios=None, site_marker='X', fragment_marker='X', bond_length=1.5, seed=None, host_bond_matrix=None)
Attach real functional-group fragments at every site of an isomer, optionally mixing several fragment types by ratio.
Sites are R sites (X atoms with a non-zero "rgroup" value, see
:mod:cage_isomer_builder.utils.sites) or, for a structure without that
array, atoms of symbol site_marker. Each fragment carries one marker
atom fragment_marker at its bonding end (e.g. Atoms('XNHH', ...) for
NH2). This is the multi-site version of :func:functionalise_host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host_system
|
Atoms
|
The isomer. |
required |
fragments
|
ase.Atoms, sequence of ase.Atoms, or dict
|
One fragment for every site, or several to mix. For an R-group isomer
(written by |
required |
ratios
|
sequence of float
|
Relative number of sites for each fragment (several fragments only). The
counts add up to the number of sites (largest-remainder method); which
site gets which fragment is random (see |
None
|
site_marker
|
str
|
Symbol of a site atom in |
'X'
|
fragment_marker
|
str
|
Symbol of the marker atom in each fragment. |
'X'
|
bond_length
|
float
|
Length (Angstrom) of each new host-fragment bond. |
1.5
|
seed
|
int
|
Seed for the random assignment of fragments to sites. |
None
|
host_bond_matrix
|
(ndarray, shape(len(host_system), len(host_system)))
|
The host's bond orders. When given, the bonds of the decorated structure are tracked too (each fragment's bonds and the new bond at each site), as needed for a force-field run on the new groups only. |
None
|
Returns:
| Type | Description |
|---|---|
Atoms or FunctionalisedIsomer
|
The decorated structure, or, with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from ase.build import molecule
>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.utils.sites import mark_site
>>> from cage_isomer_builder.utils.functionalise import functionalise_isomer_sites
>>> isomer = molecule("C6H6")
>>> mark_site(isomer, 6, 1) # R1 on C 0
>>> mark_site(isomer, 9, 1) # R1 on C 3
>>> isomer.info["rgroup_labels"] = "NH2"
>>> decorated = functionalise_isomer_sites(isomer, {"NH2": example_data.read("NH2")})
>>> decorated.get_chemical_formula() # p-phenylenediamine
'C6H8N2'
Source code in cage_isomer_builder/utils/functionalise.py
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 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
full_functionalisation ¶
Mark every aromatic C-H of the linkers as an R site.
Each H bonded to an aromatic linker carbon becomes a site atom (an X
with "rgroup" = 1, i.e. R1, see :mod:cage_isomer_builder.utils.sites),
moved out along the C-H direction to 1.47 Angstrom (about a C-N bond) so
that a fragment attached there starts at a sensible bond length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cage
|
Atoms
|
The structure. Changed in place. |
required |
linker_indices
|
sequence of int
|
Atoms of the linkers; only their C-H bonds become sites. |
required |
aromatic_only
|
bool
|
Only H on aromatic-ring carbons (planar 5- or 6-membered rings, see
:func: |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
fg_anchors |
Atoms
|
The site atoms, in slot order. |
fg_anchor_indices |
list of int
|
Index of each site atom in |
fg_anchor_h_positions |
(ndarray, shape(n_sites, 3))
|
Each site's original H position, so an inactive site can be turned back into H. |
Examples:
>>> from ase.build import molecule
>>> from cage_isomer_builder.utils.functionalise import full_functionalisation
>>> benzene = molecule("C6H6")
>>> sites, indices, h_positions = full_functionalisation(benzene, list(range(12)))
>>> len(indices), benzene.get_chemical_symbols()[6:] # every aromatic C-H is a site
(6, ['X', 'X', 'X', 'X', 'X', 'X'])
Source code in cage_isomer_builder/utils/functionalise.py
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 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 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |