Skip to content

Commit

Permalink
Merge pull request #6 from privrja/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
privrja authored Jan 19, 2019
2 parents 0e79cdf + e25a36c commit e7cfd4e
Show file tree
Hide file tree
Showing 36 changed files with 2,080 additions and 235 deletions.
181 changes: 175 additions & 6 deletions dist/smiles-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5514,9 +5514,7 @@ var Drawer = function () {
}, {
key: 'buildBlockSmiles',
value: function buildBlockSmiles() {
var tmpSmiles = this.graph.buildSmiles();
console.log(tmpSmiles);
return tmpSmiles;
return this.graph.buildSmiles();
}

/**
Expand Down Expand Up @@ -5583,7 +5581,6 @@ var Drawer = function () {
this.drawEdges(this.opts.debug);
this.drawVertices(this.opts.debug);
this.canvasWrapper.reset();
console.log(this.graph);
}

/**
Expand Down Expand Up @@ -6918,8 +6915,9 @@ var Graph = function () {
var stackSmiles = [];
this.dfsSmiles(vertex, stackSmiles);
stackSmiles = Graph.removeUnnecessaryParentheses(stackSmiles);
if (stackSmiles.length !== 0) {
smiles.push(stackSmiles.join(""));
var smile = Graph.removeUnnecessaryNumbers(stackSmiles.join(""));
if (smile.length !== 0) {
smiles.push(smile);
}
}

Expand Down Expand Up @@ -6948,6 +6946,13 @@ 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 @@ -7039,6 +7044,170 @@ var Graph = function () {
Graph._ccGetDfs(v, visited, adjacencyMatrix, component);
}
}
}, {
key: 'removeUnnecessaryNumbers',
value: function removeUnnecessaryNumbers(smiles) {
if (smiles === null) {
return '';
}
try {
var numbers = this.getNumbers(smiles);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = numbers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var number = _step.value;

var first = this.findFirst(smiles, number);
var second = this.findSecond(smiles, first, number);
var tmpRange = this.removeRangeLast(smiles, first, second);
smiles = this.repairSmiles(smiles, tmpRange, first, second, number);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

return smiles;
} catch (ex) {
return smiles;
}
}

/**
* Remove unnecessary numbers from SMILES
* @param {String} smiles
* @param {Number} first
* @param {Number} second
* @return {*}
*/

}, {
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);
}

