Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Ki Readout #36

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mtenn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ReadoutConfig(StringEnum):
"""

pic50 = "pic50"
ki = "ki"


class CombinationConfig(StringEnum):
Expand Down Expand Up @@ -203,6 +204,8 @@ def build(self) -> mtenn.model.Model:
mtenn_pred_readout = mtenn.readout.PIC50Readout(
substrate=self.pred_substrate, Km=self.pred_km
)
case ReadoutConfig.ki:
mtenn_pred_readout = mtenn.readout.KiReadout()
case None:
mtenn_pred_readout = None

Expand All @@ -211,6 +214,8 @@ def build(self) -> mtenn.model.Model:
mtenn_comb_readout = mtenn.readout.PIC50Readout(
substrate=self.comb_substrate, Km=self.comb_km
)
case ReadoutConfig.ki:
mtenn_comb_readout = mtenn.readout.KiReadout()
case None:
mtenn_comb_readout = None

Expand Down
51 changes: 46 additions & 5 deletions mtenn/readout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


class Readout(torch.nn.Module, abc.ABC):
pass
def __str__(self):
return repr(self)


class PIC50Readout(Readout):
Expand Down Expand Up @@ -58,9 +59,6 @@ def __init__(self, substrate: Optional[float] = None, Km: Optional[float] = None
def __repr__(self):
return f"PIC50Readout(substrate={self.substrate}, Km={self.Km})"

def __str__(self):
return repr(self)

def forward(self, delta_g):
"""
Method to convert a predicted delta G value into a pIC50 value.
Expand All @@ -72,7 +70,7 @@ def forward(self, delta_g):

Returns
-------
float
torch.Tensor
Calculated pIC50 value.
"""
pic50 = -delta_g / torch.log(torch.tensor(10, dtype=delta_g.dtype))
Expand All @@ -81,3 +79,46 @@ def forward(self, delta_g):
pic50 -= torch.log10(torch.tensor(self.cp_val, dtype=delta_g.dtype))

return pic50



class KiReadout(Readout):
"""
Readout implementation to convert delta G values to Ki values. This new
implementation assumes implicit energy units, WHICH WILL INVALIDATE MODELS TRAINED
PRIOR TO v0.3.0.
Assuming implicit energy units:
deltaG = ln(Ki)
Ki = exp(deltaG)
"""

def __init__(self):
"""
Initialization.

Parameters
----------
None
"""
super(KiReadout, self).__init__()

def __repr__(self):
return f"KiReadout()"

def forward(self, delta_g):
"""
Method to convert a predicted delta G value into a Ki value.

Parameters
----------
delta_g : torch.Tensor
Input delta G value.

Returns
-------
torch.Tensor
Calculated Ki value.
"""
ki = torch.exp(delta_g)

return ki