Tutorial on retaining residual strain and cutting

From BanghamLab
Revision as of 16:04, 3 June 2011 by AndrewBangham (talk | contribs) (Created page with 'Back to tutorial pages<br><br> Note<br> <span style="color: Crimson">Crimson: code relating to submodel selection</span><br> <span st…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Back to tutorial pages

Note
Crimson: code relating to submodel selection
MediumBlue: code to tell plotter to put morphogens on their respective A and B sides
RosyBrown: code for setting up the seam and cutting the mesh
When the system is arrested (ARRESTTIME=50) there is no further growth and the seams are cut.

% Section 1
function m = gpt_retainstrainandcut_20110603( m )
%m = gpt_retainstrainandcut_20110603( m )
%   Morphogen interaction function.
%   Written at 2011-06-03 14:38:33.
%   GFtbox revision 3554, 2011-06-02 12:30:52.789869.

% The user may edit any part of this function between delimiters
% of the form "USER CODE..." and "END OF USER CODE...".  The
% delimiters themselves must not be moved, edited, deleted, or added.

    if isempty(m), return; end

    fprintf( 1, '%s found in %s\n', mfilename(), which(mfilename()) );

    try
        m = local_setproperties( m );
    catch
    end

    realtime = m.globalDynamicProps.currenttime;

% Section 2
%%% USER CODE: INITIALISATION

% In this section you may modify the mesh in any way whatsoever.
    if Steps(m)==0 % First iteration
        m.userdata.ranges.modelname.range = { 'NORESIDUALS', 'FULLRESIDUALS' };
        m.userdata.ranges.modelname.index = 1;
    end
    modelname = m.userdata.ranges.modelname.range{m.userdata.ranges.modelname.index};
    switch modelname
        case 'NORESIDUALS'
            % Set up the parameters (e.g. mutations) for this model here.
            StrainRetention=0; 
        case 'FULLRESIDUALS'
            % Set up the parameters (e.g. mutations) for this model here.
            StrainRetention=1; 
        otherwise
            % If you reach here, you probably forgot a case.
    end
    % override the GUI and plot the two growth rates on the different sides
    % this line must be commented out if you want to watch the residual
    % strain build up and decay (Plot output value, Residual growth, Areal)
    m = leaf_plotoptions( m, 'morphogenA', 'KAPAR','morphogenB', 'KBPAR');
    % There is a bug in the code that colours in the mesh and colourbar
    % The work around is to click the Monochrome tick box off and on again
    % likewise the Auto color range
    % For this example it is best to turn off the auto color range
    
%%% END OF USER CODE: INITIALISATION

% Section 3
%%% SECTION 1: ACCESSING MORPHOGENS AND TIME.
%%% AUTOMATICALLY GENERATED CODE: DO NOT EDIT.

    if isempty(m), return; end

    setGlobals();
    global gNEW_KA_PAR gNEW_KA_PER gNEW_KB_PAR gNEW_KB_PER
    global gNEW_K_NOR gNEW_POLARISER gNEW_STRAINRET gNEW_ARREST
    dt = m.globalProps.timestep;
    polariser_i = gNEW_POLARISER;
    P = m.morphogens(:,polariser_i);
    [kapar_i,kapar_p,kapar_a,kapar_l] = getMgenLevels( m, 'KAPAR' );
    [kaper_i,kaper_p,kaper_a,kaper_l] = getMgenLevels( m, 'KAPER' );
    [kbpar_i,kbpar_p,kbpar_a,kbpar_l] = getMgenLevels( m, 'KBPAR' );
    [kbper_i,kbper_p,kbper_a,kbper_l] = getMgenLevels( m, 'KBPER' );
    [knor_i,knor_p,knor_a,knor_l] = getMgenLevels( m, 'KNOR' );
    [strainret_i,strainret_p,strainret_a,strainret_l] = getMgenLevels( m, 'STRAINRET' );
    [arrest_i,arrest_p,arrest_a,arrest_l] = getMgenLevels( m, 'ARREST' );
    [id_sidelines_i,id_sidelines_p,id_sidelines_a,id_sidelines_l] = getMgenLevels( m, 'ID_SIDELINES' );
    [id_topcap_i,id_topcap_p,id_topcap_a,id_topcap_l] = getMgenLevels( m, 'ID_TOPCAP' );
    [id_botcap_i,id_botcap_p,id_botcap_a,id_botcap_l] = getMgenLevels( m, 'ID_BOTCAP' );
    [f_seam_i,f_seam_p,f_seam_a,f_seam_l] = getMgenLevels( m, 'F_SEAM' );

% Mesh type: capsule
%         basecap: 1
%      baseheight: 1
%       baserings: 5
%      circumdivs: 12
%          height: 0.2
%      heightdivs: 16
%      randomness: 0.1
%          topcap: 1
%       topheight: 1
%        toprings: 5
%         version: 1
%          xwidth: 0.2
%          ywidth: 0.2

%            Morphogen   Diffusion   Decay   Dilution   Mutant
%            -------------------------------------------------
%                KAPAR        ----    ----       ----     ----
%                KAPER        ----    ----       ----     ----
%                KBPAR        ----    ----       ----     ----
%                KBPER        ----    ----       ----     ----
%                 KNOR        ----    ----       ----     ----
%            POLARISER       0.002    ----       ----     ----
%            STRAINRET        ----    ----       ----     ----
%               ARREST        ----    ----       ----     ----
%         ID_SIDELINES        ----    ----       ----     ----
%            ID_TOPCAP        ----    ----       ----     ----
%            ID_BOTCAP        ----    ----       ----     ----
%               F_SEAM        ----    ----       ----     ----


%%% USER CODE: MORPHOGEN INTERACTIONS

% In this section you may modify the mesh in any way that does not
% Section 4
% alter the set of nodes.
    if Steps(m)==0  % Initialisation code.
        % Put any code here that should only be performed at the start of
        % the simulation, for example, to set up initial morphogen values.
        % Force global variables to zeros to make debugging more reliable
        m.morphogens=zeros(size(m.morphogens));
        m.seams=logical(zeros(size(m.seams)));
        m.polfreeze=zeros(size(m.polfreeze));
        m.mgen_production=zeros(size(m.mgen_production));

        % Caps
        id_topcap_p(m.nodes(:,3)>0.17)=1;
        id_botcap_p(m.nodes(:,3)<-0.17)=1;
        % Sidelines
        indx=find(abs(m.nodes(:,1))>0.08);
        indy=find(abs(m.nodes(:,2))<0.02);
        id_sidelines_p(intersect(indx,indy))=1;
        % Seams along which the capsule will be cut (not the bottom cap)
        inds=[find(id_sidelines_p>0.5);find(id_topcap_p>0.5)];
        f_seam_p(inds)=1;
        m=leaf_set_seams(m,f_seam_p);
        % Seams will be cut when this flag is set to 1 - see see FINALISATION code
        m.userdata.CutOpen=0;
    end
    
% Section 5
    % Code common to all models. (the different strain retention is setup
    % in the initial routines above)
    strainret_p=StrainRetention.*ones(size(strainret_p));
    ARRESTTIME=50;
    if m.userdata.CutOpen==0 % Grow the silique
% Section 6
        % Code for specific models.
        % @@PRN Polariser Regulatory Network
        % Every equation to be formatted should end with an at-at Eqn N comment.
        m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant
        m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
        m = leaf_mgen_absorption( m, 'Polariser', 0);  % it will not decay everywhere
        P(id_topcap_l>0.5)=1;
        m.morphogenclamp(id_topcap_l>0.5,polariser_i) = 1;
        P(id_botcap_l>0.5)=0;
        m.morphogenclamp(id_botcap_l>0.5,polariser_i) = 1;
        % having clamped the values at each end and allowed POL to diffuse
        % diffusion will occur automatically and produce a linear gradient
        kapar_p=0.01; % Specified growth on the inside
        kbpar_p=0.001; % Much less specified growth on the outside
        kaper_p=0.2*kapar_p; % anisotropic growth (grows lengthwise)
        kbper_p=0.2*kbpar_p;
        if realtime>ARRESTTIME
            m.userdata.CutOpen=1;
        end
    elseif m.userdata.CutOpen==1
    else % relax the cut silique
        kapar_p=0;
        kbpar_p=0;
        kaper_p=0;
        kbper_p=0;
        knor_p =0;
        m = leaf_setproperty( m, 'freezing', 0.9 );
    end
% Section 7
%%% END OF USER CODE: MORPHOGEN INTERACTIONS

%%% SECTION 3: INSTALLING MODIFIED VALUES BACK INTO MESH STRUCTURE
%%% AUTOMATICALLY GENERATED CODE: DO NOT EDIT.
    m.morphogens(:,polariser_i) = P;
    m.morphogens(:,kapar_i) = kapar_p;
    m.morphogens(:,kaper_i) = kaper_p;
    m.morphogens(:,kbpar_i) = kbpar_p;
    m.morphogens(:,kbper_i) = kbper_p;
    m.morphogens(:,knor_i) = knor_p;
    m.morphogens(:,strainret_i) = strainret_p;
    m.morphogens(:,arrest_i) = arrest_p;
    m.morphogens(:,id_sidelines_i) = id_sidelines_p;
    m.morphogens(:,id_topcap_i) = id_topcap_p;
    m.morphogens(:,id_botcap_i) = id_botcap_p;
    m.morphogens(:,f_seam_i) = f_seam_p;

%%% USER CODE: FINALISATION

% In this section you may modify the mesh in any way whatsoever.
    if m.userdata.CutOpen==1
        m=leaf_dissect(m);
        m.userdata.CutOpen=2;        
        m = leaf_setproperty( m, 'freezing', 0.999 );
    end
%%% END OF USER CODE: FINALISATION

end


%%% USER CODE: SUBFUNCTIONS
% Here you may add any functions of your own, that you want to call from
% the interaction function, but never need to call from outside it.
% Whichever section they are called from, they must respect the same
% restrictions on what modifications they are allowed to make to the mesh.
% This comment can be deleted.