<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
af.py - An actin filament

Create and maintain a thin filament and the subgroups that comprise it.

Created by <NAME> on 2010-01-04.
"""

import numpy as np


class BindingSite(object):
    """A singular globular actin site"""
    def __init__(self, parent_thin_fil, index, orientation):
        """Create a binding site on the thin filament
        
        Parameters:
            parent_thin_fil: the calling thin filament instance
            index: the axial index on the parent thin filament
            orientation: select between six orientations (0-5)
        """
        # Remember passed attributes
        self.parent_thin = parent_thin_fil
        self.index = index
        self.address = ('bs', self.parent_thin.index, self.index)
        # Use the passed orientation index to choose the correct 
        # orientation vector according to schema in ThinFilament docstring
        orientation_vectors = ((0.866, -0.5), (0, -1), (-0.866, -0.5), 
                (-0.866, 0.5), (0, 1), (0.866, 0.5))
        self.orientation = orientation_vectors[orientation]
        # Start off in an activated state, fully open to binding
        self.permissiveness = 1.0
        # Create attributes to store things not yet present 
        self.bound_to = None # None if unbound, Crossbridge object otherwise
    
    def __str__(self):
        """Return the current situation of the binding site"""
        ident = ['Binding Site #' + str(self.index) + ' Info']
        ident.append(14 * '=')
        ident.append('State: ' + str(self.get_state()))
        if self.get_state() != 0:
            ident.append('Forces: ' + str(self.axialforce()) 
                         + '/' + str(self.radialforce()))
        return '\n'.join(ident)
    
    def json_dict(self):
        """Create a JSON compatible representation of the binding site
        
        Usage example:json.dumps(bs.json_dict(), indent=1) 
        
        Current output includes:
            index: the index of the binding site on the thin filament
            bound_to: T/F if the binding site is bound
            orientation: the y/z orientation of the binding site relative to 
                the center of the thin filament
            permissiveness: the 0-1 level of binding permissiveness 
            parent_thin: index of the parent thin filament
        """
        bsd = self.__dict__.copy()
        bsd['parent_thin'] = self.parent_thin.index # no recursive, index
        bsd['bound_to'] = bool(bsd['bound_to']) # consider indexing
        return bsd
    
    def axialforce(self, axial_location=None):
        """Return the axial force of the bound cross-bridge, if any
        
        Parameters:
            axial_location: location of the current node (optional)
        Returns: 
            f_x: the axial force generated by the cross-bridge
        """
        if self.bound_to is None:
            return 0.0 
        # Axial force on actin is equal but opposite 
        return -self.bound_to.axialforce(tip_axial_loc = axial_location) 
    
    def radialforce(self):
        """Radial force vector of the bound cross-bridge, if any
        
        Returns:
            (f_y, f_z): the radial force vector of this binding site
        """
        if self.bound_to is None:
            return 0.0
        force_mag = -self.bound_to.radialforce() # Equal but opposite
        return np.multiply(force_mag, self.orientation)
        """Create link to the relevant thick filament face when known"""
        self.thick_face = thick_face
    
    def bind_to(self, crossbridge):
        """Link this binding site to a cross-bridge object"""
        self.bound_to = crossbridge
    
    def unbind(self):
        """Kill off any link to a crossbridge"""
        assert(self.bound_to is not None) # Else why try to unbind?
        self.bound_to = None
    
    def get_state(self):
        """Return the current numerical state, 0/unbound or 1/bound"""
        return self.bound_to is not None
    
    def get_lattice_spacing(self):
        """Get lattice spacing from the parent filament"""
        return self.parent_thin.get_lattice_spacing()
    
    def get_axial_location(self):
        """Return the current axial location of the binding site"""
        return self.parent_thin.axial[self.index]


class ThinFace(object):
    """Represent one face of an actin filament
    Deals with orientation in the typical fashion for thin filaments
        ================
        ||     m4     ||  ^
        || m3      m5 ||  |   ^   
        ||     af     ||  Z  / 
        || m2      m0 ||    X 
        ||     m1     ||      Y-->
        ================
    """
    def __init__(self, parent_thin_fil, orientation, index, binding_sites):
        """Create the thin filament face
        
        Parameters:
            parent_thin_fil: the thin filament on which this face sits
            orientation: which myosin face is opposite this face (0-5)
            index: location on the thin filament this face occupies (0-2)
            binding_sites: links to the actin binding sites on this face
        """
        self.parent_thin = parent_thin_fil 
        self.index = index
        self.address = ('thin_face', self.parent_thin.index, self.index)
        self.orientation = orientation 
        self.binding_sites = binding_sites 
        self.thick_face = None  # ThickFace instance this face interacts with
    
    def json_dict(self):
        """Create a JSON compatible representation of the thin face
        
        Usage example: json.dumps(thin_face.json_dict(), indent=1)
        
        Current output includes:
            index: index of thin face on parent thin filament
            orientation: out of 0-5 directions, which this projects in
            binding_sites: address information for each binding site
            parent_thin: index of the parent thin filament
        """
        tfd = self.__dict__.copy()
        tfd['parent_thin'] = self.parent_thin.index # no recursive, index
        tfd.pop('thick_face') # TODO: Replace when mf indexing is complete
        tfd['binding_sites'] = [bs.address() for bs in tfd['binding_sites']]
        return tfd
    
    def nearest(self, axial_location):
        """Where is the nearest binding site?
        
        There a fair number of cases that must be dealt with here. When 
        the system becomes too short (and some nearest queries are being
        directed to a thin face that doesn't really have anything near 
        that location) the face will just return the nearest location and 
        let the kinetics deal with the fact that binding is about as likely
        as stepping into the same river twice. 
        
        Parameters:
            axial_location: the axial coordinates to seek a match for
        Return:
            binding_site: the nearest binding site on this face
        """
        # Next three lines of code enforce a jittery hiding, sometimes the <commit_msg>Address correction<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
af.py - An actin filament

Create and maintain a thin filament and the subgroups that comprise it.

Created by <NAME> on 2010-01-04.
"""

