Skip to content

Commit

Permalink
encoding debug & upgrade
Browse files Browse the repository at this point in the history
encoding debug & upgrade
  • Loading branch information
dadaoqiuzhi committed Feb 8, 2024
1 parent fc85809 commit b80b58e
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 39 deletions.
7 changes: 4 additions & 3 deletions chemi_mechanism/Deconvolu_SysConvert.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
%This function is used to transform a number to decimal system.
function num_10base = Deconvolu_SysConvert(given_num_char,base)
num_table = {'1','2','3','4','5','6','7','8','9','a','b','c','d',...
'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
num_table = {'0','1','2','3','4','5','6','7','8','9',...
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',...
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
[~,matches] = strsplit(given_num_char,num_table,'CollapseDelimiters',false);
num_10base = 0;
for i = 1:length(matches)
[~,num_true] = ismember(matches{i},num_table);
num_10base = num_10base + num_true*base^(length(matches)-i);
num_10base = num_10base + (num_true-1)*base^(length(matches)-i);
end
end
17 changes: 11 additions & 6 deletions chemi_mechanism/SysConvert.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
%scrit file name SysConvert
%purpose:
%This function is used to convert a given number into an expected number
%system. ASCII is used
%system. ASCII is used.
function target_num=SysConvert(given_num,base)
if given_num==round(given_num) && given_num>0 && base==round(base) && base>0
if base > 62
error('The base for atom id encoding is larger than 62, unrecognizable char except 0-9£¬a-z£¬A-Z may be used. Please check it')
end
if given_num == round(given_num) && given_num > 0 && base == round(base) && base > 0
control=1;remaindermat=[];
else
control=0;
error('\nConversion of number system should be with an integer!!!');
error('\nThe base and atom id must be positive integer!');
end

while control
Expand All @@ -24,12 +26,15 @@

atomid='';i=size(remaindermat,1);
while i
if remaindermat(i,2)<=9
if remaindermat(i,2) <= 9 %0-9
atomid=strcat(atomid,num2str(remaindermat(i,2)));
else
elseif remaindermat(i,2) > 9 && remaindermat(i,2) <= 35 %a-z
atomid=strcat(atomid,char(remaindermat(i,2)+87));
elseif remaindermat(i,2) > 35 && remaindermat(i,2) <= 61 %A-Z
atomid=strcat(atomid,char(remaindermat(i,2)+29));
end
i=i-1;
end

target_num=atomid;

30 changes: 29 additions & 1 deletion chemi_mechanism/car_mdf_filemaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,35 @@
elementname=eleswap{lib,2};
end
atomid_conv=SysConvert(tarBOinform{readline,1},base);
atomname=strcat(elementname,atomid_conv);
if elemax==2
if formatout==1 || formatout==2
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 3843>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
elseif elemax==1
if formatout==1 || formatout==2
if 14776335>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
end

[trjrow,~]=size(trjdata);tartrjdata=[];
for i=1:trjrow
Expand Down
48 changes: 28 additions & 20 deletions chemi_mechanism/chemi_mechanism.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,61 +69,69 @@
if elemax==2
if formatout==1 || formatout==2
fprintf('\nDifferent number system is adopted according to the atom number (ASCII)\n');
if 262143>=atomnum && atomnum>32767
fprintf('64 base number system is recommended for atom id');base=64;
if 238327>=atomnum && atomnum>32767
fprintf('62 base number system is recommended for atom id');base=62;
elseif 32767>=atomnum && atomnum>4095
fprintf('32 base number system is recommended for atom id');base=32;
elseif 4095>=atomnum && atomnum>999
fprintf('16 base number system is recommended for atom id');base=16;
elseif 999>=atomnum
fprintf('10 base number system (decimalism) is recommended for atom id');
elseif atomnum<0 || atomnum>32767
error('Atom number is less than 0 or larger than 262143. If larger, please check it and modify code accordingly!')
elseif atomnum<=916132831 || atomnum>238327
fprintf('\nAtom number is no more than 916132831 but larger than 238327. If larger, no element name is list in the number system, indicating 5 ASCII chars are used to encode\n')
base=62;
elseif atomnum > 916132831
error('Atom number exceeds 916132831, which can not be encoded. Please check it or contact the developer!')
end
elseif formatout==3
fprintf('\nDifferent number system is adopted according to the atom number (ASCII)\n');
if 65535>=atomnum && atomnum>16383
fprintf('256 base number system is recommended for atom id');base=256;
elseif 16383>=atomnum && atomnum>4095
fprintf('128 base number system is recommended for atom id');base=128;
elseif 4095>=atomnum && atomnum>1023
fprintf('64 base number system is recommended for atom id');base=64;
if 3843>=atomnum && atomnum>1023
fprintf('62 base number system is recommended for atom id');base=62;
elseif 1023>=atomnum && atomnum>255
fprintf('32 base number system is recommended for atom id');base=32;
elseif 255>=atomnum && atomnum>99
fprintf('16 base number system is recommended for atom id');base=16;
elseif 99>=atomnum
fprintf('10 base number system (decimalism) is recommended for atom id');
elseif atomnum<0 || atomnum>65535
error('Atom number is less than 0 or larger than 65535. If larger, please check it and modify code accordingly!')
elseif atomnum<=14776335 || atomnum>3843
fprintf('\nAtom number is no more than 14776335 but larger than 3843. If larger, no element name is list in the number system, indicating 4 ASCII chars are used to encode\n')
base=62;
elseif atomnum > 14776335
error('Atom number exceeds 14776335, which can not be encoded. Please check it or contact the developer!')
end
end
elseif elemax==1
if formatout==1 || formatout==2
fprintf('\nDifferent number system is adopted according to the atom number (ASCII)\n');
if 16777215>=atomnum && atomnum>1048575
fprintf('64 base number system is recommended for atom id');base=64;
if 14776335>=atomnum && atomnum>1048575
fprintf('62 base number system is recommended for atom id');base=62;
elseif 1048575>=atomnum && atomnum>65535
fprintf('32 base number system is recommended for atom id');base=32;
elseif 65535>=atomnum && atomnum>9999
fprintf('16 base number system is recommended for atom id');base=16;
elseif 9999>=atomnum
fprintf('10 base number system (decimalism) is recommended for atom id');
elseif atomnum<0 || atomnum>16777215
error('Atom number is less than 0 or larger than 16777215. If larger, please check it and modify code accordingly!')
elseif atomnum<=916132831 || atomnum>14776335
fprintf('\nAtom number is no more than 916132831 but larger than 14776335. If larger, no element name is list in the number system, indicating 5 ASCII chars are used to encode\n')
base=62;
elseif atomnum > 916132831
error('Atom number exceeds 916132831, which can not be encoded. Please check it or contact the developer!')
end
elseif formatout==3
fprintf('\nDifferent number system is adopted according to the atom number (ASCII)\n');
if 262143>=atomnum && atomnum>32767
fprintf('64 base number system is recommended for atom id');base=64;
if 238327>=atomnum && atomnum>32767
fprintf('64 base number system is recommended for atom id');base=62;
elseif 32767>=atomnum && atomnum>4095
fprintf('32 base number system is recommended for atom id');base=32;
elseif 4095>=atomnum && atomnum>999
fprintf('16 base number system is recommended for atom id');base=16;
elseif 999>=atomnum
fprintf('10 base number system (decimalism) is recommended for atom id');
elseif atomnum<0 || atomnum>262143
error('Atom number is less than 0 or larger than 262143. If larger, please check it and modify code accordingly!')
elseif atomnum<= 14776335 || atomnum>238327
fprintf('Atom number is no more than 14776335 but larger than 238327. If larger, no element name is list in the number system, indicating 4 ASCII chars are used to encode')
base=62;
elseif atomnum > 14776335
error('Atom number exceeds 14776335, which can not be encoded. Please check it or contact the developer!')
end
end
else
Expand Down
30 changes: 29 additions & 1 deletion chemi_mechanism/xyz_car_pdb_filemaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,35 @@
elementname=eleswap{lib,2};
end
atomid_conv=SysConvert(tarBOinform{readline,1},base);
atomname=strcat(elementname,atomid_conv);
if elemax==2
if formatout==1 || formatout==2
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 3843>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
elseif elemax==1
if formatout==1 || formatout==2
if 14776335>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
end

[trjrow,~]=size(trjdata);tartrjdata=[];
for i=1:trjrow
Expand Down
12 changes: 12 additions & 0 deletions lammpstrj2xyz_arc_pdb/Deconvolu_SysConvert.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%This function is used to transform a number to decimal system.
function num_10base = Deconvolu_SysConvert(given_num_char,base)
num_table = {'0','1','2','3','4','5','6','7','8','9',...
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',...
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
[~,matches] = strsplit(given_num_char,num_table,'CollapseDelimiters',false);
num_10base = 0;
for i = 1:length(matches)
[~,num_true] = ismember(matches{i},num_table);
num_10base = num_10base + (num_true-1)*base^(length(matches)-i);
end
end
17 changes: 11 additions & 6 deletions lammpstrj2xyz_arc_pdb/SysConvert.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
%scrit file name SysConvert
%purpose:
%This function is used to convert a given number into an expected number
%system. ASCII is used¡£
%system. ASCII is used.
function target_num=SysConvert(given_num,base)
if given_num==round(given_num) && given_num>0 && base==round(base) && base>0
if base > 62
error('The base for atom id encoding is larger than 62, unrecognizable char except 0-9£¬a-z£¬A-Z may be used. Please check it')
end
if given_num == round(given_num) && given_num > 0 && base == round(base) && base > 0
control=1;remaindermat=[];
else
control=0;
error('\nConversion of number system should be with an integer!!!');
error('\nThe base and atom id must be positive integer!');
end

while control
Expand All @@ -24,12 +26,15 @@

atomid='';i=size(remaindermat,1);
while i
if remaindermat(i,2)<=9
if remaindermat(i,2) <= 9 %0-9
atomid=strcat(atomid,num2str(remaindermat(i,2)));
else
elseif remaindermat(i,2) > 9 && remaindermat(i,2) <= 35 %a-z
atomid=strcat(atomid,char(remaindermat(i,2)+87));
elseif remaindermat(i,2) > 35 && remaindermat(i,2) <= 61 %A-Z
atomid=strcat(atomid,char(remaindermat(i,2)+29));
end
i=i-1;
end

target_num=atomid;

30 changes: 29 additions & 1 deletion lammpstrj2xyz_arc_pdb/xyz_arc_filemaker_speedupMOLE.m
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,35 @@
elementname=eleswap{lib,2};
end
atomid_conv=SysConvert(tarBOinform{trjreadline,1},base);
atomname=strcat(elementname,atomid_conv);
if elemax==2
if formatout==1 || formatout==2
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 3843>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
elseif elemax==1
if formatout==1 || formatout==2
if 14776335>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
end

[trjrow,~]=size(trjdata);tartrjdata=[];
for i=1:trjrow
Expand Down
30 changes: 29 additions & 1 deletion lammpstrj2xyz_arc_pdb/xyz_arc_pdb_filemaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,35 @@
elementname=eleswap{lib,2};
end
atomid_conv=SysConvert(tarBOinform{trjreadline,1},base);
atomname=strcat(elementname,atomid_conv);%
if elemax==2
if formatout==1 || formatout==2
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 3843>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
elseif elemax==1
if formatout==1 || formatout==2
if 14776335>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
elseif formatout==3
if 238327>=atomnum
atomname=strcat(elementname,atomid_conv);
else
atomname=atomid_conv;
end
end
end

[trjrow,~]=size(trjdata);tartrjdata=[];
for i=1:trjrow
Expand Down

0 comments on commit b80b58e

Please sign in to comment.