|
108 | 108 | */ |
109 | 109 | public class StructureDiagramGenerator { |
110 | 110 |
|
111 | | - static final double DEFAULT_BOND_LENGTH = 1.5; |
112 | | - private static final Vector2d DEFAULT_BOND_VECTOR = new Vector2d(0, 1); |
113 | | - private static final IdentityTemplateLibrary DEFAULT_TEMPLATE_LIBRARY = IdentityTemplateLibrary.loadFromResource("custom-templates.smi") |
| 111 | + static final double DEFAULT_BOND_LENGTH = 1.5; |
| 112 | + private static final Vector2d DEFAULT_BOND_VECTOR = new Vector2d(0, 1); |
| 113 | + private static final IdentityTemplateLibrary DEFAULT_TEMPLATE_LIBRARY = IdentityTemplateLibrary.loadFromResource("custom-templates.smi") |
114 | 114 | .add(IdentityTemplateLibrary.loadFromResource("chebi-ring-templates.smi")); |
115 | | - private static final double RAD_30 = Math.toRadians(-30); |
| 115 | + private static final double RAD_30 = Math.toRadians(-30); |
116 | 116 | private static final ILoggingTool logger = LoggingToolFactory.createLoggingTool(StructureDiagramGenerator.class); |
117 | 117 |
|
| 118 | + public static final Comparator<IAtomContainer> LARGEST_FIRST_COMPARATOR = new Comparator<IAtomContainer>() { |
| 119 | + @Override |
| 120 | + public int compare(IAtomContainer o1, IAtomContainer o2) { |
| 121 | + return Integer.compare(o2.getBondCount(), o1.getBondCount()); |
| 122 | + } |
| 123 | + }; |
| 124 | + |
118 | 125 | private IAtomContainer molecule; |
119 | 126 | private IRingSet sssr; |
120 | 127 | private final double bondLength = DEFAULT_BOND_LENGTH; |
@@ -637,7 +644,12 @@ private void generateCoordinates(Vector2d firstBondVector, boolean isConnected, |
637 | 644 | final IAtomContainerSet frags = ConnectivityChecker.partitionIntoMolecules(molecule); |
638 | 645 | if (frags.getAtomContainerCount() > 1) { |
639 | 646 | IAtomContainer rollback = molecule; |
640 | | - generateFragmentCoordinates(molecule, toList(frags)); |
| 647 | + |
| 648 | + // large => small (e.g. salt will appear on the right) |
| 649 | + List<IAtomContainer> fragList = toList(frags); |
| 650 | + Collections.sort(fragList, LARGEST_FIRST_COMPARATOR); |
| 651 | + generateFragmentCoordinates(molecule, fragList); |
| 652 | + |
641 | 653 | // don't call set molecule as it wipes x,y coordinates! |
642 | 654 | // this looks like a self assignment but actually the fragment |
643 | 655 | // method changes this.molecule |
|
0 commit comments