import numpy as np


class BindingSite(object):
    """A singular globular actin site"""
    def __init__(self, parent_thin_fil, index, orientation):
        """Create a binding site on the thin filament
        
        Parameters:
            parent_thin_fil: the calling thin filament instance
            index: the axial index on the parent thin filament
            address: largest to most local, indices for finding this
            orientation: select between six orientations (0-5)
        """
        # Remember passed attributes
        self.parent_thin = parent_thin_fil
        self.index = index
        self.address = ('bs', self.parent_thin.index, self.index)
        # Use the passed orientation index to choose the correct 
        # orientation vector according to schema in ThinFilament docstring
        orientation_vectors = ((0.866, -0.5), (0, -1), (-0.866, -0.5), 
                (-0.866, 0.5), (0, 1), (0.866, 0.5))
        self.orientation = orientation_vectors[orientation]
        # Start off in an activated state, fully open to binding
        self.permissiveness = 1.0
        # Create attributes to store things not yet present 
        self.bound_to = None # None if unbound, Crossbridge object otherwise
    
    def __str__(self):
        """Return the current situation of the binding site"""
        ident = ['Binding Site #' + str(self.index) + ' Info']
        ident.append(14 * '=')
        ident.append('State: ' + str(self.get_state()))
        if self.get_state() != 0:
            ident.append('Forces: ' + str(self.axialforce()) 
                         + '/' + str(self.radialforce()))
        return '\n'.join(ident)
    
    def json_dict(self):
        """Create a JSON compatible representation of the binding site
        
        Usage example:json.dumps(bs.json_dict(), indent=1) 
        
        Current output includes:
            index: the index of the binding site on the thin filament
            address: largest to most local, indices for finding this
            bound_to: T/F if the binding site is bound
            orientation: the y/z orientation of the binding site relative to 
                the center of the thin filament
            permissiveness: the 0-1 level of binding permissiveness 
            parent_thin: index of the parent thin filament
        """
        bsd = self.__dict__.copy()
        bsd['parent_thin'] = self.parent_thin.index # no recursive, index
        bsd['bound_to'] = bool(bsd['bound_to']) # consider indexing
        return bsd
    
    def axialforce(self, axial_location=None):
        """Return the axial force of the bound cross-bridge, if any
        
        Parameters:
            axial_location: location of the current node (optional)
        Returns: 
            f_x: the axial force generated by the cross-bridge
        """
        if self.bound_to is None:
            return 0.0 
        # Axial force on actin is equal but opposite 
        return -self.bound_to.axialforce(tip_axial_loc = axial_location) 
    
    def radialforce(self):
        """Radial force vector of the bound cross-bridge, if any
        
        Returns:
            (f_y, f_z): the radial force vector of this binding site
        """
        if self.bound_to is None:
            return 0.0
        force_mag = -self.bound_to.radialforce() # Equal but opposite
        return np.multiply(force_mag, self.orientation)
        """Create link to the relevant thick filament face when known"""
        self.thick_face = thick_face
    
    def bind_to(self, crossbridge):
        """Link this binding site to a cross-bridge object"""
        self.bound_to = crossbridge
    
    def unbind(self):
        """Kill off any link to a crossbridge"""
        assert(self.bound_to is not None) # Else why try to unbind?
        self.bound_to = None
    
    def get_state(self):
        """Return the current numerical state, 0/unbound or 1/bound"""
        return self.bound_to is not None
    
    def get_lattice_spacing(self):
        """Get lattice spacing from the parent filament"""
        return self.parent_thin.get_lattice_spacing()
    
    def get_axial_location(self):
        """Return the current axial location of the binding site"""
        return self.parent_thin.axial[self.index]


