Actelion / openchemlib

Open source Java-based chemistry library
Other
89 stars 31 forks source link

Wrong mapping with copyMoleculeByAtoms #58

Open lpatiny opened 4 years ago

lpatiny commented 4 years ago

@thsa

Related to #57

If a molecule contains hydrogen and we replace one of the hydrogens by a 'X' (not the first one, the second one), after copyMoleculeByAtoms the new position of the 'X' is not the one that is specified in the atomMap.


import OCL from 'openchemlib';

import { initOCL } from '../src';

initOCL(OCL);

const molecule = OCL.Molecule.fromSmiles('C');
molecule.addImplicitHydrogens();
molecule.setAtomicNo(2, 153); // we set a 'X' as atom

const copy = new OCL.Molecule(0, 0);
copy.setFragment(false);
const atomMap = [];
molecule.copyMoleculeByAtoms(
  copy,
  [true, true, true, false, false],
  true,
  atomMap,
);

console.log(copy.getAllAtoms()); // returns 1

console.log(atomMap); // returns [ 0, 1, 2, -1, -1 ]

console.log(copy.getAtomicNo(1)); // returns 153, should be 1
console.log(copy.getAtomicNo(2)); // returns -1, should be 153 based on atomMap
thsa commented 4 years ago

copyMoleculeByAtoms() expects that hydrogen atoms, if they exist, are at the end of the atom list. Otherwise, it will move hydrogens to the end, because it calls ensureHelperArrays() for the ring detection, if recognizeDelocalizedBonds is true. Thus, if some hydrogens are not at the end of the atom table and if you pass an includeAtom list, then the atomMap is not correct because of the resorting of the atoms.


Von: Luc Patiny notifications@github.com Gesendet: Sonntag, 26. Januar 2020 16:49 An: Actelion/openchemlib openchemlib@noreply.github.com Cc: Thomas Sander thomas.sander@idorsia.com; Mention mention@noreply.github.com Betreff: [Actelion/openchemlib] Wrong mapping with copyMoleculeByAtoms (#58)

@thsahttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fthsa&data=01%7C01%7Cthomas.sander%40idorsia.com%7C96b4aad4c6254d8c58c808d7a2775bc4%7Cbb9214bf0cb941fdbd55d0c1c3eda110%7C1&sdata=IhVqeHvd9Jn3pTfocI3Pwbxg8jzxQofcPjDp3pY5hQs%3D&reserved=0

Related to #57https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FActelion%2Fopenchemlib%2Fissues%2F57&data=01%7C01%7Cthomas.sander%40idorsia.com%7C96b4aad4c6254d8c58c808d7a2775bc4%7Cbb9214bf0cb941fdbd55d0c1c3eda110%7C1&sdata=q2R6wUXpS2pjob22yP1xU7dzW5cGYMZvyvJaRPz0sCE%3D&reserved=0

If a molecule contains hydrogen and we replace one of the hydrogens by a 'X' (not the first one, the second one), after copyMoleculeByAtoms the new position of the 'X' is not the one that is specified in the atomMap.

import OCL from 'openchemlib';

import { initOCL } from '../src';

initOCL(OCL);

const molecule = OCL.Molecule.fromSmiles('C'); molecule.addImplicitHydrogens(); molecule.setAtomicNo(2, 153); // we set a 'X' as atom

const copy = new OCL.Molecule(0, 0); copy.setFragment(false); const atomMap = []; molecule.copyMoleculeByAtoms( copy, [true, true, true, false, false], true, atomMap, );

console.log(copy.getAllAtoms()); // returns 1

console.log(atomMap); // returns [ 0, 1, 2, -1, -1 ]

console.log(copy.getAtomicNo(1)); // returns 153, should be 1 console.log(copy.getAtomicNo(2)); // returns -1, should be 153 based on atomMap

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FActelion%2Fopenchemlib%2Fissues%2F58%3Femail_source%3Dnotifications%26email_token%3DACNFEBWVJUAPVHZLA6OBNMLQ7WWJJA5CNFSM4KLXTAX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IIYMY3A&data=01%7C01%7Cthomas.sander%40idorsia.com%7C96b4aad4c6254d8c58c808d7a2775bc4%7Cbb9214bf0cb941fdbd55d0c1c3eda110%7C1&sdata=JI685lJdOZKucs%2Fyp62oCt04C8VFrr2IwtXcS6zAUPQ%3D&reserved=0, or unsubscribehttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACNFEBWL6NZGNDOD4QLB2DLQ7WWJJANCNFSM4KLXTAXQ&data=01%7C01%7Cthomas.sander%40idorsia.com%7C96b4aad4c6254d8c58c808d7a2775bc4%7Cbb9214bf0cb941fdbd55d0c1c3eda110%7C1&sdata=dYVKFZDmww9xaAqj9zP9mJg8nrSscx%2B6MZnILQmhErQ%3D&reserved=0.

The information of this email and in any file transmitted with it is strictly confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any copying, distribution or any other use of this email is prohibited and may be unlawful. In such case, you should please notify the sender immediately and destroy this email. The content of this email is not legally binding unless confirmed by letter. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state them to be the views of the sender's company.

lpatiny commented 4 years ago

Thanks for the explanation. And the ensureHelperArrays does not provide any mapping array that would allow to track the atoms during this ordering ?