mindsponge.metrics.frame_aligned_point_error

mindsponge.metrics.frame_aligned_point_error(pred_frames, target_frames, frames_mask, pred_positions, target_positions, positions_mask, length_scale, l1_clamp_distance)[source]

Measure point error under different alignments which computes error between two structures with B points under A alignments derived from the given pairs of frames. Jumper et al. (2021) Suppl. Alg. 28 “computeFAPE”. This function considers all frames. First transform the predicted atom positions to different predicted local frames, \(\vec{x_{j\_pred}^{i}} = \mathcal{T}_{i\_{pred}} \circ \vec{x_{j\_pred}}\) Then transform the true atom positions to different true local frames, \(\vec{x_{j\_gt}^{i}} = \mathcal{T}_{i\_{gt}} \circ \vec{x_{j\_gt}}\) Then compute the L2 error of all atoms positions in all local frames. \(\sum_{i }^{N_{frames}}\sum_{j}^{N_{atoms}}(\parallel \vec{x_{j\_pred}^{i}} - \vec{x_{j\_gt}^{i}} \parallel )\)

Parameters
  • pred_frames (Tensor) – The predicted frames of shape \((12, N_{frames})\) with \(N_{frames}\) the number of pairs of frames. For the first dimension, the first 9 elements are the 9 components of rotation matrix; the last 3 elements are the 3 component of translation matrix.

  • target_frames (Tensor) – The ground truth frames of same shape as pred_frames.

  • frames_mask (Tensor) – The binary mask for frames of shape \((N_{frames},)\).

  • pred_positions (Tensor) – The predicted atom positions tensor of shape \((3, N_{atoms})\) with \(N_{atoms}\) the number of atoms.

  • target_positions (Tensor) – The ground truth atom positions of same shape as pred_positions.

  • positions_mask (Tensor) – The binary mask for atom positions of shape \((N_{atoms},)\).

  • length_scale (float) – The unit distance which is used to scale distances.

  • l1_clamp_distance (float) – Distance cutoff on error beyond which gradients will be zero.

Returns

  • error_clamp (Tensor) - Backbone FAPE loss clamped with shape \((N_{recycle},)\).

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> np.random.seed(0)
>>> from mindsponge.metrics import frame_aligned_point_error
>>> from mindspore import dtype as mstype
>>> from mindspore import Tensor
>>> pred_frames = Tensor(np.random.rand(12, 256)).astype(mstype.float32)
>>> target_frames = Tensor(np.random.rand(12, 256)).astype(mstype.float32)
>>> frames_mask = Tensor(np.random.rand(256,)).astype(mstype.float32)
>>> pred_positions = Tensor(np.random.rand(3, 1024)).astype(mstype.float32)
>>> target_positions = Tensor(np.random.rand(3, 1024)).astype(mstype.float32)
>>> positions_mask = Tensor(np.random.rand(1024,)).astype(mstype.float32)
>>> length_scale = 10.0
>>> l1_clamp_distance = 10.0
>>> fape = frame_aligned_point_error(pred_frames, target_frames, frames_mask,
>>>                                  pred_positions, target_positions, positions_mask,
>>>                                  length_scale, l1_clamp_distance)
>>> print(fape)
0.08747593