class ThinFace(object):
    """Represent one face of an actin filament
    Deals with orientation in the typical fashion for thin filaments
        ================
        ||     m4     ||  ^
        || m3      m5 ||  |   ^   
        ||     af     ||  Z  / 
        || m2      m0 ||    X 
        ||     m1     ||      Y-->
        ================
    """
    def __init__(self, parent_thin_fil, orientation, index, binding_sites):
        """Create the thin filament face
        
        Parameters:
            parent_thin_fil: the thin filament on which this face sits
            orientation: which myosin face is opposite this face (0-5)
            index: location on the thin filament this face occupies (0-2)
            address: largest to most local, indices for finding this
            binding_sites: links to the actin binding sites on this face
        """
        self.parent_thin = parent_thin_fil 
        self.index = index
        self.address = ('thin_face', self.parent_thin.index, self.index)
        self.orientation = orientation 
        self.binding_sites = binding_sites 
        self.thick_face = None  # ThickFace instance this face interacts with
    
    def json_dict(self):
        """Create a JSON compatible representation of the thin face
        
        Usage example: json.dumps(thin_face.json_dict(), indent=1)
        
        Current output includes:
            index: index of thin face on parent thin filament
            orientation: out of 0-5 directions, which this projects in
            binding_sites: address information for each binding site
            parent_thin: index of the parent thin filament
        """
        tfd = self.__dict__.copy()
        tfd['parent_thin'] = self.parent_thin.index # no recursive, index
        tfd.pop('thick_face') # TODO: Replace when mf indexing is complete
        tfd['binding_sites'] = [bs.address for bs in tfd['binding_sites']]
        return tfd
    
    def nearest(self, axial_location):
        """Where is the nearest binding site?
        
        There a fair number of cases that must be dealt with here. When 
        the system becomes too short (and some nearest queries are being
        directed to a thin face that doesn't really have anything near 
        that location) the face will just return the nearest location and 
        let the kinetics deal with the fact that binding is about as likely
        as stepping into the same river twice. 
        
        Parameters:
            axial_location: the axial coordinates to seek a match for
        Return:
            binding_site: the nearest binding site on this face
        """
        # Next three lines of code enforce a jittery hiding, sometimes the 
{'fraction_non_alphanumeric': 0.08243375858684986, 'fraction_numerical': 0.009252768820972942, 'mean_word_length': 2.1321624588364436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2042917', 'n_tokens_mistral': 3941, 'n_tokens_neox': 3620, 'n_words': 1410}