Head model (volume) not working with scripts

Dear All,

this is quite a follow-up of a previous bug I spotted some years ago.
The problem is in the script generate for head model with MRI volume.
While the head model is calculated normally with the GUI, when generating the script something is wrong and the following error is displayed

Screenshot from 2020-09-17 18-30-16

The code I used (the one generated from Brainstorm) is reported below.
I had similar problem in the past and the problem was actually in the generated code (something was missing).

% Process: Compute head model
ResHeadModel = bst_process('CallProcess', 'process_headmodel', Import_data, [], ...
    'Comment',     '', ...
    'sourcespace', 2, ...  % MRI volume
    'volumegrid',  struct(...
         'Method',        'isotropic', ...
         'nLayers',       17, ...
         'Reduction',     3, ...
         'nVerticesInit', 4000, ...
         'Resolution',    0.005, ...
         'FileName',      []), ...
    'meg',         3, ...  % Overlapping spheres
    'eeg',         1, ...  % 
    'ecog',        1, ...  % 
    'seeg',        1, ...  % 
    'openmeeg',    struct(...
         'BemSelect',    [1, 1, 1], ...
         'BemCond',      [1, 0.0125, 1], ...
         'BemNames',     {{'Scalp', 'Skull', 'Brain'}}, ...
         'BemFiles',     {{}}, ...
         'isAdjoint',    0, ...
         'isAdaptative', 1, ...
         'isSplit',      0, ...
         'SplitLength',  4000), ...
    'duneuro',     struct(...
         'FemCond',            [], ...
         'FemSelect',          [], ...
         'UseTensor',          0, ...
         'Isotropic',          1, ...
         'SrcShrink',          0, ...
         'SrcForceInGM',       0, ...
         'FemType',            'fitted', ...
         'SolverType',         'cg', ...
         'GeometryAdapted',    0, ...
         'Tolerance',          1e-08, ...
         'ElecType',           'normal', ...
         'MegIntorderadd',     0, ...
         'MegType',            'physical', ...
         'SolvSolverType',     'cg', ...
         'SolvPrecond',        'amg', ...
         'SolvSmootherType',   'ssor', ...
         'SolvIntorderadd',    0, ...
         'DgSmootherType',     'ssor', ...
         'DgScheme',           'sipg', ...
         'DgPenalty',          20, ...
         'DgEdgeNormType',     'houston', ...
         'DgWeights',          1, ...
         'DgReduction',        1, ...
         'SolPostProcess',     1, ...
         'SolSubstractMean',   0, ...
         'SolSolverReduction', 1e-10, ...
         'SrcModel',           'venant', ...
         'SrcIntorderadd',     0, ...
         'SrcIntorderadd_lb',  2, ...
         'SrcNbMoments',       3, ...
         'SrcRefLen',          20, ...
         'SrcWeightExp',       1, ...
         'SrcRelaxFactor',     6, ...
         'SrcMixedMoments',    1, ...
         'SrcRestrict',        1, ...
         'SrcInit',            'closest_vertex', ...
         'BstSaveTransfer',    0, ...
         'BstEegTransferFile', 'eeg_transfer.dat', ...
         'BstMegTransferFile', 'meg_transfer.dat', ...
         'BstEegLfFile',       'eeg_lf.dat', ...
         'BstMegLfFile',       'meg_lf.dat'));

Thanks in advance for the help!

G

The code was not handling correctly the cases where the inner skull surface is missing (requires the computation of the BEM surface).
I added a fix to use the convex envelope of the cortex surface as the inner skull when the surface is missing. It may remove a few dipoles located on the brain surface, but I don't think it would make any significant difference.
https://github.com/brainstorm-tools/brainstorm3/commit/f95c115258181364ffd415c44edb44dbc666d163#diff-6f6caa872b72ebb4d314b4b9c8b9c0f1

I also added some code in the script generator to remove the unused structures (openmeeg, duneuro, volumegrid) when they are not needed. Your post made me realize the script to generate a simple head model was unnecessarily long.

Please udpate Brainstorm and try again.

Dear Francois,

thanks a lot. With your comment. I solved the issue, by simply computing the BEM surfaces before running the head model.

Thanks also for the fixes of the generated code!

Best

Giorgio