function CollectFragmUMiu()
% constructs UMiu using fragment of ready models only.
% Instructions for new UMiu design are within
% LevInfinite\Config\ToJoin.txt.

global Type InfTable AtomTypes 
global  UqType iUqType Ucells Qtypes AtomMasses

UqType = [];
iUqType = 0;
Ucells = [];
% Qtypes = [];
% AtomMasses = [];
% Shelter joint-globals
UqType_joint  = UqType;
iUqType_joint  = iUqType;
Ucells_joint  = Ucells;
% Qtypes_joint  =  Qtypes;  
% AtomMasses_joint  =  AtomMasses;


fragm_connect = zeros(2,4);
filename = 'C:\LevInfinite\Config\ToJoin.txt';
fid = fopen(filename,'rt');
s = fgetl(fid);
fragm1name = strtok(s);
s = fgetl(fid);
fragm_connect(1,1) = str2double(strtok(s));
s = fgetl(fid);
fragm_connect(1,2) = str2double(strtok(s));
s = fgetl(fid);
fragm_connect(1,3) = str2double(strtok(s));
s = fgetl(fid);
fragm_connect(1,4) = str2double(strtok(s));
s = fgetl(fid);
fragm2name = strtok(s);
s = fgetl(fid);
fragm_connect(2,1) = str2double(strtok(s));
s = fgetl(fid);
fragm_connect(2,2) = str2double(strtok(s));
s = fgetl(fid);
fragm_connect(2,3) = str2double(strtok(s));
s = fgetl(fid);
fragm_connect(2,4) = str2double(strtok(s));
s = fgetl(fid);
jointname = strtok(s);
s = fgetl(fid);
use_fr1_UMiu = strtok(s);
if use_fr1_UMiu == 'y'
   use_fr1_UMiu = 1;
else
   use_fr1_UMiu = 0;
end % if
s = fgetl(fid);
use_fr2_UMiu = strtok(s);
if use_fr2_UMiu == 'y'
   use_fr2_UMiu = 1;
else
   use_fr2_UMiu = 0;
end % if
fclose(fid);

filename = 'C:\LevInfinite\Config\Molecules.ini';
fid = fopen(filename,'rt');
molfolder = fgetl(fid);
fclose(fid);

if use_fr1_UMiu
    modelfolder = strcat(molfolder,fragm1name);
    modelfolder = strcat(modelfolder,'\');

    fullname = strcat(modelfolder,'Umiu.mat');
    load(fullname);

    % Add to joint-globals
    UqType_joint = [UqType_joint, UqType];
    iUqType_joint = iUqType_joint + iUqType;
    Ucells_joint = [Ucells_joint, Ucells];
%     Qtypes_joint  = [Qtypes_joint, Qtypes];
%     AtomMasses_joint = [AtomMasses_joint; AtomMasses];
end % if use_fr1_UMiu

if use_fr2_UMiu
    modelfolder = strcat(molfolder,fragm2name);
    modelfolder = strcat(modelfolder,'\');

    fullname = strcat(modelfolder,'Umiu.mat');
    load(fullname);


    % Add to _joint-globals
    UqType_joint = [UqType_joint, UqType];
    iUqType_joint = iUqType_joint + iUqType;
    Ucells_joint = [Ucells_joint, Ucells];
%     Qtypes_joint  = [Qtypes_joint, Qtypes];
%     AtomMasses_joint = [AtomMasses_joint; AtomMasses];
end % if use_fr2_UMiu

modelfolder = strcat(molfolder,jointname);
modelfolder = strcat(modelfolder,'\');

fullname = strcat(modelfolder,'Bstruct.mat');
load(fullname);

nAtoms = InfTable(1);
AtomMasses = zeros(nAtoms,1);
for i = 1:nAtoms
    AtomMasses(i) = Type(AtomTypes(i)).Mass;
end % i

nBonds = InfTable(2);
nAlphas = InfTable(3);
nGammas = InfTable(4);
nRos = InfTable(5);
nHis = InfTable(6);
n = InfTable(7);
Qtypes = char([1:n]);
iu = 0;
for i = 1:nBonds
    iu = iu + 1;
    Qtypes(iu) = 'q';
end % i
if nAlphas > 0
for i = 1:nAlphas
    iu = iu + 1;
    Qtypes(iu) = 'a';
end % i
end % if nAlphas > 0
if nGammas > 0
for i = 1:nGammas
    iu = iu + 1;
    Qtypes(iu) = 'g';
end % i
end % if nGammas > 0
if nRos > 0
for i = 1:nRos
    iu = iu + 1;
    Qtypes(iu) = 'r';
end % i
end % if nRos > 0
if nHis > 0
for i = 1:nHis
    iu = iu + 1;
    Qtypes(iu) = 'h';
end % i
end % if nHis > 0

UqType  = UqType_joint;
iUqType  = iUqType_joint;
clear global Ucells
global Ucells
Ucells  = Ucells_joint;

fullname = strcat(modelfolder,'Umiu.mat');
file = fullname;
save(file, 'UqType', 'iUqType', 'Ucells', 'Qtypes', 'AtomMasses');  

