Custom Decorator¶
We try and make it relatively easy to create your own decorator. All you need to do is inherit a these seven methods from the base class.
(see full base class description at the bottom)
import menten_gcn as mg
import menten_gcn.decorators as decs
class TestDec( decs.Decorator ):
def get_version_name( self ):
return "TestDec"
# NODES #
def n_node_features( self ):
return 1
def calc_node_features( self, wrapped_protein, resid, dict_cache=None ):
if wrapped_protein.get_name1( resid ) == "G":
return [ 1.0 ]
else:
return [ 0.0 ]
def describe_node_features( self ):
return [ "1 if the residue is GLY, 0 otherwise" ]
# EDGES #
def n_edge_features( self ):
return 2
def calc_edge_features( self, wrapped_protein, resid1, resid2, dict_cache=None ):
diff = resid2 - resid1
same = 1.0 if wrapped_protein.get_name1( resid1 ) == wrapped_protein.get_name1( resid2 ) else 0.0
return [ diff, same ], [ -diff, same ]
def describe_edge_features( self ):
return [ "Measures the distance in sequence space between the two residues", "1 if the two residues have the same amino acid, 0 otherwise" ]
decorators=[ decs.SimpleBBGeometry(), TestDec(), ]
data_maker = mg.DataMaker( decorators=decorators, edge_distance_cutoff_A=10.0, max_residues=5 )
data_maker.summary()
Summary:
4 Node Features:
1 : 1 if the node is a focus residue, 0 otherwise
2 : Phi of the given residue, measured in radians. Spans from -pi to pi
3 : Psi of the given residue, measured in radians. Spans from -pi to pi
4 : 1 if the residue is GLY, 0 otherwise
4 Edge Features:
1 : 1.0 if the two residues are polymer-bonded, 0.0 otherwise
2 : Euclidean distance between the two CB atoms of each residue, measured in Angstroms. In the case of GLY, use an estimate of ALA's CB position
3 : Measures the distance in sequence space between the two residues
4 : 1 if the two residues have the same amino acid, 0 otherwise
- class menten_gcn.decorators.Decorator[source]¶
-
- describe_node_features() → List[str][source]¶
Returns descriptions of how each value is computed. Our goal is for these descriptions to be relatively concise but also have enough detail to fully reproduce these calculations.
- Returns
features (list) – The length of this list will be the same value as self.n_node_features(). These are descriptions of the values to represent this decorator’s contribution to X for any arbitrary resid.
- calc_node_features(wrapped_pose: menten_gcn.wrappers.WrappedPose, resid: int, dict_cache: Optional[dict] = None) → List[float][source]¶
This does all of the business logic of calculating the values to be added for each node.
- Parameters
wrapped_pose (WrappedPose) – The pose we are currently generating data for
resid (int) – The residue ID we are currently generating data for
dict_cache (dict) – The same cache that was populated in “cache_data”. The user might not have created a cache so don’t assume this is not None. See the RosettaHBondDecorator for an example of how to use this
- Returns
features (list) – The length of this list will be the same value as self.n_node_features(). These are the values to represent this decorator’s contribution to X for this resid.
- describe_edge_features() → List[str][source]¶
Returns descriptions of how each value is computed. Our goal is for these descriptions to be relatively concise but also have enough detail to fully reproduce these calculations.
- Returns
features (list) – The length of this list will be the same value as self.n_edge_features(). These are descriptions of the values to represent this decorator’s contribution to E for any arbitrary resid pair.
- calc_edge_features(wrapped_pose: menten_gcn.wrappers.WrappedPose, resid1: int, resid2: int, dict_cache: Optional[dict] = None) → Tuple[List[float], List[float]][source]¶
This does all of the business logic of calculating the values to be added for each edge.
This function will never be called in the reverse order (with resid1 and resid2 swapped). Instead, we just create both edges at once.
- Parameters
wrapped_pose (WrappedPose) – The pose we are currently generating data for
resid1 (int) – The first residue ID we are currently generating data for
resid1 (int) – The second residue ID we are currently generating data for
dict_cache (dict) – The same cache that was populated in “cache_data”. The user might not have created a cache so don’t assume this is not None. See the RosettaHBondDecorator for an example of how to use this
- Returns
features (list) – The length of this list will be the same value as self.n_edge_features(). These are the values to represent this decorator’s contribution to E for the edge going from resid1 -> resid2.
inv_features (list) – The length of this list will be the same value as self.n_edge_features(). These are the values to represent this decorator’s contribution to E for the edge going from resid2 -> resid1.
- get_version_name() → str[source]¶
Get a unique, versioned name of this decorator for maximal reproducability
- cache_data(wrapped_pose: menten_gcn.wrappers.WrappedPose, dict_cache: dict)[source]¶
Some decorators can save time by precomputing arbitrary data and storing it in this cache. For example, the RosettaHBondDecorator recomputes and caches all hydrogen bonds so they become a simple lookup when decorating individual nodes and edges.
- Parameters
wrapped_pose (WrappedPose) – Each pose will be given its own cache. This pose is the one we are currently caching
dict_cache (dict) – Destination for your data. Please use a unique key that won’t overlap with other decorators’.
For reference, here are the methods for the WrappedPose that will be passed into your decorator