class_pi_stacking.py
Computation is based on next formula:
\[
\phi_{\pi \text{ st}} = -\displaystyle\sum_{r = 1}^R \exp\left[-\dfrac{(\pmb{v}_r - \pmb{\mu}_{\pi \text{ st}})^T \pmb{S}_{\pi \text{ st}}^{-1} (\pmb{v}_r - \pmb{\mu}_{\pi \text{ st}})}{2} \right]
\]
With \(\phi_{\pi \text{ st}}\) the field in a 3D space, \(R\) the selected ring, and where:
\[
\pmb{v}_r = \begin{bmatrix} \alpha_r \\ d_r \end{bmatrix} \quad \& \quad
\pmb{\mu}_{\pi \text{ st}} = \begin{bmatrix} \alpha_0 \\ d_0 \end{bmatrix}
= \begin{bmatrix} 29.98~^\circ \\ 4.19~\text{Å} \end{bmatrix}
\]
\[
\& \quad \pmb{S}_{\pi \text{ st}} = \begin{bmatrix} \sigma^2 \left(\alpha \right) & \sigma \left( \alpha, d \right) \\ \sigma \left( d, \alpha \right) & \sigma^2 \left( d \right) \end{bmatrix}
= \begin{bmatrix} 169.99~(^\circ)^2 & 6.62~^\circ \cdot \text{Å} \\ 6.62~^\circ \cdot \text{Å} & 0.37~\text{Å}^2 \end{bmatrix}
\]
With \(\pmb{v}_r\) the matrix with the actual computed distance (any position to the ring center of geometry) and angle (between the normal vector of the ring plan and a vector from the ring center of geometry to any position), \(\pmb{\mu}_{\pi \text{ st}}\) the optimal distance and angle, \(\pmb{S}_{\pi \text{ st}}\) a matrix with variances.
Contains a class with strategy to fill a grid with pi stacking properties.
StrategyPiStacking
Bases: StrategyProperty
A class for defining strategies to fill a grid with pi stacking
properties.
Inheritance
This class is the child of StrategyProperty. Check this one for other
attributes and methods definitions.
Source code in src/smiffer/grid/property_strategy/class_pi_stacking.py
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 | class StrategyPiStacking(StrategyProperty):
"""A class for defining strategies to fill a grid with pi stacking
properties.
Inheritance
-----------
This class is the child of `StrategyProperty`. Check this one for other
**attributes** and **methods** definitions.
"""
def populate_grid(self, grid: np.ndarray, grid_object) -> None:
"""Populate a grid following H-bond properties.
Parameters
----------
grid : `np.ndarray`
The grid to fill.
grid_object : `Grid`
The grid object to access all attributes.
"""
radius: float = (
grid_object.yaml["function_pi_stacking_mu"][1]
+ grid_object.yaml["function_pi_stacking_sigma"][1][1] ** (1 / 2)
* grid_object.yaml["other_gaussian_kernel_scalar"]
)
pi_stacking_kernel: BivariateGaussianKernel = BivariateGaussianKernel(
radius=radius,
delta=grid_object.delta,
v_mu=np.array(grid_object.yaml["function_pi_stacking_mu"]),
# Pre-inversing the matrix.
v_sigma=np.linalg.inv(
grid_object.yaml["function_pi_stacking_sigma"]
),
is_stacking=True,
)
stamp: Stamp = Stamp(
grid=grid,
grid_origin=grid_object.coord[0],
delta=grid_object.delta,
kernel=pi_stacking_kernel,
)
parsed_residue: dict = {}
for atom in grid_object.molecule:
if atom.resname not in self._atom_constant["aromatic"]:
continue
# In order to not check multiple time the same residue.
if atom.resname not in parsed_residue:
parsed_residue[atom.resname] = []
atom_id: tuple = (atom.resid, atom.chainID)
# Skip if already parsed.
if atom_id in parsed_residue[atom.resname]:
continue
parsed_residue[atom.resname] += [atom_id]
select: str = (
f"resid {atom.resid} "
f"and name {self._atom_constant['aromatic'][atom.resname]}"
)
if atom.chainID is not None:
select += f" and chainID {atom.chainID}"
res_atom = grid_object.molecule.select_atoms(select)
if len(res_atom) < 3:
continue
# Because the pi stacking kernel is a "donut" and have a
# orientation.
pi_stacking_kernel.refresh_orientation(
coordinate=res_atom.positions[:3]
)
stamp.refresh_orientation(kernel=pi_stacking_kernel.kernel())
stamp.stamp_kernel(center=res_atom.center_of_geometry())
|
populate_grid(grid, grid_object)
Populate a grid following H-bond properties.
Parameters
grid : np.ndarray
The grid to fill.
Grid
The grid object to access all attributes.
Source code in src/smiffer/grid/property_strategy/class_pi_stacking.py
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 | def populate_grid(self, grid: np.ndarray, grid_object) -> None:
"""Populate a grid following H-bond properties.
Parameters
----------
grid : `np.ndarray`
The grid to fill.
grid_object : `Grid`
The grid object to access all attributes.
"""
radius: float = (
grid_object.yaml["function_pi_stacking_mu"][1]
+ grid_object.yaml["function_pi_stacking_sigma"][1][1] ** (1 / 2)
* grid_object.yaml["other_gaussian_kernel_scalar"]
)
pi_stacking_kernel: BivariateGaussianKernel = BivariateGaussianKernel(
radius=radius,
delta=grid_object.delta,
v_mu=np.array(grid_object.yaml["function_pi_stacking_mu"]),
# Pre-inversing the matrix.
v_sigma=np.linalg.inv(
grid_object.yaml["function_pi_stacking_sigma"]
),
is_stacking=True,
)
stamp: Stamp = Stamp(
grid=grid,
grid_origin=grid_object.coord[0],
delta=grid_object.delta,
kernel=pi_stacking_kernel,
)
parsed_residue: dict = {}
for atom in grid_object.molecule:
if atom.resname not in self._atom_constant["aromatic"]:
continue
# In order to not check multiple time the same residue.
if atom.resname not in parsed_residue:
parsed_residue[atom.resname] = []
atom_id: tuple = (atom.resid, atom.chainID)
# Skip if already parsed.
if atom_id in parsed_residue[atom.resname]:
continue
parsed_residue[atom.resname] += [atom_id]
select: str = (
f"resid {atom.resid} "
f"and name {self._atom_constant['aromatic'][atom.resname]}"
)
if atom.chainID is not None:
select += f" and chainID {atom.chainID}"
res_atom = grid_object.molecule.select_atoms(select)
if len(res_atom) < 3:
continue
# Because the pi stacking kernel is a "donut" and have a
# orientation.
pi_stacking_kernel.refresh_orientation(
coordinate=res_atom.positions[:3]
)
stamp.refresh_orientation(kernel=pi_stacking_kernel.kernel())
stamp.stamp_kernel(center=res_atom.center_of_geometry())
|