|
21 | 21 | % 120\\deg angle and optimised magnetic structure. |
22 | 22 | % * `'squareAF'` Square lattice antiferromagnet. |
23 | 23 | % * `'chain'` Chain with further neighbor interactions. |
24 | | -% |
| 24 | +% * `swm_*` Custom models which are in the matlab path can be |
| 25 | +% evaluated. Checkout: |
| 26 | +% https://www.github.com/spinw/Models for pre-made models. |
| 27 | +% |
25 | 28 | % `param` |
26 | 29 | % : Input parameters of the model, row vector which gives the values of the |
27 | 30 | % Heisenberg exchange for first, second, thirs etc. neighbor bonds stored |
|
49 | 52 | end |
50 | 53 |
|
51 | 54 | fprintf0(fid,'Preparing ''%s'' model ...\n',model); |
| 55 | +modelSearch = 'swm_'; |
52 | 56 |
|
53 | 57 | obj = spinw; |
54 | 58 |
|
|
108 | 112 | end |
109 | 113 | end |
110 | 114 | otherwise |
111 | | - error('sw_model:WrongINput','Model does not exists!') |
| 115 | + % All paths |
| 116 | + allPaths = strsplit(path,':'); |
| 117 | + % Remove the builtin functions |
| 118 | + allPaths = allPaths(~strncmp(allPaths,fullfile(matlabroot, 'toolbox'), length(fullfile(matlabroot, 'toolbox')))); |
| 119 | + relPaths = allPaths(~strncmp(allPaths,fullfile(matlabroot, 'example'), length(fullfile(matlabroot, 'example')))); |
| 120 | + % Get all files |
| 121 | + allFiles = cellfun(@(x) dir(x), relPaths, 'UniformOutput', false); |
| 122 | + allFiles = cellfun(@(x) {x.name}, allFiles, 'UniformOutput', false); |
| 123 | + allFiles = [allFiles{:}]; |
| 124 | + % Search for files which are models |
| 125 | + relFiles = cellfun(@(x) x(1:end-2) ,allFiles(strncmp(allFiles, modelSearch, 3)),'UniformOutput',false); |
| 126 | + if ~any(strcmp(model, relFiles)) |
| 127 | + error('sw_model:WrongINput','Model does not exists!') |
| 128 | + end |
| 129 | + % Evaluate the model |
| 130 | + try |
| 131 | + obj = feval(model, param); |
| 132 | + catch ME |
| 133 | + error('sw_model:WrongINput','This model has an error!') |
| 134 | + end |
112 | 135 | end |
113 | 136 |
|
114 | 137 | fprintf0(fid,'... ready!\n'); |
|
0 commit comments