|
|
Line 1: |
Line 1: |
− | {| class ="wikitable" | + | {{MassBank/Matrix|data= |
− | {{#replace:
| + | &&C7H14NO3&&C7H11O3&&C5H8NO2&&C4H8NO2&&C7H13&&C4H10NO&&C6H11&&C6H7&&C4H7O&&C5H9&&C3H8N&&C4H7&& |
− | {{#lua:
| + | C7H14NO3:C7H11O3 |
− | function atomicNum(atom, str)
| + | C7H14NO3:C4H8NO2 C4H10NO C3H8N |
− | if (str == "") then return 0; end
| + | C4H10NO: C3H8NP |
− | if (str == atom) then return 1; end
| + | }} |
− | return tonumber(string.sub(str,2));
| + | |
− | end
| + | |
| | | |
− | function mass(str)
| |
− | local c,h,n,o=string.match(str,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)");
| |
− | c = atomicNum("C", c) * 12;
| |
− | h = atomicNum("H", h);
| |
− | n = atomicNum("N", n) * 14;
| |
− | o = atomicNum("O", o) * 16;
| |
− | return c + h + n + o;
| |
− | end
| |
− |
| |
− | function diff(str1, str2)
| |
− | ---computes str1 - str2. If negative, returns nil.---
| |
− | local c1,h1,n1,o1=string.match(str1,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)");
| |
− | local c2,h2,n2,o2=string.match(str2,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)");
| |
− | c1 = atomicNum("C", c1);
| |
− | h1 = atomicNum("H", h1);
| |
− | n1 = atomicNum("N", n1);
| |
− | o1 = atomicNum("O", o1);
| |
− | c2 = atomicNum("C", c2);
| |
− | h2 = atomicNum("H", h2);
| |
− | n2 = atomicNum("N", n2);
| |
− | o2 = atomicNum("O", o2);
| |
− | if (c2 > c1) then return nil; else c1 = c1 - c2; end
| |
− | if (h2 > h1) then return nil; else h1 = h1 - h2; end
| |
− | if (n2 > n1) then return nil; else n1 = n1 - n2; end
| |
− | if (o2 > o1) then return nil; else o1 = o1 - o2; end
| |
− | local ret = "";
| |
− | if (c1 > 1) then ret = ret .. "C" .. c1;
| |
− | else if (c1 == 1) then ret = ret .. "C"; end end
| |
− | if (h1 > 1) then ret = ret .. "H" .. h1;
| |
− | else if (h1 == 1) then ret = ret .. "H"; end end
| |
− | if (n1 > 1) then ret = ret .. "N" .. n1;
| |
− | else if (n1 == 1) then ret = ret .. "N"; end end
| |
− | if (o1 > 1) then ret = ret .. "O" .. o1;
| |
− | else if (o1 == 1) then ret = ret .. "O"; end end
| |
− | return ret;
| |
− | end
| |
− |
| |
− | local ruler;
| |
− | local fragments = {};
| |
− | local x, y;
| |
− | for line in stdin:gmatch("[%S ,]+") do
| |
− | if (string.find(line, "=") == nil) then ruler = line;
| |
− | else ---register fragments---
| |
− | head, tail = string.match(line, "([CHNO0-9]+) *= *([CHNO0-9 ]+)");
| |
− | y = {};
| |
− | for x in string.gmatch(tail,"[CHNO0-9]+") do
| |
− | y[x] = x;
| |
− | end
| |
− | fragments[head] = y;
| |
− | end
| |
− | end
| |
− | local axis = {};
| |
− | local i = 1;
| |
− | for formula in string.gmatch(ruler, "([%S]+)") do
| |
− | axis[i] = formula;
| |
− | i = i + 1;
| |
− | end
| |
− | print("#-\n");
| |
− | print("## sample \n");
| |
− | for i=1, table.getn(axis) do
| |
− | print("#style='text-align:right'# " .. mass(axis[i]) .. "<br/>" .. axis[i]);
| |
− | end
| |
− | for i=1, table.getn(axis) do
| |
− | print("#-\n");
| |
− | print("#style='text-align:right'# " .. mass(axis[i]) .. "<br/>" .. axis[i]);
| |
− | for j=1, table.getn(axis) do
| |
− | if (j < i) then
| |
− | s = diff(axis[j],axis[i]);
| |
− | if (s == nil)
| |
− | then print('#style="background-color:gray"# ');
| |
− | else
| |
− | if (fragments[axis[j]] ~= nil and fragments[axis[j]][axis[i]] ~= nil) then
| |
− | print('#style="background-color:orange"# ' .. s);
| |
− | else print('## ' .. s); end
| |
− | end
| |
− | else print('#style="background-color:white"# ');
| |
− | end
| |
− | end
| |
− | print("\n");
| |
− | end
| |
− | |
| |
− | C7H14NO3 C7H11O3 C5H8NO2 C4H8NO2 C7H13 C4H10NO C6H11 C6H7 C4H7O C5H9 C3H8N C4H7
| |
− | C7H14NO3 = C7H11O3 C4H8NO2 C4H10NO C3H8N
| |
− | C4H10NO = C3H8N
| |
− | }}
| |
− | |#|{{#bar:}}}}
| |
− | |}
| |
| | | |
| <!---- | | <!---- |