pulsatrix 1.1.0
Loading...
Searching...
No Matches
protein_contacts.hpp File Reference

Residue contacts from a protein language model's attention (PLM-4): ESM's contact head, the top-K head average, and precision at L, L/2 and L/5 against a structure's contacts. More...

#include <cstdint>
#include <functional>
#include <string>
#include <string_view>
#include <vector>
#include "pulsatrix/encoder_lm.hpp"
#include "pulsatrix/protein_structure.hpp"
#include "pulsatrix/text_tokenizer.hpp"
Include dependency graph for protein_contacts.hpp:

Go to the source code of this file.

Classes

struct  pulsatrix::AttentionHead
 One attention head: layer from 0, head within it from 0. More...
 
struct  pulsatrix::EsmContactHead
 ESM's contact head (EsmContactPredictionHead): a logistic regression over every head's corrected attention map, sigmoid(sum_c weight[c] * f_c(i, j) + bias). Channel c = layer * heads + head, as transformers stacks them. More...
 
struct  pulsatrix::ContactOptions
 
class  pulsatrix::ContactPredictor
 Contacts from a masked LM's attention, the way ESM predicts them: one forward pass over <cls> + the sequence + <eos>, every head's map turned into ContactFeatures, then combined. Each map is used as its layer finishes, so a pass holds one layer's at a time. Sequences are run one at a time, with no padding. More...
 
struct  pulsatrix::SeparationRange
 Pairs (i, j) counted by separation j - i: at least min, and under max unless max is 0. More...
 
struct  pulsatrix::ContactPrecisions
 Precision of the top L, L/2 and L/5 pairs, L the sequence length (rounded down). More...
 
struct  pulsatrix::ContactEvaluation
 PrecisionAtL in each of the short, medium and long ranges. More...
 
struct  pulsatrix::LabeledProtein
 A protein with known contacts, to choose heads with. More...
 
struct  pulsatrix::HeadPrecision
 

Namespaces

namespace  pulsatrix
 

Functions

EsmContactHead pulsatrix::LoadEsmContactHead (const std::string &directory, const EncoderLMConfig &config)
 Reads the contact head from an ESM-2 checkpoint directory: esm.contact_head.regression.* (EsmForMaskedLM) or contact_head.regression.* (EsmModel).
 
ContactMap pulsatrix::ContactFeatures (const float *attention, int64_t tokens)
 One head's contact features from its attention map over <cls>, L residues and <eos> (tokens x tokens, row-major, tokens = L + 2): the residue block, made symmetric (A + Aᵀ), then corrected by the average product (APC): F - rowsum * colsum / total.
 
double pulsatrix::ContactPrecision (const ContactMap &predicted, const ContactMap &truth, SeparationRange range, int64_t top)
 The fraction of the top highest-scoring pairs in range that are true contacts.
 
ContactPrecisions pulsatrix::PrecisionAtL (const ContactMap &predicted, const ContactMap &truth, SeparationRange range)
 
ContactEvaluation pulsatrix::EvaluateContacts (const ContactMap &predicted, const ContactMap &truth)
 
std::vector< HeadPrecision > pulsatrix::RankContactHeads (ContactPredictor &predictor, const std::vector< LabeledProtein > &proteins, SeparationRange range=kLongRange)
 Every head, best first, by its features' mean precision at L in range over proteins. The top K make an unsupervised predictor with ContactPredictor::average_heads (arXiv 2606.21876 chooses them with 10 labeled proteins). Choose heads on proteins you won't evaluate on.
 

Variables

constexpr SeparationRange pulsatrix::kShortRange {6, 12}
 CASP's and ESM's ranges: short 6–11, medium 12–23, long 24 and up.
 
constexpr SeparationRange pulsatrix::kMediumRange {12, 24}
 
constexpr SeparationRange pulsatrix::kLongRange {24, 0}
 

Detailed Description

Residue contacts from a protein language model's attention (PLM-4): ESM's contact head, the top-K head average, and precision at L, L/2 and L/5 against a structure's contacts.