Skip to content

Commit

Permalink
fix: ensure unicity
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Dec 27, 2023
1 parent 3f97479 commit 5f0bdf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ v1(fastify);
await fastify.ready();
fastify.swagger();

console.log('http://localhost:30822')
fastify.listen({ port: 30822, host: '0.0.0.0' }, (err) => {
if (err) {
fastify.log.error(err);
Expand Down
7 changes: 7 additions & 0 deletions docker/src/v1/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ function enhancedSmiles(smiles, params, info) {
if (smiles.length > limit) {
smiles.sort(() => Math.random() - 0.5);
}
// apparently this library can return twice the same molecule we check ourself
const uniqueSmiles = {};
const uniqueIDCodes = {}
for (const line of smiles.slice(0, limit)) {
if (uniqueSmiles[line]) continue;
uniqueSmiles[line] = true;
const entry = {};
entry.smiles = line;
if (idCode) {
const molecule = Molecule.fromSmiles(line);
molecule.stripStereoInformation();
entry.idCode = molecule.getIDCode();
if (uniqueIDCodes[entry.idCode]) continue;
uniqueIDCodes[entry.idCode] = true;
}
results.result.push(entry);
}
Expand Down

0 comments on commit 5f0bdf7

Please sign in to comment.