-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathreaction.test.ts
More file actions
249 lines (223 loc) · 8.47 KB
/
reaction.test.ts
File metadata and controls
249 lines (223 loc) · 8.47 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import { describe, expect, it } from 'vitest';
import { Molecule, Reaction } from '../lib/index.js';
describe('Reaction class', () => {
it('work as a constructor (no name)', () => {
const reaction = new Reaction();
expect(reaction.isEmpty()).toBe(true);
expect(reaction.getName()).toBe('');
});
it('work as a constructor (null name)', () => {
const reaction = new Reaction(null);
expect(reaction.isEmpty()).toBe(true);
expect(reaction.getName()).toBe('');
});
it('work as a constructor (initial name)', () => {
const reaction = new Reaction('NAME');
expect(reaction.isEmpty()).toBe(true);
expect(reaction.getName()).toBe('NAME');
});
it('should create an empty Reaction', () => {
const reaction = Reaction.create();
expect(reaction.getReactants()).toBe(0);
expect(reaction.getProducts()).toBe(0);
expect(reaction.getCatalysts()).toBe(0);
});
it('toRXN options', () => {
const reaction = Reaction.create();
expect(reaction.getReactants()).toBe(0);
expect(reaction.getProducts()).toBe(0);
expect(reaction.getCatalysts()).toBe(0);
const rxn = reaction.toRxn();
expect(rxn).toMatchSnapshot();
const reaction2 = Reaction.fromRxn(rxn);
expect(reaction2.getReactants()).toBe(0);
expect(reaction2.getProducts()).toBe(0);
expect(reaction2.getCatalysts()).toBe(0);
const rxn2 = reaction2.toRxn({
keepIdCode: true,
programName: 'Hello world!',
});
expect(rxn2).toMatchSnapshot();
});
it('toRXN options keepIdCode one reagent', () => {
const reaction = Reaction.create();
const methane = Molecule.fromSmiles('C');
reaction.addReactant(methane);
expect(reaction.getReactants()).toBe(1);
expect(reaction.getProducts()).toBe(0);
expect(reaction.getCatalysts()).toBe(0);
const rxn = reaction.toRxn();
expect(rxn).toMatchSnapshot();
const reaction2 = Reaction.fromRxn(rxn);
expect(reaction2.getReactants()).toBe(1);
expect(reaction2.getProducts()).toBe(0);
expect(reaction2.getCatalysts()).toBe(0);
const rxn2 = reaction2.toRxn({
keepIdCode: true,
programName: 'Hello world!',
});
expect(rxn2).toMatchSnapshot();
});
it('toRXN options keepIdCode two reagents', () => {
const reaction = Reaction.create();
const methane = Molecule.fromSmiles('C');
const oxygen = Molecule.fromSmiles('O');
reaction.addReactant(methane);
reaction.addReactant(oxygen);
expect(reaction.getReactants()).toBe(2);
expect(reaction.getProducts()).toBe(0);
expect(reaction.getCatalysts()).toBe(0);
const rxn = reaction.toRxn();
expect(rxn).toMatchSnapshot();
const reaction2 = Reaction.fromRxn(rxn);
expect(reaction2.getReactants()).toBe(2);
expect(reaction2.getProducts()).toBe(0);
expect(reaction2.getCatalysts()).toBe(0);
const rxn2 = reaction2.toRxn({
keepIdCode: true,
programName: 'Hello world!',
});
expect(rxn2).toMatchSnapshot();
});
it('toRXN options keepIdCode one product', () => {
const reaction = Reaction.create();
const carbonDioxide = Molecule.fromSmiles('O=C=O');
reaction.addProduct(carbonDioxide);
expect(reaction.getReactants()).toBe(0);
expect(reaction.getProducts()).toBe(1);
expect(reaction.getCatalysts()).toBe(0);
const rxn = reaction.toRxn();
expect(rxn).toMatchSnapshot();
const reaction2 = Reaction.fromRxn(rxn);
expect(reaction2.getReactants()).toBe(0);
expect(reaction2.getProducts()).toBe(1);
expect(reaction2.getCatalysts()).toBe(0);
const rxn2 = reaction2.toRxn({
keepIdCode: true,
programName: 'Hello world!',
});
expect(rxn2).toMatchSnapshot();
});
it('toRXN options keepIdCode two products', () => {
const reaction = Reaction.create();
const carbon = Molecule.fromSmiles('C');
reaction.addProduct(carbon);
const oxygen = Molecule.fromSmiles('O');
reaction.addProduct(oxygen);
expect(reaction.getReactants()).toBe(0);
expect(reaction.getProducts()).toBe(2);
expect(reaction.getCatalysts()).toBe(0);
const rxn = reaction.toRxn();
expect(rxn).toMatchSnapshot();
const reaction2 = Reaction.fromRxn(rxn);
expect(reaction2.getReactants()).toBe(0);
expect(reaction2.getProducts()).toBe(2);
expect(reaction2.getCatalysts()).toBe(0);
const rxn2 = reaction2.toRxn({
keepIdCode: true,
programName: 'Hello world!',
});
expect(rxn2).toMatchSnapshot();
});
it('should be able to add molecules', () => {
const reaction = Reaction.create();
const reactant1 = Molecule.fromSmiles('C');
const reactant2 = Molecule.fromSmiles('O');
const product = Molecule.fromSmiles('CO');
const catalyst = Molecule.fromSmiles('[Fe]');
reaction.addReactant(reactant1);
reaction.addReactant(reactant2);
reaction.addProduct(product);
reaction.addCatalyst(catalyst);
expect(reaction.getReactants()).toBe(2);
expect(reaction.getProducts()).toBe(1);
expect(reaction.getCatalysts()).toBe(1);
});
it('should be able to create from array', () => {
const reactant1 = Molecule.fromSmiles('C');
const reactant2 = Molecule.fromSmiles('O');
const product = Molecule.fromSmiles('CO');
const reaction = Reaction.fromMolecules([reactant1, reactant2, product], 2);
expect(reaction.getReactants()).toBe(2);
expect(reaction.getProducts()).toBe(1);
});
it('should work with SMILES', () => {
const reactant1 = Molecule.fromSmiles('C');
const reactant2 = Molecule.fromSmiles('O');
const product = Molecule.fromSmiles('CO');
const catalyst = Molecule.fromSmiles('[Fe]');
const reaction = Reaction.fromMolecules([reactant1, reactant2, product], 2);
reaction.addCatalyst(catalyst);
const smiles = reaction.toSmiles();
expect(smiles).toBe('C.O>[Fe]>CO');
const newReaction = Reaction.fromSmiles(smiles);
expect(newReaction.getReactants()).toBe(1);
expect(newReaction.getProducts()).toBe(1);
expect(newReaction.getCatalysts()).toBe(1);
expect(newReaction.getReactant(0).toIsomericSmiles()).toBe('C.O');
expect(newReaction.getProduct(0).toIsomericSmiles()).toBe('CO');
expect(newReaction.getCatalyst(0).toIsomericSmiles()).toBe('[Fe]');
});
it('should load and create RXN files', () => {
const rxn = `$RXN
JME Molecular Editor
2 2
$MOL
CC(C)C(=O)Cl.CCNCC>>CCNCC.Cl
JME 2017-11-16 Fri Nov 09 13:48:29 GMT+100 2018
6 5 0 0 0 0 0 0 0 0999 V2000
2.4460 0.0000 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
2.4350 1.4040 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.6307 2.1060 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
1.2175 2.1060 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2066 3.5100 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 1.4150 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
2 3 2 0 0 0 0
2 4 1 0 0 0 0
4 5 1 0 0 0 0
4 6 1 0 0 0 0
M END
$MOL
CC(C)C(=O)Cl.CCNCC>>CCNCC.Cl
JME 2017-11-16 Fri Nov 09 13:48:29 GMT+100 2018
5 4 0 0 0 0 0 0 0 0999 V2000
2.4467 0.0000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
3.6508 0.7072 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2233 0.7072 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.8550 0.0191 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0191 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 1 0 0 0 0
2 4 1 0 0 0 0
3 5 1 0 0 0 0
M END
$MOL
CC(C)C(=O)Cl.CCNCC>>CCNCC.Cl
JME 2017-11-16 Fri Nov 09 13:48:29 GMT+100 2018
5 4 0 0 0 0 0 0 0 0999 V2000
2.4467 0.0000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
3.6508 0.7072 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2233 0.7072 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.8550 0.0191 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0191 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 1 0 0 0 0
2 4 1 0 0 0 0
3 5 1 0 0 0 0
M END
$MOL
CC(C)C(=O)Cl.CCNCC>>CCNCC.Cl
JME 2017-11-16 Fri Nov 09 13:48:29 GMT+100 2018
1 0 0 0 0 0 0 0 0 0999 V2000
0.0000 0.0000 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
M END
`;
const reaction = Reaction.fromRxn(rxn);
expect(reaction.getReactants()).toBe(2);
expect(reaction.getProducts()).toBe(2);
expect(reaction.getCatalysts()).toBe(0);
expect(reaction.toRxn()).toMatchSnapshot();
expect(reaction.toRxnV3()).toMatchSnapshot();
});
});