Bond drawing-order change after call to findFrags()

User f05f6b8c05

12-08-2014 11:11:39

Hi,


If we process the attached mol file through the below code, then we see change in displayed bond drawing-order .. I have attached a pdf showing before/after.  How do we prevent this change?  We are using MarvinSketch 5.12.4 and JChem API 5.12.4.


Thank you very much for any help.


Best, Andrew


MolImporter mi = new MolImporter(f1);


Molecule mol = mi.read();


System.out.println("Before:");


System.out.println(mol.toFormat("mol"));


Molecule frags[] = mol.findFrags(Molecule.class, MoleculeGraph.FRAG_KEEPING_SGROUPS);


System.out.println("After:");


System.out.println(frags[0].toFormat("mol"));


mi.close();

ChemAxon a202a732bf

12-08-2014 18:42:11

Hi Andrew,


Fragmentation adds bonds to the fragment molecules in the order as it traverses the original molecule. Fragments still keep the ligand order, but after the MOL format export and re-import it gets lost because ligand order is not stored in MOL format, it is restored from the bond order in the file. You can restore the original order of bonds by calling the method MoleculeGraph.sortBondsAccordingTo(MolBond[] order) for the fragments, after saving the original bond order into an array. Below you can find the required method calls inserted into your code example:


...

MolBond[] originalBonds = mol.getBondArray();

Molecule frags[] = mol.findFrags(Molecule.class, MoleculeGraph.FRAG_KEEPING_SGROUPS);

frags[0].sortBondsAccordingTo(originalBonds);

...


Best regards,


Zsuzsa

User f05f6b8c05

12-08-2014 23:47:43

Thanks for the quick response.


What is the correct handling for an unknown number of fragments?  Is the below correct?


MolBond[] originalBonds = mol.getBondArray();
Molecule frags[] = mol.findFrags(Molecule.class, MoleculeGraph.FRAG_KEEPING_SGROUPS);
for (int i=0; i<frags.length; ++i) frags.sortBondsAccordingTo(originalBonds);

ChemAxon d26931946c

13-08-2014 13:16:08

Yes, the method works even if the molecule it's applied to doesn't contain all the bonds in the array.


On the other hand it is important to use the same instance of bonds, the method won't work on clones of the original molecule or with cloned bonds in the array.


 


Peter

User f05f6b8c05

13-08-2014 16:57:17

Thanks very much for confirming.  Best, Andrew