-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (70 loc) · 2.07 KB
/
index.js
File metadata and controls
80 lines (70 loc) · 2.07 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
import { appendChangeCustomLabelPosition } from './appendChangeCustomLabelPosition.js';
import { appendGetNextCustomAtomLabel } from './appendGetNextCustomAtomLabel.js';
import { extendFromMolfile } from './extendFromMolfile.js';
import { extendToMolfile } from './extendToMolfile.js';
import { extendToRxn } from './extendToRxn.js';
export function extendOCL(OCL) {
const { ConformerGenerator, ForceFieldMMFF94, Molecule, Reaction } = OCL;
ConformerGenerator.prototype.molecules = function* molecules() {
let nextConformer;
while ((nextConformer = this.getNextConformerAsMolecule()) !== null) {
yield nextConformer;
}
};
const defaultMinimiseOptions = {
maxIts: 4000,
gradTol: 1e-4,
funcTol: 1e-6,
};
const _minimise = ForceFieldMMFF94.prototype._minimise;
delete ForceFieldMMFF94.prototype._minimise;
ForceFieldMMFF94.prototype.minimise = function minimise(options) {
options = { ...defaultMinimiseOptions, ...options };
return _minimise.call(
this,
options.maxIts,
options.gradTol,
options.funcTol,
);
};
appendChangeCustomLabelPosition(Molecule);
appendGetNextCustomAtomLabel(Molecule);
extendFromMolfile(Molecule);
extendToMolfile(Molecule);
extendToRxn(Reaction, Molecule);
function parseMoleculeFromText(text) {
// Empty input
if (!text) {
return null;
}
// Molfile
if (text.includes('V2000') || text.includes('V3000')) {
return Molecule.fromMolfile(text);
}
// SMILES
try {
return Molecule.fromSmiles(text);
} catch {
// Ignore error.
}
// ID code
try {
return Molecule.fromIDCode(text);
} catch {
// Ignore error.
}
return null;
}
Molecule.fromText = function fromText(text) {
const molecule = parseMoleculeFromText(text);
if (molecule && molecule.getAllAtoms() > 0) {
return molecule;
}
return null;
};
// For npellet/visualizer, that needs to handle multiple instances of OCL
// with openchemlib-utils.
Molecule.prototype.getOCL = function getOCL() {
return OCL;
};
}