0001 function [vout, rout] = fitC13Data(v0,expdata,model, majorIterationLimit)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 4
0013 majorIterationLimit = 1000;
0014 end
0015 diffInterval = 1e-5;
0016 method = 1;
0017 printLevel = 3;
0018
0019 if method == 1
0020 if ~isfield(model, 'N')
0021 model.N = null(model.S);
0022 display('model.N should be defined');
0023 pause;
0024 end
0025
0026 x0 = model.N\v0;
0027
0028
0029 if (max(abs(model.S*v0))> 1e-6)
0030 display('v0 not quite in null space');
0031 pause;
0032 end
0033 if(max(abs(model.N*x0 - v0)) > 1e-6)
0034 max(abs(model.N*x0 - v0))
0035 display('null basis is weird');
0036 pause;
0037 end
0038
0039
0040 nalpha = size(model.N, 2);
0041 x_L = -1000*ones(nalpha,1);
0042 x_U = 1000*ones(nalpha,1);
0043 [A, b_L, b_U] = defineLinearConstraints(model, method);
0044 elseif method == 2
0045 x0 = v0;
0046 [A, x_L, x_U] = defineLinearConstraints(model, method);
0047 b_L = zeros(size(A,1),1);
0048 b_U = zeros(size(A,1),1);
0049 else
0050 display('error'); pause;
0051 end
0052
0053 numpoints = size(x0,2);
0054 vout = zeros(size(v0));
0055 rout = cell(numpoints, 1);
0056
0057 for k = 1:numpoints
0058 x_0 = x0(:,k);
0059 NLPproblem.objFunction = 'errorComputation2';
0060 NLPproblem.gradFunction = 'errorComputation2_grad';
0061 NLPproblem.lb = x_L;
0062 NLPproblem.ub = x_U;
0063 NLPproblem.name = 'c13fitting';
0064 NLPproblem.x0 = x_0;
0065 NLPproblem.A = A;
0066 NLPproblem.b_L = b_L;
0067 NLPproblem.b_U = b_U;
0068 NLPproblem.userParams.expdata = expdata;
0069 NLPproblem.userParams.model = model;
0070 NLPproblem.userParams.useparfor = true;
0071 NLPproblem.userParams.diff_interval = diffInterval;
0072
0073 NLPproblem.PriLevOpt = 1;
0074 cnan = ( method == 2);
0075
0076 NLPsolution = solveCobraNLP(NLPproblem, 'checkNaN', cnan, 'printLevel', printLevel, 'iterationLimit', majorIterationLimit, 'logFile', 'minimize_SNOPT.txt');
0077
0078 if exist('ttt.txt', 'file')
0079 fprintf('quitting due to file found\n');
0080 continue;
0081 end
0082 if method == 1
0083 vout(:,k) = model.N*NLPsolution.full;
0084 else
0085 vout(:,k) = NLPsolution.full;
0086 end
0087 rout{k} = NLPsolution;
0088 end
0089 return
0090