private IRenderingElement generateMixtureSgroup(Sgroup sgroup) { // draw the brackets // TODO - mixtures normally have attached Sgroup data // TODO - e.g. COMPONENT_FRACTION, ACTIVITY_TYPE, WEIGHT_PERCENT List<SgroupBracket> brackets = sgroup.getValue(SgroupKey.CtabBracket); if (brackets != null) { SgroupType type = sgroup.getType(); String subscript = "?"; switch (type) { case CtabComponent: Integer compNum = sgroup.getValue(SgroupKey.CtabComponentNumber); if (compNum != null) subscript = "c" + Integer.toString(compNum); else subscript = "c"; break; case CtabMixture: subscript = "mix"; break; case CtabFormulation: subscript = "f"; break; } return generateSgroupBrackets(sgroup, brackets, subscript, null); } else { return new ElementGroup(); } }
/** * If the molecule has display shortcuts (abbreviations or multiple group sgroups) certain parts * of the structure are hidden from display. This method marks the parts to hide and in the case * of abbreviations, remaps atom symbols. Appart from additional property flags, the molecule is * unchanged by this method. * * @param container molecule input * @param symbolRemap a map that will hold symbol remapping */ static void prepareDisplayShortcuts(IAtomContainer container, Map<IAtom, String> symbolRemap) { List<Sgroup> sgroups = container.getProperty(CDKConstants.CTAB_SGROUPS); if (sgroups == null || sgroups.isEmpty()) return; // select abbreviations that should be contracted for (Sgroup sgroup : sgroups) { if (sgroup.getType() == SgroupType.CtabAbbreviation) { Boolean expansion = sgroup.getValue(SgroupKey.CtabExpansion); // abbreviation is displayed as expanded if (expansion != null && expansion == Boolean.TRUE) continue; // no or empty label, skip it if (sgroup.getSubscript() == null || sgroup.getSubscript().isEmpty()) continue; contractAbbreviation(container, symbolRemap, sgroup); } else if (sgroup.getType() == SgroupType.CtabMultipleGroup) { hideMultipleParts(container, sgroup); } } }
/** * Generates polymer Sgroup elements. * * @param sgroup the Sgroup * @return the rendered elements (empty if no brackets defined) */ private IRenderingElement generatePolymerSgroup(Sgroup sgroup) { // draw the brackets List<SgroupBracket> brackets = sgroup.getValue(SgroupKey.CtabBracket); if (brackets != null) { SgroupType type = sgroup.getType(); String subscript = sgroup.getValue(SgroupKey.CtabSubScript); String connectivity = sgroup.getValue(SgroupKey.CtabConnectivity); switch (type) { case CtabCopolymer: subscript = "co"; String subtype = sgroup.getValue(SgroupKey.CtabSubType); if ("RAN".equals(subtype)) subscript = "ran"; else if ("BLK".equals(subtype)) subscript = "blk"; else if ("ALT".equals(subtype)) subscript = "alt"; break; case CtabCrossLink: subscript = "xl"; break; case CtabAnyPolymer: subscript = "any"; break; case CtabGraft: subscript = "grf"; break; case CtabMer: subscript = "mer"; break; case CtabMonomer: subscript = "mon"; break; case CtabModified: subscript = "mod"; break; case CtabStructureRepeatUnit: if (subscript == null) subscript = "n"; if (connectivity == null) connectivity = "eu"; break; } return generateSgroupBrackets(sgroup, brackets, subscript, connectivity); } else { return new ElementGroup(); } }
/** * Generate the Sgroup elements for the provided atom contains. * * @param container molecule * @return Sgroup rendering elements */ IRenderingElement generateSgroups(IAtomContainer container) { ElementGroup result = new ElementGroup(); List<Sgroup> sgroups = container.getProperty(CDKConstants.CTAB_SGROUPS); if (sgroups == null || sgroups.isEmpty()) return result; for (Sgroup sgroup : sgroups) { switch (sgroup.getType()) { case CtabAbbreviation: result.add(generateAbbreviationSgroup(sgroup)); break; case CtabMultipleGroup: result.add(generateMultipleSgroup(sgroup)); break; case CtabAnyPolymer: case CtabMonomer: case CtabCrossLink: case CtabCopolymer: case CtabStructureRepeatUnit: case CtabMer: case CtabGraft: case CtabModified: result.add(generatePolymerSgroup(sgroup)); break; case CtabComponent: case CtabMixture: case CtabFormulation: result.add(generateMixtureSgroup(sgroup)); break; case CtabGeneric: // not strictly a polymer but okay to draw as one result.add(generatePolymerSgroup(sgroup)); break; } } return result; }