/**
* Reapair SMILES
* @param {String} smiles
* @param {String} tmpRange
* @param {Number} first
* @param {Number} second
* @param {Number} number
* @return {String|*}
*/

}, {
key: 'repairSmiles',
value: function repairSmiles(smiles, tmpRange, first, second, number) {
var pattern = new RegExp("^(Br|Cl|br|cl|[BCNOPSFIbcnopsfi])$");
if (pattern.test(tmpRange)) {
return this.removeNumbers(smiles, first, second);
}
var patternOrg = new RegExp("^(Br|Cl|br|cl|[BCNOPSFIbcnopsfi])");
if (patternOrg.test(tmpRange)) {
return smiles;
}

while (tmpRange.length !== 0) {
switch (tmpRange[0]) {
case '(':
tmpRange = tmpRange.substring(1);
if (pattern.test(tmpRange)) {
return this.removeNumbers(smiles, first, second);
}
break;
case ')':
tmpRange = tmpRange.substring(1);
return this.repairSmiles(smiles, tmpRange, first, second, number);
default:
tmpRange = tmpRange.substring(1);
break;
}
}
return smiles;
}
/**
* Substring in range and remove last Organic Subset
* @param smiles
* @param first
* @param second
* @return {string}
*/

}, {
key: 'removeRangeLast',
value: function removeRangeLast(smiles, first, second) {
return smiles.substr(first + 1, second - first - 1);
}

/**
* Get numbers from SMILES
* @param smiles
* @return {Set<Number>}
*/

}, {
key: 'getNumbers',
value: function getNumbers(smiles) {
var numbers = new Set();
for (var index = 0; index < smiles.length; ++index) {
if (!isNaN(smiles[index])) {
numbers.add(smiles[index]);
}
}
return numbers;
}

/**
* return index of first occurrence number
* @param smiles
* @param number
* @return {number}
*/

}, {
key: 'findFirst',
value: function findFirst(smiles, number) {
for (var index = 0; index < smiles.length; ++index) {
if (smiles[index] == number) {
return index;
}
}
}

/**
* return index of first occurrence number from index + 1
* @param smiles
* @param from range no including this point (from, Infinity) = [from + 1, Infinity)
* @param number
* @return {*}
*/

}, {
key: 'findSecond',
value: function findSecond(smiles, from, number) {
for (var index = from + 1; index < smiles.length; ++index) {
if (smiles[index] == number) {
return index;
}
}
throw "Not Found";
}
}, {
key: 'smilesNumbersAdd',
value: function smilesNumbersAdd(vertex) {
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.

4 changes: 2 additions & 2 deletions doc/ArrayHelper.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/ArrayHelper.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Atom.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Atom.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/CanvasWrapper.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/CanvasWrapper.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/DecayPoint.js.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions doc/Drawer.html

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions doc/Drawer.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Edge.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Edge.js.html

Large diffs are not rendered by default.

1,574 changes: 1,423 additions & 151 deletions doc/Graph.html

Large diffs are not rendered by default.

137 changes: 133 additions & 4 deletions doc/Graph.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Line.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Line.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/MathHelper.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/MathHelper.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Ring.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Ring.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/RingConnection.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/RingConnection.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/SSSR.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/SSSR.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Vector2.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Vector2.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Vertex.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/Vertex.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/VertexState.js.html

Large diffs are not rendered by default.

84 changes: 82 additions & 2 deletions doc/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,12 @@ A class representing the molecular graph.
* [.getConnectedComponentCount(adjacencyMatrix)](#Graph.getConnectedComponentCount) ⇒ <code>Number</code>
* [._ccCountDfs()](#Graph._ccCountDfs)
* [._ccGetDfs()](#Graph._ccGetDfs)
* [.removeUnnecessaryNumbers(smiles)](#Graph.removeUnnecessaryNumbers) ⇒ <code>String</code>
* [.repairSmiles(smiles, tmpRange, first, second, number)](#Graph.repairSmiles) ⇒ <code>String</code> &#124; <code>\*</code>
* [.removeRangeLast(smiles, first, second)](#Graph.removeRangeLast) ⇒ <code>string</code>
* [.getNumbers(smiles)](#Graph.getNumbers) ⇒ <code>Set.&lt;Number&gt;</code>
* [.findFirst(smiles, number)](#Graph.findFirst) ⇒ <code>number</code>
* [.findSecond(smiles, from, number)](#Graph.findSecond) ⇒ <code>\*</code>
* [.getProperVertex(vertexId, sourceId, targetId)](#Graph.getProperVertex) ⇒ <code>Number</code>
* [.removeUnnecessaryParentheses(stackRight)](#Graph.removeUnnecessaryParentheses) ⇒ <code>Array</code>
* [.removeParentheses(stack, end, literal,)](#Graph.removeParentheses)
Expand Down Expand Up @@ -2064,7 +2070,7 @@ Revert decay point value and update list of decay points when edge isn't decay p
<a name="Graph+buildSmiles"></a>

### graph.buildSmiles()
Build block of SMILES based on decay pointsDFS pass through graphif there is a ring need second DFS pass for right SMILES notation
Build block of SMILES based on decay pointsDFS pass through graphif there is a ring need second DFS pass for right SMILES notationbut the numbers are already setup in vertex.value.ringbonds array so no need to second pass of dfs

**Kind**: instance method of <code>[Graph](#Graph)</code>
<a name="Graph+dfsSmilesInitialization"></a>
Expand Down Expand Up @@ -2144,6 +2150,81 @@ PRIVATE FUNCTION used by getConnectedComponentCount().
PRIVATE FUNCTION used by getConnectedComponents().

**Kind**: static method of <code>[Graph](#Graph)</code>
<a name="Graph.removeUnnecessaryNumbers"></a>

### Graph.removeUnnecessaryNumbers(smiles) ⇒ <code>String</code>
Remove numbers which is neighbours in SMILES notation -> need to perform in cyclic structures

**Kind**: static method of <code>[Graph](#Graph)</code>

| Param | Type |
| --- | --- |
| smiles | <code>String</code> |

<a name="Graph.repairSmiles"></a>

### Graph.repairSmiles(smiles, tmpRange, first, second, number) ⇒ <code>String</code> &#124; <code>\*</code>
Reapair SMILES

**Kind**: static method of <code>[Graph](#Graph)</code>

| Param | Type |
| --- | --- |
| smiles | <code>String</code> |
| tmpRange | <code>String</code> |
| first | <code>Number</code> |
| second | <code>Number</code> |
| number | <code>Number</code> |

<a name="Graph.removeRangeLast"></a>

### Graph.removeRangeLast(smiles, first, second) ⇒ <code>string</code>
Substring in range and remove last Organic Subset

**Kind**: static method of <code>[Graph](#Graph)</code>

| Param |
| --- |
| smiles |
| first |
| second |

<a name="Graph.getNumbers"></a>

### Graph.getNumbers(smiles) ⇒ <code>Set.&lt;Number&gt;</code>
Get numbers from SMILES

**Kind**: static method of <code>[Graph](#Graph)</code>

| Param |
| --- |
| smiles |

<a name="Graph.findFirst"></a>

### Graph.findFirst(smiles, number) ⇒ <code>number</code>
return index of first occurrence number

**Kind**: static method of <code>[Graph](#Graph)</code>

| Param |
| --- |
| smiles |
| number |

<a name="Graph.findSecond"></a>

### Graph.findSecond(smiles, from, number) ⇒ <code>\*</code>
return index of first occurrence number from index + 1

**Kind**: static method of <code>[Graph](#Graph)</code>

| Param | Description |
| --- | --- |
| smiles | |
| from | range no including this point (from, Infinity) = [from + 1, Infinity) |
| number | |

<a name="Graph.getProperVertex"></a>

### Graph.getProperVertex(vertexId, sourceId, targetId) ⇒ <code>Number</code>
Expand Down Expand Up @@ -3629,7 +3710,6 @@ A class representing a vertex.
| neighbouringElements | <code>Array.&lt;String&gt;</code> | The element symbols associated with neighbouring vertices. |
| forcePositioned | <code>Boolean</code> | A boolean indicating whether or not this vertex was positioned using a force-based approach. |
| vertexState | <code>Number</code> | enum of VertexState for DFS. |
| smilesNumbers | <code>Array.&lt;Number&gt;</code> | Numbers in notation for SMILES, need for second pass of DFS. |


* [Vertex](#Vertex)
Expand Down
4 changes: 2 additions & 2 deletions doc/index.html

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions spec/smilesNumbersSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const Graph = require('../src/Graph');

describe("smiles numbers", function () {
it("righData", function () {
let result = Graph.removeUnnecessaryNumbers('C(C1(CC)N1)=O');
expect(result).toEqual('C(C(CC)N)=O');
});

it("righData 2", function () {
let result = Graph.removeUnnecessaryNumbers('C(C1(CC)(C1C)C)=O');
expect(result).toEqual('C(C(CC)(CC)C)=O');
});

it("righData 3", function () {
let result = Graph.removeUnnecessaryNumbers('C(C1(CC)C1(CC)C)=O');
expect(result).toEqual('C(C(CC)C(CC)C)=O');
});

it("righData 4", function () {
let result = Graph.removeUnnecessaryNumbers('C(C1(CC)C(CC)C1)=O');
expect(result).toEqual('C(C1(CC)C(CC)C1)=O');
});

it("righData 5", function () {
let result = Graph.removeUnnecessaryNumbers('C(C1(CC)C(CC)C)=O');
expect(result).toEqual('C(C1(CC)C(CC)C)=O');
});

it("righData 6", function () {
let result = Graph.removeUnnecessaryNumbers('C21C(CC(=O)CC1CC3C3C2)CC');
expect(result).toEqual('C21C(CC(=O)CC1CCCC2)CC');
});

it("righData 7", function () {
let result = Graph.removeUnnecessaryNumbers('C21C(CC(=O)CC1CC3(C3C)C2)CC');
expect(result).toEqual('C21C(CC(=O)CC1CC(CC)C2)CC');
});

it("no changes", function () {
let result = Graph.removeUnnecessaryNumbers('N(C(C=O)CC7=CC=C(C=C7)N(C)C)C');
expect(result).toEqual('N(C(C=O)CC7=CC=C(C=C7)N(C)C)C');
});

it("no changes 2", function () {
let result = Graph.removeUnnecessaryNumbers('N3CC(=CCC3C=O)CN6CCOCC6');
expect(result).toEqual('N3CC(=CCC3C=O)CN6CCOCC6');
});

it("no changes 3", function () {
let result = Graph.removeUnnecessaryNumbers('NC(C=O)C5=CC=CC=C5');
expect(result).toEqual('NC(C=O)C5=CC=CC=C5');
});

it("no changes 4", function () {
let result = Graph.removeUnnecessaryNumbers('OC(C(C=O)N)C');
expect(result).toEqual('OC(C(C=O)N)C');
});

it("test with null", function () {
let result = Graph.removeUnnecessaryNumbers(null);
expect(result).toEqual('');
});

it("test with empty string", function () {
let result = Graph.removeUnnecessaryNumbers('');
expect(result).toEqual('');
});



});
Loading

0 comments on commit e7cfd4e

Please sign in to comment.