-
Notifications
You must be signed in to change notification settings - Fork 0
/
kemi.mpl
47 lines (39 loc) · 1.42 KB
/
kemi.mpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Kemi := module()
description "For kemi.";
option package;
export load, M, afstem, tabular, m,n;
local libLoad, classPath, elementsPath, libM, libAfstem;
afstem := proc(leftSide, rightSide, depth:=50)
local side1 := String(leftSide);
local side2 := String(rightSide);
local result := libAfstem(side1, side2, depth);
return parse(result)
end proc;
M := proc(input)
return libM(String(input))
end proc;
m := proc(mol, formelEnhed)
local molecule := M(formelEnhed);
return mol*molecule;
end proc;
n := proc(grams, formelEnhed)
local molecule := M(formelEnhed);
return grams/molecule;
end proc;
load := proc()
local mapleBasePath := kernelopts(mapledir);
local libPath := cat(mapleBasePath,"/data/kemi/kemi.jar");
libM := define_external('M', CLASS = "com.oscarspalk.kemi.Kemi", CLASSPATH = libPath, JAVA, 'molecule'::string, 'RETURN'::double);
libLoad := define_external('load', CLASS = "com.oscarspalk.kemi.Kemi", CLASSPATH = libPath, JAVA, 'path'::string, 'RETURN'::string);
libAfstem := define_external('afstem', CLASS = "com.oscarspalk.kemi.Kemi", CLASSPATH = libPath, JAVA, 'leftSide'::string,'rightSide'::string, 'depth'::integer[4], 'RETURN'::string);
elementsPath := cat(mapleBasePath, "/data/kemi/elements.json");
libLoad(elementsPath);
return;
end proc;
local ModuleLoad, ModuleUnload;
ModuleLoad := proc()
load()
end proc;
ModuleUnload := proc()
end proc;
end module;