function [rxn_data, num_new, rxgp] = prepare_genmm_rxn(rxn, rxgp, cmpd_name)

% first substrate, both ltor and rtol, is assumed to be the enzyme

num_new = 0;
if rxn.ltor.rate.k2 ~= 0
    num_new = num_new + 1;
    rxn_data{num_new}.type = 'genmm';
    rxn_data{num_new}.name = rxn.name;
    num_subs = size(rxn.lhs,1);
    
    for i = 1:num_subs
        rxgp = build_comps(rxn.lhs{i,2}, rxgp, cmpd_name);
        comp_id = find_comp_id(rxn.lhs{i,2},rxgp.comps);
        rxn_data{num_new}.substrates(i,2) = rxn.lhs{i,1};
        rxn_data{num_new}.substrates(i,1) = comp_id;
    end
    if isfield(rxn, 'rhs')
        num_prods = size(rxn.rhs,1);
        for i = 1:num_prods
            rxgp = build_comps(rxn.rhs{i,2}, rxgp, cmpd_name);
            comp_id = find_comp_id(rxn.rhs{i,2},rxgp.comps);
            rxn_data{num_new}.products(i,2) = rxn.rhs{i,1};
            rxn_data{num_new}.products(i,1) = comp_id;
        end
    end
    rxn_data{num_new}.StoP = rxn.ltor.rate;
    rxn_data{num_new}.StoP_name{1} = [rxn_data{num_new}.name '.ltor.rate.k2   '];
    for i=1:length(rxn.ltor.rate.km)
        rxn_data{num_new}.StoP_name{i+1} = [rxn_data{num_new}.name '.ltor.rate.km(' num2str(i) ')'];
    end
end
    
if rxn.rtol.rate.k2 ~= 0
    num_new = num_new + 1;
    rxn_data{num_new}.type = 'genmm';
    rxn_data{num_new}.name = rxn.name;
    num_subs = size(rxn.rhs,1);

    for i = 1:num_subs
        rxgp = build_comps(rxn.rhs{i,2}, rxgp, cmpd_name);
        comp_id = find_comp_id(rxn.rhs{i,2}, rxgp.comps);
        rxn_data{num_new}.substrates(i,2) = rxn.rhs{i,1};
        rxn_data{num_new}.substrates(i,1) = comp_id;
    end
    num_prods = size(rxn.lhs,1);
    for i = 1:num_prods
        rxgp = build_comps(rxn.lhs{i,2}, rxgp, cmpd_name);
        comp_id = find_comp_id(rxn.lhs{i,2}, rxgp.comps);
        rxn_data{num_new}.products(i,2) = rxn.lhs{i,1};
        rxn_data{num_new}.products(i,1) = comp_id;
    end
    rxn_data{num_new}.StoP = rxn.rtol.rate;
        rxn_data{num_new}.StoP_name{1} = [rxn_data{num_new}.name '.ltor.rate.k2'];
    for i=1:length(rxn.ltor.rate.km)
        rxn_data{num_new}.StoP_name{i+1} = [rxn_data{num_new}.name '.ltor.rate.km(' i ')'];
    end

end
