-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMolecule.js
More file actions
executable file
·66 lines (53 loc) · 1.39 KB
/
Molecule.js
File metadata and controls
executable file
·66 lines (53 loc) · 1.39 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function Sugar(name) {
this.n = name;
this.bonds = [null, null, null, null, null, null];
this.adj = [null, null, null, null, null, null];
}
Sugar.prototype = {
constructor Sugar,
idString: function () {
bondCount = 0;
bondType = [];
for i in xrange(this.bonds.length):
if this.bonds[i]:
bondCount += 1;
bondType.push(this.bonds[i] + str(i+1));
string = str(bondCount) + this.n;
for bond in bondType:
string += bond;
string += '-';
return string;
}
};
function Molecule() {
this.root = null;
this.ident = "Molecule: ";
}
Molecule.prototype = {
//restore constructor
constructor: Molecule,
addRoot: function (sugar) {
this.root = sugar;
}
addBond: function (parent, child, pos, bond) {
parent.adj[pos] = child;
parent.bonds[pos] = bond;
}
genId: function () {
this.genIdHelper(this.root);
return this.ident;
}
genIdHelper: function (node) {
this.ident += node.idString();
hasChild = false;
for i in xrange(node.adj.length):
if node.adj[i]:
hasChild = true;
this.genIdHelper(node.adj[i]);
if not hasChild:
this.ident += '/';
}
printName: function () {
return this.ident;
}
};