Skip to content

Commit

Permalink
Merge pull request #8 from privrja/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
privrja authored Jan 27, 2019
2 parents 08249ce + fe2206a commit 28100ea
Show file tree
Hide file tree
Showing 35 changed files with 415 additions and 122 deletions.
157 changes: 127 additions & 30 deletions dist/smiles-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6907,9 +6907,11 @@ var Graph = function () {
key: 'startDfs',
value: function startDfs(vertex, smiles) {
var stackSmiles = [];
this.first = vertex.id;
this.dfsSmiles(vertex, stackSmiles);
stackSmiles = Graph.removeUnnecessaryParentheses(stackSmiles);
var smile = Graph.removeUnnecessaryNumbers(stackSmiles.join(""));
smile = Graph.repairNumbers(smile);
if (smile.length !== 0) {
smiles.push(smile);
}
Expand All @@ -6932,16 +6934,36 @@ var Graph = function () {
return;
}

if (vertex.value.isPartOfAromaticRing) {
stackSmiles.push(vertex.value.element.toLowerCase() + Graph.smilesNumbersAdd(vertex));
if (this.first === vertex.id && vertex.value.element === "C") {
stackSmiles.push("O");
}

if (vertex.value.bracket) {
stackSmiles.push("[");
Graph.printVertexValue(stackSmiles, vertex);
if (vertex.value.bracket.hcount > 0) {
stackSmiles.push('H');
if (vertex.value.bracket.hcount > 1) {
stackSmiles.push(vertex.value.bracket.hcount);
}
}
if (vertex.value.bracket.charge > 0) {
stackSmiles.push('+');
stackSmiles.push(vertex.value.bracket.charge);
} else if (vertex.value.bracket.charge < 0) {
stackSmiles.push(vertex.value.bracket.charge);
}
stackSmiles.push("]");
} else {
stackSmiles.push(vertex.value.element + Graph.smilesNumbersAdd(vertex));
Graph.printVertexValue(stackSmiles, vertex);
}
stackSmiles.push(Graph.smilesNumbersAdd(vertex));

vertex.vertexState = VertexState.VALUES.OPEN;
for (var i = 0; i < vertex.edges.length; ++i) {
var edge = this.edges[vertex.edges[i]];
if (edge.isDecay) {
if (vertex.value.element === "C") {
if (vertex.value.element === "C" && vertex.id !== this.first) {
stackSmiles.push("(");
stackSmiles.push("O");
stackSmiles.push(")");
Expand All @@ -6956,13 +6978,6 @@ var Graph = function () {
}
vertex.vertexState = VertexState.VALUES.CLOSED;
}

/**
* Remove numbers which is neighbours in SMILES notation -> need to perform in cyclic structures
* @param {String} smiles SMILES
* @return {String} repaired SMILES
*/

}], [{
key: 'getConnectedComponents',
value: function getConnectedComponents(adjacencyMatrix) {
Expand Down Expand Up @@ -7054,6 +7069,22 @@ var Graph = function () {
Graph._ccGetDfs(v, visited, adjacencyMatrix, component);
}
}
}, {
key: 'printVertexValue',
value: function printVertexValue(stackSmiles, vertex) {
if (vertex.value.isPartOfAromaticRing) {
stackSmiles.push(vertex.value.element.toLowerCase());
} else {
stackSmiles.push(vertex.value.element);
}
}

/**
* Remove numbers which is neighbours in SMILES notation -> need to perform in cyclic structures
* @param {String} smiles SMILES
* @return {String} repaired SMILES
*/

}, {
key: 'removeUnnecessaryNumbers',
value: function removeUnnecessaryNumbers(smiles) {
Expand All @@ -7071,8 +7102,8 @@ var Graph = function () {
var number = _step.value;

var first = this.findFirst(smiles, number);
var second = this.findSecond(smiles, first, number);
var tmpRange = this.removeRangeLast(smiles, first, second);
var second = this.findSecond(smiles, first + 1, number);
var tmpRange = this.removeRangeLast(smiles, first, second, number);
smiles = this.repairSmiles(smiles, tmpRange, first, second, number);
}
} catch (err) {
Expand Down Expand Up @@ -7106,9 +7137,15 @@ var Graph = function () {

}, {
key: 'removeNumbers',
value: function removeNumbers(smiles, first, second) {
smiles = smiles.slice(0, first) + smiles.slice(first + 1);
return smiles.slice(0, second - 1) + smiles.slice(second);
value: function removeNumbers(smiles, first, second, number) {
if (number > 9) {
var numLength = number.toString().length;
smiles = smiles.slice(0, first - 1) + smiles.slice(first + numLength);
return smiles.slice(0, second - 2 - numLength) + smiles.slice(second - 1);
} else {
smiles = smiles.slice(0, first) + smiles.slice(first + 1);
return smiles.slice(0, second - 1) + smiles.slice(second);
}
}

/**
Expand All @@ -7126,7 +7163,7 @@ var Graph = function () {
value: function repairSmiles(smiles, tmpRange, first, second, number) {
var pattern = new RegExp("^(Br|Cl|[BCNOPSFIbcnopsfi])$");
if (pattern.test(tmpRange)) {
return this.removeNumbers(smiles, first, second);
return this.removeNumbers(smiles, first, second, number);
}
var patternOrg = new RegExp("^(Br|Cl|[BCNOPSFIbcnopsfi])");
if (patternOrg.test(tmpRange)) {
Expand All @@ -7137,7 +7174,7 @@ var Graph = function () {
if (tmpRange[0] === '(') {
tmpRange = tmpRange.substring(1);
if (pattern.test(tmpRange)) {
return this.removeNumbers(smiles, first, second);
return this.removeNumbers(smiles, first, second, number);
}
var leftBrackets = 1;
var rightBrackets = 0;
Expand Down Expand Up @@ -7173,8 +7210,12 @@ var Graph = function () {

}, {
key: 'removeRangeLast',
value: function removeRangeLast(smiles, first, second) {
return smiles.substring(first + 1, second);
value: function removeRangeLast(smiles, first, second, number) {
if (number > 9) {
return smiles.substring(first + number.toString().length, second - 1);
} else {
return smiles.substring(first + 1, second);
}
}

/**
Expand All @@ -7190,6 +7231,18 @@ var Graph = function () {
for (var index = 0; index < smiles.length; ++index) {
if (!isNaN(smiles[index])) {
numbers.add(smiles[index]);
} else if (smiles[index] === '%') {
index++;
var num = "";
while (!isNaN(smiles[index])) {
num += smiles[index];
index++;
if (index >= smiles.length) {
break;
}
}
index--;
numbers.add(num);
}
}
return numbers;
Expand All @@ -7205,11 +7258,7 @@ var Graph = function () {
}, {
key: 'findFirst',
value: function findFirst(smiles, number) {
for (var index = 0; index < smiles.length; ++index) {
if (smiles[index] == number) {
return index;
}
}
return smiles.indexOf(number);
}

/**
Expand All @@ -7223,12 +7272,11 @@ var Graph = function () {
}, {
key: 'findSecond',
value: function findSecond(smiles, from, number) {
for (var index = from + 1; index < smiles.length; ++index) {
if (smiles[index] == number) {
return index;
}
var result = smiles.indexOf(number, from);
if (result === -1) {
throw "Not Found";
}
throw "Not Found";
return result;
}
}, {
key: 'smilesNumbersAdd',
Expand Down Expand Up @@ -7260,6 +7308,55 @@ var Graph = function () {
value: function getProperVertex(vertexId, sourceId, targetId) {
if (vertexId === sourceId) return targetId;else return sourceId;
}
}, {
key: 'repairNumbers',
value: function repairNumbers(smiles) {
var numbers = Array.from(this.getNumbers(smiles));
numbers.sort(function (a, b) {
return b - a;
});

var index = 1;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;

try {
for (var _iterator2 = numbers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var number = _step2.value;

if (index === number) {
continue;
}
var first = this.findFirst(smiles, number);
if (number > 9) {
smiles = smiles.slice(0, first - 1) + index + smiles.slice(first + number.toString().length);
var second = this.findSecond(smiles, first + 1, number);
smiles = smiles.slice(0, second - 1) + index + smiles.slice(second + number.toString().length);
} else {
smiles = smiles.slice(0, first) + index + smiles.slice(first + 1);
var _second = this.findSecond(smiles, first + 1, number);
smiles = smiles.slice(0, _second) + index + smiles.slice(_second + 1);
}
index++;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}

return smiles;
}

/**
* Remove unnecessary parentheses from SMILES
Expand Down
2 changes: 1 addition & 1 deletion dist/smiles-drawer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/smiles-drawer.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/ArrayHelper.html
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/ArrayHelper.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ <h1 class="page-title">ArrayHelper.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/Atom.html
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ <h4 class="name" id="restoreRings"><span class="type-signature"></span>restoreRi
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/Atom.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ <h1 class="page-title">Atom.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/CanvasWrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -3718,7 +3718,7 @@ <h5>Parameters:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/CanvasWrapper.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ <h1 class="page-title">CanvasWrapper.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/DecayPoint.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1 class="page-title">DecayPoint.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/Drawer.html
Original file line number Diff line number Diff line change
Expand Up @@ -10711,7 +10711,7 @@ <h5>Parameters:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/Drawer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -3203,7 +3203,7 @@ <h1 class="page-title">Drawer.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/Edge.html
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ <h5>Parameters:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion doc/Edge.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h1 class="page-title">Edge.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 23 2019 16:51:02 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jan 27 2019 14:35:28 GMT+0100 (Střední Evropa (běžný čas)) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
Loading

0 comments on commit 28100ea

Please sign in to comment.